-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientFactory.cs
64 lines (59 loc) · 2.16 KB
/
ClientFactory.cs
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
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using TAC_Grabber.Clients;
namespace TAC_Grabber
{
static class ClientsFactory
{
private static readonly Dictionary<int, BaseHTTPClient[]> _cache = new Dictionary<int, BaseHTTPClient[]>();
private static BaseHTTPClient[] CreateClients(HttpMessageInvoker httpClient)
{
return new BaseHTTPClient[]
{
new XinitClient(httpClient),
new TMobileClient(httpClient),
new ESTMobileClient(httpClient),
new CricketWirelessClient(httpClient),
new UScellularClient(httpClient),
new UltraMobileClient(httpClient)
};
}
public static BaseHTTPClient[] CreateClients(int proxyPort = -1)
{
if (_cache.TryGetValue(proxyPort, out BaseHTTPClient[] clients))
{
_cache[proxyPort] = clients;
return _cache[proxyPort];
}
else
{
IWebProxy proxy = null;
if (proxyPort >0)
{
proxy = new WebProxy("127.0.0.1", proxyPort);
}
SocketsHttpHandler handler = new SocketsHttpHandler
{
Proxy = proxy,
UseProxy = (proxy != null),
UseCookies = false,
AllowAutoRedirect = false
};
HttpClient httpClient = new HttpClient(handler);
httpClient.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (compatible;)");
_cache[proxyPort] = CreateClients(httpClient);
return _cache[proxyPort];
}
}
public static Dictionary<string, BaseHTTPClient[]> GetClientsGroupByType()
{
return _cache.Values.SelectMany(x => x).GroupBy(x => x.GetType()).ToDictionary(x=>x.Key.Name,x=>x.ToArray());
}
public static Dictionary<int, BaseHTTPClient[]> GetClientsGroupByPort()
{
return _cache;
}
}
}