프로젝트

일반

사용자정보

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

markus / KCOM / App.xaml.cs @ af22332b

이력 | 보기 | 이력해설 | 다운로드 (10.3 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

    
19
namespace KCOM
20
{
21
    public class OpenProperties
22
    {
23
        public string DocumentItemID { get; set; }
24
        public bool bPartner { get; set; }
25
        public bool CreateFinalPDFPermission { get; set; }
26
        public bool NewCommentPermission { get; set; }
27
        public string ProjectNO { get; set; }
28
        public string UserID { get; set; }
29
        public int Mode { get; set; }
30
    }
31
    /// <summary>
32
    /// App.xaml에 대한 상호 작용 논리
33
    /// </summary>
34
    public partial class App : Application
35
    {
36
        public static BasicHttpBinding _binding;
37
        public static EndpointAddress _EndPoint;
38
        public static EndpointAddress _EndPoint_SaveLoad;
39
        public static EndpointAddress _EndPoint_Symbol;
40
        public static string UserID;
41
        public static string UserName;
42
        public static string UserIP;
43
        public static IKCOM.ViewInfo ViewInfo;
44
        public static string urlHost;
45
        public static string urlPort;
46
        public static string urlHost_DB;
47
        public static string urlPort_DB;
48
        public static string Custom_ViewInfoId;
49
        public static bool ParameterMode = false;
50

    
51

    
52
        public static RestSharp.RestClient BaseClient { get; set; }
53
        public static IKCOM.KCOM_SystemInfo SystemInfo { get; set; }
54
        private static OpenProperties ParamDecoding(string DecodingText, System.Text.Encoding oEncoding = null)
55
        {
56
            if (oEncoding == null)
57
                oEncoding = System.Text.Encoding.UTF8;
58

    
59
            byte[] byteArray = Convert.FromBase64String(DecodingText);
60

    
61
            string jsonBack = oEncoding.GetString(byteArray);
62

    
63
            return Newtonsoft.Json.JsonConvert.DeserializeObject<OpenProperties>(jsonBack);
64
        }
65

    
66
        private string versionPath = null;
67
        public SplashScreen splash = new SplashScreen("splash.png");
68

    
69
        protected override void OnStartup(StartupEventArgs e)
70
        {
71
            try
72
            {               
73
                splash.Show(false, false);
74

    
75
                if (e.Args.Count() > 0)
76
                {
77
                    var result = ParamDecoding(e.Args[0].Replace(@"kcom://", "").Replace(@"/", ""));
78
                    App.ViewInfo = new IKCOM.ViewInfo
79
                    {
80
                        DocumentItemID = result.DocumentItemID,
81
                        //DocumentItemID = "10001",
82
                        bPartner = result.bPartner,
83
                        CreateFinalPDFPermission = result.CreateFinalPDFPermission,
84
                        NewCommentPermission = result.NewCommentPermission,
85
                        ProjectNO = result.ProjectNO,
86
                        UserID = result.UserID,
87
                        //UserID = "H2009115",
88
                        //Mode = 0 , 1 , 2
89
                    };
90
                    ParameterMode = true;
91
                }
92
                else
93
                {
94
                    string[] strArg = Environment.GetCommandLineArgs();
95
                    if (strArg.Length > 1)
96
                    {
97
                        //label1.Text = strArg[1];
98

    
99
                        var result = ParamDecoding(strArg[1].Replace(@"kcom://", "").Replace(@"/", ""));
100
                        App.ViewInfo = new IKCOM.ViewInfo
101
                        {
102
                            DocumentItemID = result.DocumentItemID,
103
                            //DocumentItemID = "10001",
104
                            bPartner = result.bPartner,
105
                            CreateFinalPDFPermission = result.CreateFinalPDFPermission,
106
                            NewCommentPermission = result.NewCommentPermission,
107
                            ProjectNO = result.ProjectNO,
108
                            UserID = result.UserID,
109
                            //UserID = "H2009115",
110
                            //Mode = 0 , 1 , 2
111
                        };
112
                        ParameterMode = true;
113
                    }                
114
                }
115

    
116
                //App.ViewInfo.CreateFinalPDFPermission = false;
117
                //App.ViewInfo.NewCommentPermission = false;
118

    
119
                //GetQueryStringParameters();
120
                _binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
121
                _binding.MaxBufferSize = 2147483647;
122
                _binding.MaxReceivedMessageSize = 2147483647;
123
                _binding.OpenTimeout = new TimeSpan(0, 1, 0);
124
                _binding.ReceiveTimeout = new TimeSpan(0, 10, 0);
125
                _binding.CloseTimeout = new TimeSpan(0, 5, 0);
126
                _binding.SendTimeout = new TimeSpan(0, 5, 0);
127
                _binding.TextEncoding = System.Text.Encoding.UTF8;
128
                _binding.TransferMode = TransferMode.Buffered;
129
                //Support.SetLicense();
130

    
131
                string sBaseServiceURL = global::KCOM.Properties.Settings.Default.BaseClientAddress;
132

    
133
                var ipaddress = DNSHelper.GetDnsAdress();
134

    
135
                try
136
                {
137
                    var hostName = Dns.GetHostEntry(ipaddress).HostName;
138

    
139
                    if (!hostName.EndsWith(KCOM.Properties.Settings.Default.HOST_DOMAIN))
140
                    {
141
                        // 외부 사용자
142
                        sBaseServiceURL = global::KCOM.Properties.Settings.Default.Remote_BaseClientAddress;
143
                    }
144
                }
145
                catch (Exception ex)
146
                {
147
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
148
                }
149
#if DEBUG
150
                //_EndPoint = new EndpointAddress(@"http://10.11.252.3/MARKUS/ServiceDeepView.svc"); //효성
151
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
152

    
153
#else
154
                _EndPoint = new EndpointAddress(string.Format("{0}/ServiceDeepView.svc", sBaseServiceURL));
155
#endif
156
                
157
                if (Environment.Is64BitProcess == true) //64 bit machine
158
                {
159
                    versionPath = KCOM.Properties.Settings.Default.UpdateVer64;
160
                }
161
                else //32 bit machine
162
                {
163
                    versionPath = KCOM.Properties.Settings.Default.UpdateVer86;
164
                }
165

    
166
                if (File.Exists(versionPath))
167
                {
168
                    // 20180921 version.xml check로 변경
169
                    var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
170
                    try
171
                    {
172
                        XmlDocument xdoc = new XmlDocument();
173
                        xdoc.Load(versionPath);
174
                        XmlNode node = xdoc.SelectSingleNode("/RootElement/version");
175

    
176
                        if (assemblyVersion != node.InnerText) // node.InnerText 가 null이면 catch로 빠짐
177
                        {
178
                            //if(MessageBox.Show("Ver. " + node.InnerText + " 업데이트가 있습니다.\r\nSmartUpdate를 실행합니다.", "MARKUS", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
179
                            //{
180
                            if (MessageBox.Show("Ver. " + node.InnerText, "MARKUS", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
181
                            {
182
                                UpdateCheck(e);
183
                            }
184
                            else
185
                            {
186
                                base.Shutdown();
187
                                //현재 실행되고 있는 자기 자신 프로세스의 정보 // 위에꺼랑 두개 다 써줄필요가 있는..가?
188
                                Process proc = Process.GetCurrentProcess();
189
                                proc.Kill();
190
                            }
191
                        }
192
                        else
193
                        {
194
                            base.OnStartup(e);
195
                            splash.Close(new TimeSpan(0, 0, 2));
196
                        }
197
                    }
198
                    catch (Exception ex) //2. 파일이 없거나 파일내에 version의 값이 없다면 KCOM 실행하기
199
                    {
200
                        ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ex);
201
                        base.OnStartup(e);
202
                        splash.Close(new TimeSpan(0, 0, 2));
203
                    }
204
                }
205
            }
206
            catch (Exception ex)
207
            {
208
                MessageBox.Show("Err" + ex.Message);
209
            }
210
        }
211
        
212
        protected void UpdateCheck(StartupEventArgs e)
213
        {          
214
            try
215
            {
216
                if (e.Args.Count() > 0)
217
                {
218
                    ProcessStartInfo proInfo = new ProcessStartInfo();
219
                    var FileName = AppDomain.CurrentDomain.BaseDirectory + "SmartUpdate.exe";
220
                    
221
                    Process.Start(FileName, e.Args[0]);
222

    
223
                    base.Shutdown();
224
                    //현재 실행되고 있는 자기 자신 프로세스의 정보 
225
                    Process proc = Process.GetCurrentProcess();
226
                    proc.Kill();
227
                }                    
228
            }
229
            catch(Exception ee)
230
            {
231
                ErrorLogFileWrite("KCOM//UpdateCheck ERR : " + ee);
232
            }            
233
        }
234

    
235
        private void ErrorLogFileWrite(string Err)
236
        {
237
            try
238
            {
239
                string FilePath = "C:\\ProgramData\\MARKUS\\";
240
                //string pathString = AppDomain.CurrentDomain.BaseDirectory + "Err";
241
                string pathString = FilePath + "Err";
242

    
243
                if (!File.Exists(pathString))
244
                {
245
                    Directory.CreateDirectory(pathString);
246
                }
247

    
248
                Err = Err + "   " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\r\n";
249
                string path = pathString + "\\" + "Log_" + DateTime.Now.ToString("yyyy-MM-dd hh-mm") + ".txt";
250
                File.AppendAllText(path, Err);
251
            }
252
            catch (Exception er)
253
            {
254
                string strError = er.ToString();
255
                //MessageBox.Show("err : " + er);
256
            }
257
        }
258
    }
259
}
클립보드 이미지 추가 (최대 크기: 500 MB)