markus / PemssAPI / PemssApi.cs @ ee2f7287
이력 | 보기 | 이력해설 | 다운로드 (11.9 KB)
1 | 0f6604ce | taeseongkim | using Newtonsoft.Json.Linq; |
---|---|---|---|
2 | using System; |
||
3 | using System.Collections.Generic; |
||
4 | using System.Linq; |
||
5 | using System.Web; |
||
6 | using PemssAPI.DataModel; |
||
7 | 84190963 | taeseongkim | using System.Collections.Specialized; |
8 | using System.Net.Http; |
||
9 | c47493ca | taeseongkim | using System.Net.Http.Headers; |
10 | 0f6604ce | taeseongkim | |
11 | namespace KCOM_API |
||
12 | { |
||
13 | 84190963 | taeseongkim | /// <summary> |
14 | /// 등록은 POST, 삭제시 DELETE , LIST 는 GET 으로 호출해야 합니다. |
||
15 | /// </summary> |
||
16 | 0f6604ce | taeseongkim | public class PemssApi : IDisposable |
17 | { |
||
18 | private string gPemssUri; |
||
19 | |||
20 | public PemssApi(string PemssApiUri) |
||
21 | { |
||
22 | gPemssUri = PemssApiUri; |
||
23 | } |
||
24 | |||
25 | public void Dispose() |
||
26 | { |
||
27 | } |
||
28 | |||
29 | /// <summary> |
||
30 | /// 정합성 목록 |
||
31 | /// </summary> |
||
32 | /// <param name="pId">프로젝트 ID</param> |
||
33 | /// <param name="dId">Document ID</param> |
||
34 | /// <returns></returns> |
||
35 | public List<Requirement> GetRequirementItems(string pId,string dId) |
||
36 | { |
||
37 | List<Requirement> result = new List<Requirement>(); |
||
38 | |||
39 | try |
||
40 | { |
||
41 | var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/list/requirement?pId={pId}&dId={dId}"); |
||
42 | |||
43 | if (jsonObj != null) |
||
44 | { |
||
45 | JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings()); |
||
46 | |||
47 | foreach (var item in JArray.Parse(jObject["rows"].ToString())) |
||
48 | { |
||
49 | 84190963 | taeseongkim | List<VpCommant> VpComments = new List<VpCommant>(); |
50 | |||
51 | if (item["vpComments"].HasValues) |
||
52 | { |
||
53 | var comments = JArray.Parse(item["vpComments"].ToString()); |
||
54 | |||
55 | foreach (var comment in comments) |
||
56 | { |
||
57 | VpComments.Add(new VpCommant |
||
58 | { |
||
59 | mdId = item["mdId"]?.ToObject<string>(), |
||
60 | created = comment["created"]?.ToObject<string>(), |
||
61 | comment = comment["comment"]?.ToObject<string>(), |
||
62 | commentId = comment["commentId"]?.ToObject<string>(), |
||
63 | condition = comment["condition"].HasValues ? comment["condition"].ToObject<bool>() : false, |
||
64 | createdBy = comment["createdBy"]?.ToObject<string>(), |
||
65 | createdByName = comment["createdByName"]?.ToObject<string>(), |
||
66 | }); |
||
67 | } |
||
68 | } |
||
69 | |||
70 | 0f6604ce | taeseongkim | result.Add(new Requirement |
71 | { |
||
72 | mdId = item["mdId"]?.ToObject<string>(), |
||
73 | mdText = item["mdText"]?.ToObject<string>(), |
||
74 | fad4d1c0 | taeseongkim | MrComments = new List<MrCommant>(), |
75 | 84190963 | taeseongkim | VpComments = VpComments |
76 | 0f6604ce | taeseongkim | }); |
77 | 84190963 | taeseongkim | |
78 | |||
79 | 0f6604ce | taeseongkim | } |
80 | } |
||
81 | } |
||
82 | catch (Exception ex) |
||
83 | { |
||
84 | throw new Exception("GetRequirementItems",ex); |
||
85 | } |
||
86 | |||
87 | return result; |
||
88 | } |
||
89 | |||
90 | /// <summary> |
||
91 | /// 정합성 코멘트 등록 |
||
92 | /// </summary> |
||
93 | /// <param name="pId">프로젝트 ID</param> |
||
94 | /// <param name="dId">Document ID</param> |
||
95 | /// <param name="mdId">MR 상세 아이템 ID</param> |
||
96 | /// <param name="commentId"></param> |
||
97 | /// <param name="comment"></param> |
||
98 | /// <param name="condition"></param> |
||
99 | /// <param name="uId"></param> |
||
100 | /// <returns></returns> |
||
101 | public bool SetRequirementComment(string pId, string dId,string mdId, string commentId,string comment,bool condition,string uId) |
||
102 | { |
||
103 | bool result = false; |
||
104 | |||
105 | try |
||
106 | { |
||
107 | //http://pemss.i-on.net/rest/ext/comment/requirement?dId=116&mdId=MD0000000352&commentId=1&comment=test&condition=true&uId=admin |
||
108 | |||
109 | 84190963 | taeseongkim | var values = new NameValueCollection(){ |
110 | { "dId",dId}, |
||
111 | { "mdId", mdId}, |
||
112 | { "commentId" , commentId}, |
||
113 | { "comment" ,comment}, |
||
114 | { "condition" ,condition.ToString()}, |
||
115 | { "uId", uId} |
||
116 | }; |
||
117 | |||
118 | var jsonObj = SetWebClientString($"{gPemssUri}/rest/ext/comment/requirement", values); |
||
119 | //var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/comment/requirement?" |
||
120 | // + $"dId={dId}&mdId={mdId}&commentId={commentId}&comment={comment}&condition={condition}&uId={uId}"); |
||
121 | |||
122 | 0f6604ce | taeseongkim | if (jsonObj != null) |
123 | { |
||
124 | JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings()); |
||
125 | |||
126 | if (jObject.Property("status") != null) |
||
127 | { |
||
128 | result = jObject.Property("status").ToObject<bool>(); |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | catch (Exception ex) |
||
133 | { |
||
134 | throw new Exception("SetRequirementComment", ex); |
||
135 | } |
||
136 | |||
137 | return result; |
||
138 | } |
||
139 | |||
140 | /// <summary> |
||
141 | /// 정합성 코멘트 삭제 |
||
142 | /// </summary> |
||
143 | /// <param name="pId">프로젝트 ID</param> |
||
144 | /// <param name="dId">Document ID</param> |
||
145 | /// <param name="mdId">MR 상세 아이템 ID</param> |
||
146 | /// <param name="commentId"></param> |
||
147 | /// <param name="uId"></param> |
||
148 | /// <returns></returns> |
||
149 | public bool RemoveRequirementComment(string pId, string dId, string mdId, string commentId, string uId) |
||
150 | { |
||
151 | bool result = false; |
||
152 | |||
153 | try |
||
154 | { |
||
155 | //http://pemss.i-on.net/rest/ext/comment/requirement?dId=116&mdId=MD0000000352&commentId=1&uId=유저아이디 |
||
156 | 84190963 | taeseongkim | |
157 | var values = new NameValueCollection(){ |
||
158 | { "dId",dId}, |
||
159 | { "mdId", mdId}, |
||
160 | { "commentId" , commentId}, |
||
161 | { "uId", uId} |
||
162 | }; |
||
163 | |||
164 | c47493ca | taeseongkim | var jsonObj = DeleteWebClientString($"{gPemssUri}","/rest/ext/comment/requirement", values); |
165 | //+ $"dId={dId}&mdId={mdId}&commentId={commentId}&uId={uId}"); |
||
166 | 84190963 | taeseongkim | |
167 | // var jsonObj = DeleteWebClientString($"{gPemssUri}/rest/ext/comment/requirement", values); |
||
168 | 0f6604ce | taeseongkim | |
169 | if (jsonObj != null) |
||
170 | { |
||
171 | JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings()); |
||
172 | |||
173 | if (jObject.Property("status") != null) |
||
174 | { |
||
175 | result = jObject.Property("status").ToObject<bool>(); |
||
176 | } |
||
177 | } |
||
178 | } |
||
179 | catch (Exception ex) |
||
180 | { |
||
181 | throw new Exception("RemoveRequirementComment", ex); |
||
182 | } |
||
183 | |||
184 | return result; |
||
185 | } |
||
186 | |||
187 | /// <summary> |
||
188 | /// 문서 정보 |
||
189 | /// </summary> |
||
190 | /// <param name="pId">프로젝트 ID</param> |
||
191 | /// <param name="dId">Document ID</param> |
||
192 | /// <returns></returns> |
||
193 | public DocumentInfo GetDocumentInfo(string pId, string dId) |
||
194 | { |
||
195 | DocumentInfo result = null; |
||
196 | |||
197 | try |
||
198 | { |
||
199 | var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/docinfo?pId={pId}&dId={dId}"); |
||
200 | |||
201 | if (jsonObj != null) |
||
202 | { |
||
203 | JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings()); |
||
204 | |||
205 | result = new DocumentInfo |
||
206 | { |
||
207 | slipNo = jObject.Property("slipNo")?.Value?.ToString(), |
||
208 | dId = jObject.Property("dId").HasValues ? jObject.Property("dId").ToObject<int>() : -1, |
||
209 | docName = jObject.Property("docName")?.Value?.ToString(), |
||
210 | fileName = jObject.Property("fileName")?.Value?.ToString(), |
||
211 | revision = jObject.Property("revision")?.Value?.ToString() |
||
212 | }; |
||
213 | } |
||
214 | } |
||
215 | catch (Exception ex) |
||
216 | { |
||
217 | throw new Exception("GetDocumentInfo",ex); |
||
218 | } |
||
219 | |||
220 | return result; |
||
221 | } |
||
222 | |||
223 | /// <summary> |
||
224 | /// 사용자 정보 목록 |
||
225 | /// </summary> |
||
226 | /// <param name="pId">프로젝트 ID</param> |
||
227 | /// <param name="dId">Document ID</param> |
||
228 | /// <returns></returns> |
||
229 | public List<UserInfo> GetUserInfoItems(IEnumerable<string> userIdList) |
||
230 | { |
||
231 | List<UserInfo> result = new List<UserInfo>(); |
||
232 | |||
233 | try |
||
234 | { |
||
235 | /// uIds=U00000000006&uIds=U00000000005 |
||
236 | string param = string.Join("&",userIdList.Select(x => $"uIds={x}")); |
||
237 | |||
238 | var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/userinfo?{param}"); |
||
239 | |||
240 | if (jsonObj != null) |
||
241 | { |
||
242 | JArray array = JArray.Parse(jsonObj, new JsonLoadSettings()); |
||
243 | |||
244 | foreach (var item in array) |
||
245 | { |
||
246 | result.Add(new UserInfo |
||
247 | { |
||
248 | name = item["name"]?.ToObject<string>(), |
||
249 | email = item["email"]?.ToObject<string>(), |
||
250 | deptCode = item["deptCode"]?.ToObject<string>(), |
||
251 | deptName = item["deptName"]?.ToObject<string>() |
||
252 | }); |
||
253 | } |
||
254 | } |
||
255 | } |
||
256 | catch (Exception ex) |
||
257 | { |
||
258 | throw new Exception("GetUserInfoItems", ex); |
||
259 | } |
||
260 | |||
261 | return result; |
||
262 | } |
||
263 | |||
264 | private string GetWebClientString(string uri) |
||
265 | { |
||
266 | try |
||
267 | { |
||
268 | using (System.Net.WebClient client = new System.Net.WebClient { Encoding = System.Text.Encoding.UTF8 }) |
||
269 | { |
||
270 | var result = client.DownloadString(uri); |
||
271 | |||
272 | if (string.IsNullOrWhiteSpace(result.Replace("{", "").Replace("}", ""))) |
||
273 | { |
||
274 | return null; |
||
275 | } |
||
276 | else |
||
277 | { |
||
278 | return result; |
||
279 | } |
||
280 | } |
||
281 | } |
||
282 | catch (Exception ex) |
||
283 | { |
||
284 | return null; |
||
285 | } |
||
286 | } |
||
287 | 84190963 | taeseongkim | |
288 | private string SetWebClientString(string uri, NameValueCollection valus) |
||
289 | { |
||
290 | try |
||
291 | { |
||
292 | using (System.Net.WebClient client = new System.Net.WebClient { Encoding = System.Text.Encoding.UTF8 }) |
||
293 | { |
||
294 | var response = client.UploadValues(uri,valus); |
||
295 | |||
296 | var result = System.Text.Encoding.UTF8.GetString(response); |
||
297 | |||
298 | if (string.IsNullOrWhiteSpace(result.Replace("{", "").Replace("}", ""))) |
||
299 | { |
||
300 | return null; |
||
301 | } |
||
302 | else |
||
303 | { |
||
304 | return result; |
||
305 | } |
||
306 | } |
||
307 | } |
||
308 | catch (Exception ex) |
||
309 | { |
||
310 | return null; |
||
311 | } |
||
312 | } |
||
313 | |||
314 | c47493ca | taeseongkim | private string DeleteWebClientString(string baseUri, string RestApi, NameValueCollection data) |
315 | 84190963 | taeseongkim | { |
316 | try |
||
317 | { |
||
318 | using (var client = new HttpClient()) |
||
319 | { |
||
320 | c47493ca | taeseongkim | client.BaseAddress = new Uri(baseUri); |
321 | client.DefaultRequestHeaders.Accept.Clear(); |
||
322 | client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); |
||
323 | |||
324 | var response = client.SendAsync(new HttpRequestMessage(HttpMethod.Delete, RestApi) |
||
325 | { |
||
326 | Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(data), System.Text.Encoding.UTF8, "application/json") |
||
327 | }); |
||
328 | 84190963 | taeseongkim | |
329 | var result = response.Result; |
||
330 | |||
331 | return result.IsSuccessStatusCode.ToString(); |
||
332 | } |
||
333 | } |
||
334 | catch (Exception ex) |
||
335 | { |
||
336 | return null; |
||
337 | } |
||
338 | } |
||
339 | 0f6604ce | taeseongkim | } |
340 | } |