Пример #1
0
        public static async Task <Queue <ProxyStruct> > GetProxyList(string fileName = "Proxy.txt")
        {
            var list = new Queue <ProxyStruct>();
            var rows = File.ReadAllLines(fileName);

            try
            {
                foreach (var str in rows.Select(row => row.Split('|')).Select(arr => new ProxyStruct
                {
                    Host = arr[0],
                    Login = arr[1],
                    Type = (ProxyType)Enum.Parse(typeof(ProxyType), arr[2])
                }))
                {
                    var t = await GetProxyStruct(str);

                    while (t.Count > 0)
                    {
                        list.Enqueue(t.Dequeue());
                    }
                }
            }
            catch (Exception ex)
            {
                Informer.RaiseOnResultReceived(ex.Message);
            }

            return(list);
        }
Пример #2
0
        public static async Task <HttpRequest> GetRequestTaskAsync(ProxyStruct str)
        {
            var req = GetRequest;

            return(await Task.Run(() =>
            {
                try
                {
                    var host = str.Host;
                    var login = str.Login;
                    var type = str.Type;

                    if (string.IsNullOrEmpty(host) || !host.Contains(":"))
                    {
                        return req;
                    }

                    var arr = host.Split(':');
                    switch (type)
                    {
                    case ProxyType.Http:
                        req.Proxy = new HttpProxyClient(arr[0], int.Parse(arr[1]));
                        break;

                    case ProxyType.Socks4:
                        req.Proxy = new Socks4ProxyClient(arr[0], int.Parse(arr[1]));
                        break;

                    case ProxyType.Socks4a:
                        req.Proxy = new Socks4aProxyClient(arr[0], int.Parse(arr[1]));
                        break;

                    case ProxyType.Socks5:
                        req.Proxy = new Socks5ProxyClient(arr[0], int.Parse(arr[1]));
                        break;

                    default:
                        req.Proxy = new HttpProxyClient(arr[0], int.Parse(arr[1]));
                        break;
                    }

                    if (!string.IsNullOrEmpty(login) && login.Contains(":"))
                    {
                        var arrr = login.Split(':');
                        req.Proxy.Username = arrr[0];
                        req.Proxy.Password = arrr[1];
                    }
                }
                catch (Exception ex)
                {
                    Informer.RaiseOnResultReceived(ex.Message);
                }
                return req;
            }));
        }