Skip to content
This repository has been archived by the owner on Jun 14, 2020. It is now read-only.

Commit

Permalink
Remove TryParse method
Browse files Browse the repository at this point in the history
  • Loading branch information
extremecodetv committed Aug 25, 2017
1 parent 77972ff commit d6a41bf
Showing 1 changed file with 0 additions and 94 deletions.
94 changes: 0 additions & 94 deletions src/SocksSharp/Proxy/ProxyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,98 +124,4 @@ public NetworkStream GetDestinationStream(string destinationHost, int destinatio
}

}

public static class ProxyClient
{
/// <summary>
/// Converts the string representation of a <see cref="ProxySettings"/>.
/// A return value indicates whether the conversion succeeded.
/// </summary>
/// <typeparam name="TOutput">Implementation of the <see cref="IProxy"/></typeparam>
/// <param name="proxy">A string containing proxy settings</param>
/// <param name="proxyClient">When this method returns,
/// contains the instance of the <see cref="ProxySettings"/> value equivalent of the number contained in proxy,
/// if the conversion succeeded, or <see cref="null"/> if the conversion failed.</param>
/// <returns><see cref="true"/> if s was converted successfully; otherwise, <see cref="false"/>.</returns>
/// <remarks>String must be in one of this format
/// host:port
/// - or -
/// host:port:username
/// - or -
/// host:port:username:password
/// </remarks>
public static bool TryParse<TOutput>(string proxy, out IProxyClient<TOutput> 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<TOutput>)Activator.CreateInstance(typeof(ProxyClient<TOutput>));
proxyClient.Settings = proxySettings;
}
catch
{
return false;
}

return true;
}
}
}

0 comments on commit d6a41bf

Please sign in to comment.