프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 90a0bfa9

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