markus / KCOM / App.xaml.cs @ b627aa5a
이력 | 보기 | 이력해설 | 다운로드 (16.8 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.ProxyAddress = null; |
255 |
//basicHttpBinding.AllowCookies = false; |
256 |
//basicHttpBinding.BypassProxyOnLocal = false; |
257 |
//basicHttpBinding.UseDefaultWebProxy = false; |
258 |
//basicHttpBinding.ProxyAddress = new Uri("Http://localhost:8888"); |
259 |
|
260 |
_binding = basicHttpBinding; |
261 |
|
262 |
#endregion |
263 |
|
264 |
#region custombinding |
265 |
//var customBinding = new System.ServiceModel.Channels.CustomBinding() |
266 |
//{ |
267 |
// OpenTimeout = new TimeSpan(0, 15, 0), |
268 |
// ReceiveTimeout = new TimeSpan(0, 15, 0), |
269 |
// CloseTimeout = new TimeSpan(0, 15, 0), |
270 |
// SendTimeout = new TimeSpan(0, 15, 0), |
271 |
//}; |
272 |
|
273 |
//var messageEncoding = new WcfExtensions.ServiceModel.Channels.CompressionBindingElement(); |
274 |
//messageEncoding.Level = WcfExtensions.ServiceModel.Channels.CompressionLevel.Fast; |
275 |
|
276 |
//var httpTranport = new System.ServiceModel.Channels.HttpTransportBindingElement |
277 |
//{ |
278 |
// MaxBufferPoolSize = Int32.MaxValue, |
279 |
// MaxBufferSize = Int32.MaxValue, |
280 |
// MaxReceivedMessageSize = Int32.MaxValue, |
281 |
// RequestInitializationTimeout = new TimeSpan(0, 10, 0), |
282 |
// UseDefaultWebProxy = false, |
283 |
// ProxyAddress = new Uri("Http://127.0.0.1:8888") |
284 |
//}; |
285 |
|
286 |
|
287 |
//customBinding.CreateBindingElements(); |
288 |
//customBinding.Elements.Add(messageEncoding); |
289 |
//customBinding.Elements.Add(httpTranport); |
290 |
|
291 |
|
292 |
//_binding = customBinding; |
293 |
#endregion |
294 |
|
295 |
//Support.SetLicense(); |
296 |
|
297 |
#if DEBUG |
298 |
//sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
299 |
System.Diagnostics.Debug.WriteLine("sBaseServiceURL"); |
300 |
BaseAddress = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
301 |
#else |
302 |
BaseAddress = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
303 |
#endif |
304 |
|
305 |
var UploadAddress = CommonLib.Common.GetConfigString("KCOM_kr_co_devdoftech_cloud_FileUpload", "URL", ""); |
306 |
|
307 |
if (!string.IsNullOrWhiteSpace(UploadAddress) && !string.IsNullOrWhiteSpace(BaseAddress)) |
308 |
{ |
309 |
var uploadUri = new UriBuilder(UploadAddress); |
310 |
var baseUri = new UriBuilder(BaseAddress); |
311 |
|
312 |
uploadUri.Host = baseUri.Host; |
313 |
uploadUri.Port = baseUri.Port; |
314 |
|
315 |
FileUploadUri = uploadUri.ToString(); |
316 |
} |
317 |
|
318 |
App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc/gzip", BaseAddress)); |
319 |
_EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", BaseAddress)); |
320 |
|
321 |
#if !DEBUG |
322 |
#endif |
323 |
//var license = new License.Validator.Valid(BaseAddress + "/License"); |
324 |
|
325 |
//license.ValidateError += License_ValidateError; |
326 |
|
327 |
//license.GetLicense("public.xml"); |
328 |
|
329 |
//if (license.Activate()) |
330 |
//{ |
331 |
|
332 |
//} |
333 |
//else |
334 |
//{ |
335 |
|
336 |
//} |
337 |
|
338 |
|
339 |
await SplashScreenAsnyc(); |
340 |
|
341 |
base.OnStartup(e); |
342 |
System.Windows.Input.Keyboard.AddPreviewKeyDownHandler(this.MainWindow, KeyDownEvent); |
343 |
|
344 |
|
345 |
//System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent); |
346 |
} |
347 |
catch (Exception ex) |
348 |
{ |
349 |
Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1); |
350 |
} |
351 |
finally |
352 |
{ |
353 |
await SplashScreenAsnyc(); |
354 |
} |
355 |
} |
356 |
|
357 |
private void License_ValidateError(object sender, ValidateErrorArgs e) |
358 |
{ |
359 |
e.Received = true; |
360 |
|
361 |
Telerik.Windows.Controls.RadWindow.Alert(new Telerik.Windows.Controls.DialogParameters |
362 |
{ |
363 |
Content = "License Error : " + e.Message, |
364 |
Owner = splashScreen |
365 |
}); |
366 |
///MessageBox.Show(e.Message); |
367 |
Application.Current.Shutdown(); |
368 |
} |
369 |
|
370 |
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) |
371 |
{ |
372 |
Logger.sendReqLog("App Error ",e.Exception.ToString() + " " + e.Exception.InnerException?.ToString(), 1); |
373 |
} |
374 |
|
375 |
private void KeyDownEvent(object sender, KeyEventArgs e) |
376 |
{ |
377 |
//if (e.Key == Key.Escape || e.Key == Key.Delete) |
378 |
//{ |
379 |
System.Diagnostics.Debug.WriteLine("app key Event"); |
380 |
Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e); |
381 |
//} |
382 |
} |
383 |
|
384 |
private async Task<bool> SplashScreenAsnyc() |
385 |
{ |
386 |
int value = 100 / ISplashMessage.SplashMessageCnt; |
387 |
|
388 |
for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++) |
389 |
{ |
390 |
await Task.Delay(3); |
391 |
await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value); |
392 |
} |
393 |
|
394 |
//splashScreen.Close(); |
395 |
|
396 |
return true; |
397 |
} |
398 |
|
399 |
public static void splashString(string text) |
400 |
{ |
401 |
Task.Factory.StartNew(() => |
402 |
{ |
403 |
splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text); |
404 |
}).ConfigureAwait(false); |
405 |
} |
406 |
|
407 |
|
408 |
/// <summary> |
409 |
/// log unhandled exception |
410 |
/// </summary> |
411 |
/// <author>humkyung</author> |
412 |
/// <date>2019.05.21</date> |
413 |
/// <param name="sender"></param> |
414 |
/// <param name="e"></param> |
415 |
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) |
416 |
{ |
417 |
try |
418 |
{ |
419 |
App.FileLogger.Fatal(e.ExceptionObject as Exception); |
420 |
} |
421 |
catch (Exception ex) |
422 |
{ |
423 |
Console.WriteLine(ex.InnerException?.ToString()); |
424 |
} |
425 |
finally |
426 |
{ |
427 |
#if RELEASE |
428 |
Environment.Exit(0); |
429 |
#endif |
430 |
} |
431 |
} |
432 |
|
433 |
private void ErrorLogFileWrite(string Err) |
434 |
{ |
435 |
App.FileLogger.Debug(Err); |
436 |
} |
437 |
} |
438 |
} |