Identity.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // System.Runtime.Remoting.Identity.cs
  3. //
  4. // Author: Lluis Sanchez Gual ([email protected])
  5. //
  6. // (C) 2002, Lluis Sanchez Gual
  7. //
  8. using System.Runtime.Remoting.Messaging;
  9. using System.Runtime.Remoting.Proxies;
  10. using System.Runtime.Remoting.Contexts;
  11. using System.Runtime.Remoting.Lifetime;
  12. namespace System.Runtime.Remoting
  13. {
  14. internal abstract class Identity
  15. {
  16. // An Identity object holds remoting information about
  17. // an object. It can be used to store client side information
  18. // (information about how to reach the remote server),
  19. // and also to store server side information (information
  20. // about how to dispatch messages to the object in the server).
  21. protected Type _objectType;
  22. // URI of the object
  23. protected string _objectUri;
  24. // Message sink to use to send a message to the remote server
  25. protected IMessageSink _channelSink = null;
  26. protected IMessageSink _envoySink = null;
  27. DynamicPropertyCollection _clientDynamicProperties;
  28. DynamicPropertyCollection _serverDynamicProperties;
  29. // The ObjRef
  30. protected ObjRef _objRef;
  31. public Identity(string objectUri, Type objectType)
  32. {
  33. _objectUri = objectUri;
  34. _objectType = objectType;
  35. }
  36. public abstract ObjRef CreateObjRef (Type requestedType);
  37. public bool IsFromThisAppDomain
  38. {
  39. get
  40. {
  41. return (_channelSink == null);
  42. }
  43. }
  44. public IMessageSink ChannelSink
  45. {
  46. get { return _channelSink; }
  47. set { _channelSink = value; }
  48. }
  49. public IMessageSink EnvoySink
  50. {
  51. get { return _envoySink; }
  52. }
  53. public Type ObjectType
  54. {
  55. get { return _objectType; }
  56. }
  57. public string ObjectUri
  58. {
  59. get { return _objectUri; }
  60. set { _objectUri = value; }
  61. }
  62. public bool IsConnected
  63. {
  64. get { return _objectUri != null; }
  65. }
  66. public DynamicPropertyCollection ClientDynamicProperties
  67. {
  68. get {
  69. if (_clientDynamicProperties == null) _clientDynamicProperties = new DynamicPropertyCollection();
  70. return _clientDynamicProperties;
  71. }
  72. }
  73. public DynamicPropertyCollection ServerDynamicProperties
  74. {
  75. get {
  76. if (_serverDynamicProperties == null) _serverDynamicProperties = new DynamicPropertyCollection();
  77. return _serverDynamicProperties;
  78. }
  79. }
  80. public bool HasClientDynamicSinks
  81. {
  82. get { return (_clientDynamicProperties != null && _clientDynamicProperties.HasProperties); }
  83. }
  84. public bool HasServerDynamicSinks
  85. {
  86. get { return (_serverDynamicProperties != null && _serverDynamicProperties.HasProperties); }
  87. }
  88. public void NotifyClientDynamicSinks (bool start, IMessage req_msg, bool client_site, bool async)
  89. {
  90. if (_clientDynamicProperties != null && _clientDynamicProperties.HasProperties)
  91. _clientDynamicProperties.NotifyMessage (start, req_msg, client_site, async);
  92. }
  93. public void NotifyServerDynamicSinks (bool start, IMessage req_msg, bool client_site, bool async)
  94. {
  95. if (_serverDynamicProperties != null && _serverDynamicProperties.HasProperties)
  96. _serverDynamicProperties.NotifyMessage (start, req_msg, client_site, async);
  97. }
  98. }
  99. internal class ClientIdentity : Identity
  100. {
  101. MarshalByRefObject _proxyObject;
  102. public ClientIdentity (string objectUri, ObjRef objRef): base (objectUri, Type.GetType (objRef.TypeInfo.TypeName,true))
  103. {
  104. _objRef = objRef;
  105. _envoySink = (_objRef.EnvoyInfo != null) ? _objRef.EnvoyInfo.EnvoySinks : null;
  106. }
  107. public MarshalByRefObject ClientProxy
  108. {
  109. get { return _proxyObject; }
  110. set { _proxyObject = value; }
  111. }
  112. public override ObjRef CreateObjRef (Type requestedType)
  113. {
  114. return _objRef;
  115. }
  116. public string TargetUri
  117. {
  118. get { return _objRef.URI; }
  119. }
  120. }
  121. }