프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 52889f5e

이력 | 보기 | 이력해설 | 다운로드 (10.4 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
    /// App.xaml에 대한 상호 작용 논리
39
    /// </summary>
40
    public partial class App : Application
41
    {
42
        public static BasicHttpBinding _binding;
43
        public static EndpointAddress _EndPoint;
44
        public static EndpointAddress _EndPoint_SaveLoad;
45
        public static EndpointAddress _EndPoint_Symbol;
46
        public static string UserID;
47
        public static string UserName;
48
        public static string UserIP;
49
        public static IKCOM.ViewInfo ViewInfo;
50
        public static string urlHost;
51
        public static string urlPort;
52
        public static string urlHost_DB;
53
        public static string urlPort_DB;
54
        public static string Custom_ViewInfoId;
55
        public static bool ParameterMode = false;
56
        public static bool isExternal = false;
57

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

    
64
        /// <summary>
65
        /// Application Data Folder
66
        /// </summary>
67
        public static string AppDataFolder
68
        {
69
            get
70
            {
71
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS");
72
            }
73
        }
74

    
75

    
76
        public static RestSharp.RestClient BaseClient { get; set; }
77
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
78

    
79

    
80
        private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null)
81
        {
82
            if (oEncoding == null)
83
                oEncoding = System.Text.Encoding.UTF8;
84

    
85
            byte[] byteArray = Convert.FromBase64String(DecodingText);
86

    
87
            string jsonBack = oEncoding.GetString(byteArray);
88

    
89
            return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack);
90
        }
91

    
92
        private string versionPath = null;
93
        //public SplashScreen splash = new SplashScreen("splash.png");
94
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
95

    
96
        public App()
97
        {
98
            Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.VisualStudio2013Theme();
99
        }
100

    
101
        protected override async void OnStartup(StartupEventArgs e)
102
        {
103

    
104
            try
105
            {
106

    
107

    
108
                splashScreen.Show();
109

    
110
                /// create log database and table
111
                using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") })
112
                {
113
                    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);";
114
                    database.ExecuteNonQuery(sSql);
115
                }
116
                /// up to here
117
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
118
                log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db");
119
                log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log");
120
                App.DBLogger = LogManager.GetLogger("DBLogger");
121
                App.FileLogger = LogManager.GetLogger("EventLogger");
122

    
123
                #region  //  DNS 체크
124

    
125
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
126

    
127
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
128

    
129
                if (hostEntry == null)
130
                {
131
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
132
                    App.FileLogger.Fatal("hostEntry == null");
133
                    isExternal = true;
134
                }
135
                else if (!hostEntry.HostName.EndsWith(localdomain))
136
                {
137
                    // 외부 사용자
138
                    App.FileLogger.Fatal("hostEntry != localdomain :" + hostEntry.HostName);
139
                    isExternal = true;
140
                }
141
                #endregion
142
                //splash.Show(false, false);                
143

    
144
                if (e.Args.Count() > 0)
145
                {
146
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
147
                    App.ViewInfo = new IKCOM.ViewInfo
148
                    {
149
                        DocumentItemID = result.DocumentItemID,
150
                        EnsembleID = result.DocumentItemID,
151
                        //DocumentItemID = "10001",
152
                        bPartner = result.bPartner,
153
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
154
                        NewCommentPermission = result.NewCommentPermission,
155
                        ProjectNO = result.ProjectNO,
156
                        UserID = result.UserID,
157
                        //UserID = "H2009115",
158
                        //Mode = 0 , 1 , 2
159
                    };
160
                    ParameterMode = true;
161
                }
162
                else
163
                {
164
                    string[] strArg = Environment.GetCommandLineArgs();
165
                    if (strArg.Length > 1)
166
                    {
167
                        //label1.Text = strArg[1];
168

    
169
                        var result = ParamDecoding(strArg[1].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
                        ParameterMode = true;
184
                    }
185
                }
186

    
187
                //App.ViewInfo.CreateFinalPDFPermission = false;
188
                //App.ViewInfo.NewCommentPermission = false;
189
                //GetQueryStringParameters();
190
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
191
                _binding.MaxBufferSize = 2147483647;
192
                _binding.MaxReceivedMessageSize = 2147483647;
193
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
194
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
195
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
196
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
197
                _binding.TextEncoding = System.Text.Encoding.UTF8;
198
                _binding.TransferMode = TransferMode.Buffered;
199
                //Support.SetLicense();
200

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

    
203
#if DEBUG
204
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
205
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
206
                sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "", isExternal);
207
#else
208
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
209
#endif
210

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

    
213
                await SplashScreenAsnyc();
214
                base.OnStartup(e);
215

    
216
                //this.MainWindow = new MainWindow();
217

    
218
            }
219
            catch (Exception ex)
220
            {
221
                MessageBox.Show("Err:" + ex.ToString());
222
            }
223
            finally
224
            {
225
                await SplashScreenAsnyc();
226
            }
227
        }
228

    
229
        private async Task<bool> SplashScreenAsnyc()
230
        {
231
            int value = 100 / ISplashMessage.SplashMessageCnt;
232

    
233
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
234
            {
235
                System.Threading.Thread.Sleep(3);
236
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
237
            }
238

    
239
            splashScreen.Close();
240

    
241
            return true;
242
        }
243

    
244
        public static void splashString(string text)
245
        {
246
            Task.Factory.StartNew(() =>
247
            {
248
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
249
            });
250
        }
251

    
252

    
253
        /// <summary>
254
        /// log unhandled exception
255
        /// </summary>
256
        /// <author>humkyung</author>
257
        /// <date>2019.05.21</date>
258
        /// <param name="sender"></param>
259
        /// <param name="e"></param>
260
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
261
        {
262
            try
263
            {
264
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
265
                //App.DBLogger.Fatal(e.ExceptionObject as Exception);
266
            }
267
            catch (Exception ex)
268
            {
269
                Console.WriteLine(ex.InnerException?.ToString());
270
            }
271
            finally
272
            {
273
#if RELEASE
274
                Environment.Exit(0);
275
#endif
276
            }
277
        }
278

    
279
        private void ErrorLogFileWrite(string Err)
280
        {
281
            App.FileLogger.Debug(Err);
282
        }
283
    }
284
}
클립보드 이미지 추가 (최대 크기: 500 MB)