markus / KCOM / App.xaml.cs @ 366f00c2
이력 | 보기 | 이력해설 | 다운로드 (11.8 KB)
1 |
|
---|---|
2 |
using KCOM.Common; |
3 |
|
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 |
using KCOM.Views; |
22 |
using System.Threading.Tasks; |
23 |
using System.Windows.Input; |
24 |
|
25 |
[assembly: log4net.Config.XmlConfigurator(Watch = true)] |
26 |
namespace KCOM |
27 |
{ |
28 |
public class OpenProperties |
29 |
{ |
30 |
public string DocumentItemID { get; set; } |
31 |
public bool bPartner { get; set; } |
32 |
public bool CreateFinalPDFPermission { get; set; } |
33 |
public bool NewCommentPermission { get; set; } |
34 |
public string ProjectNO { get; set; } |
35 |
public string UserID { get; set; } |
36 |
public int Mode { get; set; } |
37 |
} |
38 |
/// <summary> |
39 |
/// App.xaml에 대한 상호 작용 논리 |
40 |
/// </summary> |
41 |
public partial class App : Application |
42 |
{ |
43 |
public static PageManager.PageStorage PageStorage; |
44 |
|
45 |
public static BasicHttpBinding _binding; |
46 |
public static EndpointAddress _EndPoint; |
47 |
public static EndpointAddress _EndPoint_SaveLoad; |
48 |
public static EndpointAddress _EndPoint_Symbol; |
49 |
public static string UserID; |
50 |
public static string UserName; |
51 |
public static string UserIP; |
52 |
public static IKCOM.ViewInfo ViewInfo; |
53 |
public static string urlHost; |
54 |
public static string urlPort; |
55 |
public static string urlHost_DB; |
56 |
public static string urlPort_DB; |
57 |
public static string Custom_ViewInfoId; |
58 |
public static bool ParameterMode = false; |
59 |
public static bool isExternal = false; |
60 |
|
61 |
/// <summary> |
62 |
/// logger |
63 |
/// </summary> |
64 |
public static ILog DBLogger = null; |
65 |
public static ILog FileLogger = null; |
66 |
|
67 |
/// <summary> |
68 |
/// VisualStudio Design Time여부 |
69 |
/// </summary> |
70 |
public static bool IsDesignMode |
71 |
{ |
72 |
get |
73 |
{ |
74 |
try |
75 |
{ |
76 |
return DesignerProperties.GetIsInDesignMode(new DependencyObject()); |
77 |
} |
78 |
catch (Exception) |
79 |
{ |
80 |
return false; |
81 |
} |
82 |
} |
83 |
private set { } |
84 |
} |
85 |
|
86 |
/// <summary> |
87 |
/// Application Data Folder |
88 |
/// </summary> |
89 |
public static string AppDataFolder |
90 |
{ |
91 |
get |
92 |
{ |
93 |
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS"); |
94 |
} |
95 |
} |
96 |
|
97 |
public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; } |
98 |
|
99 |
|
100 |
private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null) |
101 |
{ |
102 |
if (oEncoding == null) |
103 |
oEncoding = System.Text.Encoding.UTF8; |
104 |
|
105 |
byte[] byteArray = Convert.FromBase64String(DecodingText); |
106 |
|
107 |
string jsonBack = oEncoding.GetString(byteArray); |
108 |
|
109 |
return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack); |
110 |
} |
111 |
|
112 |
private string versionPath = null; |
113 |
//public SplashScreen splash = new SplashScreen("splash.png"); |
114 |
public static SplashScreenWindow splashScreen = new SplashScreenWindow(); |
115 |
|
116 |
public App() |
117 |
{ |
118 |
Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.VisualStudio2013Theme(); |
119 |
} |
120 |
|
121 |
protected override void OnExit(ExitEventArgs e) |
122 |
{ |
123 |
App.PageStorage.Clear(); |
124 |
|
125 |
base.OnExit(e); |
126 |
} |
127 |
|
128 |
protected override async void OnStartup(StartupEventArgs e) |
129 |
{ |
130 |
try |
131 |
{ |
132 |
splashScreen.Show(); |
133 |
|
134 |
/// create log database and table |
135 |
using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") }) |
136 |
{ |
137 |
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);"; |
138 |
database.ExecuteNonQuery(sSql); |
139 |
} |
140 |
/// up to here |
141 |
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |
142 |
log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db"); |
143 |
log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log"); |
144 |
App.DBLogger = LogManager.GetLogger("DBLogger"); |
145 |
App.FileLogger = LogManager.GetLogger("EventLogger"); |
146 |
|
147 |
#region // DNS 체크 |
148 |
|
149 |
string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", ""); |
150 |
|
151 |
var hostEntry = CommonLib.DNSHelper.GetHostEntryTask(); |
152 |
|
153 |
if (hostEntry == null) |
154 |
{ |
155 |
System.Diagnostics.Debug.WriteLine("(hostEntry == null"); |
156 |
App.FileLogger.Debug("hostEntry == null"); |
157 |
isExternal = true; |
158 |
} |
159 |
else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper())) |
160 |
{ |
161 |
// 외부 사용자 |
162 |
App.FileLogger.Debug(string.Format("You are external user because located out side of given domain({0})\nYour domain is {1}", localdomain, hostEntry.HostName)); |
163 |
isExternal = true; |
164 |
} |
165 |
#endregion |
166 |
|
167 |
|
168 |
if (e.Args.Count() > 0) |
169 |
{ |
170 |
var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
171 |
App.ViewInfo = new IKCOM.ViewInfo |
172 |
{ |
173 |
DocumentItemID = result.DocumentItemID, |
174 |
EnsembleID = result.DocumentItemID, |
175 |
//DocumentItemID = "10001", |
176 |
bPartner = result.bPartner, |
177 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
178 |
NewCommentPermission = result.NewCommentPermission, |
179 |
ProjectNO = result.ProjectNO, |
180 |
UserID = result.UserID, |
181 |
//UserID = "H2009115", |
182 |
//Mode = 0 , 1 , 2 |
183 |
}; |
184 |
ParameterMode = true; |
185 |
} |
186 |
else |
187 |
{ |
188 |
string[] strArg = Environment.GetCommandLineArgs(); |
189 |
if (strArg.Length > 1) |
190 |
{ |
191 |
var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", "")); |
192 |
App.ViewInfo = new IKCOM.ViewInfo |
193 |
{ |
194 |
DocumentItemID = result.DocumentItemID, |
195 |
EnsembleID = result.DocumentItemID, |
196 |
//DocumentItemID = "10001", |
197 |
bPartner = result.bPartner, |
198 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
199 |
NewCommentPermission = result.NewCommentPermission, |
200 |
ProjectNO = result.ProjectNO, |
201 |
UserID = result.UserID, |
202 |
//UserID = "H2009115", |
203 |
//Mode = 0 , 1 , 2 |
204 |
}; |
205 |
ParameterMode = true; |
206 |
} |
207 |
else |
208 |
{ |
209 |
MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내"); |
210 |
throw new ArgumentException("문서 정보가 입력되지 않았습니다."); |
211 |
} |
212 |
} |
213 |
|
214 |
//App.ViewInfo.CreateFinalPDFPermission = false; |
215 |
//App.ViewInfo.NewCommentPermission = false; |
216 |
//GetQueryStringParameters(); |
217 |
_binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
218 |
_binding.MaxBufferSize = 2147483647; |
219 |
_binding.MaxReceivedMessageSize = 2147483647; |
220 |
_binding.OpenTimeout = new TimeSpan(0, 1, 0); |
221 |
_binding.ReceiveTimeout = new TimeSpan(0, 10, 0); |
222 |
_binding.CloseTimeout = new TimeSpan(0, 5, 0); |
223 |
_binding.SendTimeout = new TimeSpan(0, 5, 0); |
224 |
_binding.TextEncoding = System.Text.Encoding.UTF8; |
225 |
_binding.TransferMode = TransferMode.Buffered; |
226 |
//Support.SetLicense(); |
227 |
|
228 |
string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", ""); |
229 |
|
230 |
#if DEBUG |
231 |
//sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
232 |
System.Diagnostics.Debug.WriteLine("sBaseServiceURL"); |
233 |
sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
234 |
#else |
235 |
sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
236 |
#endif |
237 |
App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
238 |
_EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
239 |
|
240 |
await SplashScreenAsnyc(); |
241 |
base.OnStartup(e); |
242 |
|
243 |
System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent); |
244 |
} |
245 |
catch (Exception ex) |
246 |
{ |
247 |
Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1); |
248 |
} |
249 |
finally |
250 |
{ |
251 |
await SplashScreenAsnyc(); |
252 |
} |
253 |
} |
254 |
|
255 |
private void KeyDownEvent(object sender, KeyEventArgs e) |
256 |
{ |
257 |
if (e.Key == Key.Escape || e.Key == Key.Delete) |
258 |
{ |
259 |
System.Diagnostics.Debug.WriteLine("app key Event"); |
260 |
Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e); |
261 |
} |
262 |
} |
263 |
|
264 |
private async Task<bool> SplashScreenAsnyc() |
265 |
{ |
266 |
int value = 100 / ISplashMessage.SplashMessageCnt; |
267 |
|
268 |
for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++) |
269 |
{ |
270 |
System.Threading.Thread.Sleep(3); |
271 |
await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value); |
272 |
} |
273 |
|
274 |
splashScreen.Close(); |
275 |
|
276 |
return true; |
277 |
} |
278 |
|
279 |
public static void splashString(string text) |
280 |
{ |
281 |
Task.Factory.StartNew(() => |
282 |
{ |
283 |
splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text); |
284 |
}); |
285 |
} |
286 |
|
287 |
|
288 |
/// <summary> |
289 |
/// log unhandled exception |
290 |
/// </summary> |
291 |
/// <author>humkyung</author> |
292 |
/// <date>2019.05.21</date> |
293 |
/// <param name="sender"></param> |
294 |
/// <param name="e"></param> |
295 |
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) |
296 |
{ |
297 |
try |
298 |
{ |
299 |
App.FileLogger.Fatal(e.ExceptionObject as Exception); |
300 |
} |
301 |
catch (Exception ex) |
302 |
{ |
303 |
Console.WriteLine(ex.InnerException?.ToString()); |
304 |
} |
305 |
finally |
306 |
{ |
307 |
#if RELEASE |
308 |
Environment.Exit(0); |
309 |
#endif |
310 |
} |
311 |
} |
312 |
|
313 |
private void ErrorLogFileWrite(string Err) |
314 |
{ |
315 |
App.FileLogger.Debug(Err); |
316 |
} |
317 |
} |
318 |
} |