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