프로젝트

일반

사용자정보

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

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

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

1 787a4489 KangIngu

2 af22332b ljiyeon
using KCOM.Common;
3 6b6e937c taeseongkim
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 fa48eb85 taeseongkim
using System.Windows.Input;
24 902faaea taeseongkim
using System.Windows.Resources;
25 787a4489 KangIngu
26 f280a4ce taeseongkim
[assembly: log4net.Config.XmlConfigurator(Watch = false)]
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
    }
39
    /// <summary>
40
    /// App.xaml에 대한 상호 작용 논리
41
    /// </summary>
42
    public partial class App : Application
43
    {
44 eeb0a39c taeseongkim
        public static PageManager.PageStorage PageStorage;
45
46 787a4489 KangIngu
        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 84c48033 djkim
        public static bool isExternal = false;
61 787a4489 KangIngu
62 a7346d3c humkyung
        /// <summary>
63
        /// logger
64
        /// </summary>
65 ce3f0d7a humkyung
        public static ILog DBLogger = null;
66
        public static ILog FileLogger = null;
67 902faaea taeseongkim
        
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 a7346d3c humkyung
78
        /// <summary>
79 2089959a taeseongkim
        /// 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 a7346d3c humkyung
        /// 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 787a4489 KangIngu
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 aff63364 taeseongkim
            Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.VisualStudio2013Theme();
130 cdfb57ff taeseongkim
        }
131
132 eeb0a39c taeseongkim
        protected override void OnExit(ExitEventArgs e)
133
        {
134 81908c01 taeseongkim
            try
135
            {
136
                if (App.PageStorage != null)
137
                {
138
                    App.PageStorage.Clear();
139
                }
140
            }
141
            catch (Exception)
142
            {
143
            }
144 eeb0a39c taeseongkim
145
            base.OnExit(e);
146
        }
147
148 cdfb57ff taeseongkim
        protected override async void OnStartup(StartupEventArgs e)
149
        {
150 787a4489 KangIngu
            try
151 a7346d3c humkyung
            {
152 902faaea taeseongkim
                DefaultArrowCursor = Application.GetResourceStream(new Uri(@"pack://application:,,,/Resources/Cursor/customCursor2.cur", UriKind.Absolute));
153
154 cf2671a6 ljiyeon
                splashScreen.Show();
155 1137be84 djkim
156 a7346d3c humkyung
                /// create log database and table
157 2917ab4a taeseongkim
                //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 a7346d3c humkyung
                /// up to here
167
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
168 2917ab4a taeseongkim
                
169 ce3f0d7a humkyung
                log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log");
170 2917ab4a taeseongkim
171 ce3f0d7a humkyung
                App.FileLogger = LogManager.GetLogger("EventLogger");
172 a7346d3c humkyung
173 1137be84 djkim
                #region  //  DNS 체크
174
175
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
176
177
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
178 df33d20a djkim
                
179 1137be84 djkim
                if (hostEntry == null)
180
                {
181
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
182 1ed8da93 humkyung
                    App.FileLogger.Debug("hostEntry == null");
183 1137be84 djkim
                    isExternal = true;
184
                }
185 ddfd4bc7 djkim
                else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper()))
186 1137be84 djkim
                {
187
                    // 외부 사용자
188 1ed8da93 humkyung
                    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 1137be84 djkim
                    isExternal = true;
190
                }
191
                #endregion
192
193 366f00c2 taeseongkim
194 787a4489 KangIngu
                if (e.Args.Count() > 0)
195
                {
196 c4a4d59c ljiyeon
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
197 787a4489 KangIngu
                    App.ViewInfo = new IKCOM.ViewInfo
198
                    {
199
                        DocumentItemID = result.DocumentItemID,
200 35afe17c djkim
                        EnsembleID = result.DocumentItemID,
201 787a4489 KangIngu
                        //DocumentItemID = "10001",
202
                        bPartner = result.bPartner,
203 bc664e9b djkim
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
204
                        NewCommentPermission = result.NewCommentPermission,
205 787a4489 KangIngu
                        ProjectNO = result.ProjectNO,
206
                        UserID = result.UserID,
207
                        //UserID = "H2009115",
208
                        //Mode = 0 , 1 , 2
209
                    };
210
                    ParameterMode = true;
211
                }
212 c4a4d59c ljiyeon
                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 35afe17c djkim
                            EnsembleID = result.DocumentItemID,
222 c4a4d59c ljiyeon
                            //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 1137be84 djkim
                    }
233 1ed8da93 humkyung
                    else
234
                    {
235
                        MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내");
236
                        throw new ArgumentException("문서 정보가 입력되지 않았습니다.");
237
                    }
238 c4a4d59c ljiyeon
                }
239 992a98b4 KangIngu
240
                //App.ViewInfo.CreateFinalPDFPermission = false;
241
                //App.ViewInfo.NewCommentPermission = false;
242 c4a4d59c ljiyeon
                //GetQueryStringParameters();
243
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
244 787a4489 KangIngu
                _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 af22332b ljiyeon
254 84c48033 djkim
                string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "");
255 1137be84 djkim
256 84c48033 djkim
#if DEBUG
257 eb5cdefc djkim
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
258 566f0526 taeseongkim
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
259 ff01c725 humkyung
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
260 992a98b4 KangIngu
#else
261 36d6ae21 taeseongkim
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
262 992a98b4 KangIngu
#endif
263 4eb4f3f9 humkyung
                App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
264 84c48033 djkim
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
265 264c9309 ljiyeon
266 cdfb57ff taeseongkim
                await SplashScreenAsnyc();
267
                base.OnStartup(e);
268 d97dbc7f taeseongkim
269 fa48eb85 taeseongkim
                System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent);
270 787a4489 KangIngu
            }
271
            catch (Exception ex)
272
            {
273 d0286794 taeseongkim
                Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1);
274 787a4489 KangIngu
            }
275 f7e7a61a ljiyeon
            finally
276
            {
277 cdfb57ff taeseongkim
                await SplashScreenAsnyc();
278 1137be84 djkim
            }
279 787a4489 KangIngu
        }
280 a7346d3c humkyung
281 fa48eb85 taeseongkim
        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 cdfb57ff taeseongkim
        private async Task<bool> SplashScreenAsnyc()
291
        {
292
            int value = 100 / ISplashMessage.SplashMessageCnt;
293
294
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
295
            {
296 d33ef543 taeseongkim
                await Task.Delay(3);
297 cdfb57ff taeseongkim
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
298
            }
299
300
            splashScreen.Close();
301
302
            return true;
303
        }
304
305 e0cfc73c ljiyeon
        public static void splashString(string text)
306
        {
307
            Task.Factory.StartNew(() =>
308
            {
309
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
310 2917ab4a taeseongkim
            }).ConfigureAwait(false);
311 e0cfc73c ljiyeon
        }
312
313
314 a7346d3c humkyung
        /// <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 360e4f75 djkim
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
326 a7346d3c humkyung
            }
327
            catch (Exception ex)
328
            {
329 8614f701 taeseongkim
                Console.WriteLine(ex.InnerException?.ToString());
330 a7346d3c humkyung
            }
331
            finally
332
            {
333 8614f701 taeseongkim
#if RELEASE
334 a7346d3c humkyung
                Environment.Exit(0);
335 8614f701 taeseongkim
#endif
336 a7346d3c humkyung
            }
337
        }
338
339 c4a4d59c ljiyeon
        private void ErrorLogFileWrite(string Err)
340
        {
341 ce3f0d7a humkyung
            App.FileLogger.Debug(Err);
342 c4a4d59c ljiyeon
        }
343 787a4489 KangIngu
    }
344
}
클립보드 이미지 추가 (최대 크기: 500 MB)