markus / KCOM / App.xaml.cs @ eb5cdefc
이력 | 보기 | 이력해설 | 다운로드 (12.9 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 |
public static bool isExternal = false; |
55 |
|
56 |
/// <summary> |
57 |
/// logger |
58 |
/// </summary> |
59 |
public static ILog DBLogger = null; |
60 |
public static ILog FileLogger = null; |
61 |
|
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 |
|
73 |
|
74 |
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 |
private string versionPath = null; |
89 |
public SplashScreen splash = new SplashScreen("splash.png"); |
90 |
|
91 |
protected override void OnStartup(StartupEventArgs e) |
92 |
{ |
93 |
try |
94 |
{ |
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 |
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 |
|
108 |
splash.Show(false, false); |
109 |
|
110 |
if (e.Args.Count() > 0) |
111 |
{ |
112 |
var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
113 |
App.ViewInfo = new IKCOM.ViewInfo |
114 |
{ |
115 |
DocumentItemID = result.DocumentItemID, |
116 |
EnsembleID = result.DocumentItemID, |
117 |
//DocumentItemID = "10001", |
118 |
bPartner = result.bPartner, |
119 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
120 |
NewCommentPermission = result.NewCommentPermission, |
121 |
ProjectNO = result.ProjectNO, |
122 |
UserID = result.UserID, |
123 |
//UserID = "H2009115", |
124 |
//Mode = 0 , 1 , 2 |
125 |
}; |
126 |
ParameterMode = true; |
127 |
} |
128 |
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 |
EnsembleID = result.DocumentItemID, |
140 |
//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 |
|
153 |
//App.ViewInfo.CreateFinalPDFPermission = false; |
154 |
//App.ViewInfo.NewCommentPermission = false; |
155 |
|
156 |
//GetQueryStringParameters(); |
157 |
_binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
158 |
_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 |
|
168 |
string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", ""); |
169 |
string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", ""); |
170 |
var ipaddress = CommonLib.DNSHelper.GetDnsAdress(); |
171 |
|
172 |
try |
173 |
{ |
174 |
var hostName = Dns.GetHostEntry(ipaddress).HostName; |
175 |
|
176 |
if (!hostName.EndsWith(localdomain)) |
177 |
{ |
178 |
// 외부 사용자 |
179 |
isExternal = true; |
180 |
} |
181 |
} |
182 |
catch (Exception ex) |
183 |
{ |
184 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
185 |
} |
186 |
|
187 |
#if DEBUG |
188 |
//sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
189 |
sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", ""); |
190 |
#else |
191 |
sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
192 |
#endif |
193 |
|
194 |
_EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
195 |
|
196 |
if (Environment.Is64BitProcess == true) //64 bit machine |
197 |
{ |
198 |
versionPath = CommonLib.Common.GetConfigString("UpdateVer64", "URL", "", isExternal); |
199 |
} |
200 |
else //32 bit machine |
201 |
{ |
202 |
versionPath = CommonLib.Common.GetConfigString("UpdateVer86", "URL", "", isExternal); |
203 |
} |
204 |
|
205 |
if (File.Exists(versionPath)) |
206 |
{ |
207 |
// 20180921 version.xml check로 변경 |
208 |
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
209 |
try |
210 |
{ |
211 |
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 |
{ |
217 |
//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 |
} |
231 |
else |
232 |
{ |
233 |
base.OnStartup(e); |
234 |
splash.Close(new TimeSpan(0, 0, 2)); |
235 |
} |
236 |
} |
237 |
catch (Exception ex) //2. 파일이 없거나 파일내에 version의 값이 없다면 KCOM 실행하기 |
238 |
{ |
239 |
ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ex); |
240 |
base.OnStartup(e); |
241 |
splash.Close(new TimeSpan(0, 0, 2)); |
242 |
} |
243 |
} |
244 |
} |
245 |
catch (Exception ex) |
246 |
{ |
247 |
MessageBox.Show("Err" + ex.Message); |
248 |
} |
249 |
finally |
250 |
{ |
251 |
splash.Close(new TimeSpan(0, 0, 2)); |
252 |
} |
253 |
} |
254 |
|
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 |
App.DBLogger.Fatal(e.ExceptionObject as Exception); |
267 |
} |
268 |
catch (Exception ex) |
269 |
{ |
270 |
Console.WriteLine(ex.InnerException.ToString()); |
271 |
} |
272 |
finally |
273 |
{ |
274 |
Environment.Exit(0); |
275 |
} |
276 |
} |
277 |
|
278 |
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 |
App.FileLogger.Debug(Err); |
304 |
/* |
305 |
try |
306 |
{ |
307 |
string pathString = AppDataFolder + "\\Err"; |
308 |
|
309 |
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 |
*/ |
323 |
} |
324 |
} |
325 |
} |