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