-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
147 lines (120 loc) · 5.52 KB
/
App.xaml.cs
File metadata and controls
147 lines (120 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System.IO;
using System.Windows;
using CodeGraph.Exploration;
using CodeParser.Parser;
using CSharpCodeAnalyst.CommandLine;
using CSharpCodeAnalyst.Configuration;
using CSharpCodeAnalyst.Features.AdvancedSearch;
using CSharpCodeAnalyst.Persistence.Json;
using CSharpCodeAnalyst.Features.Analyzers;
using CSharpCodeAnalyst.Features.Graph;
using CSharpCodeAnalyst.Features.Info;
using CSharpCodeAnalyst.Features.Refactoring;
using CSharpCodeAnalyst.Features.Tree;
using CSharpCodeAnalyst.Shared.Messages;
using CSharpCodeAnalyst.Shared.Notifications;
using Microsoft.Extensions.Configuration;
namespace CSharpCodeAnalyst;
public partial class App
{
protected override async void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
// Check if command line arguments are provided
if (e.Args.Length > 1)
{
// Run in command-line mode.
// ConsoleHelper.EnsureConsole();
var exitCode = await CommandLineProcessor.ProcessCommandLine(e.Args);
Environment.Exit(exitCode);
return;
}
// Run in UI mode
StartUi();
// Faster debugging
await LoadProjectFileFromCommandLineAsync(e);
}
private async Task LoadProjectFileFromCommandLineAsync(StartupEventArgs e)
{
const string prefix = "-load:";
if (e.Args.Length == 1 && e.Args[0].StartsWith(prefix))
{
var file = e.Args[0][prefix.Length..];
if (!File.Exists(file))
{
return;
}
// Allow loading a project file (json) via command line for faster debugging
if (MainWindow?.DataContext is MainViewModel dc)
{
await dc.LoadProjectFileAsync(file);
}
}
}
private void StartUi()
{
// const int delayMs = 200;
// ToolTipService.InitialShowDelayProperty.OverrideMetadata(
// typeof(DependencyObject),
// new FrameworkPropertyMetadata(delayMs));
// ToolTipService.BetweenShowDelayProperty.OverrideMetadata(
// typeof(DependencyObject),
// new FrameworkPropertyMetadata(delayMs));
try
{
Initializer.InitializeMsBuildLocator();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
// Load application settings
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true);
IConfiguration configuration = builder.Build();
var applicationSettings = configuration.GetSection("ApplicationSettings").Get<AppSettings>();
if (applicationSettings is null)
{
applicationSettings = new AppSettings();
}
var userSettings = UserPreferences.LoadOrCreate();
var uiNotification = new WindowsUserNotification();
var messaging = new MessageBus();
var analyzerManager = new AnalyzerManager();
analyzerManager.LoadAnalyzers(messaging, uiNotification);
var explorer = new CodeGraphExplorer();
var mainWindow = new MainWindow();
var explorationGraphViewer = new GraphViewer(messaging, applicationSettings.WarningCodeElementLimit);
var refactoringInteraction = new RefactoringInteraction();
var refactoringService = new RefactoringService(refactoringInteraction, messaging);
mainWindow.SetViewer(explorationGraphViewer, messaging);
var projectStorage = new JsonProjectStorage();
var projectService = new ProjectService(projectStorage, uiNotification, userSettings);
var viewModel = new MainViewModel(messaging, applicationSettings, userSettings, analyzerManager, refactoringService, projectService);
var graphViewModel = new GraphViewModel(explorationGraphViewer, explorer, messaging, applicationSettings, refactoringService);
var treeViewModel = new TreeViewModel(messaging, refactoringService);
var searchViewModel = new AdvancedSearchViewModel(messaging, refactoringService);
var infoPanelViewModel = new InfoPanelViewModel();
viewModel.InfoPanelViewModel = infoPanelViewModel;
viewModel.GraphViewModel = graphViewModel;
viewModel.TreeViewModel = treeViewModel;
viewModel.SearchViewModel = searchViewModel;
// Setup messaging
messaging.Subscribe<LocateInTreeRequest>(mainWindow.HandleLocateInTreeRequest);
messaging.Subscribe<ShowTabularDataRequest>(viewModel.HandleShowTabularData);
messaging.Subscribe<AddNodeToGraphRequest>(graphViewModel.HandleAddNodeToGraphRequest);
messaging.Subscribe<QuickInfoUpdateRequest>(infoPanelViewModel.HandleUpdateQuickInfo);
messaging.Subscribe<CycleCalculationComplete>(viewModel.HandleCycleCalculationComplete);
messaging.Subscribe<ShowPartitionsRequest>(viewModel.HandleShowPartitionsRequest);
messaging.Subscribe<ShowCycleGroupRequest>(viewModel.HandleShowCycleGroupRequest);
// Refactorings are forwarded to all other view models
messaging.Subscribe<CodeGraphRefactored>(viewModel.HandleCodeGraphRefactored);
// messaging.Subscribe<CodeElementsMoved>(viewModel.HandleCodeGraphRefactored);
// messaging.Subscribe<CodeElementsDeleted>(viewModel.HandleCodeGraphRefactored);
// messaging.Subscribe<CodeElementCreated>(viewModel.HandleCodeGraphRefactored);
mainWindow.DataContext = viewModel;
MainWindow = mainWindow;
mainWindow.Show();
}
}