프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ b627aa5a

이력 | 보기 | 이력해설 | 다운로드 (16.8 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 45ac2822 taeseongkim
                //basicHttpBinding.ProxyAddress = null;
255 5c64268e taeseongkim
                //basicHttpBinding.AllowCookies = false;
256
                //basicHttpBinding.BypassProxyOnLocal = false;
257 6a19b48d taeseongkim
                //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 787a4489 KangIngu
                //Support.SetLicense();
296 af22332b ljiyeon
297 84c48033 djkim
#if DEBUG
298 eb5cdefc djkim
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
299 566f0526 taeseongkim
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
300 76dc223b taeseongkim
                BaseAddress = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
301 992a98b4 KangIngu
#else
302 76dc223b taeseongkim
                BaseAddress = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
303 992a98b4 KangIngu
#endif
304 6a19b48d taeseongkim
                
305 76dc223b taeseongkim
                var UploadAddress = CommonLib.Common.GetConfigString("KCOM_kr_co_devdoftech_cloud_FileUpload", "URL", "");
306
307
                if (!string.IsNullOrWhiteSpace(UploadAddress) && !string.IsNullOrWhiteSpace(BaseAddress))
308
                {
309 6a19b48d taeseongkim
                    var uploadUri = new UriBuilder(UploadAddress);
310 76dc223b taeseongkim
                    var baseUri = new UriBuilder(BaseAddress);
311
312 6a19b48d taeseongkim
                    uploadUri.Host = baseUri.Host;
313
                    uploadUri.Port = baseUri.Port;
314 a1e2ba68 taeseongkim
315 6a19b48d taeseongkim
                    FileUploadUri = uploadUri.ToString();
316 76dc223b taeseongkim
                }
317
318 6a19b48d taeseongkim
                App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc/gzip", BaseAddress));
319 76dc223b taeseongkim
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", BaseAddress));
320 6a19b48d taeseongkim
                
321 77cdac33 taeseongkim
#if !DEBUG
322
#endif
323 a7bee7cf taeseongkim
                //var license = new License.Validator.Valid(BaseAddress + "/License");
324 1305c420 taeseongkim
325 a7bee7cf taeseongkim
                //license.ValidateError += License_ValidateError;
326 1305c420 taeseongkim
327 a7bee7cf taeseongkim
                //license.GetLicense("public.xml");
328 1305c420 taeseongkim
329 a7bee7cf taeseongkim
                //if (license.Activate())
330
                //{
331 77cdac33 taeseongkim
332 a7bee7cf taeseongkim
                //}
333
                //else
334
                //{
335 cf1cc862 taeseongkim
336 a7bee7cf taeseongkim
                //}
337 cf1cc862 taeseongkim
338 77cdac33 taeseongkim
339 cf1cc862 taeseongkim
                await SplashScreenAsnyc();
340
341
                base.OnStartup(e);
342
                System.Windows.Input.Keyboard.AddPreviewKeyDownHandler(this.MainWindow, KeyDownEvent);
343
344
345 1edefbdf taeseongkim
                //System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent);
346 787a4489 KangIngu
            }
347
            catch (Exception ex)
348
            {
349 274cde11 taeseongkim
                Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1);
350 787a4489 KangIngu
            }
351 f7e7a61a ljiyeon
            finally
352
            {
353 cdfb57ff taeseongkim
                await SplashScreenAsnyc();
354 1137be84 djkim
            }
355 787a4489 KangIngu
        }
356 a7346d3c humkyung
357 1305c420 taeseongkim
        private void License_ValidateError(object sender, ValidateErrorArgs e)
358
        {
359
            e.Received = true;
360
361 cf1cc862 taeseongkim
            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 1305c420 taeseongkim
            Application.Current.Shutdown();
368
        }
369
370 b60e844d taeseongkim
        private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
371
        {
372 766cdfa1 taeseongkim
            Logger.sendReqLog("App Error ",e.Exception.ToString() + " " + e.Exception.InnerException?.ToString(), 1);
373 b60e844d taeseongkim
        }
374
375 fa48eb85 taeseongkim
        private void KeyDownEvent(object sender, KeyEventArgs e)
376
        {
377 8e6884a5 taeseongkim
            //if (e.Key == Key.Escape || e.Key == Key.Delete)
378
            //{
379 fa48eb85 taeseongkim
                System.Diagnostics.Debug.WriteLine("app key Event");
380
                Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e);
381 8e6884a5 taeseongkim
            //}
382 fa48eb85 taeseongkim
        }
383
384 cdfb57ff taeseongkim
        private async Task<bool> SplashScreenAsnyc()
385
        {
386
            int value = 100 / ISplashMessage.SplashMessageCnt;
387
388
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
389
            {
390 d33ef543 taeseongkim
                await Task.Delay(3);
391 cdfb57ff taeseongkim
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
392
            }
393
394 2007ecaa taeseongkim
            //splashScreen.Close();
395 cdfb57ff taeseongkim
396
            return true;
397
        }
398
399 e0cfc73c ljiyeon
        public static void splashString(string text)
400
        {
401
            Task.Factory.StartNew(() =>
402
            {
403
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
404 2917ab4a taeseongkim
            }).ConfigureAwait(false);
405 e0cfc73c ljiyeon
        }
406
407
408 a7346d3c humkyung
        /// <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 360e4f75 djkim
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
420 a7346d3c humkyung
            }
421
            catch (Exception ex)
422
            {
423 8614f701 taeseongkim
                Console.WriteLine(ex.InnerException?.ToString());
424 a7346d3c humkyung
            }
425
            finally
426
            {
427 8614f701 taeseongkim
#if RELEASE
428 a7346d3c humkyung
                Environment.Exit(0);
429 8614f701 taeseongkim
#endif
430 a7346d3c humkyung
            }
431
        }
432
433 c4a4d59c ljiyeon
        private void ErrorLogFileWrite(string Err)
434
        {
435 ce3f0d7a humkyung
            App.FileLogger.Debug(Err);
436 c4a4d59c ljiyeon
        }
437 787a4489 KangIngu
    }
438
}
클립보드 이미지 추가 (최대 크기: 500 MB)