/// <summary> /// Adds a connection manager to the list /// </summary> /// <param name="manager"></param> public void Add(AddressBookItemConnectionManager manager) { if (!this.Contains(manager)) { base.InnerList.Add(manager); } }
/// <summary> /// Removes a connection manager from the list /// </summary> /// <param name="manager"></param> public void Remove(AddressBookItemConnectionManager manager) { if (this.Contains(manager)) { base.InnerList.Remove(manager); } }
/// <summary> /// Looks up the connection manager responsible for the address book item and disconnects it from the remote host /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnDisconnectSessionForAddressBookItem(object sender, BackgroundThreadStartEventArgs e) { // retrieve the address book item that is requiring attention AddressBookItem item = (AddressBookItem)e.Args[0]; try { lock (_sessionManagers) { AddressBookItemConnectionManager manager = _sessionManagers[item]; if (manager != null) { manager.Disconnect(); } } } catch (ThreadAbortException) { // ignore thread abort exceptions } catch (Exception ex) { Debug.WriteLine(ex); } }
/// <summary> /// Creates a connection manager for the address book item, and connects the connection to the remote host specified by the address book item /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnConnectSessionForAddressBookItem(object sender, BackgroundThreadStartEventArgs e) { // retrieve the address book item that is requiring attention AddressBookItem item = (AddressBookItem)e.Args[0]; bool disconnectFirst = (bool)e.Args[1]; bool verboseSession = (bool)e.Args[2]; bool autoRecv = (bool)e.Args[3]; try { /* * if we are supposed to disconnect the current connection first * */ if (disconnectFirst) { lock (_sessionManagers) { // look up the item to see if an existing connection is already in use AddressBookItemConnectionManager prevManager = _sessionManagers[item]; // if a connection manager is found for the item then disconnect it if (prevManager != null) { prevManager.Disconnect(); } } } // create a new tcp connection in verbose mode HttpConnection connection = new HttpConnection(verboseSession); // create a new connection manager to manage the connection AddressBookItemConnectionManager manager = new AddressBookItemConnectionManager(item, connection); // wire up to the manager's events manager.ConnectionEstablishContext += new AddressBookItemConnectionManagerContextEventHandler(OnConnectionEstablishContext); manager.ConnectionResolvingAddress += new AddressBookItemConnectionManagerResolvingAddressEventHandler(OnConnectionResolvingAddress); manager.BeforeConnectionOpened += new AddressBookItemConnectionManagerCancelEventHandler(OnBeforeConnectionOpened); manager.BeforeConnectionClosed += new AddressBookItemConnectionManagerCancelEventHandler(OnBeforeConnectionClosed); manager.ConnectionOpened += new AddressBookItemConnectionManagerEventHandler(OnConnectionOpened); manager.ConnectionClosed += new AddressBookItemConnectionManagerEventHandler(OnConnectionClosed); manager.ConnectionException += new AddressBookItemConnectionManagerExceptionEventHandler(OnConnectionException); // create the thread context that will enable us to determine the background thread upon which this connection manager is operating manager.ThreadContext = new AddressBookItemBackgroundThreadContext((BackgroundThread)sender, item); // instruct the manager to connect the connection to the remote host // pass it instructions on whether it should begin receiving automatically or not // NOTE: In almost every case from a client created connection this will be false. // Only server created sessions will be set to automatically receive. manager.Connect(autoRecv, manager.ThreadContext); // add the connection manager to our list of connection managers lock (_sessionManagers) _sessionManagers.Add(manager); } catch (ThreadAbortException) { // ignore thread abort exceptions } catch (Exception ex) { Debug.WriteLine(ex); } }
/// <summary> /// Initializes a new instance of the AddressBookItemConnectionManagerContextEventArgs class /// </summary> /// <param name="manager"></param> public AddressBookItemConnectionManagerContextEventArgs(AddressBookItemConnectionManager manager) : base(manager) { }
/// <summary> /// Initializes a new instance of the AddressBookItemConnectionManagerExceptionEventArgs class /// </summary> /// <param name="manager">The manager encountering the exception</param> /// <param name="ex">The exception encountered</param> public AddressBookItemConnectionManagerExceptionEventArgs(AddressBookItemConnectionManager manager, Exception ex) : base(manager) { _ex = ex; }
/// <summary> /// Initializes a new instance of the X class /// </summary> /// <param name="manager">The manager instance raising the event</param> /// <param name="cancel">A flag that controls whether the event is cancelled or not</param> public AddressBookItemConnectionManagerCancelEventArgs(AddressBookItemConnectionManager manager, bool cancel) : base(manager) { _cancel = cancel; }
public AddressBookItemConnectionManagerResolvingAddressEventArgs(AddressBookItemConnectionManager manager, string address, int port, object stateObject) : base(manager) { _address = address; _port = port; _stateObject = stateObject; }
/// <summary> /// Removes a connection manager from the list /// </summary> /// <param name="manager"></param> public void Remove(AddressBookItemConnectionManager manager) { if (this.Contains(manager)) base.InnerList.Remove(manager); }
/// <summary> /// Initializes a new instance of the AddressBookItemConnectionManagerEventArgs class /// </summary> /// <param name="manager">The manager instance that is causing the event</param> public AddressBookItemConnectionManagerEventArgs(AddressBookItemConnectionManager manager) : base() { _manager = manager; }
/// <summary> /// Returns a flag that indicates whether the sesion manager exists in the list /// </summary> /// <param name="manager"></param> /// <returns></returns> public bool Contains(AddressBookItemConnectionManager manager) { return(base.InnerList.Contains(manager)); }
/// <summary> /// Adds a connection manager to the list /// </summary> /// <param name="manager"></param> public void Add(AddressBookItemConnectionManager manager) { if (!this.Contains(manager)) base.InnerList.Add(manager); }
/// <summary> /// Returns a flag that indicates whether the sesion manager exists in the list /// </summary> /// <param name="manager"></param> /// <returns></returns> public bool Contains(AddressBookItemConnectionManager manager) { return base.InnerList.Contains(manager); }
/// <summary> /// Creates a connection manager for the address book item, and connects the connection to the remote host specified by the address book item /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnConnectSessionForAddressBookItem(object sender, BackgroundThreadStartEventArgs e) { // retrieve the address book item that is requiring attention AddressBookItem item = (AddressBookItem)e.Args[0]; bool disconnectFirst = (bool)e.Args[1]; bool verboseSession = (bool)e.Args[2]; bool autoRecv = (bool)e.Args[3]; try { /* * if we are supposed to disconnect the current connection first * */ if (disconnectFirst) { lock(_sessionManagers) { // look up the item to see if an existing connection is already in use AddressBookItemConnectionManager prevManager = _sessionManagers[item]; // if a connection manager is found for the item then disconnect it if (prevManager != null) prevManager.Disconnect(); } } // create a new tcp connection in verbose mode HttpConnection connection = new HttpConnection(verboseSession); // create a new connection manager to manage the connection AddressBookItemConnectionManager manager = new AddressBookItemConnectionManager(item, connection); // wire up to the manager's events manager.ConnectionEstablishContext += new AddressBookItemConnectionManagerContextEventHandler(OnConnectionEstablishContext); manager.ConnectionResolvingAddress += new AddressBookItemConnectionManagerResolvingAddressEventHandler(OnConnectionResolvingAddress); manager.BeforeConnectionOpened += new AddressBookItemConnectionManagerCancelEventHandler(OnBeforeConnectionOpened); manager.BeforeConnectionClosed += new AddressBookItemConnectionManagerCancelEventHandler(OnBeforeConnectionClosed); manager.ConnectionOpened += new AddressBookItemConnectionManagerEventHandler(OnConnectionOpened); manager.ConnectionClosed += new AddressBookItemConnectionManagerEventHandler(OnConnectionClosed); manager.ConnectionException += new AddressBookItemConnectionManagerExceptionEventHandler(OnConnectionException); // create the thread context that will enable us to determine the background thread upon which this connection manager is operating manager.ThreadContext = new AddressBookItemBackgroundThreadContext((BackgroundThread)sender, item); // instruct the manager to connect the connection to the remote host // pass it instructions on whether it should begin receiving automatically or not // NOTE: In almost every case from a client created connection this will be false. // Only server created sessions will be set to automatically receive. manager.Connect(autoRecv, manager.ThreadContext); // add the connection manager to our list of connection managers lock(_sessionManagers) _sessionManagers.Add(manager); } catch(ThreadAbortException) { // ignore thread abort exceptions } catch(Exception ex) { Debug.WriteLine(ex); } }