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