markus / KCOM / App.xaml.cs @ 8614f701
이력 | 보기 | 이력해설 | 다운로드 (10.8 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 | 787a4489 | KangIngu | |
24 | a7346d3c | humkyung | [assembly: log4net.Config.XmlConfigurator(Watch = true)] |
25 | 787a4489 | KangIngu | namespace KCOM |
26 | { |
||
27 | public class OpenProperties |
||
28 | { |
||
29 | public string DocumentItemID { get; set; } |
||
30 | public bool bPartner { get; set; } |
||
31 | public bool CreateFinalPDFPermission { get; set; } |
||
32 | public bool NewCommentPermission { get; set; } |
||
33 | public string ProjectNO { get; set; } |
||
34 | public string UserID { get; set; } |
||
35 | public int Mode { get; set; } |
||
36 | } |
||
37 | /// <summary> |
||
38 | /// App.xaml에 대한 상호 작용 논리 |
||
39 | /// </summary> |
||
40 | public partial class App : Application |
||
41 | { |
||
42 | public static BasicHttpBinding _binding; |
||
43 | public static EndpointAddress _EndPoint; |
||
44 | public static EndpointAddress _EndPoint_SaveLoad; |
||
45 | public static EndpointAddress _EndPoint_Symbol; |
||
46 | public static string UserID; |
||
47 | public static string UserName; |
||
48 | public static string UserIP; |
||
49 | public static IKCOM.ViewInfo ViewInfo; |
||
50 | public static string urlHost; |
||
51 | public static string urlPort; |
||
52 | public static string urlHost_DB; |
||
53 | public static string urlPort_DB; |
||
54 | public static string Custom_ViewInfoId; |
||
55 | public static bool ParameterMode = false; |
||
56 | 84c48033 | djkim | public static bool isExternal = false; |
57 | 787a4489 | KangIngu | |
58 | a7346d3c | humkyung | /// <summary> |
59 | /// logger |
||
60 | /// </summary> |
||
61 | ce3f0d7a | humkyung | public static ILog DBLogger = null; |
62 | public static ILog FileLogger = null; |
||
63 | a7346d3c | humkyung | |
64 | /// <summary> |
||
65 | /// Application Data Folder |
||
66 | /// </summary> |
||
67 | public static string AppDataFolder |
||
68 | { |
||
69 | get |
||
70 | { |
||
71 | return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS"); |
||
72 | } |
||
73 | } |
||
74 | 787a4489 | KangIngu | |
75 | 5928384e | djkim | |
76 | 787a4489 | KangIngu | public static RestSharp.RestClient BaseClient { get; set; } |
77 | public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; } |
||
78 | 264c9309 | ljiyeon | |
79 | |||
80 | 787a4489 | KangIngu | private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null) |
81 | { |
||
82 | if (oEncoding == null) |
||
83 | oEncoding = System.Text.Encoding.UTF8; |
||
84 | |||
85 | byte[] byteArray = Convert.FromBase64String(DecodingText); |
||
86 | |||
87 | string jsonBack = oEncoding.GetString(byteArray); |
||
88 | |||
89 | return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack); |
||
90 | } |
||
91 | |||
92 | c4a4d59c | ljiyeon | private string versionPath = null; |
93 | cf2671a6 | ljiyeon | //public SplashScreen splash = new SplashScreen("splash.png"); |
94 | e0cfc73c | ljiyeon | public static SplashScreenWindow splashScreen = new SplashScreenWindow(); |
95 | 787a4489 | KangIngu | protected override void OnStartup(StartupEventArgs e) |
96 | cf2671a6 | ljiyeon | { |
97 | 787a4489 | KangIngu | try |
98 | a7346d3c | humkyung | { |
99 | cf2671a6 | ljiyeon | splashScreen.Show(); |
100 | |||
101 | a7346d3c | humkyung | /// create log database and table |
102 | using (IAbstractDatabase database = new AppSQLiteDatabase() { FilePath = Path.Combine(AppDataFolder, "log4net.db") }) |
||
103 | { |
||
104 | 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);"; |
||
105 | database.ExecuteNonQuery(sSql); |
||
106 | } |
||
107 | /// up to here |
||
108 | AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |
||
109 | ce3f0d7a | humkyung | log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db"); |
110 | log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log"); |
||
111 | App.DBLogger = LogManager.GetLogger("DBLogger"); |
||
112 | App.FileLogger = LogManager.GetLogger("EventLogger"); |
||
113 | a7346d3c | humkyung | |
114 | cf2671a6 | ljiyeon | //splash.Show(false, false); |
115 | |||
116 | 787a4489 | KangIngu | if (e.Args.Count() > 0) |
117 | { |
||
118 | c4a4d59c | ljiyeon | var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", "")); |
119 | 787a4489 | KangIngu | App.ViewInfo = new IKCOM.ViewInfo |
120 | { |
||
121 | DocumentItemID = result.DocumentItemID, |
||
122 | 35afe17c | djkim | EnsembleID = result.DocumentItemID, |
123 | 787a4489 | KangIngu | //DocumentItemID = "10001", |
124 | bPartner = result.bPartner, |
||
125 | bc664e9b | djkim | CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
126 | NewCommentPermission = result.NewCommentPermission, |
||
127 | 787a4489 | KangIngu | ProjectNO = result.ProjectNO, |
128 | UserID = result.UserID, |
||
129 | //UserID = "H2009115", |
||
130 | //Mode = 0 , 1 , 2 |
||
131 | }; |
||
132 | ParameterMode = true; |
||
133 | } |
||
134 | c4a4d59c | ljiyeon | else |
135 | { |
||
136 | string[] strArg = Environment.GetCommandLineArgs(); |
||
137 | if (strArg.Length > 1) |
||
138 | { |
||
139 | //label1.Text = strArg[1]; |
||
140 | |||
141 | var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", "")); |
||
142 | App.ViewInfo = new IKCOM.ViewInfo |
||
143 | { |
||
144 | DocumentItemID = result.DocumentItemID, |
||
145 | 35afe17c | djkim | EnsembleID = result.DocumentItemID, |
146 | c4a4d59c | ljiyeon | //DocumentItemID = "10001", |
147 | bPartner = result.bPartner, |
||
148 | CreateFinalPDFPermission = result.CreateFinalPDFPermission, |
||
149 | NewCommentPermission = result.NewCommentPermission, |
||
150 | ProjectNO = result.ProjectNO, |
||
151 | UserID = result.UserID, |
||
152 | //UserID = "H2009115", |
||
153 | //Mode = 0 , 1 , 2 |
||
154 | }; |
||
155 | ParameterMode = true; |
||
156 | } |
||
157 | } |
||
158 | 992a98b4 | KangIngu | |
159 | //App.ViewInfo.CreateFinalPDFPermission = false; |
||
160 | //App.ViewInfo.NewCommentPermission = false; |
||
161 | c4a4d59c | ljiyeon | //GetQueryStringParameters(); |
162 | _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly); |
||
163 | 787a4489 | KangIngu | _binding.MaxBufferSize = 2147483647; |
164 | _binding.MaxReceivedMessageSize = 2147483647; |
||
165 | _binding.OpenTimeout = new TimeSpan(0, 1, 0); |
||
166 | _binding.ReceiveTimeout = new TimeSpan(0, 10, 0); |
||
167 | _binding.CloseTimeout = new TimeSpan(0, 5, 0); |
||
168 | _binding.SendTimeout = new TimeSpan(0, 5, 0); |
||
169 | _binding.TextEncoding = System.Text.Encoding.UTF8; |
||
170 | _binding.TransferMode = TransferMode.Buffered; |
||
171 | //Support.SetLicense(); |
||
172 | af22332b | ljiyeon | |
173 | 84c48033 | djkim | string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", ""); |
174 | string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", ""); |
||
175 | eb5cdefc | djkim | var ipaddress = CommonLib.DNSHelper.GetDnsAdress(); |
176 | af22332b | ljiyeon | |
177 | try |
||
178 | { |
||
179 | var hostName = Dns.GetHostEntry(ipaddress).HostName; |
||
180 | |||
181 | 84c48033 | djkim | if (!hostName.EndsWith(localdomain)) |
182 | af22332b | ljiyeon | { |
183 | // 외부 사용자 |
||
184 | 84c48033 | djkim | isExternal = true; |
185 | af22332b | ljiyeon | } |
186 | } |
||
187 | catch (Exception ex) |
||
188 | { |
||
189 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
190 | } |
||
191 | 84c48033 | djkim | #if DEBUG |
192 | eb5cdefc | djkim | //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
193 | 19391ad3 | djkim | sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "",isExternal); |
194 | 992a98b4 | KangIngu | #else |
195 | 84c48033 | djkim | sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal); |
196 | 992a98b4 | KangIngu | #endif |
197 | eb5cdefc | djkim | |
198 | 84c48033 | djkim | _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL)); |
199 | 264c9309 | ljiyeon | |
200 | Task.Factory.StartNew(() => |
||
201 | c4a4d59c | ljiyeon | { |
202 | 264c9309 | ljiyeon | int value = 100 / ISplashMessage.SplashMessageCnt; |
203 | for (int i = 1; i <= ISplashMessage.SplashMessageCnt; i++) |
||
204 | c4a4d59c | ljiyeon | { |
205 | 264c9309 | ljiyeon | System.Threading.Thread.Sleep(3); |
206 | splashScreen.Dispatcher.Invoke(() => splashScreen.Progress = i * value); |
||
207 | c4a4d59c | ljiyeon | } |
208 | 264c9309 | ljiyeon | |
209 | this.Dispatcher.Invoke(() => |
||
210 | c4a4d59c | ljiyeon | { |
211 | 264c9309 | ljiyeon | base.OnStartup(e); |
212 | splashScreen.Close(); |
||
213 | }); |
||
214 | }); |
||
215 | 787a4489 | KangIngu | } |
216 | catch (Exception ex) |
||
217 | { |
||
218 | 5aaf27a2 | djkim | MessageBox.Show("Err:" + ex.ToString()); |
219 | 787a4489 | KangIngu | } |
220 | f7e7a61a | ljiyeon | finally |
221 | { |
||
222 | cf2671a6 | ljiyeon | Task.Factory.StartNew(() => |
223 | { |
||
224 | e0cfc73c | ljiyeon | int value = 100 / ISplashMessage.SplashMessageCnt; |
225 | for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++) |
||
226 | cf2671a6 | ljiyeon | { |
227 | 264c9309 | ljiyeon | System.Threading.Thread.Sleep(3); |
228 | splashScreen.Dispatcher.Invoke(() => splashScreen.Progress = i * value); |
||
229 | cf2671a6 | ljiyeon | } |
230 | this.Dispatcher.Invoke(() => |
||
231 | { |
||
232 | //base.OnStartup(e); |
||
233 | splashScreen.Close(); |
||
234 | }); |
||
235 | }); |
||
236 | 264c9309 | ljiyeon | } |
237 | 787a4489 | KangIngu | } |
238 | a7346d3c | humkyung | |
239 | e0cfc73c | ljiyeon | public static void splashString(string text) |
240 | { |
||
241 | Task.Factory.StartNew(() => |
||
242 | { |
||
243 | splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text); |
||
244 | }); |
||
245 | } |
||
246 | |||
247 | |||
248 | a7346d3c | humkyung | /// <summary> |
249 | /// log unhandled exception |
||
250 | /// </summary> |
||
251 | /// <author>humkyung</author> |
||
252 | /// <date>2019.05.21</date> |
||
253 | /// <param name="sender"></param> |
||
254 | /// <param name="e"></param> |
||
255 | private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) |
||
256 | { |
||
257 | try |
||
258 | { |
||
259 | ce3f0d7a | humkyung | App.DBLogger.Fatal(e.ExceptionObject as Exception); |
260 | a7346d3c | humkyung | } |
261 | catch (Exception ex) |
||
262 | { |
||
263 | 8614f701 | taeseongkim | Console.WriteLine(ex.InnerException?.ToString()); |
264 | a7346d3c | humkyung | } |
265 | finally |
||
266 | { |
||
267 | 8614f701 | taeseongkim | #if RELEASE |
268 | a7346d3c | humkyung | Environment.Exit(0); |
269 | 8614f701 | taeseongkim | #endif |
270 | a7346d3c | humkyung | } |
271 | } |
||
272 | |||
273 | c4a4d59c | ljiyeon | private void ErrorLogFileWrite(string Err) |
274 | { |
||
275 | ce3f0d7a | humkyung | App.FileLogger.Debug(Err); |
276 | c4a4d59c | ljiyeon | } |
277 | 787a4489 | KangIngu | } |
278 | } |