프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 95c73392

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

1

2
using KCOM.Common;
3
using KCOM.Views;
4
using log4net;
5
using System;
6
using System.ComponentModel;
7
using System.IO;
8
using System.Linq;
9
using System.Net;
10
using System.ServiceModel;
11
using System.Threading.Tasks;
12
using System.Windows;
13
using System.Windows.Input;
14
using System.Windows.Resources;
15

    
16
namespace KCOM
17
{
18
    public class OpenProperties
19
    {
20
        public string DocumentItemID { get; set; }
21
        public bool bPartner { get; set; }
22
        public bool CreateFinalPDFPermission { get; set; }
23
        public bool NewCommentPermission { get; set; }
24
        public string ProjectNO { get; set; }
25
        public string UserID { get; set; }
26
        public int Mode { get; set; }
27
    }
28
    /// <summary>
29
    /// App.xaml에 대한 상호 작용 논리
30
    /// </summary>
31
    public partial class App : Application
32
    {
33
        public static PageManager.PageStorage PageStorage;
34
        public static string MarkusVersion = "";
35
        public static string BaseAddress;
36
        public static string FileUploadUri;
37
        public static System.ServiceModel.Channels.Binding _binding;
38
        public static EndpointAddress _EndPoint;
39
        public static EndpointAddress _EndPoint_SaveLoad;
40
        public static EndpointAddress _EndPoint_Symbol;
41
        public static string UserName;
42
        public static IKCOM.ViewInfo ViewInfo;
43
        public static string urlHost;
44
        public static string urlPort;
45
        public static string urlHost_DB;
46
        public static string urlPort_DB;
47
        public static string Custom_ViewInfoId;
48
        public static bool ParameterMode = false;
49
        public static bool isExternal = false;
50

    
51
        /// <summary>
52
        /// logger
53
        /// </summary>
54
        public static ILog FileLogger = null;
55
        
56
        public static StreamResourceInfo DefaultArrowCursor;
57

    
58
        public static Stream DefaultArrowCursorStream
59
        {
60
            get {
61
                return Application.GetResourceStream(new Uri(@"pack://application:,,,/Resources/Cursor/customCursor2.cur", UriKind.Absolute)).Stream;
62
                //DefaultArrowCursor.Stream.Position = 0;
63
                //return DefaultArrowCursor.Stream;
64
            }
65
        }
66

    
67
        public static kr.co.devdoftech.cloud.FileUpload FileUploader
68
        {
69
            get { return new kr.co.devdoftech.cloud.FileUpload{ Url = FileUploadUri }; }
70

    
71
            private set {; }
72
        }
73

    
74
        /// <summary>
75
        /// VisualStudio Design Time여부
76
        /// </summary>
77
        public static bool IsDesignMode
78
        {
79
            get
80
            {
81
                try
82
                {
83
                    return DesignerProperties.GetIsInDesignMode(new DependencyObject());
84
                }
85
                catch (Exception)
86
                {
87
                    return false;
88
                }
89
            }
90
            private set { }
91
        }
92

    
93
        /// <summary>
94
        /// Application Data Folder
95
        /// </summary>
96
        public static string AppDataFolder
97
        {
98
            get
99
            {
100
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS");
101
            }
102
        }
103

    
104
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
105

    
106

    
107
        private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null)
108
        {
109
            if (oEncoding == null)
110
                oEncoding = System.Text.Encoding.UTF8;
111

    
112
            byte[] byteArray = Convert.FromBase64String(DecodingText);
113

    
114
            string jsonBack = oEncoding.GetString(byteArray);
115

    
116
            return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack);
117
        }
118

    
119
        private string versionPath = null;
120
        //public SplashScreen splash = new SplashScreen("splash.png");
121
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
122

    
123
        public App()
124
        {
125
            Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.VisualStudio2013Theme();
126

    
127
            App.FileLogger = LogManager.GetLogger(typeof(App));
128
        }
129

    
130
        protected override void OnExit(ExitEventArgs e)
131
        {
132
            try
133
            {
134
                if (App.PageStorage != null)
135
                {
136
                    App.PageStorage.Clear();
137
                }
138
            }
139
            catch (Exception)
140
            {
141
            }
142

    
143
            base.OnExit(e);
144
        }
145

    
146
        protected override async void OnStartup(StartupEventArgs e)
147
        {
148
            try
149
            {
150
                DefaultArrowCursor = Application.GetResourceStream(new Uri(@"pack://application:,,,/Resources/Cursor/customCursor2.cur", UriKind.Absolute));
151

    
152
                splashScreen.Show();
153

    
154
                App.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
155
                /// up to here
156
                //AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
157

    
158
                #region  //  DNS 체크
159

    
160
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
161

    
162
                ViewerDataModel.Instance.IsDocumentHistory = Convert.ToBoolean(CommonLib.Common.GetConfigString("COMMON","IsDocumentHistory", "true"));
163

    
164
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
165
                
166
                if (hostEntry == null)
167
                {
168
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
169
                    //App.FileLogger.Debug("hostEntry == null");
170
                    isExternal = true;
171
                }
172
                else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper()))
173
                {
174
                    // 외부 사용자
175
                     App.FileLogger.Debug(string.Format("You are external user because located out side of given domain({0})\nYour domain is {1}", localdomain, hostEntry.HostName));
176
                    isExternal = true;
177
                }
178
                #endregion
179

    
180

    
181
                if (e.Args.Count() > 0)
182
                {
183
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
184
                    App.ViewInfo = new IKCOM.ViewInfo
185
                    {
186
                        DocumentItemID = result.DocumentItemID,
187
                        EnsembleID = result.DocumentItemID,
188
                        //DocumentItemID = "10001",
189
                        bPartner = result.bPartner,
190
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
191
                        NewCommentPermission = result.NewCommentPermission,
192
                        ProjectNO = result.ProjectNO,
193
                        UserID = result.UserID,
194
                        isAdmin = Convert.ToBoolean(result.Mode)
195
                        //UserID = "H2009115",
196
                        //Mode = result.Mode
197
                    };
198
                    ParameterMode = true; 
199
                } 
200
                else
201
                {
202
                    string[] strArg = Environment.GetCommandLineArgs();
203
                    if (strArg.Length > 1)
204
                    {
205
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
206
                        App.ViewInfo = new IKCOM.ViewInfo
207
                        {
208
                            DocumentItemID = result.DocumentItemID,
209
                            EnsembleID = result.DocumentItemID,
210
                            //DocumentItemID = "10001",
211
                            bPartner = result.bPartner,
212
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
213
                            NewCommentPermission = result.NewCommentPermission,
214
                            ProjectNO = result.ProjectNO,
215
                            UserID = result.UserID,
216
                            //UserID = "H2009115",
217
                            //Mode = 0 , 1 , 2
218
                        };
219
                        ParameterMode = true;
220
                    }
221
                    else
222
                    {
223
                        MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내");
224
                        throw new ArgumentException("문서 정보가 입력되지 않았습니다.");
225
                    }
226
                }
227

    
228
                //App.ViewInfo.CreateFinalPDFPermission = false;
229
                //App.ViewInfo.NewCommentPermission = false;
230
                //GetQueryStringParameters();
231
                //_binding = new WSHttpBinding();
232
                //_binding.Security = new WSHttpSecurity { Transport = new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.None }, Mode = SecurityMode.Transport };
233
                //_binding.MaxReceivedMessageSize = 2147483647;
234
                //_binding.OpenTimeout = new TimeSpan(0, 1, 0);
235
                //_binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
236
                //_binding.CloseTimeout = new TimeSpan(0, 5, 0);
237
                //_binding.SendTimeout = new TimeSpan(0, 5, 0);
238

    
239
                #region 기본 binding
240
                BasicHttpBinding basicHttpBinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
241
                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 } };
242
                basicHttpBinding.MaxBufferSize = 2147483647;
243
                basicHttpBinding.MaxBufferPoolSize = 2147483647;
244
                basicHttpBinding.MaxReceivedMessageSize = 2147483647;
245
                basicHttpBinding.OpenTimeout = new TimeSpan(0, 30, 0);
246
                basicHttpBinding.ReceiveTimeout = new TimeSpan(4, 30, 0);
247
                basicHttpBinding.CloseTimeout = new TimeSpan(0, 30, 0);
248
                basicHttpBinding.SendTimeout = new TimeSpan(4, 30, 0);
249
                basicHttpBinding.TextEncoding = System.Text.Encoding.UTF8;
250
                basicHttpBinding.TransferMode = TransferMode.Buffered;
251
                basicHttpBinding.MessageEncoding = WSMessageEncoding.Text;
252
                basicHttpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
253
                //basicHttpBinding.ProxyAddress = null;
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

    
357
        private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
358
        {
359
            Logger.sendReqLog("App Error ",e.Exception.ToString() + " " + e.Exception.InnerException?.ToString(), 1);
360
        }
361

    
362
        private void KeyDownEvent(object sender, KeyEventArgs e)
363
        {
364
            //if (e.Key == Key.Escape || e.Key == Key.Delete)
365
            //{
366
                System.Diagnostics.Debug.WriteLine("app key Event");
367
                Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e);
368
            //}
369
        }
370

    
371
        private async Task<bool> SplashScreenAsnyc()
372
        {
373
            int value = 100 / ISplashMessage.SplashMessageCnt;
374

    
375
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
376
            {
377
                await Task.Delay(3);
378
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
379
            }
380

    
381
            //splashScreen.Close();
382

    
383
            return true;
384
        }
385

    
386
        public static void splashString(string text)
387
        {
388
            Task.Factory.StartNew(() =>
389
            {
390
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
391
            }).ConfigureAwait(false);
392
        }
393

    
394

    
395
        /// <summary>
396
        /// log unhandled exception
397
        /// </summary>
398
        /// <author>humkyung</author>
399
        /// <date>2019.05.21</date>
400
        /// <param name="sender"></param>
401
        /// <param name="e"></param>
402
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
403
        {
404
            try
405
            {
406
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
407
            }
408
            catch (Exception ex)
409
            {
410
                Console.WriteLine(ex.InnerException?.ToString());
411
            }
412
            finally
413
            {
414
#if RELEASE
415
                Environment.Exit(0);
416
#endif
417
            }
418
        }
419

    
420
        private void ErrorLogFileWrite(string Err)
421
        {
422
            App.FileLogger.Debug(Err);
423
        }
424
    }
425
}
클립보드 이미지 추가 (최대 크기: 500 MB)