using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using SuperSocket.Common;
using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Config;
using System.Collections.Specialized;
namespace SuperSocket.SocketEngine.Configuration
{
///
/// SuperSocket's root configuration node
///
public partial class SocketServiceConfig : ConfigurationSection, IConfigurationSource
{
///
/// Gets all the server configurations
///
[ConfigurationProperty("servers")]
public ServerCollection Servers
{
get
{
return this["servers"] as ServerCollection;
}
}
///
/// Gets the service configurations
///
[ConfigurationProperty("serverTypes")]
public TypeProviderCollection ServerTypes
{
get
{
return this["serverTypes"] as TypeProviderCollection;
}
}
///
/// Gets all the connection filter configurations.
///
[ConfigurationProperty("connectionFilters", IsRequired = false)]
public TypeProviderCollection ConnectionFilters
{
get
{
return this["connectionFilters"] as TypeProviderCollection;
}
}
///
/// Gets the defined log factory types.
///
[ConfigurationProperty("logFactories", IsRequired = false)]
public TypeProviderCollection LogFactories
{
get
{
return this["logFactories"] as TypeProviderCollection;
}
}
///
/// Gets the logfactory name of the bootstrap.
///
[ConfigurationProperty("receiveFilterFactories", IsRequired = false)]
public TypeProviderCollection ReceiveFilterFactories
{
get
{
return this["receiveFilterFactories"] as TypeProviderCollection;
}
}
///
/// Gets the command loaders definition.
///
[ConfigurationProperty("commandLoaders", IsRequired = false)]
public TypeProviderCollection CommandLoaders
{
get
{
return this["commandLoaders"] as TypeProviderCollection;
}
}
///
/// Gets the max working threads.
///
[ConfigurationProperty("maxWorkingThreads", IsRequired = false, DefaultValue = -1)]
public int MaxWorkingThreads
{
get
{
return (int)this["maxWorkingThreads"];
}
}
///
/// Gets the min working threads.
///
[ConfigurationProperty("minWorkingThreads", IsRequired = false, DefaultValue = -1)]
public int MinWorkingThreads
{
get
{
return (int)this["minWorkingThreads"];
}
}
///
/// Gets the max completion port threads.
///
[ConfigurationProperty("maxCompletionPortThreads", IsRequired = false, DefaultValue = -1)]
public int MaxCompletionPortThreads
{
get
{
return (int)this["maxCompletionPortThreads"];
}
}
///
/// Gets the min completion port threads.
///
[ConfigurationProperty("minCompletionPortThreads", IsRequired = false, DefaultValue = -1)]
public int MinCompletionPortThreads
{
get
{
return (int)this["minCompletionPortThreads"];
}
}
///
/// Gets the performance data collect interval, in seconds.
///
[ConfigurationProperty("performanceDataCollectInterval", IsRequired = false, DefaultValue = 60)]
public int PerformanceDataCollectInterval
{
get
{
return (int)this["performanceDataCollectInterval"];
}
}
///
/// Gets a value indicating whether [disable performance data collector].
///
///
/// true if [disable performance data collector]; otherwise, false.
///
[ConfigurationProperty("disablePerformanceDataCollector", IsRequired = false, DefaultValue = false)]
public bool DisablePerformanceDataCollector
{
get
{
return (bool)this["disablePerformanceDataCollector"];
}
}
///
/// Gets the isolation mode.
///
[ConfigurationProperty("isolation", IsRequired = false, DefaultValue = IsolationMode.None)]
public IsolationMode Isolation
{
get { return (IsolationMode)this["isolation"]; }
}
///
/// Gets the logfactory name of the bootstrap.
///
[ConfigurationProperty("logFactory", IsRequired = false, DefaultValue = "")]
public string LogFactory
{
get
{
return (string)this["logFactory"];
}
}
///
/// Gets the option elements.
///
public NameValueCollection OptionElements { get; private set; }
///
/// Gets a value indicating whether an unknown element is encountered during deserialization.
/// To keep compatible with old configuration
///
/// The name of the unknown subelement.
/// The being used for deserialization.
///
/// true when an unknown element is encountered while deserializing; otherwise, false.
///
/// The element identified by is locked.- or -One or more of the element's attributes is locked.- or - 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.
protected override bool OnDeserializeUnrecognizedElement(string elementName, System.Xml.XmlReader reader)
{
//To keep compatible with old configuration
if (!"services".Equals(elementName, StringComparison.OrdinalIgnoreCase))
{
if (OptionElements == null)
OptionElements = new NameValueCollection();
OptionElements.Add(elementName, reader.ReadOuterXml());
return true;
}
var serverTypes = new TypeProviderCollection();
reader.Read();
serverTypes.Deserialize(reader);
this["serverTypes"] = serverTypes;
return true;
}
///
/// Gets a value indicating whether an unknown attribute is encountered during deserialization.
///
/// The name of the unrecognized attribute.
/// The value of the unrecognized attribute.
///
/// true when an unknown attribute is encountered while deserializing; otherwise, false.
///
protected override bool OnDeserializeUnrecognizedAttribute(string name, string value)
{
const string xmlns = "xmlns";
const string xmlnsPrefix = "xmlns:";
const string xsiPrefix = "xsi:";
//for configuration intellisense, allow these unrecognized attributes: xmlns, xmlns:*, xsi:*
if (name.Equals(xmlns) || name.StartsWith(xmlnsPrefix) || name.StartsWith(xsiPrefix))
return true;
return false;
}
///
/// Gets the child config.
///
/// The type of the config.
/// Name of the child config.
///
public TConfig GetChildConfig(string childConfigName)
where TConfig : ConfigurationElement, new()
{
return this.OptionElements.GetChildConfig(childConfigName);
}
IEnumerable IConfigurationSource.Servers
{
get
{
return this.Servers;
}
}
IEnumerable IConfigurationSource.ServerTypes
{
get
{
return this.ServerTypes;
}
}
IEnumerable IConfigurationSource.ConnectionFilters
{
get
{
return this.ConnectionFilters;
}
}
IEnumerable IConfigurationSource.LogFactories
{
get
{
return this.LogFactories;
}
}
IEnumerable IConfigurationSource.ReceiveFilterFactories
{
get
{
return this.ReceiveFilterFactories;
}
}
IEnumerable IConfigurationSource.CommandLoaders
{
get
{
return this.CommandLoaders;
}
}
}
}