프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / App.xaml.cs @ 26c9c3bf

이력 | 보기 | 이력해설 | 다운로드 (18.6 KB)

1 787a4489 KangIngu

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