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