From d6a41bf62e15be724bc28698915ada3f33fab960 Mon Sep 17 00:00:00 2001 From: ExtremeCodeTV Date: Fri, 25 Aug 2017 22:01:27 +0700 Subject: [PATCH] Remove TryParse method --- src/SocksSharp/Proxy/ProxyClient.cs | 94 ----------------------------- 1 file changed, 94 deletions(-) diff --git a/src/SocksSharp/Proxy/ProxyClient.cs b/src/SocksSharp/Proxy/ProxyClient.cs index db75943..5c6bb0b 100644 --- a/src/SocksSharp/Proxy/ProxyClient.cs +++ b/src/SocksSharp/Proxy/ProxyClient.cs @@ -124,98 +124,4 @@ public NetworkStream GetDestinationStream(string destinationHost, int destinatio } } - - public static class ProxyClient - { - /// - /// Converts the string representation of a . - /// A return value indicates whether the conversion succeeded. - /// - /// Implementation of the - /// A string containing proxy settings - /// When this method returns, - /// contains the instance of the value equivalent of the number contained in proxy, - /// if the conversion succeeded, or if the conversion failed. - /// if s was converted successfully; otherwise, . - /// String must be in one of this format - /// host:port - /// - or - - /// host:port:username - /// - or - - /// host:port:username:password - /// - public static bool TryParse(string proxy, out IProxyClient proxyClient) where TOutput : IProxy - { - NetworkCredential credential = null; - - proxyClient = null; - - #region Parse Address - - if (String.IsNullOrEmpty(proxy)) - { - return false; - } - - string[] values = proxy.Split(':'); - - int port = 1080; - string host = values[0]; - - if (values.Length >= 2) - { - if (!int.TryParse(values[1], out port)) - { - return false; - } - } - #endregion - - #region Parse Credential - - string username = String.Empty; - string password = String.Empty; - - if (values.Length >= 3) - { - credential = new NetworkCredential(); - - username = values[2]; - - if (values.Length >= 4) - { - password = values[3]; - } - - if (!String.IsNullOrEmpty(username)) - { - credential.UserName = username; - } - - if (!String.IsNullOrEmpty(password)) - { - credential.Password = password; - } - } - - #endregion - - var proxySettings = new ProxySettings(); - proxySettings.Host = host; - proxySettings.Port = port; - proxySettings.Credentials = credential; - - try - { - proxyClient = (IProxyClient)Activator.CreateInstance(typeof(ProxyClient)); - proxyClient.Settings = proxySettings; - } - catch - { - return false; - } - - return true; - } - } } \ No newline at end of file