markus / KCOM / App.xaml.cs @ 3e8c830d
이력 | 보기 | 이력해설 | 다운로드 (15.5 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 |
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 |
private string versionPath = null; |
91 |
//public SplashScreen splash = new SplashScreen("splash.png"); |
92 |
public static SplashScreenWindow splashScreen = new SplashScreenWindow(); |
93 |
protected override void OnStartup(StartupEventArgs e) |
94 |
{ |
95 |
try |
96 |
{ |
97 |
splashScreen.Show(); |
98 |
|
99 |
/// 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 |
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 |
|
112 |
//splash.Show(false, false); |
113 |
|
114 |
if (e.Args.Count() > 0) |
115 |
{ |
116 |
var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
117 |
App.ViewInfo = new IKCOM.ViewInfo |
118 |
{ |
119 |
DocumentItemID = result.DocumentItemID, |
120 |
EnsembleID = result.DocumentItemID, |
121 |
//DocumentItemID = "10001", |
122 |
bPartner = result.bPartner, |
123 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
124 |
NewCommentPermission = result.NewCommentPermission, |
125 |
ProjectNO = result.ProjectNO, |
126 |
UserID = result.UserID, |
127 |
//UserID = "H2009115", |
128 |
//Mode = 0 , 1 , 2 |
129 |
}; |
130 |
ParameterMode = true; |
131 |
} |
132 |
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 |
EnsembleID = result.DocumentItemID, |
144 |
//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 |
|
157 |
//App.ViewInfo.CreateFinalPDFPermission = false; |
158 |
//App.ViewInfo.NewCommentPermission = false; |
159 |
|
160 |
//GetQueryStringParameters(); |
161 |
_binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
162 |
_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 |
|
172 |
string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", ""); |
173 |
string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", ""); |
174 |
var ipaddress = CommonLib.DNSHelper.GetDnsAdress(); |
175 |
|
176 |
try |
177 |
{ |
178 |
var hostName = Dns.GetHostEntry(ipaddress).HostName; |
179 |
|
180 |
if (!hostName.EndsWith(localdomain)) |
181 |
{ |
182 |
// 외부 사용자 |
183 |
isExternal = true; |
184 |
} |
185 |
} |
186 |
catch (Exception ex) |
187 |
{ |
188 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
189 |
} |
190 |
|
191 |
#if DEBUG |
192 |
//sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
193 |
sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "",isExternal); |
194 |
#else |
195 |
sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
196 |
#endif |
197 |
|
198 |
_EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
199 |
|
200 |
if (Environment.Is64BitProcess == true) //64 bit machine |
201 |
{ |
202 |
versionPath = CommonLib.Common.GetConfigString("UpdateVer64", "URL", "", isExternal); |
203 |
} |
204 |
else //32 bit machine |
205 |
{ |
206 |
versionPath = CommonLib.Common.GetConfigString("UpdateVer86", "URL", "", isExternal); |
207 |
} |
208 |
|
209 |
if (File.Exists(versionPath)) |
210 |
{ |
211 |
// 20180921 version.xml check로 변경 |
212 |
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
213 |
try |
214 |
{ |
215 |
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 |
{ |
221 |
//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 |
} |
235 |
else |
236 |
{ |
237 |
// splash.Close(new TimeSpan(0, 0, 2)); |
238 |
Task.Factory.StartNew(() => |
239 |
{ |
240 |
int value = 100 / ISplashMessage.SplashMessageCnt; |
241 |
for (int i = 1; i <= ISplashMessage.SplashMessageCnt ; i++) |
242 |
{ |
243 |
System.Threading.Thread.Sleep(3); |
244 |
splashScreen.Dispatcher.Invoke(() => splashScreen.Progress = i * value); |
245 |
} |
246 |
this.Dispatcher.Invoke(() => |
247 |
{ |
248 |
base.OnStartup(e); |
249 |
splashScreen.Close(); |
250 |
}); |
251 |
|
252 |
}); |
253 |
} |
254 |
} |
255 |
catch (Exception ex) //2. 파일이 없거나 파일내에 version의 값이 없다면 KCOM 실행하기 |
256 |
{ |
257 |
ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ex); |
258 |
|
259 |
Task.Factory.StartNew(() => |
260 |
{ |
261 |
int value = 100 / ISplashMessage.SplashMessageCnt; |
262 |
for (int i = 1; i <= ISplashMessage.SplashMessageCnt; i++) |
263 |
{ |
264 |
System.Threading.Thread.Sleep(3); |
265 |
splashScreen.Dispatcher.Invoke(() => splashScreen.Progress = i * value); |
266 |
} |
267 |
|
268 |
this.Dispatcher.Invoke(() => |
269 |
{ |
270 |
base.OnStartup(e); |
271 |
splashScreen.Close(); |
272 |
}); |
273 |
}); |
274 |
} |
275 |
} |
276 |
} |
277 |
catch (Exception ex) |
278 |
{ |
279 |
MessageBox.Show("Err:" + ex.ToString()); |
280 |
} |
281 |
finally |
282 |
{ |
283 |
Task.Factory.StartNew(() => |
284 |
{ |
285 |
int value = 100 / ISplashMessage.SplashMessageCnt; |
286 |
for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++) |
287 |
{ |
288 |
System.Threading.Thread.Sleep(3); |
289 |
|
290 |
splashScreen.Dispatcher.Invoke(() => splashScreen.Progress = i * value); |
291 |
|
292 |
//App. |
293 |
} |
294 |
this.Dispatcher.Invoke(() => |
295 |
{ |
296 |
//base.OnStartup(e); |
297 |
splashScreen.Close(); |
298 |
}); |
299 |
}); |
300 |
} |
301 |
|
302 |
} |
303 |
|
304 |
public static void splashString(string text) |
305 |
{ |
306 |
Task.Factory.StartNew(() => |
307 |
{ |
308 |
splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text); |
309 |
}); |
310 |
} |
311 |
|
312 |
|
313 |
|
314 |
/// <summary> |
315 |
/// log unhandled exception |
316 |
/// </summary> |
317 |
/// <author>humkyung</author> |
318 |
/// <date>2019.05.21</date> |
319 |
/// <param name="sender"></param> |
320 |
/// <param name="e"></param> |
321 |
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) |
322 |
{ |
323 |
try |
324 |
{ |
325 |
App.DBLogger.Fatal(e.ExceptionObject as Exception); |
326 |
} |
327 |
catch (Exception ex) |
328 |
{ |
329 |
Console.WriteLine(ex.InnerException.ToString()); |
330 |
} |
331 |
finally |
332 |
{ |
333 |
Environment.Exit(0); |
334 |
} |
335 |
} |
336 |
|
337 |
protected void UpdateCheck(StartupEventArgs e) |
338 |
{ |
339 |
try |
340 |
{ |
341 |
if (e.Args.Count() > 0) |
342 |
{ |
343 |
ProcessStartInfo proInfo = new ProcessStartInfo(); |
344 |
var FileName = AppDomain.CurrentDomain.BaseDirectory + "SmartUpdate.exe"; |
345 |
|
346 |
Process.Start(FileName, e.Args[0]); |
347 |
|
348 |
base.Shutdown(); |
349 |
//현재 실행되고 있는 자기 자신 프로세스의 정보 |
350 |
Process proc = Process.GetCurrentProcess(); |
351 |
proc.Kill(); |
352 |
} |
353 |
} |
354 |
catch(Exception ee) |
355 |
{ |
356 |
ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ee); |
357 |
} |
358 |
} |
359 |
|
360 |
private void ErrorLogFileWrite(string Err) |
361 |
{ |
362 |
App.FileLogger.Debug(Err); |
363 |
/* |
364 |
try |
365 |
{ |
366 |
string pathString = AppDataFolder + "\\Err"; |
367 |
|
368 |
if (!File.Exists(pathString)) |
369 |
{ |
370 |
Directory.CreateDirectory(pathString); |
371 |
} |
372 |
|
373 |
Err = Err + " " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\r\n"; |
374 |
string path = pathString + "\\" + "Log_" + DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".txt"; |
375 |
File.AppendAllText(path, Err); |
376 |
} |
377 |
catch (Exception er) |
378 |
{ |
379 |
string strError = er.ToString(); |
380 |
} |
381 |
*/ |
382 |
} |
383 |
} |
384 |
} |