Advertisement
Guest User

Untitled

a guest
Jan 30th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Turbocharged.Beanstalk
  8. {
  9. public class ExtendConnectionConfiguration
  10. {
  11. public string Hostname { get; set; }
  12. public int Port { get; set; }
  13. public string ProxyHostname { get; set; }
  14. public int ProxyPort { get; set; }
  15. public string ProxyUsername { get; set; }
  16. public string ProxyPassword { get; set; }
  17.  
  18. public IJobSerializer JobSerializer { get; set; }
  19.  
  20. public ExtendConnectionConfiguration()
  21. {
  22. JobSerializer = new NewtonsoftJsonJobSerializer();
  23. }
  24.  
  25. public static ExtendConnectionConfiguration Parse(string hostConnectionString)
  26. {
  27. return ExtendConnectionConfiguration.Parse(hostConnectionString, "");
  28. }
  29.  
  30. public static ExtendConnectionConfiguration Parse(string hostConnectionString, string proxyConnectionString)
  31. {
  32. var hostParts = hostConnectionString.Split(':');
  33. var proxyParts = proxyConnectionString.Split(':');
  34. return new ExtendConnectionConfiguration
  35. {
  36. Hostname = hostParts[0].Trim(),
  37. Port = Convert.ToInt32(hostParts[1].Trim()),
  38. ProxyHostname = (proxyParts.Length > 0 && proxyParts[0] != null) ? proxyParts[0] : "",
  39. ProxyPort = (proxyParts.Length > 1 && proxyParts[1] != null) ? Convert.ToInt32(proxyParts[1].Trim()) : 0,
  40. ProxyUsername = (proxyParts.Length > 2 && proxyParts[2] != null) ? proxyParts[2] : "",
  41. ProxyPassword = (proxyParts.Length > 3 && proxyParts[3] != null) ? proxyParts[3] : ""
  42. };
  43. }
  44.  
  45. public override string ToString()
  46. {
  47. return "Host={0}:{1}; Proxy={2}:{3}; ProxyCredential={4}:{5}; JobSerializer={6}".FormatWith(
  48. Hostname,
  49. Port,
  50. ProxyHostname,
  51. ProxyPort,
  52. ProxyUsername,
  53. ProxyPassword,
  54. JobSerializer == null ? "null" : JobSerializer.GetType().Name);
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement