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 |
fdfa126d
|
taeseongkim
|
var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == prj_No).ToList();
|
121 |
3b938959
|
taeseongkim
|
|
122 |
fdfa126d
|
taeseongkim
|
if (_RunProjects.Count() == 0)
|
123 |
3b938959
|
taeseongkim
|
{
|
124 |
fdfa126d
|
taeseongkim
|
deepViewEntity.RUN_PROJECTS.AddObject(new RUN_PROJECTS { PROJECT_NO = prj_No, IS_ACTIVITY = 1, PROJECT_NAME = "", RUN_DATETIME = DateTime.Today });
|
125 |
|
|
|
126 |
|
|
var items = deepViewEntity.PROPERTIES.Where(x => x.PROPERTY == "SAMPLEPRJ");
|
127 |
|
|
|
128 |
|
|
foreach (var item in items)
|
129 |
|
|
{
|
130 |
|
|
deepViewEntity.PROPERTIES.AddObject(new PROPERTIES { TYPE = item.TYPE, PROPERTY = prj_No, VALUE = item.VALUE });
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
deepViewEntity.SaveChanges();
|
134 |
3b938959
|
taeseongkim
|
}
|
135 |
|
|
}
|
136 |
fdfa126d
|
taeseongkim
|
|
137 |
|
|
_result = SendKcom(rev_No, document_No, document_Name, group_No, prj_No, document_Id, document_Url);
|
138 |
3b938959
|
taeseongkim
|
}
|
139 |
|
|
catch (Exception ex)
|
140 |
|
|
{
|
141 |
|
|
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);
|
142 |
fdfa126d
|
taeseongkim
|
_result = "Error";
|
143 |
3b938959
|
taeseongkim
|
}
|
144 |
|
|
return _result;
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
private string SendKcom(string rev_No, string document_No, string document_Name, string group_No, string prj_No, string document_Id, string document_Url)
|
149 |
|
|
{
|
150 |
|
|
string result = false.ToString();
|
151 |
|
|
|
152 |
|
|
//string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString();
|
153 |
|
|
string _id = shortGuid();
|
154 |
fdfa126d
|
taeseongkim
|
string _doc_id = document_Id;// ((UInt32)document_Id.GetHashCode()).ToString();
|
155 |
3b938959
|
taeseongkim
|
|
156 |
|
|
string sCIConnString = ConfigurationManager.ConnectionStrings["CIConnectionString"].ConnectionString;
|
157 |
|
|
using (CIEntities _kcomEntity = new CIEntities(sCIConnString))
|
158 |
|
|
{
|
159 |
|
|
if (string.IsNullOrEmpty(group_No))
|
160 |
|
|
{
|
161 |
|
|
group_No = "0";
|
162 |
|
|
}
|
163 |
fdfa126d
|
taeseongkim
|
//if (!document_Url.ToLower().Contains("http%3a%2f%2f"))
|
164 |
|
|
//{
|
165 |
|
|
// document_Url = Base64Decode(document_Url);
|
166 |
|
|
// document_Url = System.Net.WebUtility.UrlEncode(document_Url);
|
167 |
|
|
//}
|
168 |
|
|
//document_Name = Base64DecodeFromStr(document_Name);
|
169 |
3b938959
|
taeseongkim
|
|
170 |
|
|
var doc = _kcomEntity.DOCUMENT_ITEM.Where(d => d.PROJECT_NO == prj_No && d.ID == document_Id).FirstOrDefault();
|
171 |
|
|
if (doc != null)
|
172 |
|
|
{
|
173 |
|
|
doc.DOCUMENT_ID = _doc_id;
|
174 |
|
|
doc.REVISION = rev_No;
|
175 |
|
|
doc.GROUP_NO = group_No;
|
176 |
|
|
doc.DOCUMENT_NO = document_No;
|
177 |
|
|
doc.DOCUMENT_NAME = document_Name;
|
178 |
|
|
doc.ORIGINAL_FILE = document_Url;
|
179 |
|
|
}
|
180 |
|
|
else
|
181 |
|
|
{
|
182 |
|
|
_kcomEntity.AddToDOCUMENT_ITEM(new DOCUMENT_ITEM
|
183 |
|
|
{
|
184 |
|
|
ID = document_Id,
|
185 |
|
|
REVISION = rev_No,
|
186 |
|
|
DOCUMENT_NO = document_No,
|
187 |
|
|
DOCUMENT_NAME = document_Name,
|
188 |
|
|
GROUP_NO = group_No,
|
189 |
|
|
ORIGINAL_FILE = document_Url,
|
190 |
|
|
DOCUMENT_ID = _doc_id,
|
191 |
|
|
PROJECT_NO = prj_No,
|
192 |
|
|
});
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
_kcomEntity.SaveChanges();
|
196 |
|
|
|
197 |
|
|
}
|
198 |
|
|
|
199 |
fdfa126d
|
taeseongkim
|
string sConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
|
200 |
|
|
using (KCOMEntities _entity = new KCOMEntities(sConnString))
|
201 |
|
|
{
|
202 |
|
|
_entity.AddToCONVERTER_DOC(new CONVERTER_DOC
|
203 |
|
|
{
|
204 |
|
|
ID = _id,
|
205 |
|
|
CREATE_DATETIME = DateTime.Now,
|
206 |
|
|
DOCUMENT_URL = document_Url,
|
207 |
|
|
PROJECT_NO = prj_No,
|
208 |
|
|
DOCUMENT_ID = _doc_id,
|
209 |
|
|
});
|
210 |
|
|
|
211 |
|
|
_entity.SaveChanges();
|
212 |
|
|
}
|
213 |
3b938959
|
taeseongkim
|
|
214 |
|
|
try
|
215 |
|
|
{
|
216 |
|
|
System.Net.WebClient client = new System.Net.WebClient();
|
217 |
|
|
var convertResult = client.DownloadString($"{Properties.Settings.Default.CovnertService}/Rest/ConvertAdd?ProjectNo={prj_No}&ConvertID={_id}");
|
218 |
|
|
|
219 |
|
|
JObject jObject = JObject.Parse(convertResult, new JsonLoadSettings());
|
220 |
|
|
result = jObject["ConvertAddResult"].ToString();
|
221 |
|
|
}
|
222 |
|
|
catch (Exception ex)
|
223 |
|
|
{
|
224 |
|
|
logger.Error("Conversion Web Service SendKcom Error", ex);
|
225 |
fdfa126d
|
taeseongkim
|
result = $"Markus V3 Connect Error {ex.ToString()}";
|
226 |
3b938959
|
taeseongkim
|
}
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
return result;
|
230 |
|
|
}
|
231 |
|
|
|
232 |
|
|
public string Base64DecodeFromStr(string data)
|
233 |
|
|
{
|
234 |
|
|
try
|
235 |
|
|
{
|
236 |
|
|
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
|
237 |
|
|
System.Text.Decoder utf8Decode = encoder.GetDecoder();
|
238 |
|
|
|
239 |
|
|
byte[] todecode_byte = Convert.FromBase64String(data);
|
240 |
|
|
|
241 |
|
|
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
|
242 |
|
|
|
243 |
|
|
char[] decoded_char = new char[charCount];
|
244 |
|
|
|
245 |
|
|
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
|
246 |
|
|
|
247 |
|
|
string result = new String(decoded_char);
|
248 |
|
|
|
249 |
|
|
return result;
|
250 |
|
|
}
|
251 |
|
|
catch (Exception)
|
252 |
|
|
{
|
253 |
|
|
return data;
|
254 |
|
|
}
|
255 |
|
|
}
|
256 |
|
|
|
257 |
|
|
public string Base64Decode(string data)
|
258 |
|
|
{
|
259 |
|
|
try
|
260 |
|
|
{
|
261 |
|
|
if (data.Contains("http://"))
|
262 |
|
|
{
|
263 |
|
|
return data;
|
264 |
|
|
}
|
265 |
|
|
else
|
266 |
|
|
{
|
267 |
|
|
System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
|
268 |
|
|
System.Text.Decoder utf8Decode = encoder.GetDecoder();
|
269 |
|
|
|
270 |
|
|
byte[] todecode_byte = Convert.FromBase64String(data);
|
271 |
|
|
|
272 |
|
|
int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
|
273 |
|
|
|
274 |
|
|
char[] decoded_char = new char[charCount];
|
275 |
|
|
|
276 |
|
|
utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
|
277 |
|
|
|
278 |
|
|
string result = new String(decoded_char);
|
279 |
|
|
|
280 |
|
|
return result;
|
281 |
|
|
}
|
282 |
|
|
|
283 |
|
|
|
284 |
|
|
}
|
285 |
|
|
|
286 |
|
|
catch (Exception e)
|
287 |
|
|
{
|
288 |
|
|
throw new Exception("Error in Base64Decode: " + e.Message);
|
289 |
|
|
}
|
290 |
|
|
}
|
291 |
|
|
public string shortGuid()
|
292 |
|
|
{
|
293 |
|
|
byte[] bytes = new byte[16];
|
294 |
|
|
using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
|
295 |
|
|
{
|
296 |
|
|
provider.GetBytes(bytes);
|
297 |
|
|
}
|
298 |
|
|
|
299 |
|
|
var guid = new Guid(bytes);
|
300 |
|
|
|
301 |
|
|
return Convert.ToBase64String(guid.ToByteArray())
|
302 |
|
|
.Substring(0, 10)
|
303 |
|
|
.Replace("/", "")
|
304 |
|
|
.Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
|
305 |
|
|
}
|
306 |
|
|
|
307 |
c517099d
|
taeseongkim
|
}
|
308 |
|
|
} |