프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 2e35dd78

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

1

2
using KCOM.Common;
3
using KCOM.ServiceDeepView;
4
using System;
5
using System.Collections.Generic;
6
using System.ComponentModel;
7
using System.Configuration;
8
using System.Data;
9
using System.Diagnostics;
10
using System.IO;
11
using System.Linq;
12
using System.Net;
13
using System.Reflection;
14
using System.Runtime.CompilerServices;
15
using System.ServiceModel;
16
using System.Windows;
17
using System.Xml;
18
using log4net;
19
using System.Text;
20
using System.Runtime.InteropServices;
21
using KCOM.Views;
22
using System.Threading.Tasks;
23
using Telerik.Windows.Controls;
24
using System.Windows.Input;
25

    
26
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
27
namespace KCOM
28
{
29
    public class OpenProperties
30
    {
31
        public string DocumentItemID { get; set; }
32
        public bool bPartner { get; set; }
33
        public bool CreateFinalPDFPermission { get; set; }
34
        public bool NewCommentPermission { get; set; }
35
        public string ProjectNO { get; set; }
36
        public string UserID { get; set; }
37
        public int Mode { get; set; }
38

    
39
        /// <summary>
40
        /// pemss에서 전달되는 ID
41
        /// </summary>
42
        public string pId { get; set; }
43

    
44
        /// <summary>
45
        /// pemss에서 전달되는 ID
46
        /// </summary>
47
        public string uId { get; set; }
48

    
49
        public string cId { get; set; }
50
    }
51
    /// <summary>
52
    /// App.xaml에 대한 상호 작용 논리
53
    /// </summary>
54
    public partial class App : Application
55
    {
56
        public static bool IsDesignMode
57
        {
58
            get
59
            {
60
                try
61
                {
62
                    return DesignerProperties.GetIsInDesignMode(new DependencyObject());
63
                }
64
                catch (Exception)
65
                {
66
                    return false;
67
                }
68
            }
69
            private set { }
70
        }
71

    
72
        public static BasicHttpBinding _binding;
73
        public static EndpointAddress _EndPoint;
74
        public static EndpointAddress _PemssEndPoint;
75
        public static EndpointAddress _EndPoint_SaveLoad;
76
        public static EndpointAddress _EndPoint_Symbol;
77
        public static string UserID;
78
        public static string UserName;
79
        public static string UserIP;
80
        public static IKCOM.ViewInfo ViewInfo;
81
        public static IKCOM.PEMSSInfo PEMSSInfo;
82
        public static string urlHost;
83
        public static string urlPort;
84
        public static string urlHost_DB;
85
        public static string urlPort_DB;
86
        public static string Custom_ViewInfoId;
87
        public static bool ParameterMode = false;
88
        public static bool isExternal = false;
89

    
90
        /// <summary>
91
        /// logger
92
        /// </summary>
93
        public static ILog DBLogger = null;
94
        public static ILog FileLogger = null;
95

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

    
107

    
108
        public static RestSharp.RestClient BaseClient { get; set; }
109
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
110

    
111

    
112
        private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null)
113
        {
114
            if (oEncoding == null)
115
                oEncoding = System.Text.Encoding.UTF8;
116

    
117
            byte[] byteArray = Convert.FromBase64String(DecodingText);
118

    
119
            string jsonBack = oEncoding.GetString(byteArray);
120

    
121
            return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack);
122
        }
123

    
124
        private string versionPath = null;
125
        //public SplashScreen splash = new SplashScreen("splash.png");
126
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
127

    
128
        public App()
129
        {
130
            Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.Office2016Theme();
131
        }
132

    
133
        protected override async void OnStartup(StartupEventArgs e)
134
        {
135

    
136
            try
137
            {
138

    
139
                Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
140

    
141
                splashScreen.Show();
142

    
143
                /// create log database and table
144
                using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") })
145
                {
146
                    string sSql = "CREATE TABLE IF NOT EXISTS Log (LogId INTEGER PRIMARY KEY,Date DATETIME NOT NULL,Level VARCHAR(50) NOT NULL,Logger VARCHAR(255) NOT NULL,Message TEXT DEFAULT NULL,StackTrace TEXT DEFAULT NULL);";
147
                    database.ExecuteNonQuery(sSql);
148
                }
149
                /// up to here
150
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
151
                log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db");
152
                log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log");
153
                App.DBLogger = LogManager.GetLogger("DBLogger");
154
                App.FileLogger = LogManager.GetLogger("EventLogger");
155

    
156
                #region  //  DNS 체크
157

    
158
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
159

    
160
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
161

    
162
                if (hostEntry == null)
163
                {
164
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
165
                    App.FileLogger.Fatal("hostEntry == null");
166
                    isExternal = true;
167
                }
168
                else if (!hostEntry.HostName.EndsWith(localdomain))
169
                {
170
                    // 외부 사용자
171
                    App.FileLogger.Fatal("hostEntry != localdomain :" + hostEntry.HostName);
172
                    isExternal = true;
173
                }
174
                #endregion
175
                //splash.Show(false, false);                
176

    
177
                if (e.Args.Count() > 0)
178
                {
179
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
180
                    App.ViewInfo = new IKCOM.ViewInfo
181
                    {
182
                        DocumentItemID = result.DocumentItemID,
183
                        EnsembleID = result.DocumentItemID,
184
                        //DocumentItemID = "10001",
185
                        bPartner = result.bPartner,
186
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
187
                        NewCommentPermission = result.NewCommentPermission,
188
                        ProjectNO = result.ProjectNO,
189
                        UserID = result.UserID,
190
                        //UserID = "H2009115",
191
                        //Mode = 0 , 1 , 2
192
                    };
193

    
194
                    App.PEMSSInfo = new IKCOM.PEMSSInfo
195
                    {
196
                        UserID = result.uId,
197
                        CommentID = result.cId
198
                    };
199

    
200
                    System.Diagnostics.Debug.WriteLine($"DocumentItemID : {result.DocumentItemID}");
201
                    System.Diagnostics.Debug.WriteLine($"bPartner : {result.bPartner.ToString()}");
202
                    System.Diagnostics.Debug.WriteLine($"CreateFinalPDFPermission : {result.CreateFinalPDFPermission.ToString()}");
203
                    System.Diagnostics.Debug.WriteLine($"NewCommentPermission : {result.NewCommentPermission.ToString()}");
204
                    System.Diagnostics.Debug.WriteLine($"ProjectNO : {result.ProjectNO}");
205
                    System.Diagnostics.Debug.WriteLine($"UserID : {result.UserID}");
206
                    System.Diagnostics.Debug.WriteLine($"uId : {result.uId}");
207
                    System.Diagnostics.Debug.WriteLine($"cId : {result.cId}");
208

    
209

    
210
                    App.ViewInfo.UserID = App.PEMSSInfo.UserID;
211
                    ParameterMode = true;
212
                }
213
                else
214
                {
215
                    string[] strArg = Environment.GetCommandLineArgs();
216
                    if (strArg.Length > 1)
217
                    {
218
                        //label1.Text = strArg[1];
219

    
220
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
221
                        App.ViewInfo = new IKCOM.ViewInfo
222
                        {
223
                            DocumentItemID = result.DocumentItemID,
224
                            EnsembleID = result.DocumentItemID,
225
                            //DocumentItemID = "10001",
226
                            bPartner = result.bPartner,
227
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
228
                            NewCommentPermission = result.NewCommentPermission,
229
                            ProjectNO = result.ProjectNO,
230
                            UserID = result.UserID,
231
                            //UserID = "H2009115",
232
                            //Mode = 0 , 1 , 2
233
                        };
234

    
235
                        App.PEMSSInfo = new IKCOM.PEMSSInfo
236
                        {
237
                            UserID = result.uId
238
                        };
239

    
240
                        ParameterMode = true;
241
                    }
242
                }
243

    
244
                //App.ViewInfo.CreateFinalPDFPermission = false;
245
                //App.ViewInfo.NewCommentPermission = false;
246
                //GetQueryStringParameters();
247
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
248
                _binding.MaxBufferSize = 2147483647;
249
                _binding.MaxReceivedMessageSize = 2147483647;
250
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
251
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
252
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
253
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
254
                _binding.TextEncoding = System.Text.Encoding.UTF8;
255
                _binding.TransferMode = TransferMode.Buffered;
256
                //Support.SetLicense();
257

    
258
                string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "");
259

    
260
#if DEBUG
261
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
262
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
263
                sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "", isExternal);
264
#else
265
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
266
#endif
267

    
268
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
269

    
270
#if DEBUG
271
                _PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", sBaseServiceURL));
272
#else
273
                          _PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", sBaseServiceURL));
274
#endif
275

    
276
                await SplashScreenAsnyc();
277
            
278
                base.OnStartup(e);
279
               
280
                Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
281

    
282
                UpdateCheck(e);
283

    
284
                System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent);
285

    
286

    
287
                //this.MainWindow.Show();
288
                //KeyValuePair<bool, string> updatecheck = UpdateCheck(e);
289
            }
290
            catch (Exception ex)
291
            {
292
                MessageBox.Show("Err:" + ex.ToString());
293
            }
294
            finally
295
            {
296
                await SplashScreenAsnyc();
297
            }
298
        }
299

    
300
        private void KeyDownEvent(object sender, KeyEventArgs e)
301
        {
302
            if (e.Key == Key.Delete)
303
            {
304
                if(!FocusManager.GetIsFocusScope(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.zoomAndPanCanvas))
305
                {
306
                    return;
307
                }
308
            }
309

    
310
            System.Diagnostics.Debug.WriteLine("app key Event");
311
            Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e);
312
            
313
        }
314

    
315
        private KeyValuePair<bool, string> UpdateCheck(StartupEventArgs startupEvents)
316
        {
317
            bool isUpdateCheck = false;
318
            string updateurl = string.Empty;
319
            try
320
            {
321
                bool is64bit = Environment.Is64BitProcess;
322
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
323
                ServiceDeepViewClient BaseClient = new ServiceDeepViewClient(_binding, _EndPoint);
324
                updateurl = BaseClient.GetVersionData(is64bit, clientversion);
325

    
326
                if (Check_Uri.isUri(updateurl))
327
                {
328
                    base.OnStartup(startupEvents);
329

    
330
                    var updateWin = new UpdateWindow(updateurl);
331

    
332
                    updateWin.UpdatePassEvent += (snd, evt) =>
333
                    {
334
                        updateWin.Visibility = Visibility.Hidden;
335
                        new MainWindow().Show();
336
                    };
337

    
338
                    updateWin.ShowDialog();
339
                }
340
                else
341
                {
342
                    base.OnStartup(startupEvents);
343
                    (new MainWindow()).Show();
344
                }
345
            }
346
            catch (Exception)
347
            {
348
                throw;
349
            }
350
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
351
        }
352

    
353

    
354
        private async Task<bool> SplashScreenAsnyc()
355
        {
356
            int value = 100 / ISplashMessage.SplashMessageCnt;
357

    
358
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
359
            {
360
                System.Threading.Thread.Sleep(3);
361
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
362
            }
363

    
364
            splashScreen.Close();
365

    
366
            return true;
367
        }
368

    
369
        public static void splashString(string text)
370
        {
371
            Task.Factory.StartNew(() =>
372
            {
373
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
374
            });
375
        }
376

    
377

    
378
        /// <summary>
379
        /// log unhandled exception
380
        /// </summary>
381
        /// <author>humkyung</author>
382
        /// <date>2019.05.21</date>
383
        /// <param name="sender"></param>
384
        /// <param name="e"></param>
385
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
386
        {
387
            try
388
            {
389
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
390
                //App.DBLogger.Fatal(e.ExceptionObject as Exception);
391
            }
392
            catch (Exception ex)
393
            {
394
                Console.WriteLine(ex.InnerException?.ToString());
395
            }
396
            finally
397
            {
398
#if RELEASE
399
                Environment.Exit(0);
400
#endif
401
            }
402
        }
403

    
404
        private void ErrorLogFileWrite(string Err)
405
        {
406
            App.FileLogger.Debug(Err);
407
        }
408
    }
409
}
클립보드 이미지 추가 (최대 크기: 500 MB)