markus / KCOM / App.xaml.cs @ 9d5b4bc2
이력 | 보기 | 이력해설 | 다운로드 (12.1 KB)
1 |
|
---|---|
2 |
using KCOM.Common; |
3 |
using KCOM.Views; |
4 |
using log4net; |
5 |
using System; |
6 |
using System.ComponentModel; |
7 |
using System.IO; |
8 |
using System.Linq; |
9 |
using System.ServiceModel; |
10 |
using System.Threading.Tasks; |
11 |
using System.Windows; |
12 |
using System.Windows.Input; |
13 |
using System.Windows.Resources; |
14 |
using log4net; |
15 |
|
16 |
namespace KCOM |
17 |
{ |
18 |
public class OpenProperties |
19 |
{ |
20 |
public string DocumentItemID { get; set; } |
21 |
public bool bPartner { get; set; } |
22 |
public bool CreateFinalPDFPermission { get; set; } |
23 |
public bool NewCommentPermission { get; set; } |
24 |
public string ProjectNO { get; set; } |
25 |
public string UserID { get; set; } |
26 |
public int Mode { get; set; } |
27 |
} |
28 |
/// <summary> |
29 |
/// App.xaml에 대한 상호 작용 논리 |
30 |
/// </summary> |
31 |
public partial class App : Application |
32 |
{ |
33 |
public static PageManager.PageStorage PageStorage; |
34 |
|
35 |
public static BasicHttpBinding _binding; |
36 |
public static EndpointAddress _EndPoint; |
37 |
public static EndpointAddress _EndPoint_SaveLoad; |
38 |
public static EndpointAddress _EndPoint_Symbol; |
39 |
public static string UserID; |
40 |
public static string UserName; |
41 |
public static string UserIP; |
42 |
public static IKCOM.ViewInfo ViewInfo; |
43 |
public static string urlHost; |
44 |
public static string urlPort; |
45 |
public static string urlHost_DB; |
46 |
public static string urlPort_DB; |
47 |
public static string Custom_ViewInfoId; |
48 |
public static bool ParameterMode = false; |
49 |
public static bool isExternal = false; |
50 |
|
51 |
/// <summary> |
52 |
/// logger |
53 |
/// </summary> |
54 |
public static ILog FileLogger = null; |
55 |
|
56 |
public static StreamResourceInfo DefaultArrowCursor; |
57 |
|
58 |
public static Stream DefaultArrowCursorStream |
59 |
{ |
60 |
get { |
61 |
return Application.GetResourceStream(new Uri(@"pack://application:,,,/Resources/Cursor/customCursor2.cur", UriKind.Absolute)).Stream; |
62 |
//DefaultArrowCursor.Stream.Position = 0; |
63 |
//return DefaultArrowCursor.Stream; |
64 |
} |
65 |
} |
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 |
App.FileLogger = LogManager.GetLogger(typeof(App)); |
121 |
} |
122 |
|
123 |
protected override void OnExit(ExitEventArgs e) |
124 |
{ |
125 |
try |
126 |
{ |
127 |
if (App.PageStorage != null) |
128 |
{ |
129 |
App.PageStorage.Clear(); |
130 |
} |
131 |
} |
132 |
catch (Exception) |
133 |
{ |
134 |
} |
135 |
|
136 |
base.OnExit(e); |
137 |
} |
138 |
|
139 |
protected override async void OnStartup(StartupEventArgs e) |
140 |
{ |
141 |
try |
142 |
{ |
143 |
DefaultArrowCursor = Application.GetResourceStream(new Uri(@"pack://application:,,,/Resources/Cursor/customCursor2.cur", UriKind.Absolute)); |
144 |
|
145 |
splashScreen.Show(); |
146 |
|
147 |
App.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException; |
148 |
/// up to here |
149 |
//AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |
150 |
|
151 |
#region // DNS 체크 |
152 |
|
153 |
string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", ""); |
154 |
|
155 |
ViewerDataModel.Instance.IsDocumentHistory = Convert.ToBoolean(CommonLib.Common.GetConfigString("COMMON","IsDocumentHistory", "true")); |
156 |
|
157 |
var hostEntry = CommonLib.DNSHelper.GetHostEntryTask(); |
158 |
|
159 |
if (hostEntry == null) |
160 |
{ |
161 |
System.Diagnostics.Debug.WriteLine("(hostEntry == null"); |
162 |
App.FileLogger.Debug("hostEntry == null"); |
163 |
isExternal = true; |
164 |
} |
165 |
else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper())) |
166 |
{ |
167 |
// 외부 사용자 |
168 |
App.FileLogger.Debug(string.Format("You are external user because located out side of given domain({0})\nYour domain is {1}", localdomain, hostEntry.HostName)); |
169 |
isExternal = true; |
170 |
} |
171 |
#endregion |
172 |
|
173 |
|
174 |
if (e.Args.Count() > 0) |
175 |
{ |
176 |
var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
177 |
App.ViewInfo = new IKCOM.ViewInfo |
178 |
{ |
179 |
DocumentItemID = result.DocumentItemID, |
180 |
EnsembleID = result.DocumentItemID, |
181 |
//DocumentItemID = "10001", |
182 |
bPartner = result.bPartner, |
183 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
184 |
NewCommentPermission = result.NewCommentPermission, |
185 |
ProjectNO = result.ProjectNO, |
186 |
UserID = result.UserID, |
187 |
isAdmin = Convert.ToBoolean(result.Mode) |
188 |
//UserID = "H2009115", |
189 |
//Mode = result.Mode |
190 |
}; |
191 |
ParameterMode = true; |
192 |
} |
193 |
else |
194 |
{ |
195 |
string[] strArg = Environment.GetCommandLineArgs(); |
196 |
if (strArg.Length > 1) |
197 |
{ |
198 |
var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", "")); |
199 |
App.ViewInfo = new IKCOM.ViewInfo |
200 |
{ |
201 |
DocumentItemID = result.DocumentItemID, |
202 |
EnsembleID = result.DocumentItemID, |
203 |
//DocumentItemID = "10001", |
204 |
bPartner = result.bPartner, |
205 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
206 |
NewCommentPermission = result.NewCommentPermission, |
207 |
ProjectNO = result.ProjectNO, |
208 |
UserID = result.UserID, |
209 |
//UserID = "H2009115", |
210 |
//Mode = 0 , 1 , 2 |
211 |
}; |
212 |
ParameterMode = true; |
213 |
} |
214 |
else |
215 |
{ |
216 |
MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내"); |
217 |
throw new ArgumentException("문서 정보가 입력되지 않았습니다."); |
218 |
} |
219 |
} |
220 |
|
221 |
//App.ViewInfo.CreateFinalPDFPermission = false; |
222 |
//App.ViewInfo.NewCommentPermission = false; |
223 |
//GetQueryStringParameters(); |
224 |
_binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
225 |
_binding.MaxBufferSize = 2147483647; |
226 |
_binding.MaxReceivedMessageSize = 2147483647; |
227 |
_binding.OpenTimeout = new TimeSpan(0, 1, 0); |
228 |
_binding.ReceiveTimeout = new TimeSpan(0, 10, 0); |
229 |
_binding.CloseTimeout = new TimeSpan(0, 5, 0); |
230 |
_binding.SendTimeout = new TimeSpan(0, 5, 0); |
231 |
_binding.TextEncoding = System.Text.Encoding.UTF8; |
232 |
_binding.TransferMode = TransferMode.Buffered; |
233 |
//Support.SetLicense(); |
234 |
|
235 |
string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", ""); |
236 |
|
237 |
#if DEBUG |
238 |
//sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
239 |
System.Diagnostics.Debug.WriteLine("sBaseServiceURL"); |
240 |
sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
241 |
#else |
242 |
sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
243 |
#endif |
244 |
App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
245 |
_EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
246 |
|
247 |
await SplashScreenAsnyc(); |
248 |
base.OnStartup(e); |
249 |
|
250 |
System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent); |
251 |
} |
252 |
catch (Exception ex) |
253 |
{ |
254 |
Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1); |
255 |
} |
256 |
finally |
257 |
{ |
258 |
await SplashScreenAsnyc(); |
259 |
} |
260 |
} |
261 |
|
262 |
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) |
263 |
{ |
264 |
|
265 |
Logger.sendReqLog("App Error ",e.Exception.ToString() + " " + e.Exception.InnerException?.ToString(), 1); |
266 |
} |
267 |
|
268 |
private void KeyDownEvent(object sender, KeyEventArgs e) |
269 |
{ |
270 |
//if (e.Key == Key.Escape || e.Key == Key.Delete) |
271 |
//{ |
272 |
System.Diagnostics.Debug.WriteLine("app key Event"); |
273 |
Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e); |
274 |
//} |
275 |
} |
276 |
|
277 |
private async Task<bool> SplashScreenAsnyc() |
278 |
{ |
279 |
int value = 100 / ISplashMessage.SplashMessageCnt; |
280 |
|
281 |
for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++) |
282 |
{ |
283 |
await Task.Delay(3); |
284 |
await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value); |
285 |
} |
286 |
|
287 |
//splashScreen.Close(); |
288 |
|
289 |
return true; |
290 |
} |
291 |
|
292 |
public static void splashString(string text) |
293 |
{ |
294 |
Task.Factory.StartNew(() => |
295 |
{ |
296 |
splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text); |
297 |
}).ConfigureAwait(false); |
298 |
} |
299 |
|
300 |
|
301 |
/// <summary> |
302 |
/// log unhandled exception |
303 |
/// </summary> |
304 |
/// <author>humkyung</author> |
305 |
/// <date>2019.05.21</date> |
306 |
/// <param name="sender"></param> |
307 |
/// <param name="e"></param> |
308 |
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) |
309 |
{ |
310 |
try |
311 |
{ |
312 |
App.FileLogger.Fatal(e.ExceptionObject as Exception); |
313 |
} |
314 |
catch (Exception ex) |
315 |
{ |
316 |
Console.WriteLine(ex.InnerException?.ToString()); |
317 |
} |
318 |
finally |
319 |
{ |
320 |
#if RELEASE |
321 |
Environment.Exit(0); |
322 |
#endif |
323 |
} |
324 |
} |
325 |
|
326 |
private void ErrorLogFileWrite(string Err) |
327 |
{ |
328 |
App.FileLogger.Debug(Err); |
329 |
} |
330 |
} |
331 |
} |