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