hytos / ID2.Manager / MarkusImageCreate / Program.cs @ 2ade1e61
이력 | 보기 | 이력해설 | 다운로드 (18.8 KB)
1 | d1d8c5ea | taeseongkim | 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 | c7f3eb42 | taeseongkim | using Teigha.DatabaseServices; |
10 | using OdReadExMgd; |
||
11 | b0bfc1d3 | taeseongkim | using CredentialManagement; |
12 | 7842224c | taeseongkim | using Dapper; |
13 | d1d8c5ea | taeseongkim | |
14 | namespace MarkusImageCreate |
||
15 | { |
||
16 | 0d8516d2 | taeseongkim | public class Program |
17 | d1d8c5ea | taeseongkim | { |
18 | const string CONST_SETTINGS = "SETTINGS"; |
||
19 | const string CONST_ID2Manager_Connect = "ID2Manager"; |
||
20 | 13a36357 | humkyung | const string CONST_Markus_Connect = "MARKUS"; |
21 | d1d8c5ea | taeseongkim | const string CONST_ID2ProjectsPath = "ID2ProjectsPath"; |
22 | const string CONST_MarkusImagePath = "MarkusImagePath"; |
||
23 | const string CONST_Resolution = "Resolution"; |
||
24 | const string CONST_FontPath = "FontPath"; |
||
25 | 0d8516d2 | taeseongkim | const string CONST_IsOpenGL = "IsOpenGL"; |
26 | d1d8c5ea | taeseongkim | |
27 | static string MarkusConnectionStr; |
||
28 | static string ID2ConnectionStr; |
||
29 | static string ID2ProjectsPath; |
||
30 | static string MarkusImagePath; |
||
31 | static int Resolution; |
||
32 | static string FontPath; |
||
33 | 0d8516d2 | taeseongkim | static bool IsOpenGL = false; |
34 | d1d8c5ea | taeseongkim | |
35 | 0d8516d2 | taeseongkim | public static void Main(string[] args) |
36 | d1d8c5ea | taeseongkim | { |
37 | 0d8516d2 | taeseongkim | |
38 | c7f3eb42 | taeseongkim | bool bSuccess = true; |
39 | 0d8516d2 | taeseongkim | string cmd = "DEFAULT"; |
40 | |||
41 | if(args.Length > 0) |
||
42 | { |
||
43 | cmd = args[0]; |
||
44 | } |
||
45 | 429bc8fa | taeseongkim | |
46 | try |
||
47 | c7f3eb42 | taeseongkim | { |
48 | 0d8516d2 | taeseongkim | try |
49 | { |
||
50 | Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature); |
||
51 | } |
||
52 | catch (Exception ex) |
||
53 | { |
||
54 | Console.WriteLine(ex.ToString()); |
||
55 | |||
56 | } |
||
57 | |||
58 | Console.WriteLine("Activate Teigha"); |
||
59 | |||
60 | 429bc8fa | taeseongkim | using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services()) |
61 | c7f3eb42 | taeseongkim | { |
62 | /**********************************************************************/ |
||
63 | /* Display the Product and Version that created the executable */ |
||
64 | /**********************************************************************/ |
||
65 | Console.WriteLine("\nReadExMgd developed using {0} ver {1}", HostApplicationServices.Current.Product, HostApplicationServices.Current.VersionString); |
||
66 | |||
67 | 0d8516d2 | taeseongkim | Salaros.Configuration.ConfigParser config; |
68 | |||
69 | try |
||
70 | { |
||
71 | config = new Salaros.Configuration.ConfigParser(Path.Combine(AppContext.BaseDirectory, "MarkusImageCreate.ini")); |
||
72 | } |
||
73 | catch (Exception) |
||
74 | { |
||
75 | Console.WriteLine($"Config File Path Not Found : {Path.Combine(AppContext.BaseDirectory, "MarkusImageCreate.ini")}"); |
||
76 | Console.ReadKey(); |
||
77 | throw; |
||
78 | } |
||
79 | |||
80 | c7f3eb42 | taeseongkim | ID2ConnectionStr = config.GetValue(CONST_SETTINGS, CONST_ID2Manager_Connect); |
81 | MarkusConnectionStr = config.GetValue(CONST_SETTINGS, CONST_Markus_Connect); |
||
82 | //ID2ConnectionStr = Encoding.Unicode.GetString(Convert.FromBase64String(config.GetValue(CONST_SETTINGS, CONST_ID2Manager_Connect))); |
||
83 | //MarkusConnectionStr = Encoding.Unicode.GetString(Convert.FromBase64String(config.GetValue(CONST_SETTINGS, CONST_Markus_Connect))); |
||
84 | ID2ProjectsPath = config.GetValue(CONST_SETTINGS, CONST_ID2ProjectsPath); |
||
85 | MarkusImagePath = config.GetValue(CONST_SETTINGS, CONST_MarkusImagePath); |
||
86 | Resolution = config.GetValue(CONST_SETTINGS, CONST_Resolution, 250); |
||
87 | FontPath = config.GetValue(CONST_SETTINGS, CONST_FontPath); |
||
88 | 0d8516d2 | taeseongkim | IsOpenGL = config.GetValue(CONST_SETTINGS,CONST_IsOpenGL,false); |
89 | c7f3eb42 | taeseongkim | |
90 | b0bfc1d3 | taeseongkim | while (!Directory.Exists(ID2ProjectsPath)) |
91 | { |
||
92 | string sourceComputer = ID2ProjectsPath.Split('\\').FirstOrDefault(x => !string.IsNullOrEmpty(x)); |
||
93 | 0d8516d2 | taeseongkim | IsCredential($"\\\\{sourceComputer}에 대한 인증이 필요합니다.", sourceComputer); |
94 | 429bc8fa | taeseongkim | } |
95 | |||
96 | while (!Directory.Exists(MarkusImagePath)) |
||
97 | { |
||
98 | string sourceComputer = MarkusImagePath.Split('\\').FirstOrDefault(x => !string.IsNullOrEmpty(x)); |
||
99 | 0d8516d2 | taeseongkim | IsCredential($"\\\\{sourceComputer}에 대한 인증이 필요합니다.", sourceComputer); |
100 | b0bfc1d3 | taeseongkim | } |
101 | |||
102 | 0d8516d2 | taeseongkim | if (cmd == "DEFAULT") |
103 | { |
||
104 | InitConvertPDF(); |
||
105 | } |
||
106 | else if (cmd == "INPUT") |
||
107 | c7f3eb42 | taeseongkim | { |
108 | 0d8516d2 | taeseongkim | bool isBreak = false; |
109 | |||
110 | while (!isBreak) |
||
111 | 7842224c | taeseongkim | { |
112 | string ProjectCode = null; |
||
113 | string DocID = null; |
||
114 | |||
115 | Console.WriteLine("# 생성이 필요한 DWG ID 입력 #"); |
||
116 | 0d8516d2 | taeseongkim | |
117 | 7842224c | taeseongkim | Console.Write("Team Code : "); |
118 | ProjectCode = Console.ReadLine(); |
||
119 | |||
120 | Console.Write("DWG ID : "); |
||
121 | DocID = Console.ReadLine(); |
||
122 | |||
123 | ConvertDWG(ProjectCode, DocID); |
||
124 | |||
125 | 0d8516d2 | taeseongkim | Console.WriteLine("계속 진행은 아무키나 입력,종료는 CTRL+BREAK"); |
126 | Console.ReadKey(); |
||
127 | 7842224c | taeseongkim | } |
128 | 0d8516d2 | taeseongkim | } |
129 | else if (args[0] == "RUN") |
||
130 | { |
||
131 | if (args.Count() == 3) |
||
132 | c7f3eb42 | taeseongkim | { |
133 | 0d8516d2 | taeseongkim | string ProjectCode = args[1]; |
134 | string DocID = args[2]; |
||
135 | |||
136 | ConvertDWG(ProjectCode, DocID); |
||
137 | c7f3eb42 | taeseongkim | } |
138 | } |
||
139 | 0d8516d2 | taeseongkim | else if (args[0].Contains(".dwg")) |
140 | c7f3eb42 | taeseongkim | { |
141 | 0d8516d2 | taeseongkim | Show(args[0]); |
142 | c7f3eb42 | taeseongkim | } |
143 | } |
||
144 | } |
||
145 | 429bc8fa | taeseongkim | /********************************************************************/ |
146 | /* Display the error */ |
||
147 | /********************************************************************/ |
||
148 | catch (System.Exception e) |
||
149 | { |
||
150 | bSuccess = false; |
||
151 | Console.WriteLine("Teigha?NET for .dwg files Error: " + e.Message); |
||
152 | } |
||
153 | |||
154 | if (bSuccess) |
||
155 | Console.WriteLine("OdReadExMgd Finished Successfully"); |
||
156 | 0d8516d2 | taeseongkim | |
157 | if (cmd == "DEFAULT") |
||
158 | { |
||
159 | Console.WriteLine("완료"); |
||
160 | Console.ReadKey(); |
||
161 | } |
||
162 | d1d8c5ea | taeseongkim | } |
163 | |||
164 | static string[] ProjectCodes() |
||
165 | { |
||
166 | using (ProjectRepository rep = new ProjectRepository(ID2ConnectionStr)) |
||
167 | { |
||
168 | var projects = rep.GetAllProjectList(); |
||
169 | |||
170 | return projects.Select(x => x.Code).ToArray(); |
||
171 | } |
||
172 | } |
||
173 | |||
174 | c7f3eb42 | taeseongkim | static void Show(string dwgFile) |
175 | { |
||
176 | using (Database pDb = new Database(false, true)) |
||
177 | { |
||
178 | pDb.ReadDwgFile(dwgFile, FileShare.Read, true, ""); |
||
179 | HostApplicationServices.WorkingDatabase = pDb; |
||
180 | /****************************************************************/ |
||
181 | /* Display the File Version */ |
||
182 | /****************************************************************/ |
||
183 | Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion); |
||
184 | /****************************************************************/ |
||
185 | /* Dump the database */ |
||
186 | /****************************************************************/ |
||
187 | DbDumper dumper = new DbDumper(); |
||
188 | |||
189 | //dumper.prepareDump(pDb); |
||
190 | dumper.ExplodeAndPurgeNestedBlocks(pDb); |
||
191 | |||
192 | int width = 9600; |
||
193 | int height = 6787; |
||
194 | |||
195 | dumper.Show(pDb, width, height); |
||
196 | } |
||
197 | } |
||
198 | |||
199 | d1d8c5ea | taeseongkim | static void InitConvertPDF() |
200 | { |
||
201 | foreach (var code in ProjectCodes()) |
||
202 | { |
||
203 | 7842224c | taeseongkim | ConvertAllProject(code); |
204 | d1d8c5ea | taeseongkim | } |
205 | } |
||
206 | |||
207 | 429bc8fa | taeseongkim | static bool IsCredential(string Message, string path) |
208 | b0bfc1d3 | taeseongkim | { |
209 | bool result = false; |
||
210 | |||
211 | try |
||
212 | { |
||
213 | Credential credential = new Credential |
||
214 | { |
||
215 | Type = CredentialType.DomainPassword, |
||
216 | PersistanceType = PersistanceType.LocalComputer, |
||
217 | Target = path, |
||
218 | }; |
||
219 | |||
220 | 7842224c | taeseongkim | result = credential.Load(); |
221 | |||
222 | if (!result) |
||
223 | b0bfc1d3 | taeseongkim | { |
224 | VistaPrompt prompt = new VistaPrompt(); |
||
225 | 429bc8fa | taeseongkim | prompt.Title = $"{Message}"; |
226 | b0bfc1d3 | taeseongkim | |
227 | var dialogResult = prompt.ShowDialog(); |
||
228 | |||
229 | if (dialogResult == DialogResult.OK) |
||
230 | { |
||
231 | Credential genericCredential = new Credential |
||
232 | { |
||
233 | Target = path, |
||
234 | Username = prompt.Username, |
||
235 | Password = prompt.Password, |
||
236 | Type = CredentialType.DomainPassword, |
||
237 | PersistanceType = PersistanceType.LocalComputer |
||
238 | }; |
||
239 | |||
240 | genericCredential.Save(); |
||
241 | result = true; |
||
242 | } |
||
243 | } |
||
244 | } |
||
245 | catch (Exception ex) |
||
246 | { |
||
247 | Console.WriteLine(ex.ToString()); |
||
248 | } |
||
249 | |||
250 | return result; |
||
251 | } |
||
252 | |||
253 | 7842224c | taeseongkim | static void ConvertAllProject(string code) |
254 | d1d8c5ea | taeseongkim | { |
255 | c7f3eb42 | taeseongkim | string sourcePath = Path.Combine(Path.Combine(Path.Combine(ID2ProjectsPath, code), "drawings"),"Native"); |
256 | d1d8c5ea | taeseongkim | string targetPath = Path.Combine(MarkusImagePath, code); |
257 | |||
258 | c7f3eb42 | taeseongkim | if (!Directory.Exists(targetPath)) |
259 | d1d8c5ea | taeseongkim | Directory.CreateDirectory(targetPath); |
260 | |||
261 | using (MarkusRepository rep = new MarkusRepository(MarkusConnectionStr)) |
||
262 | { |
||
263 | var convertItems = rep.GetConvertDoc(0, code); |
||
264 | |||
265 | foreach (var item in convertItems) |
||
266 | { |
||
267 | 7459b663 | taeseongkim | string dwgFile = null; |
268 | |||
269 | d1d8c5ea | taeseongkim | try |
270 | { |
||
271 | c7f3eb42 | taeseongkim | var orgFile = Path.Combine(sourcePath, item.DOCUMENT_ID + ".dwg"); |
272 | 7459b663 | taeseongkim | dwgFile = System.IO.Path.GetTempFileName().Replace(".tmp",".dwg"); |
273 | d1d8c5ea | taeseongkim | |
274 | b0bfc1d3 | taeseongkim | |
275 | c7f3eb42 | taeseongkim | File.Copy(orgFile, dwgFile,true); |
276 | d1d8c5ea | taeseongkim | |
277 | c7f3eb42 | taeseongkim | using (Database pDb = new Database(false, true)) |
278 | { |
||
279 | pDb.ReadDwgFile(dwgFile, FileShare.Read, true, ""); |
||
280 | HostApplicationServices.WorkingDatabase = pDb; |
||
281 | /****************************************************************/ |
||
282 | /* Display the File Version */ |
||
283 | /****************************************************************/ |
||
284 | Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion); |
||
285 | /****************************************************************/ |
||
286 | /* Dump the database */ |
||
287 | /****************************************************************/ |
||
288 | DbDumper dumper = new DbDumper(); |
||
289 | |||
290 | //dumper.prepareDump(pDb); |
||
291 | dumper.ExplodeAndPurgeNestedBlocks(pDb); |
||
292 | 0d8516d2 | taeseongkim | |
293 | c7f3eb42 | taeseongkim | var pngFile = Path.Combine(targetPath, item.DOCUMENT_ID + ".png"); |
294 | |||
295 | int width = 9600; |
||
296 | int height = 6787; |
||
297 | |||
298 | 0d8516d2 | taeseongkim | if (dumper.ExportPNG(pDb, IsOpenGL, pngFile, width, height)) |
299 | d1d8c5ea | taeseongkim | { |
300 | c7f3eb42 | taeseongkim | File.Delete(dwgFile); |
301 | |||
302 | var docInfoID = rep.CreateDocInfo(item.ID, 1); |
||
303 | |||
304 | var docPageResult = rep.CreateDocPage(new[]{ |
||
305 | new DocPage { |
||
306 | docinfo_id = docInfoID, |
||
307 | page_angle = 0, |
||
308 | page_width = width.ToString(), |
||
309 | page_height = height.ToString(), |
||
310 | page_number = 1 |
||
311 | |||
312 | } }); |
||
313 | |||
314 | rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 4, 1, 1, null); |
||
315 | d1d8c5ea | taeseongkim | Console.WriteLine($"Ok. {item.DOCUMENT_ID}"); |
316 | } |
||
317 | c7f3eb42 | taeseongkim | else |
318 | { |
||
319 | rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 50, 1, 1, "DWG Convert Error"); |
||
320 | Console.WriteLine($"Error. {item.DOCUMENT_ID}"); |
||
321 | } |
||
322 | d1d8c5ea | taeseongkim | } |
323 | } |
||
324 | catch (Exception ex) |
||
325 | { |
||
326 | Console.WriteLine($"Error. {item.DOCUMENT_ID} {ex.ToString()}"); |
||
327 | c7f3eb42 | taeseongkim | rep.UpdateStatusAsync(item.SERVICE_ID, item.ID,50, 1, 1, ex.ToString()); |
328 | d1d8c5ea | taeseongkim | } |
329 | 7459b663 | taeseongkim | finally |
330 | { |
||
331 | if(dwgFile != null) |
||
332 | { |
||
333 | if(File.Exists(dwgFile)) |
||
334 | { |
||
335 | File.Delete(dwgFile); |
||
336 | } |
||
337 | } |
||
338 | } |
||
339 | d1d8c5ea | taeseongkim | } |
340 | } |
||
341 | } |
||
342 | 7842224c | taeseongkim | |
343 | 0d8516d2 | taeseongkim | public static bool ConvertDWG(string code, string DocID) |
344 | 7842224c | taeseongkim | { |
345 | bool result = false; |
||
346 | |||
347 | try |
||
348 | { |
||
349 | string sourcePath = Path.Combine(Path.Combine(Path.Combine(ID2ProjectsPath, code), "drawings"), "Native"); |
||
350 | string targetPath = Path.Combine(MarkusImagePath, code); |
||
351 | |||
352 | if (!Directory.Exists(targetPath)) |
||
353 | Directory.CreateDirectory(targetPath); |
||
354 | |||
355 | using (MarkusRepository rep = new MarkusRepository(MarkusConnectionStr)) |
||
356 | { |
||
357 | 0d8516d2 | taeseongkim | string SQL = "SELECT * FROM CONVERTER_DOC WHERE DOCUMENT_ID = @DOCUMENT_ID and PROJECT_NO = @PROJECT_NO"; |
358 | 7842224c | taeseongkim | |
359 | var parameters = new DynamicParameters(); |
||
360 | parameters.Add("@PROJECT_NO", code); |
||
361 | parameters.Add("@DOCUMENT_ID", DocID); |
||
362 | |||
363 | var convertItems = rep.Query<ConvertDoc>(SQL, parameters); |
||
364 | |||
365 | if (convertItems.Count() > 0) |
||
366 | { |
||
367 | 0d8516d2 | taeseongkim | var item = convertItems.First(); |
368 | |||
369 | result = false; |
||
370 | string dwgFile = null; |
||
371 | 7842224c | taeseongkim | |
372 | 0d8516d2 | taeseongkim | try |
373 | { |
||
374 | var orgFile = Path.Combine(sourcePath, item.DOCUMENT_ID + ".dwg"); |
||
375 | dwgFile = System.IO.Path.GetTempFileName().Replace(".tmp", ".dwg"); |
||
376 | 7842224c | taeseongkim | |
377 | |||
378 | 0d8516d2 | taeseongkim | File.Copy(orgFile, dwgFile, true); |
379 | 7842224c | taeseongkim | |
380 | 0d8516d2 | taeseongkim | using (Database pDb = new Database(false, true)) |
381 | { |
||
382 | pDb.ReadDwgFile(dwgFile, FileShare.Read, true, ""); |
||
383 | HostApplicationServices.WorkingDatabase = pDb; |
||
384 | /****************************************************************/ |
||
385 | /* Display the File Version */ |
||
386 | /****************************************************************/ |
||
387 | Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion); |
||
388 | /****************************************************************/ |
||
389 | /* Dump the database */ |
||
390 | /****************************************************************/ |
||
391 | DbDumper dumper = new DbDumper(); |
||
392 | |||
393 | //dumper.prepareDump(pDb); |
||
394 | dumper.ExplodeAndPurgeNestedBlocks(pDb); |
||
395 | |||
396 | var pngFile = Path.Combine(targetPath, item.DOCUMENT_ID + ".png"); |
||
397 | |||
398 | int width = 9600; |
||
399 | int height = 6787; |
||
400 | |||
401 | if (dumper.ExportPNG(pDb,IsOpenGL, pngFile, width, height)) |
||
402 | 7842224c | taeseongkim | { |
403 | 0d8516d2 | taeseongkim | File.Delete(dwgFile); |
404 | 7842224c | taeseongkim | |
405 | 0d8516d2 | taeseongkim | var docInfoID = rep.CreateDocInfo(item.ID, 1); |
406 | 7842224c | taeseongkim | |
407 | 0d8516d2 | taeseongkim | var docPageResult = rep.CreateDocPage(new[]{ |
408 | new DocPage { |
||
409 | docinfo_id = docInfoID, |
||
410 | page_angle = 0, |
||
411 | page_width = width.ToString(), |
||
412 | page_height = height.ToString(), |
||
413 | page_number = 1 |
||
414 | 7842224c | taeseongkim | |
415 | 0d8516d2 | taeseongkim | } }); |
416 | 7842224c | taeseongkim | |
417 | 0d8516d2 | taeseongkim | rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 4, 1, 1, null); |
418 | Console.WriteLine($"Ok. {item.DOCUMENT_ID}"); |
||
419 | result = true; |
||
420 | } |
||
421 | else |
||
422 | { |
||
423 | rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 50, 1, 1, "DWG Convert Error"); |
||
424 | Console.WriteLine($"Error. {item.DOCUMENT_ID}"); |
||
425 | 7842224c | taeseongkim | } |
426 | } |
||
427 | 0d8516d2 | taeseongkim | } |
428 | catch (Exception ex) |
||
429 | { |
||
430 | Console.WriteLine($"Error. {item.DOCUMENT_ID} {ex.ToString()}"); |
||
431 | rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 50, 1, 1, ex.ToString()); |
||
432 | } |
||
433 | finally |
||
434 | { |
||
435 | if (dwgFile != null) |
||
436 | 7842224c | taeseongkim | { |
437 | 0d8516d2 | taeseongkim | if (File.Exists(dwgFile)) |
438 | 7842224c | taeseongkim | { |
439 | 0d8516d2 | taeseongkim | File.Delete(dwgFile); |
440 | 7842224c | taeseongkim | } |
441 | } |
||
442 | } |
||
443 | } |
||
444 | } |
||
445 | } |
||
446 | catch (Exception ex) |
||
447 | { |
||
448 | Console.WriteLine("Error" + ex.ToString()); |
||
449 | } |
||
450 | |||
451 | return result; |
||
452 | } |
||
453 | d1d8c5ea | taeseongkim | } |
454 | } |