프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 6c45db59

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

1 787a4489 KangIngu

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