프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / App.xaml.cs @ cdfb57ff

이력 | 보기 | 이력해설 | 다운로드 (9.87 KB)

1

2
using KCOM.Common;
3
using KCOM.ServiceDeepView;
4
using System;
5
using System.Collections.Generic;
6
using System.ComponentModel;
7
using System.Configuration;
8
using System.Data;
9
using System.Diagnostics;
10
using System.IO;
11
using System.Linq;
12
using System.Net;
13
using System.Reflection;
14
using System.Runtime.CompilerServices;
15
using System.ServiceModel;
16
using System.Windows;
17
using System.Xml;
18
using log4net;
19
using System.Text;
20
using System.Runtime.InteropServices;
21
using KCOM.Views;
22
using System.Threading.Tasks;
23

    
24
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
25
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
        public static bool isExternal = false;
57

    
58
        /// <summary>
59
        /// logger
60
        /// </summary>
61
        public static ILog DBLogger = null;
62
        public static ILog FileLogger = null;
63

    
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

    
75
        
76
        public static RestSharp.RestClient BaseClient { get; set; }
77
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
78
        
79

    
80
        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
        private string versionPath = null;
93
        //public SplashScreen splash = new SplashScreen("splash.png");
94
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
95

    
96
        public App()
97
        {
98
           
99
        }
100

    
101
        protected override async void OnStartup(StartupEventArgs e)
102
        {
103
          
104
            try
105
            {
106
                splashScreen.Show();
107
               
108
                /// 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
                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

    
121
                //splash.Show(false, false);                
122
                        
123
                if (e.Args.Count() > 0)
124
                {
125
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
126
                    App.ViewInfo = new IKCOM.ViewInfo
127
                    {
128
                        DocumentItemID = result.DocumentItemID,
129
                        EnsembleID = result.DocumentItemID,
130
                        //DocumentItemID = "10001",
131
                        bPartner = result.bPartner,
132
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
133
                        NewCommentPermission = result.NewCommentPermission,
134
                        ProjectNO = result.ProjectNO,
135
                        UserID = result.UserID,
136
                        //UserID = "H2009115",
137
                        //Mode = 0 , 1 , 2
138
                    };
139
                    ParameterMode = true;
140
                }
141
                else
142
                {
143
                    string[] strArg = Environment.GetCommandLineArgs();
144
                    if (strArg.Length > 1)
145
                    {
146
                        //label1.Text = strArg[1];
147

    
148
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
149
                        App.ViewInfo = new IKCOM.ViewInfo
150
                        {
151
                            DocumentItemID = result.DocumentItemID,
152
                            EnsembleID = result.DocumentItemID,
153
                            //DocumentItemID = "10001",
154
                            bPartner = result.bPartner,
155
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
156
                            NewCommentPermission = result.NewCommentPermission,
157
                            ProjectNO = result.ProjectNO,
158
                            UserID = result.UserID,
159
                            //UserID = "H2009115",
160
                            //Mode = 0 , 1 , 2
161
                        };
162
                        ParameterMode = true;
163
                    }                
164
                }
165

    
166
                //App.ViewInfo.CreateFinalPDFPermission = false;
167
                //App.ViewInfo.NewCommentPermission = false;
168
                //GetQueryStringParameters();
169
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
170
                _binding.MaxBufferSize = 2147483647;
171
                _binding.MaxReceivedMessageSize = 2147483647;
172
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
173
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
174
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
175
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
176
                _binding.TextEncoding = System.Text.Encoding.UTF8;
177
                _binding.TransferMode = TransferMode.Buffered;
178
                //Support.SetLicense();
179

    
180
                string sBaseServiceURL = string.Empty;//CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "");
181
                string localdomain = CommonLib.Common.GetConfigString("HOST_DOMAIN", "DOMAIN", "");
182

    
183
                var hostEntry = CommonLib.DNSHelper.GetHostEntryTask();
184

    
185
                if (hostEntry == null || !hostEntry.HostName.EndsWith(localdomain))
186
                {
187
                    // 외부 사용자
188
                    isExternal = true;
189
                }
190
#if DEBUG
191
                //sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", isExternal);
192
                sBaseServiceURL = CommonLib.Common.GetConfigString("Debug_BaseClientAddress", "URL", "", isExternal);
193
#else
194
                sBaseServiceURL = CommonLib.Common.GetConfigString("BaseClientAddress", "URL", "", IsExternal);
195
#endif
196

    
197
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
198

    
199
                await SplashScreenAsnyc();
200
                base.OnStartup(e);
201

    
202
                //this.MainWindow = new MainWindow();
203

    
204
            }
205
            catch (Exception ex)
206
            {
207
                MessageBox.Show("Err:" + ex.ToString());
208
            }
209
            finally
210
            {
211
                await SplashScreenAsnyc();
212
            }        
213
        }
214

    
215
        private async Task<bool> SplashScreenAsnyc()
216
        {
217
            int value = 100 / ISplashMessage.SplashMessageCnt;
218

    
219
            for (int i = 1; i < ISplashMessage.SplashMessageCnt; i++)
220
            {
221
                System.Threading.Thread.Sleep(3);
222
                await splashScreen.Dispatcher.InvokeAsync(() => splashScreen.Progress = i * value);
223
            }
224

    
225
            splashScreen.Close();
226

    
227
            return true;
228
        }
229

    
230
        public static void splashString(string text)
231
        {
232
            Task.Factory.StartNew(() =>
233
            {
234
                splashScreen.Dispatcher.Invoke(() => splashScreen.SplashText = text);
235
            });
236
        }
237

    
238

    
239
        /// <summary>
240
        /// log unhandled exception
241
        /// </summary>
242
        /// <author>humkyung</author>
243
        /// <date>2019.05.21</date>
244
        /// <param name="sender"></param>
245
        /// <param name="e"></param>
246
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
247
        {
248
            try
249
            {
250
                App.DBLogger.Fatal(e.ExceptionObject as Exception);
251
            }
252
            catch (Exception ex)
253
            {
254
                Console.WriteLine(ex.InnerException?.ToString());
255
            }
256
            finally
257
            {
258
#if RELEASE
259
                Environment.Exit(0);
260
#endif
261
            }
262
        }
263

    
264
        private void ErrorLogFileWrite(string Err)
265
        {
266
            App.FileLogger.Debug(Err);
267
        }
268
    }
269
}
클립보드 이미지 추가 (최대 크기: 500 MB)