/// <summary> Creates an instance of Client. </summary> /// <param name="serverConfiguration">Contains the properties necessary to /// connect to the server.</param> /// <param name="protocolConfigurations">A Dictionary of ProtocolConfiguration /// objects keyed with each protocol's unique identifier.</param> /// <param name="logger">An optional Logger to log messages. If null is passed, /// a <see cref="US.OpenServer.Logger"/> object is created.</param> /// <param name="userData">An optional Object the caller can pass through to /// each protocol.</param> public Client( ServerConfiguration serverConfiguration, Dictionary<ushort, ProtocolConfiguration> protocolConfigurations, Logger logger = null, object userData = null) { if (logger == null) logger = new Logger(); Logger = logger; Logger.Log(Level.Info, string.Format("Execution Mode: {0}", Debugger.IsAttached ? "Debug" : "Release")); ServerConfiguration = serverConfiguration; ProtocolConfigurations = protocolConfigurations; UserData = userData; }
/// <summary> Creates an instance of Server. </summary> /// <remarks> All parameters are optional. If null is passed, the object's /// configuration is read from the app.config file. If SSL/TLS is enabled, gets /// the server-side certificate from the local certificate store.</remarks> /// <param name="logger">An optional Logger to log messages. If null is passed, /// an attempt is made to read the log4net configuration from the app.config's /// file. If the configuration is present, a <see cref="US.OpenServer.Log4NetLogger"/> /// is created otherwise a <see cref="US.OpenServer.ConsoleLogger"/> is /// created.</param> /// <param name="serverConfiguration">An optional ServerConfiguration that contains the /// properties necessary to create the server. If null is passed, the /// configuration is read from the app.config's 'server' XML section /// node.</param> /// <param name="protocolConfigurations">An optional Dictionary of /// ProtocolConfiguration objects keyed with each protocol's unique identifier. /// If null is passed, the configuration is read from the app.config's /// 'protocols' XML section node.</param> /// <param name="userData">An Object the caller can pass through to each protocol.</param> public Server( ServerConfiguration serverConfiguration = null, Dictionary<ushort, ProtocolConfiguration> protocolConfigurations = null, Logger logger = null, object userData = null) { if (logger == null) { object log4NetConfiguration = ConfigurationManager.GetSection("log4net"); if (log4NetConfiguration != null) logger = new Log4NetLogger("DotNetOpenServer"); else logger = new ConsoleLogger(); } Logger = logger; Logger.Log(Level.Info, string.Format("Execution Mode: {0}", Debugger.IsAttached ? "Debug" : "Release")); if (serverConfiguration == null) serverConfiguration = (ServerConfiguration)ConfigurationManager.GetSection("server"); if (serverConfiguration == null) serverConfiguration = new ServerConfiguration(); ServerConfiguration = serverConfiguration; if (serverConfiguration.TlsConfiguration.Enabled) { certificate = Session.GetCertificateFromStore( string.Format("CN={0}", ServerConfiguration.TlsConfiguration.Certificate)); if (certificate == null) { throw new Exception(string.Format( "SSL Certificate '{0}' not found.", ServerConfiguration.TlsConfiguration.Certificate)); } } if (protocolConfigurations == null) protocolConfigurations = (Dictionary<ushort, ProtocolConfiguration>)ConfigurationManager.GetSection("protocols"); if (protocolConfigurations == null) protocolConfigurations = new Dictionary<ushort, ProtocolConfiguration>(); ProtocolConfigurations = protocolConfigurations; UserData = userData; t = new Thread(new ThreadStart(Run)); t.Start(); }
/// <summary> /// Log's an exception. /// </summary> /// <param name="ex">An Exception to log.</param> protected void LogException(Exception ex) { Logger.Log(ex); }
/// <summary> Creates an instance of Client. </summary> /// <remarks> All parameters are optional. If null is passed, the object's /// configuration is read from the app.config file. </remarks> /// <param name="logger">An optional Logger to log messages. If null is passed, /// an attempt is made to read the log4net configuration from the app.config /// file. If the configuration is not present a <see cref="US.OpenServer.Log4NetLogger"/> /// is created otherwise a <see cref="US.OpenServer.ConsoleLogger"/> is /// created.</param> /// <param name="serverConfiguration">An optional ServerConfiguration that contains the /// properties necessary to connect to the server. If null is passed, the /// configuration is read from the app.config's 'server' XML section /// node.</param> /// <param name="protocolConfigurations">An optional Dictionary of /// ProtocolConfiguration objects keyed with each protocol's unique identifier. /// If null is passed, the configuration is read from the app.config's /// 'protocols' XML section node.</param> /// <param name="userData">An Object the caller can pass through to each protocol.</param> public Client( ServerConfiguration serverConfiguration = null, Dictionary<ushort, ProtocolConfiguration> protocolConfigurations = null, Logger logger = null, object userData = null) { if (logger == null) { object log4NetConfiguration = ConfigurationManager.GetSection("log4net"); if (log4NetConfiguration != null) logger = new Log4NetLogger("DotNetOpenServerClient"); else logger = new ConsoleLogger(); } Logger = logger; Logger.Log(Level.Info, string.Format("Execution Mode: {0}", Debugger.IsAttached ? "Debug" : "Release")); if (serverConfiguration == null) serverConfiguration = (ServerConfiguration)ConfigurationManager.GetSection("server"); if (serverConfiguration == null) { serverConfiguration = new ServerConfiguration(); serverConfiguration.Host = ServerConfiguration.DEFAULT_HOST; } ServerConfiguration = serverConfiguration; if (protocolConfigurations == null) protocolConfigurations = (Dictionary<ushort, ProtocolConfiguration>)ConfigurationManager.GetSection("protocols"); if (protocolConfigurations == null) protocolConfigurations = new Dictionary<ushort, ProtocolConfiguration>(); ProtocolConfigurations = protocolConfigurations; UserData = userData; }
/// <summary> /// Log's a message. /// </summary> /// <param name="level">A Level that specifies the priority of the message.</param> /// <param name="message">A string that contains the message.</param> public void Log(Level level, string message) { Logger.Log(level, string.Format("Session [{0} {1}] - {2}", Id, Address, message)); }