프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 91c5e7a1

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

1 787a4489 KangIngu

2 af22332b ljiyeon
using KCOM.Common;
3 c4a4d59c ljiyeon
using KCOM.ServiceDeepView;
4 787a4489 KangIngu
using System;
5
using System.Collections.Generic;
6
using System.ComponentModel;
7
using System.Configuration;
8
using System.Data;
9 c4a4d59c ljiyeon
using System.Diagnostics;
10
using System.IO;
11 787a4489 KangIngu
using System.Linq;
12 c4a4d59c ljiyeon
using System.Net;
13
using System.Reflection;
14 787a4489 KangIngu
using System.Runtime.CompilerServices;
15
using System.ServiceModel;
16
using System.Windows;
17 c4a4d59c ljiyeon
using System.Xml;
18 a7346d3c humkyung
using log4net;
19 e52385b9 ljiyeon
using System.Text;
20
using System.Runtime.InteropServices;
21 cf2671a6 ljiyeon
using KCOM.Views;
22
using System.Threading.Tasks;
23 1c7f408a taeseongkim
using Telerik.Windows.Controls;
24 91c5e7a1 taeseongkim
using System.Windows.Input;
25 787a4489 KangIngu
26 a7346d3c humkyung
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
27 787a4489 KangIngu
namespace KCOM
28
{
29
    public class OpenProperties
30
    {
31
        public string DocumentItemID { get; set; }
32
        public bool bPartner { get; set; }
33
        public bool CreateFinalPDFPermission { get; set; }
34
        public bool NewCommentPermission { get; set; }
35
        public string ProjectNO { get; set; }
36
        public string UserID { get; set; }
37
        public int Mode { get; set; }
38 0f6604ce taeseongkim
39
        /// <summary>
40
        /// pemss에서 전달되는 ID
41
        /// </summary>
42
        public string pId { get; set; }
43
44
        /// <summary>
45
        /// pemss에서 전달되는 ID
46
        /// </summary>
47
        public string uId { get; set; }
48 63a36cc0 taeseongkim
49
        public string cId { get; set; }
50 787a4489 KangIngu
    }
51
    /// <summary>
52
    /// App.xaml에 대한 상호 작용 논리
53
    /// </summary>
54
    public partial class App : Application
55
    {
56 0f6604ce taeseongkim
        public static bool IsDesignMode
57
        {
58
            get
59
            {
60 b10671a4 taeseongkim
                try
61
                {
62
                    return DesignerProperties.GetIsInDesignMode(new DependencyObject());
63
                }
64
                catch (Exception)
65
                {
66
                    return false;
67
                }
68 0f6604ce taeseongkim
            }
69
            private set { }
70
        }
71
72 787a4489 KangIngu
        public static BasicHttpBinding _binding;
73
        public static EndpointAddress _EndPoint;
74 6f67c93d taeseongkim
        public static EndpointAddress _PemssEndPoint;
75 787a4489 KangIngu
        public static EndpointAddress _EndPoint_SaveLoad;
76
        public static EndpointAddress _EndPoint_Symbol;
77
        public static string UserID;
78
        public static string UserName;
79
        public static string UserIP;
80
        public static IKCOM.ViewInfo ViewInfo;
81 3a4649f8 taeseongkim
        public static IKCOM.PEMSSInfo PEMSSInfo;
82 787a4489 KangIngu
        public static string urlHost;
83
        public static string urlPort;
84
        public static string urlHost_DB;
85
        public static string urlPort_DB;
86
        public static string Custom_ViewInfoId;
87
        public static bool ParameterMode = false;
88 84c48033 djkim
        public static bool isExternal = false;
89 787a4489 KangIngu
90 a7346d3c humkyung
        /// <summary>
91
        /// logger
92
        /// </summary>
93 ce3f0d7a humkyung
        public static ILog DBLogger = null;
94
        public static ILog FileLogger = null;
95 a7346d3c humkyung
96
        /// <summary>
97
        /// Application Data Folder
98
        /// </summary>
99
        public static string AppDataFolder
100
        {
101
            get
102
            {
103
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS");
104
            }
105
        }
106 787a4489 KangIngu
107 1137be84 djkim
108 787a4489 KangIngu
        public static RestSharp.RestClient BaseClient { get; set; }
109
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
110 1137be84 djkim
111 264c9309 ljiyeon
112 787a4489 KangIngu
        private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null)
113
        {
114
            if (oEncoding == null)
115
                oEncoding = System.Text.Encoding.UTF8;
116
117
            byte[] byteArray = Convert.FromBase64String(DecodingText);
118
119
            string jsonBack = oEncoding.GetString(byteArray);
120
121
            return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack);
122
        }
123
124 c4a4d59c ljiyeon
        private string versionPath = null;
125 cf2671a6 ljiyeon
        //public SplashScreen splash = new SplashScreen("splash.png");
126 e0cfc73c ljiyeon
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
127 cdfb57ff taeseongkim
128
        public App()
129
        {
130 b10671a4 taeseongkim
            Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.Office2016Theme();
131 cdfb57ff taeseongkim
        }
132
133
        protected override async void OnStartup(StartupEventArgs e)
134
        {
135 1137be84 djkim
136 787a4489 KangIngu
            try
137 a7346d3c humkyung
            {
138 566f0526 taeseongkim
139 1c7f408a taeseongkim
                Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
140 566f0526 taeseongkim
141 cf2671a6 ljiyeon
                splashScreen.Show();
142 1137be84 djkim
143 a7346d3c humkyung
                /// create log database and table
144
                using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") })
145
                {
146
                    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);";
147
                    database.ExecuteNonQuery(sSql);
148
                }
149
                /// up to here
150
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
151 ce3f0d7a humkyung
                log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db");
152
                log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log");
153
                App.DBLogger = LogManager.GetLogger("DBLogger");
154
                App.FileLogger = LogManager.GetLogger("EventLogger");
155 a7346d3c humkyung
156 1137be84 djkim
                #region  //  DNS 체크
157
158
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
159
160
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
161
162
                if (hostEntry == null)
163
                {
164
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
165
                    App.FileLogger.Fatal("hostEntry == null");
166
                    isExternal = true;
167
                }
168
                else if (!hostEntry.HostName.EndsWith(localdomain))
169
                {
170
                    // 외부 사용자
171
                    App.FileLogger.Fatal("hostEntry != localdomain :" + hostEntry.HostName);
172
                    isExternal = true;
173
                }
174
                #endregion
175 cf2671a6 ljiyeon
                //splash.Show(false, false);                
176 1137be84 djkim
177 787a4489 KangIngu
                if (e.Args.Count() > 0)
178
                {
179 c4a4d59c ljiyeon
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
180 787a4489 KangIngu
                    App.ViewInfo = new IKCOM.ViewInfo
181
                    {
182
                        DocumentItemID = result.DocumentItemID,
183 35afe17c djkim
                        EnsembleID = result.DocumentItemID,
184 787a4489 KangIngu
                        //DocumentItemID = "10001",
185
                        bPartner = result.bPartner,
186 bc664e9b djkim
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
187
                        NewCommentPermission = result.NewCommentPermission,
188 787a4489 KangIngu
                        ProjectNO = result.ProjectNO,
189
                        UserID = result.UserID,
190
                        //UserID = "H2009115",
191
                        //Mode = 0 , 1 , 2
192
                    };
193 3a4649f8 taeseongkim
194
                    App.PEMSSInfo = new IKCOM.PEMSSInfo
195
                    {
196 63a36cc0 taeseongkim
                        UserID = result.uId,
197
                        CommentID = result.cId
198 3a4649f8 taeseongkim
                    };
199
200 c5fe2a1f taeseongkim
                    App.ViewInfo.UserID = App.PEMSSInfo.UserID;
201 787a4489 KangIngu
                    ParameterMode = true;
202
                }
203 c4a4d59c ljiyeon
                else
204
                {
205
                    string[] strArg = Environment.GetCommandLineArgs();
206
                    if (strArg.Length > 1)
207
                    {
208
                        //label1.Text = strArg[1];
209
210
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
211
                        App.ViewInfo = new IKCOM.ViewInfo
212
                        {
213
                            DocumentItemID = result.DocumentItemID,
214 35afe17c djkim
                            EnsembleID = result.DocumentItemID,
215 c4a4d59c ljiyeon
                            //DocumentItemID = "10001",
216
                            bPartner = result.bPartner,
217
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
218
                            NewCommentPermission = result.NewCommentPermission,
219
                            ProjectNO = result.ProjectNO,
220
                            UserID = result.UserID,
221
                            //UserID = "H2009115",
222
                            //Mode = 0 , 1 , 2
223
                        };
224 3a4649f8 taeseongkim
225
                        App.PEMSSInfo = new IKCOM.PEMSSInfo
226
                        {
227
                            UserID = result.uId
228
                        };
229
230 c4a4d59c ljiyeon
                        ParameterMode = true;
231 1137be84 djkim
                    }
232 c4a4d59c ljiyeon
                }
233 992a98b4 KangIngu
234
                //App.ViewInfo.CreateFinalPDFPermission = false;
235
                //App.ViewInfo.NewCommentPermission = false;
236 c4a4d59c ljiyeon
                //GetQueryStringParameters();
237
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
238 787a4489 KangIngu
                _binding.MaxBufferSize = 2147483647;
239
                _binding.MaxReceivedMessageSize = 2147483647;
240
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
241
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
242
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
243
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
244
                _binding.TextEncoding = System.Text.Encoding.UTF8;
245
                _binding.TransferMode = TransferMode.Buffered;
246
                //Support.SetLicense();
247 af22332b ljiyeon
248 84c48033 djkim
                string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "");
249 1137be84 djkim
250 84c48033 djkim
#if DEBUG
251 eb5cdefc djkim
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
252 566f0526 taeseongkim
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
253 cdfb57ff taeseongkim
                sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "", isExternal);
254 992a98b4 KangIngu
#else
255 36d6ae21 taeseongkim
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
256 992a98b4 KangIngu
#endif
257 cdfb57ff taeseongkim
258 84c48033 djkim
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
259 84190963 taeseongkim
260 0b75c341 taeseongkim
#if DEBUG
261 b9df9ab0 taeseongkim
                _PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", sBaseServiceURL));
262 0b75c341 taeseongkim
#else
263
                          _PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", sBaseServiceURL));
264
#endif
265 709b3fb7 taeseongkim
266 cdfb57ff taeseongkim
                await SplashScreenAsnyc();
267 1c7f408a taeseongkim
            
268 cdfb57ff taeseongkim
                base.OnStartup(e);
269 1c7f408a taeseongkim
               
270
                Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
271
272 f3c08420 taeseongkim
                UpdateCheck(e);
273 91c5e7a1 taeseongkim
274
                System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent);
275
276
277 1c7f408a taeseongkim
                //this.MainWindow.Show();
278
                //KeyValuePair<bool, string> updatecheck = UpdateCheck(e);
279 787a4489 KangIngu
            }
280
            catch (Exception ex)
281
            {
282 5aaf27a2 djkim
                MessageBox.Show("Err:" + ex.ToString());
283 787a4489 KangIngu
            }
284 f7e7a61a ljiyeon
            finally
285
            {
286 cdfb57ff taeseongkim
                await SplashScreenAsnyc();
287 1137be84 djkim
            }
288 787a4489 KangIngu
        }
289 a7346d3c humkyung
290 91c5e7a1 taeseongkim
        private void KeyDownEvent(object sender, KeyEventArgs e)
291
        {
292
            System.Diagnostics.Debug.WriteLine("app key Event");
293
            Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e);
294
        }
295
296 1c7f408a taeseongkim
        private KeyValuePair<bool, string> UpdateCheck(StartupEventArgs startupEvents)
297
        {
298
            bool isUpdateCheck = false;
299
            string updateurl = string.Empty;
300
            try
301
            {
302
                bool is64bit = Environment.Is64BitProcess;
303
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
304
                ServiceDeepViewClient BaseClient = new ServiceDeepViewClient(_binding, _EndPoint);
305
                updateurl = BaseClient.GetVersionData(is64bit, clientversion);
306
307
                if (Check_Uri.isUri(updateurl))
308
                {
309 f3c08420 taeseongkim
                    base.OnStartup(startupEvents);
310
311
                    var updateWin = new UpdateWindow(updateurl);
312
313
                    updateWin.UpdatePassEvent += (snd, evt) =>
314 1c7f408a taeseongkim
                    {
315 f3c08420 taeseongkim
                        updateWin.Visibility = Visibility.Hidden;
316
                        new MainWindow().Show();
317 1c7f408a taeseongkim
                    };
318
319 f3c08420 taeseongkim
                    updateWin.ShowDialog();
320 1c7f408a taeseongkim
                }
321
                else
322
                {
323
                    base.OnStartup(startupEvents);
324
                    (new MainWindow()).Show();
325
                }
326
            }
327
            catch (Exception)
328
            {
329
                throw;
330
            }
331
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
332
        }
333
334
335 cdfb57ff taeseongkim
        private async Task<bool> SplashScreenAsnyc()
336
        {
337
            int value = 100 / ISplashMessage.SplashMessageCnt;
338
339
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
340
            {
341
                System.Threading.Thread.Sleep(3);
342
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
343
            }
344
345
            splashScreen.Close();
346
347
            return true;
348
        }
349
350 e0cfc73c ljiyeon
        public static void splashString(string text)
351
        {
352
            Task.Factory.StartNew(() =>
353
            {
354
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
355
            });
356
        }
357
358
359 a7346d3c humkyung
        /// <summary>
360
        /// log unhandled exception
361
        /// </summary>
362
        /// <author>humkyung</author>
363
        /// <date>2019.05.21</date>
364
        /// <param name="sender"></param>
365
        /// <param name="e"></param>
366
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
367
        {
368
            try
369
            {
370 360e4f75 djkim
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
371
                //App.DBLogger.Fatal(e.ExceptionObject as Exception);
372 a7346d3c humkyung
            }
373
            catch (Exception ex)
374
            {
375 8614f701 taeseongkim
                Console.WriteLine(ex.InnerException?.ToString());
376 a7346d3c humkyung
            }
377
            finally
378
            {
379 8614f701 taeseongkim
#if RELEASE
380 a7346d3c humkyung
                Environment.Exit(0);
381 8614f701 taeseongkim
#endif
382 a7346d3c humkyung
            }
383
        }
384
385 c4a4d59c ljiyeon
        private void ErrorLogFileWrite(string Err)
386
        {
387 ce3f0d7a humkyung
            App.FileLogger.Debug(Err);
388 c4a4d59c ljiyeon
        }
389 787a4489 KangIngu
    }
390
}
클립보드 이미지 추가 (최대 크기: 500 MB)