프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ d62c0439

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