개정판 2decfbdf
DataBaseItemsModel 수정
Change-Id: I96830cad0b3990bb84346f438ba04e20d55ec26c
ConvertService/ServiceBase/Markus.Service.StationController/ViewModel/DataBaseItemsModel.cs | ||
---|---|---|
2 | 2 |
using Markus.Message; |
3 | 3 |
using Markus.Service.DataBase; |
4 | 4 |
using Markus.Service.Extensions; |
5 |
//using Markus.Service.Interface; |
|
6 |
using Markus.Service.StationController; |
|
5 | 7 |
using Markus.Service.StationController.Behaviors; |
6 | 8 |
using Markus.Service.StationController.Extensions; |
7 | 9 |
using Microsoft.Win32; |
8 | 10 |
using System; |
9 | 11 |
using System.Collections.Generic; |
12 |
using System.Collections.ObjectModel; |
|
10 | 13 |
using System.ComponentModel; |
14 |
using System.Diagnostics; |
|
11 | 15 |
using System.Linq; |
16 |
using System.Threading.Tasks; |
|
17 |
using System.Web; |
|
12 | 18 |
using System.Windows; |
13 | 19 |
using Telerik.Windows.Controls; |
14 | 20 |
using Telerik.Windows.Data; |
15 | 21 |
using ConvertItem = Markus.Service.Interface.ConvertItem; |
22 |
//using AliveConvertItem = Markus.Service.WcfClient.StationServiceTask.ConvertItem; |
|
23 |
using Markus.Service.WcfClient.StationServiceTask; |
|
24 |
using System.Text; |
|
25 |
using Markus.Service.Helper; |
|
16 | 26 |
|
17 | 27 |
namespace Markus.Service.StationController.ViewModel |
18 | 28 |
{ |
19 | 29 |
//세미 |
20 |
public class DataBaseItemsModel : Mvvm.ToolKit.ViewModelBase |
|
30 |
public class DataBaseItemsModel : Mvvm.ToolKit.ViewModelBase, INotifyPropertyChanged
|
|
21 | 31 |
{ |
32 |
//alive |
|
33 |
private BackgroundWorker AlivebackgroundWorker; |
|
34 |
|
|
35 |
private bool isLoading; |
|
36 |
private System.Windows.Documents.FlowDocument connectionLog; |
|
37 |
|
|
38 |
private System.Collections.ObjectModel.ObservableCollection<ConvertItem> _AliveItems; |
|
39 |
|
|
40 |
public System.Collections.ObjectModel.ObservableCollection<ConvertItem> AliveItems |
|
41 |
{ |
|
42 |
get => _AliveItems; set |
|
43 |
{ |
|
44 |
_AliveItems = value; |
|
45 |
OnPropertyChanged(() => AliveItems); |
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
public bool AliveIsLoading |
|
50 |
{ |
|
51 |
get => isLoading; set |
|
52 |
{ |
|
53 |
if (isLoading != value) |
|
54 |
{ |
|
55 |
isLoading = value; |
|
56 |
OnPropertyChanged(() => AliveIsLoading); |
|
57 |
} |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
public System.Windows.Documents.FlowDocument ConnectionLog |
|
63 |
{ |
|
64 |
get => connectionLog; |
|
65 |
set |
|
66 |
{ |
|
67 |
if (connectionLog != value) |
|
68 |
{ |
|
69 |
connectionLog = value; |
|
70 |
OnPropertyChanged(() => ConnectionLog); |
|
71 |
} |
|
72 |
} |
|
73 |
} |
|
74 |
|
|
75 |
//public AliveViewModel() |
|
76 |
//{ |
|
77 |
//} |
|
78 |
|
|
79 |
//// 진행률에 변화가 있을때 이벤트가 발생 |
|
80 |
//private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
|
81 |
//{ |
|
82 |
//} |
|
83 |
|
|
84 |
//// 일이 모두 마쳤을때 수행되어야할 코드 |
|
85 |
//private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
|
86 |
//{ |
|
87 |
//} |
|
88 |
|
|
89 |
// BackgroundWorker에서 수행할 일을 정의. |
|
90 |
private void AlivebackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
|
91 |
{ |
|
92 |
} |
|
93 |
private void AlivebackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
|
94 |
{ |
|
95 |
} |
|
96 |
private async void AlivebackgroundWorker_DoWork(object sender, DoWorkEventArgs e) |
|
97 |
{ |
|
98 |
while (IsAcitve) |
|
99 |
{ |
|
100 |
//System.Threading.Thread.Sleep(new TimeSpan(0, 0, 3)); |
|
101 |
|
|
102 |
if (!IsLoading) |
|
103 |
{ |
|
104 |
IsLoading = true; |
|
105 |
|
|
106 |
try |
|
107 |
{ |
|
108 |
|
|
109 |
List<ConvertItem> newitems = new List<ConvertItem>(); |
|
110 |
|
|
111 |
foreach (var client in App.StationClientList) |
|
112 |
{ |
|
113 |
if (await SimplePingAsync(client.Endpoint.Address.ToString())) |
|
114 |
{ |
|
115 |
try |
|
116 |
{ |
|
117 |
List<ConvertItem> itemsToList = new List<ConvertItem>(); |
|
118 |
var items = await client.AliveConvertListAsync(); |
|
119 |
//int i = 0; |
|
120 |
foreach (var item in items) |
|
121 |
{ |
|
122 |
ConvertItem itemsToEach = new ConvertItem(); |
|
123 |
itemsToEach.ServiceID = item.ServiceID; |
|
124 |
itemsToEach.ConvertID = item.ConvertID; |
|
125 |
itemsToEach.ProjectNumber = item.ProjectNumber; |
|
126 |
//itemsToEach.ConvertState = (StatusCodeType.)item.ConvertState;// (StatusCodeType) item.ConvertState; |
|
127 |
itemsToEach.ConvertState = (StatusCodeType)Enum.Parse(typeof(StatusCodeType), item.ConvertState); |
|
128 |
itemsToEach.CurrentPageNo = item.CurrentPageNo; |
|
129 |
itemsToEach.TotalPage = item.TotalPage; |
|
130 |
itemsToEach.OriginfilePath = item.OriginfilePath; |
|
131 |
itemsToEach.ConvertPath = item.ConvertPath; |
|
132 |
|
|
133 |
itemsToList.Add(itemsToEach); |
|
134 |
//i++; |
|
135 |
} |
|
136 |
newitems.AddRange(itemsToList); |
|
137 |
//System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping"); |
|
138 |
|
|
139 |
if (items.Count() == 0) |
|
140 |
{ |
|
141 |
//System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero."); |
|
142 |
} |
|
143 |
} |
|
144 |
catch (Exception ex) |
|
145 |
{ |
|
146 |
//System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}"); |
|
147 |
} |
|
148 |
} |
|
149 |
else |
|
150 |
{ |
|
151 |
//System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error"); |
|
152 |
} |
|
153 |
} |
|
154 |
|
|
155 |
// ItemsUpdate(newitems); |
|
156 |
await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems)); |
|
157 |
} |
|
158 |
catch (Exception ex) |
|
159 |
{ |
|
160 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
|
161 |
} |
|
162 |
|
|
163 |
IsLoading = false; |
|
164 |
} |
|
165 |
|
|
166 |
} |
|
167 |
} |
|
168 |
|
|
169 |
|
|
170 |
private async void AliveDataSelect() |
|
171 |
{ |
|
172 |
try |
|
173 |
{ |
|
174 |
List<ConvertItem> newitems = new List<ConvertItem>(); |
|
175 |
|
|
176 |
foreach (var client in App.StationClientList) |
|
177 |
{ |
|
178 |
if (await SimplePingAsync(client.Endpoint.Address.ToString())) |
|
179 |
{ |
|
180 |
try |
|
181 |
{ |
|
182 |
List<ConvertItem> itemsToList = new List<ConvertItem>(); |
|
183 |
var items = await client.AliveConvertListAsync(); |
|
184 |
//int i = 0; |
|
185 |
foreach (var item in items) |
|
186 |
{ |
|
187 |
ConvertItem itemsToEach = new ConvertItem(); |
|
188 |
itemsToEach.ServiceID = item.ServiceID; |
|
189 |
itemsToEach.ConvertID = item.ConvertID; |
|
190 |
itemsToEach.ProjectNumber = item.ProjectNumber; |
|
191 |
//itemsToEach.ConvertState = (StatusCodeType.)item.ConvertState;// (StatusCodeType) item.ConvertState; |
|
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 |
//i++; |
|
209 |
} |
|
210 |
newitems.AddRange(itemsToList); |
|
211 |
System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping"); |
|
212 |
|
|
213 |
if (items.Count() == 0) |
|
214 |
{ |
|
215 |
System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero."); |
|
216 |
} |
|
217 |
} |
|
218 |
catch (Exception ex) |
|
219 |
{ |
|
220 |
System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}"); |
|
221 |
} |
|
222 |
} |
|
223 |
else |
|
224 |
{ |
|
225 |
System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error"); |
|
226 |
} |
|
227 |
} |
|
228 |
|
|
229 |
ItemsUpdate(newitems); |
|
230 |
await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems)); |
|
231 |
} |
|
232 |
catch (Exception ex) |
|
233 |
{ |
|
234 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
|
235 |
} |
|
236 |
} |
|
237 |
|
|
238 |
|
|
239 |
private void ItemsUpdate(List<ConvertItem> newitems) |
|
240 |
{ |
|
241 |
|
|
242 |
foreach (var item in newitems) |
|
243 |
{ |
|
244 |
item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath); |
|
245 |
} |
|
246 |
|
|
247 |
if (AliveItems == null) |
|
248 |
{ |
|
249 |
AliveItems = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
|
250 |
|
|
251 |
foreach (var item in newitems) |
|
252 |
{ |
|
253 |
AliveItems.Add(item); |
|
254 |
} |
|
255 |
} |
|
256 |
else |
|
257 |
{ |
|
258 |
/// 데이터 업데이트 |
|
259 |
newitems.ForEach(newitem => |
|
260 |
{ |
|
261 |
AliveItems.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
|
262 |
}); |
|
263 |
|
|
264 |
// 추가 |
|
265 |
foreach (var item in newitems) |
|
266 |
{ |
|
267 |
if (AliveItems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
|
268 |
{ |
|
269 |
AliveItems.Add(item); |
|
270 |
} |
|
271 |
} |
|
272 |
|
|
273 |
/// 삭제 |
|
274 |
|
|
275 |
for (int i = AliveItems.Count() - 1; i > -1; --i) |
|
276 |
{ |
|
277 |
var item = AliveItems[i]; |
|
278 |
|
|
279 |
if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
|
280 |
{ |
|
281 |
try |
|
282 |
{ |
|
283 |
AliveItems.RemoveAt(i); |
|
284 |
} |
|
285 |
catch (Exception ex) |
|
286 |
{ |
|
287 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
|
288 |
} |
|
289 |
} |
|
290 |
} |
|
291 |
} |
|
292 |
} |
|
293 |
|
|
294 |
private void LogWrite(string log, bool IsError) |
|
295 |
{ |
|
296 |
if (IsError) |
|
297 |
{ |
|
298 |
System.Diagnostics.Trace.Fail(log); |
|
299 |
} |
|
300 |
else |
|
301 |
{ |
|
302 |
System.Diagnostics.Trace.TraceInformation(log); |
|
303 |
} |
|
304 |
} |
|
305 |
|
|
306 |
|
|
307 |
public static async Task<bool> SimplePingAsync(string uri) |
|
308 |
{ |
|
309 |
bool result = false; |
|
310 |
|
|
311 |
try |
|
312 |
{ |
|
313 |
using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient()) |
|
314 |
{ |
|
315 |
Client.Timeout = new TimeSpan(0, 0, 60); |
|
316 |
|
|
317 |
var message = await Client.GetAsync(uri); |
|
318 |
|
|
319 |
System.Net.HttpStatusCode StatusCode = message.StatusCode; |
|
320 |
|
|
321 |
switch (StatusCode) |
|
322 |
{ |
|
323 |
|
|
324 |
case System.Net.HttpStatusCode.Accepted: |
|
325 |
case System.Net.HttpStatusCode.OK: |
|
326 |
result = true; |
|
327 |
break; |
|
328 |
} |
|
329 |
} |
|
330 |
} |
|
331 |
catch (Exception ex) |
|
332 |
{ |
|
333 |
result = false; |
|
334 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
|
335 |
} |
|
336 |
|
|
337 |
return result; |
|
338 |
} |
|
339 |
|
|
340 |
//public override void Loaded() |
|
341 |
//{ |
|
342 |
// base.Loaded(); |
|
343 |
|
|
344 |
// if (!App.IsDesignMode) |
|
345 |
// { |
|
346 |
// backgroundWorker = new BackgroundWorker(); |
|
347 |
// backgroundWorker.DoWork += backgroundWorker_DoWork; |
|
348 |
// backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted; |
|
349 |
// backgroundWorker.WorkerReportsProgress = false; |
|
350 |
// backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
|
351 |
|
|
352 |
// backgroundWorker.RunWorkerAsync(); |
|
353 |
// } |
|
354 |
//} |
|
355 |
|
|
356 |
//public override void AliveClosed() |
|
357 |
//{ |
|
358 |
// if (backgroundWorker != null) |
|
359 |
// { |
|
360 |
// backgroundWorker.DoWork -= backgroundWorker_DoWork; |
|
361 |
// backgroundWorker.RunWorkerCompleted -= backgroundWorker_RunWorkerCompleted; |
|
362 |
// backgroundWorker.WorkerReportsProgress = false; |
|
363 |
// backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
|
364 |
|
|
365 |
// backgroundWorker.Dispose(); |
|
366 |
// } |
|
367 |
|
|
368 |
// base.Closed(); |
|
369 |
//} |
|
370 |
//alive |
|
371 |
|
|
372 |
public event PropertyChangedEventHandler PropertyChanged; |
|
373 |
|
|
374 |
private void NotifyPropertyChanged(String info) |
|
375 |
{ |
|
376 |
if (PropertyChanged != null) |
|
377 |
{ |
|
378 |
PropertyChanged(this, new PropertyChangedEventArgs(info)); |
|
379 |
} |
|
380 |
} |
|
381 |
|
|
22 | 382 |
BackgroundWorker backgroundWorker; |
23 | 383 |
|
24 | 384 |
Random rnd = new Random(); |
... | ... | |
38 | 398 |
set |
39 | 399 |
{ |
40 | 400 |
_SelectedStatus = value; |
41 |
OnPropertyChanged(() => SelectedStatus);
|
|
401 |
NotifyPropertyChanged("SelectedStatus");
|
|
42 | 402 |
} |
43 | 403 |
} |
44 | 404 |
|
... | ... | |
51 | 411 |
set |
52 | 412 |
{ |
53 | 413 |
_SelectedCount = value; |
54 |
OnPropertyChanged(() => SelectedCount);
|
|
414 |
NotifyPropertyChanged("SelectedCount");
|
|
55 | 415 |
} |
56 | 416 |
} |
57 | 417 |
|
58 | 418 |
|
59 | 419 |
public DelegateCommand ConvertCommand { get; private set; } |
60 | 420 |
public DelegateCommand DeleteCommand { get; private set; } |
421 |
public DelegateCommand ValidateCommand { get; private set; } |
|
61 | 422 |
|
62 | 423 |
|
63 | 424 |
private void DataConvert(object obj) |
64 | 425 |
{ |
65 |
ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
|
426 |
if (SelectFilterConvert == null && SelectRealConvert == null) |
|
427 |
{ |
|
428 |
MessageBox.Show("왼쪽 버튼 클릭 후 Converter 해주세요!"); |
|
429 |
} |
|
430 |
else |
|
431 |
{ |
|
432 |
ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
|
433 |
var resultRealConvert = 0; |
|
434 |
var resultFiltertConvert = 0; |
|
435 |
|
|
436 |
if (SelectRealConvert != null) |
|
437 |
{ |
|
438 |
/*resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert.ConvertID, SelectRealConvert.ReConverter);*/ |
|
439 |
resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert); |
|
440 |
} |
|
441 |
else if (SelectFilterConvert != null) |
|
442 |
{ |
|
443 |
//resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert.ConvertID, SelectFilterConvert.ReConverter); |
|
444 |
resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert); |
|
445 |
} |
|
446 |
System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
|
66 | 447 |
|
67 |
var resultRealConvert = _DataConvert.SetCleanUpItem(SelectRealConvert.ConvertID, SelectRealConvert.ReConverter); |
|
68 |
var resultFiltertConvert = _DataConvert.SetCleanUpItem(SelectFilterConvert.ConvertID, SelectFilterConvert.ReConverter); |
|
69 |
System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
|
448 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
|
449 |
{ |
|
450 |
var items = database.GetConvertProjects(SelectFilterConvert); |
|
451 |
|
|
452 |
foreach (var item in items) |
|
453 |
{ |
|
454 |
RealConvertSource.Add(item); |
|
455 |
} |
|
456 |
|
|
457 |
} |
|
458 |
} |
|
70 | 459 |
} |
71 | 460 |
|
72 | 461 |
private void DataDelete(object obj) |
73 | 462 |
{ |
74 |
ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
|
463 |
RadWindow.Alert("정말로 삭제 하시겠습니까?", this.OnClosed); |
|
464 |
} |
|
75 | 465 |
|
76 |
var resultRealConvert = _DataConvert.RemoveItem(SelectRealConvert.ConvertID); |
|
77 |
var resultFiltertConvert = _DataConvert.RemoveItem(SelectFilterConvert.ConvertID); |
|
78 |
System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
|
466 |
private void OnClosed(object sender, WindowClosedEventArgs e) |
|
467 |
{ |
|
468 |
var result = e.DialogResult; |
|
469 |
if (result == true) |
|
470 |
{ |
|
471 |
ConvertDatabase _DataConvert = new ConvertDatabase(App.MarkusDataBaseConnecitonString); |
|
472 |
var resultRealConvert = _DataConvert.RemoveItem(SelectRealConvert.ConvertID); |
|
473 |
var resultFiltertConvert = _DataConvert.RemoveItem(SelectFilterConvert.ConvertID); |
|
474 |
System.Diagnostics.Debug.WriteLine(resultRealConvert + " " + resultFiltertConvert); |
|
475 |
} |
|
476 |
} |
|
477 |
private void DataValidate(object obj) |
|
478 |
{ |
|
479 |
MessageBox.Show("파일 체크 할껀데 정상인지 아닌지 "); |
|
79 | 480 |
|
80 | 481 |
} |
81 | 482 |
|
... | ... | |
86 | 487 |
set |
87 | 488 |
{ |
88 | 489 |
_FilterConvertSource = value; |
89 |
OnPropertyChanged(() => FilterConvertSource);
|
|
490 |
NotifyPropertyChanged("FilterConvertSource");
|
|
90 | 491 |
} |
91 | 492 |
} |
92 | 493 |
|
... | ... | |
98 | 499 |
set |
99 | 500 |
{ |
100 | 501 |
_RealConvertSource = value; |
101 |
OnPropertyChanged(() => RealConvertSource);
|
|
502 |
NotifyPropertyChanged("RealConvertSource");
|
|
102 | 503 |
} |
103 | 504 |
} |
104 | 505 |
|
... | ... | |
110 | 511 |
set |
111 | 512 |
{ |
112 | 513 |
_SelectFilterConvert = value; |
113 |
OnPropertyChanged(() => SelectFilterConvert);
|
|
514 |
NotifyPropertyChanged("SelectFilterConvert");
|
|
114 | 515 |
} |
115 | 516 |
} |
116 | 517 |
public ConvertItem SelectRealConvert |
... | ... | |
119 | 520 |
set |
120 | 521 |
{ |
121 | 522 |
_SelectRealConvert = value; |
122 |
OnPropertyChanged(() => SelectRealConvert);
|
|
523 |
NotifyPropertyChanged("SelectRealConvert");
|
|
123 | 524 |
} |
124 | 525 |
} |
125 | 526 |
|
... | ... | |
129 | 530 |
set |
130 | 531 |
{ |
131 | 532 |
_StatusType = value; |
132 |
OnPropertyChanged(() => StatusType);
|
|
533 |
NotifyPropertyChanged("StatusType");
|
|
133 | 534 |
} |
134 | 535 |
} |
135 | 536 |
|
... | ... | |
141 | 542 |
if (_IsLoading != value) |
142 | 543 |
{ |
143 | 544 |
_IsLoading = value; |
144 |
OnPropertyChanged(() => IsLoading);
|
|
545 |
NotifyPropertyChanged("IsLoading");
|
|
145 | 546 |
} |
146 | 547 |
} |
147 | 548 |
} |
... | ... | |
173 | 574 |
DataSaveFileGemBoxCommand = new DelegateCommand(DataExport); |
174 | 575 |
ConvertCommand = new DelegateCommand(DataConvert); |
175 | 576 |
DeleteCommand = new DelegateCommand(DataDelete); |
577 |
ValidateCommand = new DelegateCommand(DataValidate); |
|
176 | 578 |
//Loaded(); |
177 | 579 |
} |
178 | 580 |
|
... | ... | |
202 | 604 |
return _StatusCodeList; |
203 | 605 |
} |
204 | 606 |
} |
205 |
|
|
206 | 607 |
// BackgroundWorker에서 수행할 일을 정의. |
207 | 608 |
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) |
208 | 609 |
{ |
610 |
|
|
209 | 611 |
while (IsAcitve) |
210 | 612 |
{ |
613 |
|
|
211 | 614 |
if (FilterConvertSource == null) |
212 | 615 |
{ |
213 | 616 |
FilterConvertSource = new System.Collections.ObjectModel.ObservableCollection<ConvertItem>(); |
... | ... | |
225 | 628 |
} |
226 | 629 |
|
227 | 630 |
/// 컨버터중인 items |
228 |
DataSelect(new[] { StatusCodeType.None, StatusCodeType.Wait, StatusCodeType.PageLoading, StatusCodeType.Saving }, RealConvertSource); |
|
631 |
RealDataSelect(new[] { StatusCodeType.None, StatusCodeType.Wait, StatusCodeType.PageLoading, StatusCodeType.Saving }, RealConvertSource);
|
|
229 | 632 |
} |
230 | 633 |
} |
231 | 634 |
|
635 |
System.Windows.Threading.DispatcherTimer DispatcherTimer = new System.Windows.Threading.DispatcherTimer(); |
|
636 |
|
|
637 |
|
|
638 |
private void RealDataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
|
639 |
{ |
|
640 |
|
|
641 |
try |
|
642 |
{ |
|
643 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
|
644 |
{ |
|
645 |
|
|
646 |
|
|
647 |
|
|
648 |
//var items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
|
649 |
// .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList(); |
|
650 |
|
|
651 |
//var items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => ((int)y).ToString() == x.ConvertState) > 0)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
|
652 |
// .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList(); |
|
653 |
//int _status = 0; |
|
654 |
//if (SelectedStatus != null) |
|
655 |
//{ |
|
656 |
// _status = (int)SelectedStatus.Value; |
|
657 |
//} |
|
658 |
|
|
659 |
var items = database.GetConvertProjects(collection)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
|
660 |
.Take(SelectedCount.ValueMember).ToList();// |
|
661 |
|
|
662 |
//if (statusCodeTypeList.Count() == 4) |
|
663 |
//{ |
|
664 |
// items.Clear(); |
|
665 |
|
|
666 |
// //items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0)//연습용 |
|
667 |
// // .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList();//실행시킨 날 보다 createtime이 최신 일때 |
|
668 |
|
|
669 |
// //items = database.GetConvertProjects(x => DateTime.Compare(x.CREATE_DATETIME, now) > 0 && statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0) |
|
670 |
// // .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList();//실행시킨 날 보다 createtime이 최신 일때 |
|
671 |
|
|
672 |
// items = database.GetConvertProjects(x => DateTime.Compare(x.CreateTime, now) > 0 , _status)//statusCodeTypeList.Count(y => ((int)y).ToString() == x.ConvertState) > 0 |
|
673 |
// .Take(SelectedCount.ValueMember).ToList(); //아래그리드는 양이 적어서 원래 대로 해도 됨 |
|
674 |
//} |
|
675 |
//if (collection.Count() == 0) |
|
676 |
//{ |
|
677 |
// if (statusCodeTypeList.Count() == 1) |
|
678 |
// { |
|
679 |
// items.ForEach(x => collection.Add(x)); |
|
680 |
// } |
|
681 |
//} |
|
682 |
|
|
683 |
//else |
|
684 |
//{ |
|
685 |
////세미 업데이트 |
|
686 |
items.ForEach(newitem => |
|
687 |
{ |
|
688 |
collection.UpdateWhere(changeitem => |
|
689 |
ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ConvertID == newitem.ConvertID && x.ProjectNumber == newitem.ProjectNumber); |
|
690 |
}); |
|
691 |
|
|
692 |
|
|
693 |
//if (statusCodeTypeList.Count() == 1) |
|
694 |
//{ |
|
695 |
// //추가 convert 후 추가됨 |
|
696 |
// foreach (var item in items) |
|
697 |
// { |
|
698 |
// if (collection.Count(x => x.DocumentID == item.DocumentID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감 |
|
699 |
// { |
|
700 |
// for (int i = 0; i < collection.Count() - 1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가 |
|
701 |
// { |
|
702 |
// if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
|
703 |
// { |
|
704 |
// collection.Insert(i, item); |
|
705 |
// } |
|
706 |
// } |
|
707 |
// } |
|
708 |
|
|
709 |
// } |
|
710 |
//} |
|
711 |
|
|
712 |
//if (statusCodeTypeList.Count() == 1) |
|
713 |
//{ |
|
714 |
// //추가 convert 후 추가됨 |
|
715 |
// foreach (var item in items) |
|
716 |
// { |
|
717 |
// if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감 |
|
718 |
// { |
|
719 |
// for (int i = 0; i < collection.Count() - 1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가 |
|
720 |
// { |
|
721 |
// if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
|
722 |
// { |
|
723 |
// collection.Insert(i, item); |
|
724 |
// } |
|
725 |
// } |
|
726 |
// } |
|
727 |
|
|
728 |
// } |
|
729 |
//} |
|
730 |
|
|
731 |
//} |
|
732 |
} |
|
733 |
|
|
734 |
} |
|
735 |
catch (Exception ex) |
|
736 |
{ |
|
737 |
MessageBox.Show(ex.ToString()); |
|
738 |
} |
|
739 |
|
|
740 |
|
|
741 |
} |
|
742 |
|
|
232 | 743 |
//<>쓸때는 IEnumerable |
744 |
|
|
233 | 745 |
private void DataSelect(IEnumerable<StatusCodeType> statusCodeTypeList, System.Collections.ObjectModel.ObservableCollection<ConvertItem> collection) |
234 | 746 |
{ |
235 |
|
|
747 |
|
|
236 | 748 |
try |
237 | 749 |
{ |
238 | 750 |
using (Markus.Service.DataBase.ConvertDatabase database = new Markus.Service.DataBase.ConvertDatabase(App.MarkusDataBaseConnecitonString)) |
239 | 751 |
{ |
240 |
var items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0) |
|
241 |
.OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList(); |
|
242 | 752 |
|
753 |
|
|
754 |
|
|
755 |
//var items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
|
756 |
// .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList(); |
|
757 |
|
|
758 |
//var items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => ((int)y).ToString() == x.ConvertState) > 0)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
|
759 |
// .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList(); |
|
760 |
int _status = 0; |
|
761 |
if (SelectedStatus != null) |
|
762 |
{ |
|
763 |
_status = (int)SelectedStatus.Value; |
|
764 |
} |
|
765 |
|
|
766 |
var items = database.GetConvertProjects(_status)//x:database객체 y:statusCodeTypeList의값 Count()안에 predicator 조건 만족하면 count개수안에 넣음 |
|
767 |
.Take(SelectedCount.ValueMember).ToList();// |
|
768 |
|
|
769 |
//if (statusCodeTypeList.Count() == 4) |
|
770 |
//{ |
|
771 |
// items.Clear(); |
|
772 |
|
|
773 |
// //items = database.GetConvertProjects(x => statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0)//연습용 |
|
774 |
// // .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList();//실행시킨 날 보다 createtime이 최신 일때 |
|
775 |
|
|
776 |
// //items = database.GetConvertProjects(x => DateTime.Compare(x.CREATE_DATETIME, now) > 0 && statusCodeTypeList.Count(y => (int)y == x.STATUS) > 0) |
|
777 |
// // .OrderByDescending(x => x.CreateTime).Take(SelectedCount.ValueMember).ToList();//실행시킨 날 보다 createtime이 최신 일때 |
|
778 |
|
|
779 |
// items = database.GetConvertProjects(x => DateTime.Compare(x.CreateTime, now) > 0 , _status)//statusCodeTypeList.Count(y => ((int)y).ToString() == x.ConvertState) > 0 |
|
780 |
// .Take(SelectedCount.ValueMember).ToList(); //아래그리드는 양이 적어서 원래 대로 해도 됨 |
|
781 |
//} |
|
243 | 782 |
if (collection.Count() == 0) |
244 | 783 |
{ |
245 |
items.ForEach(x => collection.Add(x)); |
|
784 |
if (statusCodeTypeList.Count() == 1) |
|
785 |
{ |
|
786 |
items.ForEach(x => collection.Add(x)); |
|
787 |
} |
|
246 | 788 |
} |
789 |
|
|
247 | 790 |
else |
248 | 791 |
{ |
249 |
// 데이터 업데이트 |
|
250 |
items.ForEach(newitem =>//디비 포문 |
|
792 |
////세미 업데이트 |
|
793 |
//items.ForEach(newitem => |
|
794 |
//{ |
|
795 |
// collection.UpdateWhere(changeitem => |
|
796 |
// ConvertItemEx.ChangeValues(changeitem, newitem), x => x.DocumentID == newitem.DocumentID && x.ProjectNumber == newitem.ProjectNumber); |
|
797 |
//}); |
|
798 |
|
|
799 |
////세미 업데이트 |
|
800 |
items.ForEach(newitem => |
|
251 | 801 |
{ |
252 | 802 |
collection.UpdateWhere(changeitem => |
253 |
{ |
|
254 |
ConvertItemEx.ChangeValues(changeitem, newitem); |
|
255 |
System.Threading.Thread.Sleep(new TimeSpan(0, 0, 0, 0, 10)); |
|
256 |
|
|
257 |
}, x => x.ConvertID == newitem.ConvertID);//UpdateWhere의 where절 |
|
803 |
ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
|
258 | 804 |
}); |
259 | 805 |
|
260 |
foreach (var item in items) |
|
806 |
//if (statusCodeTypeList.Count() == 1) |
|
807 |
//{ |
|
808 |
// //삭제 |
|
809 |
// for (int i = collection.Count() - 1; i >= 0; --i) |
|
810 |
// { |
|
811 |
// var item = collection[i]; |
|
812 |
|
|
813 |
// if (items.Count(x => x.DocumentID == item.DocumentID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교 |
|
814 |
// {//참=> 0제외한 모든 수 |
|
815 |
// collection.RemoveAt(i); |
|
816 |
// } |
|
817 |
// } |
|
818 |
//} |
|
819 |
|
|
820 |
//if (statusCodeTypeList.Count() == 1) |
|
821 |
//{ |
|
822 |
// //추가 convert 후 추가됨 |
|
823 |
// foreach (var item in items) |
|
824 |
// { |
|
825 |
// if (collection.Count(x => x.DocumentID == item.DocumentID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감 |
|
826 |
// { |
|
827 |
// for (int i = 0; i < collection.Count() - 1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가 |
|
828 |
// { |
|
829 |
// if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
|
830 |
// { |
|
831 |
// collection.Insert(i, item); |
|
832 |
// } |
|
833 |
// } |
|
834 |
// } |
|
835 |
|
|
836 |
// } |
|
837 |
//} |
|
838 |
|
|
839 |
if (statusCodeTypeList.Count() == 1) |
|
261 | 840 |
{ |
262 |
// System.Threading.Thread.Sleep(1);
|
|
263 |
if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)
|
|
841 |
//삭제
|
|
842 |
for (int i = collection.Count() - 1; i >= 0; --i)
|
|
264 | 843 |
{ |
265 |
collection.Add(item); |
|
266 |
} |
|
844 |
var item = collection[i]; |
|
267 | 845 |
|
846 |
if (items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교 |
|
847 |
{//참=> 0제외한 모든 수 |
|
848 |
collection.RemoveAt(i); |
|
849 |
} |
|
850 |
} |
|
268 | 851 |
} |
269 | 852 |
|
270 |
//삭제 |
|
271 |
for (int i = collection.Count() - 1; i > -1; --i) |
|
853 |
if (statusCodeTypeList.Count() == 1) |
|
272 | 854 |
{ |
273 |
var item = collection[i]; |
|
855 |
//추가 convert 후 추가됨 |
|
856 |
foreach (var item in items) |
|
857 |
{ |
|
858 |
if (collection.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//그리드와 디비 변동 없으면 안들어감 |
|
859 |
{ |
|
860 |
/*for (int i = 0; i < collection.Count()+1; i++)//위 그리드에서 카운드 개수 변함 없고 컨버터 끝난 후 추가할때 createtime 비교 하며 order by 순으로 추가*/ |
|
861 |
for (int i = 0; i < 200; i++) |
|
862 |
{ |
|
863 |
if (i < collection.Count() - 1) |
|
864 |
{ |
|
865 |
if (DateTime.Compare(collection[i].CreateTime, item.CreateTime) < 0) |
|
866 |
{ |
|
867 |
collection.Insert(i, item); |
|
868 |
break; |
|
869 |
} |
|
870 |
} |
|
871 |
else |
|
872 |
{ |
|
873 |
collection.Add(item); |
|
874 |
break; |
|
875 |
} |
|
876 |
} |
|
877 |
|
|
878 |
} |
|
274 | 879 |
|
275 |
if (items.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0)//디비에서 가져온 값과 마지막값부터 차례대로 비교 |
|
276 |
{//참=> 0제외한 모든 수 |
|
277 |
collection.RemoveAt(i); |
|
278 | 880 |
} |
279 |
// System.Threading.Thread.Sleep(new TimeSpan(0, 0, 0, 0, 1)); |
|
280 | 881 |
} |
882 |
|
|
281 | 883 |
} |
282 | 884 |
} |
885 |
|
|
283 | 886 |
} |
284 | 887 |
catch (Exception ex) |
285 | 888 |
{ |
286 | 889 |
MessageBox.Show(ex.ToString()); |
890 |
//System.Diagnostics.Debug.WriteLine(ex.ToString()); |
|
287 | 891 |
} |
288 | 892 |
|
289 | 893 |
|
290 | 894 |
} |
291 | 895 |
|
896 |
|
|
292 | 897 |
public override void Loaded() |
293 | 898 |
{ |
294 | 899 |
base.Loaded(); |
... | ... | |
302 | 907 |
backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
303 | 908 |
|
304 | 909 |
backgroundWorker.RunWorkerAsync(); |
910 |
|
|
911 |
AlivebackgroundWorker = new BackgroundWorker(); |
|
912 |
AlivebackgroundWorker.DoWork += AlivebackgroundWorker_DoWork; |
|
913 |
AlivebackgroundWorker.RunWorkerCompleted += AlivebackgroundWorker_RunWorkerCompleted; |
|
914 |
AlivebackgroundWorker.WorkerReportsProgress = false; |
|
915 |
AlivebackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(AlivebackgroundWorker_ProgressChanged); |
|
916 |
|
|
917 |
AlivebackgroundWorker.RunWorkerAsync(); |
|
305 | 918 |
} |
306 | 919 |
} |
307 | 920 |
|
308 |
|
|
309 | 921 |
public override void Closed() |
310 | 922 |
{ |
311 | 923 |
|
... | ... | |
316 | 928 |
backgroundWorker.WorkerReportsProgress = false; |
317 | 929 |
backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
318 | 930 |
|
319 |
} |
|
931 |
AlivebackgroundWorker.DoWork -= AlivebackgroundWorker_DoWork; |
|
932 |
AlivebackgroundWorker.RunWorkerCompleted -= AlivebackgroundWorker_RunWorkerCompleted; |
|
933 |
AlivebackgroundWorker.WorkerReportsProgress = false; |
|
934 |
AlivebackgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(AlivebackgroundWorker_ProgressChanged); |
|
935 |
|
|
936 |
AlivebackgroundWorker.Dispose(); |
|
320 | 937 |
|
938 |
} |
|
321 | 939 |
base.Closed(); |
322 | 940 |
} |
323 | 941 |
|
... | ... | |
492 | 1110 |
|
493 | 1111 |
} |
494 | 1112 |
|
495 |
public class SelectedCountItem |
|
1113 |
|
|
1114 |
public class SelectedCountItem : INotifyPropertyChanged |
|
496 | 1115 |
{ |
497 |
public string DisplayMember { get; set; } |
|
498 |
public int ValueMember { get; set; } |
|
1116 |
public event PropertyChangedEventHandler PropertyChanged; |
|
1117 |
|
|
1118 |
private void NotifyPropertyChanged(String info) |
|
1119 |
{ |
|
1120 |
if (PropertyChanged != null) |
|
1121 |
{ |
|
1122 |
PropertyChanged(this, new PropertyChangedEventArgs(info)); |
|
1123 |
} |
|
1124 |
} |
|
1125 |
|
|
1126 |
//public string DisplayMember { get; set; } |
|
1127 |
public string _DisplayMember; |
|
1128 |
|
|
1129 |
public string DisplayMember |
|
1130 |
{ |
|
1131 |
get => _DisplayMember; |
|
1132 |
set |
|
1133 |
{ |
|
1134 |
_DisplayMember = value; |
|
1135 |
NotifyPropertyChanged("DisplayMember"); |
|
1136 |
} |
|
1137 |
} |
|
1138 |
//public int ValueMember { get; set; } |
|
1139 |
public int _ValueMember; |
|
1140 |
public int ValueMember |
|
1141 |
{ |
|
1142 |
get => _ValueMember; |
|
1143 |
set |
|
1144 |
{ |
|
1145 |
_ValueMember = value; |
|
1146 |
NotifyPropertyChanged("ValueMember"); |
|
1147 |
} |
|
1148 |
} |
|
499 | 1149 |
} |
1150 |
|
|
500 | 1151 |
} |
1152 |
|
|
1153 |
//public class AliveViewModel : Markus.Mvvm.ToolKit.ViewModelBase |
|
1154 |
//{ |
|
1155 |
// BackgroundWorker backgroundWorker; |
|
1156 |
|
|
1157 |
// private System.Collections.ObjectModel.ObservableCollection<Markus.Service.WcfClient.StationServiceTask.ConvertItem> aliveItems; |
|
1158 |
// private bool isLoading; |
|
1159 |
// private System.Windows.Documents.FlowDocument connectionLog; |
|
1160 |
|
|
1161 |
// public System.Collections.ObjectModel.ObservableCollection<Markus.Service.WcfClient.StationServiceTask.ConvertItem> AliveItems |
|
1162 |
// { |
|
1163 |
// get => aliveItems; set |
|
1164 |
// { |
|
1165 |
// aliveItems = value; |
|
1166 |
// OnPropertyChanged(() => AliveItems); |
|
1167 |
// } |
|
1168 |
// } |
|
1169 |
|
|
1170 |
// public bool IsLoading |
|
1171 |
// { |
|
1172 |
// get => isLoading; set |
|
1173 |
// { |
|
1174 |
// if (isLoading != value) |
|
1175 |
// { |
|
1176 |
// isLoading = value; |
|
1177 |
// OnPropertyChanged(() => IsLoading); |
|
1178 |
// } |
|
1179 |
// } |
|
1180 |
// } |
|
1181 |
|
|
1182 |
|
|
1183 |
// public System.Windows.Documents.FlowDocument ConnectionLog |
|
1184 |
// { |
|
1185 |
// get => connectionLog; |
|
1186 |
// set |
|
1187 |
// { |
|
1188 |
// if (connectionLog != value) |
|
1189 |
// { |
|
1190 |
// connectionLog = value; |
|
1191 |
// OnPropertyChanged(() => ConnectionLog); |
|
1192 |
// } |
|
1193 |
// } |
|
1194 |
// } |
|
1195 |
|
|
1196 |
// public AliveViewModel() |
|
1197 |
// { |
|
1198 |
// } |
|
1199 |
|
|
1200 |
// // 진행률에 변화가 있을때 이벤트가 발생 |
|
1201 |
// private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) |
|
1202 |
// { |
|
1203 |
// } |
|
1204 |
|
|
1205 |
// // 일이 모두 마쳤을때 수행되어야할 코드 |
|
1206 |
// private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) |
|
1207 |
// { |
|
1208 |
// } |
|
1209 |
|
|
1210 |
// // BackgroundWorker에서 수행할 일을 정의. |
|
1211 |
// private async void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) |
|
1212 |
// { |
|
1213 |
// while (IsAcitve) |
|
1214 |
// { |
|
1215 |
// System.Threading.Thread.Sleep(new TimeSpan(0, 0, 3)); |
|
1216 |
|
|
1217 |
// if (!IsLoading) |
|
1218 |
// { |
|
1219 |
// IsLoading = true; |
|
1220 |
|
|
1221 |
// try |
|
1222 |
// { |
|
1223 |
|
|
1224 |
// List<Markus.Service.WcfClient.StationServiceTask.ConvertItem> newitems = new List<Markus.Service.WcfClient.StationServiceTask.ConvertItem>(); |
|
1225 |
|
|
1226 |
// foreach (var client in App.StationClientList) |
|
1227 |
// { |
|
1228 |
// if (await SimplePingAsync(client.Endpoint.Address.ToString())) |
|
1229 |
// { |
|
1230 |
// try |
|
1231 |
// { |
|
1232 |
// Markus.Service.WcfClient.StationServiceTask.ConvertItem[] items = await client.AliveConvertListAsync(); |
|
1233 |
// newitems.AddRange(items); |
|
1234 |
// //System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} ping"); |
|
1235 |
|
|
1236 |
// if (items.Count() == 0) |
|
1237 |
// { |
|
1238 |
// //System.Diagnostics.Trace.WriteLine($"{client.Endpoint.Address} Alive Items is zero."); |
|
1239 |
// } |
|
1240 |
// } |
|
1241 |
// catch (Exception ex) |
|
1242 |
// { |
|
1243 |
// //System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} {ex.Message}"); |
|
1244 |
// } |
|
1245 |
// } |
|
1246 |
// else |
|
1247 |
// { |
|
1248 |
// //System.Diagnostics.Trace.Fail($"{client.Endpoint.Address} ping Error"); |
|
1249 |
// } |
|
1250 |
// } |
|
1251 |
|
|
1252 |
// await System.Windows.Application.Current.Dispatcher.InvokeAsync(() => ItemsUpdate(newitems)); |
|
1253 |
// } |
|
1254 |
// catch (Exception ex) |
|
1255 |
// { |
|
1256 |
// System.Diagnostics.Debug.WriteLine(ex.ToString()); |
|
1257 |
// } |
|
1258 |
|
|
1259 |
// IsLoading = false; |
|
1260 |
// } |
|
1261 |
|
|
1262 |
// } |
|
1263 |
// } |
|
1264 |
|
|
1265 |
|
|
1266 |
|
|
1267 |
// private void ItemsUpdate(List<Markus.Service.WcfClient.StationServiceTask.ConvertItem> newitems) |
|
1268 |
// { |
|
1269 |
|
|
1270 |
// foreach (var item in newitems) |
|
1271 |
// { |
|
1272 |
// item.OriginfilePath = HttpUtility.UrlDecode(item.OriginfilePath); |
|
1273 |
// } |
|
1274 |
|
|
1275 |
// if (AliveItems == null) |
|
1276 |
// { |
|
1277 |
// AliveItems = new System.Collections.ObjectModel.ObservableCollection<Markus.Service.WcfClient.StationServiceTask.ConvertItem>(); |
|
1278 |
|
|
1279 |
// foreach (var item in newitems) |
|
1280 |
// { |
|
1281 |
// AliveItems.Add(item); |
|
1282 |
// } |
|
1283 |
// } |
|
1284 |
// else |
|
1285 |
// { |
|
1286 |
// /// 데이터 업데이트 |
|
1287 |
// newitems.ForEach(newitem => |
|
1288 |
// { |
|
1289 |
// AliveItems.UpdateWhere(changeitem => ConvertItemEx.ChangeValues(changeitem, newitem), x => x.ProjectNumber == newitem.ProjectNumber && x.ConvertID == newitem.ConvertID); |
|
1290 |
// }); |
|
1291 |
|
|
1292 |
// // 추가 |
|
1293 |
// foreach (var item in newitems) |
|
1294 |
// { |
|
1295 |
// if (AliveItems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
|
1296 |
// { |
|
1297 |
// AliveItems.Add(item); |
|
1298 |
// } |
|
1299 |
// } |
|
1300 |
|
|
1301 |
// /// 삭제 |
|
1302 |
|
|
1303 |
// for (int i = AliveItems.Count() - 1; i > -1; --i) |
|
1304 |
// { |
|
1305 |
// var item = AliveItems[i]; |
|
1306 |
|
|
1307 |
// if (newitems.Count(x => x.ConvertID == item.ConvertID && x.ProjectNumber == item.ProjectNumber) == 0) |
|
1308 |
// { |
|
1309 |
// try |
|
1310 |
// { |
|
1311 |
// AliveItems.RemoveAt(i); |
|
1312 |
// } |
|
1313 |
// catch (Exception ex) |
|
1314 |
// { |
|
1315 |
// System.Diagnostics.Debug.WriteLine(ex.ToString()); |
|
1316 |
// } |
|
1317 |
// } |
|
1318 |
// } |
|
1319 |
// } |
|
1320 |
// } |
|
1321 |
|
|
1322 |
// private void LogWrite(string log, bool IsError) |
|
1323 |
// { |
|
1324 |
// if (IsError) |
|
1325 |
// { |
|
1326 |
// //System.Diagnostics.Trace.Fail(log); |
|
1327 |
// } |
|
1328 |
// else |
|
1329 |
// { |
|
1330 |
// //System.Diagnostics.Trace.TraceInformation(log); |
|
1331 |
// } |
|
1332 |
// } |
|
1333 |
|
|
1334 |
|
|
1335 |
// public static async Task<bool> SimplePingAsync(string uri) |
|
1336 |
// { |
|
1337 |
// bool result = false; |
|
1338 |
|
|
1339 |
// try |
|
1340 |
// { |
|
1341 |
// using (System.Net.Http.HttpClient Client = new System.Net.Http.HttpClient()) |
|
1342 |
// { |
|
1343 |
// Client.Timeout = new TimeSpan(0, 0, 60); |
|
1344 |
|
|
1345 |
// var message = await Client.GetAsync(uri); |
|
1346 |
|
|
1347 |
// System.Net.HttpStatusCode StatusCode = message.StatusCode; |
|
1348 |
|
|
1349 |
// switch (StatusCode) |
|
1350 |
// { |
|
1351 |
|
|
1352 |
// case System.Net.HttpStatusCode.Accepted: |
|
1353 |
// case System.Net.HttpStatusCode.OK: |
|
1354 |
// result = true; |
|
1355 |
// break; |
|
1356 |
// } |
|
1357 |
// } |
|
1358 |
// } |
|
1359 |
// catch (Exception ex) |
|
1360 |
// { |
|
1361 |
// result = false; |
|
1362 |
// System.Diagnostics.Debug.WriteLine(ex.ToString()); |
|
1363 |
// } |
|
1364 |
|
|
1365 |
// return result; |
|
1366 |
// } |
|
1367 |
|
|
1368 |
// public override void Loaded() |
|
1369 |
// { |
|
1370 |
// base.Loaded(); |
|
1371 |
|
|
1372 |
// if (!App.IsDesignMode) |
|
1373 |
// { |
|
1374 |
// backgroundWorker = new BackgroundWorker(); |
|
1375 |
// backgroundWorker.DoWork += backgroundWorker_DoWork; |
|
1376 |
// backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted; |
|
1377 |
// backgroundWorker.WorkerReportsProgress = false; |
|
1378 |
// backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
|
1379 |
|
|
1380 |
// backgroundWorker.RunWorkerAsync(); |
|
1381 |
// } |
|
1382 |
// } |
|
1383 |
|
|
1384 |
// public override void Closed() |
|
1385 |
// { |
|
1386 |
// if (backgroundWorker != null) |
|
1387 |
// { |
|
1388 |
// backgroundWorker.DoWork -= backgroundWorker_DoWork; |
|
1389 |
// backgroundWorker.RunWorkerCompleted -= backgroundWorker_RunWorkerCompleted; |
|
1390 |
// backgroundWorker.WorkerReportsProgress = false; |
|
1391 |
// backgroundWorker.ProgressChanged -= new ProgressChangedEventHandler(backgroundWorker_ProgressChanged); |
|
1392 |
|
|
1393 |
// backgroundWorker.Dispose(); |
|
1394 |
// } |
|
1395 |
|
|
1396 |
// base.Closed(); |
|
1397 |
// } |
|
1398 |
//} |
내보내기 Unified diff