프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ 05fd750b

이력 | 보기 | 이력해설 | 다운로드 (32.2 KB)

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