markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ e6281033
이력 | 보기 | 이력해설 | 다운로드 (30.8 KB)
1 |
using Markus.EntityModel; |
---|---|
2 |
using Markus.Message; |
3 |
using Markus.Service.Extensions; |
4 |
using System; |
5 |
using System.Collections.Generic; |
6 |
using System.IO; |
7 |
using System.Linq; |
8 |
using static Markus.Service.DataBase.ConvertDatabase; |
9 |
using System.Windows; |
10 |
using System.Linq.Expressions; |
11 |
using Markus.Service.Interface; |
12 |
|
13 |
namespace Markus.Service.DataBase |
14 |
{ |
15 |
public class ConvertDatabase : IDisposable |
16 |
{ |
17 |
#region Constructor |
18 |
/// <summary> |
19 |
///해당 프로젝트의 데이터베이스 연결 |
20 |
/// </summary> |
21 |
|
22 |
Markus.EntityModel.MarkusModel entities; |
23 |
|
24 |
public ConvertDatabase(string ConnectionString) |
25 |
{ |
26 |
try |
27 |
{ |
28 |
entities = new Markus.EntityModel.MarkusModel(ConnectionString); |
29 |
} |
30 |
catch (Exception ex) |
31 |
{ |
32 |
System.Diagnostics.Debug.WriteLine(ex.ToString()); |
33 |
throw ex; |
34 |
} |
35 |
} |
36 |
|
37 |
public void Dispose() |
38 |
{ |
39 |
entities.Dispose(); |
40 |
} |
41 |
|
42 |
#endregion |
43 |
|
44 |
#region DataBaseItemsModel Function |
45 |
|
46 |
#region Get WaitConvertItems |
47 |
|
48 |
/// <summary> |
49 |
/// service에서 대기중이거나 오류인 아이템을 가져가서 컨버터 프로세스를 호출한다. |
50 |
/// 컨버터 상태가 에러이거나 2보다 작은 경우 |
51 |
/// UniqueKey는 각 데이터베이스의 문서 정보에서 유일한 키이며 컨버터저장에서 같은 폴더로의 저장을 방지 한다. |
52 |
/// |
53 |
/// </summary> |
54 |
/// <param name="aliveItems"></param> |
55 |
/// <param name="TakeCount"></param> |
56 |
/// <returns></returns> |
57 |
public IEnumerable<CONVERTER_DOC> GetWaitConvertItems(List<string> projectList, int TakeCount) |
58 |
{ |
59 |
var convertWaitingItems = entities.CONVERTER_DOC.OrderBy(x => x.CREATE_DATETIME).Where( |
60 |
x => |
61 |
//projectList.Contains(x.PROJECT_NO) && x.RECONVERTER < 2 && |
62 |
x.RECONVERTER < 2 && |
63 |
(x.STATUS == (int)StatusCodeType.None || x.STATUS == (int)StatusCodeType.FileError || x.STATUS == (int)StatusCodeType.Error)) |
64 |
.GroupBy(x => x.DOCUMENT_ID).Select(x => x.FirstOrDefault()) |
65 |
.Take(TakeCount); |
66 |
|
67 |
return convertWaitingItems; |
68 |
} |
69 |
|
70 |
#endregion |
71 |
|
72 |
#region Get FilterConvertItems |
73 |
|
74 |
/// <summary> |
75 |
/// 상단 그리드 선택된 Status에 따라 DB에서 값 가져온다. |
76 |
/// </summary> |
77 |
public IEnumerable<Interface.ConvertItem> GetConvertProjects(int status) |
78 |
{ |
79 |
List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>(); |
80 |
var query = from items in entities.CONVERTER_DOC |
81 |
join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems |
82 |
from subpet in GroupItems.DefaultIfEmpty() |
83 |
where items.STATUS == status |
84 |
orderby items.CREATE_DATETIME descending |
85 |
select new |
86 |
{ |
87 |
ID = items.ID, |
88 |
DOCUMENT_URL = items.DOCUMENT_URL, |
89 |
RECONVERTER = items.RECONVERTER, |
90 |
SERVICE_ID = items.SERVICE_ID, |
91 |
STATUS = items.STATUS, |
92 |
CREATE_DATETIME = items.CREATE_DATETIME, |
93 |
TOTAL_PAGE = items.TOTAL_PAGE, |
94 |
CURRENT_PAGE = items.CURRENT_PAGE, |
95 |
EXCEPTION = items.EXCEPTION, |
96 |
PROJECT_NO = items.PROJECT_NO, |
97 |
DOCUMENT_ID = items.DOCUMENT_ID, |
98 |
REVISION = subpet.REVISION, |
99 |
DOCUMENT_NO = subpet.DOCUMENT_NO, |
100 |
DOCUMENT_NAME = subpet.DOCUMENT_NAME, |
101 |
GROUP_NO = subpet.GROUP_NO |
102 |
//REVISION = documents.REVISION, |
103 |
//DOCUMENT_NO = documents.DOCUMENT_NO, |
104 |
//DOCUMENT_NAME = documents.DOCUMENT_NAME, |
105 |
//GROUP_NO = documents.GROUP_NO |
106 |
}; |
107 |
|
108 |
if (query.Count() > 0)//세미 |
109 |
{ |
110 |
foreach (var item in query) |
111 |
{ |
112 |
Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL) |
113 |
{ |
114 |
|
115 |
ReConverter = item.RECONVERTER, |
116 |
ServiceID = item.SERVICE_ID, |
117 |
ConvertState = (StatusCodeType)item.STATUS, |
118 |
CreateTime = item.CREATE_DATETIME, |
119 |
TotalPage = item.TOTAL_PAGE, |
120 |
CurrentPageNo = item.CURRENT_PAGE, |
121 |
Exception = item.EXCEPTION, |
122 |
|
123 |
Revision = item.REVISION, |
124 |
DocumnetNo = item.DOCUMENT_NO, |
125 |
DocumnetName = item.DOCUMENT_NAME, |
126 |
GroupNo = item.GROUP_NO, |
127 |
DocumentID = item.DOCUMENT_ID |
128 |
}; |
129 |
convertItems.Add(convertitem); |
130 |
} |
131 |
} |
132 |
return convertItems; |
133 |
|
134 |
} |
135 |
|
136 |
#endregion |
137 |
|
138 |
#region Update RealDataSelect |
139 |
|
140 |
/// <summary> |
141 |
/// 상단 그리드에서 선택된 RealDataSelect |
142 |
/// 용도: 중앙그리드 Items Update |
143 |
/// </summary> |
144 |
public IEnumerable<Interface.ConvertItem> GetConvertProjects(System.Collections.ObjectModel.ObservableCollection<Interface.ConvertItem> selectedConvert) |
145 |
{ |
146 |
List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>(); |
147 |
|
148 |
List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>(); |
149 |
|
150 |
foreach (var selectedConvertItem in selectedConvert) |
151 |
{ |
152 |
var query = from items in entities.CONVERTER_DOC //세미 |
153 |
join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems |
154 |
from subpet in GroupItems.DefaultIfEmpty() |
155 |
where items.PROJECT_NO == selectedConvertItem.ProjectNumber && items.ID == selectedConvertItem.ConvertID |
156 |
select new |
157 |
{ |
158 |
ID = items.ID, |
159 |
DOCUMENT_URL = items.DOCUMENT_URL, |
160 |
RECONVERTER = items.RECONVERTER, |
161 |
SERVICE_ID = items.SERVICE_ID, |
162 |
STATUS = items.STATUS, |
163 |
CREATE_DATETIME = items.CREATE_DATETIME, |
164 |
TOTAL_PAGE = items.TOTAL_PAGE, |
165 |
CURRENT_PAGE = items.CURRENT_PAGE, |
166 |
EXCEPTION = items.EXCEPTION, |
167 |
PROJECT_NO = items.PROJECT_NO, |
168 |
DOCUMENT_ID = items.DOCUMENT_ID, |
169 |
REVISION = subpet.REVISION, |
170 |
DOCUMENT_NO = subpet.DOCUMENT_NO, |
171 |
DOCUMENT_NAME = subpet.DOCUMENT_NAME, |
172 |
GROUP_NO = subpet.GROUP_NO |
173 |
}; |
174 |
|
175 |
|
176 |
if (query.Count() > 0)//세미 |
177 |
{ |
178 |
foreach (var item in query) |
179 |
{ |
180 |
Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL) |
181 |
{ |
182 |
|
183 |
ReConverter = item.RECONVERTER, |
184 |
ServiceID = item.SERVICE_ID, |
185 |
ConvertState = (StatusCodeType)item.STATUS, |
186 |
CreateTime = item.CREATE_DATETIME, |
187 |
TotalPage = item.TOTAL_PAGE, |
188 |
CurrentPageNo = item.CURRENT_PAGE, |
189 |
Exception = item.EXCEPTION, |
190 |
ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID), |
191 |
|
192 |
Revision = item.REVISION, |
193 |
DocumnetNo = item.DOCUMENT_NO, |
194 |
DocumnetName = item.DOCUMENT_NAME, |
195 |
GroupNo = item.GROUP_NO |
196 |
}; |
197 |
|
198 |
StatusKeep.Add(convertitem); |
199 |
|
200 |
} |
201 |
} |
202 |
} |
203 |
return StatusKeep; |
204 |
} |
205 |
|
206 |
#endregion |
207 |
|
208 |
#region Data Convert |
209 |
|
210 |
/// <summary> |
211 |
/// 상단 그리드에서 선택된 Convert 버튼 |
212 |
/// 용도: 중앙 그리드로 Convert된 row 값 저장 하기 위해서 입니다. |
213 |
/// </summary> |
214 |
public IEnumerable<Interface.ConvertItem> GetConvertProjects(Markus.Service.Interface.ConvertItem selectedConvert) |
215 |
{ |
216 |
List<Interface.ConvertItem> StatusKeep = new List<Interface.ConvertItem>(); |
217 |
|
218 |
|
219 |
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); |
220 |
|
221 |
stopwatch.Start(); |
222 |
|
223 |
|
224 |
List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>();//디비 다 조인 후 조건 비교 후 그리드 출력 |
225 |
var query = from items in entities.CONVERTER_DOC //세미 |
226 |
join documents in entities.DOCUMENT_ITEM on items.DOCUMENT_ID equals documents.DOCUMENT_ID into GroupItems |
227 |
from subpet in GroupItems.DefaultIfEmpty() |
228 |
where items.PROJECT_NO == selectedConvert.ProjectNumber && items.DOCUMENT_ID == selectedConvert.DocumentID |
229 |
orderby items.CREATE_DATETIME descending |
230 |
select new |
231 |
{ |
232 |
ID = items.ID, |
233 |
DOCUMENT_URL = items.DOCUMENT_URL, |
234 |
RECONVERTER = items.RECONVERTER, |
235 |
SERVICE_ID = items.SERVICE_ID, |
236 |
STATUS = items.STATUS, |
237 |
CREATE_DATETIME = items.CREATE_DATETIME, |
238 |
TOTAL_PAGE = items.TOTAL_PAGE, |
239 |
CURRENT_PAGE = items.CURRENT_PAGE, |
240 |
EXCEPTION = items.EXCEPTION, |
241 |
PROJECT_NO = items.PROJECT_NO, |
242 |
DOCUMENT_ID = items.DOCUMENT_ID, |
243 |
REVISION = subpet.REVISION, |
244 |
DOCUMENT_NO = subpet.DOCUMENT_NO, |
245 |
DOCUMENT_NAME = subpet.DOCUMENT_NAME, |
246 |
GROUP_NO = subpet.GROUP_NO |
247 |
}; |
248 |
|
249 |
if (query.Count() > 0)//세미 |
250 |
{ |
251 |
foreach (var item in query) |
252 |
{ |
253 |
Interface.ConvertItem convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL) |
254 |
{ |
255 |
|
256 |
ReConverter = item.RECONVERTER, |
257 |
ServiceID = item.SERVICE_ID, |
258 |
ConvertState = (StatusCodeType)item.STATUS, |
259 |
CreateTime = item.CREATE_DATETIME, |
260 |
TotalPage = item.TOTAL_PAGE, |
261 |
CurrentPageNo = item.CURRENT_PAGE, |
262 |
Exception = item.EXCEPTION, |
263 |
ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID), |
264 |
Revision = item.REVISION, |
265 |
DocumnetNo = item.DOCUMENT_NO, |
266 |
DocumnetName = item.DOCUMENT_NAME, |
267 |
GroupNo = item.GROUP_NO |
268 |
}; |
269 |
StatusKeep.Add(convertitem); |
270 |
} |
271 |
} |
272 |
System.Diagnostics.Debug.WriteLine(new TimeSpan(stopwatch.ElapsedTicks).ToString()); |
273 |
return StatusKeep; |
274 |
|
275 |
} |
276 |
|
277 |
#endregion |
278 |
|
279 |
#region SetCleanUpItem |
280 |
/// <summary> |
281 |
/// 오류나 wait으로 남아 있는 데이터베이스의 Item을 StatusCodeType.None으로 복구 |
282 |
/// </summary> |
283 |
/// <param name="convertID">StatusCodeType을 변경하고자 하는 ConvertItem의 ID</param> |
284 |
/// <param name="ReConvert">ReConvert가 2이면 다시 Convert를 시도 안하기 때문에 기존 값으로 유지 하고 계속 시도 할수 있도록 0을 주는 경우가 있다.</param> |
285 |
/// <returns></returns> |
286 |
/// |
287 |
public int SetCleanUpItem(ConvertItem _ConvertItem) |
288 |
{ |
289 |
int result = 0; |
290 |
|
291 |
var items = entities.CONVERTER_DOC.Where(x => x.ID == _ConvertItem.ConvertID); |
292 |
|
293 |
result = items.Count(); |
294 |
|
295 |
if (items.Count() > 0) |
296 |
{ |
297 |
var item = items.First(); |
298 |
|
299 |
item.RECONVERTER = item.RECONVERTER - _ConvertItem.ReConverter; |
300 |
item.CREATE_DATETIME = DateTime.Now; |
301 |
item.STATUS = (int)StatusCodeType.None; |
302 |
|
303 |
result = entities.SaveChanges(); |
304 |
} |
305 |
|
306 |
return result; |
307 |
} |
308 |
|
309 |
#endregion |
310 |
|
311 |
#region Convert Path |
312 |
|
313 |
private string GetConvertPath(string ProjectNo, string DocumentID) |
314 |
{ |
315 |
try |
316 |
{ |
317 |
return Path.Combine(BaseStorage(ProjectNo), ProjectNo + "_Tile", (System.Convert.ToInt64(DocumentID) / 100).ToString(), DocumentID); |
318 |
} |
319 |
catch (Exception) |
320 |
{ |
321 |
throw new Exception("GetConvertPath Error"); |
322 |
} |
323 |
|
324 |
} |
325 |
|
326 |
private string BaseStorage(string ProjectNo) |
327 |
{ |
328 |
string result = ""; |
329 |
|
330 |
var properties = entities.PROPERTIES.Where(f => f.PROPERTY == ProjectNo && f.TYPE == PROPERTIES_DEFINE.TILE_SOURCE_STORAGE); |
331 |
|
332 |
if (properties.Count() > 0) |
333 |
{ |
334 |
result = properties.First().VALUE; |
335 |
} |
336 |
else |
337 |
{ |
338 |
throw new Exception($"Project {ProjectNo} BaseStorage Not Setting."); |
339 |
} |
340 |
|
341 |
return result; |
342 |
} |
343 |
|
344 |
#endregion |
345 |
|
346 |
#region Remove |
347 |
|
348 |
/// <summary> |
349 |
/// Item 삭제 |
350 |
/// </summary> |
351 |
/// <returns></returns> |
352 |
public int RemoveItem(string convertID) |
353 |
{ |
354 |
int result = 0; |
355 |
|
356 |
var items = entities.CONVERTER_DOC.Where(x => x.ID == convertID); |
357 |
|
358 |
if (items.Count() > 0) |
359 |
{ |
360 |
CONVERTER_DOC item = items.First(); |
361 |
entities.CONVERTER_DOC.Remove(item); |
362 |
|
363 |
result = entities.SaveChanges(); |
364 |
} |
365 |
|
366 |
return result; |
367 |
} |
368 |
|
369 |
|
370 |
#endregion |
371 |
|
372 |
#endregion |
373 |
|
374 |
#region DataBaseByStatusViewModel Function |
375 |
/// <summary> |
376 |
/// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다. |
377 |
/// </summary> |
378 |
/// <returns></returns> |
379 |
public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType, Func<CONVERTER_DOC, bool> @where, int takeCount = 100) |
380 |
{ |
381 |
List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>(); |
382 |
|
383 |
|
384 |
var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList(); |
385 |
|
386 |
if (items.Count() > 0) |
387 |
{ |
388 |
foreach (var item in items) |
389 |
{ |
390 |
var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL) |
391 |
{ |
392 |
ReConverter = item.RECONVERTER, |
393 |
ServiceID = item.SERVICE_ID, |
394 |
ConvertState = ((StatusCodeType)item.STATUS), |
395 |
CreateTime = item.CREATE_DATETIME, |
396 |
TotalPage = item.TOTAL_PAGE, |
397 |
CurrentPageNo = item.CURRENT_PAGE, |
398 |
|
399 |
ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID) |
400 |
}; |
401 |
|
402 |
convertItems.Add(convertitem); |
403 |
} |
404 |
} |
405 |
return convertItems; |
406 |
} |
407 |
#endregion |
408 |
|
409 |
#region No 참조 |
410 |
|
411 |
/// <summary> |
412 |
/// 컨버터서비스를 이용하는 문서 정보 저장 |
413 |
/// UniqueID |
414 |
/// using Markus.Service.Extensions; new Guid().CreateUniqueGuid().ToString(); |
415 |
/// </summary> |
416 |
/// <param name="ProjectNo">프로젝트</param> |
417 |
/// <param name="UniqueID">컨버터 서비스의 아이템 ID</param> |
418 |
/// <param name="originfilePath"></param> |
419 |
/// <param name="DocumentID"></param> |
420 |
/// <returns></returns> |
421 |
public bool SetConvertDoc(string ProjectNo, string UniqueID, string originfilePath, string DocumentID) |
422 |
{ |
423 |
bool result = false; |
424 |
|
425 |
if (ProjectNo.IsNullOrEmpty()) |
426 |
{ |
427 |
throw new Exception("ProjectNo is Null"); |
428 |
} |
429 |
|
430 |
if (UniqueID.IsNullOrEmpty()) |
431 |
{ |
432 |
throw new Exception("UniqueID is Null"); |
433 |
} |
434 |
|
435 |
if (originfilePath.IsNullOrEmpty()) |
436 |
{ |
437 |
throw new Exception("originfilePath is Null"); |
438 |
} |
439 |
|
440 |
if (DocumentID.IsNullOrEmpty()) |
441 |
{ |
442 |
throw new Exception("DocumentID is Null"); |
443 |
} |
444 |
|
445 |
if (DocumentID.IsNullOrEmpty()) |
446 |
{ |
447 |
long _lastDocId = 0; |
448 |
|
449 |
if (entities.CONVERTER_DOC.Count() > 0) |
450 |
{ |
451 |
try |
452 |
{ |
453 |
string qry = @"SELECT * FROM CONVERTER_DOC order by CAST(DOCUMENT_ID as int) desc"; |
454 |
var _item = entities.CONVERTER_DOC.SqlQuery(qry).FirstOrDefault(); |
455 |
|
456 |
if (_item != null) |
457 |
{ |
458 |
_lastDocId = Convert.ToInt64(_item.DOCUMENT_ID) + 1; |
459 |
} |
460 |
} |
461 |
catch (Exception) |
462 |
{ |
463 |
|
464 |
throw; |
465 |
} |
466 |
} |
467 |
|
468 |
DocumentID = _lastDocId.ToString(); |
469 |
} |
470 |
|
471 |
CONVERTER_DOC convert_doc = new CONVERTER_DOC |
472 |
{ |
473 |
ID = UniqueID, |
474 |
PROJECT_NO = ProjectNo, |
475 |
DOCUMENT_URL = originfilePath, |
476 |
DOCUMENT_ID = DocumentID, |
477 |
CREATE_DATETIME = DateTime.Now, |
478 |
STATUS = 0, |
479 |
TOTAL_PAGE = 0, |
480 |
CURRENT_PAGE = 0, |
481 |
RECONVERTER = 0 |
482 |
}; |
483 |
|
484 |
|
485 |
entities.CONVERTER_DOC.Add(convert_doc); |
486 |
|
487 |
if (entities.SaveChanges() == 1) |
488 |
{ |
489 |
result = true; |
490 |
} |
491 |
|
492 |
return result; |
493 |
} |
494 |
|
495 |
/// <summary> |
496 |
/// 컨버터서비스를 이용하는 문서 정보 저장 |
497 |
/// UniqueID |
498 |
/// using Markus.Service.Extensions; new Guid().CreateUniqueGuid().ToString(); |
499 |
/// </summary> |
500 |
/// <param name="ProjectNo">프로젝트</param> |
501 |
/// <param name="UniqueID">컨버터 서비스의 아이템 ID</param> |
502 |
/// <param name="originfilePath"></param> |
503 |
/// <param name="DocumentID"></param> |
504 |
/// <returns></returns> |
505 |
public bool SetDocumentInfo(string ConvertID, int totalPage, List<DOCPAGE> pageinfo) |
506 |
{ |
507 |
bool result = false; |
508 |
|
509 |
var convertDocItems = entities.CONVERTER_DOC.Where(f => f.ID == ConvertID); |
510 |
|
511 |
if (convertDocItems.Count() > 0) |
512 |
{ |
513 |
var convertDoc = convertDocItems.First(); |
514 |
|
515 |
string docId = new Guid().CreateUniqueGuid().ToString(); |
516 |
|
517 |
var docinfo = entities.DOCINFO.FirstOrDefault(x => x.PROJECT_NO == convertDoc.PROJECT_NO && x.DOCUMENT_ID == convertDoc.DOCUMENT_ID); |
518 |
|
519 |
if (docinfo != null) |
520 |
{ |
521 |
// 기존 Docpage 삭제. |
522 |
entities.DOCPAGE.RemoveRange(docinfo.DOCPAGE); |
523 |
|
524 |
// 기존 코멘트 유지를 위한 Docinfo update |
525 |
docinfo.PROJECT_NO = convertDoc.PROJECT_NO; |
526 |
docinfo.ORIGINAL_FILE = convertDoc.DOCUMENT_URL; |
527 |
docinfo.PAGE_COUNT = totalPage; |
528 |
docinfo.DOCPAGE = pageinfo; |
529 |
entities.SaveChanges(); |
530 |
result = true; |
531 |
} |
532 |
else |
533 |
{ |
534 |
DOCINFO instace = new DOCINFO |
535 |
{ |
536 |
ID = docId, |
537 |
PROJECT_NO = convertDoc.PROJECT_NO, |
538 |
ORIGINAL_FILE = convertDoc.DOCUMENT_URL, |
539 |
DOCUMENT_ID = convertDoc.DOCUMENT_ID, |
540 |
PAGE_COUNT = totalPage, |
541 |
DOCPAGE = pageinfo |
542 |
}; |
543 |
|
544 |
entities.DOCINFO.Add(instace); |
545 |
var save = entities.SaveChanges(); |
546 |
|
547 |
if (save == pageinfo.Count() + 1) |
548 |
{ |
549 |
result = true; |
550 |
} |
551 |
} |
552 |
|
553 |
|
554 |
|
555 |
} |
556 |
|
557 |
return result; |
558 |
} |
559 |
|
560 |
public Interface.ConvertItem GetConvertItem(string ProjectNo, string UniqueID) |
561 |
{ |
562 |
Interface.ConvertItem result = null; |
563 |
|
564 |
//var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID); |
565 |
var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.ID == UniqueID); |
566 |
|
567 |
if (items.Count() > 0) |
568 |
{ |
569 |
var convertItem = items.First(); |
570 |
|
571 |
string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID); |
572 |
|
573 |
result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath); |
574 |
} |
575 |
|
576 |
return result; |
577 |
} |
578 |
|
579 |
|
580 |
public Interface.ConvertItem GetConvertItembyDocumentID(string ProjectNo, string DocumentID) |
581 |
{ |
582 |
Interface.ConvertItem result = null; |
583 |
|
584 |
//var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID); |
585 |
var items = entities.CONVERTER_DOC.Where(f => f.PROJECT_NO == ProjectNo && f.DOCUMENT_ID == DocumentID); |
586 |
|
587 |
if (items.Count() > 0) |
588 |
{ |
589 |
var convertItem = items.First(); |
590 |
string convertPath = Path.Combine(BaseStorage(convertItem.PROJECT_NO), convertItem.PROJECT_NO + "_Tile", (System.Convert.ToInt64(convertItem.DOCUMENT_ID) / 100).ToString(), convertItem.DOCUMENT_ID); |
591 |
|
592 |
if (convertItem.STATUS == (int)StatusCodeType.Completed) |
593 |
{ |
594 |
result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath, |
595 |
(StatusCodeType)convertItem.STATUS, convertItem.CURRENT_PAGE, convertItem.TOTAL_PAGE, convertItem.EXCEPTION); |
596 |
} |
597 |
else |
598 |
{ |
599 |
result = new Interface.ConvertItem(convertItem.DOCUMENT_ID, convertItem.PROJECT_NO, convertItem.ID, convertItem.DOCUMENT_URL, convertPath); |
600 |
} |
601 |
} |
602 |
|
603 |
return result; |
604 |
} |
605 |
|
606 |
public List<CONVERTER_DOC> GetConvertingItems(List<string> projectList) |
607 |
{ |
608 |
var convertWaitingItems = entities.CONVERTER_DOC.OrderBy(x => x.CREATE_DATETIME).Where( |
609 |
x => |
610 |
projectList.Contains(x.PROJECT_NO) && |
611 |
(x.STATUS > (int)StatusCodeType.None && x.STATUS < (int)StatusCodeType.Completed) && x.RECONVERTER < 2); |
612 |
|
613 |
return convertWaitingItems.ToList(); |
614 |
} |
615 |
|
616 |
/// <summary> |
617 |
/// 전체 컨버터를 가져온다. 비동기로 변경하여야 한다. |
618 |
/// </summary> |
619 |
/// <returns></returns> |
620 |
public List<Interface.ConvertItem> GetConvertItems(StatusCodeType statusCodeType) |
621 |
{ |
622 |
List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>(); |
623 |
|
624 |
var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo); |
625 |
|
626 |
if (items.Count() > 0) |
627 |
{ |
628 |
foreach (var item in items) |
629 |
{ |
630 |
var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL) |
631 |
{ |
632 |
ReConverter = item.RECONVERTER, |
633 |
ServiceID = item.SERVICE_ID, |
634 |
ConvertState = ((StatusCodeType)item.STATUS), |
635 |
CreateTime = item.CREATE_DATETIME, |
636 |
TotalPage = item.TOTAL_PAGE, |
637 |
CurrentPageNo = item.CURRENT_PAGE, |
638 |
|
639 |
ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID) |
640 |
}; |
641 |
|
642 |
|
643 |
convertItems.Add(convertitem); |
644 |
} |
645 |
} |
646 |
return convertItems; |
647 |
} |
648 |
|
649 |
public List<Interface.ConvertItem> GetConvertProjectsStatus(Func<CONVERTER_DOC, bool> @where) |
650 |
{ |
651 |
List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>(); |
652 |
|
653 |
|
654 |
//var items = entities.CONVERTER_DOC.Where(x => x.STATUS == (int)statusCodeType).Take(takeCount).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo); |
655 |
var items = entities.CONVERTER_DOC.Where(x => x.STATUS <= 4); |
656 |
|
657 |
if (items.Count() > 0) |
658 |
{ |
659 |
foreach (var item in items) |
660 |
{ |
661 |
var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL) |
662 |
{ |
663 |
ReConverter = item.RECONVERTER, |
664 |
ServiceID = item.SERVICE_ID, |
665 |
//ConvertState = ((StatusCodeType)item.STATUS).ToString(), |
666 |
//ConvertState = (item.STATUS).ToString(), |
667 |
ConvertState = (StatusCodeType)item.STATUS, |
668 |
CreateTime = item.CREATE_DATETIME, |
669 |
TotalPage = item.TOTAL_PAGE, |
670 |
CurrentPageNo = item.CURRENT_PAGE, |
671 |
Exception = item.EXCEPTION, |
672 |
ConvertPath = GetConvertPath(item.PROJECT_NO, item.DOCUMENT_ID) |
673 |
}; |
674 |
|
675 |
|
676 |
convertItems.Add(convertitem); |
677 |
} |
678 |
} |
679 |
|
680 |
return convertItems; |
681 |
} |
682 |
|
683 |
|
684 |
public bool SetConvertState(string ServiceID, string UniqueID, int State, int CurrentPage, int TotalPage, string Error) |
685 |
{ |
686 |
bool result = false; |
687 |
|
688 |
try |
689 |
{ |
690 |
var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.ID == UniqueID); |
691 |
//var items = entities.CONVERTER_DOC.SingleOrDefault(f => f.PROJECT_NO == gProjectNo && f.ID == UniqueID); |
692 |
|
693 |
if (items != null) |
694 |
{ |
695 |
items.SERVICE_ID = ServiceID; |
696 |
items.STATUS = State; |
697 |
items.CURRENT_PAGE = CurrentPage; |
698 |
items.TOTAL_PAGE = TotalPage; |
699 |
|
700 |
StatusCodeType statusCode = (StatusCodeType)State; |
701 |
|
702 |
if (items.START_DATETIME == null) |
703 |
{ |
704 |
items.START_DATETIME = DateTime.Now; |
705 |
} |
706 |
|
707 |
switch (statusCode) |
708 |
{ |
709 |
case StatusCodeType.None: |
710 |
break; |
711 |
case StatusCodeType.Wait: |
712 |
items.START_DATETIME = DateTime.Now; |
713 |
break; |
714 |
case StatusCodeType.PageLoading: |
715 |
break; |
716 |
case StatusCodeType.Saving: |
717 |
break; |
718 |
case StatusCodeType.Completed: |
719 |
items.CURRENT_PAGE = items.TOTAL_PAGE; |
720 |
items.END_DATETIME = DateTime.Now; |
721 |
break; |
722 |
case StatusCodeType.FileError: |
723 |
Error = $" file Error :" + Error; |
724 |
items.END_DATETIME = DateTime.Now; |
725 |
break; |
726 |
case StatusCodeType.PageError: |
727 |
Error = $" Page No {CurrentPage} Error :" + Error; |
728 |
break; |
729 |
case StatusCodeType.NeedsPassword: |
730 |
break; |
731 |
case StatusCodeType.Error: |
732 |
Error = $" Error :" + Error; |
733 |
items.END_DATETIME = DateTime.Now; |
734 |
break; |
735 |
default: |
736 |
break; |
737 |
} |
738 |
|
739 |
if (items.EXCEPTION == null) |
740 |
{ |
741 |
items.EXCEPTION = ""; |
742 |
} |
743 |
|
744 |
if (items.EXCEPTION.Length < 255) |
745 |
{ |
746 |
items.EXCEPTION = items.EXCEPTION + Error; |
747 |
} |
748 |
|
749 |
entities.SaveChanges(); |
750 |
result = true; |
751 |
} |
752 |
} |
753 |
catch (Exception ex) |
754 |
{ |
755 |
throw new Exception("SetConvertState", ex); |
756 |
} |
757 |
|
758 |
return result; |
759 |
} |
760 |
|
761 |
public SERVICE_PROPERTIES GetServiceProperties(string ServiceID) |
762 |
{ |
763 |
SERVICE_PROPERTIES result = null; |
764 |
|
765 |
var items = entities.SERVICE_PROPERTIES.Where(x => x.ID == ServiceID); |
766 |
|
767 |
if (items.Count() > 0) |
768 |
{ |
769 |
result = items.First(); |
770 |
} |
771 |
|
772 |
return result; |
773 |
} |
774 |
|
775 |
|
776 |
/// <summary> |
777 |
/// 현재 서비스에서 컨버터중인 아이템. |
778 |
/// </summary> |
779 |
/// <returns></returns> |
780 |
public List<Interface.ConvertItem> GetServiceAliveItems(string ServiceID) |
781 |
{ |
782 |
List<Interface.ConvertItem> convertItems = new List<Interface.ConvertItem>(); |
783 |
|
784 |
var items = entities.CONVERTER_DOC.Where(x => x.SERVICE_ID == ServiceID && x.STATUS > (int)StatusCodeType.None && x.STATUS < (int)StatusCodeType.Completed).ToList(); //.Where(x => x.PROJECT_NO == gProjectNo); |
785 |
|
786 |
if (items.Count() > 0) |
787 |
{ |
788 |
foreach (var item in items) |
789 |
{ |
790 |
var convertitem = new Interface.ConvertItem(item.DOCUMENT_ID, item.PROJECT_NO, item.ID, item.DOCUMENT_URL); |
791 |
convertItems.Add(convertitem); |
792 |
} |
793 |
} |
794 |
return convertItems; |
795 |
} |
796 |
|
797 |
#endregion |
798 |
|
799 |
} |
800 |
} |