public void Connect( )
        {
            Debug.Print("NetworkWrapper.Connect: IsConnected={0}", IsConnected);
            if (IsConnected)
            {
                Debug.Print("NetworkWrapper.Connect: already connected");
                return;
            }

            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.");
                CleanUp( );
                return;
            }
            _currentServer = _serverEnumerator.Current;
            OnServerChange(_currentServer);

            Debug.Print("NetworkWrapper.Connect: Calling _currentServer.Connect()");
            try {
                _currentServer.Connect( );
            }
            catch (Exception e) {
                Debug.Print("NetworkWrapper.Connect: _currentServer.Connect() threw an exception:\n{0}", e);
            }
        }
 private void CleanUp( )
 {
     Debug.Print("NetworkWrapper.CleanUp()");
     _currentServer          = null;
     _serverEnumerator       = null;
     _haveRaisedStartedEvent = false;
 }
        private void OnServerChange(ServerWrapper newServerHostName)
        {
            var handler = ServerChange;

            if (null != handler)
            {
                handler(this, new ServerChangeEventArgs(newServerHostName));
            }
        }
        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);
            }
        }
        public NetworkWrapper(NetworkConfiguration networkConfig)
        {
            NetworkConfiguration = networkConfig;

            try {
                Servers = new Collection <ServerWrapper>(networkConfig.Servers.Select(_ => {
                    var wrapper = new ServerWrapper(_)
                    {
                        NetworkWrapper = this,
                    };
                    wrapper.ConnectFailed    += HandleConnectFailed;
                    wrapper.ConnectStarted   += HandleConnectStarted;
                    wrapper.ConnectSucceeded += HandleConnectSucceeded;
                    return(wrapper);
                }).ToList( ));
            }
            catch (Exception e) {
                Debug.Print("NetworkWrapper.`ctor: caught exception:\n{0}", e);
            }
        }
 public ServerChangeEventArgs( ServerWrapper serverWrapper )
 {
     ServerWrapper = serverWrapper;
 }
 private void NetworkWrapper_ServerChange( object sender, ServerChangeEventArgs ev )
 {
     _currentServer = ev.ServerWrapper;
 }
Beispiel #8
0
 private void NetworkWrapper_ServerChange(object sender, ServerChangeEventArgs ev)
 {
     _currentServer = ev.ServerWrapper;
 }
 public ServerChangeEventArgs(ServerWrapper serverWrapper)
 {
     ServerWrapper = serverWrapper;
 }
        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 );
            }
        }
 private void OnServerChange( ServerWrapper newServerHostName )
 {
     var handler = ServerChange;
     if ( null != handler ) {
         handler( this, new ServerChangeEventArgs( newServerHostName ) );
     }
 }