프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 5928384e

이력 | 보기 | 이력해설 | 다운로드 (12.6 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
        
73
        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
        private string versionPath = null;
88
        public SplashScreen splash = new SplashScreen("splash.png");
89

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

    
107
                splash.Show(false, false);
108

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

    
150
                //App.ViewInfo.CreateFinalPDFPermission = false;
151
                //App.ViewInfo.NewCommentPermission = false;
152

    
153
                //GetQueryStringParameters();
154
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
155
                _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
                
165
                string sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "");
166

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

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

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

    
273
        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
            App.FileLogger.Debug(Err);
299
            /*
300
            try
301
            {
302
                string pathString = AppDataFolder + "\\Err";
303

    
304
                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
            */
318
        }
319
    }
320
}
클립보드 이미지 추가 (최대 크기: 500 MB)