Skip to content

Commit db8f975

Browse files
authored
Refactoring MainViewModel (#34)
Refactored MainViewModel Extracted Project, Import and Export
1 parent 7d49f85 commit db8f975

23 files changed

+808
-545
lines changed

ApprovalTestTool/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private static async Task RunTestCode(string slnPath, string outputPath)
154154
{
155155
var parserConfig = new ParserConfig(new ProjectExclusionRegExCollection(), false);
156156
var parser = new Parser(parserConfig);
157-
var graph = await parser.Parse(slnPath);
157+
var graph = await parser.ParseAsync(slnPath);
158158
await File.WriteAllTextAsync(outputPath, graph.ToDebug());
159159
}
160160

CSharpCodeAnalyst/App.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ private void StartUi()
9696

9797
var userSettings = UserSettings.Instance;
9898

99-
var messageBox = new WindowsUserNotification();
99+
var uiNotification = new WindowsUserNotification();
100100
var messaging = new MessageBus();
101101

102102
var analyzerManager = new AnalyzerManager();
103-
analyzerManager.LoadAnalyzers(messaging, messageBox);
103+
analyzerManager.LoadAnalyzers(messaging, uiNotification);
104104

105105
var explorer = new CodeGraphExplorer();
106106
var mainWindow = new MainWindow();

CSharpCodeAnalyst/CommandLine/ConsoleValidationCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private static async Task<CodeGraph> ParseSolution(string solutionPath, Applicat
9191
var filter = new ProjectExclusionRegExCollection();
9292
filter.Initialize(settings.DefaultProjectExcludeFilter);
9393
var parser = new Parser(new ParserConfig(filter, settings.IncludeExternalCode));
94-
var graph = await parser.Parse(solutionPath).ConfigureAwait(false);
94+
var graph = await parser.ParseAsync(solutionPath).ConfigureAwait(false);
9595

9696
var failures = parser.Diagnostics.FormatFailures();
9797
if (!string.IsNullOrEmpty(failures))

CSharpCodeAnalyst/Common/ConsoleUserNotification.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,25 @@ public void ShowWarning(string message)
2323
{
2424
Trace.TraceWarning(message);
2525
}
26+
27+
public string? ShowOpenFileDialog(string filter, string title)
28+
{
29+
// Not in console mode
30+
return null;
31+
}
32+
33+
public string? ShowSaveFileDialog(string filter, string title)
34+
{
35+
// Not in console mode
36+
return null;
37+
}
38+
39+
public void ShowErrorWarningDialog(List<string> errors, List<string> warnings)
40+
{
41+
}
42+
43+
public bool AskYesNoQuestion(string saveMessage, string saveTitle)
44+
{
45+
return true;
46+
}
2647
}

CSharpCodeAnalyst/Common/ErrorWarningDialog.xaml.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ public partial class ErrorWarningDialog : Window
88
private ErrorWarningDialog(List<string> errors, List<string> warnings)
99
{
1010
InitializeComponent();
11-
12-
13-
11+
1412
ErrorList.ItemsSource = errors;
1513
WarningList.ItemsSource = warnings;
1614

CSharpCodeAnalyst/Common/IUserNotification.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ public interface IUserNotification
99
void ShowInfo(string message);
1010

1111
void ShowWarning(string message);
12+
string? ShowOpenFileDialog(string filter, string title);
13+
string? ShowSaveFileDialog(string filter, string title);
14+
void ShowErrorWarningDialog(List<string> errors, List<string> warnings);
15+
bool AskYesNoQuestion(string saveMessage, string saveTitle);
1216
}

CSharpCodeAnalyst/Common/Result.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
namespace CSharpCodeAnalyst.Common;
2+
3+
/// <summary>
4+
/// Without data
5+
/// </summary>
6+
public class Result
7+
{
8+
private Result(bool isSuccess, bool isCanceled, Exception? error)
9+
{
10+
IsSuccess = isSuccess;
11+
IsCanceled = isCanceled;
12+
Error = error;
13+
}
14+
15+
public bool IsSuccess { get; }
16+
public bool IsCanceled { get; }
17+
18+
public bool IsFailure
19+
{
20+
get => !IsSuccess && !IsCanceled;
21+
}
22+
23+
public Exception? Error { get; }
24+
25+
public static Result Success()
26+
{
27+
return new Result(true, false, null);
28+
}
29+
30+
public static Result Failure(Exception error)
31+
{
32+
return new Result(false, false, error);
33+
}
34+
35+
public static Result Canceled()
36+
{
37+
return new Result(false, true, null);
38+
}
39+
}
40+
41+
public class Result<T>
42+
{
43+
44+
private Result(bool isSuccess, T? data, Exception? error, bool isCanceled)
45+
{
46+
IsCanceled = isCanceled;
47+
IsSuccess = isSuccess;
48+
Data = data;
49+
Error = error;
50+
}
51+
52+
public bool IsSuccess { get; }
53+
public bool IsCanceled { get; }
54+
public T? Data { get; }
55+
public Exception? Error { get; }
56+
57+
public static Result<T> Success(T data)
58+
{
59+
return new Result<T>(true, data, null, false);
60+
}
61+
62+
public static Result<T> Failure(Exception error)
63+
{
64+
return new Result<T>(false, default, error, false);
65+
}
66+
67+
public static Result<T> Canceled()
68+
{
69+
return new Result<T>(false, default, null, true);
70+
}
71+
}

CSharpCodeAnalyst/Common/WindowsUserNotification.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Windows;
22
using CSharpCodeAnalyst.Resources;
33
using CSharpCodeAnalyst.Shared.UI;
4+
using Microsoft.Win32;
45

56
namespace CSharpCodeAnalyst.Common;
67

@@ -27,4 +28,37 @@ public void ShowWarning(string message)
2728
MessageBox.Show(message, Strings.Warning_Title,
2829
MessageBoxButton.OK, MessageBoxImage.Warning);
2930
}
31+
32+
public string? ShowOpenFileDialog(string filter, string title)
33+
{
34+
var dialog = new OpenFileDialog
35+
{
36+
Filter = filter,
37+
Title = title
38+
};
39+
40+
return dialog.ShowDialog() == true ? dialog.FileName : null;
41+
}
42+
43+
public string? ShowSaveFileDialog(string filter, string title)
44+
{
45+
var dialog = new SaveFileDialog
46+
{
47+
Filter = filter,
48+
Title = title
49+
};
50+
51+
return dialog.ShowDialog() == true ? dialog.FileName : null;
52+
}
53+
54+
public void ShowErrorWarningDialog(List<string> errors, List<string> warnings)
55+
{
56+
ErrorWarningDialog.Show(errors, warnings, Application.Current.MainWindow);
57+
}
58+
59+
public bool AskYesNoQuestion(string message, string title)
60+
{
61+
return MessageBox.Show(message, title,
62+
MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;
63+
}
3064
}

0 commit comments

Comments
 (0)