-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommunication.cs
More file actions
103 lines (89 loc) · 2.54 KB
/
Copy pathCommunication.cs
File metadata and controls
103 lines (89 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.IO;
using System.Text;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
namespace IconCMO
{
public static class HttpRequestHandler
{
public static HttpWebResponse SendRequest(string httpRequest)
{
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("https://secure3.iconcmo.com/api/");
request.ContentType = "application/xml";
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";
byte[] postBytes = Encoding.ASCII.GetBytes(httpRequest);
request.ContentLength = postBytes.Length;
ServicePointManager.ServerCertificateValidationCallback = Validator;
Stream requestStream = null;
try
{
requestStream = request.GetRequestStream();
}
catch (WebException e)
{
}
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
return response;
}
public static bool Validator(object sender, X509Certificate certificate,
X509Chain chain, SslPolicyErrors sslErrs)
{
return true;
}
public static string BuildRequest(string requestData, IconFilter _filter, IconAuth _auth, IconSort _sort)
{
string filter, sort;
if (_filter == null)
filter = string.Empty;
else
filter = _filter.GetFilterXML();
if (_sort == null)
sort = string.Empty;
else
sort = _sort.GetSortXML();
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<Icon>" +
_auth.GetAuthXML() +
"<Request>" +
requestData +
filter +
sort +
"</Request>" +
"</Icon>";
}
public static void GetSession(XmlDocument doc, ref IconAuth _auth)
{
XmlNode node = doc.SelectSingleNode("/iconresponse/session");
_auth.Session = node.InnerText;
}
}
public class ImageDownloader
{
private Collection<string> imageList;
private string localImageCache;
public ImageDownloader(Collection<string> _imageList, string _localImageCache)
{
imageList = _imageList;
localImageCache = _localImageCache;
}
public void DownloadImages()
{
WebClient client = new WebClient();
foreach (string image in imageList)
{
string targetFile = localImageCache + Path.DirectorySeparatorChar + Path.GetFileName(image);
if (!File.Exists(targetFile))
client.DownloadFile(new Uri(image), targetFile);
}
}
}
}