hytos / ID2.Manager / MarkusImageCreate / Program.cs @ 0d7d99aa
이력 | 보기 | 이력해설 | 다운로드 (11.6 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 | d1d8c5ea | taeseongkim | |
13 | namespace MarkusImageCreate |
||
14 | { |
||
15 | class Program |
||
16 | { |
||
17 | const string CONST_SETTINGS = "SETTINGS"; |
||
18 | const string CONST_ID2Manager_Connect = "ID2Manager"; |
||
19 | const string CONST_Markus_Connect = "Markus"; |
||
20 | const string CONST_ID2ProjectsPath = "ID2ProjectsPath"; |
||
21 | const string CONST_MarkusImagePath = "MarkusImagePath"; |
||
22 | const string CONST_Resolution = "Resolution"; |
||
23 | const string CONST_FontPath = "FontPath"; |
||
24 | |||
25 | |||
26 | static string MarkusConnectionStr; |
||
27 | static string ID2ConnectionStr; |
||
28 | static string ID2ProjectsPath; |
||
29 | static string MarkusImagePath; |
||
30 | static int Resolution; |
||
31 | static string FontPath; |
||
32 | |||
33 | static void Main(string[] args) |
||
34 | { |
||
35 | c7f3eb42 | taeseongkim | bool bSuccess = true; |
36 | 429bc8fa | taeseongkim | |
37 | try |
||
38 | c7f3eb42 | taeseongkim | { |
39 | 429bc8fa | taeseongkim | Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature); |
40 | using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services()) |
||
41 | c7f3eb42 | taeseongkim | { |
42 | HostApplicationServices.Current = new OdaMgdMViewApp.HostAppServ(); |
||
43 | /**********************************************************************/ |
||
44 | /* Display the Product and Version that created the executable */ |
||
45 | /**********************************************************************/ |
||
46 | Console.WriteLine("\nReadExMgd developed using {0} ver {1}", HostApplicationServices.Current.Product, HostApplicationServices.Current.VersionString); |
||
47 | |||
48 | Salaros.Configuration.ConfigParser config = new Salaros.Configuration.ConfigParser(Path.Combine(AppContext.BaseDirectory, "MarkusImageCreate.ini")); |
||
49 | ID2ConnectionStr = config.GetValue(CONST_SETTINGS, CONST_ID2Manager_Connect); |
||
50 | MarkusConnectionStr = config.GetValue(CONST_SETTINGS, CONST_Markus_Connect); |
||
51 | //ID2ConnectionStr = Encoding.Unicode.GetString(Convert.FromBase64String(config.GetValue(CONST_SETTINGS, CONST_ID2Manager_Connect))); |
||
52 | //MarkusConnectionStr = Encoding.Unicode.GetString(Convert.FromBase64String(config.GetValue(CONST_SETTINGS, CONST_Markus_Connect))); |
||
53 | ID2ProjectsPath = config.GetValue(CONST_SETTINGS, CONST_ID2ProjectsPath); |
||
54 | MarkusImagePath = config.GetValue(CONST_SETTINGS, CONST_MarkusImagePath); |
||
55 | Resolution = config.GetValue(CONST_SETTINGS, CONST_Resolution, 250); |
||
56 | FontPath = config.GetValue(CONST_SETTINGS, CONST_FontPath); |
||
57 | |||
58 | b0bfc1d3 | taeseongkim | while (!Directory.Exists(ID2ProjectsPath)) |
59 | { |
||
60 | string sourceComputer = ID2ProjectsPath.Split('\\').FirstOrDefault(x => !string.IsNullOrEmpty(x)); |
||
61 | 429bc8fa | taeseongkim | IsCredential($"\\\\{sourceComputer}에 대한 인증이 필요합니다.",sourceComputer); |
62 | } |
||
63 | |||
64 | while (!Directory.Exists(MarkusImagePath)) |
||
65 | { |
||
66 | string sourceComputer = MarkusImagePath.Split('\\').FirstOrDefault(x => !string.IsNullOrEmpty(x)); |
||
67 | IsCredential($"\\\\{sourceComputer}에 대한 인증이 필요합니다.",sourceComputer); |
||
68 | b0bfc1d3 | taeseongkim | } |
69 | |||
70 | c7f3eb42 | taeseongkim | if (args.Length > 0) |
71 | { |
||
72 | if (args[0].Contains(".dwg")) |
||
73 | { |
||
74 | Show(args[0]); |
||
75 | } |
||
76 | } |
||
77 | else |
||
78 | { |
||
79 | InitConvertPDF(); |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 | 429bc8fa | taeseongkim | /********************************************************************/ |
84 | /* Display the error */ |
||
85 | /********************************************************************/ |
||
86 | catch (System.Exception e) |
||
87 | { |
||
88 | bSuccess = false; |
||
89 | Console.WriteLine("Teigha?NET for .dwg files Error: " + e.Message); |
||
90 | } |
||
91 | |||
92 | if (bSuccess) |
||
93 | Console.WriteLine("OdReadExMgd Finished Successfully"); |
||
94 | |||
95 | d1d8c5ea | taeseongkim | Console.WriteLine("완료"); |
96 | Console.ReadKey(); |
||
97 | } |
||
98 | |||
99 | static string[] ProjectCodes() |
||
100 | { |
||
101 | using (ProjectRepository rep = new ProjectRepository(ID2ConnectionStr)) |
||
102 | { |
||
103 | var projects = rep.GetAllProjectList(); |
||
104 | |||
105 | return projects.Select(x => x.Code).ToArray(); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | c7f3eb42 | taeseongkim | static void Show(string dwgFile) |
110 | { |
||
111 | using (Database pDb = new Database(false, true)) |
||
112 | { |
||
113 | pDb.ReadDwgFile(dwgFile, FileShare.Read, true, ""); |
||
114 | HostApplicationServices.WorkingDatabase = pDb; |
||
115 | /****************************************************************/ |
||
116 | /* Display the File Version */ |
||
117 | /****************************************************************/ |
||
118 | Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion); |
||
119 | /****************************************************************/ |
||
120 | /* Dump the database */ |
||
121 | /****************************************************************/ |
||
122 | DbDumper dumper = new DbDumper(); |
||
123 | |||
124 | //dumper.prepareDump(pDb); |
||
125 | dumper.ExplodeAndPurgeNestedBlocks(pDb); |
||
126 | |||
127 | int width = 9600; |
||
128 | int height = 6787; |
||
129 | |||
130 | dumper.Show(pDb, width, height); |
||
131 | } |
||
132 | } |
||
133 | |||
134 | d1d8c5ea | taeseongkim | static void InitConvertPDF() |
135 | { |
||
136 | foreach (var code in ProjectCodes()) |
||
137 | { |
||
138 | c7f3eb42 | taeseongkim | ConvertDWG(code); |
139 | d1d8c5ea | taeseongkim | } |
140 | } |
||
141 | |||
142 | 429bc8fa | taeseongkim | static bool IsCredential(string Message, string path) |
143 | b0bfc1d3 | taeseongkim | { |
144 | bool result = false; |
||
145 | |||
146 | try |
||
147 | { |
||
148 | Credential credential = new Credential |
||
149 | { |
||
150 | Type = CredentialType.DomainPassword, |
||
151 | PersistanceType = PersistanceType.LocalComputer, |
||
152 | Target = path, |
||
153 | }; |
||
154 | |||
155 | if (credential.Load() == false) |
||
156 | { |
||
157 | VistaPrompt prompt = new VistaPrompt(); |
||
158 | 429bc8fa | taeseongkim | prompt.Title = $"{Message}"; |
159 | b0bfc1d3 | taeseongkim | |
160 | var dialogResult = prompt.ShowDialog(); |
||
161 | |||
162 | if (dialogResult == DialogResult.OK) |
||
163 | { |
||
164 | Credential genericCredential = new Credential |
||
165 | { |
||
166 | Target = path, |
||
167 | Username = prompt.Username, |
||
168 | Password = prompt.Password, |
||
169 | Type = CredentialType.DomainPassword, |
||
170 | PersistanceType = PersistanceType.LocalComputer |
||
171 | }; |
||
172 | |||
173 | genericCredential.Save(); |
||
174 | result = true; |
||
175 | } |
||
176 | } |
||
177 | } |
||
178 | catch (Exception ex) |
||
179 | { |
||
180 | Console.WriteLine(ex.ToString()); |
||
181 | } |
||
182 | |||
183 | return result; |
||
184 | } |
||
185 | |||
186 | c7f3eb42 | taeseongkim | static void ConvertDWG(string code) |
187 | d1d8c5ea | taeseongkim | { |
188 | c7f3eb42 | taeseongkim | string sourcePath = Path.Combine(Path.Combine(Path.Combine(ID2ProjectsPath, code), "drawings"),"Native"); |
189 | d1d8c5ea | taeseongkim | string targetPath = Path.Combine(MarkusImagePath, code); |
190 | |||
191 | c7f3eb42 | taeseongkim | if (!Directory.Exists(targetPath)) |
192 | d1d8c5ea | taeseongkim | Directory.CreateDirectory(targetPath); |
193 | |||
194 | using (MarkusRepository rep = new MarkusRepository(MarkusConnectionStr)) |
||
195 | { |
||
196 | var convertItems = rep.GetConvertDoc(0, code); |
||
197 | |||
198 | foreach (var item in convertItems) |
||
199 | { |
||
200 | 7459b663 | taeseongkim | string dwgFile = null; |
201 | |||
202 | d1d8c5ea | taeseongkim | try |
203 | { |
||
204 | c7f3eb42 | taeseongkim | var orgFile = Path.Combine(sourcePath, item.DOCUMENT_ID + ".dwg"); |
205 | 7459b663 | taeseongkim | dwgFile = System.IO.Path.GetTempFileName().Replace(".tmp",".dwg"); |
206 | d1d8c5ea | taeseongkim | |
207 | b0bfc1d3 | taeseongkim | |
208 | c7f3eb42 | taeseongkim | File.Copy(orgFile, dwgFile,true); |
209 | d1d8c5ea | taeseongkim | |
210 | c7f3eb42 | taeseongkim | using (Database pDb = new Database(false, true)) |
211 | { |
||
212 | pDb.ReadDwgFile(dwgFile, FileShare.Read, true, ""); |
||
213 | HostApplicationServices.WorkingDatabase = pDb; |
||
214 | /****************************************************************/ |
||
215 | /* Display the File Version */ |
||
216 | /****************************************************************/ |
||
217 | Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion); |
||
218 | /****************************************************************/ |
||
219 | /* Dump the database */ |
||
220 | /****************************************************************/ |
||
221 | DbDumper dumper = new DbDumper(); |
||
222 | |||
223 | //dumper.prepareDump(pDb); |
||
224 | dumper.ExplodeAndPurgeNestedBlocks(pDb); |
||
225 | |||
226 | var pngFile = Path.Combine(targetPath, item.DOCUMENT_ID + ".png"); |
||
227 | |||
228 | int width = 9600; |
||
229 | int height = 6787; |
||
230 | |||
231 | if (dumper.ExportPNG(pDb, pngFile, width, height)) |
||
232 | d1d8c5ea | taeseongkim | { |
233 | c7f3eb42 | taeseongkim | File.Delete(dwgFile); |
234 | |||
235 | var docInfoID = rep.CreateDocInfo(item.ID, 1); |
||
236 | |||
237 | var docPageResult = rep.CreateDocPage(new[]{ |
||
238 | new DocPage { |
||
239 | docinfo_id = docInfoID, |
||
240 | page_angle = 0, |
||
241 | page_width = width.ToString(), |
||
242 | page_height = height.ToString(), |
||
243 | page_number = 1 |
||
244 | |||
245 | } }); |
||
246 | |||
247 | rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 4, 1, 1, null); |
||
248 | d1d8c5ea | taeseongkim | Console.WriteLine($"Ok. {item.DOCUMENT_ID}"); |
249 | } |
||
250 | c7f3eb42 | taeseongkim | else |
251 | { |
||
252 | rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 50, 1, 1, "DWG Convert Error"); |
||
253 | Console.WriteLine($"Error. {item.DOCUMENT_ID}"); |
||
254 | } |
||
255 | d1d8c5ea | taeseongkim | } |
256 | } |
||
257 | catch (Exception ex) |
||
258 | { |
||
259 | Console.WriteLine($"Error. {item.DOCUMENT_ID} {ex.ToString()}"); |
||
260 | c7f3eb42 | taeseongkim | rep.UpdateStatusAsync(item.SERVICE_ID, item.ID,50, 1, 1, ex.ToString()); |
261 | d1d8c5ea | taeseongkim | } |
262 | 7459b663 | taeseongkim | finally |
263 | { |
||
264 | if(dwgFile != null) |
||
265 | { |
||
266 | if(File.Exists(dwgFile)) |
||
267 | { |
||
268 | File.Delete(dwgFile); |
||
269 | } |
||
270 | } |
||
271 | } |
||
272 | d1d8c5ea | taeseongkim | } |
273 | } |
||
274 | } |
||
275 | } |
||
276 | } |