hytos / ID2.Manager / MarkusImageCreate / Program.cs @ 429bc8fa
이력 | 보기 | 이력해설 | 다운로드 (11.2 KB)
1 |
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 |
using Teigha.DatabaseServices; |
10 |
using OdReadExMgd; |
11 |
using CredentialManagement; |
12 |
|
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 |
bool bSuccess = true; |
36 |
|
37 |
try |
38 |
{ |
39 |
Teigha.Runtime.Services.odActivate(ActivationData.userInfo, ActivationData.userSignature); |
40 |
using (Teigha.Runtime.Services srv = new Teigha.Runtime.Services()) |
41 |
{ |
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 |
while (!Directory.Exists(ID2ProjectsPath)) |
59 |
{ |
60 |
string sourceComputer = ID2ProjectsPath.Split('\\').FirstOrDefault(x => !string.IsNullOrEmpty(x)); |
61 |
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 |
} |
69 |
|
70 |
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 |
/********************************************************************/ |
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 |
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 |
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 |
static void InitConvertPDF() |
135 |
{ |
136 |
foreach (var code in ProjectCodes()) |
137 |
{ |
138 |
ConvertDWG(code); |
139 |
} |
140 |
} |
141 |
|
142 |
static bool IsCredential(string Message, string path) |
143 |
{ |
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 |
prompt.Title = $"{Message}"; |
159 |
|
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 |
static void ConvertDWG(string code) |
187 |
{ |
188 |
string sourcePath = Path.Combine(Path.Combine(Path.Combine(ID2ProjectsPath, code), "drawings"),"Native"); |
189 |
string targetPath = Path.Combine(MarkusImagePath, code); |
190 |
|
191 |
if (!Directory.Exists(targetPath)) |
192 |
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 |
try |
201 |
{ |
202 |
var orgFile = Path.Combine(sourcePath, item.DOCUMENT_ID + ".dwg"); |
203 |
var dwgFile = Path.Combine(targetPath, item.DOCUMENT_ID + ".dwg"); |
204 |
|
205 |
|
206 |
File.Copy(orgFile, dwgFile,true); |
207 |
|
208 |
using (Database pDb = new Database(false, true)) |
209 |
{ |
210 |
pDb.ReadDwgFile(dwgFile, FileShare.Read, true, ""); |
211 |
HostApplicationServices.WorkingDatabase = pDb; |
212 |
/****************************************************************/ |
213 |
/* Display the File Version */ |
214 |
/****************************************************************/ |
215 |
Console.WriteLine("File Version: {0}", pDb.OriginalFileVersion); |
216 |
/****************************************************************/ |
217 |
/* Dump the database */ |
218 |
/****************************************************************/ |
219 |
DbDumper dumper = new DbDumper(); |
220 |
|
221 |
//dumper.prepareDump(pDb); |
222 |
dumper.ExplodeAndPurgeNestedBlocks(pDb); |
223 |
|
224 |
var pngFile = Path.Combine(targetPath, item.DOCUMENT_ID + ".png"); |
225 |
|
226 |
int width = 9600; |
227 |
int height = 6787; |
228 |
|
229 |
if (dumper.ExportPNG(pDb, pngFile, width, height)) |
230 |
{ |
231 |
File.Delete(dwgFile); |
232 |
|
233 |
var docInfoID = rep.CreateDocInfo(item.ID, 1); |
234 |
|
235 |
var docPageResult = rep.CreateDocPage(new[]{ |
236 |
new DocPage { |
237 |
docinfo_id = docInfoID, |
238 |
page_angle = 0, |
239 |
page_width = width.ToString(), |
240 |
page_height = height.ToString(), |
241 |
page_number = 1 |
242 |
|
243 |
} }); |
244 |
|
245 |
rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 4, 1, 1, null); |
246 |
Console.WriteLine($"Ok. {item.DOCUMENT_ID}"); |
247 |
} |
248 |
else |
249 |
{ |
250 |
rep.UpdateStatusAsync(item.SERVICE_ID, item.ID, 50, 1, 1, "DWG Convert Error"); |
251 |
Console.WriteLine($"Error. {item.DOCUMENT_ID}"); |
252 |
} |
253 |
} |
254 |
} |
255 |
catch (Exception ex) |
256 |
{ |
257 |
Console.WriteLine($"Error. {item.DOCUMENT_ID} {ex.ToString()}"); |
258 |
rep.UpdateStatusAsync(item.SERVICE_ID, item.ID,50, 1, 1, ex.ToString()); |
259 |
} |
260 |
} |
261 |
} |
262 |
} |
263 |
} |
264 |
} |