예제 #1
0
        /// <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;
        }
예제 #2
0
        /// <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;
            }
            if (serverConfiguration.Host == ServerConfiguration.DEFAULT_BIND_ADDRESS)
            {
                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;
        }
예제 #3
0
        /// <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();
        }