Context.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // System.Runtime.Remoting.Contexts.Context..cs
  3. //
  4. // Author:
  5. // Miguel de Icaza ([email protected])
  6. // Lluis Sanchez Gual ([email protected])
  7. //
  8. // (C) Ximian, Inc. http://www.ximian.com
  9. //
  10. using System.Collections;
  11. using System.Runtime.Remoting.Messaging;
  12. using System.Runtime.Remoting.Lifetime;
  13. namespace System.Runtime.Remoting.Contexts {
  14. public class Context {
  15. static Context default_context;
  16. static ArrayList domain_contexts = new ArrayList();
  17. // Default server object sink chain
  18. static IMessageSink default_object_sink;
  19. // Default server context sink chain
  20. static IMessageSink default_context_sink;
  21. // The sink chain that has to be used by all calls entering the context
  22. IMessageSink server_context_sink_chain = null;
  23. ArrayList context_properties;
  24. int context_id;
  25. bool frozen;
  26. static int global_count;
  27. static Context ()
  28. {
  29. // Creates the default context sink chain
  30. default_context_sink = new ServerContextTerminatorSink();
  31. // Creates the default object sink chain
  32. default_object_sink = new StackBuilderSink();
  33. default_object_sink = new ServerObjectTerminatorSink(default_object_sink);
  34. default_object_sink = new Lifetime.LeaseSink(default_object_sink);
  35. default_context = new Context ();
  36. default_context.frozen = true;
  37. }
  38. public Context ()
  39. {
  40. context_id = global_count++;
  41. }
  42. public static Context DefaultContext {
  43. get {
  44. return default_context;
  45. }
  46. }
  47. public virtual int ContextID {
  48. get {
  49. return context_id;
  50. }
  51. }
  52. public virtual IContextProperty GetProperty (string name)
  53. {
  54. if (context_properties == null)
  55. return null;
  56. foreach (IContextProperty p in context_properties)
  57. if (p.Name == name)
  58. return p;
  59. return null;
  60. }
  61. public virtual void SetProperty (IContextProperty prop)
  62. {
  63. if (prop == null)
  64. throw new ArgumentNullException ("IContextProperty");
  65. if (this == default_context)
  66. throw new InvalidOperationException ("Can not add properties to " +
  67. "default context");
  68. if (frozen)
  69. throw new InvalidOperationException ("Context is Frozen");
  70. if (context_properties == null)
  71. context_properties = new ArrayList ();
  72. context_properties.Add (prop);
  73. }
  74. [MonoTODO("Create sinks from contributor properties")]
  75. internal IMessageSink GetServerContextSinkChain()
  76. {
  77. if (server_context_sink_chain == null)
  78. {
  79. server_context_sink_chain = default_context_sink;
  80. }
  81. return server_context_sink_chain;
  82. }
  83. [MonoTODO("Create object sinks from contributor properties")]
  84. internal IMessageSink CreateServerObjectSinkChain (MarshalByRefObject obj)
  85. {
  86. return default_object_sink;
  87. }
  88. }
  89. }