Exemple #1
0
        /// <summary>
        /// Creates CommunicationServer instance.
        /// </summary>
        /// <param name="config">Server configuration.</param>
        public CommunicationServer(ServerConfig config)
        {
            // TODO Communication server should be a backup by default. Some work is needed here.

            Config = config;

            _componentOverseer = new ComponentOverseer(Config.CommunicationTimeout, ComponentOverseerCheckInterval);
            _workManager = new WorkManager(_componentOverseer);
            _msgProcessor = new MessageProcessor(_componentOverseer, _workManager);
            _tcpServer = new TcpServer(Config.Address, _msgProcessor);
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            CommunicationServer communicationServer;
            try
            {
                var config = ServerConfigurationSection.LoadConfig("serverConfig", args);

                var serverAddress = IpEndPointParser.Parse(config.Address, config.Port);
                var timeout = config.Timeout;
                var isBackup = config.IsBackup;

                IPEndPoint masterServerAddress;
                if (isBackup)
                    masterServerAddress = IpEndPointParser.Parse(config.MasterServer.Address, config.MasterServer.Port);

                //_logger.Info("Server address: " + serverAddress);

                var serverConfig = new ServerConfig
                {
                    Mode = isBackup ? ServerConfig.ServerMode.Backup : ServerConfig.ServerMode.Primary,
                    Address = serverAddress,
                    CommunicationTimeout = timeout
                };

                communicationServer = new CommunicationServer(serverConfig);
            }
            catch (Exception ex)
            {
                var errorText = string.Format("{0}:{1}", ex.GetType().FullName, ex.Message);
                if (ex.InnerException != null)
                    errorText += string.Format("|({0}:{1})", ex.InnerException.GetType().FullName,
                        ex.InnerException.Message);
                //_logger.Error(errorText);
                return;
            }

            communicationServer.Start();

            while (Console.ReadLine() != "exit")
            {
                // input handling
            }

            communicationServer.Stop();
        }