13 |
13 |
|
14 |
14 |
namespace MarkusImageCreate
|
15 |
15 |
{
|
16 |
|
class Program
|
|
16 |
public class Program
|
17 |
17 |
{
|
18 |
18 |
const string CONST_SETTINGS = "SETTINGS";
|
19 |
19 |
const string CONST_ID2Manager_Connect = "ID2Manager";
|
... | ... | |
22 |
22 |
const string CONST_MarkusImagePath = "MarkusImagePath";
|
23 |
23 |
const string CONST_Resolution = "Resolution";
|
24 |
24 |
const string CONST_FontPath = "FontPath";
|
25 |
|
|
|
25 |
const string CONST_IsOpenGL = "IsOpenGL";
|
26 |
26 |
|
27 |
27 |
static string MarkusConnectionStr;
|
28 |
28 |
static string ID2ConnectionStr;
|
... | ... | |
30 |
30 |
static string MarkusImagePath;
|
31 |
31 |
static int Resolution;
|
32 |
32 |
static string FontPath;
|
|
33 |
static bool IsOpenGL = false;
|
33 |
34 |
|
34 |
|
static void Main(string[] args)
|
|
35 |
public static void Main(string[] args)
|
35 |
36 |
{
|
|
37 |
|
36 |
38 |
bool bSuccess = true;
|
|
39 |
string cmd = "DEFAULT";
|
|
40 |
|
|
41 |
if(args.Length > 0)
|
|
42 |
{
|
|
43 |
cmd = args[0];
|
|
44 |
}
|
37 |
45 |
|
38 |
46 |
try
|
39 |
47 |
{
|
40 |
|
Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature);
|
|
48 |
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 |
|
41 |
60 |
using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services())
|
42 |
61 |
{
|
43 |
|
HostApplicationServices.Current = new OdaMgdMViewApp.HostAppServ();
|
44 |
62 |
/**********************************************************************/
|
45 |
63 |
/* Display the Product and Version that created the executable */
|
46 |
64 |
/**********************************************************************/
|
47 |
65 |
Console.WriteLine("\nReadExMgd developed using {0} ver {1}", HostApplicationServices.Current.Product, HostApplicationServices.Current.VersionString);
|
48 |
66 |
|
49 |
|
Salaros.Configuration.ConfigParser config = new Salaros.Configuration.ConfigParser(Path.Combine(AppContext.BaseDirectory, "MarkusImageCreate.ini"));
|
|
67 |
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 |
|
50 |
80 |
ID2ConnectionStr = config.GetValue(CONST_SETTINGS, CONST_ID2Manager_Connect);
|
51 |
81 |
MarkusConnectionStr = config.GetValue(CONST_SETTINGS, CONST_Markus_Connect);
|
52 |
82 |
//ID2ConnectionStr = Encoding.Unicode.GetString(Convert.FromBase64String(config.GetValue(CONST_SETTINGS, CONST_ID2Manager_Connect)));
|
... | ... | |
55 |
85 |
MarkusImagePath = config.GetValue(CONST_SETTINGS, CONST_MarkusImagePath);
|
56 |
86 |
Resolution = config.GetValue(CONST_SETTINGS, CONST_Resolution, 250);
|
57 |
87 |
FontPath = config.GetValue(CONST_SETTINGS, CONST_FontPath);
|
|
88 |
IsOpenGL = config.GetValue(CONST_SETTINGS,CONST_IsOpenGL,false);
|
58 |
89 |
|
59 |
90 |
while (!Directory.Exists(ID2ProjectsPath))
|
60 |
91 |
{
|
61 |
92 |
string sourceComputer = ID2ProjectsPath.Split('\\').FirstOrDefault(x => !string.IsNullOrEmpty(x));
|
62 |
|
IsCredential($"\\\\{sourceComputer}에 대한 인증이 필요합니다.",sourceComputer);
|
|
93 |
IsCredential($"\\\\{sourceComputer}에 대한 인증이 필요합니다.", sourceComputer);
|
63 |
94 |
}
|
64 |
95 |
|
65 |
96 |
while (!Directory.Exists(MarkusImagePath))
|
66 |
97 |
{
|
67 |
98 |
string sourceComputer = MarkusImagePath.Split('\\').FirstOrDefault(x => !string.IsNullOrEmpty(x));
|
68 |
|
IsCredential($"\\\\{sourceComputer}에 대한 인증이 필요합니다.",sourceComputer);
|
|
99 |
IsCredential($"\\\\{sourceComputer}에 대한 인증이 필요합니다.", sourceComputer);
|
69 |
100 |
}
|
70 |
101 |
|
71 |
|
if (args.Length > 0)
|
|
102 |
if (cmd == "DEFAULT")
|
|
103 |
{
|
|
104 |
InitConvertPDF();
|
|
105 |
}
|
|
106 |
else if (cmd == "INPUT")
|
72 |
107 |
{
|
73 |
|
if (args[0] == "INPUT")
|
|
108 |
bool isBreak = false;
|
|
109 |
|
|
110 |
while (!isBreak)
|
74 |
111 |
{
|
75 |
112 |
string ProjectCode = null;
|
76 |
113 |
string DocID = null;
|
77 |
114 |
|
78 |
115 |
Console.WriteLine("# 생성이 필요한 DWG ID 입력 #");
|
79 |
|
|
|
116 |
|
80 |
117 |
Console.Write("Team Code : ");
|
81 |
118 |
ProjectCode = Console.ReadLine();
|
82 |
119 |
|
83 |
120 |
Console.Write("DWG ID : ");
|
84 |
121 |
DocID = Console.ReadLine();
|
85 |
122 |
|
86 |
|
|
87 |
123 |
ConvertDWG(ProjectCode, DocID);
|
88 |
124 |
|
|
125 |
Console.WriteLine("계속 진행은 아무키나 입력,종료는 CTRL+BREAK");
|
|
126 |
Console.ReadKey();
|
89 |
127 |
}
|
90 |
|
else if (args[0].Contains(".dwg"))
|
|
128 |
}
|
|
129 |
else if (args[0] == "RUN")
|
|
130 |
{
|
|
131 |
if (args.Count() == 3)
|
91 |
132 |
{
|
92 |
|
Show(args[0]);
|
|
133 |
string ProjectCode = args[1];
|
|
134 |
string DocID = args[2];
|
|
135 |
|
|
136 |
ConvertDWG(ProjectCode, DocID);
|
93 |
137 |
}
|
94 |
138 |
}
|
95 |
|
else
|
|
139 |
else if (args[0].Contains(".dwg"))
|
96 |
140 |
{
|
97 |
|
InitConvertPDF();
|
|
141 |
Show(args[0]);
|
98 |
142 |
}
|
99 |
143 |
}
|
100 |
144 |
}
|
... | ... | |
109 |
153 |
|
110 |
154 |
if (bSuccess)
|
111 |
155 |
Console.WriteLine("OdReadExMgd Finished Successfully");
|
112 |
|
|
113 |
|
Console.WriteLine("완료");
|
114 |
|
Console.ReadKey();
|
|
156 |
|
|
157 |
if (cmd == "DEFAULT")
|
|
158 |
{
|
|
159 |
Console.WriteLine("완료");
|
|
160 |
Console.ReadKey();
|
|
161 |
}
|
115 |
162 |
}
|
116 |
163 |
|
117 |
164 |
static string[] ProjectCodes()
|
... | ... | |
242 |
289 |
|
243 |
290 |
//dumper.prepareDump(pDb);
|
244 |
291 |
dumper.ExplodeAndPurgeNestedBlocks(pDb);
|
245 |
|
|
|
292 |
|
246 |
293 |
var pngFile = Path.Combine(targetPath, item.DOCUMENT_ID + ".png");
|
247 |
294 |
|
248 |
295 |
int width = 9600;
|
249 |
296 |
int height = 6787;
|
250 |
297 |
|
251 |
|
if (dumper.ExportPNG(pDb, pngFile, width, height))
|
|
298 |
if (dumper.ExportPNG(pDb, IsOpenGL, pngFile, width, height))
|
252 |
299 |
{
|
253 |
300 |
File.Delete(dwgFile);
|
254 |
301 |
|
... | ... | |
293 |
340 |
}
|
294 |
341 |
}
|
295 |
342 |
|
296 |
|
static bool ConvertDWG(string code, string DocID)
|
|
343 |
public static bool ConvertDWG(string code, string DocID)
|
297 |
344 |
{
|
298 |
345 |
bool result = false;
|
299 |
346 |
|
... | ... | |
307 |
354 |
|
308 |
355 |
using (MarkusRepository rep = new MarkusRepository(MarkusConnectionStr))
|
309 |
356 |
{
|
310 |
|
string SQL = "SELECT * FROM CONVERTER_DOC WHERE STATUS <> 4 and DOCUMENT_ID = @DOCUMENT_ID and PROJECT_NO = @PROJECT_NO";
|
|
357 |
string SQL = "SELECT * FROM CONVERTER_DOC WHERE DOCUMENT_ID = @DOCUMENT_ID and PROJECT_NO = @PROJECT_NO";
|
311 |
358 |
|
312 |
359 |
var parameters = new DynamicParameters();
|
313 |
360 |
parameters.Add("@PROJECT_NO", code);
|
... | ... | |
317 |
364 |
|
318 |
365 |
if (convertItems.Count() > 0)
|
319 |
366 |
{
|
320 |
|
foreach (var item in convertItems)
|
321 |
|
{
|
322 |
|
result = false;
|
323 |
|
string dwgFile = null;
|
|
367 |
var item = convertItems.First();
|
|
368 |
|
|
369 |
result = false;
|
|
370 |
string dwgFile = null;
|
324 |
371 |
|
325 |
|
try
|
326 |
|
{
|
327 |
|
var orgFile = Path.Combine(sourcePath, item.DOCUMENT_ID + ".dwg");
|
328 |
|
dwgFile = System.IO.Path.GetTempFileName().Replace(".tmp", ".dwg");
|
|
372 |
try
|
|
373 |
{
|
|
374 |
var orgFile = Path.Combine(sourcePath, item.DOCUMENT_ID + ".dwg");
|
|
375 |
dwgFile = System.IO.Path.GetTempFileName().Replace(".tmp", ".dwg");
|
329 |
376 |
|
330 |
377 |
|
331 |
|
File.Copy(orgFile, dwgFile, true);
|
|
378 |
File.Copy(orgFile, dwgFile, true);
|
332 |
379 |
|
333 |
|
using (Database pDb = new Database(false, true))
|
|
380 |
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))
|
334 |
402 |
{
|
335 |
|
pDb.ReadDwgFile(dwgFile, FileShare.Read, true, "");
|
336 |
|
HostApplicationServices.WorkingDatabase = pDb;
|
337 |
|
/****************************************************************/
|
338 |
|
/* Display the File Version */
|
339 |
|
/****************************************************************/
|
340 |
|
Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion);
|
341 |
|
/****************************************************************/
|
342 |
|
/* Dump the database */
|
343 |
|
/****************************************************************/
|
344 |
|
DbDumper dumper = new DbDumper();
|
345 |
|
|
346 |
|
//dumper.prepareDump(pDb);
|
347 |
|
dumper.ExplodeAndPurgeNestedBlocks(pDb);
|
|
403 |
File.Delete(dwgFile);
|
348 |
404 |
|
349 |
|
var pngFile = Path.Combine(targetPath, item.DOCUMENT_ID + ".png");
|
|
405 |
var docInfoID = rep.CreateDocInfo(item.ID, 1);
|
350 |
406 |
|
351 |
|
int width = 9600;
|
352 |
|
int height = 6787;
|
|
407 |
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
|
353 |
414 |
|
354 |
|
if (dumper.ExportPNG(pDb, pngFile, width, height))
|
355 |
|
{
|
356 |
|
File.Delete(dwgFile);
|
|
415 |
} });
|
357 |
416 |
|
358 |
|
var docInfoID = rep.CreateDocInfo(item.ID, 1);
|
359 |
|
|
360 |
|
var docPageResult = rep.CreateDocPage(new[]{
|
361 |
|
new DocPage {
|
362 |
|
docinfo_id = docInfoID,
|
363 |
|
page_angle = 0,
|
364 |
|
page_width = width.ToString(),
|
365 |
|
page_height = height.ToString(),
|
366 |
|
page_number = 1
|
367 |
|
|
368 |
|
} });
|
369 |
|
|
370 |
|
rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 4, 1, 1, null);
|
371 |
|
Console.WriteLine($"Ok. {item.DOCUMENT_ID}");
|
372 |
|
result = true;
|
373 |
|
}
|
374 |
|
else
|
375 |
|
{
|
376 |
|
rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 50, 1, 1, "DWG Convert Error");
|
377 |
|
Console.WriteLine($"Error. {item.DOCUMENT_ID}");
|
378 |
|
}
|
|
417 |
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}");
|
379 |
425 |
}
|
380 |
426 |
}
|
381 |
|
catch (Exception ex)
|
382 |
|
{
|
383 |
|
Console.WriteLine($"Error. {item.DOCUMENT_ID} {ex.ToString()}");
|
384 |
|
rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 50, 1, 1, ex.ToString());
|
385 |
|
}
|
386 |
|
finally
|
|
427 |
}
|
|
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)
|
387 |
436 |
{
|
388 |
|
if (dwgFile != null)
|
|
437 |
if (File.Exists(dwgFile))
|
389 |
438 |
{
|
390 |
|
if (File.Exists(dwgFile))
|
391 |
|
{
|
392 |
|
File.Delete(dwgFile);
|
393 |
|
}
|
|
439 |
File.Delete(dwgFile);
|
394 |
440 |
}
|
395 |
441 |
}
|
396 |
442 |
}
|
397 |
443 |
}
|
398 |
|
|
399 |
444 |
}
|
400 |
445 |
}
|
401 |
446 |
catch (Exception ex)
|