markus / KCOM / App.xaml.cs @ 52827a4c
이력 | 보기 | 이력해설 | 다운로드 (11.2 KB)
1 | 787a4489 | KangIngu | |
---|---|---|---|
2 | af22332b | ljiyeon | using KCOM.Common; |
3 | c4a4d59c | ljiyeon | using KCOM.ServiceDeepView; |
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 | /// 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 | 787a4489 | KangIngu | |
76 | 1137be84 | djkim | |
77 | 787a4489 | KangIngu | public static RestSharp.RestClient BaseClient { get; set; } |
78 | public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; } |
||
79 | 1137be84 | djkim | |
80 | 264c9309 | ljiyeon | |
81 | 787a4489 | KangIngu | 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 | c4a4d59c | ljiyeon | private string versionPath = null; |
94 | cf2671a6 | ljiyeon | //public SplashScreen splash = new SplashScreen("splash.png"); |
95 | e0cfc73c | ljiyeon | public static SplashScreenWindow splashScreen = new SplashScreenWindow(); |
96 | cdfb57ff | taeseongkim | |
97 | public App() |
||
98 | { |
||
99 | aff63364 | taeseongkim | Telerik.Windows.Controls.StyleManager.ApplicationTheme = new Telerik.Windows.Controls.VisualStudio2013Theme(); |
100 | cdfb57ff | taeseongkim | } |
101 | |||
102 | protected override async void OnStartup(StartupEventArgs e) |
||
103 | { |
||
104 | 787a4489 | KangIngu | try |
105 | a7346d3c | humkyung | { |
106 | cf2671a6 | ljiyeon | splashScreen.Show(); |
107 | 1137be84 | djkim | |
108 | a7346d3c | humkyung | /// 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 | ce3f0d7a | humkyung | 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 | a7346d3c | humkyung | |
121 | 1137be84 | djkim | #region // DNS 체크 |
122 | |||
123 | string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", ""); |
||
124 | |||
125 | var hostEntry = CommonLib.DNSHelper.GetHostEntryTask(); |
||
126 | df33d20a | djkim | |
127 | 1137be84 | djkim | if (hostEntry == null) |
128 | { |
||
129 | System.Diagnostics.Debug.WriteLine("(hostEntry == null"); |
||
130 | 1ed8da93 | humkyung | App.FileLogger.Debug("hostEntry == null"); |
131 | 1137be84 | djkim | isExternal = true; |
132 | } |
||
133 | ddfd4bc7 | djkim | else if (!string.IsNullOrEmpty(localdomain) && !hostEntry.HostName.ToUpper().EndsWith(localdomain.ToUpper())) |
134 | 1137be84 | djkim | { |
135 | // 외부 사용자 |
||
136 | 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)); |
137 | 1137be84 | djkim | isExternal = true; |
138 | } |
||
139 | #endregion |
||
140 | |||
141 | 787a4489 | KangIngu | if (e.Args.Count() > 0) |
142 | { |
||
143 | c4a4d59c | ljiyeon | var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
144 | 787a4489 | KangIngu | App.ViewInfo = new IKCOM.ViewInfo |
145 | { |
||
146 | DocumentItemID = result.DocumentItemID, |
||
147 | 35afe17c | djkim | EnsembleID = result.DocumentItemID, |
148 | 787a4489 | KangIngu | //DocumentItemID = "10001", |
149 | bPartner = result.bPartner, |
||
150 | bc664e9b | djkim | CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
151 | NewCommentPermission = result.NewCommentPermission, |
||
152 | 787a4489 | KangIngu | ProjectNO = result.ProjectNO, |
153 | UserID = result.UserID, |
||
154 | //UserID = "H2009115", |
||
155 | //Mode = 0 , 1 , 2 |
||
156 | }; |
||
157 | ParameterMode = true; |
||
158 | } |
||
159 | c4a4d59c | ljiyeon | 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 | 35afe17c | djkim | EnsembleID = result.DocumentItemID, |
169 | c4a4d59c | ljiyeon | //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 | 1137be84 | djkim | } |
180 | 1ed8da93 | humkyung | else |
181 | { |
||
182 | MessageBox.Show("문서 정보가 입력되지 않았습니다.\n프로그램이 종료됩니다.", "안내"); |
||
183 | throw new ArgumentException("문서 정보가 입력되지 않았습니다."); |
||
184 | } |
||
185 | c4a4d59c | ljiyeon | } |
186 | 992a98b4 | KangIngu | |
187 | //App.ViewInfo.CreateFinalPDFPermission = false; |
||
188 | //App.ViewInfo.NewCommentPermission = false; |
||
189 | c4a4d59c | ljiyeon | //GetQueryStringParameters(); |
190 | _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
||
191 | 787a4489 | KangIngu | _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 | af22332b | ljiyeon | |
201 | 84c48033 | djkim | string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", ""); |
202 | 1137be84 | djkim | |
203 | 84c48033 | djkim | #if DEBUG |
204 | eb5cdefc | djkim | //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
205 | 566f0526 | taeseongkim | System.Diagnostics.Debug.WriteLine("sBaseServiceURL"); |
206 | ff01c725 | humkyung | sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
207 | 992a98b4 | KangIngu | #else |
208 | 36d6ae21 | taeseongkim | sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
209 | 992a98b4 | KangIngu | #endif |
210 | 4eb4f3f9 | humkyung | App.FileLogger.Debug(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
211 | 84c48033 | djkim | _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
212 | 264c9309 | ljiyeon | |
213 | cdfb57ff | taeseongkim | await SplashScreenAsnyc(); |
214 | base.OnStartup(e); |
||
215 | fa48eb85 | taeseongkim | |
216 | System.Windows.Input.Keyboard.AddKeyDownHandler(this.MainWindow, KeyDownEvent); |
||
217 | |||
218 | 787a4489 | KangIngu | } |
219 | catch (Exception ex) |
||
220 | { |
||
221 | 5aaf27a2 | djkim | MessageBox.Show("Err:" + ex.ToString()); |
222 | 787a4489 | KangIngu | } |
223 | f7e7a61a | ljiyeon | finally |
224 | { |
||
225 | cdfb57ff | taeseongkim | await SplashScreenAsnyc(); |
226 | 1137be84 | djkim | } |
227 | 787a4489 | KangIngu | } |
228 | a7346d3c | humkyung | |
229 | fa48eb85 | taeseongkim | 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 | cdfb57ff | taeseongkim | 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 | e0cfc73c | ljiyeon | public static void splashString(string text) |
254 | { |
||
255 | Task.Factory.StartNew(() => |
||
256 | { |
||
257 | splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text); |
||
258 | }); |
||
259 | } |
||
260 | |||
261 | |||
262 | a7346d3c | humkyung | /// <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 | 360e4f75 | djkim | App.FileLogger.Fatal(e.ExceptionObject as Exception); |
274 | a7346d3c | humkyung | } |
275 | catch (Exception ex) |
||
276 | { |
||
277 | 8614f701 | taeseongkim | Console.WriteLine(ex.InnerException?.ToString()); |
278 | a7346d3c | humkyung | } |
279 | finally |
||
280 | { |
||
281 | 8614f701 | taeseongkim | #if RELEASE |
282 | a7346d3c | humkyung | Environment.Exit(0); |
283 | 8614f701 | taeseongkim | #endif |
284 | a7346d3c | humkyung | } |
285 | } |
||
286 | |||
287 | c4a4d59c | ljiyeon | private void ErrorLogFileWrite(string Err) |
288 | { |
||
289 | ce3f0d7a | humkyung | App.FileLogger.Debug(Err); |
290 | c4a4d59c | ljiyeon | } |
291 | 787a4489 | KangIngu | } |
292 | } |