markus / KCOM / App.xaml.cs @ cf2671a6
이력 | 보기 | 이력해설 | 다운로드 (14.8 KB)
1 | 787a4489 | KangIngu | |
---|---|---|---|
2 | af22332b | ljiyeon | using KCOM.Common; |
3 | c4a4d59c | ljiyeon | using KCOM.ServiceDeepView; |
4 | 787a4489 | KangIngu | using System; |
5 | using System.Collections.Generic; |
||
6 | using System.ComponentModel; |
||
7 | using System.Configuration; |
||
8 | using System.Data; |
||
9 | c4a4d59c | ljiyeon | using System.Diagnostics; |
10 | using System.IO; |
||
11 | 787a4489 | KangIngu | using System.Linq; |
12 | c4a4d59c | ljiyeon | using System.Net; |
13 | using System.Reflection; |
||
14 | 787a4489 | KangIngu | using System.Runtime.CompilerServices; |
15 | using System.ServiceModel; |
||
16 | using System.Windows; |
||
17 | c4a4d59c | ljiyeon | using System.Xml; |
18 | a7346d3c | humkyung | using log4net; |
19 | e52385b9 | ljiyeon | using System.Text; |
20 | using System.Runtime.InteropServices; |
||
21 | cf2671a6 | ljiyeon | using KCOM.Views; |
22 | using System.Threading.Tasks; |
||
23 | 787a4489 | KangIngu | |
24 | a7346d3c | humkyung | [assembly: log4net.Config.XmlConfigurator(Watch = true)] |
25 | 787a4489 | KangIngu | 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 | 84c48033 | djkim | public static bool isExternal = false; |
57 | 787a4489 | KangIngu | |
58 | a7346d3c | humkyung | /// <summary> |
59 | /// logger |
||
60 | /// </summary> |
||
61 | ce3f0d7a | humkyung | public static ILog DBLogger = null; |
62 | public static ILog FileLogger = null; |
||
63 | a7346d3c | humkyung | |
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 | 787a4489 | KangIngu | |
75 | 5928384e | djkim | |
76 | 787a4489 | KangIngu | public static RestSharp.RestClient BaseClient { get; set; } |
77 | public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; } |
||
78 | private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null) |
||
79 | { |
||
80 | if (oEncoding == null) |
||
81 | oEncoding = System.Text.Encoding.UTF8; |
||
82 | |||
83 | byte[] byteArray = Convert.FromBase64String(DecodingText); |
||
84 | |||
85 | string jsonBack = oEncoding.GetString(byteArray); |
||
86 | |||
87 | return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack); |
||
88 | } |
||
89 | |||
90 | c4a4d59c | ljiyeon | private string versionPath = null; |
91 | cf2671a6 | ljiyeon | //public SplashScreen splash = new SplashScreen("splash.png"); |
92 | public SplashScreenWindow splashScreen = new SplashScreenWindow(); |
||
93 | 787a4489 | KangIngu | protected override void OnStartup(StartupEventArgs e) |
94 | cf2671a6 | ljiyeon | { |
95 | 787a4489 | KangIngu | try |
96 | a7346d3c | humkyung | { |
97 | cf2671a6 | ljiyeon | splashScreen.Show(); |
98 | |||
99 | a7346d3c | humkyung | /// create log database and table |
100 | using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") }) |
||
101 | { |
||
102 | 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);"; |
||
103 | database.ExecuteNonQuery(sSql); |
||
104 | } |
||
105 | /// up to here |
||
106 | AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |
||
107 | ce3f0d7a | humkyung | log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db"); |
108 | log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log"); |
||
109 | App.DBLogger = LogManager.GetLogger("DBLogger"); |
||
110 | App.FileLogger = LogManager.GetLogger("EventLogger"); |
||
111 | a7346d3c | humkyung | |
112 | cf2671a6 | ljiyeon | //splash.Show(false, false); |
113 | |||
114 | 787a4489 | KangIngu | if (e.Args.Count() > 0) |
115 | { |
||
116 | c4a4d59c | ljiyeon | var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
117 | 787a4489 | KangIngu | App.ViewInfo = new IKCOM.ViewInfo |
118 | { |
||
119 | DocumentItemID = result.DocumentItemID, |
||
120 | 35afe17c | djkim | EnsembleID = result.DocumentItemID, |
121 | 787a4489 | KangIngu | //DocumentItemID = "10001", |
122 | bPartner = result.bPartner, |
||
123 | bc664e9b | djkim | CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
124 | NewCommentPermission = result.NewCommentPermission, |
||
125 | 787a4489 | KangIngu | ProjectNO = result.ProjectNO, |
126 | UserID = result.UserID, |
||
127 | //UserID = "H2009115", |
||
128 | //Mode = 0 , 1 , 2 |
||
129 | }; |
||
130 | ParameterMode = true; |
||
131 | } |
||
132 | c4a4d59c | ljiyeon | else |
133 | { |
||
134 | string[] strArg = Environment.GetCommandLineArgs(); |
||
135 | if (strArg.Length > 1) |
||
136 | { |
||
137 | //label1.Text = strArg[1]; |
||
138 | |||
139 | var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", "")); |
||
140 | App.ViewInfo = new IKCOM.ViewInfo |
||
141 | { |
||
142 | DocumentItemID = result.DocumentItemID, |
||
143 | 35afe17c | djkim | EnsembleID = result.DocumentItemID, |
144 | c4a4d59c | ljiyeon | //DocumentItemID = "10001", |
145 | bPartner = result.bPartner, |
||
146 | CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
||
147 | NewCommentPermission = result.NewCommentPermission, |
||
148 | ProjectNO = result.ProjectNO, |
||
149 | UserID = result.UserID, |
||
150 | //UserID = "H2009115", |
||
151 | //Mode = 0 , 1 , 2 |
||
152 | }; |
||
153 | ParameterMode = true; |
||
154 | } |
||
155 | } |
||
156 | 992a98b4 | KangIngu | |
157 | //App.ViewInfo.CreateFinalPDFPermission = false; |
||
158 | //App.ViewInfo.NewCommentPermission = false; |
||
159 | |||
160 | c4a4d59c | ljiyeon | //GetQueryStringParameters(); |
161 | _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
||
162 | 787a4489 | KangIngu | _binding.MaxBufferSize = 2147483647; |
163 | _binding.MaxReceivedMessageSize = 2147483647; |
||
164 | _binding.OpenTimeout = new TimeSpan(0, 1, 0); |
||
165 | _binding.ReceiveTimeout = new TimeSpan(0, 10, 0); |
||
166 | _binding.CloseTimeout = new TimeSpan(0, 5, 0); |
||
167 | _binding.SendTimeout = new TimeSpan(0, 5, 0); |
||
168 | _binding.TextEncoding = System.Text.Encoding.UTF8; |
||
169 | _binding.TransferMode = TransferMode.Buffered; |
||
170 | //Support.SetLicense(); |
||
171 | af22332b | ljiyeon | |
172 | 84c48033 | djkim | string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", ""); |
173 | string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", ""); |
||
174 | eb5cdefc | djkim | var ipaddress = CommonLib.DNSHelper.GetDnsAdress(); |
175 | af22332b | ljiyeon | |
176 | try |
||
177 | { |
||
178 | var hostName = Dns.GetHostEntry(ipaddress).HostName; |
||
179 | |||
180 | 84c48033 | djkim | if (!hostName.EndsWith(localdomain)) |
181 | af22332b | ljiyeon | { |
182 | // 외부 사용자 |
||
183 | 84c48033 | djkim | isExternal = true; |
184 | af22332b | ljiyeon | } |
185 | } |
||
186 | catch (Exception ex) |
||
187 | { |
||
188 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
189 | } |
||
190 | 814116a9 | humkyung | |
191 | 84c48033 | djkim | #if DEBUG |
192 | eb5cdefc | djkim | //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
193 | 19391ad3 | djkim | sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "",isExternal); |
194 | 992a98b4 | KangIngu | #else |
195 | 84c48033 | djkim | sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
196 | 992a98b4 | KangIngu | #endif |
197 | eb5cdefc | djkim | |
198 | 84c48033 | djkim | _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
199 | |||
200 | c4a4d59c | ljiyeon | if (Environment.Is64BitProcess == true) //64 bit machine |
201 | { |
||
202 | 84c48033 | djkim | versionPath = CommonLib.Common.GetConfigString("UpdateVer64", "URL", "", isExternal); |
203 | c4a4d59c | ljiyeon | } |
204 | else //32 bit machine |
||
205 | { |
||
206 | 84c48033 | djkim | versionPath = CommonLib.Common.GetConfigString("UpdateVer86", "URL", "", isExternal); |
207 | c4a4d59c | ljiyeon | } |
208 | |||
209 | af22332b | ljiyeon | if (File.Exists(versionPath)) |
210 | c4a4d59c | ljiyeon | { |
211 | af22332b | ljiyeon | // 20180921 version.xml check로 변경 |
212 | var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
||
213 | try |
||
214 | c4a4d59c | ljiyeon | { |
215 | af22332b | ljiyeon | XmlDocument xdoc = new XmlDocument(); |
216 | xdoc.Load(versionPath); |
||
217 | XmlNode node = xdoc.SelectSingleNode("/RootElement/version"); |
||
218 | |||
219 | if (assemblyVersion != node.InnerText) // node.InnerText 가 null이면 catch로 빠짐 |
||
220 | c4a4d59c | ljiyeon | { |
221 | af22332b | ljiyeon | //if(MessageBox.Show("Ver. " + node.InnerText + " 업데이트가 있습니다.\r\nSmartUpdate를 실행합니다.", "MARKUS", MessageBoxButton.OKCancel) == MessageBoxResult.OK) |
222 | //{ |
||
223 | if (MessageBox.Show("Ver. " + node.InnerText, "MARKUS", MessageBoxButton.OKCancel) == MessageBoxResult.OK) |
||
224 | { |
||
225 | UpdateCheck(e); |
||
226 | } |
||
227 | else |
||
228 | { |
||
229 | base.Shutdown(); |
||
230 | //현재 실행되고 있는 자기 자신 프로세스의 정보 // 위에꺼랑 두개 다 써줄필요가 있는..가? |
||
231 | Process proc = Process.GetCurrentProcess(); |
||
232 | proc.Kill(); |
||
233 | } |
||
234 | c4a4d59c | ljiyeon | } |
235 | else |
||
236 | cf2671a6 | ljiyeon | { |
237 | // splash.Close(new TimeSpan(0, 0, 2)); |
||
238 | Task.Factory.StartNew(() => |
||
239 | { |
||
240 | for (int i = 1; i <= 100; i++) |
||
241 | { |
||
242 | System.Threading.Thread.Sleep(1); |
||
243 | splashScreen.Dispatcher.Invoke(() => splashScreen.Progress = i); |
||
244 | } |
||
245 | this.Dispatcher.Invoke(() => |
||
246 | { |
||
247 | base.OnStartup(e); |
||
248 | splashScreen.Close(); |
||
249 | }); |
||
250 | |||
251 | }); |
||
252 | c4a4d59c | ljiyeon | } |
253 | } |
||
254 | af22332b | ljiyeon | catch (Exception ex) //2. 파일이 없거나 파일내에 version의 값이 없다면 KCOM 실행하기 |
255 | c4a4d59c | ljiyeon | { |
256 | af22332b | ljiyeon | ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ex); |
257 | cf2671a6 | ljiyeon | |
258 | Task.Factory.StartNew(() => |
||
259 | { |
||
260 | for (int i = 1; i <= 100; i++) |
||
261 | { |
||
262 | System.Threading.Thread.Sleep(1); |
||
263 | splashScreen.Dispatcher.Invoke(() => splashScreen.Progress = i); |
||
264 | } |
||
265 | this.Dispatcher.Invoke(() => |
||
266 | { |
||
267 | base.OnStartup(e); |
||
268 | splashScreen.Close(); |
||
269 | }); |
||
270 | }); |
||
271 | } |
||
272 | c4a4d59c | ljiyeon | } |
273 | 787a4489 | KangIngu | } |
274 | catch (Exception ex) |
||
275 | { |
||
276 | 5aaf27a2 | djkim | MessageBox.Show("Err:" + ex.ToString()); |
277 | 787a4489 | KangIngu | } |
278 | f7e7a61a | ljiyeon | finally |
279 | { |
||
280 | cf2671a6 | ljiyeon | Task.Factory.StartNew(() => |
281 | { |
||
282 | for (int i = 1; i <= 100; i++) |
||
283 | { |
||
284 | System.Threading.Thread.Sleep(1); |
||
285 | splashScreen.Dispatcher.Invoke(() => splashScreen.Progress = i); |
||
286 | } |
||
287 | this.Dispatcher.Invoke(() => |
||
288 | { |
||
289 | //base.OnStartup(e); |
||
290 | splashScreen.Close(); |
||
291 | }); |
||
292 | }); |
||
293 | f7e7a61a | ljiyeon | } |
294 | cf2671a6 | ljiyeon | |
295 | 787a4489 | KangIngu | } |
296 | a7346d3c | humkyung | |
297 | /// <summary> |
||
298 | /// log unhandled exception |
||
299 | /// </summary> |
||
300 | /// <author>humkyung</author> |
||
301 | /// <date>2019.05.21</date> |
||
302 | /// <param name="sender"></param> |
||
303 | /// <param name="e"></param> |
||
304 | private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) |
||
305 | { |
||
306 | try |
||
307 | { |
||
308 | ce3f0d7a | humkyung | App.DBLogger.Fatal(e.ExceptionObject as Exception); |
309 | a7346d3c | humkyung | } |
310 | catch (Exception ex) |
||
311 | { |
||
312 | Console.WriteLine(ex.InnerException.ToString()); |
||
313 | } |
||
314 | finally |
||
315 | { |
||
316 | Environment.Exit(0); |
||
317 | } |
||
318 | } |
||
319 | |||
320 | c4a4d59c | ljiyeon | protected void UpdateCheck(StartupEventArgs e) |
321 | { |
||
322 | try |
||
323 | { |
||
324 | if (e.Args.Count() > 0) |
||
325 | { |
||
326 | ProcessStartInfo proInfo = new ProcessStartInfo(); |
||
327 | var FileName = AppDomain.CurrentDomain.BaseDirectory + "SmartUpdate.exe"; |
||
328 | |||
329 | Process.Start(FileName, e.Args[0]); |
||
330 | |||
331 | base.Shutdown(); |
||
332 | //현재 실행되고 있는 자기 자신 프로세스의 정보 |
||
333 | Process proc = Process.GetCurrentProcess(); |
||
334 | proc.Kill(); |
||
335 | } |
||
336 | } |
||
337 | catch(Exception ee) |
||
338 | { |
||
339 | ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ee); |
||
340 | } |
||
341 | } |
||
342 | |||
343 | private void ErrorLogFileWrite(string Err) |
||
344 | { |
||
345 | ce3f0d7a | humkyung | App.FileLogger.Debug(Err); |
346 | /* |
||
347 | c4a4d59c | ljiyeon | try |
348 | { |
||
349 | f7e7a61a | ljiyeon | string pathString = AppDataFolder + "\\Err"; |
350 | af22332b | ljiyeon | |
351 | c4a4d59c | ljiyeon | if (!File.Exists(pathString)) |
352 | { |
||
353 | Directory.CreateDirectory(pathString); |
||
354 | } |
||
355 | |||
356 | Err = Err + " " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\r\n"; |
||
357 | string path = pathString + "\\" + "Log_" + DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".txt"; |
||
358 | File.AppendAllText(path, Err); |
||
359 | } |
||
360 | catch (Exception er) |
||
361 | { |
||
362 | string strError = er.ToString(); |
||
363 | } |
||
364 | ce3f0d7a | humkyung | */ |
365 | c4a4d59c | ljiyeon | } |
366 | 787a4489 | KangIngu | } |
367 | } |