PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Visual Studio 2008/CSWebBrowserWithProxy/InternetProxy.cs

#
C# | 94 lines | 69 code | 8 blank | 17 comment | 5 complexity | 822332ddc46fa63c94eb43b5450e8ebe MD5 | raw file
  1. /****************************** Module Header ******************************\
  2. Module Name: InternetProxy.cs
  3. Project: CSWebBrowserWithProxy
  4. Copyright (c) Microsoft Corporation.
  5. This class is used to describe a proxy server and the credential to connect to it.
  6. Please set the proxy servers in ProxyList.xml first.
  7. This source is subject to the Microsoft Public License.
  8. See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
  9. All other rights reserved.
  10. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  11. EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
  12. WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
  13. \***************************************************************************/
  14. using System.Collections.Generic;
  15. using System.Xml.Linq;
  16. namespace CSWebBrowserWithProxy
  17. {
  18. public class InternetProxy
  19. {
  20. public string ProxyName { get; set; }
  21. public string Address { get; set; }
  22. public string UserName { get; set; }
  23. public string Password { get; set; }
  24. public override bool Equals(object obj)
  25. {
  26. if (obj is InternetProxy)
  27. {
  28. InternetProxy proxy = obj as InternetProxy;
  29. return this.Address.Equals(proxy.Address, System.StringComparison.OrdinalIgnoreCase)
  30. && this.UserName.EndsWith(proxy.UserName, System.StringComparison.OrdinalIgnoreCase)
  31. && this.Password.Equals(proxy.Password, System.StringComparison.Ordinal);
  32. }
  33. else
  34. {
  35. return false;
  36. }
  37. }
  38. public override int GetHashCode()
  39. {
  40. return this.Address.GetHashCode()
  41. +this.UserName.GetHashCode()
  42. +this.Password.GetHashCode();
  43. }
  44. public static readonly InternetProxy NoProxy = new InternetProxy
  45. {
  46. Address = string.Empty,
  47. Password = string.Empty,
  48. ProxyName = string.Empty,
  49. UserName = string.Empty
  50. };
  51. static List<InternetProxy> proxyList = null;
  52. public static List<InternetProxy> ProxyList
  53. {
  54. get
  55. {
  56. // Gets the proxy servers in ProxyList.xml.
  57. if (proxyList == null)
  58. {
  59. proxyList = new List<InternetProxy>();
  60. try
  61. {
  62. XElement listXml = XElement.Load("ProxyList.xml");
  63. foreach (var proxy in listXml.Elements("Proxy"))
  64. {
  65. proxyList.Add(
  66. new InternetProxy
  67. {
  68. ProxyName = proxy.Element("ProxyName").Value,
  69. Address = proxy.Element("Address").Value,
  70. UserName = proxy.Element("UserName").Value,
  71. Password = proxy.Element("Password").Value
  72. });
  73. }
  74. }
  75. catch (System.Exception)
  76. {
  77. }
  78. }
  79. return proxyList;
  80. }
  81. }
  82. }
  83. }