/
App.xaml.cs
234 lines (188 loc) · 8.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
using DevExpress.Xpf.Core;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using VNC;
namespace VNCCodeCommandConsole
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private static int BASE_ERRORNUMBER = ErrorNumbers.APPERROR;
private const string LOG_APPNAME = Common.LOG_APPNAME;
public App()
{
Log.Info("SignalRDelay", Common.LOG_APPNAME); Thread.Sleep(100);
long startTicks = Log.CONSTRUCTOR("Enter", LOG_APPNAME);
var defaultThemes = Theme.Themes;
Theme.RemoveTheme(Theme.Office2007BlackName);
Theme.RemoveTheme(Theme.Office2007BlueName);
Theme.RemoveTheme(Theme.Office2007SilverName);
Theme.RemoveTheme(Theme.Office2010BlackName);
Theme.RemoveTheme(Theme.Office2010BlueName);
Theme.RemoveTheme(Theme.Office2010SilverName);
Theme.RemoveTheme(Theme.Office2013Name);
Theme.RemoveTheme(Theme.Office2013TouchName);
Theme.RemoveTheme(Theme.Office2013LightGrayName);
Theme.RemoveTheme(Theme.Office2013LightGrayTouchName);
Theme.RemoveTheme(Theme.Office2013DarkGrayName);
Theme.RemoveTheme(Theme.Office2013DarkGrayTouchName);
Theme.RemoveTheme(Theme.Office2016ColorfulName);
Theme.RemoveTheme(Theme.Office2016ColorfulTouchName);
Theme.RemoveTheme(Theme.Office2016WhiteTouchName);
Theme.RemoveTheme(Theme.Office2016BlackTouchName);
Theme.RemoveTheme(Theme.DXStyleName);
Theme.RemoveTheme(Theme.DeepBlueName);
Theme.RemoveTheme(Theme.SevenName);
Theme.RemoveTheme(Theme.VS2010Name);
Theme.RemoveTheme(Theme.TouchlineDarkName);
Theme.RemoveTheme(Theme.LightGrayName);
Theme.RemoveTheme(Theme.HybridAppName);
var newThemes = Theme.Themes;
// TODO(crhodes)
// Cannot loop across and delete themes. Read-Only collection.
// Add to manually remove above. ;(
//foreach (var theme in defaultThemes)
//{
// var name = theme.Name;
// if (name.Contains("2013") || name.Contains("2010") || name.Contains("2007"))
// {
// Theme.RemoveTheme(name);
// }
//}
ApplicationThemeHelper.ApplicationThemeName = Data.Config.DefaultUITheme;
Log.CONSTRUCTOR("Exit", LOG_APPNAME, startTicks);
}
private void Application_Startup(object sender, StartupEventArgs e)
{
long startTicks = Log.APPLICATION_START("Enter", LOG_APPNAME);
try
{
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Common.CurrentUser = new WindowsPrincipal(WindowsIdentity.GetCurrent());
if (Data.Config.ADBypass)
{
Common.IsAdministrator = true;
Common.IsBetaUser = true;
}
else
{
if (!Data.Config.AD_Users_AllowAll)
{
bool isAuthorizedUser = VNC.ActiveDirectory.Helper.CheckGroupMembership(
//"maward",
Common.CurrentUser.Identity.Name,
Data.Config.ADGroup_Users,
Data.Config.AD_Domain);
if (!isAuthorizedUser)
{
MessageBox.Show(string.Format("You must be a member of {0}\\{1} to run this application.",
Data.Config.AD_Domain, Data.Config.ADGroup_Users));
return;
}
}
Common.IsAdministrator = VNC.ActiveDirectory.Helper.CheckDirectGroupMembership(
Common.CurrentUser.Identity.Name,
Data.Config.ADGroup_Administrators,
Data.Config.AD_Domain);
Common.IsBetaUser = VNC.ActiveDirectory.Helper.CheckDirectGroupMembership(
Common.CurrentUser.Identity.Name,
Data.Config.ADGroup_BetaUsers,
Data.Config.AD_Domain);
Common.IsDeveloper = Common.CurrentUser.Identity.Name.Contains("crhodes") ? true : false;
// Next lines are for testing UI only. Comment out for normal operation.
//Common.IsAdministrator = false;
//Common.IsBetaUser = false;
//Common.IsDeveloper = false;
}
// Cannot do here as the Common.ApplicationDataSet has not been loaded. Need to move here or do later.
// For now this is in DXRibbonWindowMain();
//var eventMessage = "Started";
//SQLInformation.Helper.IndicateApplicationUsage(LOG_APPNAME, DateTime.Now, currentUser.Identity.Name, eventMessage);
// Launch the main window.
// TODO(crhodes)
// Would be cool to start this with a Window specified in the App.Config file
//User_Interface.Windows.SplashScreen _window1 = new User_Interface.Windows.SplashScreen();
User_Interface.Windows.DXRibbonWindowMain _window1 = new User_Interface.Windows.DXRibbonWindowMain();
//User_Interface.Windows.About _window1 = new User_Interface.Windows.About();
//String windowArgs = string.Empty;
// Check for arguments; if there are some build the path to the package out of the args.
//if (args.Args.Length > 0 && args.Args[0] != null)
//{
// for (int i = 0; i < args.Args.Length; ++i)
// {
// windowArgs = args.Args[i];
// switch (i)
// {
// case 0: // Patient Id
// //patientId = windowArgs;
// break;
// }
// }
//}
_window1.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
MessageBox.Show(ex.InnerException.ToString());
}
Log.APPLICATION_START("Exit", LOG_APPNAME, startTicks);
}
private void Application_SessionEnding(object sender, SessionEndingCancelEventArgs e)
{
#if TRACE
long startTicks = Log.APPLICATION_END("Enter", LOG_APPNAME, BASE_ERRORNUMBER + 0);
#endif
#if TRACE
Log.APPLICATION_END("Exit", LOG_APPNAME, BASE_ERRORNUMBER + 0, startTicks);
#endif
}
private void Application_Exit(object sender, ExitEventArgs e)
{
#if TRACE
long startTicks = Log.APPLICATION_END("Enter", LOG_APPNAME, BASE_ERRORNUMBER + 0);
#endif
#if TRACE
Log.APPLICATION_END("Exit", LOG_APPNAME, BASE_ERRORNUMBER + 0, startTicks);
#endif
}
private void Application_Deactivated(object sender, EventArgs e)
{
#if TRACE
long startTicks = Log.APPLICATION_END("Enter", LOG_APPNAME, BASE_ERRORNUMBER + 0);
#endif
#if TRACE
Log.APPLICATION_END("Exit", LOG_APPNAME, BASE_ERRORNUMBER + 0, startTicks);
#endif
}
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
#if TRACE
long startTicks = Log.Debug("Enter", LOG_APPNAME, BASE_ERRORNUMBER + 0);
#endif
MessageBox.Show("Application_DispatcherUnhandledException: " + e.Exception.Message, LOG_APPNAME, MessageBoxButton.OK, MessageBoxImage.Warning);
MessageBox.Show("Application_DispatcherUnhandledException Inner: " + e.Exception.InnerException.Message, LOG_APPNAME, MessageBoxButton.OK, MessageBoxImage.Warning);
//e.Handled = true; // Use if can handle exception that is thrown
e.Handled = false; // Default
#if TRACE
Log.Debug("Exit", LOG_APPNAME, BASE_ERRORNUMBER + 0, startTicks);
#endif
}
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception ex = e.ExceptionObject as Exception;
MessageBox.Show(ex.Message, "Uncaught Thread Exception",
MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}