markus / ConvertService / ServiceBase / Markus.Service.StationController / ViewModel / DataBaseItemsModel.cs @ 902f397c
이력 | 보기 | 이력해설 | 다운로드 (32.1 KB)
1 |
using Markus.Message; |
---|---|
2 |
using Markus.Service.DataBase; |
3 |
using Markus.Service.Extensions; |
4 |
using Markus.Service.StationController.Data; |
5 |
using Markus.Service.StationController.Behaviors; |
6 |
using Markus.Service.StationController.Extensions; |
7 |
using Microsoft.Win32; |
8 |
using System; |
9 |
using System.Collections.Generic; |
10 |
using System.ComponentModel; |
11 |
using System.Linq; |
12 |
using System.Threading.Tasks; |
13 |
using System.Web; |
14 |
using System.Windows; |
15 |
using Telerik.Windows.Controls; |
16 |
using Telerik.Windows.Data; |
17 |
using ConvertItem = Markus.Service.Interface.ConvertItem; |
18 |
using System.Net; |
19 |
using System.Windows.Threading; |
20 |
using System.Diagnostics; |
21 |
using System.Windows.Input; |
22 |
using Markus.Mvvm.ToolKit; |
23 |
using System.Windows.Data; |
24 |
|
25 |
namespace Markus.Service.StationController.ViewModel |
26 |
{ |
27 |
//세미 |
28 |
public class DataBaseItemsModel : Mvvm.ToolKit.ViewModelBase |
29 |
{ |
30 |
#region Constructor |
31 |
|
32 |
/// <summary> |
33 |
/// 실행하면 처음 들어가는 부분 |
34 |
/// </summary> |
35 |
public DataBaseItemsModel() |
36 |
{ |
37 |
DataSaveFileGemBoxCommand = new DelegateCommand(DataExportData); |
38 |
ConvertCommand = new DelegateCommand(DataConvert); |
39 |
DeleteCommand = new DelegateCommand(DataDelete); |
40 |
ValidateCommand = new DelegateCommand(DataValidate); |
41 |
MarkusLinkCommand = new DelegateCommand(MarkusLink); |
42 |
} |
43 |
|
44 |
#endregion |
45 |
|
46 |
#region Properties |
47 |
|
48 |
private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _AliveItems; |
49 |
public System.Collections.ObjectModel.ObservableCollection<ConvertItem> AliveItems |
50 |
{ |
51 |
get => _AliveItems; |
52 |
set |
53 |
{ |
54 |
_AliveItems = value; |
55 |
OnPropertyChanged(() => AliveItems); |
56 |
} |
57 |
} |
58 |
|
59 |
private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _FilterConvertSource; |
60 |
public System.Collections.ObjectModel.ObservableCollection<ConvertItem> FilterConvertSource |
61 |
{ |
62 |
//get => _FilterConvertSource; |
63 |
get |
64 |
{ |
65 |
//if (_FilterConvertSource == null) |
66 |
//{ |
67 |
// _FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
68 |
//} |
69 |
//var view = CollectionViewSource.GetDefaultView(FilterConvertSource); |
70 |
//if (view.CanFilter) |
71 |
//{ |
72 |
// view.Filter = TestFilter; |
73 |
//} |
74 |
return _FilterConvertSource; |
75 |
} |
76 |
set |
77 |
{ |
78 |
_FilterConvertSource = value; |
79 |
OnPropertyChanged(() => FilterConvertSource); |
80 |
} |
81 |
} |
82 |
|
83 |
|
84 |
private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _RealConvertSource; |
85 |
public System.Collections.ObjectModel.ObservableCollection<ConvertItem> RealConvertSource |
86 |
{ |
87 |
get => _RealConvertSource; |
88 |
set |
89 |
{ |
90 |
_RealConvertSource = value; |
91 |
OnPropertyChanged(() => RealConvertSource); |
92 |
} |
93 |
} |
94 |
|
95 |
|
96 |
private System.Windows.Documents.FlowDocument connectionLog; |
97 |
public System.Windows.Documents.FlowDocument ConnectionLog |
98 |
{ |
99 |
get => connectionLog; |
100 |
set |
101 |
{ |
102 |
if (connectionLog != value) |
103 |
{ |
104 |
connectionLog = value; |
105 |
OnPropertyChanged(() => ConnectionLog); |
106 |
} |
107 |
} |
108 |
} |
109 |
|
110 |
|
111 |
private Telerik.Windows.Data.EnumMemberViewModel _SelectedStatus; |
112 |
public Telerik.Windows.Data.EnumMemberViewModel SelectedStatus |
113 |
{ |
114 |
get => _SelectedStatus; |
115 |
set |
116 |
{ |
117 |
_SelectedStatus = value; |
118 |
OnPropertyChanged(() => SelectedStatus); |
119 |
} |
120 |
} |
121 |
|
122 |
|
123 |
private SelectedCountItem _SelectedCount; |
124 |
public SelectedCountItem SelectedCount |
125 |
{ |
126 |
get => _SelectedCount; |
127 |
set |
128 |
{ |
129 |
_SelectedCount = value; |
130 |
OnPropertyChanged(() => SelectedCount); |
131 |
} |
132 |
} |
133 |
|
134 |
List<SelectedCountItem> _SelectedCountList; |
135 |
public List<SelectedCountItem> SelectedCountList |
136 |
{ |
137 |
get |
138 |
{ |
139 |
if (_SelectedCountList == null) |
140 |
{ |
141 |
_SelectedCountList = new List<SelectedCountItem> |
142 |
{ |
143 |
new SelectedCountItem{DisplayMember = "50",ValueMember = 50}, |
144 |
new SelectedCountItem{DisplayMember = "100",ValueMember = 100}, |
145 |
new SelectedCountItem{DisplayMember = "150",ValueMember = 150}, |
146 |
new SelectedCountItem{DisplayMember = "200",ValueMember = 200} |
147 |
}; |
148 |
} |
149 |
|
150 |
return _SelectedCountList; |
151 |
} |
152 |
} |
153 |
|
154 |
private ConvertItem _SelectFilterConvert; |
155 |
public ConvertItem SelectFilterConvert |
156 |
{ |
157 |
get => _SelectFilterConvert; |
158 |
set |
159 |
{ |
160 |
_SelectFilterConvert = value; |
161 |
OnPropertyChanged(() => SelectFilterConvert); |
162 |
} |
163 |
} |
164 |
|
165 |
private ConvertItem _SelectRealConvert; |
166 |
public ConvertItem SelectRealConvert |
167 |
{ |
168 |
get => _SelectRealConvert; |
169 |
set |
170 |
{ |
171 |
_SelectRealConvert = value; |
172 |
OnPropertyChanged(() => SelectRealConvert); |
173 |
} |
174 |
} |
175 |
|
176 |
|
177 |
private StatusTypeList _StatusType; |
178 |
public StatusTypeList StatusType |
179 |
{ |
180 |
get => _StatusType; |
181 |
set |
182 |
{ |
183 |
_StatusType = value; |
184 |
OnPropertyChanged(() => StatusType); |
185 |
} |
186 |
} |
187 |
|
188 |
private bool _IsLoading; |
189 |
public bool IsLoading |
190 |
{ |
191 |
get => _IsLoading; |
192 |
set |
193 |
{ |
194 |
if (_IsLoading != value) |
195 |
{ |
196 |
_IsLoading = value; |
197 |
OnPropertyChanged(() => IsLoading); |
198 |
} |
199 |
} |
200 |
} |
201 |
|
202 |
IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> _StatusCodeList; |
203 |
public IEnumerable<Telerik.Windows.Data.EnumMemberViewModel> StatusCodeList |
204 |
{ |
205 |
get |
206 |
{ |
207 |
if (_StatusCodeList == null) |
208 |
{ |
209 |
_StatusCodeList = Telerik.Windows.Data.EnumDataSource.FromType<StatusCodeType>(); |
210 |
} |
211 |
|
212 |
return _StatusCodeList; |
213 |
} |
214 |
} |
215 |
|
216 |
public bool _ConvertShow; |
217 |
public bool ConvertShow |
218 |
{ |
219 |
get => _ConvertShow; |
220 |
set |
221 |
{ |
222 |
if(_ConvertShow =! value) |
223 |
{ |
224 |
_ConvertShow = false; |
225 |
} |
226 |
_ConvertShow = value; |
227 |
OnPropertyChanged(() => ConvertShow); |
228 |
} |
229 |
} |
230 |
|
231 |
public string _ProjectNumberFilter; |
232 |
public string ProjectNumberFilter |
233 |
{ |
234 |
get { return _ProjectNumberFilter; } |
235 |
set |
236 |
{ |
237 |
if (_ProjectNumberFilter != value) |
238 |
{ |
239 |
_ProjectNumberFilter = value; |
240 |
OnPropertyChanged(() => ProjectNumberFilter); |
241 |
CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
242 |
} |
243 |
} |
244 |
} |
245 |
|
246 |
public string _UniqueKeyFilter; |
247 |
public string UniqueKeyFilter |
248 |
{ |
249 |
get { return _UniqueKeyFilter; } |
250 |
set |
251 |
{ |
252 |
if (_UniqueKeyFilter != value) |
253 |
{ |
254 |
_UniqueKeyFilter = value; |
255 |
OnPropertyChanged(() => UniqueKeyFilter); |
256 |
CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
257 |
} |
258 |
} |
259 |
} |
260 |
|
261 |
public string _ConvertStateFilter; |
262 |
public string ConvertStateFilter |
263 |
{ |
264 |
get { return _ConvertStateFilter; } |
265 |
set |
266 |
{ |
267 |
if (_ConvertStateFilter != value) |
268 |
{ |
269 |
_ConvertStateFilter = value; |
270 |
OnPropertyChanged(() => ConvertStateFilter); |
271 |
CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
272 |
} |
273 |
} |
274 |
} |
275 |
|
276 |
public string _Docuemnt_NOFilter; |
277 |
public string Docuemnt_NOFilter |
278 |
{ |
279 |
get { return _Docuemnt_NOFilter; } |
280 |
set |
281 |
{ |
282 |
if (_Docuemnt_NOFilter != value) |
283 |
{ |
284 |
_Docuemnt_NOFilter = value; |
285 |
OnPropertyChanged(() => Docuemnt_NOFilter); |
286 |
CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
287 |
} |
288 |
} |
289 |
} |
290 |
|
291 |
public string _Docuemnt_NameFilter; |
292 |
public string Docuemnt_NameFilter |
293 |
{ |
294 |
get { return _Docuemnt_NameFilter; } |
295 |
set |
296 |
{ |
297 |
if (_Docuemnt_NameFilter != value) |
298 |
{ |
299 |
_Docuemnt_NameFilter = value; |
300 |
OnPropertyChanged(() => Docuemnt_NameFilter); |
301 |
CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
302 |
} |
303 |
} |
304 |
} |
305 |
|
306 |
public string _ReconverterFilter; |
307 |
public string ReconverterFilter |
308 |
{ |
309 |
get { return _ReconverterFilter; } |
310 |
set |
311 |
{ |
312 |
if (_ReconverterFilter != value) |
313 |
{ |
314 |
_ReconverterFilter = value; |
315 |
OnPropertyChanged(() => ReconverterFilter); |
316 |
CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
317 |
} |
318 |
} |
319 |
} |
320 |
|
321 |
public string _Service_IDFilter; |
322 |
public string Service_IDFilter |
323 |
{ |
324 |
get { return _Service_IDFilter; } |
325 |
set |
326 |
{ |
327 |
if (_Service_IDFilter != value) |
328 |
{ |
329 |
_Service_IDFilter = value; |
330 |
OnPropertyChanged(() => Service_IDFilter); |
331 |
CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
332 |
} |
333 |
} |
334 |
} |
335 |
|
336 |
public string _RevisionFilter; |
337 |
public string RevisionFilter |
338 |
{ |
339 |
get { return _RevisionFilter; } |
340 |
set |
341 |
{ |
342 |
if (_RevisionFilter != value) |
343 |
{ |
344 |
_RevisionFilter = value; |
345 |
OnPropertyChanged(() => RevisionFilter); |
346 |
CollectionViewSource.GetDefaultView(FilterConvertSource).Refresh(); |
347 |
} |
348 |
} |
349 |
} |
350 |
#endregion |
351 |
|
352 |
#region Command |
353 |
|
354 |
public DelegateCommand ConvertCommand { get; private set; } |
355 |
public DelegateCommand DeleteCommand { get; private set; } |
356 |
public DelegateCommand ValidateCommand { get; private set; } |
357 |
public DelegateCommand DataSaveFileGemBoxCommand { get; private set; } |
358 |
public DelegateCommand MarkusLinkCommand { get; private set; } |
359 |
#endregion |
360 |
|
361 |
#region Main Logic |
362 |
|
363 |
/// <summary> |
364 |
/// 각각의 Grid row 객체들 업데이트 |
365 |
/// </summary> |
366 |
|
367 |
private DispatcherTimer dispatcherTimer; |
368 |
public override void Loaded() |
369 |
{ |
370 |
base.Loaded(); |
371 |
|
372 |
if (!App.IsDesignMode) |
373 |
{ |
374 |
dispatcherTimer = new DispatcherTimer(); |
375 |
dispatcherTimer.Tick += new EventHandler(Timer_Tick); |
376 |
dispatcherTimer.Interval = new TimeSpan(0, 0, 1); |
377 |
dispatcherTimer.Start(); |
378 |
} |
379 |
} |
380 |
|
381 |
private async void Timer_Tick(object sender, EventArgs e) |
382 |
{ |
383 |
dispatcherTimer.Stop(); |
384 |
|
385 |
if (IsAcitve) |
386 |
{ |
387 |
await App.Current.Dispatcher.InvokeAsync(() => |
388 |
{ |
389 |
DataSelect(); |
390 |
|
391 |
AliveDataSelect(); |
392 |
}); |
393 |
} |
394 |
|
395 |
await Task.Delay(5000); |
396 |
|
397 |
//System.Threading.Thread.Sleep(new TimeSpan(0,0,0,0,100)); |
398 |
|
399 |
dispatcherTimer.Start(); |
400 |
} |
401 |
|
402 |
public override void Closed() |
403 |
{ |
404 |
if (dispatcherTimer != null) |
405 |
{ |
406 |
dispatcherTimer.Stop(); |
407 |
} |
408 |
|
409 |
base.Closed(); |
410 |
} |
411 |
|
412 |
|
413 |
#endregion |
414 |
|
415 |
#region Function |
416 |
|
417 |
#region Data Select |
418 |
|
419 |
/// <summary> |
420 |
/// 상단 그리드 중앙 그리드 출력 데이터 |
421 |
/// </summary> |
422 |
private void DataSelect() |
423 |
{ |
424 |
|
425 |
if (FilterConvertSource == null) |
426 |
{ |
427 |
FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
428 |
} |
429 |
|
430 |
if (RealConvertSource == null) |
431 |
{ |
432 |
RealConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
433 |
} |
434 |
|
435 |
/// combobox 에서 선택된 items |
436 |
if (SelectedStatus != null) |
437 |
{ |
438 |
DataSelect(new[] { (StatusCodeType)(SelectedStatus.Value) }, FilterConvertSource); |
439 |
} |
440 |
|
441 |
/// 컨버터중인 items |
442 |
RealDataSelect(new[] { StatusCodeType.None, StatusCodeType.Wait, StatusCodeType.PageLoading, StatusCodeType.Saving }, RealConvertSource); |
443 |
|
444 |
} |
445 |
|
446 |
private void RealDataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
447 |
{ |
448 |
try |
449 |
{ |
450 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
451 |
{ |
452 |
var items = database.GetConvertProjects(collection)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
453 |
.Take(SelectedCount.ValueMember).ToList();// |
454 |
|
455 |
items.ForEach(newitem => |
456 |
{ |
457 |
collection.UpdateWhere(changeitem => |
458 |
ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ConvertID == newitem.ConvertID && x.ProjectNumber == newitem.ProjectNumber); |
459 |
}); |
460 |
} |
461 |
} |
462 |
catch (Exception ex) |
463 |
{ |
464 |
MessageBox.Show(ex.ToString()); |
465 |
} |
466 |
} |
467 |
|
468 |
private void DataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
469 |
{ |
470 |
try |
471 |
{ |
472 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
473 |
{ |
474 |
|
475 |
int _status = 0; |
476 |
if (SelectedStatus != null) |
477 |
{ |
478 |
_status = (int)SelectedStatus.Value; |
479 |
} |
480 |
|
481 |
//if (ProjectNumberFilter != null) |
482 |
//{ |
483 |
// from item in FilterConvertSource |
484 |
// where like % item.ProjectNumber |
485 |
//} |
486 |
|
487 |
var items = database.GetConvertProjects(_status)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
488 |
.Take(SelectedCount.ValueMember).ToList(); |
489 |
|
490 |
if (collection.Count() == 0) |
491 |
{ |
492 |
if (statusCodeTypeList.Count() == 1) |
493 |
{ |
494 |
items.ForEach(x => collection.Add(x)); |
495 |
} |
496 |
} |
497 |
else |
498 |
{ |
499 |
|
500 |
////세미 업데이트 |
501 |
items.ForEach(newitem => |
502 |
{ |
503 |
collection.UpdateWhere(changeitem => |
504 |
ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
505 |
}); |
506 |
|
507 |
|
508 |
if (statusCodeTypeList.Count() == 1) |
509 |
{ |
510 |
//삭제 |
511 |
for (int i = collection.Count() - 1; i >= 0; --i) |
512 |
{ |
513 |
var item = collection[i]; |
514 |
|
515 |
if (items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교 |
516 |
{//참=> 0제외한 모든 수 |
517 |
collection.RemoveAt(i); |
518 |
} |
519 |
} |
520 |
} |
521 |
|
522 |
if (statusCodeTypeList.Count() == 1) |
523 |
{ |
524 |
//추가 convert 후 추가됨 |
525 |
foreach (var item in items) |
526 |
{ |
527 |
if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감 |
528 |
{ |
529 |
/*for (int i = 0; i < collection.Count()+1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가*/ |
530 |
for (int i = 0; i < 200; i++) |
531 |
{ |
532 |
if (i < collection.Count() - 1) |
533 |
{ |
534 |
if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
535 |
{ |
536 |
collection.Insert(i, item); |
537 |
break; |
538 |
} |
539 |
} |
540 |
else |
541 |
{ |
542 |
collection.Add(item); |
543 |
break; |
544 |
} |
545 |
} |
546 |
|
547 |
} |
548 |
|
549 |
} |
550 |
} |
551 |
|
552 |
} |
553 |
} |
554 |
|
555 |
} |
556 |
catch (Exception ex) |
557 |
{ |
558 |
MessageBox.Show(ex.ToString()); |
559 |
} |
560 |
} |
561 |
|
562 |
/// <summary> |
563 |
/// 서비스의 실시간 컨버터 Item |
564 |
/// </summary> |
565 |
private async void AliveDataSelect() |
566 |
{ |
567 |
try |
568 |
{ |
569 |
List<ConvertItem> newitems = new List<ConvertItem>(); |
570 |
|
571 |
foreach (var client in App.StationClientList) |
572 |
{ |
573 |
if (await SimplePingAsync(client.Endpoint.Address.ToString())) |
574 |
{ |
575 |
try |
576 |
{ |
577 |
List<ConvertItem> itemsToList = new List<ConvertItem>(); |
578 |
var items = await client.AliveConvertListAsync(); |
579 |
foreach (var item in items) |
580 |
{ |
581 |
ConvertItem itemsToEach = new ConvertItem(); |
582 |
itemsToEach.ServiceID = item.ServiceID; |
583 |
itemsToEach.ConvertID = item.ConvertID; |
584 |
itemsToEach.ProjectNumber = item.ProjectNumber; |
585 |
|
586 |
if (item.ConvertState != null) |
587 |
{ |
588 |
itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState); |
589 |
} |
590 |
|
591 |
itemsToEach.CurrentPageNo = item.CurrentPageNo; |
592 |
itemsToEach.TotalPage = item.TotalPage; |
593 |
itemsToEach.OriginfilePath = item.OriginfilePath; |
594 |
itemsToEach.ConvertPath = item.ConvertPath; |
595 |
itemsToEach.MarkusLink = item.MarkusLink; |
596 |
itemsToEach.UniqueKey = item.UniqueKey; |
597 |
itemsToEach.FileName = item.FileName; |
598 |
itemsToEach.ConvertPath = item.ConvertPath; |
599 |
itemsToEach.CreateTime = item.CreateTime; |
600 |
itemsToEach.Exception = item.Exception; |
601 |
itemsToEach.ProcessorAffinity = item.ProcessorAffinity; |
602 |
itemsToEach.ReConverter = item.ReConverter; |
603 |
itemsToEach.DocumentID = item.DocumentID; |
604 |
itemsToEach.DocumnetName = item.DocumnetName; |
605 |
itemsToEach.GroupNo = item.GroupNo; |
606 |
itemsToEach.Revision = item.Revision; |
607 |
itemsToEach.StartTime = item.StartTime; |
608 |
itemsToEach.EndTime = item.EndTime; |
609 |
|
610 |
|
611 |
itemsToList.Add(itemsToEach); |
612 |
} |
613 |
newitems.AddRange(itemsToList); |
614 |
System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping"); |
615 |
|
616 |
if (items.Count() == 0) |
617 |
{ |
618 |
System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero."); |
619 |
} |
620 |
} |
621 |
catch (Exception ex) |
622 |
{ |
623 |
System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}"); |
624 |
} |
625 |
} |
626 |
else |
627 |
{ |
628 |
System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error"); |
629 |
} |
630 |
} |
631 |
|
632 |
ItemsUpdate(newitems); |
633 |
await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems)); |
634 |
} |
635 |
catch (Exception ex) |
636 |
{ |
637 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
638 |
} |
639 |
} |
640 |
|
641 |
/// <summary> |
642 |
/// AliveDataSelect의 Data Update |
643 |
/// </summary> |
644 |
/// <param name="newitems"></param> |
645 |
private void ItemsUpdate(List<ConvertItem> newitems) |
646 |
{ |
647 |
|
648 |
foreach (var item in newitems) |
649 |
{ |
650 |
item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath); |
651 |
} |
652 |
|
653 |
if (AliveItems == null) |
654 |
{ |
655 |
AliveItems = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
656 |
|
657 |
foreach (var item in newitems) |
658 |
{ |
659 |
AliveItems.Add(item); |
660 |
} |
661 |
} |
662 |
else |
663 |
{ |
664 |
/// 데이터 업데이트 |
665 |
newitems.ForEach(newitem => |
666 |
{ |
667 |
AliveItems.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
668 |
}); |
669 |
|
670 |
// 추가 |
671 |
foreach (var item in newitems) |
672 |
{ |
673 |
if (AliveItems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
674 |
{ |
675 |
AliveItems.Add(item); |
676 |
} |
677 |
} |
678 |
|
679 |
/// 삭제 |
680 |
|
681 |
for (int i = AliveItems.Count() - 1; i > -1; --i) |
682 |
{ |
683 |
var item = AliveItems[i]; |
684 |
|
685 |
if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
686 |
{ |
687 |
try |
688 |
{ |
689 |
AliveItems.RemoveAt(i); |
690 |
} |
691 |
catch (Exception ex) |
692 |
{ |
693 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
694 |
} |
695 |
} |
696 |
} |
697 |
} |
698 |
} |
699 |
|
700 |
|
701 |
public static async Task<bool> SimplePingAsync(string uri) |
702 |
{ |
703 |
bool result = false; |
704 |
|
705 |
try |
706 |
{ |
707 |
using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient()) |
708 |
{ |
709 |
Client.Timeout = new TimeSpan(0, 0, 60); |
710 |
|
711 |
var message = await Client.GetAsync(uri); |
712 |
|
713 |
System.Net.HttpStatusCode StatusCode = message.StatusCode; |
714 |
|
715 |
switch (StatusCode) |
716 |
{ |
717 |
|
718 |
case System.Net.HttpStatusCode.Accepted: |
719 |
case System.Net.HttpStatusCode.OK: |
720 |
result = true; |
721 |
break; |
722 |
} |
723 |
} |
724 |
} |
725 |
catch (Exception ex) |
726 |
{ |
727 |
result = false; |
728 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
729 |
} |
730 |
|
731 |
return result; |
732 |
} |
733 |
|
734 |
#endregion |
735 |
|
736 |
#region Data Convert |
737 |
|
738 |
private void DataConvert(object obj) |
739 |
{ |
740 |
if (SelectFilterConvert == null && SelectRealConvert == null) |
741 |
{ |
742 |
MessageBox.Show("왼쪽 버튼 클릭 후 Converter 해주세요!"); |
743 |
} |
744 |
else |
745 |
{ |
746 |
ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
747 |
var resultRealConvert = 0; |
748 |
var resultFiltertConvert = 0; |
749 |
|
750 |
if (SelectRealConvert != null) |
751 |
{ |
752 |
resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert); |
753 |
} |
754 |
else if (SelectFilterConvert != null) |
755 |
{ |
756 |
resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert); |
757 |
} |
758 |
System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
759 |
|
760 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
761 |
{ |
762 |
var items = database.GetConvertProjects(SelectFilterConvert); |
763 |
|
764 |
foreach (var item in items) |
765 |
{ |
766 |
RealConvertSource.Add(item); |
767 |
} |
768 |
if (RealConvertSource.Count() == 1) |
769 |
{ |
770 |
ConvertShow = true; |
771 |
} |
772 |
} |
773 |
} |
774 |
} |
775 |
|
776 |
#endregion |
777 |
|
778 |
#region Validation |
779 |
|
780 |
private void DataValidate(object obj) |
781 |
{ |
782 |
|
783 |
bool result = false; |
784 |
|
785 |
WebRequest webRequest = WebRequest.Create(SelectFilterConvert.OriginfilePath); |
786 |
webRequest.Timeout = 1200; // miliseconds |
787 |
webRequest.Method = "HEAD"; |
788 |
|
789 |
HttpWebResponse response = null; |
790 |
|
791 |
try |
792 |
{ |
793 |
response = (HttpWebResponse)webRequest.GetResponse(); |
794 |
result = true; |
795 |
} |
796 |
catch (WebException webException) |
797 |
{ |
798 |
MessageBox.Show(SelectFilterConvert.FileName + " doesn't exist: " + webException.Message); |
799 |
result = true; |
800 |
} |
801 |
finally |
802 |
{ |
803 |
if (response != null) |
804 |
{ |
805 |
response.Close(); |
806 |
} |
807 |
} |
808 |
if (result == true) |
809 |
{ |
810 |
MessageBox.Show("File exists"); |
811 |
} |
812 |
} |
813 |
|
814 |
#endregion |
815 |
|
816 |
#region MarkusLink |
817 |
|
818 |
private void MarkusLink(object obj)///여기서 부터 |
819 |
{ |
820 |
if (obj is ConvertItem) |
821 |
{ |
822 |
if (obj != null) |
823 |
{ |
824 |
var convertitem = obj as ConvertItem; |
825 |
|
826 |
SelectFilterConvert = convertitem; |
827 |
|
828 |
SelectRealConvert = convertitem; |
829 |
|
830 |
ProcessStartInfo startInfo = null; |
831 |
|
832 |
startInfo = new ProcessStartInfo("iexplore.exe", convertitem.MarkusLink); |
833 |
|
834 |
Process.Start(startInfo); |
835 |
} |
836 |
} |
837 |
} |
838 |
|
839 |
#endregion |
840 |
|
841 |
#region Data Delete |
842 |
|
843 |
private void DataDelete(object obj) |
844 |
{ |
845 |
RadWindow.Alert("do you want to delete it??", this.OnClosed); |
846 |
} |
847 |
|
848 |
private void OnClosed(object sender, WindowClosedEventArgs e) |
849 |
{ |
850 |
var result = e.DialogResult; |
851 |
if (result == true) |
852 |
{ |
853 |
ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
854 |
var resultRealConvert = _DataConvert.RemoveItem(SelectRealConvert.ConvertID); |
855 |
var resultFiltertConvert = _DataConvert.RemoveItem(SelectFilterConvert.ConvertID); |
856 |
System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
857 |
} |
858 |
} |
859 |
|
860 |
|
861 |
#endregion |
862 |
|
863 |
#region Data Export |
864 |
|
865 |
|
866 |
/// <summary> |
867 |
/// 필터된 상단 그리드 엑셀로 출력 |
868 |
/// </summary> |
869 |
|
870 |
public void DataExportData(object obj) |
871 |
{ |
872 |
SaveFileDialog saveFileDialog = new SaveFileDialog(); |
873 |
|
874 |
saveFileDialog.FileName = "Document"; // Default file name |
875 |
saveFileDialog.DefaultExt = ".txt"; // Default file extension |
876 |
saveFileDialog.Filter = "Csv documents (.Csv)|*.csv|Excel(2017~2019)Worksheets|*.xlsx"; // Filter files by extension |
877 |
|
878 |
|
879 |
if (saveFileDialog.ShowDialog() == true) |
880 |
{ |
881 |
|
882 |
|
883 |
if (!string.IsNullOrWhiteSpace(saveFileDialog.FileName)) |
884 |
{ |
885 |
|
886 |
var extension = new System.IO.FileInfo(saveFileDialog.FileName).Extension; |
887 |
|
888 |
if (extension == ".xlsx" || extension == ".csv") |
889 |
{ |
890 |
|
891 |
var headers = new List<HeaderMember> |
892 |
{ |
893 |
new HeaderMember{HeaderName = "ServiceID", Property = "ServiceID" }, |
894 |
new HeaderMember{HeaderName = "ConvertID", Property = "ConvertID" }, |
895 |
new HeaderMember{HeaderName = "ProjectNumber", Property = "ProjectNumber" }, |
896 |
new HeaderMember{HeaderName = "ConvertState", Property = "ConvertState" }, |
897 |
new HeaderMember{HeaderName = "CurrentPageNo", Property = "CurrentPageNo" }, |
898 |
new HeaderMember{HeaderName = "TotalPage", Property = "TotalPage" }, |
899 |
new HeaderMember{HeaderName = "OriginfilePath", Property = "OriginfilePath" }, |
900 |
new HeaderMember{HeaderName = "ConvertPath", Property = "ConvertPath" }, |
901 |
new HeaderMember{HeaderName = "CreateTime", Property = "CreateTime" }, |
902 |
new HeaderMember{HeaderName = "Exception", Property = "Exception" }, |
903 |
new HeaderMember{HeaderName = "ProcessorAffinity", Property = "ProcessorAffinity" }, |
904 |
new HeaderMember{HeaderName = "ReConverter", Property = "ReConverter" }, |
905 |
new HeaderMember{HeaderName = "UniqueKey", Property = "UniqueKey" } |
906 |
}; |
907 |
|
908 |
|
909 |
DataExport dataExport = new DataExport(); |
910 |
dataExport.DataExportExcel(saveFileDialog.FileName, "Hello world", FilterConvertSource, headers); |
911 |
//_dataExport.DataExportExcel(saveFileDialog.FileName, saveFileDialog.FileName.ToString(), Projectsource, headers); |
912 |
//GemBoxFileSave(obj); |
913 |
} |
914 |
} |
915 |
} |
916 |
} |
917 |
|
918 |
#endregion |
919 |
|
920 |
#region TestFilter |
921 |
|
922 |
|
923 |
/// <summary> |
924 |
/// Grid Filter |
925 |
/// </summary> |
926 |
|
927 |
private bool TestFilter(object item) |
928 |
{ |
929 |
var Item = item as ConvertItem; |
930 |
if (ProjectNumberFilter == null) return true; |
931 |
if (ProjectNumberFilter == Item.ProjectNumber) return true; |
932 |
return false; |
933 |
} |
934 |
|
935 |
#endregion |
936 |
|
937 |
#endregion |
938 |
} |
939 |
} |
940 |
|