프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ f513c215

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