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