프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ a1e2ba68

이력 | 보기 | 이력해설 | 다운로드 (13.5 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.ServiceModel;
10
using System.Threading.Tasks;
11
using System.Windows;
12
using System.Windows.Input;
13
using System.Windows.Resources;
14

    
15
namespace KCOM
16
{
17
    public class OpenProperties
18
    {
19
        public string DocumentItemID { get; set; }
20
        public bool bPartner { get; set; }
21
        public bool CreateFinalPDFPermission { get; set; }
22
        public bool NewCommentPermission { get; set; }
23
        public string ProjectNO { get; set; }
24
        public string UserID { get; set; }
25
        public int Mode { get; set; }
26
    }
27
    /// <summary>
28
    /// App.xaml에 대한 상호 작용 논리
29
    /// </summary>
30
    public partial class App : Application
31
    {
32
        public static PageManager.PageStorage PageStorage;
33
        public static string MarkusVersion = "";
34
        public static string BaseAddress;
35
        public static string FileUploadUri;
36
        public static BasicHttpBinding _binding;
37
        public static EndpointAddress _EndPoint;
38
        public static EndpointAddress _EndPoint_SaveLoad;
39
        public static EndpointAddress _EndPoint_Symbol;
40
        public static string UserID;
41
        public static string UserName;
42
        public static string UserIP;
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
        public static bool isExternal = false;
51

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

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

    
68
        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
        /// <summary>
76
        /// 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
        /// 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

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

    
107

    
108
        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
        private string versionPath = null;
121
        //public SplashScreen splash = new SplashScreen("splash.png");
122
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
123

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

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

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

    
144
            base.OnExit(e);
145
        }
146

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

    
153
                splashScreen.Show();
154

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

    
159
                #region  //  DNS 체크
160

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

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

    
165
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
166
                
167
                if (hostEntry == null)
168
                {
169
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
170
                    //App.FileLogger.Debug("hostEntry == null");
171
                    isExternal = true;
172
                }
173
                else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper()))
174
                {
175
                    // 외부 사용자
176
                     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
                    isExternal = true;
178
                }
179
                #endregion
180

    
181

    
182
                if (e.Args.Count() > 0)
183
                {
184
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
185
                    App.ViewInfo = new IKCOM.ViewInfo
186
                    {
187
                        DocumentItemID = result.DocumentItemID,
188
                        EnsembleID = result.DocumentItemID,
189
                        //DocumentItemID = "10001",
190
                        bPartner = result.bPartner,
191
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
192
                        NewCommentPermission = result.NewCommentPermission,
193
                        ProjectNO = result.ProjectNO,
194
                        UserID = result.UserID,
195
                        isAdmin = Convert.ToBoolean(result.Mode)
196
                        //UserID = "H2009115",
197
                        //Mode = result.Mode
198
                    };
199
                    ParameterMode = true;
200
                } 
201
                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
                            EnsembleID = result.DocumentItemID,
211
                            //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
                    }
222
                    else
223
                    {
224
                        MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내");
225
                        throw new ArgumentException("문서 정보가 입력되지 않았습니다.");
226
                    }
227
                }
228

    
229
                //App.ViewInfo.CreateFinalPDFPermission = false;
230
                //App.ViewInfo.NewCommentPermission = false;
231
                //GetQueryStringParameters();
232
                //_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
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
241
                _binding.MaxBufferSize = 2147483647;
242
                _binding.MaxReceivedMessageSize = 2147483647;
243
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
244
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
245
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
246
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
247
                _binding.TextEncoding = System.Text.Encoding.UTF8;
248
                _binding.TransferMode = TransferMode.Buffered;
249
                //_binding.TextEncoding = System.Text.Encoding.UTF8;
250
                //Support.SetLicense();
251

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

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

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

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

    
270
                    FileUploadUri = uri.ToString();
271

    
272

    
273
                }
274

    
275
                App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", BaseAddress));
276
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", BaseAddress));
277

    
278
                
279

    
280
                await SplashScreenAsnyc();
281
                base.OnStartup(e);
282
                System.Windows.Input.Keyboard.AddPreviewKeyDownHandler(this.MainWindow, KeyDownEvent);
283
                //System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent);
284
            }
285
            catch (Exception ex)
286
            {
287
                Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1);
288
            }
289
            finally
290
            {
291
                await SplashScreenAsnyc();
292
            }
293
        }
294

    
295
        private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
296
        {
297
            Logger.sendReqLog("App Error ",e.Exception.ToString() + " " + e.Exception.InnerException?.ToString(), 1);
298
        }
299

    
300
        private void KeyDownEvent(object sender, KeyEventArgs e)
301
        {
302
            //if (e.Key == Key.Escape || e.Key == Key.Delete)
303
            //{
304
                System.Diagnostics.Debug.WriteLine("app key Event");
305
                Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e);
306
            //}
307
        }
308

    
309
        private async Task<bool> SplashScreenAsnyc()
310
        {
311
            int value = 100 / ISplashMessage.SplashMessageCnt;
312

    
313
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
314
            {
315
                await Task.Delay(3);
316
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
317
            }
318

    
319
            //splashScreen.Close();
320

    
321
            return true;
322
        }
323

    
324
        public static void splashString(string text)
325
        {
326
            Task.Factory.StartNew(() =>
327
            {
328
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
329
            }).ConfigureAwait(false);
330
        }
331

    
332

    
333
        /// <summary>
334
        /// log unhandled exception
335
        /// </summary>
336
        /// <author>humkyung</author>
337
        /// <date>2019.05.21</date>
338
        /// <param name="sender"></param>
339
        /// <param name="e"></param>
340
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
341
        {
342
            try
343
            {
344
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
345
            }
346
            catch (Exception ex)
347
            {
348
                Console.WriteLine(ex.InnerException?.ToString());
349
            }
350
            finally
351
            {
352
#if RELEASE
353
                Environment.Exit(0);
354
#endif
355
            }
356
        }
357

    
358
        private void ErrorLogFileWrite(string Err)
359
        {
360
            App.FileLogger.Debug(Err);
361
        }
362
    }
363
}
클립보드 이미지 추가 (최대 크기: 500 MB)