markus / KCOM / App.xaml.cs @ 35afe17c
이력 | 보기 | 이력해설 | 다운로드 (12.7 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 |
|
22 |
[assembly: log4net.Config.XmlConfigurator(Watch = true)] |
23 |
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 |
/// <summary> |
56 |
/// logger |
57 |
/// </summary> |
58 |
public static ILog DBLogger = null; |
59 |
public static ILog FileLogger = null; |
60 |
|
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 |
|
72 |
|
73 |
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 |
private string versionPath = null; |
88 |
public SplashScreen splash = new SplashScreen("splash.png"); |
89 |
|
90 |
protected override void OnStartup(StartupEventArgs e) |
91 |
{ |
92 |
try |
93 |
{ |
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 |
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 |
|
107 |
splash.Show(false, false); |
108 |
|
109 |
if (e.Args.Count() > 0) |
110 |
{ |
111 |
var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
112 |
App.ViewInfo = new IKCOM.ViewInfo |
113 |
{ |
114 |
DocumentItemID = result.DocumentItemID, |
115 |
EnsembleID = result.DocumentItemID, |
116 |
//DocumentItemID = "10001", |
117 |
bPartner = result.bPartner, |
118 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
119 |
NewCommentPermission = result.NewCommentPermission, |
120 |
ProjectNO = result.ProjectNO, |
121 |
UserID = result.UserID, |
122 |
//UserID = "H2009115", |
123 |
//Mode = 0 , 1 , 2 |
124 |
}; |
125 |
ParameterMode = true; |
126 |
} |
127 |
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 |
EnsembleID = result.DocumentItemID, |
139 |
//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 |
|
152 |
//App.ViewInfo.CreateFinalPDFPermission = false; |
153 |
//App.ViewInfo.NewCommentPermission = false; |
154 |
|
155 |
//GetQueryStringParameters(); |
156 |
_binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
157 |
_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 |
|
167 |
string sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", ""); |
168 |
|
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 |
#if DEBUG |
186 |
//_EndPoint = new EndpointAddress(@"http://10.11.252.3/MARKUS/ServiceDeepView.svc"); //효성 |
187 |
_EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
188 |
|
189 |
#else |
190 |
_EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
191 |
#endif |
192 |
|
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 |
if (File.Exists(versionPath)) |
203 |
{ |
204 |
// 20180921 version.xml check로 변경 |
205 |
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
206 |
try |
207 |
{ |
208 |
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 |
{ |
214 |
//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 |
} |
228 |
else |
229 |
{ |
230 |
base.OnStartup(e); |
231 |
splash.Close(new TimeSpan(0, 0, 2)); |
232 |
} |
233 |
} |
234 |
catch (Exception ex) //2. 파일이 없거나 파일내에 version의 값이 없다면 KCOM 실행하기 |
235 |
{ |
236 |
ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ex); |
237 |
base.OnStartup(e); |
238 |
splash.Close(new TimeSpan(0, 0, 2)); |
239 |
} |
240 |
} |
241 |
} |
242 |
catch (Exception ex) |
243 |
{ |
244 |
MessageBox.Show("Err" + ex.Message); |
245 |
} |
246 |
finally |
247 |
{ |
248 |
splash.Close(new TimeSpan(0, 0, 2)); |
249 |
} |
250 |
} |
251 |
|
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 |
App.DBLogger.Fatal(e.ExceptionObject as Exception); |
264 |
} |
265 |
catch (Exception ex) |
266 |
{ |
267 |
Console.WriteLine(ex.InnerException.ToString()); |
268 |
} |
269 |
finally |
270 |
{ |
271 |
Environment.Exit(0); |
272 |
} |
273 |
} |
274 |
|
275 |
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 |
App.FileLogger.Debug(Err); |
301 |
/* |
302 |
try |
303 |
{ |
304 |
string pathString = AppDataFolder + "\\Err"; |
305 |
|
306 |
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 |
*/ |
320 |
} |
321 |
} |
322 |
} |