markus / KCOM / App.xaml.cs @ a197bf6f
이력 | 보기 | 이력해설 | 다운로드 (18.6 KB)
1 |
|
---|---|
2 |
using KCOM.Common; |
3 |
using KCOM.Views; |
4 |
///using License.Validator; |
5 |
using log4net; |
6 |
using System; |
7 |
using System.ComponentModel; |
8 |
using System.IO; |
9 |
using System.Linq; |
10 |
using System.Net; |
11 |
using System.ServiceModel; |
12 |
using System.Threading.Tasks; |
13 |
using System.Windows; |
14 |
using System.Windows.Input; |
15 |
using System.Windows.Resources; |
16 |
|
17 |
namespace KCOM |
18 |
{ |
19 |
public class OpenProperties |
20 |
{ |
21 |
public string DocumentItemID { get; set; } |
22 |
public bool bPartner { get; set; } |
23 |
public bool CreateFinalPDFPermission { get; set; } |
24 |
public bool NewCommentPermission { get; set; } |
25 |
public string ProjectNO { get; set; } |
26 |
public string UserID { get; set; } |
27 |
public int Mode { get; set; } |
28 |
} |
29 |
|
30 |
/// <summary> |
31 |
/// App.xaml에 대한 상호 작용 논리 |
32 |
/// </summary> |
33 |
public partial class App : Application |
34 |
{ |
35 |
public static PageManager.PageStorage PageStorage; |
36 |
public static string MarkusVersion = ""; |
37 |
public static string BaseAddress; |
38 |
public static string FileUploadUri; |
39 |
public static System.ServiceModel.Channels.Binding _binding; |
40 |
public static EndpointAddress _EndPoint; |
41 |
public static EndpointAddress _EndPoint_SaveLoad; |
42 |
public static EndpointAddress _EndPoint_Symbol; |
43 |
public static string UserName; |
44 |
public static IKCOM.ViewInfo ViewInfo; |
45 |
|
46 |
public static string urlHost; |
47 |
public static string urlPort; |
48 |
public static string urlHost_DB; |
49 |
public static string urlPort_DB; |
50 |
|
51 |
/// <summary> |
52 |
/// 현재 활성화된 MarkupInfo의 Id |
53 |
/// </summary> |
54 |
public static string Custom_ViewInfoId { get; set; } |
55 |
|
56 |
public static bool ParameterMode = false; |
57 |
public static bool isExternal = false; |
58 |
public static bool isAuthenticate = false; |
59 |
public static string AuthenticateToken = null; |
60 |
|
61 |
/// <summary> |
62 |
/// logger |
63 |
/// </summary> |
64 |
public static ILog FileLogger = null; |
65 |
|
66 |
public static StreamResourceInfo DefaultArrowCursor; |
67 |
|
68 |
public static Stream DefaultArrowCursorStream |
69 |
{ |
70 |
get { |
71 |
return Application.GetResourceStream(new Uri(@"pack://application:,,,/Resources/Cursor/customCursor2.cur", UriKind.Absolute)).Stream; |
72 |
//DefaultArrowCursor.Stream.Position = 0; |
73 |
//return DefaultArrowCursor.Stream; |
74 |
} |
75 |
} |
76 |
|
77 |
public static kr.co.devdoftech.cloud.FileUpload FileUploader |
78 |
{ |
79 |
get { return new kr.co.devdoftech.cloud.FileUpload{ Url = FileUploadUri }; } |
80 |
|
81 |
private set {; } |
82 |
} |
83 |
|
84 |
/// <summary> |
85 |
/// VisualStudio Design Time여부 |
86 |
/// </summary> |
87 |
public static bool IsDesignMode |
88 |
{ |
89 |
get |
90 |
{ |
91 |
try |
92 |
{ |
93 |
return DesignerProperties.GetIsInDesignMode(new DependencyObject()); |
94 |
} |
95 |
catch (Exception) |
96 |
{ |
97 |
return false; |
98 |
} |
99 |
} |
100 |
private set { } |
101 |
} |
102 |
|
103 |
/// <summary> |
104 |
/// Application Data Folder |
105 |
/// </summary> |
106 |
public static string AppDataFolder |
107 |
{ |
108 |
get |
109 |
{ |
110 |
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS"); |
111 |
} |
112 |
} |
113 |
|
114 |
public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; } |
115 |
|
116 |
public static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null) |
117 |
{ |
118 |
if (oEncoding == null) |
119 |
oEncoding = System.Text.Encoding.UTF8; |
120 |
|
121 |
byte[] byteArray = Convert.FromBase64String(DecodingText); |
122 |
|
123 |
string jsonBack = oEncoding.GetString(byteArray); |
124 |
|
125 |
return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack); |
126 |
} |
127 |
|
128 |
private string versionPath = null; |
129 |
public static SplashScreenWindow splashScreen { get; } = new SplashScreenWindow(); |
130 |
|
131 |
public App() |
132 |
{ |
133 |
Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.VisualStudio2013Theme(); |
134 |
|
135 |
App.FileLogger = LogManager.GetLogger(typeof(App)); |
136 |
} |
137 |
|
138 |
protected override void OnExit(ExitEventArgs e) |
139 |
{ |
140 |
try |
141 |
{ |
142 |
if (App.PageStorage != null) |
143 |
{ |
144 |
App.PageStorage.Clear(); |
145 |
} |
146 |
} |
147 |
catch (Exception) |
148 |
{ |
149 |
} |
150 |
|
151 |
base.OnExit(e); |
152 |
} |
153 |
|
154 |
protected override async void OnStartup(StartupEventArgs e) |
155 |
{ |
156 |
try |
157 |
{ |
158 |
DefaultArrowCursor = Application.GetResourceStream(new Uri(@"pack://application:,,,/Resources/Cursor/customCursor2.cur", UriKind.Absolute)); |
159 |
|
160 |
splashScreen.Show(); |
161 |
|
162 |
App.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException; |
163 |
/// up to here |
164 |
//AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |
165 |
|
166 |
#region // DNS 체크 |
167 |
|
168 |
string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", ""); |
169 |
|
170 |
ViewerDataModel.Instance.IsDocumentHistory = Convert.ToBoolean(CommonLib.Common.GetConfigString("COMMON","IsDocumentHistory", "true")); |
171 |
|
172 |
var hostEntry = CommonLib.DNSHelper.GetHostEntryTask(); |
173 |
|
174 |
if (hostEntry == null) |
175 |
{ |
176 |
System.Diagnostics.Debug.WriteLine("(hostEntry == null"); |
177 |
//App.FileLogger.Debug("hostEntry == null"); |
178 |
isExternal = true; |
179 |
} |
180 |
else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper())) |
181 |
{ |
182 |
// 외부 사용자 |
183 |
App.FileLogger.Debug(string.Format("You are external user because located out side of given domain({0})\nYour domain is {1}", localdomain, hostEntry.HostName)); |
184 |
isExternal = true; |
185 |
} |
186 |
#endregion |
187 |
|
188 |
|
189 |
if (e.Args.Any()) |
190 |
{ |
191 |
var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
192 |
#if DEBUG |
193 |
/* |
194 |
ViewerDataModel.Instance.IsDocumentHistory = true; |
195 |
result.DocumentItemID = "3712215963"; |
196 |
result.ProjectNO = "00000"; |
197 |
result.UserID = "P190111_qa03"; |
198 |
result.CreateFinalPDFPermission = false; |
199 |
result.NewCommentPermission = true; |
200 |
|
201 |
//doftech |
202 |
* humkyung |
203 |
P190111_qa03 |
204 |
P190111_qa04 |
205 |
P190111_sa03 |
206 |
P190111_sa04 |
207 |
P190111_sa05 |
208 |
user1 |
209 |
*/ |
210 |
#endif |
211 |
|
212 |
App.ViewInfo = new IKCOM.ViewInfo |
213 |
{ |
214 |
DocumentItemID = result.DocumentItemID, |
215 |
EnsembleID = result.DocumentItemID, |
216 |
//DocumentItemID = "10001", |
217 |
bPartner = result.bPartner, |
218 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
219 |
NewCommentPermission = result.NewCommentPermission, |
220 |
ProjectNO = result.ProjectNO, |
221 |
UserID = result.UserID, |
222 |
isAdmin = Convert.ToBoolean(result.Mode) |
223 |
//UserID = "H2009115", |
224 |
//Mode = result.Mode |
225 |
}; |
226 |
ParameterMode = true; |
227 |
} |
228 |
else |
229 |
{ |
230 |
string[] strArg = Environment.GetCommandLineArgs(); |
231 |
if (strArg.Length > 1) |
232 |
{ |
233 |
var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", "")); |
234 |
App.ViewInfo = new IKCOM.ViewInfo |
235 |
{ |
236 |
DocumentItemID = result.DocumentItemID, |
237 |
EnsembleID = result.DocumentItemID, |
238 |
//DocumentItemID = "10001", |
239 |
bPartner = result.bPartner, |
240 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
241 |
NewCommentPermission = result.NewCommentPermission, |
242 |
ProjectNO = result.ProjectNO, |
243 |
UserID = result.UserID, |
244 |
//UserID = "H2009115", |
245 |
//Mode = 0 , 1 , 2 |
246 |
}; |
247 |
ParameterMode = true; |
248 |
} |
249 |
else |
250 |
{ |
251 |
MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내"); |
252 |
throw new ArgumentException("문서 정보가 입력되지 않았습니다."); |
253 |
} |
254 |
} |
255 |
|
256 |
BaseAddress = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
257 |
_EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", BaseAddress)); |
258 |
|
259 |
if (_EndPoint.Uri.Scheme == Uri.UriSchemeHttps) |
260 |
{ |
261 |
#region custombinding |
262 |
var customBinding = new System.ServiceModel.Channels.CustomBinding() |
263 |
{ |
264 |
OpenTimeout = new TimeSpan(0, 30, 0), |
265 |
ReceiveTimeout = new TimeSpan(0, 30, 0), |
266 |
CloseTimeout = new TimeSpan(0, 30, 0), |
267 |
SendTimeout = new TimeSpan(0, 30, 0), |
268 |
}; |
269 |
|
270 |
//var messageEncoding = new WcfExtensions.ServiceModel.Channels.CompressionBindingElement(); |
271 |
//messageEncoding.Level = WcfExtensions.ServiceModel.Channels.CompressionLevel.Maximum; |
272 |
|
273 |
var httpTranport = new System.ServiceModel.Channels.HttpsTransportBindingElement |
274 |
{ |
275 |
MaxBufferPoolSize = Int32.MaxValue, |
276 |
MaxBufferSize = Int32.MaxValue, |
277 |
MaxReceivedMessageSize = Int32.MaxValue, |
278 |
RequestInitializationTimeout = new TimeSpan(0, 30, 0), |
279 |
//UseDefaultWebProxy = false, |
280 |
//ProxyAddress = new Uri("Http://127.0.0.1:8888") |
281 |
}; |
282 |
|
283 |
customBinding.CreateBindingElements(); |
284 |
|
285 |
var reliableSession = new System.ServiceModel.Channels.ReliableSessionBindingElement(); |
286 |
|
287 |
var encoding = new System.ServiceModel.Channels.TextMessageEncodingBindingElement |
288 |
{ |
289 |
MaxReadPoolSize = Int32.MaxValue, |
290 |
MaxWritePoolSize = Int32.MaxValue, |
291 |
MessageVersion = System.ServiceModel.Channels.MessageVersion.Soap12WSAddressing10, |
292 |
WriteEncoding = System.Text.Encoding.UTF8, |
293 |
ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas |
294 |
{ |
295 |
MaxArrayLength = Int32.MaxValue, |
296 |
MaxBytesPerRead = Int32.MaxValue, |
297 |
MaxDepth = Int32.MaxValue, |
298 |
MaxNameTableCharCount = Int32.MaxValue, |
299 |
MaxStringContentLength = Int32.MaxValue |
300 |
} |
301 |
}; |
302 |
//reliableSession.Ordered = true; // Set other properties as needed |
303 |
customBinding.Elements.Add(reliableSession); |
304 |
//customBinding.Elements.Add(messageEncoding); |
305 |
//customBinding.Elements.Add(encoding); |
306 |
customBinding.Elements.Add(httpTranport); |
307 |
|
308 |
_binding = customBinding; |
309 |
#endregion |
310 |
} |
311 |
else |
312 |
{ |
313 |
#region 기본 binding |
314 |
BasicHttpBinding basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.None); |
315 |
basicHttpBinding.Security = new BasicHttpSecurity { Transport = new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.None, ProxyCredentialType = HttpProxyCredentialType.None }, Mode = BasicHttpSecurityMode.None, Message = new BasicHttpMessageSecurity { AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Basic256, ClientCredentialType = BasicHttpMessageCredentialType.UserName } }; |
316 |
basicHttpBinding.MaxBufferSize = 2147483647; |
317 |
basicHttpBinding.MaxBufferPoolSize = 2147483647; |
318 |
basicHttpBinding.MaxReceivedMessageSize = 2147483647; |
319 |
basicHttpBinding.OpenTimeout = new TimeSpan(4, 30, 0); |
320 |
basicHttpBinding.ReceiveTimeout = new TimeSpan(4, 30, 0); |
321 |
basicHttpBinding.CloseTimeout = new TimeSpan(4, 30, 0); |
322 |
basicHttpBinding.SendTimeout = new TimeSpan(4, 30, 0); |
323 |
basicHttpBinding.TextEncoding = System.Text.Encoding.UTF8; |
324 |
basicHttpBinding.TransferMode = TransferMode.Buffered; |
325 |
basicHttpBinding.MessageEncoding = WSMessageEncoding.Text; |
326 |
basicHttpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; |
327 |
|
328 |
_binding = basicHttpBinding; |
329 |
#endregion |
330 |
} |
331 |
|
332 |
if (isAuthenticate) |
333 |
{ |
334 |
App.AuthenticateToken = Authenticate(BaseAddress); |
335 |
} |
336 |
|
337 |
var UploadAddress = CommonLib.Common.GetConfigString("KCOM_kr_co_devdoftech_cloud_FileUpload", "URL", ""); |
338 |
|
339 |
if (!string.IsNullOrWhiteSpace(UploadAddress) && !string.IsNullOrWhiteSpace(BaseAddress)) |
340 |
{ |
341 |
var uploadUri = new UriBuilder(UploadAddress); |
342 |
var baseUri = new UriBuilder(BaseAddress); |
343 |
|
344 |
uploadUri.Host = baseUri.Host; |
345 |
uploadUri.Port = baseUri.Port; |
346 |
|
347 |
FileUploadUri = uploadUri.ToString(); |
348 |
} |
349 |
|
350 |
App.FileLogger.Debug(_EndPoint.Uri); |
351 |
#if !DEBUG |
352 |
#endif |
353 |
//var license = new License.Validator.Valid(BaseAddress + "/License"); |
354 |
//license.ValidateError += License_ValidateError; |
355 |
//license.GetLicense("public.xml"); |
356 |
//if (license.Activate()) |
357 |
//{ |
358 |
//} |
359 |
//else |
360 |
//{ |
361 |
//} |
362 |
|
363 |
await SplashScreenAsnyc(); |
364 |
|
365 |
base.OnStartup(e); |
366 |
System.Windows.Input.Keyboard.AddPreviewKeyDownHandler(this.MainWindow, KeyDownEvent); |
367 |
|
368 |
|
369 |
//System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent); |
370 |
} |
371 |
catch (Exception ex) |
372 |
{ |
373 |
Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1); |
374 |
} |
375 |
finally |
376 |
{ |
377 |
await SplashScreenAsnyc(); |
378 |
} |
379 |
} |
380 |
|
381 |
|
382 |
private string Authenticate(string baseUri) |
383 |
{ |
384 |
string result = null; |
385 |
|
386 |
try |
387 |
{ |
388 |
Uri uri = new Uri(baseUri); |
389 |
string baseUrl = uri.Scheme + "://" + uri.Host + (uri.IsDefaultPort ? "" : ":" + uri.Port); |
390 |
|
391 |
using (System.Net.WebClient client = new System.Net.WebClient()) |
392 |
{ |
393 |
client.Headers.Add(HttpRequestHeader.Authorization, "!dsfadsfa@@~"); |
394 |
var response = client.DownloadString(baseUrl + "/Authenticate"); |
395 |
|
396 |
if (response != null) |
397 |
{ |
398 |
result = response; |
399 |
} |
400 |
} |
401 |
} |
402 |
catch (Exception) |
403 |
{ |
404 |
|
405 |
throw; |
406 |
} |
407 |
|
408 |
return result; |
409 |
} |
410 |
|
411 |
/*private void License_ValidateError(object sender, ValidateErrorArgs e) |
412 |
{ |
413 |
e.Received = true; |
414 |
|
415 |
Telerik.Windows.Controls.RadWindow.Alert(new Telerik.Windows.Controls.DialogParameters |
416 |
{ |
417 |
Content = "License Error : " + e.Message, |
418 |
Owner = splashScreen |
419 |
}); |
420 |
///MessageBox.Show(e.Message); |
421 |
Application.Current.Shutdown(); |
422 |
} |
423 |
*/ |
424 |
|
425 |
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) |
426 |
{ |
427 |
Logger.sendReqLog("App Error ",e.Exception.ToString() + " " + e.Exception.InnerException?.ToString(), 1); |
428 |
} |
429 |
|
430 |
private void KeyDownEvent(object sender, KeyEventArgs e) |
431 |
{ |
432 |
//if (e.Key == Key.Escape || e.Key == Key.Delete) |
433 |
//{ |
434 |
System.Diagnostics.Debug.WriteLine("app key Event"); |
435 |
Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e); |
436 |
//} |
437 |
} |
438 |
|
439 |
private async Task<bool> SplashScreenAsnyc() |
440 |
{ |
441 |
int value = 100 / ISplashMessage.SplashMessageCnt; |
442 |
|
443 |
for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++) |
444 |
{ |
445 |
await Task.Delay(1); |
446 |
await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value); |
447 |
} |
448 |
|
449 |
//splashScreen.Close(); |
450 |
|
451 |
return true; |
452 |
} |
453 |
|
454 |
public static void splashString(string text) |
455 |
{ |
456 |
Task.Factory.StartNew(() => |
457 |
{ |
458 |
splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text); |
459 |
}).ConfigureAwait(false); |
460 |
} |
461 |
|
462 |
|
463 |
/// <summary> |
464 |
/// log unhandled exception |
465 |
/// </summary> |
466 |
/// <author>humkyung</author> |
467 |
/// <date>2019.05.21</date> |
468 |
/// <param name="sender"></param> |
469 |
/// <param name="e"></param> |
470 |
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) |
471 |
{ |
472 |
try |
473 |
{ |
474 |
App.FileLogger.Fatal(e.ExceptionObject as Exception); |
475 |
} |
476 |
catch (Exception ex) |
477 |
{ |
478 |
Console.WriteLine(ex.InnerException?.ToString()); |
479 |
} |
480 |
finally |
481 |
{ |
482 |
#if RELEASE |
483 |
Environment.Exit(0); |
484 |
#endif |
485 |
} |
486 |
} |
487 |
|
488 |
private void ErrorLogFileWrite(string Err) |
489 |
{ |
490 |
App.FileLogger.Debug(Err); |
491 |
} |
492 |
} |
493 |
} |