프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ f3c08420

이력 | 보기 | 이력해설 | 다운로드 (13.4 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
using KCOM.Views;
22
using System.Threading.Tasks;
23
using Telerik.Windows.Controls;
24

    
25
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
26
namespace KCOM
27
{
28
    public class OpenProperties
29
    {
30
        public string DocumentItemID { get; set; }
31
        public bool bPartner { get; set; }
32
        public bool CreateFinalPDFPermission { get; set; }
33
        public bool NewCommentPermission { get; set; }
34
        public string ProjectNO { get; set; }
35
        public string UserID { get; set; }
36
        public int Mode { get; set; }
37

    
38
        /// <summary>
39
        /// pemss에서 전달되는 ID
40
        /// </summary>
41
        public string pId { get; set; }
42

    
43
        /// <summary>
44
        /// pemss에서 전달되는 ID
45
        /// </summary>
46
        public string uId { get; set; }
47

    
48
        public string cId { get; set; }
49
    }
50
    /// <summary>
51
    /// App.xaml에 대한 상호 작용 논리
52
    /// </summary>
53
    public partial class App : Application
54
    {
55
        public static bool IsDesignMode
56
        {
57
            get
58
            {
59
                try
60
                {
61
                    return DesignerProperties.GetIsInDesignMode(new DependencyObject());
62
                }
63
                catch (Exception)
64
                {
65
                    return false;
66
                }
67
            }
68
            private set { }
69
        }
70

    
71
        public static BasicHttpBinding _binding;
72
        public static EndpointAddress _EndPoint;
73
        public static EndpointAddress _PemssEndPoint;
74
        public static EndpointAddress _EndPoint_SaveLoad;
75
        public static EndpointAddress _EndPoint_Symbol;
76
        public static string UserID;
77
        public static string UserName;
78
        public static string UserIP;
79
        public static IKCOM.ViewInfo ViewInfo;
80
        public static IKCOM.PEMSSInfo PEMSSInfo;
81
        public static string urlHost;
82
        public static string urlPort;
83
        public static string urlHost_DB;
84
        public static string urlPort_DB;
85
        public static string Custom_ViewInfoId;
86
        public static bool ParameterMode = false;
87
        public static bool isExternal = false;
88

    
89
        /// <summary>
90
        /// logger
91
        /// </summary>
92
        public static ILog DBLogger = null;
93
        public static ILog FileLogger = null;
94

    
95
        /// <summary>
96
        /// Application Data Folder
97
        /// </summary>
98
        public static string AppDataFolder
99
        {
100
            get
101
            {
102
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS");
103
            }
104
        }
105

    
106

    
107
        public static RestSharp.RestClient BaseClient { get; set; }
108
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
109

    
110

    
111
        private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null)
112
        {
113
            if (oEncoding == null)
114
                oEncoding = System.Text.Encoding.UTF8;
115

    
116
            byte[] byteArray = Convert.FromBase64String(DecodingText);
117

    
118
            string jsonBack = oEncoding.GetString(byteArray);
119

    
120
            return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack);
121
        }
122

    
123
        private string versionPath = null;
124
        //public SplashScreen splash = new SplashScreen("splash.png");
125
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
126

    
127
        public App()
128
        {
129
            Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.Office2016Theme();
130
        }
131

    
132
        protected override async void OnStartup(StartupEventArgs e)
133
        {
134

    
135
            try
136
            {
137

    
138
                Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
139

    
140
                splashScreen.Show();
141

    
142
                /// create log database and table
143
                using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") })
144
                {
145
                    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);";
146
                    database.ExecuteNonQuery(sSql);
147
                }
148
                /// up to here
149
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
150
                log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db");
151
                log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log");
152
                App.DBLogger = LogManager.GetLogger("DBLogger");
153
                App.FileLogger = LogManager.GetLogger("EventLogger");
154

    
155
                #region  //  DNS 체크
156

    
157
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
158

    
159
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
160

    
161
                if (hostEntry == null)
162
                {
163
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
164
                    App.FileLogger.Fatal("hostEntry == null");
165
                    isExternal = true;
166
                }
167
                else if (!hostEntry.HostName.EndsWith(localdomain))
168
                {
169
                    // 외부 사용자
170
                    App.FileLogger.Fatal("hostEntry != localdomain :" + hostEntry.HostName);
171
                    isExternal = true;
172
                }
173
                #endregion
174
                //splash.Show(false, false);                
175

    
176
                if (e.Args.Count() > 0)
177
                {
178
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
179
                    App.ViewInfo = new IKCOM.ViewInfo
180
                    {
181
                        DocumentItemID = result.DocumentItemID,
182
                        EnsembleID = result.DocumentItemID,
183
                        //DocumentItemID = "10001",
184
                        bPartner = result.bPartner,
185
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
186
                        NewCommentPermission = result.NewCommentPermission,
187
                        ProjectNO = result.ProjectNO,
188
                        UserID = result.UserID,
189
                        //UserID = "H2009115",
190
                        //Mode = 0 , 1 , 2
191
                    };
192

    
193
                    App.PEMSSInfo = new IKCOM.PEMSSInfo
194
                    {
195
                        UserID = result.uId,
196
                        CommentID = result.cId
197
                    };
198

    
199
                    ParameterMode = true;
200
                }
201
                else
202
                {
203
                    string[] strArg = Environment.GetCommandLineArgs();
204
                    if (strArg.Length > 1)
205
                    {
206
                        //label1.Text = strArg[1];
207

    
208
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
209
                        App.ViewInfo = new IKCOM.ViewInfo
210
                        {
211
                            DocumentItemID = result.DocumentItemID,
212
                            EnsembleID = result.DocumentItemID,
213
                            //DocumentItemID = "10001",
214
                            bPartner = result.bPartner,
215
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
216
                            NewCommentPermission = result.NewCommentPermission,
217
                            ProjectNO = result.ProjectNO,
218
                            UserID = result.UserID,
219
                            //UserID = "H2009115",
220
                            //Mode = 0 , 1 , 2
221
                        };
222

    
223
                        App.PEMSSInfo = new IKCOM.PEMSSInfo
224
                        {
225
                            UserID = result.uId
226
                        };
227

    
228
                        ParameterMode = true;
229
                    }
230
                }
231

    
232
                //App.ViewInfo.CreateFinalPDFPermission = false;
233
                //App.ViewInfo.NewCommentPermission = false;
234
                //GetQueryStringParameters();
235
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
236
                _binding.MaxBufferSize = 2147483647;
237
                _binding.MaxReceivedMessageSize = 2147483647;
238
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
239
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
240
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
241
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
242
                _binding.TextEncoding = System.Text.Encoding.UTF8;
243
                _binding.TransferMode = TransferMode.Buffered;
244
                //Support.SetLicense();
245

    
246
                string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "");
247

    
248
#if DEBUG
249
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
250
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
251
                sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "", isExternal);
252
#else
253
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
254
#endif
255

    
256
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
257

    
258
#if DEBUG
259
                _PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", "http://localhost:13009"));
260
#else
261
                          _PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", sBaseServiceURL));
262
#endif
263

    
264
                await SplashScreenAsnyc();
265
            
266
                base.OnStartup(e);
267
               
268
                Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
269

    
270
                UpdateCheck(e);
271
                //this.MainWindow.Show();
272
                //KeyValuePair<bool, string> updatecheck = UpdateCheck(e);
273
            }
274
            catch (Exception ex)
275
            {
276
                MessageBox.Show("Err:" + ex.ToString());
277
            }
278
            finally
279
            {
280
                await SplashScreenAsnyc();
281
            }
282
        }
283

    
284
        private KeyValuePair<bool, string> UpdateCheck(StartupEventArgs startupEvents)
285
        {
286
            bool isUpdateCheck = false;
287
            string updateurl = string.Empty;
288
            try
289
            {
290
                bool is64bit = Environment.Is64BitProcess;
291
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
292
                ServiceDeepViewClient BaseClient = new ServiceDeepViewClient(_binding, _EndPoint);
293
                updateurl = BaseClient.GetVersionData(is64bit, clientversion);
294

    
295
                if (Check_Uri.isUri(updateurl))
296
                {
297
                    base.OnStartup(startupEvents);
298

    
299
                    var updateWin = new UpdateWindow(updateurl);
300

    
301
                    updateWin.UpdatePassEvent += (snd, evt) =>
302
                    {
303
                        updateWin.Visibility = Visibility.Hidden;
304
                        new MainWindow().Show();
305
                    };
306

    
307
                    updateWin.ShowDialog();
308
                }
309
                else
310
                {
311
                    base.OnStartup(startupEvents);
312
                    (new MainWindow()).Show();
313
                }
314
            }
315
            catch (Exception)
316
            {
317
                throw;
318
            }
319
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
320
        }
321

    
322

    
323
        private async Task<bool> SplashScreenAsnyc()
324
        {
325
            int value = 100 / ISplashMessage.SplashMessageCnt;
326

    
327
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
328
            {
329
                System.Threading.Thread.Sleep(3);
330
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
331
            }
332

    
333
            splashScreen.Close();
334

    
335
            return true;
336
        }
337

    
338
        public static void splashString(string text)
339
        {
340
            Task.Factory.StartNew(() =>
341
            {
342
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
343
            });
344
        }
345

    
346

    
347
        /// <summary>
348
        /// log unhandled exception
349
        /// </summary>
350
        /// <author>humkyung</author>
351
        /// <date>2019.05.21</date>
352
        /// <param name="sender"></param>
353
        /// <param name="e"></param>
354
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
355
        {
356
            try
357
            {
358
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
359
                //App.DBLogger.Fatal(e.ExceptionObject as Exception);
360
            }
361
            catch (Exception ex)
362
            {
363
                Console.WriteLine(ex.InnerException?.ToString());
364
            }
365
            finally
366
            {
367
#if RELEASE
368
                Environment.Exit(0);
369
#endif
370
            }
371
        }
372

    
373
        private void ErrorLogFileWrite(string Err)
374
        {
375
            App.FileLogger.Debug(Err);
376
        }
377
    }
378
}
클립보드 이미지 추가 (최대 크기: 500 MB)