프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ c5fe2a1f

이력 | 보기 | 이력해설 | 다운로드 (13.5 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 787a4489 KangIngu
25 a7346d3c humkyung
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
26 787a4489 KangIngu
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 0f6604ce taeseongkim
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 63a36cc0 taeseongkim
48
        public string cId { get; set; }
49 787a4489 KangIngu
    }
50
    /// <summary>
51
    /// App.xaml에 대한 상호 작용 논리
52
    /// </summary>
53
    public partial class App : Application
54
    {
55 0f6604ce taeseongkim
        public static bool IsDesignMode
56
        {
57
            get
58
            {
59 b10671a4 taeseongkim
                try
60
                {
61
                    return DesignerProperties.GetIsInDesignMode(new DependencyObject());
62
                }
63
                catch (Exception)
64
                {
65
                    return false;
66
                }
67 0f6604ce taeseongkim
            }
68
            private set { }
69
        }
70
71 787a4489 KangIngu
        public static BasicHttpBinding _binding;
72
        public static EndpointAddress _EndPoint;
73 6f67c93d taeseongkim
        public static EndpointAddress _PemssEndPoint;
74 787a4489 KangIngu
        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 3a4649f8 taeseongkim
        public static IKCOM.PEMSSInfo PEMSSInfo;
81 787a4489 KangIngu
        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 84c48033 djkim
        public static bool isExternal = false;
88 787a4489 KangIngu
89 a7346d3c humkyung
        /// <summary>
90
        /// logger
91
        /// </summary>
92 ce3f0d7a humkyung
        public static ILog DBLogger = null;
93
        public static ILog FileLogger = null;
94 a7346d3c humkyung
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 787a4489 KangIngu
106 1137be84 djkim
107 787a4489 KangIngu
        public static RestSharp.RestClient BaseClient { get; set; }
108
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
109 1137be84 djkim
110 264c9309 ljiyeon
111 787a4489 KangIngu
        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 c4a4d59c ljiyeon
        private string versionPath = null;
124 cf2671a6 ljiyeon
        //public SplashScreen splash = new SplashScreen("splash.png");
125 e0cfc73c ljiyeon
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
126 cdfb57ff taeseongkim
127
        public App()
128
        {
129 b10671a4 taeseongkim
            Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.Office2016Theme();
130 cdfb57ff taeseongkim
        }
131
132
        protected override async void OnStartup(StartupEventArgs e)
133
        {
134 1137be84 djkim
135 787a4489 KangIngu
            try
136 a7346d3c humkyung
            {
137 566f0526 taeseongkim
138 1c7f408a taeseongkim
                Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
139 566f0526 taeseongkim
140 cf2671a6 ljiyeon
                splashScreen.Show();
141 1137be84 djkim
142 a7346d3c humkyung
                /// 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 ce3f0d7a humkyung
                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 a7346d3c humkyung
155 1137be84 djkim
                #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 cf2671a6 ljiyeon
                //splash.Show(false, false);                
175 1137be84 djkim
176 787a4489 KangIngu
                if (e.Args.Count() > 0)
177
                {
178 c4a4d59c ljiyeon
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
179 787a4489 KangIngu
                    App.ViewInfo = new IKCOM.ViewInfo
180
                    {
181
                        DocumentItemID = result.DocumentItemID,
182 35afe17c djkim
                        EnsembleID = result.DocumentItemID,
183 787a4489 KangIngu
                        //DocumentItemID = "10001",
184
                        bPartner = result.bPartner,
185 bc664e9b djkim
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
186
                        NewCommentPermission = result.NewCommentPermission,
187 787a4489 KangIngu
                        ProjectNO = result.ProjectNO,
188
                        UserID = result.UserID,
189
                        //UserID = "H2009115",
190
                        //Mode = 0 , 1 , 2
191
                    };
192 3a4649f8 taeseongkim
193
                    App.PEMSSInfo = new IKCOM.PEMSSInfo
194
                    {
195 63a36cc0 taeseongkim
                        UserID = result.uId,
196
                        CommentID = result.cId
197 3a4649f8 taeseongkim
                    };
198
199 c5fe2a1f taeseongkim
                    App.ViewInfo.UserID = App.PEMSSInfo.UserID;
200 787a4489 KangIngu
                    ParameterMode = true;
201
                }
202 c4a4d59c ljiyeon
                else
203
                {
204
                    string[] strArg = Environment.GetCommandLineArgs();
205
                    if (strArg.Length > 1)
206
                    {
207
                        //label1.Text = strArg[1];
208
209
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
210
                        App.ViewInfo = new IKCOM.ViewInfo
211
                        {
212
                            DocumentItemID = result.DocumentItemID,
213 35afe17c djkim
                            EnsembleID = result.DocumentItemID,
214 c4a4d59c ljiyeon
                            //DocumentItemID = "10001",
215
                            bPartner = result.bPartner,
216
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
217
                            NewCommentPermission = result.NewCommentPermission,
218
                            ProjectNO = result.ProjectNO,
219
                            UserID = result.UserID,
220
                            //UserID = "H2009115",
221
                            //Mode = 0 , 1 , 2
222
                        };
223 3a4649f8 taeseongkim
224
                        App.PEMSSInfo = new IKCOM.PEMSSInfo
225
                        {
226
                            UserID = result.uId
227
                        };
228
229 c4a4d59c ljiyeon
                        ParameterMode = true;
230 1137be84 djkim
                    }
231 c4a4d59c ljiyeon
                }
232 992a98b4 KangIngu
233
                //App.ViewInfo.CreateFinalPDFPermission = false;
234
                //App.ViewInfo.NewCommentPermission = false;
235 c4a4d59c ljiyeon
                //GetQueryStringParameters();
236
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
237 787a4489 KangIngu
                _binding.MaxBufferSize = 2147483647;
238
                _binding.MaxReceivedMessageSize = 2147483647;
239
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
240
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
241
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
242
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
243
                _binding.TextEncoding = System.Text.Encoding.UTF8;
244
                _binding.TransferMode = TransferMode.Buffered;
245
                //Support.SetLicense();
246 af22332b ljiyeon
247 84c48033 djkim
                string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "");
248 1137be84 djkim
249 84c48033 djkim
#if DEBUG
250 eb5cdefc djkim
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
251 566f0526 taeseongkim
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
252 cdfb57ff taeseongkim
                sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "", isExternal);
253 992a98b4 KangIngu
#else
254 36d6ae21 taeseongkim
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
255 992a98b4 KangIngu
#endif
256 cdfb57ff taeseongkim
257 84c48033 djkim
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
258 84190963 taeseongkim
259 0b75c341 taeseongkim
#if DEBUG
260
                _PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", "http://localhost:13009"));
261
#else
262
                          _PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", sBaseServiceURL));
263
#endif
264 709b3fb7 taeseongkim
265 cdfb57ff taeseongkim
                await SplashScreenAsnyc();
266 1c7f408a taeseongkim
            
267 cdfb57ff taeseongkim
                base.OnStartup(e);
268 1c7f408a taeseongkim
               
269
                Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
270
271 f3c08420 taeseongkim
                UpdateCheck(e);
272 1c7f408a taeseongkim
                //this.MainWindow.Show();
273
                //KeyValuePair<bool, string> updatecheck = UpdateCheck(e);
274 787a4489 KangIngu
            }
275
            catch (Exception ex)
276
            {
277 5aaf27a2 djkim
                MessageBox.Show("Err:" + ex.ToString());
278 787a4489 KangIngu
            }
279 f7e7a61a ljiyeon
            finally
280
            {
281 cdfb57ff taeseongkim
                await SplashScreenAsnyc();
282 1137be84 djkim
            }
283 787a4489 KangIngu
        }
284 a7346d3c humkyung
285 1c7f408a taeseongkim
        private KeyValuePair<bool, string> UpdateCheck(StartupEventArgs startupEvents)
286
        {
287
            bool isUpdateCheck = false;
288
            string updateurl = string.Empty;
289
            try
290
            {
291
                bool is64bit = Environment.Is64BitProcess;
292
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
293
                ServiceDeepViewClient BaseClient = new ServiceDeepViewClient(_binding, _EndPoint);
294
                updateurl = BaseClient.GetVersionData(is64bit, clientversion);
295
296
                if (Check_Uri.isUri(updateurl))
297
                {
298 f3c08420 taeseongkim
                    base.OnStartup(startupEvents);
299
300
                    var updateWin = new UpdateWindow(updateurl);
301
302
                    updateWin.UpdatePassEvent += (snd, evt) =>
303 1c7f408a taeseongkim
                    {
304 f3c08420 taeseongkim
                        updateWin.Visibility = Visibility.Hidden;
305
                        new MainWindow().Show();
306 1c7f408a taeseongkim
                    };
307
308 f3c08420 taeseongkim
                    updateWin.ShowDialog();
309 1c7f408a taeseongkim
                }
310
                else
311
                {
312
                    base.OnStartup(startupEvents);
313
                    (new MainWindow()).Show();
314
                }
315
            }
316
            catch (Exception)
317
            {
318
                throw;
319
            }
320
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
321
        }
322
323
324 cdfb57ff taeseongkim
        private async Task<bool> SplashScreenAsnyc()
325
        {
326
            int value = 100 / ISplashMessage.SplashMessageCnt;
327
328
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
329
            {
330
                System.Threading.Thread.Sleep(3);
331
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
332
            }
333
334
            splashScreen.Close();
335
336
            return true;
337
        }
338
339 e0cfc73c ljiyeon
        public static void splashString(string text)
340
        {
341
            Task.Factory.StartNew(() =>
342
            {
343
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
344
            });
345
        }
346
347
348 a7346d3c humkyung
        /// <summary>
349
        /// log unhandled exception
350
        /// </summary>
351
        /// <author>humkyung</author>
352
        /// <date>2019.05.21</date>
353
        /// <param name="sender"></param>
354
        /// <param name="e"></param>
355
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
356
        {
357
            try
358
            {
359 360e4f75 djkim
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
360
                //App.DBLogger.Fatal(e.ExceptionObject as Exception);
361 a7346d3c humkyung
            }
362
            catch (Exception ex)
363
            {
364 8614f701 taeseongkim
                Console.WriteLine(ex.InnerException?.ToString());
365 a7346d3c humkyung
            }
366
            finally
367
            {
368 8614f701 taeseongkim
#if RELEASE
369 a7346d3c humkyung
                Environment.Exit(0);
370 8614f701 taeseongkim
#endif
371 a7346d3c humkyung
            }
372
        }
373
374 c4a4d59c ljiyeon
        private void ErrorLogFileWrite(string Err)
375
        {
376 ce3f0d7a humkyung
            App.FileLogger.Debug(Err);
377 c4a4d59c ljiyeon
        }
378 787a4489 KangIngu
    }
379
}
클립보드 이미지 추가 (최대 크기: 500 MB)