markus / KCOM_API / MarkusService.svc.cs @ 3b938959
이력 | 보기 | 이력해설 | 다운로드 (11.6 KB)
1 | cf1cc862 | taeseongkim | using KCOMDataModel.DataModel; |
---|---|---|---|
2 | 3b938959 | taeseongkim | using log4net; |
3 | using Newtonsoft.Json.Linq; |
||
4 | cf1cc862 | taeseongkim | using System; |
5 | c517099d | taeseongkim | using System.Collections.Generic; |
6 | cf1cc862 | taeseongkim | using System.Configuration; |
7 | c517099d | taeseongkim | using System.Linq; |
8 | using System.Runtime.Serialization; |
||
9 | using System.ServiceModel; |
||
10 | using System.ServiceModel.Activation; |
||
11 | using System.ServiceModel.Web; |
||
12 | using System.Text; |
||
13 | |||
14 | namespace KCOM_API |
||
15 | { |
||
16 | [ServiceContract(Namespace = "")] |
||
17 | [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] |
||
18 | public class MarkusService : System.Web.Services.WebService |
||
19 | { |
||
20 | 3b938959 | taeseongkim | protected ILog logger = LogManager.GetLogger(typeof(MarkusService)); |
21 | |||
22 | cf1cc862 | taeseongkim | [WebGet(UriTemplate = "AddMember?UserId={UserId}&Name={Name}&Company={Company}&Department={Department}&Position={Position}&email={email}", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] |
23 | c517099d | taeseongkim | [OperationContract] |
24 | cf1cc862 | taeseongkim | public AddMemberResults AddMember(string UserId,string Name, string Company, string Department,string Position,string email) |
25 | c517099d | taeseongkim | { |
26 | cf1cc862 | taeseongkim | AddMemberResults results = new AddMemberResults(false,null); |
27 | |||
28 | try |
||
29 | { |
||
30 | string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString; |
||
31 | using (CIEntities _ci = new CIEntities(sCIConnString)) |
||
32 | { |
||
33 | if (_ci.MEMBER.Count(x => x.ID == UserId) == 0) |
||
34 | { |
||
35 | _ci.AddToMEMBER(new MEMBER |
||
36 | { |
||
37 | ID = UserId, |
||
38 | NAME = Name, |
||
39 | COMPANY = Company, |
||
40 | DEPARTMENT = Department, |
||
41 | POSITION = Position, |
||
42 | EMAIL_ADDRESS = email, |
||
43 | MODIFIED_DATETIME = DateTime.Now, |
||
44 | CREATE_DATETIME = DateTime.Now |
||
45 | }); |
||
46 | |||
47 | _ci.SaveChanges(); |
||
48 | |||
49 | results.IsSuccess = true; |
||
50 | } |
||
51 | else |
||
52 | { |
||
53 | results.Message = "User already exists."; |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | catch (Exception ex) |
||
58 | { |
||
59 | results.Message = "system Error"; |
||
60 | } |
||
61 | finally |
||
62 | { |
||
63 | |||
64 | } |
||
65 | |||
66 | return results; |
||
67 | c517099d | taeseongkim | } |
68 | |||
69 | cf1cc862 | taeseongkim | [WebInvoke(UriTemplate = "GetMembers",Method ="POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] |
70 | c517099d | taeseongkim | [OperationContract] |
71 | cf1cc862 | taeseongkim | public GetMembersResults GetMembers() |
72 | c517099d | taeseongkim | { |
73 | cf1cc862 | taeseongkim | GetMembersResults results = new GetMembersResults(); |
74 | c517099d | taeseongkim | |
75 | cf1cc862 | taeseongkim | try |
76 | c517099d | taeseongkim | { |
77 | cf1cc862 | taeseongkim | string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString; |
78 | using (CIEntities _ci = new CIEntities(sCIConnString)) |
||
79 | c517099d | taeseongkim | { |
80 | cf1cc862 | taeseongkim | if (_ci.MEMBER.Count() > 0) |
81 | { |
||
82 | results.Members = _ci.MEMBER.Select(m => new Member |
||
83 | { |
||
84 | ID = m.ID, |
||
85 | NAME = m.NAME, |
||
86 | COMPANY = m.COMPANY, |
||
87 | DEPARTMENT = m.DEPARTMENT, |
||
88 | POSITION = m.POSITION, |
||
89 | EMAIL_ADDRESS = m.EMAIL_ADDRESS |
||
90 | }).ToArray(); |
||
91 | } |
||
92 | c517099d | taeseongkim | } |
93 | cf1cc862 | taeseongkim | } |
94 | catch (Exception ex) |
||
95 | { |
||
96 | } |
||
97 | finally |
||
98 | { |
||
99 | c517099d | taeseongkim | |
100 | cf1cc862 | taeseongkim | } |
101 | c517099d | taeseongkim | |
102 | cf1cc862 | taeseongkim | return results; |
103 | } |
||
104 | 3b938959 | taeseongkim | |
105 | [WebGet(UriTemplate = "ConvertRun?rev_No={rev_No}&document_No={document_No}&document_Name={document_Name}&group_No={group_No}&prj_No={prj_No}&document_Id={document_Id}&document_Url={document_Url}", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] |
||
106 | [OperationContract] |
||
107 | public string ConvertRun(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
||
108 | { |
||
109 | string _result = null; |
||
110 | try |
||
111 | { |
||
112 | logger.Info($"Conversion Web Service ConvertRun call rev_No :{rev_No} document_No : {document_No} document_Name : {document_Name} group_No : {group_No} prj_No : {prj_No} document_Id : {document_Id} document_Url : {document_Url}"); |
||
113 | |||
114 | string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; |
||
115 | using (KCOMEntities deepViewEntity = new KCOMEntities(sConnString)) |
||
116 | { |
||
117 | //_result = ConnectStringBuilder.DeepViewConnectionString().ToString(); |
||
118 | //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now); |
||
119 | //var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber); |
||
120 | var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null); |
||
121 | |||
122 | if (_RunProjects.Count() > 0) |
||
123 | { |
||
124 | _result = SendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url); |
||
125 | } |
||
126 | else |
||
127 | { |
||
128 | _result = false.ToString(); |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | catch (Exception ex) |
||
133 | { |
||
134 | logger.Error($"Conversion Web Service ConvertRun Error rev_No :{rev_No} document_No : {document_No} document_Name : {document_Name} group_No : {group_No} prj_No : {prj_No} document_Id : {document_Id} document_Url : {document_Url}", ex); |
||
135 | _result = ex.Message.ToString(); |
||
136 | } |
||
137 | return _result; |
||
138 | } |
||
139 | |||
140 | |||
141 | private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url) |
||
142 | { |
||
143 | string result = false.ToString(); |
||
144 | |||
145 | //string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString(); |
||
146 | string _id = shortGuid(); |
||
147 | string _doc_id = ((UInt32)document_Id.GetHashCode()).ToString(); |
||
148 | |||
149 | string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString; |
||
150 | using (CIEntities _kcomEntity = new CIEntities(sCIConnString)) |
||
151 | { |
||
152 | if (string.IsNullOrEmpty(group_No)) |
||
153 | { |
||
154 | group_No = "0"; |
||
155 | } |
||
156 | if (!document_Url.Contains("http%3a%2f%2f")) |
||
157 | { |
||
158 | document_Url = Base64Decode(document_Url); |
||
159 | document_Url = System.Net.WebUtility.UrlEncode(document_Url); |
||
160 | } |
||
161 | document_Name = Base64DecodeFromStr(document_Name); |
||
162 | |||
163 | var doc = _kcomEntity.DOCUMENT_ITEM.Where(d => d.PROJECT_NO == prj_No && d.ID == document_Id).FirstOrDefault(); |
||
164 | if (doc != null) |
||
165 | { |
||
166 | doc.DOCUMENT_ID = _doc_id; |
||
167 | doc.REVISION = rev_No; |
||
168 | doc.GROUP_NO = group_No; |
||
169 | doc.DOCUMENT_NO = document_No; |
||
170 | doc.DOCUMENT_NAME = document_Name; |
||
171 | doc.ORIGINAL_FILE = document_Url; |
||
172 | } |
||
173 | else |
||
174 | { |
||
175 | _kcomEntity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM |
||
176 | { |
||
177 | ID = document_Id, |
||
178 | REVISION = rev_No, |
||
179 | DOCUMENT_NO = document_No, |
||
180 | DOCUMENT_NAME = document_Name, |
||
181 | GROUP_NO = group_No, |
||
182 | ORIGINAL_FILE = document_Url, |
||
183 | DOCUMENT_ID = _doc_id, |
||
184 | PROJECT_NO = prj_No, |
||
185 | }); |
||
186 | } |
||
187 | |||
188 | _kcomEntity.SaveChanges(); |
||
189 | |||
190 | string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; |
||
191 | using (KCOMEntities _entity = new KCOMEntities(sConnString)) |
||
192 | { |
||
193 | _entity.AddToCONVERTER_DOC(new CONVERTER_DOC |
||
194 | { |
||
195 | ID = _id, |
||
196 | CREATE_DATETIME = DateTime.Now, |
||
197 | DOCUMENT_URL = document_Url, |
||
198 | PROJECT_NO = prj_No, |
||
199 | DOCUMENT_ID = _doc_id, |
||
200 | }); |
||
201 | |||
202 | _entity.SaveChanges(); |
||
203 | } |
||
204 | } |
||
205 | |||
206 | |||
207 | try |
||
208 | { |
||
209 | System.Net.WebClient client = new System.Net.WebClient(); |
||
210 | var convertResult = client.DownloadString($"{Properties.Settings.Default.CovnertService}/Rest/ConvertAdd?ProjectNo={prj_No}&ConvertID={_id}"); |
||
211 | |||
212 | JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings()); |
||
213 | result = jObject["ConvertAddResult"].ToString(); |
||
214 | } |
||
215 | catch (Exception ex) |
||
216 | { |
||
217 | logger.Error("Conversion Web Service SendKcom Error", ex); |
||
218 | result = $"Markus V3 Connect Error {ex.Message}"; |
||
219 | } |
||
220 | |||
221 | |||
222 | return result; |
||
223 | } |
||
224 | |||
225 | public string Base64DecodeFromStr(string data) |
||
226 | { |
||
227 | try |
||
228 | { |
||
229 | System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); |
||
230 | System.Text.Decoder utf8Decode = encoder.GetDecoder(); |
||
231 | |||
232 | byte[] todecode_byte = Convert.FromBase64String(data); |
||
233 | |||
234 | int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); |
||
235 | |||
236 | char[] decoded_char = new char[charCount]; |
||
237 | |||
238 | utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); |
||
239 | |||
240 | string result = new String(decoded_char); |
||
241 | |||
242 | return result; |
||
243 | } |
||
244 | catch (Exception) |
||
245 | { |
||
246 | return data; |
||
247 | } |
||
248 | } |
||
249 | |||
250 | public string Base64Decode(string data) |
||
251 | { |
||
252 | try |
||
253 | { |
||
254 | if (data.Contains("http://")) |
||
255 | { |
||
256 | return data; |
||
257 | } |
||
258 | else |
||
259 | { |
||
260 | System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); |
||
261 | System.Text.Decoder utf8Decode = encoder.GetDecoder(); |
||
262 | |||
263 | byte[] todecode_byte = Convert.FromBase64String(data); |
||
264 | |||
265 | int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); |
||
266 | |||
267 | char[] decoded_char = new char[charCount]; |
||
268 | |||
269 | utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); |
||
270 | |||
271 | string result = new String(decoded_char); |
||
272 | |||
273 | return result; |
||
274 | } |
||
275 | |||
276 | |||
277 | } |
||
278 | |||
279 | catch (Exception e) |
||
280 | { |
||
281 | throw new Exception("Error in Base64Decode: " + e.Message); |
||
282 | } |
||
283 | } |
||
284 | public string shortGuid() |
||
285 | { |
||
286 | byte[] bytes = new byte[16]; |
||
287 | using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create()) |
||
288 | { |
||
289 | provider.GetBytes(bytes); |
||
290 | } |
||
291 | |||
292 | var guid = new Guid(bytes); |
||
293 | |||
294 | return Convert.ToBase64String(guid.ToByteArray()) |
||
295 | .Substring(0, 10) |
||
296 | .Replace("/", "") |
||
297 | .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x"); |
||
298 | } |
||
299 | |||
300 | c517099d | taeseongkim | } |
301 | } |