프로젝트

일반

사용자정보

개정판 66bd3240

ID66bd32406cca227c13fbec844b115eb99715efc6
상위 4e4b3e82
하위 c095f3cb

김태성이(가) 일년 이상 전에 추가함

issue #0000 fileupload api - svg 추가

Change-Id: I3e3fdf586fd732c226f08ab9e2fbb300cb82ebc7

차이점 보기:

FileUploadWevService/FileUpload.asmx.cs
1 1
using KCOMDataModel.DataModel;
2
using SvgNet;
3
using SvgNet.Elements;
4
using SvgNet.Interfaces;
2 5
using System;
3 6
using System.Collections.Generic;
4 7
using System.Configuration;
5 8
using System.Drawing;
9
using System.Drawing.Drawing2D;
6 10
using System.IO;
7 11
using System.Linq;
12
using System.Text;
8 13
using System.Web;
9 14
using System.Web.Services;
10 15

  
......
29 34
            KCOMEntities entity = new KCOMEntities(sConnString);
30 35

  
31 36
            /// 사용자가 Comment한 이미지 URL를 생성한다.
32
            
37

  
33 38
            var item = entity.PROPERTIES.Where(data => data.TYPE == "SystemInfo" && data.PROPERTY == "Url").FirstOrDefault();
34 39
            string result = "";
35
            if (item!=null)
40
            if (item != null)
36 41
            {
37 42
                result = string.Format(@"{0}/UserData/{1}/{2}/{3}", item.VALUE, ProjectNo, UserID, FileName);
38 43
            }
39 44
            else
40 45
            {
41
                throw new Exception("SystemInfo 정보가 없습니다."); 
46
                throw new Exception("SystemInfo 정보가 없습니다.");
42 47
            }
43 48

  
44 49
            try
45 50
            {
46 51
                var TileSourceProperty = entity.PROPERTIES.Where(data => data.TYPE == "TileSorceStorage" && data.PROPERTY == ProjectNo).FirstOrDefault();
47
                if(TileSourceProperty == null)
52
                if (TileSourceProperty == null)
48 53
                {
49 54
                    throw new Exception("TileSourceStorage 정보가 없습니다.");
50 55
                }
51 56
                /// 실제 이미지를 저장할 위치
52
                string DirectoryPath = string.Format(Path.Combine(TileSourceProperty.VALUE , "UserData", ProjectNo, UserID));
57
                string DirectoryPath = string.Format(Path.Combine(TileSourceProperty.VALUE, "UserData", ProjectNo, UserID));
53 58
                DirectoryInfo directoryInfo_ = new DirectoryInfo(DirectoryPath);
54 59

  
55 60
                if (!directoryInfo_.Exists)
......
75 80
            return result;
76 81
        }
77 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.DrawImage(image, 0, 0);
129
                            GraphicsContainer cnt = ig.BeginContainer();
130
                            ig.EndContainer(cnt);
131

  
132
                            string s = ig.WriteSVGString();
133
                            string tempFile = Path.Combine(directoryInfo_.FullName, FileName);
134
                            var tw = new StreamWriter(tempFile, false);
135
                            tw.Write(s);
136
                            tw.Close();
137
                            tw.Dispose();
138
                            ig.Dispose();
139
                        }
140
                    }
141
                }
142
            }
143
            catch (Exception ex)
144
            {
145
                result = ex.ToString();
146
            }
147

  
148
            return result;
149
        }
150

  
151

  
152

  
153
        [WebMethod]
154
        public string ServerMapPathTest(string uri)
155
        {
156
            return GetFilePath(uri);
157
        }
158

  
159
        private string GetFilePath(string fileUri)
160
        {
161
            string filePath = null;
162

  
163
            try
164
            {
165
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
166
                KCOMEntities entity = new KCOMEntities(sConnString);
167

  
168
                var sysinfo = entity.PROPERTIES.Where(data => data.TYPE == "SystemInfo" && data.PROPERTY == "Url").FirstOrDefault();
169

  
170
                filePath = HttpContext.Current.Server.MapPath(new Uri(fileUri.Replace(sysinfo.VALUE, $"{ "Http://" + HttpContext.Current.Request.Url.Authority}")).LocalPath);
171
            }
172
            catch (Exception ex)
173
            {
174
                throw;
175
            }
176

  
177
            return filePath;
178
        }
179

  
180

  
181
        [WebMethod]
182
        public string SymbolRegen()
183
        {
184
            string result = "";
185

  
186
            try
187
            {
188
                StringBuilder sb = new StringBuilder();
189

  
190
                string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
191
                KCOMEntities entity = new KCOMEntities(sConnString);
192

  
193
                var sysinfo = entity.PROPERTIES.Where(data => data.TYPE == "SystemInfo" && data.PROPERTY == "Url").FirstOrDefault();
194

  
195
                foreach (var symbol in entity.SYMBOL_PRIVATE.Where(x => !x.IMAGE_URL.EndsWith(".svg")))
196
                {
197
                    //if (symbol.IMAGE_URL.StartsWith(sysinfo.VALUE))
198
                    //{
199
                    //    symbol.IMAGE_URL = symbol.IMAGE_URL.Replace(sysinfo.VALUE, "");
200
                    //}
201

  
202
                    if (symbol.IMAGE_URL.EndsWith(".png") || symbol.IMAGE_URL.EndsWith(".jpg"))
203
                    {
204
                        var filePath = GetFilePath(symbol.IMAGE_URL);
205

  
206
                        symbol.IMAGE_URL = symbol.IMAGE_URL.Replace(".png", ".svg").Replace(".jpg", ".svg");
207

  
208
                        using (var image = Image.FromFile(filePath))
209
                        {
210
                            using (var ig = new SvgGraphics(Color.Transparent))
211
                            {
212
                                ig.SmoothingMode = SmoothingMode.HighSpeed;
213
                                ig.DrawImage(image, 0, 0);
214
                                GraphicsContainer cnt = ig.BeginContainer();
215
                                ig.EndContainer(cnt);
216

  
217
                                string s = ig.WriteSVGString();
218
                                string svgFile = filePath.Replace(".png", ".svg").Replace(".jpg", ".svg");
219

  
220
                                var tw = new StreamWriter(svgFile, false);
221
                                tw.Write(s);
222
                                tw.Close();
223
                                tw.Dispose();
224
                                ig.Dispose();
225
                            }
226
                        }
227
                    }
228
                }
229

  
230
                foreach (var symbol in entity.SYMBOL_PUBLIC.Where(x => !x.IMAGE_URL.EndsWith(".svg")))
231
                {
232
                    //if (symbol.IMAGE_URL.StartsWith(sysinfo.VALUE))
233
                    //{
234
                    //    symbol.IMAGE_URL = symbol.IMAGE_URL.Replace(sysinfo.VALUE, "");
235
                    //}
236

  
237
                    if (symbol.IMAGE_URL.EndsWith(".png") || symbol.IMAGE_URL.EndsWith(".jpg"))
238
                    {
239
                        var filePath = GetFilePath(symbol.IMAGE_URL);
240

  
241
                        symbol.IMAGE_URL = symbol.IMAGE_URL.Replace(".png", ".svg").Replace(".jpg", ".svg");
242

  
243
                        using (var image = Image.FromFile(filePath))
244
                        {
245
                            using (var ig = new SvgGraphics(Color.Transparent))
246
                            {
247
                                ig.DrawImage(image, 0, 0);
248
                                GraphicsContainer cnt = ig.BeginContainer();
249
                                ig.EndContainer(cnt);
250

  
251
                                string s = ig.WriteSVGString();
252
                                string svgFile = filePath.Replace(".png", ".svg").Replace(".jpg", ".svg");
253

  
254
                                var tw = new StreamWriter(svgFile, false);
255
                                tw.Write(s);
256
                                tw.Close();
257
                                tw.Dispose();
258
                                ig.Dispose();
259
                            }
260
                        }
261
                    }
262
                }
263

  
264
                entity.SaveChanges();
265

  
266
                result = "OK";
267
            }
268
            catch (Exception)
269
            {
270
                throw;
271
            }
272
            return result;
273
        }
274

  
275

  
78 276
        public Image Converter(string base64String)
79 277
        {
80 278
            byte[] imageBytes = Convert.FromBase64String(base64String);

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)