프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.DataBase / ConvertDatabase.cs @ 5a954acc

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