프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ cf1cc862

이력 | 보기 | 이력해설 | 다운로드 (14.3 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.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 BasicHttpBinding _binding;
38
        public static EndpointAddress _EndPoint;
39
        public static EndpointAddress _EndPoint_SaveLoad;
40
        public static EndpointAddress _EndPoint_Symbol;
41
        public static string UserID;
42
        public static string UserName;
43
        public static string UserIP;
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
        public static string Custom_ViewInfoId;
50
        public static bool ParameterMode = false;
51
        public static bool isExternal = false;
52

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

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

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

    
73
            private set {; }
74
        }
75

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

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

    
106
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
107

    
108

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

    
114
            byte[] byteArray = Convert.FromBase64String(DecodingText);
115

    
116
            string jsonBack = oEncoding.GetString(byteArray);
117

    
118
            return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack);
119
        }
120

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

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

    
129
            App.FileLogger = LogManager.GetLogger(typeof(App));
130
        }
131

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

    
145
            base.OnExit(e);
146
        }
147

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

    
154
                splashScreen.Show();
155

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

    
160
                #region  //  DNS 체크
161

    
162
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
163

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

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

    
182

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

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

    
241
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
242
                _binding.MaxBufferSize = 2147483647;
243
                _binding.MaxReceivedMessageSize = 2147483647;
244
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
245
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
246
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
247
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
248
                _binding.TextEncoding = System.Text.Encoding.UTF8;
249
                _binding.TransferMode = TransferMode.Buffered;
250
                //_binding.TextEncoding = System.Text.Encoding.UTF8;
251
                //Support.SetLicense();
252

    
253
#if DEBUG
254
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
255
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
256
                BaseAddress = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
257
#else
258
                BaseAddress = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
259
#endif
260

    
261
                var UploadAddress = CommonLib.Common.GetConfigString("KCOM_kr_co_devdoftech_cloud_FileUpload", "URL", "");
262

    
263
                if (!string.IsNullOrWhiteSpace(UploadAddress) && !string.IsNullOrWhiteSpace(BaseAddress))
264
                {
265
                    var uri = new UriBuilder(UploadAddress);
266
                    var baseUri = new UriBuilder(BaseAddress);
267

    
268
                    uri.Host = baseUri.Host;
269
                    uri.Port = baseUri.Port;
270

    
271
                    FileUploadUri = uri.ToString();
272

    
273

    
274
                }
275

    
276
                App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", BaseAddress));
277
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", BaseAddress));
278
                
279
                var license = new License.Validator.Valid(BaseAddress + "/License1");
280

    
281
                license.ValidateError += License_ValidateError;
282

    
283
                license.GetLicense("public.xml");
284

    
285
                if (license.Activate())
286
                {
287
    
288
                }
289
                else
290
                {
291

    
292
                }
293

    
294
                await SplashScreenAsnyc();
295

    
296
                base.OnStartup(e);
297
                System.Windows.Input.Keyboard.AddPreviewKeyDownHandler(this.MainWindow, KeyDownEvent);
298

    
299

    
300
                //System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent);
301
            }
302
            catch (Exception ex)
303
            {
304
                Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1);
305
            }
306
            finally
307
            {
308
                await SplashScreenAsnyc();
309
            }
310
        }
311

    
312
        private void License_ValidateError(object sender, ValidateErrorArgs e)
313
        {
314
            e.Received = true;
315

    
316
            Telerik.Windows.Controls.RadWindow.Alert(new Telerik.Windows.Controls.DialogParameters
317
            {
318
                Content = "License Error : " + e.Message,
319
                Owner = splashScreen
320
            });
321
            ///MessageBox.Show(e.Message);
322
            Application.Current.Shutdown();
323
        }
324

    
325
        private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
326
        {
327
            Logger.sendReqLog("App Error ",e.Exception.ToString() + " " + e.Exception.InnerException?.ToString(), 1);
328
        }
329

    
330
        private void KeyDownEvent(object sender, KeyEventArgs e)
331
        {
332
            //if (e.Key == Key.Escape || e.Key == Key.Delete)
333
            //{
334
                System.Diagnostics.Debug.WriteLine("app key Event");
335
                Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e);
336
            //}
337
        }
338

    
339
        private async Task<bool> SplashScreenAsnyc()
340
        {
341
            int value = 100 / ISplashMessage.SplashMessageCnt;
342

    
343
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
344
            {
345
                await Task.Delay(3);
346
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
347
            }
348

    
349
            //splashScreen.Close();
350

    
351
            return true;
352
        }
353

    
354
        public static void splashString(string text)
355
        {
356
            Task.Factory.StartNew(() =>
357
            {
358
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
359
            }).ConfigureAwait(false);
360
        }
361

    
362

    
363
        /// <summary>
364
        /// log unhandled exception
365
        /// </summary>
366
        /// <author>humkyung</author>
367
        /// <date>2019.05.21</date>
368
        /// <param name="sender"></param>
369
        /// <param name="e"></param>
370
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
371
        {
372
            try
373
            {
374
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
375
            }
376
            catch (Exception ex)
377
            {
378
                Console.WriteLine(ex.InnerException?.ToString());
379
            }
380
            finally
381
            {
382
#if RELEASE
383
                Environment.Exit(0);
384
#endif
385
            }
386
        }
387

    
388
        private void ErrorLogFileWrite(string Err)
389
        {
390
            App.FileLogger.Debug(Err);
391
        }
392
    }
393
}