프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 902faaea

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

1

2
using KCOM.Common;
3

    
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 System.Windows.Input;
24
using System.Windows.Resources;
25

    
26
[assembly: log4net.Config.XmlConfigurator(Watch = false)]
27
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
    }
39
    /// <summary>
40
    /// App.xaml에 대한 상호 작용 논리
41
    /// </summary>
42
    public partial class App : Application
43
    {
44
        public static PageManager.PageStorage PageStorage;
45

    
46
        public static BasicHttpBinding _binding;
47
        public static EndpointAddress _EndPoint;
48
        public static EndpointAddress _EndPoint_SaveLoad;
49
        public static EndpointAddress _EndPoint_Symbol;
50
        public static string UserID;
51
        public static string UserName;
52
        public static string UserIP;
53
        public static IKCOM.ViewInfo ViewInfo;
54
        public static string urlHost;
55
        public static string urlPort;
56
        public static string urlHost_DB;
57
        public static string urlPort_DB;
58
        public static string Custom_ViewInfoId;
59
        public static bool ParameterMode = false;
60
        public static bool isExternal = false;
61

    
62
        /// <summary>
63
        /// logger
64
        /// </summary>
65
        public static ILog DBLogger = null;
66
        public static ILog FileLogger = null;
67
        
68
        public static StreamResourceInfo DefaultArrowCursor;
69

    
70
        public static Stream DefaultArrowCursorStream
71
        {
72
            get {
73
                DefaultArrowCursor.Stream.Position = 0;
74
                return DefaultArrowCursor.Stream;
75
            }
76
        }
77

    
78
        /// <summary>
79
        /// VisualStudio Design Time여부
80
        /// </summary>
81
        public static bool IsDesignMode
82
        {
83
            get
84
            {
85
                try
86
                {
87
                    return DesignerProperties.GetIsInDesignMode(new DependencyObject());
88
                }
89
                catch (Exception)
90
                {
91
                    return false;
92
                }
93
            }
94
            private set { }
95
        }
96

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

    
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.VisualStudio2013Theme();
130
        }
131

    
132
        protected override void OnExit(ExitEventArgs e)
133
        {
134
            try
135
            {
136
                if (App.PageStorage != null)
137
                {
138
                    App.PageStorage.Clear();
139
                }
140
            }
141
            catch (Exception)
142
            {
143
            }
144

    
145
            base.OnExit(e);
146
        }
147

    
148
        protected override async void OnStartup(StartupEventArgs e)
149
        {
150
            try
151
            {
152
                DefaultArrowCursor = Application.GetResourceStream(new Uri(@"pack://application:,,,/Resources/Cursor/customCursor2.cur", UriKind.Absolute));
153

    
154
                splashScreen.Show();
155

    
156
                /// create log database and table
157
                //using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") })
158
                //{
159
                //    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);";
160
                //    database.ExecuteNonQuery(sSql);
161
                //}
162

    
163
                //log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db");
164
                //App.DBLogger = LogManager.GetLogger("DBLogger");
165

    
166
                /// up to here
167
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
168
                
169
                log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log");
170

    
171
                App.FileLogger = LogManager.GetLogger("EventLogger");
172

    
173
                #region  //  DNS 체크
174

    
175
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
176

    
177
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
178
                
179
                if (hostEntry == null)
180
                {
181
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
182
                    App.FileLogger.Debug("hostEntry == null");
183
                    isExternal = true;
184
                }
185
                else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper()))
186
                {
187
                    // 외부 사용자
188
                    App.FileLogger.Debug(string.Format("You are external user because located out side of given domain({0})\nYour domain is {1}", localdomain, hostEntry.HostName));
189
                    isExternal = true;
190
                }
191
                #endregion
192

    
193

    
194
                if (e.Args.Count() > 0)
195
                {
196
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
197
                    App.ViewInfo = new IKCOM.ViewInfo
198
                    {
199
                        DocumentItemID = result.DocumentItemID,
200
                        EnsembleID = result.DocumentItemID,
201
                        //DocumentItemID = "10001",
202
                        bPartner = result.bPartner,
203
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
204
                        NewCommentPermission = result.NewCommentPermission,
205
                        ProjectNO = result.ProjectNO,
206
                        UserID = result.UserID,
207
                        //UserID = "H2009115",
208
                        //Mode = 0 , 1 , 2
209
                    };
210
                    ParameterMode = true;
211
                }
212
                else
213
                {
214
                    string[] strArg = Environment.GetCommandLineArgs();
215
                    if (strArg.Length > 1)
216
                    {
217
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
218
                        App.ViewInfo = new IKCOM.ViewInfo
219
                        {
220
                            DocumentItemID = result.DocumentItemID,
221
                            EnsembleID = result.DocumentItemID,
222
                            //DocumentItemID = "10001",
223
                            bPartner = result.bPartner,
224
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
225
                            NewCommentPermission = result.NewCommentPermission,
226
                            ProjectNO = result.ProjectNO,
227
                            UserID = result.UserID,
228
                            //UserID = "H2009115",
229
                            //Mode = 0 , 1 , 2
230
                        };
231
                        ParameterMode = true;
232
                    }
233
                    else
234
                    {
235
                        MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내");
236
                        throw new ArgumentException("문서 정보가 입력되지 않았습니다.");
237
                    }
238
                }
239

    
240
                //App.ViewInfo.CreateFinalPDFPermission = false;
241
                //App.ViewInfo.NewCommentPermission = false;
242
                //GetQueryStringParameters();
243
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
244
                _binding.MaxBufferSize = 2147483647;
245
                _binding.MaxReceivedMessageSize = 2147483647;
246
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
247
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
248
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
249
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
250
                _binding.TextEncoding = System.Text.Encoding.UTF8;
251
                _binding.TransferMode = TransferMode.Buffered;
252
                //Support.SetLicense();
253

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

    
256
#if DEBUG
257
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
258
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
259
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
260
#else
261
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
262
#endif
263
                App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
264
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
265

    
266
                await SplashScreenAsnyc();
267
                base.OnStartup(e);
268

    
269
                System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent);
270
            }
271
            catch (Exception ex)
272
            {
273
                Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1);
274
            }
275
            finally
276
            {
277
                await SplashScreenAsnyc();
278
            }
279
        }
280

    
281
        private void KeyDownEvent(object sender, KeyEventArgs e)
282
        {
283
            if (e.Key == Key.Escape || e.Key == Key.Delete)
284
            {
285
                System.Diagnostics.Debug.WriteLine("app key Event");
286
                Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e);
287
            }
288
        }
289

    
290
        private async Task<bool> SplashScreenAsnyc()
291
        {
292
            int value = 100 / ISplashMessage.SplashMessageCnt;
293

    
294
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
295
            {
296
                await Task.Delay(3);
297
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
298
            }
299

    
300
            splashScreen.Close();
301

    
302
            return true;
303
        }
304

    
305
        public static void splashString(string text)
306
        {
307
            Task.Factory.StartNew(() =>
308
            {
309
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
310
            }).ConfigureAwait(false);
311
        }
312

    
313

    
314
        /// <summary>
315
        /// log unhandled exception
316
        /// </summary>
317
        /// <author>humkyung</author>
318
        /// <date>2019.05.21</date>
319
        /// <param name="sender"></param>
320
        /// <param name="e"></param>
321
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
322
        {
323
            try
324
            {
325
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
326
            }
327
            catch (Exception ex)
328
            {
329
                Console.WriteLine(ex.InnerException?.ToString());
330
            }
331
            finally
332
            {
333
#if RELEASE
334
                Environment.Exit(0);
335
#endif
336
            }
337
        }
338

    
339
        private void ErrorLogFileWrite(string Err)
340
        {
341
            App.FileLogger.Debug(Err);
342
        }
343
    }
344
}
클립보드 이미지 추가 (최대 크기: 500 MB)