프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 8e6884a5

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

1

2
using KCOM.Common;
3
using KCOM.Views;
4
using log4net;
5
using System;
6
using System.ComponentModel;
7
using System.IO;
8
using System.Linq;
9
using System.ServiceModel;
10
using System.Threading.Tasks;
11
using System.Windows;
12
using System.Windows.Input;
13
using System.Windows.Resources;
14
using log4net;
15

    
16
namespace KCOM
17
{
18
    public class OpenProperties
19
    {
20
        public string DocumentItemID { get; set; }
21
        public bool bPartner { get; set; }
22
        public bool CreateFinalPDFPermission { get; set; }
23
        public bool NewCommentPermission { get; set; }
24
        public string ProjectNO { get; set; }
25
        public string UserID { get; set; }
26
        public int Mode { get; set; }
27
    }
28
    /// <summary>
29
    /// App.xaml에 대한 상호 작용 논리
30
    /// </summary>
31
    public partial class App : Application
32
    {
33
        public static PageManager.PageStorage PageStorage;
34

    
35
        public static BasicHttpBinding _binding;
36
        public static EndpointAddress _EndPoint;
37
        public static EndpointAddress _EndPoint_SaveLoad;
38
        public static EndpointAddress _EndPoint_Symbol;
39
        public static string UserID;
40
        public static string UserName;
41
        public static string UserIP;
42
        public static IKCOM.ViewInfo ViewInfo;
43
        public static string urlHost;
44
        public static string urlPort;
45
        public static string urlHost_DB;
46
        public static string urlPort_DB;
47
        public static string Custom_ViewInfoId;
48
        public static bool ParameterMode = false;
49
        public static bool isExternal = false;
50

    
51
        /// <summary>
52
        /// logger
53
        /// </summary>
54
        public static ILog FileLogger = null;
55
        
56
        public static StreamResourceInfo DefaultArrowCursor;
57

    
58
        public static Stream DefaultArrowCursorStream
59
        {
60
            get {
61
                DefaultArrowCursor.Stream.Position = 0;
62
                return DefaultArrowCursor.Stream;
63
            }
64
        }
65

    
66
        /// <summary>
67
        /// 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
        /// 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

    
96
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
97

    
98

    
99
        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
        private string versionPath = null;
112
        //public SplashScreen splash = new SplashScreen("splash.png");
113
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
114

    
115
        public App()
116
        {
117
            Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.VisualStudio2013Theme();
118

    
119
            App.FileLogger = LogManager.GetLogger(typeof(App));
120
        }
121

    
122
        protected override void OnExit(ExitEventArgs e)
123
        {
124
            try
125
            {
126
                if (App.PageStorage != null)
127
                {
128
                    App.PageStorage.Clear();
129
                }
130
            }
131
            catch (Exception)
132
            {
133
            }
134

    
135
            base.OnExit(e);
136
        }
137

    
138
        protected override async void OnStartup(StartupEventArgs e)
139
        {
140
            try
141
            {
142
                DefaultArrowCursor = Application.GetResourceStream(new Uri(@"pack://application:,,,/Resources/Cursor/customCursor2.cur", UriKind.Absolute));
143

    
144
                splashScreen.Show();
145

    
146
                App.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
147
                /// up to here
148
                //AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
149

    
150
                #region  //  DNS 체크
151

    
152
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
153

    
154
                ViewerDataModel.Instance.IsDocumentHistory = Convert.ToBoolean(CommonLib.Common.GetConfigString("COMMON","IsDocumentHistory", "true"));
155

    
156
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
157
                
158
                if (hostEntry == null)
159
                {
160
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
161
                    App.FileLogger.Debug("hostEntry == null");
162
                    isExternal = true;
163
                }
164
                else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper()))
165
                {
166
                    // 외부 사용자
167
                    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
                    isExternal = true;
169
                }
170
                #endregion
171

    
172

    
173
                if (e.Args.Count() > 0)
174
                {
175
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
176
                    App.ViewInfo = new IKCOM.ViewInfo
177
                    {
178
                        DocumentItemID = result.DocumentItemID,
179
                        EnsembleID = result.DocumentItemID,
180
                        //DocumentItemID = "10001",
181
                        bPartner = result.bPartner,
182
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
183
                        NewCommentPermission = result.NewCommentPermission,
184
                        ProjectNO = result.ProjectNO,
185
                        UserID = result.UserID,
186
                        //UserID = "H2009115",
187
                        //Mode = 0 , 1 , 2
188
                    };
189
                    ParameterMode = true;
190
                } 
191
                else
192
                {
193
                    string[] strArg = Environment.GetCommandLineArgs();
194
                    if (strArg.Length > 1)
195
                    {
196
                        var result = ParamDecoding(strArg[1].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
                        MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내");
215
                        throw new ArgumentException("문서 정보가 입력되지 않았습니다.");
216
                    }
217
                }
218

    
219
                //App.ViewInfo.CreateFinalPDFPermission = false;
220
                //App.ViewInfo.NewCommentPermission = false;
221
                //GetQueryStringParameters();
222
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
223
                _binding.MaxBufferSize = 2147483647;
224
                _binding.MaxReceivedMessageSize = 2147483647;
225
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
226
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
227
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
228
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
229
                _binding.TextEncoding = System.Text.Encoding.UTF8;
230
                _binding.TransferMode = TransferMode.Buffered;
231
                //Support.SetLicense();
232

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

    
235
#if DEBUG
236
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
237
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
238
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
239
#else
240
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
241
#endif
242
                App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
243
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
244

    
245
                await SplashScreenAsnyc();
246
                base.OnStartup(e);
247

    
248
                System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent);
249
            }
250
            catch (Exception ex)
251
            {
252
                Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1);
253
            }
254
            finally
255
            {
256
                await SplashScreenAsnyc();
257
            }
258
        }
259

    
260
        private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
261
        {
262

    
263
            Logger.sendReqLog("App Error ",e.Exception.ToString() + " " + e.Exception.InnerException?.ToString(), 1);
264
        }
265

    
266
        private void KeyDownEvent(object sender, KeyEventArgs e)
267
        {
268
            //if (e.Key == Key.Escape || e.Key == Key.Delete)
269
            //{
270
                System.Diagnostics.Debug.WriteLine("app key Event");
271
                Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e);
272
            //}
273
        }
274

    
275
        private async Task<bool> SplashScreenAsnyc()
276
        {
277
            int value = 100 / ISplashMessage.SplashMessageCnt;
278

    
279
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
280
            {
281
                await Task.Delay(3);
282
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
283
            }
284

    
285
            splashScreen.Close();
286

    
287
            return true;
288
        }
289

    
290
        public static void splashString(string text)
291
        {
292
            Task.Factory.StartNew(() =>
293
            {
294
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
295
            }).ConfigureAwait(false);
296
        }
297

    
298

    
299
        /// <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
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
311
            }
312
            catch (Exception ex)
313
            {
314
                Console.WriteLine(ex.InnerException?.ToString());
315
            }
316
            finally
317
            {
318
#if RELEASE
319
                Environment.Exit(0);
320
#endif
321
            }
322
        }
323

    
324
        private void ErrorLogFileWrite(string Err)
325
        {
326
            App.FileLogger.Debug(Err);
327
        }
328
    }
329
}
클립보드 이미지 추가 (최대 크기: 500 MB)