Skip to content

Commit

Permalink
Cleanup and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-yotta committed Nov 6, 2020
1 parent 7eaf6fd commit d185d98
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 105 deletions.
6 changes: 5 additions & 1 deletion CodeMonitor/CodeMonitor.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Compile Update="**\*.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
Expand Down
4 changes: 2 additions & 2 deletions CodeMonitor/Models/CleanupCodeFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CodeMonitor
namespace CodeMonitor.Models
{
public class CleanupCodeFile
{
Expand All @@ -7,6 +7,6 @@ public CleanupCodeFile(string path)
Path = path;
}

public string Path {get;}
public string Path { get; }
}
}
22 changes: 10 additions & 12 deletions CodeMonitor/Models/CleanupCodeWatcher.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
using System.Text;
using System.Reactive.Subjects;
using System.Reactive.Linq;
using System.Reactive.Concurrency;
using DynamicData;

namespace CodeMonitor

namespace CodeMonitor.Models
{
public class CleanupCodeWatcher
{
Expand Down Expand Up @@ -57,8 +55,11 @@ private bool ShouldHandle(string s)
s.EndsWith("~") ||
s.EndsWith(".csproj") ||
s.EndsWith(".TMP")
) return false;

)
{
return false;
}

if (Directory.Exists(s))
{
return false;
Expand All @@ -76,9 +77,7 @@ private bool ShouldHandle(string s)
var result = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();

if (result != "") return false;

return true;
return result?.Length == 0;
}

public void ResetChanged()
Expand Down Expand Up @@ -112,7 +111,7 @@ public void CleanupFiles()
{
var psi = new ProcessStartInfo
{
FileName = @"c:\bin\cleanupcode.exe",
FileName = $@"{Settings.RsCltPath}\cleanupcode.exe",
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
Expand Down Expand Up @@ -150,7 +149,7 @@ public void CleanupFiles()
throw new Exception("CleanupCode was sad");
}

lock(_mutex)
lock (_mutex)
{
_changed.Clear();
results.Clear();
Expand Down Expand Up @@ -182,6 +181,5 @@ public void Start()

ResetChanged();
}

}
}
33 changes: 16 additions & 17 deletions CodeMonitor/Models/InspectCodeLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using System.Reactive.Linq;
using System.Reactive.Concurrency;
using DynamicData;

namespace CodeMonitor

namespace CodeMonitor.Models
{
public class InspectCodeLoop
{
Expand Down Expand Up @@ -54,8 +54,11 @@ private bool ShouldHandle(string s)
s.EndsWith("~") ||
s.EndsWith(".csproj") ||
s.EndsWith(".TMP")
) return false;

)
{
return false;
}

if (Directory.Exists(s))
{
return false;
Expand All @@ -73,9 +76,7 @@ private bool ShouldHandle(string s)
var result = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();

if (result != "") return false;

return true;
return result?.Length == 0;
}

private void ExamineFiles(ICollection<string> filePaths)
Expand All @@ -84,7 +85,7 @@ private void ExamineFiles(ICollection<string> filePaths)

var psi = new ProcessStartInfo
{
FileName = @"c:\bin\inspectcode.exe",
FileName = $@"{Settings.RsCltPath}\inspectcode.exe",
CreateNoWindow = true,
RedirectStandardOutput = true
};
Expand All @@ -104,7 +105,7 @@ private void ExamineFiles(ICollection<string> filePaths)
}

//TODO: Use a config file
if(filePaths.Count < 100)
if (filePaths.Count < 100)
{
args.AddRange(filePaths.Select(x => $"--input={x}"));
}
Expand All @@ -114,7 +115,7 @@ private void ExamineFiles(ICollection<string> filePaths)
args.ForEach(psi.ArgumentList.Add);

var proc = Process.Start(psi);
proc.OutputDataReceived += (o,e) => status.OnNext(e.Data);
proc.OutputDataReceived += (o, e) => status.OnNext(e.Data);
proc.BeginOutputReadLine();
proc.WaitForExit();
var xml = File.ReadAllText(outFile);
Expand All @@ -123,7 +124,7 @@ private void ExamineFiles(ICollection<string> filePaths)

var problems = doc.Root.Element("Issues")
.Elements("Project")
.Elements((XName)"Issue")
.Elements("Issue")
.Select(x =>
(
File: x.Attribute("File").Value,
Expand All @@ -145,7 +146,7 @@ private void ExamineFiles(ICollection<string> filePaths)
}
}

IDisposable subscription;
private IDisposable subscription;

internal void Stop()
{
Expand Down Expand Up @@ -197,25 +198,24 @@ private void Loop(long _)
.Select(x => x.key)
.ToList();

if (gone.Any() || _changed.Any())
if (gone.Count > 0 || _changed.Count > 0)
{
var changeNote = new StringBuilder();

changeNote.AppendLine();
changeNote.AppendLine("Changes detected!");
if (gone.Any())
if (gone.Count > 0)
{
changeNote.AppendLine("Gone: ");
changeNote.AppendLine(string.Join(Environment.NewLine, gone));
}
if (_changed.Any())
if (_changed.Count > 0)
{
changeNote.AppendLine("Changed: ");
changeNote.AppendLine(string.Join(Environment.NewLine, _changed));
}
changeNote.AppendLine("Analyzing...");


foreach (var g in gone)
{
results.Remove(g);
Expand All @@ -230,7 +230,6 @@ private void Loop(long _)
}
finally
{

status.OnNext("Idle");
active.OnNext(false);
}
Expand Down
2 changes: 1 addition & 1 deletion CodeMonitor/Models/InspectCodeProblem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CodeMonitor
namespace CodeMonitor.Models
{
public class InspectCodeProblem
{
Expand Down
2 changes: 1 addition & 1 deletion CodeMonitor/Models/InspectCodeResult.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace CodeMonitor
namespace CodeMonitor.Models
{
public class InspectCodeFileProblems
{
Expand Down
19 changes: 14 additions & 5 deletions CodeMonitor/Program.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
using Avalonia;
using Avalonia.Logging.Serilog;
using Avalonia.ReactiveUI;

using System;
using System.IO;

namespace CodeMonitor
{
class Program
public static class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
public static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}

// Avalonia configuration, don't remove; also used by visual designer.
}

private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
File.WriteAllText("Error-" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".trace", (e.ExceptionObject as Exception)?.ToString());
}

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
Expand Down
14 changes: 1 addition & 13 deletions CodeMonitor/ViewModels/FileToCleanViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
using System;
using System.Collections.ObjectModel;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using DynamicData;
using ReactiveUI;
using SharpDX.Direct2D1;

#warning subscriptions need disposing
namespace CodeMonitor.ViewModels
namespace CodeMonitor.ViewModels
{
public class FileToCleanViewModel
{
Expand Down
22 changes: 15 additions & 7 deletions CodeMonitor/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
using System;
using System.Collections.ObjectModel;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using Avalonia.Controls;
using CodeMonitor.Models;
using DynamicData;
using PropertyChanged;
using ReactiveUI;

#warning subscriptions need disposing
namespace CodeMonitor.ViewModels
{
[AddINotifyPropertyChangedInterface]
Expand All @@ -19,9 +18,11 @@ public class MainWindowViewModel : ViewModelBase
public ReactiveCommand<Window,Unit> Add { get; }

public ReadOnlyObservableCollection<MonitoredDirectoryViewModel> Monitored => monitored;
private ReadOnlyObservableCollection<MonitoredDirectoryViewModel> monitored;
private readonly ReadOnlyObservableCollection<MonitoredDirectoryViewModel> monitored;

private SourceCache<MonitoredDirectoryViewModel, string> monitoredSourceCache;
private readonly SourceCache<MonitoredDirectoryViewModel, string> monitoredSourceCache;

public ReactiveCommand<Window, Unit> SetResharperCliPath {get; }

public MainWindowViewModel()
{
Expand All @@ -30,13 +31,14 @@ public MainWindowViewModel()
monitoredSourceCache.Connect()
.ObserveOn(RxApp.MainThreadScheduler)
.Bind(out monitored)
.DisposeMany()
.Subscribe();

Add = ReactiveCommand.CreateFromTask<Window,Unit>(async w =>
Add = ReactiveCommand.CreateFromTask<Window>(async w =>
{
var d = new OpenFolderDialog();

var result = await d.ShowAsync(w);
var result = await d.ShowAsync(w).ConfigureAwait(false);

if (Directory.Exists(result))
{
Expand All @@ -47,7 +49,13 @@ public MainWindowViewModel()

monitoredSourceCache.AddOrUpdate(new MonitoredDirectoryViewModel(result));
}
return Unit.Default;
});

SetResharperCliPath = ReactiveCommand.Create<Window>(async w =>
{
var d = new OpenFolderDialog ();

Settings.RsCltPath = await d.ShowAsync(w).ConfigureAwait(false);
});
}
}
Expand Down
Loading

0 comments on commit d185d98

Please sign in to comment.