RemotingConfiguration.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // System.Runtime.Remoting.RemotingConfiguration.cs
  3. //
  4. // Author: Jaime Anguiano Olarra ([email protected])
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2002, Jaime Anguiano Olarra
  8. //
  9. // FIXME: This is just the skeleton for practical purposes
  10. using System;
  11. using System.IO;
  12. using System.Reflection;
  13. using System.Collections;
  14. using System.Runtime.Remoting.Activation;
  15. using Mono.Xml;
  16. namespace System.Runtime.Remoting
  17. {
  18. public class RemotingConfiguration
  19. {
  20. static string applicationID = null;
  21. static string applicationName = null;
  22. static string configFile = "";
  23. static MiniParser parser = null;
  24. static string processGuid = null;
  25. static Hashtable wellKnownClientEntries = new Hashtable();
  26. static Hashtable activatedClientEntries = new Hashtable();
  27. static Hashtable wellKnownServiceEntries = new Hashtable();
  28. static Hashtable activatedServiceEntries = new Hashtable();
  29. // public properties
  30. // At this time the ID will be the application name
  31. public static string ApplicationId
  32. {
  33. get
  34. {
  35. applicationID = AppDomain.CurrentDomain.SetupInformation.ApplicationName;
  36. return applicationID;
  37. }
  38. }
  39. public static string ApplicationName
  40. {
  41. get {
  42. try {
  43. applicationName = AppDomain.CurrentDomain.SetupInformation.ApplicationName;
  44. }
  45. catch (Exception e) {
  46. throw e;
  47. }
  48. // We return null if the application name has not been set.
  49. return null;
  50. }
  51. set { applicationName = value; }
  52. }
  53. public static string ProcessId
  54. {
  55. get {
  56. if (processGuid == null)
  57. processGuid = AppDomain.GetProcessGuid ();
  58. return processGuid;
  59. }
  60. }
  61. // public methods
  62. public static void Configure (string filename)
  63. {
  64. throw new NotImplementedException ();
  65. }
  66. public static ActivatedClientTypeEntry[] GetRegisteredActivatedClientTypes ()
  67. {
  68. ActivatedClientTypeEntry[] entries = new ActivatedClientTypeEntry[activatedClientEntries.Count];
  69. activatedClientEntries.Values.CopyTo (entries,0);
  70. return entries;
  71. }
  72. public static ActivatedServiceTypeEntry[] GetRegisteredActivatedServiceTypes ()
  73. {
  74. ActivatedServiceTypeEntry[] entries = new ActivatedServiceTypeEntry[activatedServiceEntries.Count];
  75. activatedServiceEntries.Values.CopyTo (entries,0);
  76. return entries;
  77. }
  78. public static WellKnownClientTypeEntry[] GetRegisteredWellKnownClientTypes ()
  79. {
  80. WellKnownClientTypeEntry[] entries = new WellKnownClientTypeEntry[wellKnownClientEntries.Count];
  81. wellKnownClientEntries.Values.CopyTo (entries,0);
  82. return entries;
  83. }
  84. public static WellKnownServiceTypeEntry[] GetRegisteredWellKnownServiceTypes ()
  85. {
  86. WellKnownServiceTypeEntry[] entries = new WellKnownServiceTypeEntry[wellKnownServiceEntries.Count];
  87. wellKnownServiceEntries.Values.CopyTo (entries,0);
  88. return entries;
  89. }
  90. public static bool IsActivationAllowed (Type serverType)
  91. {
  92. return activatedServiceEntries.ContainsKey (serverType);
  93. }
  94. public static ActivatedClientTypeEntry IsRemotelyActivatedClientType (Type serviceType)
  95. {
  96. return activatedClientEntries [serviceType] as ActivatedClientTypeEntry;
  97. }
  98. public static ActivatedClientTypeEntry IsRemotelyActivatedClientType (string typeName, string assemblyName)
  99. {
  100. return IsRemotelyActivatedClientType (Assembly.Load(assemblyName).GetType (typeName));
  101. }
  102. public static WellKnownClientTypeEntry IsWellKnownClientType (Type serviceType)
  103. {
  104. return wellKnownClientEntries [serviceType] as WellKnownClientTypeEntry;
  105. }
  106. public static WellKnownClientTypeEntry IsWellKnownClientType (string typeName, string assemblyName)
  107. {
  108. return IsWellKnownClientType (Assembly.Load(assemblyName).GetType (typeName));
  109. }
  110. public static void RegisterActivatedClientType (ActivatedClientTypeEntry entry)
  111. {
  112. if (wellKnownClientEntries.ContainsKey (entry.ObjectType) || activatedClientEntries.ContainsKey (entry.ObjectType))
  113. throw new RemotingException ("Attempt to redirect activation of type '" + entry.ObjectType.FullName + "' which is already redirected.");
  114. activatedClientEntries[entry.ObjectType] = entry;
  115. ActivationServices.EnableProxyActivation (entry.ObjectType, true);
  116. }
  117. public static void RegisterActivatedClientType (Type type, string appUrl)
  118. {
  119. if (type == null) throw new ArgumentNullException ("type");
  120. if (appUrl == null) throw new ArgumentNullException ("appUrl");
  121. RegisterActivatedClientType (new ActivatedClientTypeEntry (type, appUrl));
  122. }
  123. public static void RegisterActivatedServiceType (ActivatedServiceTypeEntry entry)
  124. {
  125. activatedServiceEntries.Add (entry.ObjectType, entry);
  126. }
  127. public static void RegisterActivatedServiceType (Type type)
  128. {
  129. RegisterActivatedServiceType (new ActivatedServiceTypeEntry (type));
  130. }
  131. public static void RegisterWellKnownClientType (Type type, string objectUrl)
  132. {
  133. if (type == null) throw new ArgumentNullException ("type");
  134. if (objectUrl == null) throw new ArgumentNullException ("objectUrl");
  135. RegisterWellKnownClientType (new WellKnownClientTypeEntry (type, objectUrl));
  136. }
  137. public static void RegisterWellKnownClientType (WellKnownClientTypeEntry entry)
  138. {
  139. if (wellKnownClientEntries.ContainsKey (entry.ObjectType) || activatedClientEntries.ContainsKey (entry.ObjectType))
  140. throw new RemotingException ("Attempt to redirect activation of type '" + entry.ObjectType.FullName + "' which is already redirected.");
  141. wellKnownClientEntries[entry.ObjectType] = entry;
  142. ActivationServices.EnableProxyActivation (entry.ObjectType, true);
  143. }
  144. public static void RegisterWellKnownServiceType (Type type, string objectUrl, WellKnownObjectMode mode)
  145. {
  146. RegisterWellKnownServiceType (new WellKnownServiceTypeEntry (type, objectUrl, mode));
  147. }
  148. public static void RegisterWellKnownServiceType (WellKnownServiceTypeEntry entry)
  149. {
  150. wellKnownServiceEntries [entry.ObjectUri] = entry;
  151. RemotingServices.CreateWellKnownServerIdentity (entry.ObjectType, entry.ObjectUri, entry.Mode);
  152. }
  153. }
  154. }