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