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