コード例 #1
0
        /// <summary>
        /// Disconnects the previously connected connection
        /// </summary>
        /// <returns></returns>
        public bool Disconnect()
        {
            try
            {
                // the connection may have already been disconnected
                if (!_connection.IsAlive)
                {
                    return(false);
                }

                /*
                 * raise the before disconnect event
                 * */
                AddressBookItemConnectionManagerCancelEventArgs e = new AddressBookItemConnectionManagerCancelEventArgs(this, false);
                this.OnBeforeConnectionClosed(this, e);

                // bail on the connection if we have been told to cancel
                if (e.Cancel)
                {
                    return(false);
                }

                // disconnect the connection from the remote host
                _connection.Close();

                return(true);
            }
            catch (Exception ex)
            {
                this.OnConnectionException(this, new AddressBookItemConnectionManagerExceptionEventArgs(this, ex));
            }
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Connects a connection to the address and port specified by the address book item
        /// </summary>
        /// <param name="autoRecv">A flag that indicates whether the connection should begin receiving data as soon as it is connected. Some sessions may not need to receive immediately</param>
        /// <returns></returns>
        public bool Connect(bool autoRecv, object stateObject)
        {
            try
            {
                this.InternalEstablishContext();

                /*
                 * raise the before connect event
                 * */
                AddressBookItemConnectionManagerCancelEventArgs e = new AddressBookItemConnectionManagerCancelEventArgs(this, false);
                this.OnBeforeConnectionOpened(this, e);

                // bail on the connection if we have been told to cancel
                if (e.Cancel)
                {
                    return(false);
                }

                // resolve the address book item to a remote host
                IPEndPoint ep = HttpUtils.Resolve(_item.Address, _item.Port, this, new AddressResolutionEventHandler(this.OnInternalConnectionResolvingAddress), stateObject);

                // connect the connection to the remote host
                _connection.Open(ep, autoRecv);

                return(true);
            }
            catch (Exception ex)
            {
                this.OnConnectionException(this, new AddressBookItemConnectionManagerExceptionEventArgs(this, ex));
            }
            return(false);
        }
コード例 #3
0
 /// <summary>
 /// Raises the BeforeDisconnected event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnBeforeConnectionClosed(object sender, AddressBookItemConnectionManagerCancelEventArgs e)
 {
     try
     {
         if (this.BeforeConnectionClosed != null)
         {
             this.BeforeConnectionClosed(sender, e);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex);
     }
 }
コード例 #4
0
		/// <summary>
		/// Raises the BeforeDisconnected event
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected virtual void OnBeforeConnectionClosed(object sender, AddressBookItemConnectionManagerCancelEventArgs e)
		{
			try
			{
				if (this.BeforeConnectionClosed != null)
					this.BeforeConnectionClosed(sender, e);
			}
			catch(Exception ex)
			{
				Debug.WriteLine(ex);
			}
		}
コード例 #5
0
		/// <summary>
		/// Disconnects the previously connected connection
		/// </summary>
		/// <returns></returns>
		public bool Disconnect()
		{
			try
			{
				// the connection may have already been disconnected
				if (!_connection.IsAlive)
					return false;

				/*
				 * raise the before disconnect event 
				 * */
				AddressBookItemConnectionManagerCancelEventArgs e = new AddressBookItemConnectionManagerCancelEventArgs(this, false);
				this.OnBeforeConnectionClosed(this, e);

				// bail on the connection if we have been told to cancel
				if (e.Cancel)
					return false;

				// disconnect the connection from the remote host
				_connection.Close();

				return true;
			}
			catch(Exception ex)
			{
				this.OnConnectionException(this, new AddressBookItemConnectionManagerExceptionEventArgs(this, ex));
			}
			return false;
		}
コード例 #6
0
		/// <summary>
		/// Connects a connection to the address and port specified by the address book item
		/// </summary>
		/// <param name="autoRecv">A flag that indicates whether the connection should begin receiving data as soon as it is connected. Some sessions may not need to receive immediately</param>
		/// <returns></returns>
		public bool Connect(bool autoRecv, object stateObject)
		{
			try
			{				
				this.InternalEstablishContext();

				/*
				 * raise the before connect event 
				 * */
				AddressBookItemConnectionManagerCancelEventArgs e = new AddressBookItemConnectionManagerCancelEventArgs(this, false);
				this.OnBeforeConnectionOpened(this, e);

				// bail on the connection if we have been told to cancel
				if (e.Cancel)
					return false;

				// resolve the address book item to a remote host
				IPEndPoint ep = HttpUtils.Resolve(_item.Address, _item.Port, this, new AddressResolutionEventHandler(this.OnInternalConnectionResolvingAddress), stateObject);						

				// connect the connection to the remote host
				_connection.Open(ep, autoRecv);

				return true;
			}
			catch(Exception ex)
			{
				this.OnConnectionException(this, new AddressBookItemConnectionManagerExceptionEventArgs(this, ex));
			}
			return false;
		}