markus / KCOM / App.xaml.cs @ c7598c7d
이력 | 보기 | 이력해설 | 다운로드 (12.4 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 |
|
20 |
[assembly: log4net.Config.XmlConfigurator(Watch = true)] |
21 |
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 |
/// <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 |
|
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 |
private string versionPath = null; |
84 |
public SplashScreen splash = new SplashScreen("splash.png"); |
85 |
|
86 |
protected override void OnStartup(StartupEventArgs e) |
87 |
{ |
88 |
try |
89 |
{ |
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 |
splash.Show(false, false); |
102 |
|
103 |
if (e.Args.Count() > 0) |
104 |
{ |
105 |
var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
106 |
App.ViewInfo = new IKCOM.ViewInfo |
107 |
{ |
108 |
DocumentItemID = result.DocumentItemID, |
109 |
//DocumentItemID = "10001", |
110 |
bPartner = result.bPartner, |
111 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
112 |
NewCommentPermission = result.NewCommentPermission, |
113 |
ProjectNO = result.ProjectNO, |
114 |
UserID = result.UserID, |
115 |
//UserID = "H2009115", |
116 |
//Mode = 0 , 1 , 2 |
117 |
}; |
118 |
ParameterMode = true; |
119 |
} |
120 |
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 |
|
144 |
//App.ViewInfo.CreateFinalPDFPermission = false; |
145 |
//App.ViewInfo.NewCommentPermission = false; |
146 |
|
147 |
//GetQueryStringParameters(); |
148 |
_binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
149 |
_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 |
|
159 |
string sBaseServiceURL = global::KCOM.Properties.Settings.Default.BaseClientAddress; |
160 |
|
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 |
#if DEBUG |
178 |
//_EndPoint = new EndpointAddress(@"http://10.11.252.3/MARKUS/ServiceDeepView.svc"); //효성 |
179 |
_EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
180 |
|
181 |
#else |
182 |
_EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
183 |
#endif |
184 |
|
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 |
if (File.Exists(versionPath)) |
195 |
{ |
196 |
// 20180921 version.xml check로 변경 |
197 |
var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
198 |
try |
199 |
{ |
200 |
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 |
{ |
206 |
//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 |
} |
220 |
else |
221 |
{ |
222 |
base.OnStartup(e); |
223 |
splash.Close(new TimeSpan(0, 0, 2)); |
224 |
} |
225 |
} |
226 |
catch (Exception ex) //2. 파일이 없거나 파일내에 version의 값이 없다면 KCOM 실행하기 |
227 |
{ |
228 |
ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ex); |
229 |
base.OnStartup(e); |
230 |
splash.Close(new TimeSpan(0, 0, 2)); |
231 |
} |
232 |
} |
233 |
else |
234 |
{ |
235 |
splash.Close(new TimeSpan(0, 0, 2)); |
236 |
} |
237 |
} |
238 |
catch (Exception ex) |
239 |
{ |
240 |
MessageBox.Show("Err" + ex.Message); |
241 |
} |
242 |
} |
243 |
|
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 |
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 |
string FilePath = "C:\\ProgramData\\MARKUS\\"; |
295 |
//string pathString = AppDomain.CurrentDomain.BaseDirectory + "Err"; |
296 |
string pathString = FilePath + "Err"; |
297 |
|
298 |
if (!File.Exists(pathString)) |
299 |
{ |
300 |
Directory.CreateDirectory(pathString); |
301 |
} |
302 |
|
303 |
Err = Err + " " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\r\n"; |
304 |
string path = pathString + "\\" + "Log_" + DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".txt"; |
305 |
File.AppendAllText(path, Err); |
306 |
} |
307 |
catch (Exception er) |
308 |
{ |
309 |
string strError = er.ToString(); |
310 |
//MessageBox.Show("err : " + er); |
311 |
} |
312 |
} |
313 |
} |
314 |
} |