-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathApp.xaml.cs
154 lines (127 loc) · 6.81 KB
/
App.xaml.cs
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
148
149
150
151
152
153
154
using CommonServiceLocator;
using DevelopmentInProgress.TradeView.Core.Interfaces;
using DevelopmentInProgress.TradeView.Data;
using DevelopmentInProgress.TradeView.Data.File;
using DevelopmentInProgress.TradeView.Service;
using DevelopmentInProgress.TradeView.Wpf.Common.Cache;
using DevelopmentInProgress.TradeView.Wpf.Common.Chart;
using DevelopmentInProgress.TradeView.Wpf.Common.Helpers;
using DevelopmentInProgress.TradeView.Wpf.Common.Manager;
using DevelopmentInProgress.TradeView.Wpf.Common.Services;
using DevelopmentInProgress.TradeView.Wpf.Common.ViewModel;
using DevelopmentInProgress.TradeView.Wpf.Configuration.Utility;
using DevelopmentInProgress.TradeView.Wpf.Controls.Messaging;
using DevelopmentInProgress.TradeView.Wpf.Host.Controller.Context;
using DevelopmentInProgress.TradeView.Wpf.Host.Controller.Navigation;
using DevelopmentInProgress.TradeView.Wpf.Host.Controller.RegionAdapters;
using DevelopmentInProgress.TradeView.Wpf.Host.Controller.View;
using DevelopmentInProgress.TradeView.Wpf.Host.Controller.ViewModel;
using DevelopmentInProgress.TradeView.Wpf.Host.Logger;
using DevelopmentInProgress.TradeView.Wpf.Strategies.Utility;
using DevelopmentInProgress.TradeView.Wpf.Trading.ViewModel;
using Prism.Ioc;
using Prism.Logging;
using Prism.Modularity;
using Prism.Regions;
using Prism.Unity;
using Serilog;
using System;
using System.ComponentModel;
using System.IO;
using System.Windows;
using Xceed.Wpf.AvalonDock;
namespace DevelopmentInProgress.TradeView.Wpf.Host
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : PrismApplication
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
}
protected override IModuleCatalog CreateModuleCatalog()
{
using Stream xamlStream = File.OpenRead("Configuration/ModuleCatalog.xaml");
var moduleCatalog = ModuleCatalog.CreateFromXaml(xamlStream);
return moduleCatalog;
}
protected override async void RegisterTypes(IContainerRegistry containerRegistry)
{
Serilog.Core.Logger logger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();
containerRegistry.RegisterInstance<ILogger>(logger);
containerRegistry.RegisterSingleton<ILoggerFacade, LoggerFacade>();
containerRegistry.RegisterSingleton<NavigationManager>();
containerRegistry.RegisterSingleton<ModulesNavigationView>();
containerRegistry.RegisterSingleton<ModulesNavigationViewModel>();
containerRegistry.RegisterSingleton<ModuleNavigator>();
containerRegistry.Register<IViewContext, ViewContext>();
containerRegistry.RegisterSingleton<IExchangeApiFactory, ExchangeApiFactory>();
containerRegistry.Register<IExchangeService, ExchangeService>();
containerRegistry.Register<ITradeViewConfigurationAccounts, TradeViewConfigurationAccountsFile>();
containerRegistry.Register<ITradeViewConfigurationStrategy, TradeViewConfigurationStrategyFile>();
containerRegistry.Register<ITradeViewConfigurationServer, TradeViewConfigurationServerFile>();
containerRegistry.Register<IAccountsService, AccountsService>();
containerRegistry.Register<IStrategyService, StrategyService>();
containerRegistry.Register<ITradeServerService, TradeServerService>();
containerRegistry.Register<IWpfExchangeService, WpfExchangeService>();
containerRegistry.Register<ISymbolsCache, SymbolsCache>();
containerRegistry.RegisterSingleton<ISymbolsCacheFactory, SymbolsCacheFactory>();
containerRegistry.RegisterSingleton<IServerMonitorCache, ServerMonitorCache>();
containerRegistry.RegisterSingleton<IOrderBookHelperFactory, OrderBookHelperFactory>();
containerRegistry.RegisterSingleton<ITradeHelperFactory, TradeHelperFactory>();
containerRegistry.RegisterSingleton<IHelperFactoryContainer, HelperFactoryContainer>();
containerRegistry.RegisterSingleton<IChartHelper, ChartHelper>();
containerRegistry.Register<OrdersViewModel>();
containerRegistry.Register<AccountBalancesViewModel>();
containerRegistry.Register<AccountViewModel>();
containerRegistry.Register<SymbolsViewModel>();
containerRegistry.Register<TradePanelViewModel>();
containerRegistry.Register<IStrategyFileManager, StrategyFileManager>();
containerRegistry.Register<ISymbolsLoader, SymbolsLoader>();
containerRegistry.Register<IStrategyAssemblyManager, StrategyAssemblyManager>();
containerRegistry.Register<Strategies.ViewModel.SymbolsViewModel>();
containerRegistry.Register<Strategies.ViewModel.StrategyParametersViewModel>();
containerRegistry.RegisterSingleton<IHttpClientManager, HttpClientManager>();
var serverMonitorCache = Container.Resolve<IServerMonitorCache>();
serverMonitorCache.StartObservingServers();
var symbolsCacheFactory = Container.Resolve<ISymbolsCacheFactory>();
await symbolsCacheFactory.SubscribeAccountsAssets().ConfigureAwait(false);
}
protected override void ConfigureRegionAdapterMappings(RegionAdapterMappings regionAdapterMappings)
{
if(regionAdapterMappings == null)
{
throw new ArgumentNullException(nameof(regionAdapterMappings));
}
regionAdapterMappings.RegisterMapping(typeof(DockingManager), new DockingManagerRegionAdapter(ServiceLocator.Current.GetInstance<IRegionBehaviorFactory>()));
}
protected override Window CreateShell()
{
return Container.Resolve<ShellWindow>();
}
protected override void InitializeShell(Window shell)
{
if (shell == null)
{
throw new ArgumentNullException(nameof(shell));
}
var modulesNavigationViewModel = Container.Resolve<ModulesNavigationViewModel>();
((ShellWindow)shell).ModulesNavigationViewModel = modulesNavigationViewModel;
Current.MainWindow = shell;
Current.MainWindow.WindowState = WindowState.Maximized;
Current.MainWindow.Show();
}
private void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception)args.ExceptionObject;
var log = Container.Resolve<ILoggerFacade>();
log.Log(e.ToString(), Category.Exception, Priority.Low);
}
}
}