markus / KCOM / App.xaml.cs @ eb5cdefc
이력 | 보기 | 이력해설 | 다운로드 (12.9 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 | 787a4489 | KangIngu | |
22 | a7346d3c | humkyung | [assembly: log4net.Config.XmlConfigurator(Watch = true)] |
23 | 787a4489 | KangIngu | namespace KCOM |
24 | { |
||
25 | public class OpenProperties |
||
26 | { |
||
27 | public string DocumentItemID { get; set; } |
||
28 | public bool bPartner { get; set; } |
||
29 | public bool CreateFinalPDFPermission { get; set; } |
||
30 | public bool NewCommentPermission { get; set; } |
||
31 | public string ProjectNO { get; set; } |
||
32 | public string UserID { get; set; } |
||
33 | public int Mode { get; set; } |
||
34 | } |
||
35 | /// <summary> |
||
36 | /// App.xaml에 대한 상호 작용 논리 |
||
37 | /// </summary> |
||
38 | public partial class App : Application |
||
39 | { |
||
40 | public static BasicHttpBinding _binding; |
||
41 | public static EndpointAddress _EndPoint; |
||
42 | public static EndpointAddress _EndPoint_SaveLoad; |
||
43 | public static EndpointAddress _EndPoint_Symbol; |
||
44 | public static string UserID; |
||
45 | public static string UserName; |
||
46 | public static string UserIP; |
||
47 | public static IKCOM.ViewInfo ViewInfo; |
||
48 | public static string urlHost; |
||
49 | public static string urlPort; |
||
50 | public static string urlHost_DB; |
||
51 | public static string urlPort_DB; |
||
52 | public static string Custom_ViewInfoId; |
||
53 | public static bool ParameterMode = false; |
||
54 | 84c48033 | djkim | public static bool isExternal = false; |
55 | 787a4489 | KangIngu | |
56 | a7346d3c | humkyung | /// <summary> |
57 | /// logger |
||
58 | /// </summary> |
||
59 | ce3f0d7a | humkyung | public static ILog DBLogger = null; |
60 | public static ILog FileLogger = null; |
||
61 | a7346d3c | humkyung | |
62 | /// <summary> |
||
63 | /// Application Data Folder |
||
64 | /// </summary> |
||
65 | public static string AppDataFolder |
||
66 | { |
||
67 | get |
||
68 | { |
||
69 | return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS"); |
||
70 | } |
||
71 | } |
||
72 | 787a4489 | KangIngu | |
73 | 5928384e | djkim | |
74 | 787a4489 | KangIngu | public static RestSharp.RestClient BaseClient { get; set; } |
75 | public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; } |
||
76 | private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null) |
||
77 | { |
||
78 | if (oEncoding == null) |
||
79 | oEncoding = System.Text.Encoding.UTF8; |
||
80 | |||
81 | byte[] byteArray = Convert.FromBase64String(DecodingText); |
||
82 | |||
83 | string jsonBack = oEncoding.GetString(byteArray); |
||
84 | |||
85 | return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack); |
||
86 | } |
||
87 | |||
88 | c4a4d59c | ljiyeon | private string versionPath = null; |
89 | c7fcb949 | ljiyeon | public SplashScreen splash = new SplashScreen("splash.png"); |
90 | c4a4d59c | ljiyeon | |
91 | 787a4489 | KangIngu | protected override void OnStartup(StartupEventArgs e) |
92 | { |
||
93 | try |
||
94 | a7346d3c | humkyung | { |
95 | /// create log database and table |
||
96 | using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") }) |
||
97 | { |
||
98 | 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);"; |
||
99 | database.ExecuteNonQuery(sSql); |
||
100 | } |
||
101 | /// up to here |
||
102 | AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |
||
103 | ce3f0d7a | humkyung | log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db"); |
104 | log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log"); |
||
105 | App.DBLogger = LogManager.GetLogger("DBLogger"); |
||
106 | App.FileLogger = LogManager.GetLogger("EventLogger"); |
||
107 | a7346d3c | humkyung | |
108 | c7fcb949 | ljiyeon | splash.Show(false, false); |
109 | |||
110 | 787a4489 | KangIngu | if (e.Args.Count() > 0) |
111 | { |
||
112 | c4a4d59c | ljiyeon | var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
113 | 787a4489 | KangIngu | App.ViewInfo = new IKCOM.ViewInfo |
114 | { |
||
115 | DocumentItemID = result.DocumentItemID, |
||
116 | 35afe17c | djkim | EnsembleID = result.DocumentItemID, |
117 | 787a4489 | KangIngu | //DocumentItemID = "10001", |
118 | bPartner = result.bPartner, |
||
119 | bc664e9b | djkim | CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
120 | NewCommentPermission = result.NewCommentPermission, |
||
121 | 787a4489 | KangIngu | ProjectNO = result.ProjectNO, |
122 | UserID = result.UserID, |
||
123 | //UserID = "H2009115", |
||
124 | //Mode = 0 , 1 , 2 |
||
125 | }; |
||
126 | ParameterMode = true; |
||
127 | } |
||
128 | c4a4d59c | ljiyeon | else |
129 | { |
||
130 | string[] strArg = Environment.GetCommandLineArgs(); |
||
131 | if (strArg.Length > 1) |
||
132 | { |
||
133 | //label1.Text = strArg[1]; |
||
134 | |||
135 | var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", "")); |
||
136 | App.ViewInfo = new IKCOM.ViewInfo |
||
137 | { |
||
138 | DocumentItemID = result.DocumentItemID, |
||
139 | 35afe17c | djkim | EnsembleID = result.DocumentItemID, |
140 | c4a4d59c | ljiyeon | //DocumentItemID = "10001", |
141 | bPartner = result.bPartner, |
||
142 | CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
||
143 | NewCommentPermission = result.NewCommentPermission, |
||
144 | ProjectNO = result.ProjectNO, |
||
145 | UserID = result.UserID, |
||
146 | //UserID = "H2009115", |
||
147 | //Mode = 0 , 1 , 2 |
||
148 | }; |
||
149 | ParameterMode = true; |
||
150 | } |
||
151 | } |
||
152 | 992a98b4 | KangIngu | |
153 | //App.ViewInfo.CreateFinalPDFPermission = false; |
||
154 | //App.ViewInfo.NewCommentPermission = false; |
||
155 | |||
156 | c4a4d59c | ljiyeon | //GetQueryStringParameters(); |
157 | _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
||
158 | 787a4489 | KangIngu | _binding.MaxBufferSize = 2147483647; |
159 | _binding.MaxReceivedMessageSize = 2147483647; |
||
160 | _binding.OpenTimeout = new TimeSpan(0, 1, 0); |
||
161 | _binding.ReceiveTimeout = new TimeSpan(0, 10, 0); |
||
162 | _binding.CloseTimeout = new TimeSpan(0, 5, 0); |
||
163 | _binding.SendTimeout = new TimeSpan(0, 5, 0); |
||
164 | _binding.TextEncoding = System.Text.Encoding.UTF8; |
||
165 | _binding.TransferMode = TransferMode.Buffered; |
||
166 | //Support.SetLicense(); |
||
167 | af22332b | ljiyeon | |
168 | 84c48033 | djkim | string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", ""); |
169 | string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", ""); |
||
170 | eb5cdefc | djkim | var ipaddress = CommonLib.DNSHelper.GetDnsAdress(); |
171 | af22332b | ljiyeon | |
172 | try |
||
173 | { |
||
174 | var hostName = Dns.GetHostEntry(ipaddress).HostName; |
||
175 | |||
176 | 84c48033 | djkim | if (!hostName.EndsWith(localdomain)) |
177 | af22332b | ljiyeon | { |
178 | // 외부 사용자 |
||
179 | 84c48033 | djkim | isExternal = true; |
180 | af22332b | ljiyeon | } |
181 | } |
||
182 | catch (Exception ex) |
||
183 | { |
||
184 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
185 | } |
||
186 | 814116a9 | humkyung | |
187 | 84c48033 | djkim | #if DEBUG |
188 | eb5cdefc | djkim | //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
189 | 84c48033 | djkim | sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", ""); |
190 | 992a98b4 | KangIngu | #else |
191 | 84c48033 | djkim | sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
192 | 992a98b4 | KangIngu | #endif |
193 | eb5cdefc | djkim | |
194 | 84c48033 | djkim | _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
195 | |||
196 | c4a4d59c | ljiyeon | if (Environment.Is64BitProcess == true) //64 bit machine |
197 | { |
||
198 | 84c48033 | djkim | versionPath = CommonLib.Common.GetConfigString("UpdateVer64", "URL", "", isExternal); |
199 | c4a4d59c | ljiyeon | } |
200 | else //32 bit machine |
||
201 | { |
||
202 | 84c48033 | djkim | versionPath = CommonLib.Common.GetConfigString("UpdateVer86", "URL", "", isExternal); |
203 | c4a4d59c | ljiyeon | } |
204 | |||
205 | af22332b | ljiyeon | if (File.Exists(versionPath)) |
206 | c4a4d59c | ljiyeon | { |
207 | af22332b | ljiyeon | // 20180921 version.xml check로 변경 |
208 | var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
||
209 | try |
||
210 | c4a4d59c | ljiyeon | { |
211 | af22332b | ljiyeon | XmlDocument xdoc = new XmlDocument(); |
212 | xdoc.Load(versionPath); |
||
213 | XmlNode node = xdoc.SelectSingleNode("/RootElement/version"); |
||
214 | |||
215 | if (assemblyVersion != node.InnerText) // node.InnerText 가 null이면 catch로 빠짐 |
||
216 | c4a4d59c | ljiyeon | { |
217 | af22332b | ljiyeon | //if(MessageBox.Show("Ver. " + node.InnerText + " 업데이트가 있습니다.\r\nSmartUpdate를 실행합니다.", "MARKUS", MessageBoxButton.OKCancel) == MessageBoxResult.OK) |
218 | //{ |
||
219 | if (MessageBox.Show("Ver. " + node.InnerText, "MARKUS", MessageBoxButton.OKCancel) == MessageBoxResult.OK) |
||
220 | { |
||
221 | UpdateCheck(e); |
||
222 | } |
||
223 | else |
||
224 | { |
||
225 | base.Shutdown(); |
||
226 | //현재 실행되고 있는 자기 자신 프로세스의 정보 // 위에꺼랑 두개 다 써줄필요가 있는..가? |
||
227 | Process proc = Process.GetCurrentProcess(); |
||
228 | proc.Kill(); |
||
229 | } |
||
230 | c4a4d59c | ljiyeon | } |
231 | else |
||
232 | { |
||
233 | af22332b | ljiyeon | base.OnStartup(e); |
234 | splash.Close(new TimeSpan(0, 0, 2)); |
||
235 | c4a4d59c | ljiyeon | } |
236 | } |
||
237 | af22332b | ljiyeon | catch (Exception ex) //2. 파일이 없거나 파일내에 version의 값이 없다면 KCOM 실행하기 |
238 | c4a4d59c | ljiyeon | { |
239 | af22332b | ljiyeon | ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ex); |
240 | c4a4d59c | ljiyeon | base.OnStartup(e); |
241 | c7fcb949 | ljiyeon | splash.Close(new TimeSpan(0, 0, 2)); |
242 | af22332b | ljiyeon | } |
243 | c4a4d59c | ljiyeon | } |
244 | 787a4489 | KangIngu | } |
245 | catch (Exception ex) |
||
246 | { |
||
247 | 6707a5c7 | ljiyeon | MessageBox.Show("Err" + ex.Message); |
248 | 787a4489 | KangIngu | } |
249 | f7e7a61a | ljiyeon | finally |
250 | { |
||
251 | splash.Close(new TimeSpan(0, 0, 2)); |
||
252 | } |
||
253 | 787a4489 | KangIngu | } |
254 | a7346d3c | humkyung | |
255 | /// <summary> |
||
256 | /// log unhandled exception |
||
257 | /// </summary> |
||
258 | /// <author>humkyung</author> |
||
259 | /// <date>2019.05.21</date> |
||
260 | /// <param name="sender"></param> |
||
261 | /// <param name="e"></param> |
||
262 | private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) |
||
263 | { |
||
264 | try |
||
265 | { |
||
266 | ce3f0d7a | humkyung | App.DBLogger.Fatal(e.ExceptionObject as Exception); |
267 | a7346d3c | humkyung | } |
268 | catch (Exception ex) |
||
269 | { |
||
270 | Console.WriteLine(ex.InnerException.ToString()); |
||
271 | } |
||
272 | finally |
||
273 | { |
||
274 | Environment.Exit(0); |
||
275 | } |
||
276 | } |
||
277 | |||
278 | c4a4d59c | ljiyeon | protected void UpdateCheck(StartupEventArgs e) |
279 | { |
||
280 | try |
||
281 | { |
||
282 | if (e.Args.Count() > 0) |
||
283 | { |
||
284 | ProcessStartInfo proInfo = new ProcessStartInfo(); |
||
285 | var FileName = AppDomain.CurrentDomain.BaseDirectory + "SmartUpdate.exe"; |
||
286 | |||
287 | Process.Start(FileName, e.Args[0]); |
||
288 | |||
289 | base.Shutdown(); |
||
290 | //현재 실행되고 있는 자기 자신 프로세스의 정보 |
||
291 | Process proc = Process.GetCurrentProcess(); |
||
292 | proc.Kill(); |
||
293 | } |
||
294 | } |
||
295 | catch(Exception ee) |
||
296 | { |
||
297 | ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ee); |
||
298 | } |
||
299 | } |
||
300 | |||
301 | private void ErrorLogFileWrite(string Err) |
||
302 | { |
||
303 | ce3f0d7a | humkyung | App.FileLogger.Debug(Err); |
304 | /* |
||
305 | c4a4d59c | ljiyeon | try |
306 | { |
||
307 | f7e7a61a | ljiyeon | string pathString = AppDataFolder + "\\Err"; |
308 | af22332b | ljiyeon | |
309 | c4a4d59c | ljiyeon | if (!File.Exists(pathString)) |
310 | { |
||
311 | Directory.CreateDirectory(pathString); |
||
312 | } |
||
313 | |||
314 | Err = Err + " " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\r\n"; |
||
315 | string path = pathString + "\\" + "Log_" + DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".txt"; |
||
316 | File.AppendAllText(path, Err); |
||
317 | } |
||
318 | catch (Exception er) |
||
319 | { |
||
320 | string strError = er.ToString(); |
||
321 | } |
||
322 | ce3f0d7a | humkyung | */ |
323 | c4a4d59c | ljiyeon | } |
324 | 787a4489 | KangIngu | } |
325 | } |