프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / PemssAPI / PemssApi.cs @ 84190963

이력 | 보기 | 이력해설 | 다운로드 (11.4 KB)

1
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
using System.Collections.Specialized;
8
using System.Net.Http;
9

    
10
namespace KCOM_API
11
{
12
    /// <summary>
13
    /// 등록은 POST, 삭제시 DELETE , LIST 는 GET 으로 호출해야 합니다.
14
    /// </summary>
15
    public class PemssApi : IDisposable
16
    {
17
        private string gPemssUri;
18

    
19
        public PemssApi(string PemssApiUri)
20
        {
21
            gPemssUri = PemssApiUri;
22
        }
23

    
24
        public void Dispose()
25
        {
26
        }
27

    
28
        /// <summary>
29
        /// 정합성 목록
30
        /// </summary>
31
        /// <param name="pId">프로젝트 ID</param>
32
        /// <param name="dId">Document ID</param>
33
        /// <returns></returns>
34
        public List<Requirement> GetRequirementItems(string pId,string dId)
35
        {
36
            List<Requirement> result = new List<Requirement>();
37

    
38
            try
39
            {
40
                var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/list/requirement?pId={pId}&dId={dId}");
41

    
42
                if (jsonObj != null)
43
                {
44
                    JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings());
45

    
46
                    foreach (var item in JArray.Parse(jObject["rows"].ToString()))
47
                    {
48
                        List<VpCommant> VpComments = new List<VpCommant>();
49

    
50
                        if (item["vpComments"].HasValues)
51
                        {
52
                            var comments = JArray.Parse(item["vpComments"].ToString());
53

    
54
                            foreach (var comment in comments)
55
                            {
56
                                VpComments.Add(new VpCommant
57
                                {
58
                                    mdId = item["mdId"]?.ToObject<string>(),
59
                                    created = comment["created"]?.ToObject<string>(),
60
                                    comment = comment["comment"]?.ToObject<string>(),
61
                                    commentId = comment["commentId"]?.ToObject<string>(),
62
                                    condition = comment["condition"].HasValues ? comment["condition"].ToObject<bool>() : false,
63
                                    createdBy  = comment["createdBy"]?.ToObject<string>(),
64
                                    createdByName = comment["createdByName"]?.ToObject<string>(),
65
                                });
66
                            }
67
                        }
68

    
69
                        result.Add(new Requirement
70
                        {
71
                            mdId = item["mdId"]?.ToObject<string>(),
72
                            mdText = item["mdText"]?.ToObject<string>(),
73
                            MrComments = new List<MrCommant>(),
74
                            VpComments = VpComments
75
                        });
76

    
77

    
78
                    }
79
                }
80
            }
81
            catch (Exception ex)
82
            {
83
                throw new Exception("GetRequirementItems",ex);
84
            }
85
            
86
            return result;
87
        }
88

    
89
        /// <summary>
90
        /// 정합성 코멘트 등록
91
        /// </summary>
92
        /// <param name="pId">프로젝트 ID</param>
93
        /// <param name="dId">Document ID</param>
94
        /// <param name="mdId">MR 상세 아이템 ID</param>
95
        /// <param name="commentId"></param>
96
        /// <param name="comment"></param>
97
        /// <param name="condition"></param>
98
        /// <param name="uId"></param>
99
        /// <returns></returns>
100
        public bool SetRequirementComment(string pId, string dId,string mdId, string commentId,string comment,bool condition,string uId)
101
        {
102
            bool result = false;
103

    
104
            try
105
            {
106
                //http://pemss.i-on.net/rest/ext/comment/requirement?dId=116&mdId=MD0000000352&commentId=1&comment=test&condition=true&uId=admin
107

    
108
                var values = new NameValueCollection(){
109
                    { "dId",dId},
110
                    { "mdId", mdId},
111
                    { "commentId" , commentId},
112
                    { "comment" ,comment},
113
                    { "condition" ,condition.ToString()},
114
                    { "uId", uId}
115
                };
116

    
117
                var jsonObj = SetWebClientString($"{gPemssUri}/rest/ext/comment/requirement", values);
118
                //var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/comment/requirement?"
119
                //                    + $"dId={dId}&mdId={mdId}&commentId={commentId}&comment={comment}&condition={condition}&uId={uId}");
120

    
121
                if (jsonObj != null)
122
                {
123
                    JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings());
124

    
125
                    if (jObject.Property("status") != null)
126
                    {
127
                        result = jObject.Property("status").ToObject<bool>();
128
                    }
129
                }
130
            }
131
            catch (Exception ex)
132
            {
133
                throw new Exception("SetRequirementComment", ex);
134
            }
135

    
136
            return result;
137
        }
138

    
139
        /// <summary>
140
        /// 정합성 코멘트 삭제
141
        /// </summary>
142
        /// <param name="pId">프로젝트 ID</param>
143
        /// <param name="dId">Document ID</param>
144
        /// <param name="mdId">MR 상세 아이템 ID</param>
145
        /// <param name="commentId"></param>
146
        /// <param name="uId"></param>
147
        /// <returns></returns>
148
        public bool RemoveRequirementComment(string pId, string dId, string mdId, string commentId, string uId)
149
        {
150
            bool result = false;
151

    
152
            try
153
            {
154
                //http://pemss.i-on.net/rest/ext/comment/requirement?dId=116&mdId=MD0000000352&commentId=1&uId=유저아이디
155

    
156
                var values = new NameValueCollection(){
157
                    { "dId",dId},
158
                    { "mdId", mdId},
159
                    { "commentId" , commentId},
160
                    { "uId", uId}
161
                };
162

    
163
                var jsonObj = DeleteWebClientString($"{gPemssUri}/rest/ext/comment/requirement"
164
                                    + $"dId={dId}&mdId={mdId}&commentId={commentId}&uId={uId}");
165

    
166
                // var jsonObj = DeleteWebClientString($"{gPemssUri}/rest/ext/comment/requirement", values);
167

    
168
                if (jsonObj != null)
169
                {
170
                    JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings());
171

    
172
                    if (jObject.Property("status") != null)
173
                    {
174
                        result = jObject.Property("status").ToObject<bool>();
175
                    }
176
                }
177
            }
178
            catch (Exception ex)
179
            {
180
                throw new Exception("RemoveRequirementComment", ex);
181
            }
182

    
183
            return result;
184
        }
185

    
186
        /// <summary>
187
        /// 문서 정보
188
        /// </summary>
189
        /// <param name="pId">프로젝트 ID</param>
190
        /// <param name="dId">Document ID</param>
191
        /// <returns></returns>
192
        public DocumentInfo GetDocumentInfo(string pId, string dId)
193
        {
194
            DocumentInfo result = null;
195

    
196
            try
197
            {
198
                var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/docinfo?pId={pId}&dId={dId}");
199

    
200
                if (jsonObj != null)
201
                {
202
                    JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings());
203

    
204
                    result = new DocumentInfo
205
                    {
206
                        slipNo = jObject.Property("slipNo")?.Value?.ToString(),
207
                        dId = jObject.Property("dId").HasValues ? jObject.Property("dId").ToObject<int>() : -1,
208
                        docName = jObject.Property("docName")?.Value?.ToString(),
209
                        fileName = jObject.Property("fileName")?.Value?.ToString(),
210
                        revision = jObject.Property("revision")?.Value?.ToString()
211
                    };
212
                }
213
            }
214
            catch (Exception ex)
215
            {
216
                throw new Exception("GetDocumentInfo",ex);
217
            }
218
            
219
            return result;
220
        }
221

    
222
        /// <summary>
223
        /// 사용자 정보 목록
224
        /// </summary>
225
        /// <param name="pId">프로젝트 ID</param>
226
        /// <param name="dId">Document ID</param>
227
        /// <returns></returns>
228
        public List<UserInfo> GetUserInfoItems(IEnumerable<string> userIdList)
229
        {
230
            List<UserInfo> result = new List<UserInfo>();
231

    
232
            try
233
            {
234
                /// uIds=U00000000006&uIds=U00000000005
235
                string param = string.Join("&",userIdList.Select(x => $"uIds={x}"));
236

    
237
                var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/userinfo?{param}");
238

    
239
                if (jsonObj != null)
240
                {
241
                    JArray array = JArray.Parse(jsonObj, new JsonLoadSettings());
242

    
243
                    foreach (var item in array)
244
                    {
245
                        result.Add(new UserInfo
246
                        {
247
                            name = item["name"]?.ToObject<string>(),
248
                            email = item["email"]?.ToObject<string>(),
249
                            deptCode = item["deptCode"]?.ToObject<string>(),
250
                            deptName = item["deptName"]?.ToObject<string>()
251
                        });
252
                    }
253
                }
254
            }
255
            catch (Exception ex)
256
            {
257
                throw new Exception("GetUserInfoItems", ex);
258
            }
259

    
260
            return result;
261
        }
262

    
263
        private string GetWebClientString(string uri)
264
        {
265
            try
266
            {
267
                using (System.Net.WebClient client = new System.Net.WebClient { Encoding = System.Text.Encoding.UTF8 })
268
                {
269
                    var result = client.DownloadString(uri);
270

    
271
                    if (string.IsNullOrWhiteSpace(result.Replace("{", "").Replace("}", "")))
272
                    {
273
                        return null;
274
                    }
275
                    else
276
                    {
277
                        return result;
278
                    }
279
                }
280
            }
281
            catch (Exception ex)
282
            {
283
                return null;
284
            }
285
        }
286

    
287
        private string SetWebClientString(string uri, NameValueCollection valus)
288
        {
289
            try
290
            {
291
                using (System.Net.WebClient client = new System.Net.WebClient { Encoding = System.Text.Encoding.UTF8 })
292
                {
293
                    var response = client.UploadValues(uri,valus);
294

    
295
                    var result = System.Text.Encoding.UTF8.GetString(response);
296

    
297
                    if (string.IsNullOrWhiteSpace(result.Replace("{", "").Replace("}", "")))
298
                    {
299
                        return null;
300
                    }
301
                    else
302
                    {
303
                        return result;
304
                    }
305
                }
306
            }
307
            catch (Exception ex)
308
            {
309
                return null;
310
            }
311
        }
312

    
313
        private string DeleteWebClientString(string uri)
314
        {
315
            try
316
            {
317
                using (var client = new HttpClient())
318
                {
319
                    var response = client.DeleteAsync(uri);
320

    
321
                    var result = response.Result;
322

    
323
                        return result.IsSuccessStatusCode.ToString();
324
                }
325
            }
326
            catch (Exception ex)
327
            {
328
                return null;
329
            }
330
        }
331
    }
332
}
클립보드 이미지 추가 (최대 크기: 500 MB)