| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- //
- // System.Net.GlobalProxySelection
- //
- // Author:
- // Lawrence Pit ([email protected])
- //
- using System;
- using System.Collections;
- using System.Configuration;
- using System.IO;
- using System.Runtime.Serialization;
- namespace System.Net
- {
- public class GlobalProxySelection
- {
- private static IWebProxy proxy;
-
- // Constructors
- public GlobalProxySelection() { }
-
- // Properties
-
- static IWebProxy GetProxy ()
- {
- if (proxy != null)
- return proxy;
- lock (typeof (GlobalProxySelection)) {
- if (proxy != null)
- return proxy;
- object p = ConfigurationSettings.GetConfig ("system.net/defaultProxy");
- if (p == null)
- p = new EmptyWebProxy ();
- proxy = (IWebProxy) p;
- }
- return proxy;
- }
-
- public static IWebProxy Select {
- get { return GetProxy (); }
- set {
- if (value == null)
- throw new ArgumentNullException ("GlobalProxySelection.Select",
- "null IWebProxy not allowed. Use GetEmptyWebProxy ()");
- lock (typeof (GlobalProxySelection))
- proxy = value;
- }
- }
-
- // Methods
-
- public static IWebProxy GetEmptyWebProxy()
- {
- // must return a new one each time, as the credentials
- // can be set
- return new EmptyWebProxy ();
- }
-
- // Internal Classes
-
- internal class EmptyWebProxy : IWebProxy {
- private ICredentials credentials = null;
-
- internal EmptyWebProxy () { }
-
- public ICredentials Credentials {
- get { return credentials; }
- set { credentials = value; }
- }
- public Uri GetProxy (Uri destination)
- {
- return destination;
- }
- public bool IsBypassed (Uri host)
- {
- return true; // pass directly to host
- }
- }
- }
- }
|