프로젝트

일반

사용자정보

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

markus / KCOM_Backup_2019.09.26_03.36.14 / App.xaml.cs @ b10671a4

이력 | 보기 | 이력해설 | 다운로드 (11.6 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
        public string cId { get; set; }
48
    }
49
    /// <summary>
50
    /// App.xaml에 대한 상호 작용 논리
51
    /// </summary>
52
    public partial class App : Application
53
    {
54
        public static bool IsDesignMode
55
        {
56
            get
57
            {
58
                return DesignerProperties.GetIsInDesignMode(new DependencyObject());
59
            }
60
            private set { }
61
        }
62

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

    
81
        /// <summary>
82
        /// logger
83
        /// </summary>
84
        public static ILog DBLogger = null;
85
        public static ILog FileLogger = null;
86

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

    
98

    
99
        public static RestSharp.RestClient BaseClient { get; set; }
100
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
101

    
102

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

    
108
            byte[] byteArray = Convert.FromBase64String(DecodingText);
109

    
110
            string jsonBack = oEncoding.GetString(byteArray);
111

    
112
            return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack);
113
        }
114

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

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

    
124
        protected override async void OnStartup(StartupEventArgs e)
125
        {
126

    
127
            try
128
            {
129

    
130

    
131
                splashScreen.Show();
132

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

    
146
                #region  //  DNS 체크
147

    
148
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
149

    
150
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
151

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

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

    
184
                    App.PEMSSInfo = new IKCOM.PEMSSInfo
185
                    {
186
                        UserID = result.uId,
187
                        CommentID = result.cId
188
                    };
189

    
190
                    ParameterMode = true;
191
                }
192
                else
193
                {
194
                    string[] strArg = Environment.GetCommandLineArgs();
195
                    if (strArg.Length > 1)
196
                    {
197
                        //label1.Text = strArg[1];
198

    
199
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
200
                        App.ViewInfo = new IKCOM.ViewInfo
201
                        {
202
                            DocumentItemID = result.DocumentItemID,
203
                            EnsembleID = result.DocumentItemID,
204
                            //DocumentItemID = "10001",
205
                            bPartner = result.bPartner,
206
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
207
                            NewCommentPermission = result.NewCommentPermission,
208
                            ProjectNO = result.ProjectNO,
209
                            UserID = result.UserID,
210
                            //UserID = "H2009115",
211
                            //Mode = 0 , 1 , 2
212
                        };
213

    
214
                        App.PEMSSInfo = new IKCOM.PEMSSInfo
215
                        {
216
                            UserID = result.uId
217
                        };
218

    
219
                        ParameterMode = true;
220
                    }
221
                }
222

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

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

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

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

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

    
255
                await SplashScreenAsnyc();
256
                base.OnStartup(e);
257

    
258
                //this.MainWindow = new MainWindow();
259

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

    
271
        private async Task<bool> SplashScreenAsnyc()
272
        {
273
            int value = 100 / ISplashMessage.SplashMessageCnt;
274

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

    
281
            splashScreen.Close();
282

    
283
            return true;
284
        }
285

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

    
294

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

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