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