프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ c5fe2a1f

이력 | 보기 | 이력해설 | 다운로드 (13.5 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

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

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

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

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

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

    
89
        /// <summary>
90
        /// logger
91
        /// </summary>
92
        public static ILog DBLogger = null;
93
        public static ILog FileLogger = null;
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

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

    
110

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

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

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

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

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

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

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

    
135
            try
136
            {
137

    
138
                Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
139

    
140
                splashScreen.Show();
141

    
142
                /// create log database and table
143
                using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") })
144
                {
145
                    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);";
146
                    database.ExecuteNonQuery(sSql);
147
                }
148
                /// up to here
149
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
150
                log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db");
151
                log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log");
152
                App.DBLogger = LogManager.GetLogger("DBLogger");
153
                App.FileLogger = LogManager.GetLogger("EventLogger");
154

    
155
                #region  //  DNS 체크
156

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

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

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

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

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

    
199
                    App.ViewInfo.UserID = App.PEMSSInfo.UserID;
200
                    ParameterMode = true;
201
                }
202
                else
203
                {
204
                    string[] strArg = Environment.GetCommandLineArgs();
205
                    if (strArg.Length > 1)
206
                    {
207
                        //label1.Text = strArg[1];
208

    
209
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
210
                        App.ViewInfo = new IKCOM.ViewInfo
211
                        {
212
                            DocumentItemID = result.DocumentItemID,
213
                            EnsembleID = result.DocumentItemID,
214
                            //DocumentItemID = "10001",
215
                            bPartner = result.bPartner,
216
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
217
                            NewCommentPermission = result.NewCommentPermission,
218
                            ProjectNO = result.ProjectNO,
219
                            UserID = result.UserID,
220
                            //UserID = "H2009115",
221
                            //Mode = 0 , 1 , 2
222
                        };
223

    
224
                        App.PEMSSInfo = new IKCOM.PEMSSInfo
225
                        {
226
                            UserID = result.uId
227
                        };
228

    
229
                        ParameterMode = true;
230
                    }
231
                }
232

    
233
                //App.ViewInfo.CreateFinalPDFPermission = false;
234
                //App.ViewInfo.NewCommentPermission = false;
235
                //GetQueryStringParameters();
236
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
237
                _binding.MaxBufferSize = 2147483647;
238
                _binding.MaxReceivedMessageSize = 2147483647;
239
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
240
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
241
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
242
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
243
                _binding.TextEncoding = System.Text.Encoding.UTF8;
244
                _binding.TransferMode = TransferMode.Buffered;
245
                //Support.SetLicense();
246

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

    
249
#if DEBUG
250
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
251
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
252
                sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "", isExternal);
253
#else
254
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
255
#endif
256

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

    
259
#if DEBUG
260
                _PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", "http://localhost:13009"));
261
#else
262
                          _PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", sBaseServiceURL));
263
#endif
264

    
265
                await SplashScreenAsnyc();
266
            
267
                base.OnStartup(e);
268
               
269
                Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
270

    
271
                UpdateCheck(e);
272
                //this.MainWindow.Show();
273
                //KeyValuePair<bool, string> updatecheck = UpdateCheck(e);
274
            }
275
            catch (Exception ex)
276
            {
277
                MessageBox.Show("Err:" + ex.ToString());
278
            }
279
            finally
280
            {
281
                await SplashScreenAsnyc();
282
            }
283
        }
284

    
285
        private KeyValuePair<bool, string> UpdateCheck(StartupEventArgs startupEvents)
286
        {
287
            bool isUpdateCheck = false;
288
            string updateurl = string.Empty;
289
            try
290
            {
291
                bool is64bit = Environment.Is64BitProcess;
292
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
293
                ServiceDeepViewClient BaseClient = new ServiceDeepViewClient(_binding, _EndPoint);
294
                updateurl = BaseClient.GetVersionData(is64bit, clientversion);
295

    
296
                if (Check_Uri.isUri(updateurl))
297
                {
298
                    base.OnStartup(startupEvents);
299

    
300
                    var updateWin = new UpdateWindow(updateurl);
301

    
302
                    updateWin.UpdatePassEvent += (snd, evt) =>
303
                    {
304
                        updateWin.Visibility = Visibility.Hidden;
305
                        new MainWindow().Show();
306
                    };
307

    
308
                    updateWin.ShowDialog();
309
                }
310
                else
311
                {
312
                    base.OnStartup(startupEvents);
313
                    (new MainWindow()).Show();
314
                }
315
            }
316
            catch (Exception)
317
            {
318
                throw;
319
            }
320
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
321
        }
322

    
323

    
324
        private async Task<bool> SplashScreenAsnyc()
325
        {
326
            int value = 100 / ISplashMessage.SplashMessageCnt;
327

    
328
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
329
            {
330
                System.Threading.Thread.Sleep(3);
331
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
332
            }
333

    
334
            splashScreen.Close();
335

    
336
            return true;
337
        }
338

    
339
        public static void splashString(string text)
340
        {
341
            Task.Factory.StartNew(() =>
342
            {
343
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
344
            });
345
        }
346

    
347

    
348
        /// <summary>
349
        /// log unhandled exception
350
        /// </summary>
351
        /// <author>humkyung</author>
352
        /// <date>2019.05.21</date>
353
        /// <param name="sender"></param>
354
        /// <param name="e"></param>
355
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
356
        {
357
            try
358
            {
359
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
360
                //App.DBLogger.Fatal(e.ExceptionObject as Exception);
361
            }
362
            catch (Exception ex)
363
            {
364
                Console.WriteLine(ex.InnerException?.ToString());
365
            }
366
            finally
367
            {
368
#if RELEASE
369
                Environment.Exit(0);
370
#endif
371
            }
372
        }
373

    
374
        private void ErrorLogFileWrite(string Err)
375
        {
376
            App.FileLogger.Debug(Err);
377
        }
378
    }
379
}
클립보드 이미지 추가 (최대 크기: 500 MB)