프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 6a19b48d

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

1 787a4489 KangIngu

2 af22332b ljiyeon
using KCOM.Common;
3 b60e844d taeseongkim
using KCOM.Views;
4 1305c420 taeseongkim
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
    /// <summary>
30
    /// App.xaml에 대한 상호 작용 논리
31
    /// </summary>
32
    public partial class App : Application
33
    {
34 eeb0a39c taeseongkim
        public static PageManager.PageStorage PageStorage;
35 a1e2ba68 taeseongkim
        public static string MarkusVersion = "";
36 76dc223b taeseongkim
        public static string BaseAddress;
37
        public static string FileUploadUri;
38 6a19b48d taeseongkim
        public static System.ServiceModel.Channels.Binding _binding;
39 787a4489 KangIngu
        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 84c48033 djkim
        public static bool isExternal = false;
51 787a4489 KangIngu
52 a7346d3c humkyung
        /// <summary>
53
        /// logger
54
        /// </summary>
55 ce3f0d7a humkyung
        public static ILog FileLogger = null;
56 902faaea taeseongkim
        
57
        public static StreamResourceInfo DefaultArrowCursor;
58
59
        public static Stream DefaultArrowCursorStream
60
        {
61
            get {
62 9d5b4bc2 taeseongkim
                return Application.GetResourceStream(new Uri(@"pack://application:,,,/Resources/Cursor/customCursor2.cur", UriKind.Absolute)).Stream;
63
                //DefaultArrowCursor.Stream.Position = 0;
64
                //return DefaultArrowCursor.Stream;
65 902faaea taeseongkim
            }
66
        }
67 a7346d3c humkyung
68 76dc223b taeseongkim
        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 a7346d3c humkyung
        /// <summary>
76 2089959a taeseongkim
        /// 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 a7346d3c humkyung
        /// 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 787a4489 KangIngu
105
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
106 1137be84 djkim
107 264c9309 ljiyeon
108 787a4489 KangIngu
        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 c4a4d59c ljiyeon
        private string versionPath = null;
121 cf2671a6 ljiyeon
        //public SplashScreen splash = new SplashScreen("splash.png");
122 e0cfc73c ljiyeon
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
123 cdfb57ff taeseongkim
124
        public App()
125
        {
126 aff63364 taeseongkim
            Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.VisualStudio2013Theme();
127 b60e844d taeseongkim
128
            App.FileLogger = LogManager.GetLogger(typeof(App));
129 cdfb57ff taeseongkim
        }
130
131 eeb0a39c taeseongkim
        protected override void OnExit(ExitEventArgs e)
132
        {
133 81908c01 taeseongkim
            try
134
            {
135
                if (App.PageStorage != null)
136
                {
137
                    App.PageStorage.Clear();
138
                }
139
            }
140
            catch (Exception)
141
            {
142
            }
143 eeb0a39c taeseongkim
144
            base.OnExit(e);
145
        }
146
147 cdfb57ff taeseongkim
        protected override async void OnStartup(StartupEventArgs e)
148
        {
149 787a4489 KangIngu
            try
150 a7346d3c humkyung
            {
151 902faaea taeseongkim
                DefaultArrowCursor = Application.GetResourceStream(new Uri(@"pack://application:,,,/Resources/Cursor/customCursor2.cur", UriKind.Absolute));
152
153 cf2671a6 ljiyeon
                splashScreen.Show();
154 1137be84 djkim
155 b60e844d taeseongkim
                App.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
156 a7346d3c humkyung
                /// up to here
157 b60e844d taeseongkim
                //AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
158 a7346d3c humkyung
159 1137be84 djkim
                #region  //  DNS 체크
160
161
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
162
163 8e6884a5 taeseongkim
                ViewerDataModel.Instance.IsDocumentHistory = Convert.ToBoolean(CommonLib.Common.GetConfigString("COMMON","IsDocumentHistory", "true"));
164
165 1137be84 djkim
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
166 df33d20a djkim
                
167 1137be84 djkim
                if (hostEntry == null)
168
                {
169
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
170 664ea2e1 taeseongkim
                    //App.FileLogger.Debug("hostEntry == null");
171 1137be84 djkim
                    isExternal = true;
172
                }
173 ddfd4bc7 djkim
                else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper()))
174 1137be84 djkim
                {
175
                    // 외부 사용자
176 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));
177 1137be84 djkim
                    isExternal = true;
178
                }
179
                #endregion
180
181 366f00c2 taeseongkim
182 787a4489 KangIngu
                if (e.Args.Count() > 0)
183
                {
184 c4a4d59c ljiyeon
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
185 787a4489 KangIngu
                    App.ViewInfo = new IKCOM.ViewInfo
186
                    {
187
                        DocumentItemID = result.DocumentItemID,
188 35afe17c djkim
                        EnsembleID = result.DocumentItemID,
189 787a4489 KangIngu
                        //DocumentItemID = "10001",
190
                        bPartner = result.bPartner,
191 bc664e9b djkim
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
192
                        NewCommentPermission = result.NewCommentPermission,
193 787a4489 KangIngu
                        ProjectNO = result.ProjectNO,
194
                        UserID = result.UserID,
195 9d5b4bc2 taeseongkim
                        isAdmin = Convert.ToBoolean(result.Mode)
196 787a4489 KangIngu
                        //UserID = "H2009115",
197 7cf8b728 taeseongkim
                        //Mode = result.Mode
198 787a4489 KangIngu
                    };
199 77cdac33 taeseongkim
                    ParameterMode = true; 
200 401a87f8 taeseongkim
                } 
201 c4a4d59c ljiyeon
                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 35afe17c djkim
                            EnsembleID = result.DocumentItemID,
211 c4a4d59c ljiyeon
                            //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 1137be84 djkim
                    }
222 1ed8da93 humkyung
                    else
223
                    {
224
                        MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내");
225
                        throw new ArgumentException("문서 정보가 입력되지 않았습니다.");
226
                    }
227 c4a4d59c ljiyeon
                }
228 992a98b4 KangIngu
229
                //App.ViewInfo.CreateFinalPDFPermission = false;
230
                //App.ViewInfo.NewCommentPermission = false;
231 c4a4d59c ljiyeon
                //GetQueryStringParameters();
232 a7578175 taeseongkim
                //_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 6a19b48d taeseongkim
                #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 787a4489 KangIngu
                //Support.SetLicense();
295 af22332b ljiyeon
296 84c48033 djkim
#if DEBUG
297 eb5cdefc djkim
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
298 566f0526 taeseongkim
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
299 76dc223b taeseongkim
                BaseAddress = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
300 992a98b4 KangIngu
#else
301 76dc223b taeseongkim
                BaseAddress = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
302 992a98b4 KangIngu
#endif
303 6a19b48d taeseongkim
                
304 76dc223b taeseongkim
                var UploadAddress = CommonLib.Common.GetConfigString("KCOM_kr_co_devdoftech_cloud_FileUpload", "URL", "");
305
306
                if (!string.IsNullOrWhiteSpace(UploadAddress) && !string.IsNullOrWhiteSpace(BaseAddress))
307
                {
308 6a19b48d taeseongkim
                    var uploadUri = new UriBuilder(UploadAddress);
309 76dc223b taeseongkim
                    var baseUri = new UriBuilder(BaseAddress);
310
311 6a19b48d taeseongkim
                    uploadUri.Host = baseUri.Host;
312
                    uploadUri.Port = baseUri.Port;
313 a1e2ba68 taeseongkim
314 6a19b48d taeseongkim
                    FileUploadUri = uploadUri.ToString();
315 76dc223b taeseongkim
                }
316
317 6a19b48d taeseongkim
                App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc/gzip", BaseAddress));
318 76dc223b taeseongkim
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", BaseAddress));
319 6a19b48d taeseongkim
                
320 77cdac33 taeseongkim
#if !DEBUG
321
#endif
322 a7bee7cf taeseongkim
                //var license = new License.Validator.Valid(BaseAddress + "/License");
323 1305c420 taeseongkim
324 a7bee7cf taeseongkim
                //license.ValidateError += License_ValidateError;
325 1305c420 taeseongkim
326 a7bee7cf taeseongkim
                //license.GetLicense("public.xml");
327 1305c420 taeseongkim
328 a7bee7cf taeseongkim
                //if (license.Activate())
329
                //{
330 77cdac33 taeseongkim
331 a7bee7cf taeseongkim
                //}
332
                //else
333
                //{
334 cf1cc862 taeseongkim
335 a7bee7cf taeseongkim
                //}
336 cf1cc862 taeseongkim
337 77cdac33 taeseongkim
338 cf1cc862 taeseongkim
                await SplashScreenAsnyc();
339
340
                base.OnStartup(e);
341
                System.Windows.Input.Keyboard.AddPreviewKeyDownHandler(this.MainWindow, KeyDownEvent);
342
343
344 1edefbdf taeseongkim
                //System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent);
345 787a4489 KangIngu
            }
346
            catch (Exception ex)
347
            {
348 274cde11 taeseongkim
                Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1);
349 787a4489 KangIngu
            }
350 f7e7a61a ljiyeon
            finally
351
            {
352 cdfb57ff taeseongkim
                await SplashScreenAsnyc();
353 1137be84 djkim
            }
354 787a4489 KangIngu
        }
355 a7346d3c humkyung
356 1305c420 taeseongkim
        private void License_ValidateError(object sender, ValidateErrorArgs e)
357
        {
358
            e.Received = true;
359
360 cf1cc862 taeseongkim
            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 1305c420 taeseongkim
            Application.Current.Shutdown();
367
        }
368
369 b60e844d taeseongkim
        private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
370
        {
371 766cdfa1 taeseongkim
            Logger.sendReqLog("App Error ",e.Exception.ToString() + " " + e.Exception.InnerException?.ToString(), 1);
372 b60e844d taeseongkim
        }
373
374 fa48eb85 taeseongkim
        private void KeyDownEvent(object sender, KeyEventArgs e)
375
        {
376 8e6884a5 taeseongkim
            //if (e.Key == Key.Escape || e.Key == Key.Delete)
377
            //{
378 fa48eb85 taeseongkim
                System.Diagnostics.Debug.WriteLine("app key Event");
379
                Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e);
380 8e6884a5 taeseongkim
            //}
381 fa48eb85 taeseongkim
        }
382
383 cdfb57ff taeseongkim
        private async Task<bool> SplashScreenAsnyc()
384
        {
385
            int value = 100 / ISplashMessage.SplashMessageCnt;
386
387
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
388
            {
389 d33ef543 taeseongkim
                await Task.Delay(3);
390 cdfb57ff taeseongkim
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
391
            }
392
393 2007ecaa taeseongkim
            //splashScreen.Close();
394 cdfb57ff taeseongkim
395
            return true;
396
        }
397
398 e0cfc73c ljiyeon
        public static void splashString(string text)
399
        {
400
            Task.Factory.StartNew(() =>
401
            {
402
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
403 2917ab4a taeseongkim
            }).ConfigureAwait(false);
404 e0cfc73c ljiyeon
        }
405
406
407 a7346d3c humkyung
        /// <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 360e4f75 djkim
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
419 a7346d3c humkyung
            }
420
            catch (Exception ex)
421
            {
422 8614f701 taeseongkim
                Console.WriteLine(ex.InnerException?.ToString());
423 a7346d3c humkyung
            }
424
            finally
425
            {
426 8614f701 taeseongkim
#if RELEASE
427 a7346d3c humkyung
                Environment.Exit(0);
428 8614f701 taeseongkim
#endif
429 a7346d3c humkyung
            }
430
        }
431
432 c4a4d59c ljiyeon
        private void ErrorLogFileWrite(string Err)
433
        {
434 ce3f0d7a humkyung
            App.FileLogger.Debug(Err);
435 c4a4d59c ljiyeon
        }
436 787a4489 KangIngu
    }
437
}
클립보드 이미지 추가 (최대 크기: 500 MB)