コード例 #1
0
        /// <summary>
        /// Remove entry from phone-book, then break connection established early.
        /// </summary>
        public void Disconnect()
        {
            if (this._handle == IntPtr.Zero)
            {
                return;
            }

            Ras.RASCONNSTATUS status = new Ras.RASCONNSTATUS();

            // force hangup
            try
            {
                Ras.RasCheck(Ras.RasHangUp(this._handle));
            }
            catch (RasException ex)
            {
                if (ex.ErrorCode != (uint)RasError.ERROR_NO_CONNECTION)
                {
                    throw ex;
                }
            }

            while (6 != Ras.RasGetConnectStatus(this._handle, status))
            {
                Thread.Sleep(0);
            }

            this.DeleteEntry();
            this._handle = IntPtr.Zero;
        }
コード例 #2
0
        /// <summary>
        /// Create new entry in phone-book, then establish connection. <see cref="Disconnect()"/> method must be called in any case to balance call of this method.
        /// </summary>
        public void Connect()
        {
            if (this._handle != IntPtr.Zero)
            {
                Ras.RASCONNSTATUS status = new Ras.RASCONNSTATUS();
                uint res = Ras.RasGetConnectStatus(this._handle, status);
                if (res == 6)              // i.e. ERROR_INVALID_HANDLE
                {
                    this._handle = IntPtr.Zero;
                }
                else
                {
                    return;                     // already established
                }
            }
            uint validateName = Ras.RasValidateEntryName(null, this._params.szEntryName);

            if (validateName != (uint)RasError.SUCCESS)
            {
                throw new RasException("Entry name " + ((this._params.szEntryName == null || this._params.szEntryName.Length <= 0) ? "<Empty Name>" : this._params.szEntryName) + " not valid or already presented in phone-book.");
            }
            // 1) Create new entry
            this._ent.dwDialMode                 = 1;
            this._ent.dwDialExtraPercent         = 75;
            this._ent.dwDialExtraSampleSeconds   = 120;
            this._ent.dwHangUpExtraPercent       = 10;
            this._ent.dwHangUpExtraSampleSeconds = 120;
            this.SetEntry();
            // just test that entry was written successfully
            this.GetEntry();
            // 2) Use created entry to establish connection
            try
            {
                Ras.RasCheck(Ras.RasDial(null, (this._phonebook != null && this._phonebook.Length > 0) ? this._phonebook : null, this._params, 0, null, ref this._handle));
            }
            catch (Exception ex)
            {
                this.Disconnect();
                throw ex;
            }

            this.OnConnected();

            this.StartWatch();
            Ras.RasConnectionNotification(this._handle, this._disconnEvent.Handle, Ras.RASNOTIFICATION.RASCN_Disconnection);
        }
コード例 #3
0
		/// <summary>
		/// Remove entry from phone-book, then break connection established early.
		/// </summary>
		public void Disconnect()
		{
			if(this._handle==IntPtr.Zero)
				return;
			
			Ras.RASCONNSTATUS status = new Ras.RASCONNSTATUS();

			// force hangup
			try
			{
				Ras.RasCheck(Ras.RasHangUp(this._handle));
			}
			catch (RasException ex)
			{
				if (ex.ErrorCode!=(uint)RasError.ERROR_NO_CONNECTION)
					throw ex;
			}

			while(6!=Ras.RasGetConnectStatus(this._handle, status))
			{
				Thread.Sleep(0);
			}

			this.DeleteEntry();
			this._handle = IntPtr.Zero;

		}
コード例 #4
0
		/// <summary>
		/// Create new entry in phone-book, then establish connection. <see cref="Disconnect()"/> method must be called in any case to balance call of this method.
		/// </summary>
		public void Connect()
		{
			if(this._handle!=IntPtr.Zero)
			{
				Ras.RASCONNSTATUS status = new Ras.RASCONNSTATUS();
				uint res=Ras.RasGetConnectStatus(this._handle, status);
				if(res==6) // i.e. ERROR_INVALID_HANDLE
					this._handle = IntPtr.Zero;
				else
					return; // already established
			}
			uint validateName = Ras.RasValidateEntryName(null, this._params.szEntryName);
			if(validateName!=(uint)RasError.SUCCESS)
				throw new RasException("Entry name " + ((this._params.szEntryName==null || this._params.szEntryName.Length<=0) ? "<Empty Name>" : this._params.szEntryName) + " not valid or already presented in phone-book.");
			// 1) Create new entry
			this._ent.dwDialMode = 1;
			this._ent.dwDialExtraPercent = 75;
			this._ent.dwDialExtraSampleSeconds = 120;
			this._ent.dwHangUpExtraPercent = 10;
			this._ent.dwHangUpExtraSampleSeconds = 120;
			this.SetEntry();
			// just test that entry was written successfully
			this.GetEntry();
			// 2) Use created entry to establish connection
			try
			{
				Ras.RasCheck(Ras.RasDial(null, (this._phonebook!=null && this._phonebook.Length>0) ? this._phonebook : null, this._params, 0, null, ref this._handle));
			}
			catch (Exception ex)
			{
				this.Disconnect();
				throw ex;
			}
			
			this.OnConnected();
			
			this.StartWatch();
			Ras.RasConnectionNotification(this._handle, this._disconnEvent.Handle, Ras.RASNOTIFICATION.RASCN_Disconnection);
			
		}