개정판 c7f3eb42
issue #00000 markus image Create 수정
Change-Id: I9fc9beeea867be787be7c425e905b6fdfeadfbba
ID2.Manager/MarkusImageCreate/Program.cs | ||
---|---|---|
6 | 6 |
using System.Threading.Tasks; |
7 | 7 |
using System.IO; |
8 | 8 |
using ID2.Manager.Dapper.Entities; |
9 |
using Teigha.DatabaseServices; |
|
10 |
using OdReadExMgd; |
|
9 | 11 |
|
10 | 12 |
namespace MarkusImageCreate |
11 | 13 |
{ |
... | ... | |
29 | 31 |
|
30 | 32 |
static void Main(string[] args) |
31 | 33 |
{ |
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(); |
|
34 |
bool bSuccess = true; |
|
35 |
Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature); |
|
36 |
using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services()) |
|
37 |
{ |
|
38 |
try |
|
39 |
{ |
|
40 |
HostApplicationServices.Current = new OdaMgdMViewApp.HostAppServ(); |
|
41 |
/**********************************************************************/ |
|
42 |
/* Display the Product and Version that created the executable */ |
|
43 |
/**********************************************************************/ |
|
44 |
Console.WriteLine("\nReadExMgd developed using {0} ver {1}", HostApplicationServices.Current.Product, HostApplicationServices.Current.VersionString); |
|
45 |
|
|
46 |
Salaros.Configuration.ConfigParser config = new Salaros.Configuration.ConfigParser(Path.Combine(AppContext.BaseDirectory, "MarkusImageCreate.ini")); |
|
47 |
ID2ConnectionStr = config.GetValue(CONST_SETTINGS, CONST_ID2Manager_Connect); |
|
48 |
MarkusConnectionStr = config.GetValue(CONST_SETTINGS, CONST_Markus_Connect); |
|
49 |
//ID2ConnectionStr = Encoding.Unicode.GetString(Convert.FromBase64String(config.GetValue(CONST_SETTINGS, CONST_ID2Manager_Connect))); |
|
50 |
//MarkusConnectionStr = Encoding.Unicode.GetString(Convert.FromBase64String(config.GetValue(CONST_SETTINGS, CONST_Markus_Connect))); |
|
51 |
ID2ProjectsPath = config.GetValue(CONST_SETTINGS, CONST_ID2ProjectsPath); |
|
52 |
MarkusImagePath = config.GetValue(CONST_SETTINGS, CONST_MarkusImagePath); |
|
53 |
Resolution = config.GetValue(CONST_SETTINGS, CONST_Resolution, 250); |
|
54 |
FontPath = config.GetValue(CONST_SETTINGS, CONST_FontPath); |
|
55 |
|
|
56 |
if (args.Length > 0) |
|
57 |
{ |
|
58 |
if (args[0].Contains(".dwg")) |
|
59 |
{ |
|
60 |
Show(args[0]); |
|
61 |
} |
|
62 |
} |
|
63 |
else |
|
64 |
{ |
|
65 |
InitConvertPDF(); |
|
66 |
} |
|
67 |
} |
|
68 |
/********************************************************************/ |
|
69 |
/* Display the error */ |
|
70 |
/********************************************************************/ |
|
71 |
catch (System.Exception e) |
|
72 |
{ |
|
73 |
bSuccess = false; |
|
74 |
Console.WriteLine("Teigha?NET for .dwg files Error: " + e.Message); |
|
75 |
} |
|
44 | 76 |
|
77 |
if (bSuccess) |
|
78 |
Console.WriteLine("OdReadExMgd Finished Successfully"); |
|
79 |
} |
|
45 | 80 |
Console.WriteLine("완료"); |
46 | 81 |
Console.ReadKey(); |
47 | 82 |
} |
... | ... | |
56 | 91 |
} |
57 | 92 |
} |
58 | 93 |
|
94 |
static void Show(string dwgFile) |
|
95 |
{ |
|
96 |
using (Database pDb = new Database(false, true)) |
|
97 |
{ |
|
98 |
pDb.ReadDwgFile(dwgFile, FileShare.Read, true, ""); |
|
99 |
HostApplicationServices.WorkingDatabase = pDb; |
|
100 |
/****************************************************************/ |
|
101 |
/* Display the File Version */ |
|
102 |
/****************************************************************/ |
|
103 |
Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion); |
|
104 |
/****************************************************************/ |
|
105 |
/* Dump the database */ |
|
106 |
/****************************************************************/ |
|
107 |
DbDumper dumper = new DbDumper(); |
|
108 |
|
|
109 |
//dumper.prepareDump(pDb); |
|
110 |
dumper.ExplodeAndPurgeNestedBlocks(pDb); |
|
111 |
|
|
112 |
int width = 9600; |
|
113 |
int height = 6787; |
|
114 |
|
|
115 |
dumper.Show(pDb, width, height); |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
59 | 119 |
static void InitConvertPDF() |
60 | 120 |
{ |
61 | 121 |
foreach (var code in ProjectCodes()) |
62 | 122 |
{ |
63 |
ConvertPDF(code);
|
|
123 |
ConvertDWG(code);
|
|
64 | 124 |
} |
65 | 125 |
} |
66 | 126 |
|
67 |
static void ConvertPDF(string code)
|
|
127 |
static void ConvertDWG(string code)
|
|
68 | 128 |
{ |
69 |
string sourcePath = Path.Combine(Path.Combine(ID2ProjectsPath, code), "drawings");
|
|
129 |
string sourcePath = Path.Combine(Path.Combine(Path.Combine(ID2ProjectsPath, code), "drawings"),"Native");
|
|
70 | 130 |
string targetPath = Path.Combine(MarkusImagePath, code); |
71 | 131 |
|
72 |
if(!Directory.Exists(targetPath)) |
|
132 |
if (!Directory.Exists(targetPath))
|
|
73 | 133 |
Directory.CreateDirectory(targetPath); |
74 | 134 |
|
75 | 135 |
using (MarkusRepository rep = new MarkusRepository(MarkusConnectionStr)) |
... | ... | |
80 | 140 |
{ |
81 | 141 |
try |
82 | 142 |
{ |
83 |
var pdfFile = Path.Combine(sourcePath, item.DOCUMENT_URL); |
|
143 |
var orgFile = Path.Combine(sourcePath, item.DOCUMENT_ID + ".dwg"); |
|
144 |
var dwgFile = Path.Combine(targetPath, item.DOCUMENT_ID + ".dwg"); |
|
84 | 145 |
|
85 |
using (Markus.MarkusPDF markusPDF = new Markus.MarkusPDF()) |
|
86 |
{ |
|
87 |
markusPDF.pdfLoad(pdfFile, -1, Resolution, FontPath); |
|
146 |
File.Copy(orgFile, dwgFile,true); |
|
88 | 147 |
|
89 |
if (markusPDF.PageCount() > 0) |
|
148 |
using (Database pDb = new Database(false, true)) |
|
149 |
{ |
|
150 |
pDb.ReadDwgFile(dwgFile, FileShare.Read, true, ""); |
|
151 |
HostApplicationServices.WorkingDatabase = pDb; |
|
152 |
/****************************************************************/ |
|
153 |
/* Display the File Version */ |
|
154 |
/****************************************************************/ |
|
155 |
Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion); |
|
156 |
/****************************************************************/ |
|
157 |
/* Dump the database */ |
|
158 |
/****************************************************************/ |
|
159 |
DbDumper dumper = new DbDumper(); |
|
160 |
|
|
161 |
//dumper.prepareDump(pDb); |
|
162 |
dumper.ExplodeAndPurgeNestedBlocks(pDb); |
|
163 |
|
|
164 |
var pngFile = Path.Combine(targetPath, item.DOCUMENT_ID + ".png"); |
|
165 |
|
|
166 |
int width = 9600; |
|
167 |
int height = 6787; |
|
168 |
|
|
169 |
if (dumper.ExportPNG(pDb, pngFile, width, height)) |
|
90 | 170 |
{ |
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); |
|
171 |
File.Delete(dwgFile); |
|
172 |
|
|
173 |
var docInfoID = rep.CreateDocInfo(item.ID, 1); |
|
174 |
|
|
175 |
var docPageResult = rep.CreateDocPage(new[]{ |
|
176 |
new DocPage { |
|
177 |
docinfo_id = docInfoID, |
|
178 |
page_angle = 0, |
|
179 |
page_width = width.ToString(), |
|
180 |
page_height = height.ToString(), |
|
181 |
page_number = 1 |
|
182 |
|
|
183 |
} }); |
|
184 |
|
|
185 |
rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 4, 1, 1, null); |
|
109 | 186 |
Console.WriteLine($"Ok. {item.DOCUMENT_ID}"); |
110 | 187 |
} |
188 |
else |
|
189 |
{ |
|
190 |
rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 50, 1, 1, "DWG Convert Error"); |
|
191 |
Console.WriteLine($"Error. {item.DOCUMENT_ID}"); |
|
192 |
} |
|
111 | 193 |
} |
112 | 194 |
} |
113 | 195 |
catch (Exception ex) |
114 | 196 |
{ |
115 | 197 |
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());
|
|
198 |
rep.UpdateStatusAsync(item.SERVICE_ID, item.ID,50, 1, 1, ex.ToString());
|
|
117 | 199 |
} |
118 | 200 |
} |
119 | 201 |
} |
내보내기 Unified diff