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