프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 3e8c830d

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

1 787a4489 KangIngu

2 af22332b ljiyeon
using KCOM.Common;
3 c4a4d59c ljiyeon
using KCOM.ServiceDeepView;
4 787a4489 KangIngu
using System;
5
using System.Collections.Generic;
6
using System.ComponentModel;
7
using System.Configuration;
8
using System.Data;
9 c4a4d59c ljiyeon
using System.Diagnostics;
10
using System.IO;
11 787a4489 KangIngu
using System.Linq;
12 c4a4d59c ljiyeon
using System.Net;
13
using System.Reflection;
14 787a4489 KangIngu
using System.Runtime.CompilerServices;
15
using System.ServiceModel;
16
using System.Windows;
17 c4a4d59c ljiyeon
using System.Xml;
18 a7346d3c humkyung
using log4net;
19 e52385b9 ljiyeon
using System.Text;
20
using System.Runtime.InteropServices;
21 cf2671a6 ljiyeon
using KCOM.Views;
22
using System.Threading.Tasks;
23 787a4489 KangIngu
24 a7346d3c humkyung
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
25 787a4489 KangIngu
namespace KCOM
26
{
27
    public class OpenProperties
28
    {
29
        public string DocumentItemID { get; set; }
30
        public bool bPartner { get; set; }
31
        public bool CreateFinalPDFPermission { get; set; }
32
        public bool NewCommentPermission { get; set; }
33
        public string ProjectNO { get; set; }
34
        public string UserID { get; set; }
35
        public int Mode { get; set; }
36
    }
37
    /// <summary>
38
    /// App.xaml에 대한 상호 작용 논리
39
    /// </summary>
40
    public partial class App : Application
41
    {
42
        public static BasicHttpBinding _binding;
43
        public static EndpointAddress _EndPoint;
44
        public static EndpointAddress _EndPoint_SaveLoad;
45
        public static EndpointAddress _EndPoint_Symbol;
46
        public static string UserID;
47
        public static string UserName;
48
        public static string UserIP;
49
        public static IKCOM.ViewInfo ViewInfo;
50
        public static string urlHost;
51
        public static string urlPort;
52
        public static string urlHost_DB;
53
        public static string urlPort_DB;
54
        public static string Custom_ViewInfoId;
55
        public static bool ParameterMode = false;
56 84c48033 djkim
        public static bool isExternal = false;
57 787a4489 KangIngu
58 a7346d3c humkyung
        /// <summary>
59
        /// logger
60
        /// </summary>
61 ce3f0d7a humkyung
        public static ILog DBLogger = null;
62
        public static ILog FileLogger = null;
63 a7346d3c humkyung
64
        /// <summary>
65
        /// Application Data Folder
66
        /// </summary>
67
        public static string AppDataFolder
68
        {
69
            get
70
            {
71
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS");
72
            }
73
        }
74 787a4489 KangIngu
75 5928384e djkim
        
76 787a4489 KangIngu
        public static RestSharp.RestClient BaseClient { get; set; }
77
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
78
        private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null)
79
        {
80
            if (oEncoding == null)
81
                oEncoding = System.Text.Encoding.UTF8;
82
83
            byte[] byteArray = Convert.FromBase64String(DecodingText);
84
85
            string jsonBack = oEncoding.GetString(byteArray);
86
87
            return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack);
88
        }
89
90 c4a4d59c ljiyeon
        private string versionPath = null;
91 cf2671a6 ljiyeon
        //public SplashScreen splash = new SplashScreen("splash.png");
92 e0cfc73c ljiyeon
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
93 787a4489 KangIngu
        protected override void OnStartup(StartupEventArgs e)
94 cf2671a6 ljiyeon
        {          
95 787a4489 KangIngu
            try
96 a7346d3c humkyung
            {
97 cf2671a6 ljiyeon
                splashScreen.Show();
98
               
99 a7346d3c humkyung
                /// create log database and table
100
                using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") })
101
                {
102
                    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);";
103
                    database.ExecuteNonQuery(sSql);
104
                }
105
                /// up to here
106
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
107 ce3f0d7a humkyung
                log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db");
108
                log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log");
109
                App.DBLogger = LogManager.GetLogger("DBLogger");
110
                App.FileLogger = LogManager.GetLogger("EventLogger");
111 a7346d3c humkyung
112 cf2671a6 ljiyeon
                //splash.Show(false, false);                
113
                        
114 787a4489 KangIngu
                if (e.Args.Count() > 0)
115
                {
116 c4a4d59c ljiyeon
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
117 787a4489 KangIngu
                    App.ViewInfo = new IKCOM.ViewInfo
118
                    {
119
                        DocumentItemID = result.DocumentItemID,
120 35afe17c djkim
                        EnsembleID = result.DocumentItemID,
121 787a4489 KangIngu
                        //DocumentItemID = "10001",
122
                        bPartner = result.bPartner,
123 bc664e9b djkim
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
124
                        NewCommentPermission = result.NewCommentPermission,
125 787a4489 KangIngu
                        ProjectNO = result.ProjectNO,
126
                        UserID = result.UserID,
127
                        //UserID = "H2009115",
128
                        //Mode = 0 , 1 , 2
129
                    };
130
                    ParameterMode = true;
131
                }
132 c4a4d59c ljiyeon
                else
133
                {
134
                    string[] strArg = Environment.GetCommandLineArgs();
135
                    if (strArg.Length > 1)
136
                    {
137
                        //label1.Text = strArg[1];
138
139
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
140
                        App.ViewInfo = new IKCOM.ViewInfo
141
                        {
142
                            DocumentItemID = result.DocumentItemID,
143 35afe17c djkim
                            EnsembleID = result.DocumentItemID,
144 c4a4d59c ljiyeon
                            //DocumentItemID = "10001",
145
                            bPartner = result.bPartner,
146
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
147
                            NewCommentPermission = result.NewCommentPermission,
148
                            ProjectNO = result.ProjectNO,
149
                            UserID = result.UserID,
150
                            //UserID = "H2009115",
151
                            //Mode = 0 , 1 , 2
152
                        };
153
                        ParameterMode = true;
154
                    }                
155
                }
156 992a98b4 KangIngu
157
                //App.ViewInfo.CreateFinalPDFPermission = false;
158
                //App.ViewInfo.NewCommentPermission = false;
159
160 c4a4d59c ljiyeon
                //GetQueryStringParameters();
161
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
162 787a4489 KangIngu
                _binding.MaxBufferSize = 2147483647;
163
                _binding.MaxReceivedMessageSize = 2147483647;
164
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
165
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
166
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
167
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
168
                _binding.TextEncoding = System.Text.Encoding.UTF8;
169
                _binding.TransferMode = TransferMode.Buffered;
170
                //Support.SetLicense();
171 af22332b ljiyeon
172 84c48033 djkim
                string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "");
173
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
174 eb5cdefc djkim
                var ipaddress = CommonLib.DNSHelper.GetDnsAdress();
175 af22332b ljiyeon
176
                try
177
                {
178
                    var hostName = Dns.GetHostEntry(ipaddress).HostName;
179
180 84c48033 djkim
                    if (!hostName.EndsWith(localdomain))
181 af22332b ljiyeon
                    {
182
                        // 외부 사용자
183 84c48033 djkim
                        isExternal = true;                        
184 af22332b ljiyeon
                    }
185
                }
186
                catch (Exception ex)
187
                {
188
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
189
                }
190 814116a9 humkyung
191 84c48033 djkim
#if DEBUG
192 eb5cdefc djkim
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
193 19391ad3 djkim
                sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "",isExternal);
194 992a98b4 KangIngu
#else
195 84c48033 djkim
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
196 992a98b4 KangIngu
#endif
197 eb5cdefc djkim
                                
198 84c48033 djkim
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
199
200 c4a4d59c ljiyeon
                if (Environment.Is64BitProcess == true) //64 bit machine
201
                {
202 84c48033 djkim
                    versionPath = CommonLib.Common.GetConfigString("UpdateVer64", "URL", "", isExternal);
203 c4a4d59c ljiyeon
                }
204
                else //32 bit machine
205
                {
206 84c48033 djkim
                    versionPath = CommonLib.Common.GetConfigString("UpdateVer86", "URL", "", isExternal);
207 c4a4d59c ljiyeon
                }
208
209 af22332b ljiyeon
                if (File.Exists(versionPath))
210 c4a4d59c ljiyeon
                {
211 af22332b ljiyeon
                    // 20180921 version.xml check로 변경
212
                    var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
213
                    try
214 c4a4d59c ljiyeon
                    {
215 af22332b ljiyeon
                        XmlDocument xdoc = new XmlDocument();
216
                        xdoc.Load(versionPath);
217
                        XmlNode node = xdoc.SelectSingleNode("/RootElement/version");
218
219
                        if (assemblyVersion != node.InnerText) // node.InnerText 가 null이면 catch로 빠짐
220 c4a4d59c ljiyeon
                        {
221 af22332b ljiyeon
                            //if(MessageBox.Show("Ver. " + node.InnerText + " 업데이트가 있습니다.\r\nSmartUpdate를 실행합니다.", "MARKUS", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
222
                            //{
223
                            if (MessageBox.Show("Ver. " + node.InnerText, "MARKUS", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
224
                            {
225
                                UpdateCheck(e);
226
                            }
227
                            else
228
                            {
229
                                base.Shutdown();
230
                                //현재 실행되고 있는 자기 자신 프로세스의 정보 // 위에꺼랑 두개 다 써줄필요가 있는..가?
231
                                Process proc = Process.GetCurrentProcess();
232
                                proc.Kill();
233
                            }
234 c4a4d59c ljiyeon
                        }
235
                        else
236 cf2671a6 ljiyeon
                        {                           
237
                            // splash.Close(new TimeSpan(0, 0, 2));
238
                            Task.Factory.StartNew(() =>
239
                            {
240 e0cfc73c ljiyeon
                                int value = 100 / ISplashMessage.SplashMessageCnt;
241
                                for (int i = 1; i <= ISplashMessage.SplashMessageCnt ; i++)
242 cf2671a6 ljiyeon
                                {
243 e0cfc73c ljiyeon
                                    System.Threading.Thread.Sleep(3);
244
                                    splashScreen.Dispatcher.Invoke(() => splashScreen.Progress = i * value);
245 cf2671a6 ljiyeon
                                }
246
                                this.Dispatcher.Invoke(() =>
247
                                {
248
                                    base.OnStartup(e);
249
                                    splashScreen.Close();
250
                                });
251
                                
252
                            });
253 c4a4d59c ljiyeon
                        }
254
                    }
255 af22332b ljiyeon
                    catch (Exception ex) //2. 파일이 없거나 파일내에 version의 값이 없다면 KCOM 실행하기
256 c4a4d59c ljiyeon
                    {
257 af22332b ljiyeon
                        ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ex);
258 cf2671a6 ljiyeon
                        
259
                        Task.Factory.StartNew(() =>
260
                        {
261 e0cfc73c ljiyeon
                            int value = 100 / ISplashMessage.SplashMessageCnt;
262
                            for (int i = 1; i <= ISplashMessage.SplashMessageCnt; i++)
263 cf2671a6 ljiyeon
                            {
264 e0cfc73c ljiyeon
                                System.Threading.Thread.Sleep(3);
265
                                splashScreen.Dispatcher.Invoke(() => splashScreen.Progress = i * value);                                
266 cf2671a6 ljiyeon
                            }
267 e0cfc73c ljiyeon
                            
268 cf2671a6 ljiyeon
                            this.Dispatcher.Invoke(() =>
269
                            {
270
                                base.OnStartup(e);
271
                                splashScreen.Close();
272
                            });
273
                        });
274
                    }                
275 c4a4d59c ljiyeon
                }
276 787a4489 KangIngu
            }
277
            catch (Exception ex)
278
            {
279 5aaf27a2 djkim
                MessageBox.Show("Err:" + ex.ToString());
280 787a4489 KangIngu
            }
281 f7e7a61a ljiyeon
            finally
282
            {
283 cf2671a6 ljiyeon
                Task.Factory.StartNew(() =>
284
                {
285 e0cfc73c ljiyeon
                    int value = 100 / ISplashMessage.SplashMessageCnt;
286
                    for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
287 cf2671a6 ljiyeon
                    {
288 e0cfc73c ljiyeon
                        System.Threading.Thread.Sleep(3);
289
                        
290
                        splashScreen.Dispatcher.Invoke(() => splashScreen.Progress = i * value);
291
292
                        //App.                      
293 cf2671a6 ljiyeon
                    }
294
                    this.Dispatcher.Invoke(() =>
295
                    {
296
                        //base.OnStartup(e);
297
                        splashScreen.Close();
298
                    });
299
                });
300 f7e7a61a ljiyeon
            }
301 cf2671a6 ljiyeon
        
302 787a4489 KangIngu
        }
303 a7346d3c humkyung
304 e0cfc73c ljiyeon
        public static void splashString(string text)
305
        {
306
            Task.Factory.StartNew(() =>
307
            {
308
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
309
            });
310
        }
311
312
313
314 a7346d3c humkyung
        /// <summary>
315
        /// log unhandled exception
316
        /// </summary>
317
        /// <author>humkyung</author>
318
        /// <date>2019.05.21</date>
319
        /// <param name="sender"></param>
320
        /// <param name="e"></param>
321
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
322
        {
323
            try
324
            {
325 ce3f0d7a humkyung
                App.DBLogger.Fatal(e.ExceptionObject as Exception);
326 a7346d3c humkyung
            }
327
            catch (Exception ex)
328
            {
329
                Console.WriteLine(ex.InnerException.ToString());
330
            }
331
            finally
332
            {
333
                Environment.Exit(0);
334
            }
335
        }
336
337 c4a4d59c ljiyeon
        protected void UpdateCheck(StartupEventArgs e)
338
        {          
339
            try
340
            {
341
                if (e.Args.Count() > 0)
342
                {
343
                    ProcessStartInfo proInfo = new ProcessStartInfo();
344
                    var FileName = AppDomain.CurrentDomain.BaseDirectory + "SmartUpdate.exe";
345
                    
346
                    Process.Start(FileName, e.Args[0]);
347
348
                    base.Shutdown();
349
                    //현재 실행되고 있는 자기 자신 프로세스의 정보 
350
                    Process proc = Process.GetCurrentProcess();
351
                    proc.Kill();
352
                }                    
353
            }
354
            catch(Exception ee)
355
            {
356
                ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ee);
357
            }            
358
        }
359
360
        private void ErrorLogFileWrite(string Err)
361
        {
362 ce3f0d7a humkyung
            App.FileLogger.Debug(Err);
363
            /*
364 c4a4d59c ljiyeon
            try
365
            {
366 f7e7a61a ljiyeon
                string pathString = AppDataFolder + "\\Err";
367 af22332b ljiyeon
368 c4a4d59c ljiyeon
                if (!File.Exists(pathString))
369
                {
370
                    Directory.CreateDirectory(pathString);
371
                }
372
373
                Err = Err + "   " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\r\n";
374
                string path = pathString + "\\" + "Log_" + DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".txt";
375
                File.AppendAllText(path, Err);
376
            }
377
            catch (Exception er)
378
            {
379
                string strError = er.ToString();
380
            }
381 ce3f0d7a humkyung
            */
382 c4a4d59c ljiyeon
        }
383 787a4489 KangIngu
    }
384
}
클립보드 이미지 추가 (최대 크기: 500 MB)