1
|
using KCOM.Common;
|
2
|
using KCOM.Controls;
|
3
|
using KCOM.Views;
|
4
|
using KCOMDataModel;
|
5
|
using KCOMDataModel.DataModel;
|
6
|
using MarkupToPDF.Common;
|
7
|
using MarkupToPDF.Controls.Parsing;
|
8
|
using MarkupToPDF.Serialize.Core;
|
9
|
using MarkupToPDF.Serialize.S_Control;
|
10
|
using System;
|
11
|
using System.Collections.Generic;
|
12
|
using System.ComponentModel;
|
13
|
using System.Diagnostics;
|
14
|
using System.IO;
|
15
|
using System.Linq;
|
16
|
using System.Net;
|
17
|
using System.Reflection;
|
18
|
using System.Runtime.InteropServices;
|
19
|
using System.Text;
|
20
|
using System.Threading;
|
21
|
using System.Threading.Tasks;
|
22
|
using System.Windows;
|
23
|
using System.Windows.Controls;
|
24
|
using System.Windows.Data;
|
25
|
using System.Windows.Documents;
|
26
|
using System.Windows.Input;
|
27
|
using System.Windows.Media;
|
28
|
using System.Windows.Media.Imaging;
|
29
|
using System.Windows.Navigation;
|
30
|
using System.Windows.Shapes;
|
31
|
using System.Xml;
|
32
|
using Telerik.Windows.Controls;
|
33
|
using WinInterop = System.Windows.Interop;
|
34
|
|
35
|
namespace KCOM
|
36
|
{
|
37
|
/// <summary>
|
38
|
/// MainWindow.xaml에 대한 상호 작용 논리
|
39
|
/// </summary>
|
40
|
public partial class MainWindow : Window
|
41
|
{
|
42
|
bool isSaveCheck = false;
|
43
|
|
44
|
ProgressControl progressControl = null;
|
45
|
string destfilepath = string.Empty;
|
46
|
|
47
|
public MainWindow()
|
48
|
{
|
49
|
App.splashString(ISplashMessage.MAINWINDOW);
|
50
|
this.Loaded += MainWindow_Loaded;
|
51
|
this.Unloaded += MainWindow_Unloaded;
|
52
|
this.PreviewKeyDown += new KeyEventHandler(KeyEventDownAction);
|
53
|
this.Activated += MainWindow_Activated;
|
54
|
}
|
55
|
|
56
|
private void MainWindow_Activated(object sender, EventArgs e)
|
57
|
{
|
58
|
this.Topmost = true;
|
59
|
}
|
60
|
|
61
|
private void MainWindow_Unloaded(object sender, RoutedEventArgs e)
|
62
|
{
|
63
|
//ViewerDataModel.Instance.ImageViewPath.UriSource = null;
|
64
|
//ViewerDataModel.Instance.ImageViewPath_C.UriSource = null;
|
65
|
}
|
66
|
|
67
|
public static BitmapImage CursorChange()
|
68
|
{
|
69
|
BitmapImage bmp = new BitmapImage();
|
70
|
bmp.BeginInit();
|
71
|
bmp.StreamSource = System.Windows.Application.GetResourceStream(new Uri("/KCOM;Component/Resources/Cursor/customCursor2.cur", UriKind.Relative)).Stream;
|
72
|
return bmp;
|
73
|
}
|
74
|
|
75
|
public void DialogMessage_Alert(string content, string header)
|
76
|
{
|
77
|
Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters()
|
78
|
{
|
79
|
Owner = Application.Current.MainWindow,
|
80
|
Content = new TextBlock()
|
81
|
{
|
82
|
MinWidth = 400,
|
83
|
FontSize = 12,
|
84
|
Text = content,
|
85
|
TextWrapping = System.Windows.TextWrapping.Wrap
|
86
|
},
|
87
|
Header = header,
|
88
|
Theme = new Telerik.Windows.Controls.VisualStudio2013Theme(),
|
89
|
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
|
90
|
};
|
91
|
Telerik.Windows.Controls.RadWindow.Alert(parameters);
|
92
|
}
|
93
|
|
94
|
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
|
95
|
{
|
96
|
InitializeComponent();
|
97
|
|
98
|
//cursor change
|
99
|
this.Cursor = new Cursor(CursorChange().StreamSource);
|
100
|
|
101
|
var point = GetScreenCenter();
|
102
|
|
103
|
this.Left = point.X;
|
104
|
this.Top = point.Y;
|
105
|
|
106
|
ViewerDataModel.Instance.SystemMain = this;
|
107
|
|
108
|
if (!App.ParameterMode)
|
109
|
{
|
110
|
//App.ViewInfo = new IKCOM.ViewInfo
|
111
|
//{
|
112
|
// DocumentItemID = "11111112",
|
113
|
// //DocumentItemID = "10001",
|
114
|
// bPartner = false,
|
115
|
// CreateFinalPDFPermission = true,
|
116
|
// NewCommentPermission = true,
|
117
|
// ProjectNO = "000000",
|
118
|
// UserID = "H2011357",
|
119
|
// //UserID = "H2009115",
|
120
|
// //Mode = 0 , 1 , 2
|
121
|
//};
|
122
|
//DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내");
|
123
|
|
124
|
//#if DEBUG
|
125
|
// App.ViewInfo = new IKCOM.ViewInfo
|
126
|
// {
|
127
|
// DocumentItemID = "11111112",
|
128
|
// //DocumentItemID = "10001",
|
129
|
// bPartner = false,
|
130
|
// CreateFinalPDFPermission = true,
|
131
|
// NewCommentPermission = true,
|
132
|
// ProjectNO = "000000",
|
133
|
// UserID = "H2011357",
|
134
|
// //UserID = "H2009115",
|
135
|
// //Mode = 0 , 1 , 2
|
136
|
// };
|
137
|
// App.ParameterMode = true;
|
138
|
// this.dzMainMenu.ServiceOn();
|
139
|
// this.dzMainMenu.SetView(App.ViewInfo);
|
140
|
//#else
|
141
|
|
142
|
DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내");
|
143
|
this.dzMainMenu.pageNavigator.Visibility = Visibility.Collapsed;
|
144
|
this.dzMainMenu.historyPane.Visibility = Visibility.Collapsed;
|
145
|
this.dzMainMenu.infoListPane.Visibility = Visibility.Collapsed;
|
146
|
this.dzMainMenu.searchPane.Visibility = Visibility.Collapsed;
|
147
|
this.dzMainMenu.talkPane.Visibility = Visibility.Collapsed;
|
148
|
//#endif
|
149
|
}
|
150
|
else
|
151
|
{
|
152
|
this.dzMainMenu.ServiceOn();
|
153
|
|
154
|
if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission)
|
155
|
{
|
156
|
this.dzTopMenu.radRibbonView.HelpButtonVisibility = Visibility.Collapsed;
|
157
|
var list = this.dzTopMenu.ChildrenOfType<RadRibbonTab>().ToList();
|
158
|
list.ForEach(item => item.Visibility = Visibility.Collapsed);
|
159
|
this.dzTopMenu.ribbontab_ReadOnly.Visibility = Visibility.Visible;
|
160
|
this.dzTopMenu.radRibbonView.SelectedItem = this.dzTopMenu.ribbontab_ReadOnly;
|
161
|
//this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed;
|
162
|
//this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed;
|
163
|
//this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false;
|
164
|
}
|
165
|
|
166
|
try
|
167
|
{
|
168
|
///this.dzMainMenu.HubSet();
|
169
|
this.dzMainMenu.SetView(App.ViewInfo);
|
170
|
}
|
171
|
catch (Exception ex)
|
172
|
{
|
173
|
MessageBox.Show(string.Format("웹 서비스 접속시 에러가 발생했습니다.\n{0}", ex.StackTrace));
|
174
|
|
175
|
System.Environment.Exit(0);
|
176
|
}
|
177
|
}
|
178
|
|
179
|
//App.ViewInfo = new IKCOM.ViewInfo
|
180
|
//{
|
181
|
// DocumentItemID = "11111112",
|
182
|
// //DocumentItemID = "10001",
|
183
|
// bPartner = false,
|
184
|
// CreateFinalPDFPermission = true,
|
185
|
// NewCommentPermission = true,
|
186
|
// ProjectNO = "000000",
|
187
|
// UserID = "H2011357",
|
188
|
// //UserID = "H2009115",
|
189
|
// //Mode = 0 , 1 , 2
|
190
|
//};0
|
191
|
|
192
|
//this.dzMainMenu.ServiceOn();
|
193
|
//this.dzMainMenu.SetView(App.ViewInfo);
|
194
|
}
|
195
|
|
196
|
private Point GetScreenCenter()
|
197
|
{
|
198
|
Point result = new Point();
|
199
|
|
200
|
//first get all the screens
|
201
|
System.Drawing.Rectangle ret;
|
202
|
int ScreenWidth = 0;
|
203
|
|
204
|
var mousePosition = System.Windows.Forms.Cursor.Position;
|
205
|
|
206
|
for (int i = 1; i <= System.Windows.Forms.Screen.AllScreens.Count(); i++)
|
207
|
{
|
208
|
ret = System.Windows.Forms.Screen.AllScreens[i - 1].Bounds;
|
209
|
|
210
|
if (ret.Contains(mousePosition))
|
211
|
{
|
212
|
result.X = ScreenWidth + (ret.Width / 2 - this.Width / 2);
|
213
|
result.Y = (ret.Height / 2 - this.Height / 2);
|
214
|
|
215
|
break;
|
216
|
}
|
217
|
else
|
218
|
{
|
219
|
ScreenWidth += ret.Width;
|
220
|
}
|
221
|
|
222
|
}
|
223
|
|
224
|
|
225
|
return result;
|
226
|
}
|
227
|
|
228
|
protected override void OnStateChanged(EventArgs e)
|
229
|
{
|
230
|
base.OnStateChanged(e);
|
231
|
}
|
232
|
|
233
|
protected override void OnClosing(CancelEventArgs e)
|
234
|
{
|
235
|
base.OnClosing(e);
|
236
|
|
237
|
SaveCheck();
|
238
|
|
239
|
//Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
|
240
|
KeyValuePair<bool, string> updatecheck = UpdateCheck();
|
241
|
if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
|
242
|
{
|
243
|
CallUpdateProcess(updatecheck.Value);
|
244
|
}
|
245
|
}
|
246
|
|
247
|
private void SaveCheck()
|
248
|
{
|
249
|
if (ViewerDataModel.Instance.UndoDataList.Count > 0)
|
250
|
{
|
251
|
DateTime undoTime = ViewerDataModel.Instance.UndoDataList.OrderByDescending(order => order.EventTime).FirstOrDefault().EventTime;
|
252
|
DateTime updatetime = DateTime.Now.AddDays(-1);
|
253
|
if (ViewerDataModel.Instance._markupInfoList.Count > 0)
|
254
|
{
|
255
|
updatetime = ViewerDataModel.Instance._markupInfoList.OrderByDescending(order => order.UpdateTime).FirstOrDefault().UpdateTime;
|
256
|
}
|
257
|
|
258
|
if (undoTime > updatetime)
|
259
|
{
|
260
|
DialogParameters parameters = new DialogParameters()
|
261
|
{
|
262
|
Owner = Application.Current.MainWindow,
|
263
|
Content = new TextBlock()
|
264
|
{
|
265
|
MinWidth = 400,
|
266
|
FontSize = 11,
|
267
|
Text = "Found unsaved comments. Save now?",
|
268
|
TextWrapping = System.Windows.TextWrapping.Wrap
|
269
|
},
|
270
|
Header = "Confirm",
|
271
|
Theme = new VisualStudio2013Theme(),
|
272
|
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
|
273
|
Closed = OnClosingSave,
|
274
|
};
|
275
|
RadWindow.Confirm(parameters);
|
276
|
}
|
277
|
else
|
278
|
{
|
279
|
isSaveCheck = true;
|
280
|
}
|
281
|
}
|
282
|
else
|
283
|
{
|
284
|
isSaveCheck = true;
|
285
|
}
|
286
|
}
|
287
|
private void OnClosingSave(object sender, WindowClosedEventArgs e)
|
288
|
{
|
289
|
if (e.DialogResult == true)
|
290
|
{
|
291
|
dzTopMenu.SaveEventCallback(null, null);
|
292
|
}
|
293
|
isSaveCheck = true;
|
294
|
}
|
295
|
|
296
|
private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
|
297
|
{
|
298
|
Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
|
299
|
{
|
300
|
double bytesIn = double.Parse(e.BytesReceived.ToString());
|
301
|
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
|
302
|
double percentage = bytesIn / totalBytes * 100;
|
303
|
progressControl.splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %";
|
304
|
progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
|
305
|
}));
|
306
|
}
|
307
|
|
308
|
/// <summary>
|
309
|
/// KCOM_API 를 통해 업데이트 URL 을 가져옴.
|
310
|
/// false : 업데이트 불필요.
|
311
|
/// true : 업데이트 필요. url 을 같이 Return.
|
312
|
/// </summary>
|
313
|
/// <returns></returns>
|
314
|
private KeyValuePair<bool, string> UpdateCheck()
|
315
|
{
|
316
|
bool isUpdateCheck = false;
|
317
|
string updateurl = string.Empty;
|
318
|
try
|
319
|
{
|
320
|
bool is64bit = Environment.Is64BitProcess;
|
321
|
string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
322
|
updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
|
323
|
|
324
|
if (Check_Uri.isUri(updateurl))
|
325
|
{
|
326
|
DialogParameters parameters = new DialogParameters()
|
327
|
{
|
328
|
Owner = Application.Current.MainWindow,
|
329
|
Content = new TextBlock()
|
330
|
{
|
331
|
MinWidth = 400,
|
332
|
FontSize = 11,
|
333
|
Text = "Update is available. \n Update now?",
|
334
|
TextWrapping = System.Windows.TextWrapping.Wrap
|
335
|
},
|
336
|
Header = "Confirm",
|
337
|
Theme = new VisualStudio2013Theme(),
|
338
|
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
|
339
|
Closed = delegate (object windowSender, WindowClosedEventArgs e)
|
340
|
{
|
341
|
if (e.DialogResult == true)
|
342
|
{
|
343
|
isUpdateCheck = true;
|
344
|
}
|
345
|
else
|
346
|
{
|
347
|
isUpdateCheck = false;
|
348
|
}
|
349
|
}
|
350
|
};
|
351
|
RadWindow.Confirm(parameters);
|
352
|
|
353
|
}
|
354
|
else
|
355
|
{
|
356
|
isUpdateCheck = false;
|
357
|
}
|
358
|
}
|
359
|
catch (Exception ex)
|
360
|
{
|
361
|
throw ex;
|
362
|
}
|
363
|
return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
|
364
|
}
|
365
|
|
366
|
/// <summary>
|
367
|
/// SmartUpdate 를 호출.
|
368
|
/// </summary>
|
369
|
/// <param name="updateurl">Download 할 설치파일 경로</param>
|
370
|
private void CallUpdateProcess(string updateurl)
|
371
|
{
|
372
|
ProcessStartInfo proInfo = new ProcessStartInfo();
|
373
|
string smartupdaterpath = string.Empty;
|
374
|
smartupdaterpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmartUpdate.exe");
|
375
|
Process.Start(smartupdaterpath, updateurl);
|
376
|
}
|
377
|
private async void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
|
378
|
{
|
379
|
try
|
380
|
{
|
381
|
await Dispatcher.InvokeAsync(() => progressControl.splashText.Text = "Download Completed");
|
382
|
|
383
|
if (progressControl != null)
|
384
|
{
|
385
|
progressControl.Close();
|
386
|
progressControl = null;
|
387
|
}
|
388
|
if (File.Exists(destfilepath))
|
389
|
{
|
390
|
ProcessStartInfo update_msi = new ProcessStartInfo();
|
391
|
update_msi.FileName = destfilepath;
|
392
|
Process.Start(update_msi);
|
393
|
}
|
394
|
this.Close();
|
395
|
}
|
396
|
catch (Exception)
|
397
|
{
|
398
|
throw;
|
399
|
}
|
400
|
|
401
|
}
|
402
|
}
|
403
|
}
|