markus / ConvertService / ConverterService / DZConverterLib / Copy (6) of DZConverter.cs @ ced47e14
이력 | 보기 | 이력해설 | 다운로드 (25.9 KB)
1 | 7ca218b3 | KangIngu | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Data.Objects.DataClasses; |
||
4 | using System.Drawing; |
||
5 | using System.Drawing.Imaging; |
||
6 | using System.IO; |
||
7 | using System.Linq; |
||
8 | using System.Security.Permissions; |
||
9 | using System.Threading.Tasks; |
||
10 | using DeepView.Toolkit.GuidGenerator; |
||
11 | using DeepViewDataModel.Common; |
||
12 | using DeepViewDataModel.DataModel; |
||
13 | using DZConverterLib.DAL; |
||
14 | using pdftron.PDF; |
||
15 | |||
16 | namespace DZConverterLib |
||
17 | { |
||
18 | public class DZConverter: IDisposable |
||
19 | { |
||
20 | //public const string ProjectRoot = @"D:\DeepViewConverter\"; |
||
21 | //public const string DownloadDir_PDF = ProjectRoot + @"\PDFPath"; |
||
22 | public string DownloadDir_PDF; |
||
23 | private PDFDoc doc = null; |
||
24 | private EntityCollection<DocPage> pageSet = null; |
||
25 | public int pageCount = 0; |
||
26 | public ConverterPDF ConverterItem; |
||
27 | public event EventHandler<MakeConverterErrorArgs> ConverterMakeError; |
||
28 | public event EventHandler<EndConverterEventArgs> EndConverter; |
||
29 | |||
30 | private static ImageCodecInfo DefaultImageCodecInfo = GetEncoderInfo("image/png"); |
||
31 | private static EncoderParameters DefaultEncoderParameters = new EncoderParameters(2) |
||
32 | { |
||
33 | Param = new EncoderParameter[]{ |
||
34 | new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L), |
||
35 | new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8L) |
||
36 | } |
||
37 | }; |
||
38 | public DZConverter() |
||
39 | { |
||
40 | pdftron.PDFNet.Initialize("daelim.co.kr(Doftech Corp):CPU:2::W:AMC(20120315):EF6E886F25A414FFB5F8C1F2999CF2DA33DC6C5164315BAF7011B87AF0FA"); |
||
41 | |||
42 | pageSet = new EntityCollection<DocPage>(); |
||
43 | } |
||
44 | |||
45 | private void SendError(int Level,string ErrorCode, string _Exception, bool ThreadStop) |
||
46 | { |
||
47 | if (ConverterMakeError != null) |
||
48 | ConverterMakeError(this, new MakeConverterErrorArgs |
||
49 | { |
||
50 | ThreadStop = ThreadStop, |
||
51 | ConverterID = ConverterItem.ID, |
||
52 | _Exception = _Exception, |
||
53 | ErrorCode = ErrorCode, |
||
54 | Level = Level |
||
55 | }); |
||
56 | } |
||
57 | |||
58 | [FileIOPermission(SecurityAction.LinkDemand)] |
||
59 | public void GetSingleFile(object obj) |
||
60 | { |
||
61 | try |
||
62 | { |
||
63 | ConverterItem = obj as ConverterPDF; |
||
64 | |||
65 | using (DeepViewEntities _deepview = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
||
66 | { |
||
67 | var _property = _deepview.Properties.Where(pro => pro.Property == ConverterItem.ProjectNo); |
||
68 | |||
69 | if (_property.Count() > 0) |
||
70 | { |
||
71 | DownloadDir_PDF = _property.Where(t => t.Type == PropertiesType.PropertiesType.Const_TileSorceStorage).First().Value; |
||
72 | |||
73 | if (!Directory.Exists(DownloadDir_PDF)) // 폴더 없을 시 생성 |
||
74 | { |
||
75 | Directory.CreateDirectory(DownloadDir_PDF); |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | |||
80 | DownloadFile(); |
||
81 | } |
||
82 | catch (Exception e) |
||
83 | { |
||
84 | SendError(0, "Converter Error ", e.ToString(), true); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | |||
89 | private void SetState(IConverterPDF.ConverterStatus Status) |
||
90 | { |
||
91 | using (DeepViewEntities _entity = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
||
92 | { |
||
93 | var _items = _entity.ConverterPDF.Where(converter => converter.ID == this.ConverterItem.ID); |
||
94 | if (_items.Count() > 0) |
||
95 | { |
||
96 | if (Status == IConverterPDF.ConverterStatus.Create) |
||
97 | { |
||
98 | _items.First().StartDateTime = DateTime.Now; |
||
99 | } |
||
100 | |||
101 | _items.First().Status = (int)Status; |
||
102 | _entity.SaveChanges(); |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | |||
107 | private void SetCurrentPage(int CurrentPage, IConverterPDF.ConverterStatus Status) |
||
108 | { |
||
109 | |||
110 | using (DeepViewEntities _entity = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
||
111 | { |
||
112 | var _items = _entity.ConverterPDF.Where(converter => converter.ID == this.ConverterItem.ID); |
||
113 | if (_items.Count() > 0) |
||
114 | { |
||
115 | _items.First().Status = (int)Status; |
||
116 | _items.First().CurrentPage = CurrentPage; |
||
117 | _entity.SaveChanges(); |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | |||
122 | System.Net.WebClient _fileFactory = new System.Net.WebClient(); |
||
123 | |||
124 | [FileIOPermission(SecurityAction.LinkDemand)] |
||
125 | public void DownloadFile() |
||
126 | { |
||
127 | string DocUri = ConverterItem.PdfUrl; //PDF 전체 경로 |
||
128 | string FileName = DocUri.Remove(0, DocUri.LastIndexOf("/") + 1); |
||
129 | string ProjectFolderPath = DownloadDir_PDF + "\\" + ConverterItem.ProjectNo + "_Tile"; //프로젝트 폴더 |
||
130 | string ItemListPath = ProjectFolderPath + "\\" + (System.Convert.ToInt64(ConverterItem.SharepointItemID) / 100).ToString(); |
||
131 | string ItemPath = ItemListPath + "\\" + ConverterItem.SharepointItemID; |
||
132 | string DownloadFilePath = ItemPath + "\\" + FileName; |
||
133 | |||
134 | #region 폴더 생성 |
||
135 | try |
||
136 | { |
||
137 | |||
138 | DirectoryInfo _dir = new DirectoryInfo(ItemPath); |
||
139 | |||
140 | if (_dir.Exists) |
||
141 | { |
||
142 | _dir.Empty(false); |
||
143 | |||
144 | } |
||
145 | else |
||
146 | { |
||
147 | Directory.CreateDirectory(ItemPath); |
||
148 | } |
||
149 | |||
150 | } |
||
151 | catch (Exception ex) |
||
152 | { |
||
153 | //DeleteDirectoryDirs(ItemPath); |
||
154 | SendError(0,"폴더삭제 에러",ex.ToString(), false); |
||
155 | } |
||
156 | |||
157 | #endregion |
||
158 | |||
159 | #region 다운로드 |
||
160 | |||
161 | try |
||
162 | { |
||
163 | |||
164 | _fileFactory.UseDefaultCredentials = true; |
||
165 | |||
166 | _fileFactory.DownloadFileCompleted +=(snd,evt)=> |
||
167 | { |
||
168 | if (File.Exists(DownloadFilePath) && evt.Error == null) |
||
169 | { |
||
170 | SetState(IConverterPDF.ConverterStatus.Create); |
||
171 | |||
172 | #region 기본 설정 |
||
173 | doc = new PDFDoc(DownloadFilePath); |
||
174 | #endregion |
||
175 | System.Diagnostics.Debug.WriteLine("download file completed : " + DocUri); |
||
176 | ConvertProcess(DownloadFilePath, ItemPath, FileName); |
||
177 | } |
||
178 | else |
||
179 | { |
||
180 | SendError(1, "File Not Found", "File Download Error" + DownloadFilePath, true); |
||
181 | } |
||
182 | }; |
||
183 | System.Diagnostics.Debug.WriteLine("download file : " + DocUri); |
||
184 | _fileFactory.DownloadFileAsync(new Uri(DocUri), DownloadFilePath); |
||
185 | |||
186 | #endregion |
||
187 | } |
||
188 | catch (Exception ex) |
||
189 | { |
||
190 | SendError(1, "File Download Error : Url - " + DocUri + " Download Path : " + DownloadFilePath, ex.ToString(), true); |
||
191 | } |
||
192 | finally |
||
193 | { |
||
194 | |||
195 | } |
||
196 | } |
||
197 | |||
198 | [FileIOPermission(SecurityAction.LinkDemand)] |
||
199 | public void ConvertProcess(string DownloadFilePath, string ItemPath, string FileName) |
||
200 | { |
||
201 | |||
202 | ResultSet Result_Check = new ResultSet(); |
||
203 | #region PDF 체크 |
||
204 | try |
||
205 | { |
||
206 | Result_Check = Check_PDF(); |
||
207 | } |
||
208 | catch (Exception ex) |
||
209 | { |
||
210 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
211 | Result_Check.Message = ex.ToString(); |
||
212 | Result_Check.result = false; |
||
213 | } |
||
214 | |||
215 | if (!Result_Check.result) |
||
216 | { |
||
217 | SendError(1, "PDF 체크 실패 : 보안설정으로 인한 PDF 체크 실패", Result_Check.Message,false); |
||
218 | } |
||
219 | #endregion |
||
220 | |||
221 | #region PDF에서 이미지로 변환 |
||
222 | |||
223 | try |
||
224 | { |
||
225 | int _pageCount = ConvertImage(ItemPath); |
||
226 | if (_pageCount == pageSet.Count()) |
||
227 | { |
||
228 | SetCurrentPage(_pageCount,IConverterPDF.ConverterStatus.Crop); |
||
229 | |||
230 | var _infotoDBResult = SetPageInfoToDB(); // 데이터베이스 입력 |
||
231 | |||
232 | if (_infotoDBResult != null) |
||
233 | SendError(0, "SetPageInfoToDB()", _infotoDBResult, true); |
||
234 | } |
||
235 | else |
||
236 | { |
||
237 | SendError(0, "converter Check", "Page Count :" + _pageCount + " PageSet : " + pageSet.Count(), true); |
||
238 | return; |
||
239 | } |
||
240 | } |
||
241 | catch (Exception ex) |
||
242 | { |
||
243 | SendError(0, "converter Check ","if (!ConvertImage(ItemPath, FileName)) " + ex.ToString(), true); |
||
244 | } |
||
245 | |||
246 | #endregion |
||
247 | |||
248 | if (EndConverter != null) |
||
249 | EndConverter(this, new EndConverterEventArgs { ConverterPDF = ConverterItem}); |
||
250 | } |
||
251 | |||
252 | public ResultSet Check_PDF() |
||
253 | { |
||
254 | ResultSet _result = new ResultSet(); |
||
255 | bool _Security = false; |
||
256 | bool _isEncrypte = true; |
||
257 | try |
||
258 | { |
||
259 | |||
260 | _Security = doc.InitSecurityHandler(); |
||
261 | _isEncrypte = doc.IsEncrypted(); |
||
262 | |||
263 | //접근권한 체크 |
||
264 | if (!_Security) |
||
265 | { |
||
266 | _result.result = false; |
||
267 | _result.Message = "Document authentication Error"; |
||
268 | } |
||
269 | else |
||
270 | if (_isEncrypte) |
||
271 | { |
||
272 | _result.result = false; |
||
273 | _result.Message = "Document is Encrypted"; |
||
274 | } |
||
275 | else |
||
276 | _result.result = true; |
||
277 | |||
278 | } |
||
279 | catch (Exception ex) |
||
280 | { |
||
281 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
282 | _result.Message = ex.ToString(); |
||
283 | _result.result = false; |
||
284 | } |
||
285 | |||
286 | return _result; |
||
287 | } |
||
288 | |||
289 | |||
290 | #region private Method |
||
291 | |||
292 | private static ImageCodecInfo GetEncoderInfo(String mimeType) |
||
293 | { |
||
294 | int j; |
||
295 | ImageCodecInfo[] encoders; |
||
296 | encoders = ImageCodecInfo.GetImageEncoders(); |
||
297 | for (j = 0; j < encoders.Length; ++j) |
||
298 | { |
||
299 | if (encoders[j].MimeType == mimeType) |
||
300 | return encoders[j]; |
||
301 | } |
||
302 | return null; |
||
303 | } |
||
304 | |||
305 | private string ConvertDeepImage(string convertFile) |
||
306 | { |
||
307 | string _result = string.Empty; |
||
308 | |||
309 | ImageFields.ImageFields creator = new ImageFields.ImageFields() |
||
310 | { |
||
311 | TileSize = 256, |
||
312 | TileFormat = ImageFields.ImageFormat.AutoSelect, |
||
313 | CopyMetadata = false, |
||
314 | ConversionCopyMetadata = false, |
||
315 | LowLevelPass = true |
||
316 | }; |
||
317 | |||
318 | FileInfo _file = new FileInfo(convertFile); |
||
319 | |||
320 | try |
||
321 | { |
||
322 | if (_file.Exists) |
||
323 | { |
||
324 | creator.Create(_file.FullName, _file.FullName.ToString().Replace(".jpg", ".xml")); |
||
325 | System.Diagnostics.Debug.WriteLine("!!! DeepImage filename : " + convertFile); |
||
326 | _file.Delete(); |
||
327 | } |
||
328 | } |
||
329 | catch (Exception ex) |
||
330 | { |
||
331 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
332 | |||
333 | if (ex.GetType() == typeof(System.ArgumentException)) |
||
334 | _result = "DPI Exception."; |
||
335 | else |
||
336 | _result = "Code 102312394"; |
||
337 | } |
||
338 | return _result; |
||
339 | } |
||
340 | |||
341 | object _lock = new object(); |
||
342 | |||
343 | private string PageToDeep(Bitmap Bitmap,string FilePath,int Index) |
||
344 | { |
||
345 | string _result = string.Empty; |
||
346 | string pagePath = FilePath + "\\" + Index; |
||
347 | string ImageName = pagePath + "\\" + Index + ".jpg"; |
||
348 | |||
349 | try |
||
350 | { |
||
351 | lock (_lock) |
||
352 | { |
||
353 | using (MemoryStream _savestream = new MemoryStream()) |
||
354 | { |
||
355 | Bitmap.Save(_savestream, DefaultImageCodecInfo, DefaultEncoderParameters); |
||
356 | Bitmap = new Bitmap(_savestream); |
||
357 | Directory.CreateDirectory(pagePath); |
||
358 | Bitmap.Save(ImageName); |
||
359 | Bitmap.Dispose(); |
||
360 | } |
||
361 | |||
362 | _result = ConvertDeepImage(ImageName); |
||
363 | SetCurrentPage(Index, IConverterPDF.ConverterStatus.Crop); |
||
364 | } |
||
365 | |||
366 | } |
||
367 | catch (Exception ex) |
||
368 | { |
||
369 | _result = ex.ToString(); |
||
370 | } |
||
371 | |||
372 | System.GC.Collect(); |
||
373 | System.GC.WaitForPendingFinalizers(); |
||
374 | return _result; |
||
375 | } |
||
376 | |||
377 | private int ConvertImage(string FilePath) |
||
378 | { |
||
379 | int _result = 0; |
||
380 | |||
381 | try |
||
382 | { |
||
383 | Bitmap newBmp_; |
||
384 | pageCount = doc.GetPageCount(); |
||
385 | |||
386 | using (DeepViewEntities _entity = new DeepViewEntities(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
||
387 | { |
||
388 | var _items = _entity.ConverterPDF.Where(converter => converter.ID == this.ConverterItem.ID); |
||
389 | if (_items.Count() > 0) |
||
390 | { |
||
391 | _items.First().TotalPages = pageCount; |
||
392 | _entity.SaveChanges(); |
||
393 | } |
||
394 | } |
||
395 | |||
396 | #region 이미지 만들기 |
||
397 | |||
398 | for (PageIterator itr = doc.GetPageIterator(); itr.HasNext(); itr.Next()) |
||
399 | { |
||
400 | Page _page = itr.Current(); |
||
401 | int _pageNo = itr.GetPageNumber(); |
||
402 | |||
403 | try |
||
404 | { |
||
405 | System.Diagnostics.Debug.WriteLine("!!! Put Image : " + _pageNo); |
||
406 | |||
407 | using (pdftron.PDF.PDFDraw draw = new pdftron.PDF.PDFDraw()) |
||
408 | { |
||
409 | var widthData = (int)_page.GetPageWidth(); |
||
410 | int heightData = (int)_page.GetPageHeight(); |
||
411 | pageSet.Add(new DocPage |
||
412 | { |
||
413 | Id = GuidGenerator.GetUniqueGuid(), |
||
414 | PageWidth = (widthData * 3).ToString(), |
||
415 | PageHeight = (heightData * 3).ToString(), |
||
416 | PageNumber = _pageNo, |
||
417 | PageAngle = 0, |
||
418 | }); |
||
419 | |||
420 | var rotation = doc.GetPage(_pageNo).GetRotation(); |
||
421 | draw.SetImageSize((int)(widthData * 3), (int)(heightData * 3), true); |
||
422 | //draw.SetImageSize((int)(widthData), (int)(heightData), true); |
||
423 | draw.SetAntiAliasing(true); |
||
424 | draw.SetImageSmoothing(true); |
||
425 | draw.SetThinLineAdjustment(true, true); |
||
426 | newBmp_ = draw.GetBitmap(_page); |
||
427 | SetCurrentPage(_pageNo,IConverterPDF.ConverterStatus.Create); |
||
428 | _Task.Add(Task.Factory.StartNew<string>(() => PageToDeep(newBmp_, FilePath, _pageNo))); |
||
429 | |||
430 | if (_pageNo == pageCount || _pageNo % 5 == 0) |
||
431 | { |
||
432 | Task.WaitAll(_Task.ToArray()); |
||
433 | } |
||
434 | } |
||
435 | } |
||
436 | catch (Exception ex) |
||
437 | { |
||
438 | SendError(0, "ConverterImage Error : Page NO -" + _pageNo.ToString(), ex.ToString(), true); |
||
439 | return 0; |
||
440 | } |
||
441 | |||
442 | } |
||
443 | |||
444 | Task.WaitAll(_Task.ToArray()); |
||
445 | _result = _Task.Where(r => r.Result.Count() == 0).Count(); |
||
446 | if (_result != pageCount) |
||
447 | { |
||
448 | var _Ex = from task in _Task |
||
449 | let a = task.Result |
||
450 | where (task.Result.Count() > 0) |
||
451 | select new { ex = string.Join(",", a) }; |
||
452 | |||
453 | SendError(0, "Converter Error code(21324) : Page Count Error", string.Join(",", _Ex), true); |
||
454 | return 0; |
||
455 | } |
||
456 | |||
457 | _Task.ForEach(f=>f.Dispose()); |
||
458 | _Task.Clear(); |
||
459 | |||
460 | GC.Collect(2); |
||
461 | GC.Collect(2); |
||
462 | } |
||
463 | catch (Exception ex) |
||
464 | { |
||
465 | |||
466 | SendError(0, "code 1230saf325 Error :", ex.ToString(), true); |
||
467 | } |
||
468 | finally |
||
469 | { |
||
470 | doc.Close(); |
||
471 | doc.Dispose(); |
||
472 | pdftron.PDFNet.Terminate(); |
||
473 | doc = null; |
||
474 | } |
||
475 | |||
476 | #endregion |
||
477 | return _result; |
||
478 | } |
||
479 | |||
480 | List<Task<string>> _Task = new List<Task<string>>(); |
||
481 | |||
482 | private string ConvertImgToDeep(string convertFileName, int Index) |
||
483 | { |
||
484 | string _result = string.Empty; |
||
485 | FileInfo convertFile = new FileInfo(convertFileName); |
||
486 | |||
487 | ImageFields.ImageFields creator = new ImageFields.ImageFields |
||
488 | { |
||
489 | TileSize = 256, |
||
490 | TileFormat = ImageFields.ImageFormat.AutoSelect, |
||
491 | CopyMetadata = false, |
||
492 | ConversionCopyMetadata = false, |
||
493 | LowLevelPass = true |
||
494 | }; |
||
495 | |||
496 | try |
||
497 | { |
||
498 | if (convertFile.Exists) |
||
499 | { |
||
500 | creator.Create(convertFile.FullName, convertFile.FullName.ToString().Replace(".jpg", ".xml")); |
||
501 | convertFile.Delete(); |
||
502 | |||
503 | } |
||
504 | else |
||
505 | { |
||
506 | _result = "Code 123412545 Page No :" + Index.ToString() + " ex : File Not"; |
||
507 | } |
||
508 | } |
||
509 | catch (Exception ex) |
||
510 | { |
||
511 | System.Diagnostics.Debug.WriteLine(ex.ToString()); |
||
512 | |||
513 | if (ex.GetType() == typeof(System.ArgumentException)) |
||
514 | _result = "DPI Exception. Page No :" + Index.ToString(); |
||
515 | else |
||
516 | _result = "Code 102312394 Page No :" + Index.ToString() + " ex" + ex.Message; |
||
517 | } |
||
518 | System.Diagnostics.Debug.WriteLine("ImageFields End : " + _result); |
||
519 | return _result; |
||
520 | } |
||
521 | |||
522 | private string SetPageInfoToDB() |
||
523 | { |
||
524 | try |
||
525 | { |
||
526 | |||
527 | #region DB에 페이지 정보 입력 |
||
528 | |||
529 | |||
530 | using (CI_Entities deepViewEntity = new CI_Entities(ConnectStringBuilder.ProjectCIConnectString(ConverterItem.ProjectNo).ToString())) |
||
531 | { |
||
532 | var _docinfo = deepViewEntity |
||
533 | .DocInfo.Where(info => info.OrginPDFUrl == ConverterItem.PdfUrl); |
||
534 | |||
535 | if (_docinfo.Count() > 0) |
||
536 | { |
||
537 | System.Diagnostics.Stopwatch _watch = new System.Diagnostics.Stopwatch(); |
||
538 | _watch.Start(); |
||
539 | var _doc = _docinfo.First(); |
||
540 | _doc.SharepointItemID = ConverterItem.SharepointItemID; |
||
541 | _doc.PageCount = pageCount; |
||
542 | |||
543 | pageSet.AsParallel().ForAll(p => p.DocInfo_Id = _doc.Id); |
||
544 | |||
545 | var _exceptDocInfo = (from newinfo in pageSet |
||
546 | select new { newinfo.PageNumber, newinfo.DocInfo_Id,newinfo.PageWidth,newinfo.PageHeight}) |
||
547 | .Except |
||
548 | (from oldinfo in _doc.DocPage |
||
549 | select new { oldinfo.PageNumber, oldinfo.DocInfo_Id, oldinfo.PageWidth, oldinfo.PageHeight }); |
||
550 | |||
551 | var _delDocInfo = (from oldinfo in _doc.DocPage |
||
552 | select new { oldinfo.PageNumber, oldinfo.DocInfo_Id, oldinfo.PageWidth, oldinfo.PageHeight }) |
||
553 | .Except |
||
554 | (from newinfo in pageSet |
||
555 | select new { newinfo.PageNumber, newinfo.DocInfo_Id, newinfo.PageWidth, newinfo.PageHeight }) |
||
556 | .ToList(); /// 삭제되는 collection은 하나씩 제거 될때마다 수정되기 때문에 |
||
557 | /// foreach가 안된다. 그러므로 tolist로 가져와서 작업한다. |
||
558 | |||
559 | //using (DeepView_SystemEntities SystemEntity = new DeepView_SystemEntities(ConnectStringBuilder.DeepViewSystemConnectionString().ToString())) |
||
560 | //{ |
||
561 | // SystemEntity.RemoveBackup_DocInfo.AddObject(new RemoveBackup_DocInfo |
||
562 | // { |
||
563 | // BackupUserID = "ConvertStation", |
||
564 | // BackupTime= DateTime.Now, |
||
565 | // ID = GuidGenerator.GetUniqueGuid(), |
||
566 | // OriginDocInfoID = _doc.Id, |
||
567 | // SharepointItemID = _doc.SharepointItemID, |
||
568 | // OriginPDFUrl= _doc.OrginPDFUrl, |
||
569 | // PageCount= _doc.PageCount, |
||
570 | // ProjectNo = ConverterItem.ProjectNo, |
||
571 | // Status = true |
||
572 | // }); |
||
573 | |||
574 | |||
575 | // foreach (var item in _delDocInfo) |
||
576 | // { |
||
577 | // var _delitem = _doc.DocPage.Where(p => p.PageNumber == item.PageNumber).First(); |
||
578 | |||
579 | // deepViewEntity.DocPage.DeleteObject(_delitem); |
||
580 | // //deepViewEntity.DocPage.DeleteObject(item); |
||
581 | // } |
||
582 | //} |
||
583 | foreach (var item in _delDocInfo) |
||
584 | { |
||
585 | var _delitem = _doc.DocPage.Where(p => p.PageNumber == item.PageNumber).First(); |
||
586 | |||
587 | deepViewEntity.DocPage.DeleteObject(_delitem); |
||
588 | //deepViewEntity.DocPage.DeleteObject(item); |
||
589 | } |
||
590 | |||
591 | deepViewEntity.SaveChanges(); |
||
592 | |||
593 | foreach (var exceptitem in _exceptDocInfo) |
||
594 | { |
||
595 | var _lstPage = deepViewEntity.DocPage.Where(page => page.PageNumber == exceptitem.PageNumber |
||
596 | && page.DocInfo_Id == exceptitem.DocInfo_Id); |
||
597 | |||
598 | if (_lstPage.Count() > 0) |
||
599 | { |
||
600 | var _page = _lstPage.First(); |
||
601 | _page.PageHeight = exceptitem.PageHeight; |
||
602 | _page.PageWidth = exceptitem.PageWidth; |
||
603 | } |
||
604 | else |
||
605 | { |
||
606 | _doc.DocPage.Add(pageSet.Where(p=>p.PageNumber == exceptitem.PageNumber).First()); |
||
607 | } |
||
608 | } |
||
609 | |||
610 | deepViewEntity.SaveChanges(); |
||
611 | |||
612 | _watch.Stop(); |
||
613 | System.Diagnostics.Debug.WriteLine(_watch.ElapsedMilliseconds); |
||
614 | } |
||
615 | else |
||
616 | { |
||
617 | |||
618 | Guid guid = GuidGenerator.GetUniqueGuid(); |
||
619 | DocInfo instace = new DocInfo |
||
620 | { |
||
621 | Id = guid, |
||
622 | OrginPDFUrl = ConverterItem.PdfUrl, |
||
623 | SharepointItemID = ConverterItem.SharepointItemID, |
||
624 | PageCount = pageCount, |
||
625 | DocPage = pageSet |
||
626 | }; |
||
627 | deepViewEntity.DocInfo.AddObject(instace); |
||
628 | } |
||
629 | |||
630 | deepViewEntity.SaveChanges(); |
||
631 | } |
||
632 | } |
||
633 | catch (Exception e) |
||
634 | { |
||
635 | return e.ToString(); |
||
636 | } |
||
637 | |||
638 | #endregion |
||
639 | |||
640 | return null; |
||
641 | } |
||
642 | #endregion |
||
643 | |||
644 | public void Dispose() |
||
645 | { |
||
646 | if (doc != null) |
||
647 | { |
||
648 | doc.Close(); |
||
649 | doc.Dispose(); |
||
650 | pdftron.PDFNet.Terminate(); |
||
651 | doc = null; |
||
652 | } |
||
653 | |||
654 | if (_fileFactory != null) |
||
655 | { |
||
656 | _fileFactory.Dispose(); |
||
657 | _fileFactory = null; |
||
658 | } |
||
659 | |||
660 | |||
661 | GC.Collect(); |
||
662 | GC.WaitForPendingFinalizers(); |
||
663 | } |
||
664 | |||
665 | } |
||
666 | |||
667 | public enum FinalStatus |
||
668 | { |
||
669 | /// <summary> |
||
670 | /// Final PDF를 만들기 위한 순서에 추가 |
||
671 | /// </summary> |
||
672 | Insert = 0, |
||
673 | |||
674 | /// <summary> |
||
675 | /// 앞의 final이 처리중일때 대기 |
||
676 | /// </summary> |
||
677 | Wait = 1, |
||
678 | |||
679 | /// <summary> |
||
680 | /// 만들고 있는중 |
||
681 | /// 이때 데이터베이스에 Current Page는 만들고 있는 페이지 |
||
682 | /// </summary> |
||
683 | Create = 2, |
||
684 | |||
685 | /// <summary> |
||
686 | /// final pdf 완료시 |
||
687 | /// </summary> |
||
688 | Seccess = 99, |
||
689 | |||
690 | /// <summary> |
||
691 | /// 에러 |
||
692 | /// </summary> |
||
693 | Error = 88 |
||
694 | } |
||
695 | |||
696 | } |