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