프로젝트

일반

사용자정보

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

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

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

1

2
using KCOM.Common;
3
using KCOM.ServiceDeepView;
4
using System;
5
using System.Collections.Generic;
6
using System.ComponentModel;
7
using System.Configuration;
8
using System.Data;
9
using System.Diagnostics;
10
using System.IO;
11
using System.Linq;
12
using System.Net;
13
using System.Reflection;
14
using System.Runtime.CompilerServices;
15
using System.ServiceModel;
16
using System.Windows;
17
using System.Xml;
18
using log4net;
19

    
20
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
21
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
        /// <summary>
54
        /// logger
55
        /// </summary>
56
        public static ILog DBLogger = null;
57
        public static ILog FileLogger = null;
58

    
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

    
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
        private string versionPath = null;
85
        public SplashScreen splash = new SplashScreen("splash.png");
86

    
87
        protected override void OnStartup(StartupEventArgs e)
88
        {
89
            try
90
            {
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
                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

    
104
                splash.Show(false, false);
105

    
106
                if (e.Args.Count() > 0)
107
                {
108
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
109
                    App.ViewInfo = new IKCOM.ViewInfo
110
                    {
111
                        DocumentItemID = result.DocumentItemID,
112
                        //DocumentItemID = "10001",
113
                        bPartner = result.bPartner,
114
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
115
                        NewCommentPermission = result.NewCommentPermission,
116
                        ProjectNO = result.ProjectNO,
117
                        UserID = result.UserID,
118
                        //UserID = "H2009115",
119
                        //Mode = 0 , 1 , 2
120
                    };
121
                    ParameterMode = true;
122
                }
123
                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

    
147
                //App.ViewInfo.CreateFinalPDFPermission = false;
148
                //App.ViewInfo.NewCommentPermission = false;
149

    
150
                //GetQueryStringParameters();
151
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
152
                _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

    
162
                string sBaseServiceURL = global::KCOM.Properties.Settings.Default.BaseClientAddress;
163

    
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
#if DEBUG
181
                //_EndPoint = new EndpointAddress(@"http://10.11.252.3/MARKUS/ServiceDeepView.svc"); //효성
182
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
183

    
184
#else
185
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
186
#endif
187
                
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
                if (File.Exists(versionPath))
198
                {
199
                    // 20180921 version.xml check로 변경
200
                    var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
201
                    try
202
                    {
203
                        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
                        {
209
                            //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
                        }
223
                        else
224
                        {
225
                            base.OnStartup(e);
226
                            splash.Close(new TimeSpan(0, 0, 2));
227
                        }
228
                    }
229
                    catch (Exception ex) //2. 파일이 없거나 파일내에 version의 값이 없다면 KCOM 실행하기
230
                    {
231
                        ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ex);
232
                        base.OnStartup(e);
233
                        splash.Close(new TimeSpan(0, 0, 2));
234
                    }
235
                }
236
            }
237
            catch (Exception ex)
238
            {
239
                MessageBox.Show("Err" + ex.Message);
240
            }
241
            finally
242
            {
243
                splash.Close(new TimeSpan(0, 0, 2));
244
            }
245
        }
246

    
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
                App.DBLogger.Fatal(e.ExceptionObject as Exception);
259
            }
260
            catch (Exception ex)
261
            {
262
                Console.WriteLine(ex.InnerException.ToString());
263
            }
264
            finally
265
            {
266
                Environment.Exit(0);
267
            }
268
        }
269

    
270
        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
            App.FileLogger.Debug(Err);
296
            /*
297
            try
298
            {
299
                string pathString = AppDataFolder + "\\Err";
300

    
301
                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
            */
315
        }
316
    }
317
}
클립보드 이미지 추가 (최대 크기: 500 MB)