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; }
private void ConnectionEstablished( object sender, ConnectionEstablishedEventArgs ev ) { Console.WriteLine( "ConsoleHarness: ConnectionEstablished:" ); Console.WriteLine( "+ remote end point: {0}", ev.Server.ServerEndPoint ); Console.WriteLine( ); _serverConnector = null; _server = ev.Server; _protocolHandler = _server.ProtocolHandler; _selfUser = _server.SelfUser; _selfUser.Error += HandleError; _selfUser.Quit += HandleSelfQuit; _server.Registered += HandleRegistered; _server.MotdComplete += HandleMotdComplete; _connected = true; }
protected virtual void Dispose( bool disposing ) { if ( disposing ) { if ( null != _serverConnector ) { _serverConnector.Dispose( ); _serverConnector = null; } if ( null != _doneEvent ) { _doneEvent.Dispose( ); _doneEvent = null; } } }
private void ConnectionFailed( object sender, EventArgs ev ) { Console.WriteLine( "ConsoleHarness: ConnectionFailed." ); Console.WriteLine( ); if ( null != _serverConnector ) { _serverConnector.Dispose( ); _serverConnector = null; } _doneEvent.Set( ); }
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 ConnectionFailed( object sender, EventArgs ev ) { Debug.Print( "NetworkWrapper.ConnectionFailed" ); if ( null != _serverConnector ) { _serverConnector.Dispose( ); _serverConnector = null; } OnConnectAttemptFailed( ); }
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 ); } }
private void CleanUp( ) { if ( null != _serverConnector ) { _serverConnector.Dispose( ); _serverConnector = null; } }