프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ f513c215

이력 | 보기 | 이력해설 | 다운로드 (12.8 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
        public static bool isExternal = false;
55

    
56
        /// <summary>
57
        /// logger
58
        /// </summary>
59
        public static ILog DBLogger = null;
60
        public static ILog FileLogger = null;
61

    
62
        /// <summary>
63
        /// Application Data Folder
64
        /// </summary>
65
        public static string AppDataFolder
66
        {
67
            get
68
            {
69
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS");
70
            }
71
        }
72

    
73
        
74
        public static RestSharp.RestClient BaseClient { get; set; }
75
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
76
        private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null)
77
        {
78
            if (oEncoding == null)
79
                oEncoding = System.Text.Encoding.UTF8;
80

    
81
            byte[] byteArray = Convert.FromBase64String(DecodingText);
82

    
83
            string jsonBack = oEncoding.GetString(byteArray);
84

    
85
            return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack);
86
        }
87

    
88
        private string versionPath = null;
89
        public SplashScreen splash = new SplashScreen("splash.png");
90

    
91
        protected override void OnStartup(StartupEventArgs e)
92
        {
93
            try
94
            {
95
                /// create log database and table
96
                using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") })
97
                {
98
                    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);";
99
                    database.ExecuteNonQuery(sSql);
100
                }
101
                /// up to here
102
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
103
                log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db");
104
                log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log");
105
                App.DBLogger = LogManager.GetLogger("DBLogger");
106
                App.FileLogger = LogManager.GetLogger("EventLogger");
107

    
108
                splash.Show(false, false);
109

    
110
                if (e.Args.Count() > 0)
111
                {
112
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
113
                    App.ViewInfo = new IKCOM.ViewInfo
114
                    {
115
                        DocumentItemID = result.DocumentItemID,
116
                        EnsembleID = 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
                            EnsembleID = result.DocumentItemID,
140
                            //DocumentItemID = "10001",
141
                            bPartner = result.bPartner,
142
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
143
                            NewCommentPermission = result.NewCommentPermission,
144
                            ProjectNO = result.ProjectNO,
145
                            UserID = result.UserID,
146
                            //UserID = "H2009115",
147
                            //Mode = 0 , 1 , 2
148
                        };
149
                        ParameterMode = true;
150
                    }                
151
                }
152

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

    
156
                //GetQueryStringParameters();
157
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
158
                _binding.MaxBufferSize = 2147483647;
159
                _binding.MaxReceivedMessageSize = 2147483647;
160
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
161
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
162
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
163
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
164
                _binding.TextEncoding = System.Text.Encoding.UTF8;
165
                _binding.TransferMode = TransferMode.Buffered;
166
                //Support.SetLicense();
167

    
168
                string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "");
169
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
170
                var ipaddress = DNSHelper.GetDnsAdress();
171

    
172
                try
173
                {
174
                    var hostName = Dns.GetHostEntry(ipaddress).HostName;
175

    
176
                    if (!hostName.EndsWith(localdomain))
177
                    {
178
                        // 외부 사용자
179
                        isExternal = true;                        
180
                    }
181
                }
182
                catch (Exception ex)
183
                {
184
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
185
                }
186

    
187
#if DEBUG
188
                sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "");
189
#else
190
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
191
#endif
192
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
193

    
194
                if (Environment.Is64BitProcess == true) //64 bit machine
195
                {
196
                    versionPath = CommonLib.Common.GetConfigString("UpdateVer64", "URL", "", isExternal);
197
                }
198
                else //32 bit machine
199
                {
200
                    versionPath = CommonLib.Common.GetConfigString("UpdateVer86", "URL", "", isExternal);
201
                }
202

    
203
                if (File.Exists(versionPath))
204
                {
205
                    // 20180921 version.xml check로 변경
206
                    var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
207
                    try
208
                    {
209
                        XmlDocument xdoc = new XmlDocument();
210
                        xdoc.Load(versionPath);
211
                        XmlNode node = xdoc.SelectSingleNode("/RootElement/version");
212

    
213
                        if (assemblyVersion != node.InnerText) // node.InnerText 가 null이면 catch로 빠짐
214
                        {
215
                            //if(MessageBox.Show("Ver. " + node.InnerText + " 업데이트가 있습니다.\r\nSmartUpdate를 실행합니다.", "MARKUS", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
216
                            //{
217
                            if (MessageBox.Show("Ver. " + node.InnerText, "MARKUS", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
218
                            {
219
                                UpdateCheck(e);
220
                            }
221
                            else
222
                            {
223
                                base.Shutdown();
224
                                //현재 실행되고 있는 자기 자신 프로세스의 정보 // 위에꺼랑 두개 다 써줄필요가 있는..가?
225
                                Process proc = Process.GetCurrentProcess();
226
                                proc.Kill();
227
                            }
228
                        }
229
                        else
230
                        {
231
                            base.OnStartup(e);
232
                            splash.Close(new TimeSpan(0, 0, 2));
233
                        }
234
                    }
235
                    catch (Exception ex) //2. 파일이 없거나 파일내에 version의 값이 없다면 KCOM 실행하기
236
                    {
237
                        ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ex);
238
                        base.OnStartup(e);
239
                        splash.Close(new TimeSpan(0, 0, 2));
240
                    }
241
                }
242
            }
243
            catch (Exception ex)
244
            {
245
                MessageBox.Show("Err" + ex.Message);
246
            }
247
            finally
248
            {
249
                splash.Close(new TimeSpan(0, 0, 2));
250
            }
251
        }
252

    
253
        /// <summary>
254
        /// log unhandled exception
255
        /// </summary>
256
        /// <author>humkyung</author>
257
        /// <date>2019.05.21</date>
258
        /// <param name="sender"></param>
259
        /// <param name="e"></param>
260
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
261
        {
262
            try
263
            {
264
                App.DBLogger.Fatal(e.ExceptionObject as Exception);
265
            }
266
            catch (Exception ex)
267
            {
268
                Console.WriteLine(ex.InnerException.ToString());
269
            }
270
            finally
271
            {
272
                Environment.Exit(0);
273
            }
274
        }
275

    
276
        protected void UpdateCheck(StartupEventArgs e)
277
        {          
278
            try
279
            {
280
                if (e.Args.Count() > 0)
281
                {
282
                    ProcessStartInfo proInfo = new ProcessStartInfo();
283
                    var FileName = AppDomain.CurrentDomain.BaseDirectory + "SmartUpdate.exe";
284
                    
285
                    Process.Start(FileName, e.Args[0]);
286

    
287
                    base.Shutdown();
288
                    //현재 실행되고 있는 자기 자신 프로세스의 정보 
289
                    Process proc = Process.GetCurrentProcess();
290
                    proc.Kill();
291
                }                    
292
            }
293
            catch(Exception ee)
294
            {
295
                ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ee);
296
            }            
297
        }
298

    
299
        private void ErrorLogFileWrite(string Err)
300
        {
301
            App.FileLogger.Debug(Err);
302
            /*
303
            try
304
            {
305
                string pathString = AppDataFolder + "\\Err";
306

    
307
                if (!File.Exists(pathString))
308
                {
309
                    Directory.CreateDirectory(pathString);
310
                }
311

    
312
                Err = Err + "   " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\r\n";
313
                string path = pathString + "\\" + "Log_" + DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".txt";
314
                File.AppendAllText(path, Err);
315
            }
316
            catch (Exception er)
317
            {
318
                string strError = er.ToString();
319
            }
320
            */
321
        }
322
    }
323
}
클립보드 이미지 추가 (최대 크기: 500 MB)