프로젝트

일반

사용자정보

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

markus / PemssAPI / PemssApi.cs @ 0f6604ce

이력 | 보기 | 이력해설 | 다운로드 (7.93 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

    
8
namespace KCOM_API
9
{
10
    public class PemssApi : IDisposable
11
    {
12
        private string gPemssUri;
13

    
14
        public PemssApi(string PemssApiUri)
15
        {
16
            gPemssUri = PemssApiUri;
17
        }
18

    
19
        public void Dispose()
20
        {
21
        }
22

    
23
        /// <summary>
24
        /// 정합성 목록
25
        /// </summary>
26
        /// <param name="pId">프로젝트 ID</param>
27
        /// <param name="dId">Document ID</param>
28
        /// <returns></returns>
29
        public List<Requirement> GetRequirementItems(string pId,string dId)
30
        {
31
            List<Requirement> result = new List<Requirement>();
32

    
33
            try
34
            {
35
                var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/list/requirement?pId={pId}&dId={dId}");
36

    
37
                if (jsonObj != null)
38
                {
39
                    JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings());
40

    
41
                    foreach (var item in JArray.Parse(jObject["rows"].ToString()))
42
                    {
43
                        result.Add(new Requirement
44
                        {
45
                            mdId = item["mdId"]?.ToObject<string>(),
46
                            mdText = item["mdText"]?.ToObject<string>(),
47
                            mrComments = new List<Commant>()
48
                        });
49
                    }
50
                }
51
            }
52
            catch (Exception ex)
53
            {
54
                throw new Exception("GetRequirementItems",ex);
55
            }
56
            
57
            return result;
58
        }
59

    
60
        /// <summary>
61
        /// 정합성 코멘트 등록
62
        /// </summary>
63
        /// <param name="pId">프로젝트 ID</param>
64
        /// <param name="dId">Document ID</param>
65
        /// <param name="mdId">MR 상세 아이템 ID</param>
66
        /// <param name="commentId"></param>
67
        /// <param name="comment"></param>
68
        /// <param name="condition"></param>
69
        /// <param name="uId"></param>
70
        /// <returns></returns>
71
        public bool SetRequirementComment(string pId, string dId,string mdId, string commentId,string comment,bool condition,string uId)
72
        {
73
            bool result = false;
74

    
75
            try
76
            {
77
                //http://pemss.i-on.net/rest/ext/comment/requirement?dId=116&mdId=MD0000000352&commentId=1&comment=test&condition=true&uId=admin
78

    
79
                var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/comment/requirement?" 
80
                                    + $"dId={dId}&mdId={mdId}&commentId={commentId}&comment={comment}&condition={condition}&uId={uId}");
81
                if (jsonObj != null)
82
                {
83
                    JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings());
84

    
85
                    if (jObject.Property("status") != null)
86
                    {
87
                        result = jObject.Property("status").ToObject<bool>();
88
                    }
89
                }
90
            }
91
            catch (Exception ex)
92
            {
93
                throw new Exception("SetRequirementComment", ex);
94
            }
95

    
96
            return result;
97
        }
98

    
99
        /// <summary>
100
        /// 정합성 코멘트 삭제
101
        /// </summary>
102
        /// <param name="pId">프로젝트 ID</param>
103
        /// <param name="dId">Document ID</param>
104
        /// <param name="mdId">MR 상세 아이템 ID</param>
105
        /// <param name="commentId"></param>
106
        /// <param name="uId"></param>
107
        /// <returns></returns>
108
        public bool RemoveRequirementComment(string pId, string dId, string mdId, string commentId, string uId)
109
        {
110
            bool result = false;
111

    
112
            try
113
            {
114
                //http://pemss.i-on.net/rest/ext/comment/requirement?dId=116&mdId=MD0000000352&commentId=1&uId=유저아이디
115
              
116
                var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/comment/requirement?dId={dId}&mdId={mdId}&commentId={commentId}&uId={uId}");
117

    
118
                if (jsonObj != null)
119
                {
120
                    JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings());
121

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

    
133
            return result;
134
        }
135

    
136
        /// <summary>
137
        /// 문서 정보
138
        /// </summary>
139
        /// <param name="pId">프로젝트 ID</param>
140
        /// <param name="dId">Document ID</param>
141
        /// <returns></returns>
142
        public DocumentInfo GetDocumentInfo(string pId, string dId)
143
        {
144
            DocumentInfo result = null;
145

    
146
            try
147
            {
148
                var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/docinfo?pId={pId}&dId={dId}");
149

    
150
                if (jsonObj != null)
151
                {
152
                    JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings());
153

    
154
                    result = new DocumentInfo
155
                    {
156
                        slipNo = jObject.Property("slipNo")?.Value?.ToString(),
157
                        dId = jObject.Property("dId").HasValues ? jObject.Property("dId").ToObject<int>() : -1,
158
                        docName = jObject.Property("docName")?.Value?.ToString(),
159
                        fileName = jObject.Property("fileName")?.Value?.ToString(),
160
                        revision = jObject.Property("revision")?.Value?.ToString()
161
                    };
162
                }
163
            }
164
            catch (Exception ex)
165
            {
166
                throw new Exception("GetDocumentInfo",ex);
167
            }
168
            
169
            return result;
170
        }
171

    
172
        /// <summary>
173
        /// 사용자 정보 목록
174
        /// </summary>
175
        /// <param name="pId">프로젝트 ID</param>
176
        /// <param name="dId">Document ID</param>
177
        /// <returns></returns>
178
        public List<UserInfo> GetUserInfoItems(IEnumerable<string> userIdList)
179
        {
180
            List<UserInfo> result = new List<UserInfo>();
181

    
182
            try
183
            {
184
                /// uIds=U00000000006&uIds=U00000000005
185
                string param = string.Join("&",userIdList.Select(x => $"uIds={x}"));
186

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

    
189
                if (jsonObj != null)
190
                {
191
                    JArray array = JArray.Parse(jsonObj, new JsonLoadSettings());
192

    
193
                    foreach (var item in array)
194
                    {
195
                        result.Add(new UserInfo
196
                        {
197
                            name = item["name"]?.ToObject<string>(),
198
                            email = item["email"]?.ToObject<string>(),
199
                            deptCode = item["deptCode"]?.ToObject<string>(),
200
                            deptName = item["deptName"]?.ToObject<string>()
201
                        });
202
                    }
203
                }
204
            }
205
            catch (Exception ex)
206
            {
207
                throw new Exception("GetUserInfoItems", ex);
208
            }
209

    
210
            return result;
211
        }
212

    
213
        private string GetWebClientString(string uri)
214
        {
215
            try
216
            {
217
                using (System.Net.WebClient client = new System.Net.WebClient { Encoding = System.Text.Encoding.UTF8 })
218
                {
219
                    var result = client.DownloadString(uri);
220

    
221
                    if (string.IsNullOrWhiteSpace(result.Replace("{", "").Replace("}", "")))
222
                    {
223
                        return null;
224
                    }
225
                    else
226
                    {
227
                        return result;
228
                    }
229
                }
230
            }
231
            catch (Exception ex)
232
            {
233
                return null;
234
            }
235
        }
236
    }
237
}
클립보드 이미지 추가 (최대 크기: 500 MB)