프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ aa42c9c1

이력 | 보기 | 이력해설 | 다운로드 (12 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 787a4489 KangIngu
25 f280a4ce taeseongkim
[assembly: log4net.Config.XmlConfigurator(Watch = false)]
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
    }
38
    /// <summary>
39
    /// App.xaml에 대한 상호 작용 논리
40
    /// </summary>
41
    public partial class App : Application
42
    {
43 eeb0a39c taeseongkim
        public static PageManager.PageStorage PageStorage;
44
45 787a4489 KangIngu
        public static BasicHttpBinding _binding;
46
        public static EndpointAddress _EndPoint;
47
        public static EndpointAddress _EndPoint_SaveLoad;
48
        public static EndpointAddress _EndPoint_Symbol;
49
        public static string UserID;
50
        public static string UserName;
51
        public static string UserIP;
52
        public static IKCOM.ViewInfo ViewInfo;
53
        public static string urlHost;
54
        public static string urlPort;
55
        public static string urlHost_DB;
56
        public static string urlPort_DB;
57
        public static string Custom_ViewInfoId;
58
        public static bool ParameterMode = false;
59 84c48033 djkim
        public static bool isExternal = false;
60 787a4489 KangIngu
61 a7346d3c humkyung
        /// <summary>
62
        /// logger
63
        /// </summary>
64 ce3f0d7a humkyung
        public static ILog DBLogger = null;
65
        public static ILog FileLogger = null;
66 a7346d3c humkyung
67
        /// <summary>
68 2089959a taeseongkim
        /// VisualStudio Design Time여부
69
        /// </summary>
70
        public static bool IsDesignMode
71
        {
72
            get
73
            {
74
                try
75
                {
76
                    return DesignerProperties.GetIsInDesignMode(new DependencyObject());
77
                }
78
                catch (Exception)
79
                {
80
                    return false;
81
                }
82
            }
83
            private set { }
84
        }
85
86
        /// <summary>
87 a7346d3c humkyung
        /// Application Data Folder
88
        /// </summary>
89
        public static string AppDataFolder
90
        {
91
            get
92
            {
93
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS");
94
            }
95
        }
96 787a4489 KangIngu
97
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
98 1137be84 djkim
99 264c9309 ljiyeon
100 787a4489 KangIngu
        private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null)
101
        {
102
            if (oEncoding == null)
103
                oEncoding = System.Text.Encoding.UTF8;
104
105
            byte[] byteArray = Convert.FromBase64String(DecodingText);
106
107
            string jsonBack = oEncoding.GetString(byteArray);
108
109
            return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack);
110
        }
111
112 c4a4d59c ljiyeon
        private string versionPath = null;
113 cf2671a6 ljiyeon
        //public SplashScreen splash = new SplashScreen("splash.png");
114 e0cfc73c ljiyeon
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
115 cdfb57ff taeseongkim
116
        public App()
117
        {
118 aff63364 taeseongkim
            Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.VisualStudio2013Theme();
119 cdfb57ff taeseongkim
        }
120
121 eeb0a39c taeseongkim
        protected override void OnExit(ExitEventArgs e)
122
        {
123 81908c01 taeseongkim
            try
124
            {
125
                if (App.PageStorage != null)
126
                {
127
                    App.PageStorage.Clear();
128
                }
129
            }
130
            catch (Exception)
131
            {
132
            }
133 eeb0a39c taeseongkim
134
            base.OnExit(e);
135
        }
136
137 cdfb57ff taeseongkim
        protected override async void OnStartup(StartupEventArgs e)
138
        {
139 787a4489 KangIngu
            try
140 a7346d3c humkyung
            {
141 cf2671a6 ljiyeon
                splashScreen.Show();
142 1137be84 djkim
143 a7346d3c humkyung
                /// create log database and table
144 2917ab4a taeseongkim
                //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
150
                //log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db");
151
                //App.DBLogger = LogManager.GetLogger("DBLogger");
152
153 a7346d3c humkyung
                /// up to here
154
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
155 2917ab4a taeseongkim
                
156 ce3f0d7a humkyung
                log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log");
157 2917ab4a taeseongkim
158 ce3f0d7a humkyung
                App.FileLogger = LogManager.GetLogger("EventLogger");
159 a7346d3c humkyung
160 1137be84 djkim
                #region  //  DNS 체크
161
162
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
163
164
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
165 df33d20a djkim
                
166 1137be84 djkim
                if (hostEntry == null)
167
                {
168
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
169 1ed8da93 humkyung
                    App.FileLogger.Debug("hostEntry == null");
170 1137be84 djkim
                    isExternal = true;
171
                }
172 ddfd4bc7 djkim
                else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper()))
173 1137be84 djkim
                {
174
                    // 외부 사용자
175 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));
176 1137be84 djkim
                    isExternal = true;
177
                }
178
                #endregion
179
180 366f00c2 taeseongkim
181 787a4489 KangIngu
                if (e.Args.Count() > 0)
182
                {
183 c4a4d59c ljiyeon
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
184 787a4489 KangIngu
                    App.ViewInfo = new IKCOM.ViewInfo
185
                    {
186
                        DocumentItemID = result.DocumentItemID,
187 35afe17c djkim
                        EnsembleID = result.DocumentItemID,
188 787a4489 KangIngu
                        //DocumentItemID = "10001",
189
                        bPartner = result.bPartner,
190 bc664e9b djkim
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
191
                        NewCommentPermission = result.NewCommentPermission,
192 787a4489 KangIngu
                        ProjectNO = result.ProjectNO,
193
                        UserID = result.UserID,
194
                        //UserID = "H2009115",
195
                        //Mode = 0 , 1 , 2
196
                    };
197
                    ParameterMode = true;
198
                }
199 c4a4d59c ljiyeon
                else
200
                {
201
                    string[] strArg = Environment.GetCommandLineArgs();
202
                    if (strArg.Length > 1)
203
                    {
204
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
205
                        App.ViewInfo = new IKCOM.ViewInfo
206
                        {
207
                            DocumentItemID = result.DocumentItemID,
208 35afe17c djkim
                            EnsembleID = result.DocumentItemID,
209 c4a4d59c ljiyeon
                            //DocumentItemID = "10001",
210
                            bPartner = result.bPartner,
211
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
212
                            NewCommentPermission = result.NewCommentPermission,
213
                            ProjectNO = result.ProjectNO,
214
                            UserID = result.UserID,
215
                            //UserID = "H2009115",
216
                            //Mode = 0 , 1 , 2
217
                        };
218
                        ParameterMode = true;
219 1137be84 djkim
                    }
220 1ed8da93 humkyung
                    else
221
                    {
222
                        MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내");
223
                        throw new ArgumentException("문서 정보가 입력되지 않았습니다.");
224
                    }
225 c4a4d59c ljiyeon
                }
226 992a98b4 KangIngu
227
                //App.ViewInfo.CreateFinalPDFPermission = false;
228
                //App.ViewInfo.NewCommentPermission = false;
229 c4a4d59c ljiyeon
                //GetQueryStringParameters();
230
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
231 787a4489 KangIngu
                _binding.MaxBufferSize = 2147483647;
232
                _binding.MaxReceivedMessageSize = 2147483647;
233
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
234
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
235
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
236
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
237
                _binding.TextEncoding = System.Text.Encoding.UTF8;
238
                _binding.TransferMode = TransferMode.Buffered;
239
                //Support.SetLicense();
240 af22332b ljiyeon
241 84c48033 djkim
                string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "");
242 1137be84 djkim
243 84c48033 djkim
#if DEBUG
244 eb5cdefc djkim
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
245 566f0526 taeseongkim
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
246 ff01c725 humkyung
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
247 992a98b4 KangIngu
#else
248 36d6ae21 taeseongkim
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
249 992a98b4 KangIngu
#endif
250 4eb4f3f9 humkyung
                App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
251 84c48033 djkim
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
252 264c9309 ljiyeon
253 cdfb57ff taeseongkim
                await SplashScreenAsnyc();
254
                base.OnStartup(e);
255 d97dbc7f taeseongkim
256 fa48eb85 taeseongkim
                System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent);
257 787a4489 KangIngu
            }
258
            catch (Exception ex)
259
            {
260 d0286794 taeseongkim
                Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1);
261 787a4489 KangIngu
            }
262 f7e7a61a ljiyeon
            finally
263
            {
264 cdfb57ff taeseongkim
                await SplashScreenAsnyc();
265 1137be84 djkim
            }
266 787a4489 KangIngu
        }
267 a7346d3c humkyung
268 fa48eb85 taeseongkim
        private void KeyDownEvent(object sender, KeyEventArgs e)
269
        {
270
            if (e.Key == Key.Escape || e.Key == Key.Delete)
271
            {
272
                System.Diagnostics.Debug.WriteLine("app key Event");
273
                Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e);
274
            }
275
        }
276
277 cdfb57ff taeseongkim
        private async Task<bool> SplashScreenAsnyc()
278
        {
279
            int value = 100 / ISplashMessage.SplashMessageCnt;
280
281
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
282
            {
283 d33ef543 taeseongkim
                await Task.Delay(3);
284 cdfb57ff taeseongkim
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
285
            }
286
287
            splashScreen.Close();
288
289
            return true;
290
        }
291
292 e0cfc73c ljiyeon
        public static void splashString(string text)
293
        {
294
            Task.Factory.StartNew(() =>
295
            {
296
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
297 2917ab4a taeseongkim
            }).ConfigureAwait(false);
298 e0cfc73c ljiyeon
        }
299
300
301 a7346d3c humkyung
        /// <summary>
302
        /// log unhandled exception
303
        /// </summary>
304
        /// <author>humkyung</author>
305
        /// <date>2019.05.21</date>
306
        /// <param name="sender"></param>
307
        /// <param name="e"></param>
308
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
309
        {
310
            try
311
            {
312 360e4f75 djkim
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
313 a7346d3c humkyung
            }
314
            catch (Exception ex)
315
            {
316 8614f701 taeseongkim
                Console.WriteLine(ex.InnerException?.ToString());
317 a7346d3c humkyung
            }
318
            finally
319
            {
320 8614f701 taeseongkim
#if RELEASE
321 a7346d3c humkyung
                Environment.Exit(0);
322 8614f701 taeseongkim
#endif
323 a7346d3c humkyung
            }
324
        }
325
326 c4a4d59c ljiyeon
        private void ErrorLogFileWrite(string Err)
327
        {
328 ce3f0d7a humkyung
            App.FileLogger.Debug(Err);
329 c4a4d59c ljiyeon
        }
330 787a4489 KangIngu
    }
331
}
클립보드 이미지 추가 (최대 크기: 500 MB)