프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 0b75c341

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

1

2
using KCOM.Common;
3
using KCOM.ServiceDeepView;
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

    
24
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
25
namespace KCOM
26
{
27
    public class OpenProperties
28
    {
29
        public string DocumentItemID { get; set; }
30
        public bool bPartner { get; set; }
31
        public bool CreateFinalPDFPermission { get; set; }
32
        public bool NewCommentPermission { get; set; }
33
        public string ProjectNO { get; set; }
34
        public string UserID { get; set; }
35
        public int Mode { get; set; }
36

    
37
        /// <summary>
38
        /// pemss에서 전달되는 ID
39
        /// </summary>
40
        public string pId { get; set; }
41

    
42
        /// <summary>
43
        /// pemss에서 전달되는 ID
44
        /// </summary>
45
        public string uId { get; set; }
46
    }
47
    /// <summary>
48
    /// App.xaml에 대한 상호 작용 논리
49
    /// </summary>
50
    public partial class App : Application
51
    {
52
        public static bool IsDesignMode
53
        {
54
            get
55
            {
56
                return DesignerProperties.GetIsInDesignMode(new DependencyObject());
57
            }
58
            private set { }
59
        }
60

    
61
        public static BasicHttpBinding _binding;
62
        public static EndpointAddress _EndPoint;
63
        public static EndpointAddress _PemssEndPoint;
64
        public static EndpointAddress _EndPoint_SaveLoad;
65
        public static EndpointAddress _EndPoint_Symbol;
66
        public static string UserID;
67
        public static string UserName;
68
        public static string UserIP;
69
        public static IKCOM.ViewInfo ViewInfo;
70
        public static IKCOM.PEMSSInfo PEMSSInfo;
71
        public static string urlHost;
72
        public static string urlPort;
73
        public static string urlHost_DB;
74
        public static string urlPort_DB;
75
        public static string Custom_ViewInfoId;
76
        public static bool ParameterMode = false;
77
        public static bool isExternal = false;
78

    
79
        /// <summary>
80
        /// logger
81
        /// </summary>
82
        public static ILog DBLogger = null;
83
        public static ILog FileLogger = null;
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

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

    
100

    
101
        private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null)
102
        {
103
            if (oEncoding == null)
104
                oEncoding = System.Text.Encoding.UTF8;
105

    
106
            byte[] byteArray = Convert.FromBase64String(DecodingText);
107

    
108
            string jsonBack = oEncoding.GetString(byteArray);
109

    
110
            return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack);
111
        }
112

    
113
        private string versionPath = null;
114
        //public SplashScreen splash = new SplashScreen("splash.png");
115
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
116

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

    
122
        protected override async void OnStartup(StartupEventArgs e)
123
        {
124

    
125
            try
126
            {
127

    
128

    
129
                splashScreen.Show();
130

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

    
144
                #region  //  DNS 체크
145

    
146
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
147

    
148
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
149

    
150
                if (hostEntry == null)
151
                {
152
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
153
                    App.FileLogger.Fatal("hostEntry == null");
154
                    isExternal = true;
155
                }
156
                else if (!hostEntry.HostName.EndsWith(localdomain))
157
                {
158
                    // 외부 사용자
159
                    App.FileLogger.Fatal("hostEntry != localdomain :" + hostEntry.HostName);
160
                    isExternal = true;
161
                }
162
                #endregion
163
                //splash.Show(false, false);                
164

    
165
                if (e.Args.Count() > 0)
166
                {
167
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
168
                    App.ViewInfo = new IKCOM.ViewInfo
169
                    {
170
                        DocumentItemID = result.DocumentItemID,
171
                        EnsembleID = result.DocumentItemID,
172
                        //DocumentItemID = "10001",
173
                        bPartner = result.bPartner,
174
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
175
                        NewCommentPermission = result.NewCommentPermission,
176
                        ProjectNO = result.ProjectNO,
177
                        UserID = result.UserID,
178
                        //UserID = "H2009115",
179
                        //Mode = 0 , 1 , 2
180
                    };
181

    
182
                    App.PEMSSInfo = new IKCOM.PEMSSInfo
183
                    {
184
                        UserID = result.uId
185
                    };
186

    
187
                    ParameterMode = true;
188
                }
189
                else
190
                {
191
                    string[] strArg = Environment.GetCommandLineArgs();
192
                    if (strArg.Length > 1)
193
                    {
194
                        //label1.Text = strArg[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

    
211
                        App.PEMSSInfo = new IKCOM.PEMSSInfo
212
                        {
213
                            UserID = result.uId
214
                        };
215

    
216
                        ParameterMode = true;
217
                    }
218
                }
219

    
220
                //App.ViewInfo.CreateFinalPDFPermission = false;
221
                //App.ViewInfo.NewCommentPermission = false;
222
                //GetQueryStringParameters();
223
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
224
                _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

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

    
236
#if DEBUG
237
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
238
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
239
                sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "", isExternal);
240
#else
241
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
242
#endif
243

    
244
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
245

    
246
#if DEBUG
247
                _PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", "http://localhost:13009"));
248
#else
249
                          _PemssEndPoint = new EndpointAddress(string.Format("{0}/PemssService.svc", sBaseServiceURL));
250
#endif
251

    
252
                await SplashScreenAsnyc();
253
                base.OnStartup(e);
254

    
255
                //this.MainWindow = new MainWindow();
256

    
257
            }
258
            catch (Exception ex)
259
            {
260
                MessageBox.Show("Err:" + ex.ToString());
261
            }
262
            finally
263
            {
264
                await SplashScreenAsnyc();
265
            }
266
        }
267

    
268
        private async Task<bool> SplashScreenAsnyc()
269
        {
270
            int value = 100 / ISplashMessage.SplashMessageCnt;
271

    
272
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
273
            {
274
                System.Threading.Thread.Sleep(3);
275
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
276
            }
277

    
278
            splashScreen.Close();
279

    
280
            return true;
281
        }
282

    
283
        public static void splashString(string text)
284
        {
285
            Task.Factory.StartNew(() =>
286
            {
287
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
288
            });
289
        }
290

    
291

    
292
        /// <summary>
293
        /// log unhandled exception
294
        /// </summary>
295
        /// <author>humkyung</author>
296
        /// <date>2019.05.21</date>
297
        /// <param name="sender"></param>
298
        /// <param name="e"></param>
299
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
300
        {
301
            try
302
            {
303
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
304
                //App.DBLogger.Fatal(e.ExceptionObject as Exception);
305
            }
306
            catch (Exception ex)
307
            {
308
                Console.WriteLine(ex.InnerException?.ToString());
309
            }
310
            finally
311
            {
312
#if RELEASE
313
                Environment.Exit(0);
314
#endif
315
            }
316
        }
317

    
318
        private void ErrorLogFileWrite(string Err)
319
        {
320
            App.FileLogger.Debug(Err);
321
        }
322
    }
323
}
클립보드 이미지 추가 (최대 크기: 500 MB)