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