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