프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ ff01c725

이력 | 보기 | 이력해설 | 다운로드 (10.7 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
            try
104
            {
105
                splashScreen.Show();
106

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

    
120
                #region  //  DNS 체크
121

    
122
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
123

    
124
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
125

    
126
                if (hostEntry == null)
127
                {
128
                    System.Diagnostics.Debug.WriteLine("(hostEntry == null");
129
                    App.FileLogger.Debug("hostEntry == null");
130
                    isExternal = true;
131
                }
132
                else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain))
133
                {
134
                    // 외부 사용자
135
                    App.FileLogger.Debug(string.Format("You are external user because located out side of given domain({0})\nYour domain is {1}", localdomain, hostEntry.HostName));
136
                    isExternal = true;
137
                }
138
                #endregion
139

    
140
                if (e.Args.Count() > 0)
141
                {
142
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
143
                    App.ViewInfo = new IKCOM.ViewInfo
144
                    {
145
                        DocumentItemID = result.DocumentItemID,
146
                        EnsembleID = result.DocumentItemID,
147
                        //DocumentItemID = "10001",
148
                        bPartner = result.bPartner,
149
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
150
                        NewCommentPermission = result.NewCommentPermission,
151
                        ProjectNO = result.ProjectNO,
152
                        UserID = result.UserID,
153
                        //UserID = "H2009115",
154
                        //Mode = 0 , 1 , 2
155
                    };
156
                    ParameterMode = true;
157
                }
158
                else
159
                {
160
                    string[] strArg = Environment.GetCommandLineArgs();
161
                    if (strArg.Length > 1)
162
                    {
163
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
164
                        App.ViewInfo = new IKCOM.ViewInfo
165
                        {
166
                            DocumentItemID = result.DocumentItemID,
167
                            EnsembleID = result.DocumentItemID,
168
                            //DocumentItemID = "10001",
169
                            bPartner = result.bPartner,
170
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
171
                            NewCommentPermission = result.NewCommentPermission,
172
                            ProjectNO = result.ProjectNO,
173
                            UserID = result.UserID,
174
                            //UserID = "H2009115",
175
                            //Mode = 0 , 1 , 2
176
                        };
177
                        ParameterMode = true;
178
                    }
179
                    else
180
                    {
181
                        MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내");
182
                        throw new ArgumentException("문서 정보가 입력되지 않았습니다.");
183
                    }
184
                }
185

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

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

    
202
#if DEBUG
203
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
204
                System.Diagnostics.Debug.WriteLine("sBaseServiceURL");
205
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
206
#else
207
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
208
#endif
209
                App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
210
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
211

    
212
                await SplashScreenAsnyc();
213
                base.OnStartup(e);
214
            }
215
            catch (Exception ex)
216
            {
217
                MessageBox.Show("Err:" + ex.ToString());
218
            }
219
            finally
220
            {
221
                await SplashScreenAsnyc();
222
            }
223
        }
224

    
225
        private async Task<bool> SplashScreenAsnyc()
226
        {
227
            int value = 100 / ISplashMessage.SplashMessageCnt;
228

    
229
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
230
            {
231
                System.Threading.Thread.Sleep(3);
232
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
233
            }
234

    
235
            splashScreen.Close();
236

    
237
            return true;
238
        }
239

    
240
        public static void splashString(string text)
241
        {
242
            Task.Factory.StartNew(() =>
243
            {
244
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
245
            });
246
        }
247

    
248

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

    
274
        private void ErrorLogFileWrite(string Err)
275
        {
276
            App.FileLogger.Debug(Err);
277
        }
278
    }
279
}
클립보드 이미지 추가 (최대 크기: 500 MB)