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