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