using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Configuration; using System.IO; using System.Security.Authentication; using System.Text; using System.Xml; using System.Linq; using SuperSocket.Common; using SuperSocket.SocketBase; using SuperSocket.SocketBase.Config; namespace SuperSocket.SocketEngine.Configuration { /// /// Server configuration /// public partial class Server : ConfigurationElementBase, IServerConfig { /// /// Gets the name of the server type this appServer want to use. /// /// /// The name of the server type. /// [ConfigurationProperty("serverTypeName", IsRequired = false)] public string ServerTypeName { get { return this["serverTypeName"] as string; } } /// /// Gets the type definition of the appserver. /// /// /// The type of the server. /// [ConfigurationProperty("serverType", IsRequired = false)] public string ServerType { get { return this["serverType"] as string; } } /// /// Gets the Receive filter factory. /// [ConfigurationProperty("receiveFilterFactory", IsRequired = false)] public string ReceiveFilterFactory { get { return this["receiveFilterFactory"] as string; } } /// /// Gets the ip. /// [ConfigurationProperty("ip", IsRequired = false)] public string Ip { get { return this["ip"] as string; } } /// /// Gets the port. /// [ConfigurationProperty("port", IsRequired = false)] public int Port { get { return (int)this["port"]; } } /// /// Gets the mode. /// [ConfigurationProperty("mode", IsRequired = false, DefaultValue = "Tcp")] public SocketMode Mode { get { return (SocketMode)this["mode"]; } } /// /// Gets a value indicating whether this is disabled. /// /// /// true if disabled; otherwise, false. /// [ConfigurationProperty("disabled", DefaultValue = "false")] public bool Disabled { get { return (bool)this["disabled"]; } } /// /// Gets the send time out. /// [ConfigurationProperty("sendTimeOut", IsRequired = false, DefaultValue = ServerConfig.DefaultSendTimeout)] public int SendTimeOut { get { return (int)this["sendTimeOut"]; } } /// /// Gets the max connection number. /// [ConfigurationProperty("maxConnectionNumber", IsRequired = false, DefaultValue = ServerConfig.DefaultMaxConnectionNumber)] public int MaxConnectionNumber { get { return (int)this["maxConnectionNumber"]; } } /// /// Gets the size of the receive buffer. /// /// /// The size of the receive buffer. /// [ConfigurationProperty("receiveBufferSize", IsRequired = false, DefaultValue = ServerConfig.DefaultReceiveBufferSize)] public int ReceiveBufferSize { get { return (int)this["receiveBufferSize"]; } } /// /// Gets the size of the send buffer. /// /// /// The size of the send buffer. /// [ConfigurationProperty("sendBufferSize", IsRequired = false, DefaultValue = ServerConfig.DefaultSendBufferSize)] public int SendBufferSize { get { return (int)this["sendBufferSize"]; } } /// /// Gets a value indicating whether sending is in synchronous mode. /// /// /// true if [sync send]; otherwise, false. /// [ConfigurationProperty("syncSend", IsRequired = false, DefaultValue = false)] public bool SyncSend { get { return (bool)this["syncSend"]; } } /// /// Gets a value indicating whether log command in log file. /// /// true if log command; otherwise, false. [ConfigurationProperty("logCommand", IsRequired = false, DefaultValue = false)] public bool LogCommand { get { return (bool)this["logCommand"]; } } /// /// Gets a value indicating whether [log basic session activity like connected and disconnected]. /// /// /// true if [log basic session activity]; otherwise, false. /// [ConfigurationProperty("logBasicSessionActivity", IsRequired = false, DefaultValue = true)] public bool LogBasicSessionActivity { get { return (bool)this["logBasicSessionActivity"]; } } /// /// Gets a value indicating whether [log all socket exception]. /// /// /// true if [log all socket exception]; otherwise, false. /// [ConfigurationProperty("logAllSocketException", IsRequired = false, DefaultValue = false)] public bool LogAllSocketException { get { return (bool)this["logAllSocketException"]; } } /// /// Gets a value indicating whether clear idle session. /// /// true if clear idle session; otherwise, false. [ConfigurationProperty("clearIdleSession", IsRequired = false, DefaultValue = false)] public bool ClearIdleSession { get { return (bool)this["clearIdleSession"]; } } /// /// Gets the clear idle session interval, in seconds. /// /// The clear idle session interval. [ConfigurationProperty("clearIdleSessionInterval", IsRequired = false, DefaultValue = ServerConfig.DefaultClearIdleSessionInterval)] public int ClearIdleSessionInterval { get { return (int)this["clearIdleSessionInterval"]; } } /// /// Gets the idle session timeout time length, in seconds. /// /// The idle session time out. [ConfigurationProperty("idleSessionTimeOut", IsRequired = false, DefaultValue = ServerConfig.DefaultIdleSessionTimeOut)] public int IdleSessionTimeOut { get { return (int)this["idleSessionTimeOut"]; } } /// /// Gets the certificate config. /// /// The certificate config. [ConfigurationProperty("certificate", IsRequired = false)] public CertificateConfig CertificateConfig { get { return (CertificateConfig)this["certificate"]; } } /// /// Gets X509Certificate configuration. /// /// /// X509Certificate configuration. /// public ICertificateConfig Certificate { get { return CertificateConfig; } } /// /// Gets the security protocol, X509 certificate. /// [ConfigurationProperty("security", IsRequired = false, DefaultValue = "None")] public string Security { get { return (string)this["security"]; } } /// /// Gets the max allowed length of request. /// /// /// The max allowed length of request. /// [ConfigurationProperty("maxRequestLength", IsRequired = false, DefaultValue = ServerConfig.DefaultMaxRequestLength)] public int MaxRequestLength { get { return (int)this["maxRequestLength"]; } } /// /// Gets a value indicating whether [disable session snapshot] /// [ConfigurationProperty("disableSessionSnapshot", IsRequired = false, DefaultValue = false)] public bool DisableSessionSnapshot { get { return (bool)this["disableSessionSnapshot"]; } } /// /// Gets the interval to taking snapshot for all live sessions. /// [ConfigurationProperty("sessionSnapshotInterval", IsRequired = false, DefaultValue = ServerConfig.DefaultSessionSnapshotInterval)] public int SessionSnapshotInterval { get { return (int)this["sessionSnapshotInterval"]; } } /// /// Gets the connection filters used by this server instance. /// /// /// The connection filters's name list, seperated by comma /// [ConfigurationProperty("connectionFilter", IsRequired = false)] public string ConnectionFilter { get { return (string)this["connectionFilter"]; } } /// /// Gets the command loader, multiple values should be separated by comma. /// [ConfigurationProperty("commandLoader", IsRequired = false)] public string CommandLoader { get { return (string)this["commandLoader"]; } } /// /// Gets the start keep alive time, in seconds /// [ConfigurationProperty("keepAliveTime", IsRequired = false, DefaultValue = ServerConfig.DefaultKeepAliveTime)] public int KeepAliveTime { get { return (int)this["keepAliveTime"]; } } /// /// Gets the keep alive interval, in seconds. /// [ConfigurationProperty("keepAliveInterval", IsRequired = false, DefaultValue = ServerConfig.DefaultKeepAliveInterval)] public int KeepAliveInterval { get { return (int)this["keepAliveInterval"]; } } /// /// Gets the backlog size of socket listening. /// [ConfigurationProperty("listenBacklog", IsRequired = false, DefaultValue = ServerConfig.DefaultListenBacklog)] public int ListenBacklog { get { return (int)this["listenBacklog"]; } } /// /// Gets the startup order of the server instance. /// [ConfigurationProperty("startupOrder", IsRequired = false, DefaultValue = 0)] public int StartupOrder { get { return (int)this["startupOrder"]; } } /// /// Gets/sets the size of the sending queue. /// /// /// The size of the sending queue. /// [ConfigurationProperty("sendingQueueSize", IsRequired = false, DefaultValue = ServerConfig.DefaultSendingQueueSize)] public int SendingQueueSize { get { return (int)this["sendingQueueSize"]; } } /// /// Gets the logfactory name of the server instance. /// [ConfigurationProperty("logFactory", IsRequired = false, DefaultValue = "")] public string LogFactory { get { return (string)this["logFactory"]; } } /// /// Gets the default text encoding. /// /// /// The text encoding. /// [ConfigurationProperty("textEncoding", IsRequired = false, DefaultValue = "")] public string TextEncoding { get { return (string)this["textEncoding"]; } } /// /// Gets the listeners' configuration. /// [ConfigurationProperty("listeners", IsRequired = false)] public ListenerConfigCollection Listeners { get { return this["listeners"] as ListenerConfigCollection; } } /// /// Gets the listeners' configuration. /// IEnumerable IServerConfig.Listeners { get { return this.Listeners; } } /// /// Gets the command assemblies configuration. /// /// /// The command assemblies. /// [ConfigurationProperty("commandAssemblies", IsRequired = false)] public CommandAssemblyCollection CommandAssemblies { get { return this["commandAssemblies"] as CommandAssemblyCollection; } } IEnumerable IServerConfig.CommandAssemblies { get { return this.CommandAssemblies; } } /// /// 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); } /// /// Gets a value indicating whether an unknown attribute is encountered during deserialization. /// To keep compatible with old configuration /// /// 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) { //To keep compatible with old configuration if (!"serviceName".Equals(name, StringComparison.OrdinalIgnoreCase)) return base.OnDeserializeUnrecognizedAttribute(name, value); this["serverTypeName"] = value; return true; } } }