SocketServiceConfig.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.Linq;
  5. using System.Text;
  6. using SuperSocket.Common;
  7. using SuperSocket.SocketBase;
  8. using SuperSocket.SocketBase.Config;
  9. using System.Collections.Specialized;
  10. namespace SuperSocket.SocketEngine.Configuration
  11. {
  12. /// <summary>
  13. /// SuperSocket's root configuration node
  14. /// </summary>
  15. public partial class SocketServiceConfig : ConfigurationSection, IConfigurationSource
  16. {
  17. /// <summary>
  18. /// Gets all the server configurations
  19. /// </summary>
  20. [ConfigurationProperty("servers")]
  21. public ServerCollection Servers
  22. {
  23. get
  24. {
  25. return this["servers"] as ServerCollection;
  26. }
  27. }
  28. /// <summary>
  29. /// Gets the service configurations
  30. /// </summary>
  31. [ConfigurationProperty("serverTypes")]
  32. public TypeProviderCollection ServerTypes
  33. {
  34. get
  35. {
  36. return this["serverTypes"] as TypeProviderCollection;
  37. }
  38. }
  39. /// <summary>
  40. /// Gets all the connection filter configurations.
  41. /// </summary>
  42. [ConfigurationProperty("connectionFilters", IsRequired = false)]
  43. public TypeProviderCollection ConnectionFilters
  44. {
  45. get
  46. {
  47. return this["connectionFilters"] as TypeProviderCollection;
  48. }
  49. }
  50. /// <summary>
  51. /// Gets the defined log factory types.
  52. /// </summary>
  53. [ConfigurationProperty("logFactories", IsRequired = false)]
  54. public TypeProviderCollection LogFactories
  55. {
  56. get
  57. {
  58. return this["logFactories"] as TypeProviderCollection;
  59. }
  60. }
  61. /// <summary>
  62. /// Gets the logfactory name of the bootstrap.
  63. /// </summary>
  64. [ConfigurationProperty("receiveFilterFactories", IsRequired = false)]
  65. public TypeProviderCollection ReceiveFilterFactories
  66. {
  67. get
  68. {
  69. return this["receiveFilterFactories"] as TypeProviderCollection;
  70. }
  71. }
  72. /// <summary>
  73. /// Gets the command loaders definition.
  74. /// </summary>
  75. [ConfigurationProperty("commandLoaders", IsRequired = false)]
  76. public TypeProviderCollection CommandLoaders
  77. {
  78. get
  79. {
  80. return this["commandLoaders"] as TypeProviderCollection;
  81. }
  82. }
  83. /// <summary>
  84. /// Gets the max working threads.
  85. /// </summary>
  86. [ConfigurationProperty("maxWorkingThreads", IsRequired = false, DefaultValue = -1)]
  87. public int MaxWorkingThreads
  88. {
  89. get
  90. {
  91. return (int)this["maxWorkingThreads"];
  92. }
  93. }
  94. /// <summary>
  95. /// Gets the min working threads.
  96. /// </summary>
  97. [ConfigurationProperty("minWorkingThreads", IsRequired = false, DefaultValue = -1)]
  98. public int MinWorkingThreads
  99. {
  100. get
  101. {
  102. return (int)this["minWorkingThreads"];
  103. }
  104. }
  105. /// <summary>
  106. /// Gets the max completion port threads.
  107. /// </summary>
  108. [ConfigurationProperty("maxCompletionPortThreads", IsRequired = false, DefaultValue = -1)]
  109. public int MaxCompletionPortThreads
  110. {
  111. get
  112. {
  113. return (int)this["maxCompletionPortThreads"];
  114. }
  115. }
  116. /// <summary>
  117. /// Gets the min completion port threads.
  118. /// </summary>
  119. [ConfigurationProperty("minCompletionPortThreads", IsRequired = false, DefaultValue = -1)]
  120. public int MinCompletionPortThreads
  121. {
  122. get
  123. {
  124. return (int)this["minCompletionPortThreads"];
  125. }
  126. }
  127. /// <summary>
  128. /// Gets the performance data collect interval, in seconds.
  129. /// </summary>
  130. [ConfigurationProperty("performanceDataCollectInterval", IsRequired = false, DefaultValue = 60)]
  131. public int PerformanceDataCollectInterval
  132. {
  133. get
  134. {
  135. return (int)this["performanceDataCollectInterval"];
  136. }
  137. }
  138. /// <summary>
  139. /// Gets a value indicating whether [disable performance data collector].
  140. /// </summary>
  141. /// <value>
  142. /// <c>true</c> if [disable performance data collector]; otherwise, <c>false</c>.
  143. /// </value>
  144. [ConfigurationProperty("disablePerformanceDataCollector", IsRequired = false, DefaultValue = false)]
  145. public bool DisablePerformanceDataCollector
  146. {
  147. get
  148. {
  149. return (bool)this["disablePerformanceDataCollector"];
  150. }
  151. }
  152. /// <summary>
  153. /// Gets the isolation mode.
  154. /// </summary>
  155. [ConfigurationProperty("isolation", IsRequired = false, DefaultValue = IsolationMode.None)]
  156. public IsolationMode Isolation
  157. {
  158. get { return (IsolationMode)this["isolation"]; }
  159. }
  160. /// <summary>
  161. /// Gets the logfactory name of the bootstrap.
  162. /// </summary>
  163. [ConfigurationProperty("logFactory", IsRequired = false, DefaultValue = "")]
  164. public string LogFactory
  165. {
  166. get
  167. {
  168. return (string)this["logFactory"];
  169. }
  170. }
  171. /// <summary>
  172. /// Gets the option elements.
  173. /// </summary>
  174. public NameValueCollection OptionElements { get; private set; }
  175. /// <summary>
  176. /// Gets a value indicating whether an unknown element is encountered during deserialization.
  177. /// To keep compatible with old configuration
  178. /// </summary>
  179. /// <param name="elementName">The name of the unknown subelement.</param>
  180. /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> being used for deserialization.</param>
  181. /// <returns>
  182. /// true when an unknown element is encountered while deserializing; otherwise, false.
  183. /// </returns>
  184. /// <exception cref="T:System.Configuration.ConfigurationErrorsException">The element identified by <paramref name="elementName"/> is locked.- or -One or more of the element's attributes is locked.- or -<paramref name="elementName"/> is unrecognized, or the element has an unrecognized attribute.- or -The element has a Boolean attribute with an invalid value.- or -An attempt was made to deserialize a property more than once.- or -An attempt was made to deserialize a property that is not a valid member of the element.- or -The element cannot contain a CDATA or text element.</exception>
  185. protected override bool OnDeserializeUnrecognizedElement(string elementName, System.Xml.XmlReader reader)
  186. {
  187. //To keep compatible with old configuration
  188. if (!"services".Equals(elementName, StringComparison.OrdinalIgnoreCase))
  189. {
  190. if (OptionElements == null)
  191. OptionElements = new NameValueCollection();
  192. OptionElements.Add(elementName, reader.ReadOuterXml());
  193. return true;
  194. }
  195. var serverTypes = new TypeProviderCollection();
  196. reader.Read();
  197. serverTypes.Deserialize(reader);
  198. this["serverTypes"] = serverTypes;
  199. return true;
  200. }
  201. /// <summary>
  202. /// Gets a value indicating whether an unknown attribute is encountered during deserialization.
  203. /// </summary>
  204. /// <param name="name">The name of the unrecognized attribute.</param>
  205. /// <param name="value">The value of the unrecognized attribute.</param>
  206. /// <returns>
  207. /// true when an unknown attribute is encountered while deserializing; otherwise, false.
  208. /// </returns>
  209. protected override bool OnDeserializeUnrecognizedAttribute(string name, string value)
  210. {
  211. const string xmlns = "xmlns";
  212. const string xmlnsPrefix = "xmlns:";
  213. const string xsiPrefix = "xsi:";
  214. //for configuration intellisense, allow these unrecognized attributes: xmlns, xmlns:*, xsi:*
  215. if (name.Equals(xmlns) || name.StartsWith(xmlnsPrefix) || name.StartsWith(xsiPrefix))
  216. return true;
  217. return false;
  218. }
  219. /// <summary>
  220. /// Gets the child config.
  221. /// </summary>
  222. /// <typeparam name="TConfig">The type of the config.</typeparam>
  223. /// <param name="childConfigName">Name of the child config.</param>
  224. /// <returns></returns>
  225. public TConfig GetChildConfig<TConfig>(string childConfigName)
  226. where TConfig : ConfigurationElement, new()
  227. {
  228. return this.OptionElements.GetChildConfig<TConfig>(childConfigName);
  229. }
  230. IEnumerable<IServerConfig> IConfigurationSource.Servers
  231. {
  232. get
  233. {
  234. return this.Servers;
  235. }
  236. }
  237. IEnumerable<ITypeProvider> IConfigurationSource.ServerTypes
  238. {
  239. get
  240. {
  241. return this.ServerTypes;
  242. }
  243. }
  244. IEnumerable<ITypeProvider> IConfigurationSource.ConnectionFilters
  245. {
  246. get
  247. {
  248. return this.ConnectionFilters;
  249. }
  250. }
  251. IEnumerable<ITypeProvider> IConfigurationSource.LogFactories
  252. {
  253. get
  254. {
  255. return this.LogFactories;
  256. }
  257. }
  258. IEnumerable<ITypeProvider> IConfigurationSource.ReceiveFilterFactories
  259. {
  260. get
  261. {
  262. return this.ReceiveFilterFactories;
  263. }
  264. }
  265. IEnumerable<ITypeProvider> IConfigurationSource.CommandLoaders
  266. {
  267. get
  268. {
  269. return this.CommandLoaders;
  270. }
  271. }
  272. }
  273. }