Пример #1
0
 public IProcessedMessage SendModel()
 {
     return(MessageProcessor.GetInstance().Send(Model, this, Callback));
 }
Пример #2
0
        public void Start()
        {
            lock (MessageProcessor.GetInstance())
            {
                if (!_isLoaded)
                {
                    Logger.GetInstance().WriteLine("Loading configuration: " +
                                                   (String.IsNullOrEmpty(ConfigPath) ? MessageProcessor.defaultConfigPath : ConfigPath));
                    try
                    {
                        if (_configParser != null)
                        {
                            MessageProcessor.GetInstance().Load(_configParser);
                        }
                        else if (!String.IsNullOrEmpty(ConfigPath))
                        {
                            CreateXmlConfigParser();
                            MessageProcessor.GetInstance().Load(_configParser);
                        }
                        else
                        {
                            MessageProcessor.GetInstance().Load();
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.GetInstance().Write(ex, "Can't load configuration, application can't continue. ");
                        return;
                    }
                }
                _isLoaded = true;
            }

            try
            {
                System.Net.IPAddress ip = System.Net.IPAddress.Any;
                if (!String.IsNullOrEmpty(IPAddress))
                {
                    ip = Dns.GetHostAddresses(IPAddress)[0];
                }
                _server = new TcpListener(ip, Port);
                _server.Start((int)SocketOptionName.MaxConnections);
                Logger.GetInstance().WriteLine("Starts listening port " + Port
                                               + (String.IsNullOrEmpty(IPAddress) ? "" : " on address " + IPAddress)
                                               + " ...");
                EventHandler <ListeningEventArgs> handler = StartListeningEvent;
                if (handler != null)
                {
                    handler(this, new ListeningEventArgs(ip, Port, DateTime.Now));
                }

                _stopped = false;
                DoBeginAcceptTcpClient();
            }
            catch (Exception e)
            {
                Logger.GetInstance().Write(e);
                Stop();
                throw e;
            }
        }