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