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