프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ 2089959a

이력 | 보기 | 이력해설 | 다운로드 (11.2 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
        /// VisualStudio Design Time여부
66
        /// </summary>
67
        public static bool IsDesignMode
68
        {
69
            get
70
            {
71
                try
72
                {
73
                    return DesignerProperties.GetIsInDesignMode(new DependencyObject());
74
                }
75
                catch (Exception)
76
                {
77
                    return false;
78
                }
79
            }
80
            private set { }
81
        }
82

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

    
94

    
95
        public static RestSharp.RestClient BaseClient { get; set; }
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

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

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

    
139
                #region  //  DNS 체크
140

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

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

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

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

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

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

    
231
                await SplashScreenAsnyc();
232
                base.OnStartup(e);
233
            }
234
            catch (Exception ex)
235
            {
236
                MessageBox.Show("Err:" + ex.ToString());
237
            }
238
            finally
239
            {
240
                await SplashScreenAsnyc();
241
            }
242
        }
243

    
244
        private async Task<bool> SplashScreenAsnyc()
245
        {
246
            int value = 100 / ISplashMessage.SplashMessageCnt;
247

    
248
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
249
            {
250
                System.Threading.Thread.Sleep(3);
251
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
252
            }
253

    
254
            splashScreen.Close();
255

    
256
            return true;
257
        }
258

    
259
        public static void splashString(string text)
260
        {
261
            Task.Factory.StartNew(() =>
262
            {
263
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
264
            });
265
        }
266

    
267

    
268
        /// <summary>
269
        /// log unhandled exception
270
        /// </summary>
271
        /// <author>humkyung</author>
272
        /// <date>2019.05.21</date>
273
        /// <param name="sender"></param>
274
        /// <param name="e"></param>
275
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
276
        {
277
            try
278
            {
279
                App.FileLogger.Fatal(e.ExceptionObject as Exception);
280
            }
281
            catch (Exception ex)
282
            {
283
                Console.WriteLine(ex.InnerException?.ToString());
284
            }
285
            finally
286
            {
287
#if RELEASE
288
                Environment.Exit(0);
289
#endif
290
            }
291
        }
292

    
293
        private void ErrorLogFileWrite(string Err)
294
        {
295
            App.FileLogger.Debug(Err);
296
        }
297
    }
298
}
클립보드 이미지 추가 (최대 크기: 500 MB)