markus / KCOM / App.xaml.cs @ 91c5e7a1
이력 | 보기 | 이력해설 | 다운로드 (13.8 KB)
1 |
|
---|---|
2 |
using KCOM.Common; |
3 |
using KCOM.ServiceDeepView; |
4 |
using System; |
5 |
using System.Collections.Generic; |
6 |
using System.ComponentModel; |
7 |
using System.Configuration; |
8 |
using System.Data; |
9 |
using System.Diagnostics; |
10 |
using System.IO; |
11 |
using System.Linq; |
12 |
using System.Net; |
13 |
using System.Reflection; |
14 |
using System.Runtime.CompilerServices; |
15 |
using System.ServiceModel; |
16 |
using System.Windows; |
17 |
using System.Xml; |
18 |
using log4net; |
19 |
using System.Text; |
20 |
using System.Runtime.InteropServices; |
21 |
using KCOM.Views; |
22 |
using System.Threading.Tasks; |
23 |
using Telerik.Windows.Controls; |
24 |
using System.Windows.Input; |
25 |
|
26 |
[assembly: log4net.Config.XmlConfigurator(Watch = true)] |
27 |
namespace KCOM |
28 |
{ |
29 |
public class OpenProperties |
30 |
{ |
31 |
public string DocumentItemID { get; set; } |
32 |
public bool bPartner { get; set; } |
33 |
public bool CreateFinalPDFPermission { get; set; } |
34 |
public bool NewCommentPermission { get; set; } |
35 |
public string ProjectNO { get; set; } |
36 |
public string UserID { get; set; } |
37 |
public int Mode { get; set; } |
38 |
|
39 |
/// <summary> |
40 |
/// pemss에서 전달되는 ID |
41 |
/// </summary> |
42 |
public string pId { get; set; } |
43 |
|
44 |
/// <summary> |
45 |
/// pemss에서 전달되는 ID |
46 |
/// </summary> |
47 |
public string uId { get; set; } |
48 |
|
49 |
public string cId { get; set; } |
50 |
} |
51 |
/// <summary> |
52 |
/// App.xaml에 대한 상호 작용 논리 |
53 |
/// </summary> |
54 |
public partial class App : Application |
55 |
{ |
56 |
public static bool IsDesignMode |
57 |
{ |
58 |
get |
59 |
{ |
60 |
try |
61 |
{ |
62 |
return DesignerProperties.GetIsInDesignMode(new DependencyObject()); |
63 |
} |
64 |
catch (Exception) |
65 |
{ |
66 |
return false; |
67 |
} |
68 |
} |
69 |
private set { } |
70 |
} |
71 |
|
72 |
public static BasicHttpBinding _binding; |
73 |
public static EndpointAddress _EndPoint; |
74 |
public static EndpointAddress _PemssEndPoint; |
75 |
public static EndpointAddress _EndPoint_SaveLoad; |
76 |
public static EndpointAddress _EndPoint_Symbol; |
77 |
public static string UserID; |
78 |
public static string UserName; |
79 |
public static string UserIP; |
80 |
public static IKCOM.ViewInfo ViewInfo; |
81 |
public static IKCOM.PEMSSInfo PEMSSInfo; |
82 |
public static string urlHost; |
83 |
public static string urlPort; |
84 |
public static string urlHost_DB; |
85 |
public static string urlPort_DB; |
86 |
public static string Custom_ViewInfoId; |
87 |
public static bool ParameterMode = false; |
88 |
public static bool isExternal = false; |
89 |
|
90 |
/// <summary> |
91 |
/// logger |
92 |
/// </summary> |
93 |
public static ILog DBLogger = null; |
94 |
public static ILog FileLogger = null; |
95 |
|
96 |
/// <summary> |
97 |
/// Application Data Folder |
98 |
/// </summary> |
99 |
public static string AppDataFolder |
100 |
{ |
101 |
get |
102 |
{ |
103 |
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS"); |
104 |
} |
105 |
} |
106 |
|
107 |
|
108 |
public static RestSharp.RestClient BaseClient { get; set; } |
109 |
public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; } |
110 |
|
111 |
|
112 |
private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null) |
113 |
{ |
114 |
if (oEncoding == null) |
115 |
oEncoding = System.Text.Encoding.UTF8; |
116 |
|
117 |
byte[] byteArray = Convert.FromBase64String(DecodingText); |
118 |
|
119 |
string jsonBack = oEncoding.GetString(byteArray); |
120 |
|
121 |
return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack); |
122 |
} |
123 |
|
124 |
private string versionPath = null; |
125 |
//public SplashScreen splash = new SplashScreen("splash.png"); |
126 |
public static SplashScreenWindow splashScreen = new SplashScreenWindow(); |
127 |
|
128 |
public App() |
129 |
{ |
130 |
Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.Office2016Theme(); |
131 |
} |
132 |
|
133 |
protected override async void OnStartup(StartupEventArgs e) |
134 |
{ |
135 |
|
136 |
try |
137 |
{ |
138 |
|
139 |
Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; |
140 |
|
141 |
splashScreen.Show(); |
142 |
|
143 |
/// create log database and table |
144 |
using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") }) |
145 |
{ |
146 |
string sSql = "CREATE TABLE IF NOT EXISTS Log (LogId INTEGER PRIMARY KEY,Date DATETIME NOT NULL,Level VARCHAR(50) NOT NULL,Logger VARCHAR(255) NOT NULL,Message TEXT DEFAULT NULL,StackTrace TEXT DEFAULT NULL);"; |
147 |
database.ExecuteNonQuery(sSql); |
148 |
} |
149 |
/// up to here |
150 |
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |
151 |
log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db"); |
152 |
log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log"); |
153 |
App.DBLogger = LogManager.GetLogger("DBLogger"); |
154 |
App.FileLogger = LogManager.GetLogger("EventLogger"); |
155 |
|
156 |
#region // DNS 체크 |
157 |
|
158 |
string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", ""); |
159 |
|
160 |
var hostEntry = CommonLib.DNSHelper.GetHostEntryTask(); |
161 |
|
162 |
if (hostEntry == null) |
163 |
{ |
164 |
System.Diagnostics.Debug.WriteLine("(hostEntry == null"); |
165 |
App.FileLogger.Fatal("hostEntry == null"); |
166 |
isExternal = true; |
167 |
} |
168 |
else if (!hostEntry.HostName.EndsWith(localdomain)) |
169 |
{ |
170 |
// 외부 사용자 |
171 |
App.FileLogger.Fatal("hostEntry != localdomain :" + hostEntry.HostName); |
172 |
isExternal = true; |
173 |
} |
174 |
#endregion |
175 |
//splash.Show(false, false); |
176 |
|
177 |
if (e.Args.Count() > 0) |
178 |
{ |
179 |
var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
180 |
App.ViewInfo = new IKCOM.ViewInfo |
181 |
{ |
182 |
DocumentItemID = result.DocumentItemID, |
183 |
EnsembleID = result.DocumentItemID, |
184 |
//DocumentItemID = "10001", |
185 |
bPartner = result.bPartner, |
186 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
187 |
NewCommentPermission = result.NewCommentPermission, |
188 |
ProjectNO = result.ProjectNO, |
189 |
UserID = result.UserID, |
190 |
//UserID = "H2009115", |
191 |
//Mode = 0 , 1 , 2 |
192 |
}; |
193 |
|
194 |
App.PEMSSInfo = new IKCOM.PEMSSInfo |
195 |
{ |
196 |
UserID = result.uId, |
197 |
CommentID = result.cId |
198 |
}; |
199 |
|
200 |
App.ViewInfo.UserID = App.PEMSSInfo.UserID; |
201 |
ParameterMode = true; |
202 |
} |
203 |
else |
204 |
{ |
205 |
string[] strArg = Environment.GetCommandLineArgs(); |
206 |
if (strArg.Length > 1) |
207 |
{ |
208 |
//label1.Text = strArg[1]; |
209 |
|
210 |
var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", "")); |
211 |
App.ViewInfo = new IKCOM.ViewInfo |
212 |
{ |
213 |
DocumentItemID = result.DocumentItemID, |
214 |
EnsembleID = result.DocumentItemID, |
215 |
//DocumentItemID = "10001", |
216 |
bPartner = result.bPartner, |
217 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
218 |
NewCommentPermission = result.NewCommentPermission, |
219 |
ProjectNO = result.ProjectNO, |
220 |
UserID = result.UserID, |
221 |
//UserID = "H2009115", |
222 |
//Mode = 0 , 1 , 2 |
223 |
}; |
224 |
|
225 |
App.PEMSSInfo = new IKCOM.PEMSSInfo |
226 |
{ |
227 |
UserID = result.uId |
228 |
}; |
229 |
|
230 |
ParameterMode = true; |
231 |
} |
232 |
} |
233 |
|
234 |
//App.ViewInfo.CreateFinalPDFPermission = false; |
235 |
//App.ViewInfo.NewCommentPermission = false; |
236 |
//GetQueryStringParameters(); |
237 |
_binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
238 |
_binding.MaxBufferSize = 2147483647; |
239 |
_binding.MaxReceivedMessageSize = 2147483647; |
240 |
_binding.OpenTimeout = new TimeSpan(0, 1, 0); |
241 |
_binding.ReceiveTimeout = new TimeSpan(0, 10, 0); |
242 |
_binding.CloseTimeout = new TimeSpan(0, 5, 0); |
243 |
_binding.SendTimeout = new TimeSpan(0, 5, 0); |
244 |
_binding.TextEncoding = System.Text.Encoding.UTF8; |
245 |
_binding.TransferMode = TransferMode.Buffered; |
246 |
//Support.SetLicense(); |
247 |
|
248 |
string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", ""); |
249 |
|
250 |
#if DEBUG |
251 |
//sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
252 |
System.Diagnostics.Debug.WriteLine("sBaseServiceURL"); |
253 |
sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "", isExternal); |
254 |
#else |
255 |
sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
256 |
#endif |
257 |
|
258 |
_EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
259 |
|
260 |
#if DEBUG |
261 |
_PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", sBaseServiceURL)); |
262 |
#else |
263 |
_PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", sBaseServiceURL)); |
264 |
#endif |
265 |
|
266 |
await SplashScreenAsnyc(); |
267 |
|
268 |
base.OnStartup(e); |
269 |
|
270 |
Current.ShutdownMode = ShutdownMode.OnMainWindowClose; |
271 |
|
272 |
UpdateCheck(e); |
273 |
|
274 |
System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent); |
275 |
|
276 |
|
277 |
//this.MainWindow.Show(); |
278 |
//KeyValuePair<bool, string> updatecheck = UpdateCheck(e); |
279 |
} |
280 |
catch (Exception ex) |
281 |
{ |
282 |
MessageBox.Show("Err:" + ex.ToString()); |
283 |
} |
284 |
finally |
285 |
{ |
286 |
await SplashScreenAsnyc(); |
287 |
} |
288 |
} |
289 |
|
290 |
private void KeyDownEvent(object sender, KeyEventArgs e) |
291 |
{ |
292 |
System.Diagnostics.Debug.WriteLine("app key Event"); |
293 |
Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e); |
294 |
} |
295 |
|
296 |
private KeyValuePair<bool, string> UpdateCheck(StartupEventArgs startupEvents) |
297 |
{ |
298 |
bool isUpdateCheck = false; |
299 |
string updateurl = string.Empty; |
300 |
try |
301 |
{ |
302 |
bool is64bit = Environment.Is64BitProcess; |
303 |
string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
304 |
ServiceDeepViewClient BaseClient = new ServiceDeepViewClient(_binding, _EndPoint); |
305 |
updateurl = BaseClient.GetVersionData(is64bit, clientversion); |
306 |
|
307 |
if (Check_Uri.isUri(updateurl)) |
308 |
{ |
309 |
base.OnStartup(startupEvents); |
310 |
|
311 |
var updateWin = new UpdateWindow(updateurl); |
312 |
|
313 |
updateWin.UpdatePassEvent += (snd, evt) => |
314 |
{ |
315 |
updateWin.Visibility = Visibility.Hidden; |
316 |
new MainWindow().Show(); |
317 |
}; |
318 |
|
319 |
updateWin.ShowDialog(); |
320 |
} |
321 |
else |
322 |
{ |
323 |
base.OnStartup(startupEvents); |
324 |
(new MainWindow()).Show(); |
325 |
} |
326 |
} |
327 |
catch (Exception) |
328 |
{ |
329 |
throw; |
330 |
} |
331 |
return new KeyValuePair<bool, string>(isUpdateCheck, updateurl); |
332 |
} |
333 |
|
334 |
|
335 |
private async Task<bool> SplashScreenAsnyc() |
336 |
{ |
337 |
int value = 100 / ISplashMessage.SplashMessageCnt; |
338 |
|
339 |
for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++) |
340 |
{ |
341 |
System.Threading.Thread.Sleep(3); |
342 |
await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value); |
343 |
} |
344 |
|
345 |
splashScreen.Close(); |
346 |
|
347 |
return true; |
348 |
} |
349 |
|
350 |
public static void splashString(string text) |
351 |
{ |
352 |
Task.Factory.StartNew(() => |
353 |
{ |
354 |
splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text); |
355 |
}); |
356 |
} |
357 |
|
358 |
|
359 |
/// <summary> |
360 |
/// log unhandled exception |
361 |
/// </summary> |
362 |
/// <author>humkyung</author> |
363 |
/// <date>2019.05.21</date> |
364 |
/// <param name="sender"></param> |
365 |
/// <param name="e"></param> |
366 |
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) |
367 |
{ |
368 |
try |
369 |
{ |
370 |
App.FileLogger.Fatal(e.ExceptionObject as Exception); |
371 |
//App.DBLogger.Fatal(e.ExceptionObject as Exception); |
372 |
} |
373 |
catch (Exception ex) |
374 |
{ |
375 |
Console.WriteLine(ex.InnerException?.ToString()); |
376 |
} |
377 |
finally |
378 |
{ |
379 |
#if RELEASE |
380 |
Environment.Exit(0); |
381 |
#endif |
382 |
} |
383 |
} |
384 |
|
385 |
private void ErrorLogFileWrite(string Err) |
386 |
{ |
387 |
App.FileLogger.Debug(Err); |
388 |
} |
389 |
} |
390 |
} |