markus / FileUploadWevService / FileUpload.asmx.cs @ b2d0f316
이력 | 보기 | 이력해설 | 다운로드 (11.6 KB)
1 | 76dc223b | taeseongkim | using KCOMDataModel.DataModel; |
---|---|---|---|
2 | 66bd3240 | taeseongkim | using SvgNet; |
3 | using SvgNet.Elements; |
||
4 | using SvgNet.Interfaces; |
||
5 | 76dc223b | taeseongkim | using System; |
6 | using System.Collections.Generic; |
||
7 | using System.Configuration; |
||
8 | using System.Drawing; |
||
9 | 66bd3240 | taeseongkim | using System.Drawing.Drawing2D; |
10 | 76dc223b | taeseongkim | using System.IO; |
11 | using System.Linq; |
||
12 | 66bd3240 | taeseongkim | using System.Text; |
13 | 76dc223b | taeseongkim | using System.Web; |
14 | a2c29ea2 | swate0609 | using System.Web.Configuration; |
15 | 76dc223b | taeseongkim | using System.Web.Services; |
16 | |||
17 | namespace FileUploadWevService |
||
18 | { |
||
19 | /// <summary> |
||
20 | /// FileUpload의 요약 설명입니다. |
||
21 | /// </summary> |
||
22 | [WebService(Namespace = "http://tempuri.org/")] |
||
23 | [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] |
||
24 | [System.ComponentModel.ToolboxItem(false)] |
||
25 | // ASP.NET AJAX를 사용하여 스크립트에서 이 웹 서비스를 호출하려면 다음 줄의 주석 처리를 제거합니다. |
||
26 | // [System.Web.Script.Services.ScriptService] |
||
27 | public class FileUpload : System.Web.Services.WebService |
||
28 | { |
||
29 | |||
30 | [WebMethod] |
||
31 | //public string Run(string ProjectNo, string VPNo, string UserID, string FileName, byte[] imageBytes) |
||
32 | public string Run(string ProjectNo, string VPNo, string UserID, string FileName, byte[] f) |
||
33 | { |
||
34 | string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; |
||
35 | KCOMEntities entity = new KCOMEntities(sConnString); |
||
36 | |||
37 | /// 사용자가 Comment한 이미지 URL를 생성한다. |
||
38 | 66bd3240 | taeseongkim | |
39 | 76dc223b | taeseongkim | var item = entity.PROPERTIES.Where(data => data.TYPE == "SystemInfo" && data.PROPERTY == "Url").FirstOrDefault(); |
40 | string result = ""; |
||
41 | 66bd3240 | taeseongkim | if (item != null) |
42 | 76dc223b | taeseongkim | { |
43 | result = string.Format(@"{0}/UserData/{1}/{2}/{3}", item.VALUE, ProjectNo, UserID, FileName); |
||
44 | } |
||
45 | else |
||
46 | { |
||
47 | 66bd3240 | taeseongkim | throw new Exception("SystemInfo 정보가 없습니다."); |
48 | 76dc223b | taeseongkim | } |
49 | |||
50 | try |
||
51 | { |
||
52 | var TileSourceProperty = entity.PROPERTIES.Where(data => data.TYPE == "TileSorceStorage" && data.PROPERTY == ProjectNo).FirstOrDefault(); |
||
53 | 66bd3240 | taeseongkim | if (TileSourceProperty == null) |
54 | 76dc223b | taeseongkim | { |
55 | throw new Exception("TileSourceStorage 정보가 없습니다."); |
||
56 | } |
||
57 | /// 실제 이미지를 저장할 위치 |
||
58 | 66bd3240 | taeseongkim | string DirectoryPath = string.Format(Path.Combine(TileSourceProperty.VALUE, "UserData", ProjectNo, UserID)); |
59 | 76dc223b | taeseongkim | DirectoryInfo directoryInfo_ = new DirectoryInfo(DirectoryPath); |
60 | |||
61 | if (!directoryInfo_.Exists) |
||
62 | { |
||
63 | directoryInfo_.Create(); |
||
64 | } |
||
65 | //Image imageinfo = Converter(base64String); |
||
66 | |||
67 | MemoryStream ms = new MemoryStream(f); |
||
68 | FileStream fs = new FileStream(directoryInfo_ + @"\" + FileName, FileMode.Create); |
||
69 | ms.WriteTo(fs); |
||
70 | |||
71 | ms.Close(); |
||
72 | fs.Close(); |
||
73 | fs.Dispose(); |
||
74 | //imageinfo.Save(DirectoryPath + @"\" + FileName + "png", System.Drawing.Imaging.ImageFormat.Png); |
||
75 | } |
||
76 | catch (Exception ex) |
||
77 | { |
||
78 | result = ex.ToString(); |
||
79 | } |
||
80 | |||
81 | return result; |
||
82 | } |
||
83 | |||
84 | 66bd3240 | taeseongkim | [WebMethod] |
85 | //public string Run(string ProjectNo, string VPNo, string UserID, string FileName, byte[] imageBytes) |
||
86 | public string RunSymbol(string ProjectNo, string VPNo, string UserID, string FileName, byte[] f) |
||
87 | { |
||
88 | string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; |
||
89 | KCOMEntities entity = new KCOMEntities(sConnString); |
||
90 | |||
91 | /// 사용자가 Comment한 이미지 URL를 생성한다. |
||
92 | |||
93 | var item = entity.PROPERTIES.Where(data => data.TYPE == "SystemInfo" && data.PROPERTY == "Url").FirstOrDefault(); |
||
94 | string result = ""; |
||
95 | 5639752b | taeseongkim | |
96 | if (item == null) |
||
97 | 66bd3240 | taeseongkim | { |
98 | throw new Exception("SystemInfo 정보가 없습니다."); |
||
99 | } |
||
100 | |||
101 | try |
||
102 | { |
||
103 | var TileSourceProperty = entity.PROPERTIES.Where(data => data.TYPE == "TileSorceStorage" && data.PROPERTY == ProjectNo).FirstOrDefault(); |
||
104 | if (TileSourceProperty == null) |
||
105 | { |
||
106 | throw new Exception("TileSourceStorage 정보가 없습니다."); |
||
107 | } |
||
108 | 5639752b | taeseongkim | |
109 | 66bd3240 | taeseongkim | /// 실제 이미지를 저장할 위치 |
110 | string DirectoryPath = string.Format(Path.Combine(TileSourceProperty.VALUE, "UserData", ProjectNo, UserID)); |
||
111 | DirectoryInfo directoryInfo_ = new DirectoryInfo(DirectoryPath); |
||
112 | |||
113 | if (!directoryInfo_.Exists) |
||
114 | { |
||
115 | directoryInfo_.Create(); |
||
116 | } |
||
117 | |||
118 | a2c29ea2 | swate0609 | var vWebConfig = WebConfigurationManager.AppSettings[0]; |
119 | if (true)//!ImageUploadWebService.Properties.Settings.Default.IsSaveSVG) |
||
120 | 66bd3240 | taeseongkim | { |
121 | 5639752b | taeseongkim | MemoryStream ms = new MemoryStream(f); |
122 | FileStream fs = new FileStream(directoryInfo_ + @"\" + FileName, FileMode.Create); |
||
123 | ms.WriteTo(fs); |
||
124 | |||
125 | ms.Close(); |
||
126 | fs.Close(); |
||
127 | fs.Dispose(); |
||
128 | } |
||
129 | else |
||
130 | { |
||
131 | FileName = FileName.Replace(".png", ".svg"); |
||
132 | |||
133 | using (MemoryStream ms = new MemoryStream(f)) |
||
134 | 66bd3240 | taeseongkim | { |
135 | 5639752b | taeseongkim | using (var image = Image.FromStream(ms)) |
136 | 66bd3240 | taeseongkim | { |
137 | 5639752b | taeseongkim | using (var ig = new SvgGraphics(Color.Transparent)) |
138 | { |
||
139 | //ig.PixelOffsetMode = PixelOffsetMode.HighSpeed; |
||
140 | ig.CompositingQuality = CompositingQuality.HighSpeed; |
||
141 | |||
142 | ig.DrawImage(image, 0, 0); |
||
143 | GraphicsContainer cnt = ig.BeginContainer(); |
||
144 | ig.EndContainer(cnt); |
||
145 | |||
146 | string s = ig.WriteSVGString(); |
||
147 | string tempFile = Path.Combine(directoryInfo_.FullName, FileName); |
||
148 | var tw = new StreamWriter(tempFile, false); |
||
149 | tw.Write(s); |
||
150 | tw.Close(); |
||
151 | tw.Dispose(); |
||
152 | ig.Dispose(); |
||
153 | } |
||
154 | 66bd3240 | taeseongkim | } |
155 | } |
||
156 | } |
||
157 | 5639752b | taeseongkim | |
158 | result = string.Format(@"{0}/UserData/{1}/{2}/{3}", item.VALUE, ProjectNo, UserID, FileName); |
||
159 | 66bd3240 | taeseongkim | } |
160 | catch (Exception ex) |
||
161 | { |
||
162 | result = ex.ToString(); |
||
163 | } |
||
164 | |||
165 | return result; |
||
166 | } |
||
167 | |||
168 | |||
169 | |||
170 | [WebMethod] |
||
171 | public string ServerMapPathTest(string uri) |
||
172 | { |
||
173 | return GetFilePath(uri); |
||
174 | } |
||
175 | |||
176 | private string GetFilePath(string fileUri) |
||
177 | { |
||
178 | string filePath = null; |
||
179 | |||
180 | try |
||
181 | { |
||
182 | string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; |
||
183 | KCOMEntities entity = new KCOMEntities(sConnString); |
||
184 | |||
185 | var sysinfo = entity.PROPERTIES.Where(data => data.TYPE == "SystemInfo" && data.PROPERTY == "Url").FirstOrDefault(); |
||
186 | |||
187 | filePath = HttpContext.Current.Server.MapPath(new Uri(fileUri.Replace(sysinfo.VALUE, $"{ "Http://" + HttpContext.Current.Request.Url.Authority}")).LocalPath); |
||
188 | } |
||
189 | catch (Exception ex) |
||
190 | { |
||
191 | throw; |
||
192 | } |
||
193 | |||
194 | return filePath; |
||
195 | } |
||
196 | |||
197 | |||
198 | [WebMethod] |
||
199 | public string SymbolRegen() |
||
200 | { |
||
201 | string result = ""; |
||
202 | |||
203 | try |
||
204 | { |
||
205 | StringBuilder sb = new StringBuilder(); |
||
206 | |||
207 | string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; |
||
208 | KCOMEntities entity = new KCOMEntities(sConnString); |
||
209 | |||
210 | var sysinfo = entity.PROPERTIES.Where(data => data.TYPE == "SystemInfo" && data.PROPERTY == "Url").FirstOrDefault(); |
||
211 | |||
212 | foreach (var symbol in entity.SYMBOL_PRIVATE.Where(x => !x.IMAGE_URL.EndsWith(".svg"))) |
||
213 | { |
||
214 | //if (symbol.IMAGE_URL.StartsWith(sysinfo.VALUE)) |
||
215 | //{ |
||
216 | // symbol.IMAGE_URL = symbol.IMAGE_URL.Replace(sysinfo.VALUE, ""); |
||
217 | //} |
||
218 | |||
219 | if (symbol.IMAGE_URL.EndsWith(".png") || symbol.IMAGE_URL.EndsWith(".jpg")) |
||
220 | { |
||
221 | var filePath = GetFilePath(symbol.IMAGE_URL); |
||
222 | |||
223 | symbol.IMAGE_URL = symbol.IMAGE_URL.Replace(".png", ".svg").Replace(".jpg", ".svg"); |
||
224 | |||
225 | using (var image = Image.FromFile(filePath)) |
||
226 | { |
||
227 | using (var ig = new SvgGraphics(Color.Transparent)) |
||
228 | { |
||
229 | ig.SmoothingMode = SmoothingMode.HighSpeed; |
||
230 | ig.DrawImage(image, 0, 0); |
||
231 | GraphicsContainer cnt = ig.BeginContainer(); |
||
232 | ig.EndContainer(cnt); |
||
233 | |||
234 | string s = ig.WriteSVGString(); |
||
235 | string svgFile = filePath.Replace(".png", ".svg").Replace(".jpg", ".svg"); |
||
236 | |||
237 | var tw = new StreamWriter(svgFile, false); |
||
238 | tw.Write(s); |
||
239 | tw.Close(); |
||
240 | tw.Dispose(); |
||
241 | ig.Dispose(); |
||
242 | } |
||
243 | } |
||
244 | } |
||
245 | } |
||
246 | |||
247 | foreach (var symbol in entity.SYMBOL_PUBLIC.Where(x => !x.IMAGE_URL.EndsWith(".svg"))) |
||
248 | { |
||
249 | //if (symbol.IMAGE_URL.StartsWith(sysinfo.VALUE)) |
||
250 | //{ |
||
251 | // symbol.IMAGE_URL = symbol.IMAGE_URL.Replace(sysinfo.VALUE, ""); |
||
252 | //} |
||
253 | |||
254 | if (symbol.IMAGE_URL.EndsWith(".png") || symbol.IMAGE_URL.EndsWith(".jpg")) |
||
255 | { |
||
256 | var filePath = GetFilePath(symbol.IMAGE_URL); |
||
257 | |||
258 | symbol.IMAGE_URL = symbol.IMAGE_URL.Replace(".png", ".svg").Replace(".jpg", ".svg"); |
||
259 | |||
260 | using (var image = Image.FromFile(filePath)) |
||
261 | { |
||
262 | using (var ig = new SvgGraphics(Color.Transparent)) |
||
263 | { |
||
264 | ig.DrawImage(image, 0, 0); |
||
265 | GraphicsContainer cnt = ig.BeginContainer(); |
||
266 | ig.EndContainer(cnt); |
||
267 | |||
268 | string s = ig.WriteSVGString(); |
||
269 | string svgFile = filePath.Replace(".png", ".svg").Replace(".jpg", ".svg"); |
||
270 | |||
271 | var tw = new StreamWriter(svgFile, false); |
||
272 | tw.Write(s); |
||
273 | tw.Close(); |
||
274 | tw.Dispose(); |
||
275 | ig.Dispose(); |
||
276 | } |
||
277 | } |
||
278 | } |
||
279 | } |
||
280 | |||
281 | entity.SaveChanges(); |
||
282 | |||
283 | result = "OK"; |
||
284 | } |
||
285 | catch (Exception) |
||
286 | { |
||
287 | throw; |
||
288 | } |
||
289 | return result; |
||
290 | } |
||
291 | |||
292 | |||
293 | 76dc223b | taeseongkim | public Image Converter(string base64String) |
294 | { |
||
295 | byte[] imageBytes = Convert.FromBase64String(base64String); |
||
296 | |||
297 | using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) |
||
298 | { |
||
299 | Image image = Image.FromStream(ms, true); |
||
300 | return image; |
||
301 | } |
||
302 | } |
||
303 | } |
||
304 | } |