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