forked from smartquant/SharpQuant.QuantStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
113 lines (75 loc) · 3.25 KB
/
Program.cs
File metadata and controls
113 lines (75 loc) · 3.25 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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Reflection;
using System.Configuration;
using System.Threading;
using SharpQuant.Common;
using SharpQuant.UI.ErrorManager;
using QuantStudio.Startup;
using Autofac;
namespace QuantStudio
{
static class Program
{
static string[] _dllpaths;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
if (!Platform.IsUnix)
if (!SingleInstance.Start())
{
SingleInstance.ShowFirstInstance();
return;
}
_dllpaths = ConfigurationManager.AppSettings["dllpath"].Split(';');
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(LoadAssemblies);
//re-direct exceptions to runtime error manager
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//threadpool optimization
ThreadPool.SetMinThreads(5, 5);
ProgramInit.InitContainer();
var splashScreen = Globals.container.Resolve<ISplashScreen>();
ThreadPool.QueueUserWorkItem(new WaitCallback((o) => { Application.Run(splashScreen as Form); }));
Thread.Sleep(100);
splashScreen.SetProgressText("Initializing Settings...");
ProgramInit.RegisterModule();
//Need to do this again...
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
//Setup mainform
var main = new MainForm();
var setup = new SetupMainForm(main, Globals.container);
setup.DoIt();
splashScreen.CloseThis();
Application.Run(main);
ProgramInit.Cleanup();
if (!Platform.IsUnix)
SingleInstance.Stop();
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
RuntimeErrorManager.ReportError(new RuntimeError(RuntimeErrorLevel.Medium, (Exception)e.ExceptionObject, "Application"));
}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
RuntimeErrorManager.ReportError(new RuntimeError(RuntimeErrorLevel.Medium, e.Exception, "Application"));
}
static Assembly LoadAssemblies(object sender, ResolveEventArgs args)
{
string simpleName = new AssemblyName(args.Name).Name;
foreach (var p in _dllpaths)
{
string path = System.IO.Path.Combine(p, simpleName + ".dll");
if (System.IO.File.Exists(path)) return Assembly.LoadFrom(path);
}
return null;
}
}
}