프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ ffd70d3c

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