프로젝트

일반

사용자정보

개정판 3b938959

ID3b9389598593358f5f751e2d612ec6bb3960a522
상위 a8aec13a
하위 5639752b

김태성이(가) 11달 전에 추가함

issue #000000 검색 수정

Change-Id: I7ac25e17a0b62f753c52f52b8a77b73bb3bbe2bf

차이점 보기:

KCOM_API/MarkusService.svc.cs
1 1
using KCOMDataModel.DataModel;
2
using log4net;
3
using Newtonsoft.Json.Linq;
2 4
using System;
3 5
using System.Collections.Generic;
4 6
using System.Configuration;
......
15 17
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
16 18
    public class MarkusService : System.Web.Services.WebService
17 19
    {
20
        protected ILog logger = LogManager.GetLogger(typeof(MarkusService));
21

  
18 22
        [WebGet(UriTemplate = "AddMember?UserId={UserId}&Name={Name}&Company={Company}&Department={Department}&Position={Position}&email={email}", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
19 23
        [OperationContract]
20 24
        public AddMemberResults AddMember(string UserId,string Name, string Company, string Department,string Position,string email)
......
97 101

  
98 102
            return results;
99 103
        }
104

  
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

  
100 300
    }
101 301
}

내보내기 Unified diff

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