markus / KCOM / App.xaml.cs @ 91e84544
이력 | 보기 | 이력해설 | 다운로드 (11.6 KB)
1 | 787a4489 | KangIngu | |
---|---|---|---|
2 | af22332b | ljiyeon | using KCOM.Common; |
3 | 6b6e937c | taeseongkim | |
4 | 787a4489 | KangIngu | using System; |
5 | using System.Collections.Generic; |
||
6 | using System.ComponentModel; |
||
7 | using System.Configuration; |
||
8 | using System.Data; |
||
9 | c4a4d59c | ljiyeon | using System.Diagnostics; |
10 | using System.IO; |
||
11 | 787a4489 | KangIngu | using System.Linq; |
12 | c4a4d59c | ljiyeon | using System.Net; |
13 | using System.Reflection; |
||
14 | 787a4489 | KangIngu | using System.Runtime.CompilerServices; |
15 | using System.ServiceModel; |
||
16 | using System.Windows; |
||
17 | c4a4d59c | ljiyeon | using System.Xml; |
18 | a7346d3c | humkyung | using log4net; |
19 | e52385b9 | ljiyeon | using System.Text; |
20 | using System.Runtime.InteropServices; |
||
21 | cf2671a6 | ljiyeon | using KCOM.Views; |
22 | using System.Threading.Tasks; |
||
23 | fa48eb85 | taeseongkim | using System.Windows.Input; |
24 | 787a4489 | KangIngu | |
25 | a7346d3c | humkyung | [assembly: log4net.Config.XmlConfigurator(Watch = true)] |
26 | 787a4489 | KangIngu | 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 | 84c48033 | djkim | public static bool isExternal = false; |
58 | 787a4489 | KangIngu | |
59 | a7346d3c | humkyung | /// <summary> |
60 | /// logger |
||
61 | /// </summary> |
||
62 | ce3f0d7a | humkyung | public static ILog DBLogger = null; |
63 | public static ILog FileLogger = null; |
||
64 | a7346d3c | humkyung | |
65 | /// <summary> |
||
66 | 2089959a | taeseongkim | /// VisualStudio Design Time여부 |
67 | /// </summary> |
||
68 | public static bool IsDesignMode |
||
69 | { |
||
70 | get |
||
71 | { |
||
72 | try |
||
73 | { |
||
74 | return DesignerProperties.GetIsInDesignMode(new DependencyObject()); |
||
75 | } |
||
76 | catch (Exception) |
||
77 | { |
||
78 | return false; |
||
79 | } |
||
80 | } |
||
81 | private set { } |
||
82 | } |
||
83 | |||
84 | /// <summary> |
||
85 | a7346d3c | humkyung | /// Application Data Folder |
86 | /// </summary> |
||
87 | public static string AppDataFolder |
||
88 | { |
||
89 | get |
||
90 | { |
||
91 | return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS"); |
||
92 | } |
||
93 | } |
||
94 | 787a4489 | KangIngu | |
95 | 1137be84 | djkim | |
96 | 787a4489 | KangIngu | public static RestSharp.RestClient BaseClient { get; set; } |
97 | public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; } |
||
98 | 1137be84 | djkim | |
99 | 264c9309 | ljiyeon | |
100 | 787a4489 | KangIngu | 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 | c4a4d59c | ljiyeon | private string versionPath = null; |
113 | cf2671a6 | ljiyeon | //public SplashScreen splash = new SplashScreen("splash.png"); |
114 | e0cfc73c | ljiyeon | public static SplashScreenWindow splashScreen = new SplashScreenWindow(); |
115 | cdfb57ff | taeseongkim | |
116 | public App() |
||
117 | { |
||
118 | aff63364 | taeseongkim | Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.VisualStudio2013Theme(); |
119 | cdfb57ff | taeseongkim | } |
120 | |||
121 | protected override async void OnStartup(StartupEventArgs e) |
||
122 | { |
||
123 | 787a4489 | KangIngu | try |
124 | a7346d3c | humkyung | { |
125 | cf2671a6 | ljiyeon | splashScreen.Show(); |
126 | 1137be84 | djkim | |
127 | a7346d3c | humkyung | /// create log database and table |
128 | using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") }) |
||
129 | { |
||
130 | 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);"; |
||
131 | database.ExecuteNonQuery(sSql); |
||
132 | } |
||
133 | /// up to here |
||
134 | AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |
||
135 | ce3f0d7a | humkyung | log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db"); |
136 | log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log"); |
||
137 | App.DBLogger = LogManager.GetLogger("DBLogger"); |
||
138 | App.FileLogger = LogManager.GetLogger("EventLogger"); |
||
139 | a7346d3c | humkyung | |
140 | 1137be84 | djkim | #region // DNS 체크 |
141 | |||
142 | string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", ""); |
||
143 | |||
144 | var hostEntry = CommonLib.DNSHelper.GetHostEntryTask(); |
||
145 | df33d20a | djkim | |
146 | 1137be84 | djkim | if (hostEntry == null) |
147 | { |
||
148 | System.Diagnostics.Debug.WriteLine("(hostEntry == null"); |
||
149 | 1ed8da93 | humkyung | App.FileLogger.Debug("hostEntry == null"); |
150 | 1137be84 | djkim | isExternal = true; |
151 | } |
||
152 | ddfd4bc7 | djkim | else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper())) |
153 | 1137be84 | djkim | { |
154 | // 외부 사용자 |
||
155 | 1ed8da93 | humkyung | App.FileLogger.Debug(string.Format("You are external user because located out side of given domain({0})\nYour domain is {1}", localdomain, hostEntry.HostName)); |
156 | 1137be84 | djkim | isExternal = true; |
157 | } |
||
158 | #endregion |
||
159 | |||
160 | 787a4489 | KangIngu | if (e.Args.Count() > 0) |
161 | { |
||
162 | c4a4d59c | ljiyeon | var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
163 | 787a4489 | KangIngu | App.ViewInfo = new IKCOM.ViewInfo |
164 | { |
||
165 | DocumentItemID = result.DocumentItemID, |
||
166 | 35afe17c | djkim | EnsembleID = result.DocumentItemID, |
167 | 787a4489 | KangIngu | //DocumentItemID = "10001", |
168 | bPartner = result.bPartner, |
||
169 | bc664e9b | djkim | CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
170 | NewCommentPermission = result.NewCommentPermission, |
||
171 | 787a4489 | KangIngu | ProjectNO = result.ProjectNO, |
172 | UserID = result.UserID, |
||
173 | //UserID = "H2009115", |
||
174 | //Mode = 0 , 1 , 2 |
||
175 | }; |
||
176 | ParameterMode = true; |
||
177 | } |
||
178 | c4a4d59c | ljiyeon | else |
179 | { |
||
180 | string[] strArg = Environment.GetCommandLineArgs(); |
||
181 | if (strArg.Length > 1) |
||
182 | { |
||
183 | var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", "")); |
||
184 | App.ViewInfo = new IKCOM.ViewInfo |
||
185 | { |
||
186 | DocumentItemID = result.DocumentItemID, |
||
187 | 35afe17c | djkim | EnsembleID = result.DocumentItemID, |
188 | c4a4d59c | ljiyeon | //DocumentItemID = "10001", |
189 | bPartner = result.bPartner, |
||
190 | CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
||
191 | NewCommentPermission = result.NewCommentPermission, |
||
192 | ProjectNO = result.ProjectNO, |
||
193 | UserID = result.UserID, |
||
194 | //UserID = "H2009115", |
||
195 | //Mode = 0 , 1 , 2 |
||
196 | }; |
||
197 | ParameterMode = true; |
||
198 | 1137be84 | djkim | } |
199 | 1ed8da93 | humkyung | else |
200 | { |
||
201 | MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내"); |
||
202 | throw new ArgumentException("문서 정보가 입력되지 않았습니다."); |
||
203 | } |
||
204 | c4a4d59c | ljiyeon | } |
205 | 992a98b4 | KangIngu | |
206 | //App.ViewInfo.CreateFinalPDFPermission = false; |
||
207 | //App.ViewInfo.NewCommentPermission = false; |
||
208 | c4a4d59c | ljiyeon | //GetQueryStringParameters(); |
209 | _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
||
210 | 787a4489 | KangIngu | _binding.MaxBufferSize = 2147483647; |
211 | _binding.MaxReceivedMessageSize = 2147483647; |
||
212 | _binding.OpenTimeout = new TimeSpan(0, 1, 0); |
||
213 | _binding.ReceiveTimeout = new TimeSpan(0, 10, 0); |
||
214 | _binding.CloseTimeout = new TimeSpan(0, 5, 0); |
||
215 | _binding.SendTimeout = new TimeSpan(0, 5, 0); |
||
216 | _binding.TextEncoding = System.Text.Encoding.UTF8; |
||
217 | _binding.TransferMode = TransferMode.Buffered; |
||
218 | //Support.SetLicense(); |
||
219 | af22332b | ljiyeon | |
220 | 84c48033 | djkim | string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", ""); |
221 | 1137be84 | djkim | |
222 | 84c48033 | djkim | #if DEBUG |
223 | eb5cdefc | djkim | //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
224 | 566f0526 | taeseongkim | System.Diagnostics.Debug.WriteLine("sBaseServiceURL"); |
225 | ff01c725 | humkyung | sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
226 | 992a98b4 | KangIngu | #else |
227 | 36d6ae21 | taeseongkim | sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
228 | 992a98b4 | KangIngu | #endif |
229 | 4eb4f3f9 | humkyung | App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
230 | 84c48033 | djkim | _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
231 | 264c9309 | ljiyeon | |
232 | cdfb57ff | taeseongkim | await SplashScreenAsnyc(); |
233 | base.OnStartup(e); |
||
234 | 91e84544 | taeseongkim | |
235 | fa48eb85 | taeseongkim | System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent); |
236 | 787a4489 | KangIngu | } |
237 | catch (Exception ex) |
||
238 | { |
||
239 | 5aaf27a2 | djkim | MessageBox.Show("Err:" + ex.ToString()); |
240 | 787a4489 | KangIngu | } |
241 | f7e7a61a | ljiyeon | finally |
242 | { |
||
243 | cdfb57ff | taeseongkim | await SplashScreenAsnyc(); |
244 | 1137be84 | djkim | } |
245 | 787a4489 | KangIngu | } |
246 | a7346d3c | humkyung | |
247 | fa48eb85 | taeseongkim | private void KeyDownEvent(object sender, KeyEventArgs e) |
248 | { |
||
249 | if (e.Key == Key.Escape || e.Key == Key.Delete) |
||
250 | { |
||
251 | System.Diagnostics.Debug.WriteLine("app key Event"); |
||
252 | Common.ViewerDataModel.Instance.SystemMain.KeyEventDownAction(sender, e); |
||
253 | } |
||
254 | } |
||
255 | |||
256 | cdfb57ff | taeseongkim | private async Task<bool> SplashScreenAsnyc() |
257 | { |
||
258 | int value = 100 / ISplashMessage.SplashMessageCnt; |
||
259 | |||
260 | for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++) |
||
261 | { |
||
262 | System.Threading.Thread.Sleep(3); |
||
263 | await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value); |
||
264 | } |
||
265 | |||
266 | splashScreen.Close(); |
||
267 | |||
268 | return true; |
||
269 | } |
||
270 | |||
271 | e0cfc73c | ljiyeon | public static void splashString(string text) |
272 | { |
||
273 | Task.Factory.StartNew(() => |
||
274 | { |
||
275 | splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text); |
||
276 | }); |
||
277 | } |
||
278 | |||
279 | |||
280 | a7346d3c | humkyung | /// <summary> |
281 | /// log unhandled exception |
||
282 | /// </summary> |
||
283 | /// <author>humkyung</author> |
||
284 | /// <date>2019.05.21</date> |
||
285 | /// <param name="sender"></param> |
||
286 | /// <param name="e"></param> |
||
287 | private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) |
||
288 | { |
||
289 | try |
||
290 | { |
||
291 | 360e4f75 | djkim | App.FileLogger.Fatal(e.ExceptionObject as Exception); |
292 | a7346d3c | humkyung | } |
293 | catch (Exception ex) |
||
294 | { |
||
295 | 8614f701 | taeseongkim | Console.WriteLine(ex.InnerException?.ToString()); |
296 | a7346d3c | humkyung | } |
297 | finally |
||
298 | { |
||
299 | 8614f701 | taeseongkim | #if RELEASE |
300 | a7346d3c | humkyung | Environment.Exit(0); |
301 | 8614f701 | taeseongkim | #endif |
302 | a7346d3c | humkyung | } |
303 | } |
||
304 | |||
305 | c4a4d59c | ljiyeon | private void ErrorLogFileWrite(string Err) |
306 | { |
||
307 | ce3f0d7a | humkyung | App.FileLogger.Debug(Err); |
308 | c4a4d59c | ljiyeon | } |
309 | 787a4489 | KangIngu | } |
310 | } |