markus / KCOM / App.xaml.cs @ 766cdfa1
이력 | 보기 | 이력해설 | 다운로드 (11.7 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 |
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 |
var hostEntry = CommonLib.DNSHelper.GetHostEntryTask(); |
155 |
|
156 |
if (hostEntry == null) |
157 |
{ |
158 |
System.Diagnostics.Debug.WriteLine("(hostEntry == null"); |
159 |
App.FileLogger.Debug("hostEntry == null"); |
160 |
isExternal = true; |
161 |
} |
162 |
else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper())) |
163 |
{ |
164 |
// 외부 사용자 |
165 |
App.FileLogger.Debug(string.Format("You are external user because located out side of given domain({0})\nYour domain is {1}", localdomain, hostEntry.HostName)); |
166 |
isExternal = true; |
167 |
} |
168 |
#endregion |
169 |
|
170 |
|
171 |
if (e.Args.Count() > 0) |
172 |
{ |
173 |
var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
174 |
App.ViewInfo = new IKCOM.ViewInfo |
175 |
{ |
176 |
DocumentItemID = result.DocumentItemID, |
177 |
EnsembleID = result.DocumentItemID, |
178 |
//DocumentItemID = "10001", |
179 |
bPartner = result.bPartner, |
180 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
181 |
NewCommentPermission = result.NewCommentPermission, |
182 |
ProjectNO = result.ProjectNO, |
183 |
UserID = result.UserID, |
184 |
//UserID = "H2009115", |
185 |
//Mode = 0 , 1 , 2 |
186 |
}; |
187 |
ParameterMode = true; |
188 |
} |
189 |
else |
190 |
{ |
191 |
string[] strArg = Environment.GetCommandLineArgs(); |
192 |
if (strArg.Length > 1) |
193 |
{ |
194 |
var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", "")); |
195 |
App.ViewInfo = new IKCOM.ViewInfo |
196 |
{ |
197 |
DocumentItemID = result.DocumentItemID, |
198 |
EnsembleID = result.DocumentItemID, |
199 |
//DocumentItemID = "10001", |
200 |
bPartner = result.bPartner, |
201 |
CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
202 |
NewCommentPermission = result.NewCommentPermission, |
203 |
ProjectNO = result.ProjectNO, |
204 |
UserID = result.UserID, |
205 |
//UserID = "H2009115", |
206 |
//Mode = 0 , 1 , 2 |
207 |
}; |
208 |
ParameterMode = true; |
209 |
} |
210 |
else |
211 |
{ |
212 |
MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내"); |
213 |
throw new ArgumentException("문서 정보가 입력되지 않았습니다."); |
214 |
} |
215 |
} |
216 |
|
217 |
//App.ViewInfo.CreateFinalPDFPermission = false; |
218 |
//App.ViewInfo.NewCommentPermission = false; |
219 |
//GetQueryStringParameters(); |
220 |
_binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
221 |
_binding.MaxBufferSize = 2147483647; |
222 |
_binding.MaxReceivedMessageSize = 2147483647; |
223 |
_binding.OpenTimeout = new TimeSpan(0, 1, 0); |
224 |
_binding.ReceiveTimeout = new TimeSpan(0, 10, 0); |
225 |
_binding.CloseTimeout = new TimeSpan(0, 5, 0); |
226 |
_binding.SendTimeout = new TimeSpan(0, 5, 0); |
227 |
_binding.TextEncoding = System.Text.Encoding.UTF8; |
228 |
_binding.TransferMode = TransferMode.Buffered; |
229 |
//Support.SetLicense(); |
230 |
|
231 |
string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", ""); |
232 |
|
233 |
#if DEBUG |
234 |
//sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
235 |
System.Diagnostics.Debug.WriteLine("sBaseServiceURL"); |
236 |
sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
237 |
#else |
238 |
sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
239 |
#endif |
240 |
App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
241 |
_EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
242 |
|
243 |
await SplashScreenAsnyc(); |
244 |
base.OnStartup(e); |
245 |
|
246 |
System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent); |
247 |
} |
248 |
catch (Exception ex) |
249 |
{ |
250 |
Logger.sendReqLog("OnStartUp",ex.ToString() + " " + ex.InnerException?.ToString(),1); |
251 |
} |
252 |
finally |
253 |
{ |
254 |
await SplashScreenAsnyc(); |
255 |
} |
256 |
} |
257 |
|
258 |
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) |
259 |
{ |
260 |
|
261 |
Logger.sendReqLog("App Error ",e.Exception.ToString() + " " + e.Exception.InnerException?.ToString(), 1); |
262 |
} |
263 |
|
264 |
private void KeyDownEvent(object sender, KeyEventArgs e) |
265 |
{ |
266 |
if (e.Key == Key.Escape || e.Key == Key.Delete) |
267 |
{ |
268 |
System.Diagnostics.Debug.WriteLine("app key Event"); |
269 |
Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e); |
270 |
} |
271 |
} |
272 |
|
273 |
private async Task<bool> SplashScreenAsnyc() |
274 |
{ |
275 |
int value = 100 / ISplashMessage.SplashMessageCnt; |
276 |
|
277 |
for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++) |
278 |
{ |
279 |
await Task.Delay(3); |
280 |
await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value); |
281 |
} |
282 |
|
283 |
splashScreen.Close(); |
284 |
|
285 |
return true; |
286 |
} |
287 |
|
288 |
public static void splashString(string text) |
289 |
{ |
290 |
Task.Factory.StartNew(() => |
291 |
{ |
292 |
splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text); |
293 |
}).ConfigureAwait(false); |
294 |
} |
295 |
|
296 |
|
297 |
/// <summary> |
298 |
/// log unhandled exception |
299 |
/// </summary> |
300 |
/// <author>humkyung</author> |
301 |
/// <date>2019.05.21</date> |
302 |
/// <param name="sender"></param> |
303 |
/// <param name="e"></param> |
304 |
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) |
305 |
{ |
306 |
try |
307 |
{ |
308 |
App.FileLogger.Fatal(e.ExceptionObject as Exception); |
309 |
} |
310 |
catch (Exception ex) |
311 |
{ |
312 |
Console.WriteLine(ex.InnerException?.ToString()); |
313 |
} |
314 |
finally |
315 |
{ |
316 |
#if RELEASE |
317 |
Environment.Exit(0); |
318 |
#endif |
319 |
} |
320 |
} |
321 |
|
322 |
private void ErrorLogFileWrite(string Err) |
323 |
{ |
324 |
App.FileLogger.Debug(Err); |
325 |
} |
326 |
} |
327 |
} |