개정판 950e6b84
issue #00000 convert service
- markus library 수정 후 적용
- pdf download를 plugin으로 변경
- convert 안정화
Change-Id: Ibafcf7fb59445659f8361922f80d47e3e6610a65
ConvertService/ServiceBase/Markus.Service.Convert/ConvertService.cs | ||
---|---|---|
27 | 27 |
private string gTempFileName; |
28 | 28 |
private Markus.SaveTask gSaveTask; |
29 | 29 |
private Markus.MarkusPDF gMarkusPDF; |
30 |
private string gFontsFolder; |
|
31 |
private bool gIsApiDownload; |
|
30 | 32 | |
31 | 33 |
// 컨버터 완료시 파일갯수를 체크 하여 틀리면 reconvert를 1로 하고 다시 컨버팅 하도록 한다. |
32 | 34 |
private int ReConvert; |
... | ... | |
47 | 49 |
BasicHttpBinding myBinding = new BasicHttpBinding(); |
48 | 50 |
EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate(ConvertProcessContext.ServiceStationUri)); |
49 | 51 |
StationServiceClient = new StationServiceClient(myBinding, myEndpoint); |
50 |
|
|
51 |
gMarkusPDF = new MarkusPDF(); |
|
52 |
gIsApiDownload = ConvertProcessContext.IsApiDownload; |
|
53 | ||
54 |
gMarkusPDF = new MarkusPDF(); |
|
55 |
|
|
52 | 56 |
gSaveTask = new SaveTask(); |
57 | ||
58 |
if (!string.IsNullOrWhiteSpace(ConvertProcessContext.FontsFolder)) |
|
59 |
{ |
|
60 |
gFontsFolder = ConvertProcessContext.FontsFolder; |
|
61 |
gSaveTask.SetFontsFolder(ConvertProcessContext.FontsFolder); |
|
62 |
} |
|
63 | ||
53 | 64 |
gSaveTask.StateChangeEvent += MarkusPdfStateChangeEvent; |
54 | 65 |
} |
55 | 66 | |
... | ... | |
123 | 134 |
break; |
124 | 135 |
case StatusCodeType.PageError: |
125 | 136 |
break; |
137 |
case StatusCodeType.FontNotFound: |
|
138 |
break; |
|
126 | 139 |
case StatusCodeType.NeedsPassword: |
127 | 140 |
break; |
128 | 141 |
case StatusCodeType.Error: |
... | ... | |
157 | 170 | |
158 | 171 |
try |
159 | 172 |
{ |
160 |
StationServiceClient.ConvertProcessState(ConvertProcessContext.ConvertID, (int)StatusCodeType.Wait, 0, 0, ""); |
|
173 |
#if PROCESS_TEST |
|
174 | ||
175 |
Console.WriteLine($"ConvertID : {ConvertProcessContext.ConvertID} : {StatusCodeType.Wait.ToString()}"); |
|
161 | 176 | |
177 |
#else |
|
178 |
StationServiceClient.ConvertProcessState(ConvertProcessContext.ConvertID, (int)StatusCodeType.Wait, 0, 0, ""); |
|
179 |
#endif |
|
162 | 180 |
result = await ConvertAsync(saveitem); |
181 |
#if PROCESS_TEST |
|
182 | ||
183 |
Console.WriteLine($"finish!!!"); |
|
184 |
#else |
|
185 |
StationServiceClient.ConvertFinish(saveitem.Id, (int)result.StatusCode, saveitem.CurrentPage, saveitem.TotalPages, result.Message); |
|
163 | 186 | |
187 |
#endif |
|
164 | 188 |
// 플러그인 실행 |
165 |
PluginService.Run(saveitem.Id);
|
|
189 |
#if PROCESS_TEST
|
|
166 | 190 | |
167 |
this.Dispose(); |
|
191 |
Console.WriteLine($"run Plugin : {saveitem.Id}"); |
|
192 |
#endif |
|
193 |
PluginService.Run(saveitem.Id); |
|
168 | 194 | |
169 |
StationServiceClient.ConvertFinish(saveitem.Id, (int)result.StatusCode, saveitem.CurrentPage, saveitem.TotalPages,result.Message); |
|
170 | 195 |
} |
171 | 196 |
catch (Exception ex) |
172 | 197 |
{ |
173 | 198 |
result.StatusCode = StatusCodeType.Error; |
174 |
logger.Error($"File Convert Error",ex); |
|
199 |
logger.Error($"File Convert Error", ex); |
|
200 | ||
201 |
#if PROCESS_TEST |
|
202 | ||
203 |
Console.WriteLine($"run Plugin : {saveitem.Id}"); |
|
204 |
#else |
|
175 | 205 |
StationServiceClient.ConvertFinish(saveitem.Id, (int)result.StatusCode, saveitem.CurrentPage, saveitem.TotalPages, $"ConvertService Error {saveitem.Id} {ex.Message} {ex.InnerException?.ToString()}"); |
206 |
#endif |
|
207 |
} |
|
208 |
finally |
|
209 |
{ |
|
210 |
this.Dispose(); |
|
176 | 211 |
} |
177 | 212 | |
178 | 213 |
return result; |
... | ... | |
193 | 228 |
{ |
194 | 229 |
System.IO.Directory.Delete(saveitem.SavePath, true); |
195 | 230 |
} |
196 |
catch (Exception) |
|
231 |
catch (Exception ex)
|
|
197 | 232 |
{ |
198 | ||
233 |
#if PROCESS_TEST |
|
234 |
Console.WriteLine(ex.ToString()); |
|
235 |
#endif |
|
199 | 236 |
} |
200 | 237 | |
201 | 238 |
if ((DateTime.Now - deleteTime) > new TimeSpan(0, 5, 0)) |
... | ... | |
204 | 241 |
logger.Error(msg); |
205 | 242 |
result.StatusCode = StatusCodeType.FileError; |
206 | 243 |
result.Message = LogHelper.GetStack() + " " +LogHelper.GetStack() + " " + msg; |
207 | ||
244 |
#if PROCESS_TEST |
|
245 |
Console.WriteLine($"{StatusCodeType.FileError.ToString()} : {result.Message} "); |
|
246 |
#endif |
|
208 | 247 |
return result; |
209 | 248 |
} |
210 | 249 | |
... | ... | |
227 | 266 |
System.Threading.Thread.Sleep(100); |
228 | 267 |
} |
229 | 268 | |
230 |
gMarkusPDF.pdfLoad(gTempFileName, saveitem.MinimumFontSize, saveitem.UseResolution); |
|
269 |
gMarkusPDF.pdfLoad(gTempFileName, saveitem.MinimumFontSize, saveitem.UseResolution, gFontsFolder);
|
|
231 | 270 | |
232 | 271 |
if(gMarkusPDF.PageCount() > 0) |
233 | 272 |
{ |
... | ... | |
380 | 419 |
{ |
381 | 420 |
try |
382 | 421 |
{ |
383 |
|
|
384 |
downloadFilePath = await RestDownloadAsync(pdfFileUri, saveItem.SavePath); |
|
385 |
/*bseng |
|
386 |
*/ |
|
387 |
/* 벽산으로 임시 주석 |
|
388 |
|
|
389 |
FileName = DownloadUri.GetFileName(saveItem.PdfFilePath); |
|
390 |
downloadFilePath = System.IO.Path.Combine(saveItem.SavePath, FileName); |
|
422 |
if (gIsApiDownload) |
|
423 |
{ |
|
424 |
///read api download |
|
425 |
///벽산 |
|
426 |
downloadFilePath = await RestDownloadAsync(pdfFileUri, saveItem.SavePath); |
|
427 |
} |
|
428 |
else |
|
429 |
{ |
|
430 |
FileName = DownloadUri.GetFileName(saveItem.PdfFilePath); |
|
431 |
downloadFilePath = System.IO.Path.Combine(saveItem.SavePath, FileName); |
|
391 | 432 | |
392 |
using (System.Net.WebClient webClient = new System.Net.WebClient()) |
|
393 |
{ |
|
394 |
webClient.UseDefaultCredentials = true;//.Headers.Add("Authorization: BASIC SGVsbG8="); //가상의 인증 |
|
395 |
webClient.Proxy = null; |
|
396 |
if (!System.IO.Directory.Exists(ConvertProcessContext.TempDirectory)) |
|
397 |
{ |
|
398 |
System.IO.Directory.CreateDirectory(ConvertProcessContext.TempDirectory); |
|
399 |
} |
|
400 | ||
401 |
webClient.DownloadFile(pdfFileUri, downloadFilePath); |
|
402 | ||
403 |
webClient.Dispose(); |
|
404 |
} |
|
405 |
* */ |
|
433 |
using (System.Net.WebClient webClient = new System.Net.WebClient()) |
|
434 |
{ |
|
435 |
webClient.UseDefaultCredentials = true; |
|
436 |
webClient.Headers.Add("Authorization: BASIC SGVsbG8="); //가상의 인증 |
|
437 |
webClient.Proxy = null; |
|
438 |
if (!System.IO.Directory.Exists(ConvertProcessContext.TempDirectory)) |
|
439 |
{ |
|
440 |
System.IO.Directory.CreateDirectory(ConvertProcessContext.TempDirectory); |
|
441 |
} |
|
442 | ||
443 |
webClient.DownloadFile(pdfFileUri, downloadFilePath); |
|
444 | ||
445 |
webClient.Dispose(); |
|
446 |
} |
|
447 |
} |
|
406 | 448 |
await Task.Delay(300); |
407 | 449 |
} |
408 | 450 |
catch (Exception ex) |
... | ... | |
470 | 512 |
await fs.WriteAsync(response.RawBytes, 0, response.RawBytes.Length); |
471 | 513 |
fs.Close(); |
472 | 514 |
} |
473 |
|
|
474 |
//var fileInfo = new FileInfo(downloadFilePath); |
|
475 | ||
476 |
//using (var fileStream = fileInfo.OpenWrite()) |
|
477 |
//{ |
|
478 |
// await fileStream.WriteAsync(response.RawBytes, 0, response.RawBytes.Length); |
|
479 |
// fileStream.Close(); |
|
480 |
// //int position = 0; |
|
481 |
// //int step = 300000; |
|
482 |
// //int length = 300000; |
|
483 | ||
484 |
// //while (position < response.RawBytes.Length) |
|
485 |
// //{ |
|
486 |
// // if (position + step < response.RawBytes.Length) |
|
487 |
// // { |
|
488 |
// // length = position + step; |
|
489 |
// // } |
|
490 |
// // else |
|
491 |
// // { |
|
492 |
// // length = response.RawBytes.Length - position; |
|
493 |
// // } |
|
494 | ||
495 |
// // await fileStream.WriteAsync(response.RawBytes, position, length); |
|
496 | ||
497 |
// // position = position + step; |
|
498 |
// //} |
|
499 |
//} |
|
500 | 515 | |
501 | 516 |
return downloadFilePath; |
502 | 517 |
} |
... | ... | |
555 | 570 |
System.Threading.Thread.SpinWait(5); |
556 | 571 | |
557 | 572 |
gMarkusPDF = new MarkusPDF(); |
558 |
gMarkusPDF.pdfLoad(gTempFileName, saveitem.MinimumFontSize, saveitem.UseResolution); |
|
573 |
gMarkusPDF.pdfLoad(gTempFileName, saveitem.MinimumFontSize, saveitem.UseResolution, gFontsFolder);
|
|
559 | 574 |
} |
560 | 575 | |
561 | 576 |
System.Threading.Thread.SpinWait(2); |
... | ... | |
573 | 588 |
} |
574 | 589 | |
575 | 590 |
gMarkusPDF = new MarkusPDF(); |
576 |
gMarkusPDF.pdfLoad(gTempFileName, saveitem.MinimumFontSize, saveitem.UseResolution); |
|
591 |
gMarkusPDF.pdfLoad(gTempFileName, saveitem.MinimumFontSize, saveitem.UseResolution, gFontsFolder);
|
|
577 | 592 | |
578 | 593 |
currentPageNo = currentPageNo - 1; |
579 | 594 |
} |
내보내기 Unified diff