hytos / ID2.Manager / MarkusImageCreate / Program.cs @ 8eca8767
이력 | 보기 | 이력해설 | 다운로드 (5.03 KB)
1 |
using ID2.Manager.Dapper.Repository; |
---|---|
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.Linq; |
5 |
using System.Text; |
6 |
using System.Threading.Tasks; |
7 |
using System.IO; |
8 |
using ID2.Manager.Dapper.Entities; |
9 |
|
10 |
namespace MarkusImageCreate |
11 |
{ |
12 |
class Program |
13 |
{ |
14 |
const string CONST_SETTINGS = "SETTINGS"; |
15 |
const string CONST_ID2Manager_Connect = "ID2Manager"; |
16 |
const string CONST_Markus_Connect = "Markus"; |
17 |
const string CONST_ID2ProjectsPath = "ID2ProjectsPath"; |
18 |
const string CONST_MarkusImagePath = "MarkusImagePath"; |
19 |
const string CONST_Resolution = "Resolution"; |
20 |
const string CONST_FontPath = "FontPath"; |
21 |
|
22 |
|
23 |
static string MarkusConnectionStr; |
24 |
static string ID2ConnectionStr; |
25 |
static string ID2ProjectsPath; |
26 |
static string MarkusImagePath; |
27 |
static int Resolution; |
28 |
static string FontPath; |
29 |
|
30 |
static void Main(string[] args) |
31 |
{ |
32 |
|
33 |
Salaros.Configuration.ConfigParser config = new Salaros.Configuration.ConfigParser(Path.Combine(AppContext.BaseDirectory,"MarkusImageCreate.ini")); |
34 |
ID2ConnectionStr = config.GetValue(CONST_SETTINGS, CONST_ID2Manager_Connect); |
35 |
MarkusConnectionStr = config.GetValue(CONST_SETTINGS, CONST_Markus_Connect); |
36 |
//ID2ConnectionStr = Encoding.Unicode.GetString(Convert.FromBase64String(config.GetValue(CONST_SETTINGS, CONST_ID2Manager_Connect))); |
37 |
//MarkusConnectionStr = Encoding.Unicode.GetString(Convert.FromBase64String(config.GetValue(CONST_SETTINGS, CONST_Markus_Connect))); |
38 |
ID2ProjectsPath = config.GetValue(CONST_SETTINGS, CONST_ID2ProjectsPath); |
39 |
MarkusImagePath = config.GetValue(CONST_SETTINGS, CONST_MarkusImagePath); |
40 |
Resolution = config.GetValue(CONST_SETTINGS, CONST_Resolution,250); |
41 |
FontPath = config.GetValue(CONST_SETTINGS, CONST_FontPath); |
42 |
|
43 |
InitConvertPDF(); |
44 |
|
45 |
Console.WriteLine("완료"); |
46 |
Console.ReadKey(); |
47 |
} |
48 |
|
49 |
static string[] ProjectCodes() |
50 |
{ |
51 |
using (ProjectRepository rep = new ProjectRepository(ID2ConnectionStr)) |
52 |
{ |
53 |
var projects = rep.GetAllProjectList(); |
54 |
|
55 |
return projects.Select(x => x.Code).ToArray(); |
56 |
} |
57 |
} |
58 |
|
59 |
static void InitConvertPDF() |
60 |
{ |
61 |
foreach (var code in ProjectCodes()) |
62 |
{ |
63 |
ConvertPDF(code); |
64 |
} |
65 |
} |
66 |
|
67 |
static void ConvertPDF(string code) |
68 |
{ |
69 |
string sourcePath = Path.Combine(Path.Combine(ID2ProjectsPath, code), "drawings"); |
70 |
string targetPath = Path.Combine(MarkusImagePath, code); |
71 |
|
72 |
if(!Directory.Exists(targetPath)) |
73 |
Directory.CreateDirectory(targetPath); |
74 |
|
75 |
using (MarkusRepository rep = new MarkusRepository(MarkusConnectionStr)) |
76 |
{ |
77 |
var convertItems = rep.GetConvertDoc(0, code); |
78 |
|
79 |
foreach (var item in convertItems) |
80 |
{ |
81 |
try |
82 |
{ |
83 |
var pdfFile = Path.Combine(sourcePath, item.DOCUMENT_URL); |
84 |
|
85 |
using (Markus.MarkusPDF markusPDF = new Markus.MarkusPDF()) |
86 |
{ |
87 |
markusPDF.pdfLoad(pdfFile, -1, Resolution, FontPath); |
88 |
|
89 |
if (markusPDF.PageCount() > 0) |
90 |
{ |
91 |
var saveFileName = Path.Combine(targetPath, item.DOCUMENT_ID + ".png"); |
92 |
var result = markusPDF.SavePage(1, saveFileName); |
93 |
|
94 |
if (result.StatusCode == Markus.Message.StatusCodeType.Completed) |
95 |
{ |
96 |
var docInfoID = rep.CreateDocInfo(item.ID, 1); |
97 |
|
98 |
var docPageResult = rep.CreateDocPage(new[]{ |
99 |
new DocPage { |
100 |
docinfo_id = docInfoID, |
101 |
page_angle = 0, |
102 |
page_width = result.SavePageInfo.Width.ToString(), |
103 |
page_height = result.SavePageInfo.Height.ToString(), |
104 |
page_number = 1 |
105 |
} }); |
106 |
} |
107 |
|
108 |
rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, (int)result.StatusCode, 1, 1, result.Message); |
109 |
Console.WriteLine($"Ok. {item.DOCUMENT_ID}"); |
110 |
} |
111 |
} |
112 |
} |
113 |
catch (Exception ex) |
114 |
{ |
115 |
Console.WriteLine($"Error. {item.DOCUMENT_ID} {ex.ToString()}"); |
116 |
rep.UpdateStatusAsync(item.SERVICE_ID, item.ID,(int)Markus.Message.StatusCodeType.Error, 1, 1, ex.ToString()); |
117 |
} |
118 |
} |
119 |
} |
120 |
} |
121 |
} |
122 |
} |