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