RemotingConfiguration.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 processId = null;
  23. static string configFile = "";
  24. static MiniParser parser = 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. processId = AppDomain.CurrentDomain.SetupInformation.ApplicationName;
  57. return processId;
  58. }
  59. }
  60. // public methods
  61. public static void Configure (string filename)
  62. {
  63. throw new NotImplementedException ();
  64. }
  65. public static ActivatedClientTypeEntry[] GetRegisteredActivatedClientTypes ()
  66. {
  67. ActivatedClientTypeEntry[] entries = new ActivatedClientTypeEntry[activatedClientEntries.Count];
  68. activatedClientEntries.Values.CopyTo (entries,0);
  69. return entries;
  70. }
  71. public static ActivatedServiceTypeEntry[] GetRegisteredActivatedServiceTypes ()
  72. {
  73. ActivatedServiceTypeEntry[] entries = new ActivatedServiceTypeEntry[activatedServiceEntries.Count];
  74. activatedServiceEntries.Values.CopyTo (entries,0);
  75. return entries;
  76. }
  77. public static WellKnownClientTypeEntry[] GetRegisteredWellKnownClientTypes ()
  78. {
  79. WellKnownClientTypeEntry[] entries = new WellKnownClientTypeEntry[wellKnownClientEntries.Count];
  80. wellKnownClientEntries.Values.CopyTo (entries,0);
  81. return entries;
  82. }
  83. public static WellKnownServiceTypeEntry[] GetRegisteredWellKnownServiceTypes ()
  84. {
  85. WellKnownServiceTypeEntry[] entries = new WellKnownServiceTypeEntry[wellKnownServiceEntries.Count];
  86. wellKnownServiceEntries.Values.CopyTo (entries,0);
  87. return entries;
  88. }
  89. public static bool IsActivationAllowed (Type serverType)
  90. {
  91. return activatedServiceEntries.ContainsKey (serverType);
  92. }
  93. public static ActivatedClientTypeEntry IsRemotelyActivatedClientType (Type serviceType)
  94. {
  95. return activatedClientEntries [serviceType] as ActivatedClientTypeEntry;
  96. }
  97. public static ActivatedClientTypeEntry IsRemotelyActivatedClientType (string typeName, string assemblyName)
  98. {
  99. return IsRemotelyActivatedClientType (Assembly.Load(assemblyName).GetType (typeName));
  100. }
  101. public static WellKnownClientTypeEntry IsWellKnownClientType (Type serviceType)
  102. {
  103. return wellKnownClientEntries [serviceType] as WellKnownClientTypeEntry;
  104. }
  105. public static WellKnownClientTypeEntry IsWellKnownClientType (string typeName, string assemblyName)
  106. {
  107. return IsWellKnownClientType (Assembly.Load(assemblyName).GetType (typeName));
  108. }
  109. public static void RegisterActivatedClientType (ActivatedClientTypeEntry entry)
  110. {
  111. if (wellKnownClientEntries.ContainsKey (entry.ObjectType) || activatedClientEntries.ContainsKey (entry.ObjectType))
  112. throw new RemotingException ("Attempt to redirect activation of type '" + entry.ObjectType.FullName + "' which is already redirected.");
  113. activatedClientEntries[entry.ObjectType] = entry;
  114. ActivationServices.EnableProxyActivation (entry.ObjectType, true);
  115. }
  116. public static void RegisterActivatedClientType (Type type, string appUrl)
  117. {
  118. if (type == null) throw new ArgumentNullException ("type");
  119. if (appUrl == null) throw new ArgumentNullException ("appUrl");
  120. RegisterActivatedClientType (new ActivatedClientTypeEntry (type, appUrl));
  121. }
  122. public static void RegisterActivatedServiceType (ActivatedServiceTypeEntry entry)
  123. {
  124. activatedServiceEntries.Add (entry.ObjectType, entry);
  125. }
  126. public static void RegisterActivatedServiceType (Type type)
  127. {
  128. RegisterActivatedServiceType (new ActivatedServiceTypeEntry (type));
  129. }
  130. public static void RegisterWellKnownClientType (Type type, string objectUrl)
  131. {
  132. if (type == null) throw new ArgumentNullException ("type");
  133. if (objectUrl == null) throw new ArgumentNullException ("objectUrl");
  134. RegisterWellKnownClientType (new WellKnownClientTypeEntry (type, objectUrl));
  135. }
  136. public static void RegisterWellKnownClientType (WellKnownClientTypeEntry entry)
  137. {
  138. if (wellKnownClientEntries.ContainsKey (entry.ObjectType) || activatedClientEntries.ContainsKey (entry.ObjectType))
  139. throw new RemotingException ("Attempt to redirect activation of type '" + entry.ObjectType.FullName + "' which is already redirected.");
  140. wellKnownClientEntries[entry.ObjectType] = entry;
  141. ActivationServices.EnableProxyActivation (entry.ObjectType, true);
  142. }
  143. public static void RegisterWellKnownServiceType (Type type, string objectUrl, WellKnownObjectMode mode)
  144. {
  145. RegisterWellKnownServiceType (new WellKnownServiceTypeEntry (type, objectUrl, mode));
  146. }
  147. public static void RegisterWellKnownServiceType (WellKnownServiceTypeEntry entry)
  148. {
  149. wellKnownServiceEntries [entry.ObjectUri] = entry;
  150. RemotingServices.CreateWellKnownServerIdentity (entry.ObjectType, entry.ObjectUri, entry.Mode);
  151. }
  152. }
  153. }