hytos / ID2.Manager / MarkusImageCreate / Program.cs @ c7f3eb42
이력 | 보기 | 이력해설 | 다운로드 (9.17 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 | d1d8c5ea | taeseongkim | |
12 | namespace MarkusImageCreate |
||
13 | { |
||
14 | class Program |
||
15 | { |
||
16 | const string CONST_SETTINGS = "SETTINGS"; |
||
17 | const string CONST_ID2Manager_Connect = "ID2Manager"; |
||
18 | const string CONST_Markus_Connect = "Markus"; |
||
19 | const string CONST_ID2ProjectsPath = "ID2ProjectsPath"; |
||
20 | const string CONST_MarkusImagePath = "MarkusImagePath"; |
||
21 | const string CONST_Resolution = "Resolution"; |
||
22 | const string CONST_FontPath = "FontPath"; |
||
23 | |||
24 | |||
25 | static string MarkusConnectionStr; |
||
26 | static string ID2ConnectionStr; |
||
27 | static string ID2ProjectsPath; |
||
28 | static string MarkusImagePath; |
||
29 | static int Resolution; |
||
30 | static string FontPath; |
||
31 | |||
32 | static void Main(string[] args) |
||
33 | { |
||
34 | c7f3eb42 | taeseongkim | 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 | } |
||
76 | d1d8c5ea | taeseongkim | |
77 | c7f3eb42 | taeseongkim | if (bSuccess) |
78 | Console.WriteLine("OdReadExMgd Finished Successfully"); |
||
79 | } |
||
80 | d1d8c5ea | taeseongkim | Console.WriteLine("완료"); |
81 | Console.ReadKey(); |
||
82 | } |
||
83 | |||
84 | static string[] ProjectCodes() |
||
85 | { |
||
86 | using (ProjectRepository rep = new ProjectRepository(ID2ConnectionStr)) |
||
87 | { |
||
88 | var projects = rep.GetAllProjectList(); |
||
89 | |||
90 | return projects.Select(x => x.Code).ToArray(); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | c7f3eb42 | taeseongkim | 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 | |||
119 | d1d8c5ea | taeseongkim | static void InitConvertPDF() |
120 | { |
||
121 | foreach (var code in ProjectCodes()) |
||
122 | { |
||
123 | c7f3eb42 | taeseongkim | ConvertDWG(code); |
124 | d1d8c5ea | taeseongkim | } |
125 | } |
||
126 | |||
127 | c7f3eb42 | taeseongkim | static void ConvertDWG(string code) |
128 | d1d8c5ea | taeseongkim | { |
129 | c7f3eb42 | taeseongkim | string sourcePath = Path.Combine(Path.Combine(Path.Combine(ID2ProjectsPath, code), "drawings"),"Native"); |
130 | d1d8c5ea | taeseongkim | string targetPath = Path.Combine(MarkusImagePath, code); |
131 | |||
132 | c7f3eb42 | taeseongkim | if (!Directory.Exists(targetPath)) |
133 | d1d8c5ea | taeseongkim | Directory.CreateDirectory(targetPath); |
134 | |||
135 | using (MarkusRepository rep = new MarkusRepository(MarkusConnectionStr)) |
||
136 | { |
||
137 | var convertItems = rep.GetConvertDoc(0, code); |
||
138 | |||
139 | foreach (var item in convertItems) |
||
140 | { |
||
141 | try |
||
142 | { |
||
143 | c7f3eb42 | taeseongkim | var orgFile = Path.Combine(sourcePath, item.DOCUMENT_ID + ".dwg"); |
144 | var dwgFile = Path.Combine(targetPath, item.DOCUMENT_ID + ".dwg"); |
||
145 | d1d8c5ea | taeseongkim | |
146 | c7f3eb42 | taeseongkim | File.Copy(orgFile, dwgFile,true); |
147 | d1d8c5ea | taeseongkim | |
148 | c7f3eb42 | taeseongkim | 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)) |
||
170 | d1d8c5ea | taeseongkim | { |
171 | c7f3eb42 | taeseongkim | 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); |
||
186 | d1d8c5ea | taeseongkim | Console.WriteLine($"Ok. {item.DOCUMENT_ID}"); |
187 | } |
||
188 | c7f3eb42 | taeseongkim | else |
189 | { |
||
190 | rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 50, 1, 1, "DWG Convert Error"); |
||
191 | Console.WriteLine($"Error. {item.DOCUMENT_ID}"); |
||
192 | } |
||
193 | d1d8c5ea | taeseongkim | } |
194 | } |
||
195 | catch (Exception ex) |
||
196 | { |
||
197 | Console.WriteLine($"Error. {item.DOCUMENT_ID} {ex.ToString()}"); |
||
198 | c7f3eb42 | taeseongkim | rep.UpdateStatusAsync(item.SERVICE_ID, item.ID,50, 1, 1, ex.ToString()); |
199 | d1d8c5ea | taeseongkim | } |
200 | } |
||
201 | } |
||
202 | } |
||
203 | } |
||
204 | } |