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