프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 7f8a2ff4

이력 | 보기 | 이력해설 | 다운로드 (11.6 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

    
25
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
26
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
        public static BasicHttpBinding _binding;
44
        public static EndpointAddress _EndPoint;
45
        public static EndpointAddress _EndPoint_SaveLoad;
46
        public static EndpointAddress _EndPoint_Symbol;
47
        public static string UserID;
48
        public static string UserName;
49
        public static string UserIP;
50
        public static IKCOM.ViewInfo ViewInfo;
51
        public static string urlHost;
52
        public static string urlPort;
53
        public static string urlHost_DB;
54
        public static string urlPort_DB;
55
        public static string Custom_ViewInfoId;
56
        public static bool ParameterMode = false;
57
        public static bool isExternal = false;
58

    
59
        /// <summary>
60
        /// logger
61
        /// </summary>
62
        public static ILog DBLogger = null;
63
        public static ILog FileLogger = null;
64

    
65
        /// <summary>
66
        /// VisualStudio Design Time여부
67
        /// </summary>
68
        public static bool IsDesignMode
69
        {
70
            get
71
            {
72
                try
73
                {
74
                    return DesignerProperties.GetIsInDesignMode(new DependencyObject());
75
                }
76
                catch (Exception)
77
                {
78
                    return false;
79
                }
80
            }
81
            private set { }
82
        }
83

    
84
        /// <summary>
85
        /// Application Data Folder
86
        /// </summary>
87
        public static string AppDataFolder
88
        {
89
            get
90
            {
91
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS");
92
            }
93
        }
94

    
95

    
96
        public static RestSharp.RestClient BaseClient { get; set; }
97
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
98

    
99

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

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

    
121
        protected override async void OnStartup(StartupEventArgs e)
122
        {
123
            try
124
            {
125
                splashScreen.Show();
126

    
127
                /// create log database and table
128
                using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") })
129
                {
130
                    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);";
131
                    database.ExecuteNonQuery(sSql);
132
                }
133
                /// up to here
134
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
135
                log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db");
136
                log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log");
137
                App.DBLogger = LogManager.GetLogger("DBLogger");
138
                App.FileLogger = LogManager.GetLogger("EventLogger");
139

    
140
                #region  //  DNS 체크
141

    
142
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
143

    
144
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
145
                
146
                if (hostEntry == null)
147
                {
148
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
149
                    App.FileLogger.Debug("hostEntry == null");
150
                    isExternal = true;
151
                }
152
                else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper()))
153
                {
154
                    // 외부 사용자
155
                    App.FileLogger.Debug(string.Format("You are external user because located out side of given domain({0})\nYour domain is {1}", localdomain, hostEntry.HostName));
156
                    isExternal = true;
157
                }
158
                #endregion
159

    
160
                if (e.Args.Count() > 0)
161
                {
162
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
163
                    App.ViewInfo = new IKCOM.ViewInfo
164
                    {
165
                        DocumentItemID = result.DocumentItemID,
166
                        EnsembleID = result.DocumentItemID,
167
                        //DocumentItemID = "10001",
168
                        bPartner = result.bPartner,
169
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
170
                        NewCommentPermission = result.NewCommentPermission,
171
                        ProjectNO = result.ProjectNO,
172
                        UserID = result.UserID,
173
                        //UserID = "H2009115",
174
                        //Mode = 0 , 1 , 2
175
                    };
176
                    ParameterMode = true;
177
                }
178
                else
179
                {
180
                    string[] strArg = Environment.GetCommandLineArgs();
181
                    if (strArg.Length > 1)
182
                    {
183
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
184
                        App.ViewInfo = new IKCOM.ViewInfo
185
                        {
186
                            DocumentItemID = result.DocumentItemID,
187
                            EnsembleID = result.DocumentItemID,
188
                            //DocumentItemID = "10001",
189
                            bPartner = result.bPartner,
190
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
191
                            NewCommentPermission = result.NewCommentPermission,
192
                            ProjectNO = result.ProjectNO,
193
                            UserID = result.UserID,
194
                            //UserID = "H2009115",
195
                            //Mode = 0 , 1 , 2
196
                        };
197
                        ParameterMode = true;
198
                    }
199
                    else
200
                    {
201
                        MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내");
202
                        throw new ArgumentException("문서 정보가 입력되지 않았습니다.");
203
                    }
204
                }
205

    
206
                //App.ViewInfo.CreateFinalPDFPermission = false;
207
                //App.ViewInfo.NewCommentPermission = false;
208
                //GetQueryStringParameters();
209
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
210
                _binding.MaxBufferSize = 2147483647;
211
                _binding.MaxReceivedMessageSize = 2147483647;
212
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
213
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
214
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
215
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
216
                _binding.TextEncoding = System.Text.Encoding.UTF8;
217
                _binding.TransferMode = TransferMode.Buffered;
218
                //Support.SetLicense();
219

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

    
222
#if DEBUG
223
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
224
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
225
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
226
#else
227
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
228
#endif
229
                App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
230
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
231

    
232
                await SplashScreenAsnyc();
233
                base.OnStartup(e);
234
                
235
                System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent);
236
            }
237
            catch (Exception ex)
238
            {
239
                MessageBox.Show("Err:" + ex.ToString());
240
            }
241
            finally
242
            {
243
                await SplashScreenAsnyc();
244
            }
245
        }
246

    
247
        private void KeyDownEvent(object sender, KeyEventArgs e)
248
        {
249
            if (e.Key == Key.Escape || e.Key == Key.Delete)
250
            {
251
                System.Diagnostics.Debug.WriteLine("app key Event");
252
                Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e);
253
            }
254
        }
255

    
256
        private async Task<bool> SplashScreenAsnyc()
257
        {
258
            int value = 100 / ISplashMessage.SplashMessageCnt;
259

    
260
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
261
            {
262
                System.Threading.Thread.Sleep(3);
263
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
264
            }
265

    
266
            splashScreen.Close();
267

    
268
            return true;
269
        }
270

    
271
        public static void splashString(string text)
272
        {
273
            Task.Factory.StartNew(() =>
274
            {
275
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
276
            });
277
        }
278

    
279

    
280
        /// <summary>
281
        /// log unhandled exception
282
        /// </summary>
283
        /// <author>humkyung</author>
284
        /// <date>2019.05.21</date>
285
        /// <param name="sender"></param>
286
        /// <param name="e"></param>
287
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
288
        {
289
            try
290
            {
291
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
292
            }
293
            catch (Exception ex)
294
            {
295
                Console.WriteLine(ex.InnerException?.ToString());
296
            }
297
            finally
298
            {
299
#if RELEASE
300
                Environment.Exit(0);
301
#endif
302
            }
303
        }
304

    
305
        private void ErrorLogFileWrite(string Err)
306
        {
307
            App.FileLogger.Debug(Err);
308
        }
309
    }
310
}
클립보드 이미지 추가 (최대 크기: 500 MB)