markus / ConvertService / ConverterService / ConvertionWebService / Conversion.asmx.cs @ 32e95118
이력 | 보기 | 이력해설 | 다운로드 (5.34 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Web; |
5 |
using System.Web.Services; |
6 |
using System.Runtime.Remoting.Channels; |
7 |
using System.Runtime.Remoting.Channels.Tcp; |
8 |
using IConverterPDF; |
9 |
using System.Text; |
10 |
using DeepViewDataModel.DataModel; |
11 |
using DeepViewDataModel.Common; |
12 |
using DeepView.Toolkit.GuidGenerator; |
13 |
|
14 |
namespace ConvertionWebService |
15 |
{ |
16 |
/// <summary> |
17 |
/// Summary description for Conversio |
18 |
/// </summary> |
19 |
[WebService(Namespace = "http://tempuri.org/")] |
20 |
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] |
21 |
[System.ComponentModel.ToolboxItem(false)] |
22 |
public class Conversion : System.Web.Services.WebService |
23 |
{ |
24 |
|
25 |
RemConverterPDFObject remObj = null; |
26 |
|
27 |
public Conversion() |
28 |
{ |
29 |
try |
30 |
{ |
31 |
System.Runtime.Remoting.Channels.IChannel _ch = ChannelServices.GetChannel("tcp"); |
32 |
|
33 |
if(_ch == null) |
34 |
{ |
35 |
TcpChannel chan = new TcpChannel(); |
36 |
ChannelServices.RegisterChannel(chan, false); |
37 |
} |
38 |
// Create an instance of the remote object |
39 |
remObj = (RemConverterPDFObject)Activator.GetObject(typeof(RemConverterPDFObject), |
40 |
Properties.Settings.Default.ConverterRemotingUrl); |
41 |
|
42 |
} |
43 |
catch (Exception ex) |
44 |
{ |
45 |
SendNotice(ex.ToString()); |
46 |
} |
47 |
} |
48 |
|
49 |
private void SendNotice(string ex) |
50 |
{ |
51 |
if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.ErrorNoticeID)) |
52 |
{ |
53 |
var _lstID = Properties.Settings.Default.ErrorNoticeID.Split(';').ToList(); |
54 |
//EmailClient.EmailClient _client = new EmailClient.EmailClient(_lstID.First()); |
55 |
StringBuilder _bl = new StringBuilder(); |
56 |
_bl.AppendLine("Conversion Web Service Error"); |
57 |
_bl.AppendLine(ex); |
58 |
//var _emailResult = _client.SendEmail(_lstID, _lstID, "<Conversion Web Service Error>", _bl.ToString(), false); |
59 |
} |
60 |
} |
61 |
|
62 |
[WebMethod] |
63 |
public string Run(string projNumber, string DocumentUrl, string ItemID) |
64 |
{ |
65 |
string _result = null; |
66 |
try |
67 |
{ |
68 |
using (DeepView_Entity deepViewEntity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
69 |
{ |
70 |
_result = ConnectStringBuilder.DeepViewConnectionString().ToString(); |
71 |
//var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber && DateTime.Parse(r.RUN_DATETIME)<= DateTime.Now); |
72 |
//var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO == projNumber); |
73 |
var _RunProjects = deepViewEntity.RUN_PROJECTS.Where(r => r.PROJECT_NO != null); |
74 |
|
75 |
if (_RunProjects.Count() > 0) |
76 |
{ |
77 |
_result = SendKcom(projNumber, DocumentUrl, ItemID); |
78 |
} |
79 |
else |
80 |
{ |
81 |
//_result = client.Run(projNumber, DocumentUrl); |
82 |
} |
83 |
} |
84 |
} |
85 |
catch (Exception ex) |
86 |
{ |
87 |
_result += "error"; |
88 |
SendNotice("Project NO : " + projNumber + "\r\n DocumentUrl : " + DocumentUrl + "\r\n Error" + ex.ToString()); |
89 |
} |
90 |
return _result; |
91 |
} |
92 |
|
93 |
private string SendKcom(string projNumber, string DocumentUrl, string ItemID) |
94 |
{ |
95 |
if (remObj == null) |
96 |
{ |
97 |
return "Window Service Connection Error"; |
98 |
} |
99 |
else |
100 |
{ |
101 |
string _id = GetGuid(0, GuidGenerator.GetUniqueGuid()).ToString(); |
102 |
|
103 |
using (DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString())) |
104 |
{ |
105 |
_entity.AddToCONVERTER_DOC(new CONVERTER_DOC |
106 |
{ |
107 |
ID = _id.ToString(), |
108 |
CREATE_DATETIME = DateTime.Now, |
109 |
DOCUMENT_URL = DocumentUrl, |
110 |
PROJECT_NO = projNumber, |
111 |
DOCUMENT_ID = ItemID, |
112 |
}); |
113 |
_entity.SaveChanges(); |
114 |
|
115 |
|
116 |
var _result = remObj.SetConverterPDF(projNumber, _id); |
117 |
|
118 |
if (_result.Exception != null) |
119 |
return "Window Service Error"; |
120 |
else |
121 |
return true.ToString(); |
122 |
} |
123 |
} |
124 |
} |
125 |
|
126 |
private Guid GetGuid(int Count,Guid ID) |
127 |
{ |
128 |
Guid _ID = ID; |
129 |
string _id = _ID.ToString(); |
130 |
DeepView_Entity _entity = new DeepView_Entity(ConnectStringBuilder.DeepViewConnectionString().ToString()); |
131 |
|
132 |
if (_entity.CONVERTER_DOC.Where(c => c.ID == _id).Count() > 0) |
133 |
{ |
134 |
_entity.Dispose(); |
135 |
|
136 |
if (Count > 10) |
137 |
{ |
138 |
new Exception("GetGuid : Not Generator"); |
139 |
} |
140 |
|
141 |
if (Count < 3) |
142 |
{ |
143 |
System.Threading.Thread.Sleep(3); |
144 |
} |
145 |
|
146 |
GetGuid(Count++,GuidGenerator.GetUniqueGuid()); |
147 |
} |
148 |
|
149 |
return ID; |
150 |
} |
151 |
} |
152 |
} |