프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ e52385b9

이력 | 보기 | 이력해설 | 다운로드 (13 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
using System.Text;
20
using System.Runtime.InteropServices;
21

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

    
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

    
72
        [DllImport("kernel32")]
73
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
74

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

    
92
        protected override void OnStartup(StartupEventArgs e)
93
        {
94
            try
95
            {
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
                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

    
109
                splash.Show(false, false);
110

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

    
152
                //App.ViewInfo.CreateFinalPDFPermission = false;
153
                //App.ViewInfo.NewCommentPermission = false;
154

    
155
                //GetQueryStringParameters();
156
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
157
                _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

    
167
                StringBuilder BaseClientAddress = new StringBuilder(512);
168
                GetPrivateProfileString("BaseClientAddress", "URL", "(NONE)", BaseClientAddress, 512, Path.Combine(AppDataFolder, "FinalService.ini"));
169

    
170
                //string sBaseServiceURL = global::KCOM.Properties.Settings.Default.BaseClientAddress;
171
                string sBaseServiceURL = BaseClientAddress.ToString();
172

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

    
193
#else
194
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
195
#endif
196
                
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
                if (File.Exists(versionPath))
207
                {
208
                    // 20180921 version.xml check로 변경
209
                    var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
210
                    try
211
                    {
212
                        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
                        {
218
                            //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
                        }
232
                        else
233
                        {
234
                            base.OnStartup(e);
235
                            splash.Close(new TimeSpan(0, 0, 2));
236
                        }
237
                    }
238
                    catch (Exception ex) //2. 파일이 없거나 파일내에 version의 값이 없다면 KCOM 실행하기
239
                    {
240
                        ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ex);
241
                        base.OnStartup(e);
242
                        splash.Close(new TimeSpan(0, 0, 2));
243
                    }
244
                }
245
            }
246
            catch (Exception ex)
247
            {
248
                MessageBox.Show("Err" + ex.Message);
249
            }
250
            finally
251
            {
252
                splash.Close(new TimeSpan(0, 0, 2));
253
            }
254
        }
255

    
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
                App.DBLogger.Fatal(e.ExceptionObject as Exception);
268
            }
269
            catch (Exception ex)
270
            {
271
                Console.WriteLine(ex.InnerException.ToString());
272
            }
273
            finally
274
            {
275
                Environment.Exit(0);
276
            }
277
        }
278

    
279
        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
            App.FileLogger.Debug(Err);
305
            /*
306
            try
307
            {
308
                string pathString = AppDataFolder + "\\Err";
309

    
310
                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
            */
324
        }
325
    }
326
}
클립보드 이미지 추가 (최대 크기: 500 MB)