GlobalProxySelection.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // System.Net.GlobalProxySelection
  3. //
  4. // Author:
  5. // Lawrence Pit ([email protected])
  6. //
  7. using System;
  8. using System.Collections;
  9. using System.IO;
  10. using System.Runtime.Serialization;
  11. namespace System.Net
  12. {
  13. public class GlobalProxySelection
  14. {
  15. private static IWebProxy proxy;
  16. // Static Initializer
  17. static GlobalProxySelection ()
  18. {
  19. proxy = GetEmptyWebProxy ();
  20. // TODO: create proxy object based on information from
  21. // the global or application configuration file.
  22. }
  23. // Constructors
  24. public GlobalProxySelection() { }
  25. // Properties
  26. public static IWebProxy Select {
  27. get { return proxy; }
  28. set {
  29. proxy = (value == null) ? GetEmptyWebProxy () : value;
  30. }
  31. }
  32. // Methods
  33. public static IWebProxy GetEmptyWebProxy()
  34. {
  35. // must return a new one each time, as the credentials
  36. // can be set
  37. return new EmptyWebProxy ();
  38. }
  39. // Internal Classes
  40. internal class EmptyWebProxy : IWebProxy {
  41. private ICredentials credentials = null;
  42. internal EmptyWebProxy () { }
  43. public ICredentials Credentials {
  44. get { return credentials; }
  45. set { credentials = value; }
  46. }
  47. public Uri GetProxy (Uri destination)
  48. {
  49. return destination;
  50. }
  51. public bool IsBypassed (Uri host)
  52. {
  53. return true; // pass directly to host
  54. }
  55. }
  56. }
  57. }