Ejemplo n.º 1
0
        public void Connect( )
        {
            Debug.Print( "NetworkWrapper.Connect: IsConnected={0}", IsConnected );
            if ( IsConnected ) {
                throw new InvalidOperationException( "Network is already connected" );
            }

            Debug.Print( "NetworkWrapper.Connect: _serverEnumerator={0}", _serverEnumerator );
            if ( null == _serverEnumerator ) {
                _serverEnumerator = Servers.GetEnumerator( );
            }

            Debug.Print( "NetworkWrapper.Connect: advancing enumerator" );
            if ( !_serverEnumerator.MoveNext( ) ) {
                Debug.Print( "NetworkWrapper.Connect: out of server:port pairs to try." );
                _haveRaisedStartedEvent = false;
                return;
            }
            _currentServer = _serverEnumerator.Current;
            OnServerChange( _currentServer );

            Debug.Print( "NetworkWrapper.Connect: constructing _serverConnector" );
            _serverConnector = new ServerConnector( new ConnectionConfiguration {
                NickName = "ZiveIrcTest",
                UserName = "******",
                RealName = "Testing instance of ZiveIrc. Contact: IceKarma",
                NickServPassword = "******",
                ServerHostName = _currentServer.ServerConfiguration.HostName,
                Ports = _currentServer.ServerConfiguration.Ports,
            } );
            _serverConnector.ConnectionEstablished += ConnectionEstablished;
            _serverConnector.ConnectionAttemptStarted += ConnectionAttemptStarted;
            _serverConnector.ConnectionAttemptFailed += ConnectionAttemptFailed;
            _serverConnector.ConnectionFailed += ConnectionFailed;

            Debug.Print( "NetworkWrapper.Connect: Calling _serverConnector.BeginConnect()" );
            try {
                _serverConnector.BeginConnect( );
            }
            catch ( Exception e ) {
                Debug.Print( "NetworkWrapper.Connect: _serverConnector.BeginConnect threw an exception:\n{0}", e );
            }
        }
Ejemplo n.º 2
0
        private void Run( string[ ] args ) {
#if DEBUG
            Debug.Listeners.Add( new CustomTraceListener( ) );
#endif

            var ports = new Collection<int>( );
            foreach ( var arg in args[ 1 ].Split( new[ ] { ',' }, StringSplitOptions.RemoveEmptyEntries ) ) {
                if ( '+' == arg[ 0 ] ) {
                    IntHelper.TryParse( arg.Substring( 1 ), _ => ports.Add( -_ ) );
                } else {
                    IntHelper.TryParse( arg, ports.Add );
                }
            }

            Console.CancelKeyPress += ConsoleCancelKeyPress;

            _identServer = new IdentServer( );
            _identServer.Start( );

            _serverConnector = new ServerConnector( new ConnectionConfiguration {
                NickName = "ZiveIrcTest",
                UserName = "******",
                RealName = "Testing instance of ZiveIrc. Contact: IceKarma",
                NickServPassword = "******",
                ServerHostName = args[ 0 ],
                Ports = ports,
            } );

            _serverConnector.ConnectionEstablished += ConnectionEstablished;
            _serverConnector.ConnectionAttemptStarted += ConnectionAttemptStarted;
            _serverConnector.ConnectionAttemptFailed += ConnectionAttemptFailed;
            _serverConnector.ConnectionFailed += ConnectionFailed;

            Console.WriteLine( "Starting connection attempt." );
            _serverConnector.BeginConnect( );

            _doneEvent.WaitOne( );
            _doneEvent.Dispose( );
            _doneEvent = null;
        }
Ejemplo n.º 3
0
        public void Connect( )
        {
            if ( IsConnected ) {
                throw new InvalidOperationException( "Server is already connected" );
            }

            Debug.Print( "ServerWrapper.Connect: constructing _serverConnector" );
            _serverConnector = new ServerConnector( new ConnectionConfiguration {
                NickName = _configuration.UserConfiguration.NickName,
                UserName = _configuration.UserConfiguration.UserName,
                RealName = _configuration.UserConfiguration.RealName,
                NickServPassword = "******",
                ServerHostName = ServerConfiguration.HostName,
                Ports = ServerConfiguration.Ports,
            } );
            _serverConnector.ConnectionEstablished += HandleConnectionEstablished;
            _serverConnector.ConnectionAttemptStarted += HandleConnectionAttemptStarted;
            _serverConnector.ConnectionAttemptFailed += HandleConnectionAttemptFailed;
            _serverConnector.ConnectionFailed += HandleConnectionFailed;

            Debug.Print( "ServerWrapper.Connect: Calling _serverConnector.BeginConnect()" );
            try {
                _serverConnector.BeginConnect( );
            }
            catch ( Exception e ) {
                Debug.Print( "ServerWrapper.Connect: _serverConnector.BeginConnect threw an exception:\n{0}", e );
            }
        }