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