示例#1
0
 protected virtual void OnConnectionStatusChangedEvent(RasConnectionState state)
 {
     if (ConnectionStatusChanged != null)
     {
         ConnectionStatusChanged(state);
     }
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RasConnectionState"/> class.
 /// </summary>
 /// <param name="connectionState">The state of the connection.</param>
 /// <param name="device">The device through which the connection has been established.</param>
 /// <param name="phoneNumber">The phone number dialed for this specific connection.</param>
 /// <param name="localEndpoint">Optional. The local client endpoint information of a virtual private network (VPN) tunnel.</param>
 /// <param name="remoteEndpoint">Optional. The remote client endpoint information of a virtual private network (VPN) tunnel.</param>
 /// <param name="connectionSubState">The state of an Internet Key Exchange version2 (IKEv2) virtual private network (VPN) tunnel.</param>
 public RasConnectionStatus(RasConnectionState connectionState, RasDevice device, string phoneNumber, IPAddress localEndpoint, IPAddress remoteEndpoint, RasConnectionSubState connectionSubState)
 {
     ConnectionState    = connectionState;
     Device             = device ?? throw new ArgumentNullException(nameof(device));
     PhoneNumber        = phoneNumber;
     LocalEndPoint      = localEndpoint;
     RemoteEndPoint     = remoteEndpoint;
     ConnectionSubState = connectionSubState;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DotRas.StateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="callbackId">The application defined value that was specified during dialing.</param>
 /// <param name="subEntryId">The one-based index for the phone book entry associated with this connection.</param>
 /// <param name="handle">The handle of the connection.</param>
 /// <param name="state">The state the remote access connection is about to enter.</param>
 /// <param name="errorCode">The error code (if any) that occurred.</param>
 /// <param name="errorMessage">The error message of the <paramref name="errorCode"/> that occurred.</param>
 /// <param name="extendedErrorCode">The extended error code (if any) that occurred.</param>
 internal StateChangedEventArgs(IntPtr callbackId, int subEntryId, RasHandle handle, RasConnectionState state, int errorCode, string errorMessage, int extendedErrorCode)
 {
     this.CallbackId = callbackId;
     this.SubEntryId = subEntryId;
     this.Handle = handle;
     this.State = state;
     this.ErrorCode = errorCode;
     this.ErrorMessage = errorMessage;
     this.ExtendedErrorCode = extendedErrorCode;
 }
示例#4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DotRas.StateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="callbackId">The application defined value that was specified during dialing.</param>
 /// <param name="subEntryId">The one-based index for the phone book entry associated with this connection.</param>
 /// <param name="handle">The handle of the connection.</param>
 /// <param name="state">The state the remote access connection is about to enter.</param>
 /// <param name="errorCode">The error code (if any) that occurred.</param>
 /// <param name="errorMessage">The error message of the <paramref name="errorCode"/> that occurred.</param>
 /// <param name="extendedErrorCode">The extended error code (if any) that occurred.</param>
 internal StateChangedEventArgs(IntPtr callbackId, int subEntryId, RasHandle handle, RasConnectionState state, int errorCode, string errorMessage, int extendedErrorCode)
 {
     CallbackId        = callbackId;
     SubEntryId        = subEntryId;
     Handle            = handle;
     State             = state;
     ErrorCode         = errorCode;
     ErrorMessage      = errorMessage;
     ExtendedErrorCode = extendedErrorCode;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RasDialCallbackTraceEvent"/> class.
 /// </summary>
 /// <param name="result">The result of the callback.</param>
 /// <param name="callbackId">The callback id.</param>
 /// <param name="subEntryId">The subentry id.</param>
 /// <param name="dangerousHandle">The dangerous handle.</param>
 /// <param name="message">The message.</param>
 /// <param name="state">The state.</param>
 /// <param name="errorCode">The error code.</param>
 /// <param name="extendedErrorCode">The extended error code.</param>
 public RasDialCallbackTraceEvent(bool result, IntPtr callbackId, int subEntryId, IntPtr dangerousHandle, int message, RasConnectionState state, int errorCode, int extendedErrorCode)
 {
     Result            = result;
     CallbackId        = callbackId;
     SubEntryId        = subEntryId;
     DangerousHandle   = dangerousHandle;
     Message           = message;
     State             = state;
     ErrorCode         = errorCode;
     ExtendedErrorCode = extendedErrorCode;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RasDialCallbackTraceEvent"/> class.
 /// </summary>
 /// <param name="result">The result of the callback.</param>
 /// <param name="callbackId">The callback id.</param>
 /// <param name="subEntryId">The subentry id.</param>
 /// <param name="dangerousHandle">The dangerous handle.</param>
 /// <param name="message">The message.</param>
 /// <param name="state">The state.</param>
 /// <param name="errorCode">The error code.</param>
 /// <param name="extendedErrorCode">The extended error code.</param>
 public RasDialCallbackTraceEvent(bool result, IntPtr callbackId, int subEntryId, IntPtr dangerousHandle, int message, RasConnectionState state, int errorCode, int extendedErrorCode)
 {
     this.Result = result;
     this.CallbackId = callbackId;
     this.SubEntryId = subEntryId;
     this.DangerousHandle = dangerousHandle;
     this.Message = message;
     this.State = state;
     this.ErrorCode = errorCode;
     this.ExtendedErrorCode = extendedErrorCode;
 }
示例#7
0
        public void DialAsyncCancelTest()
        {
            // Set the state at which to signal the connection should be cancelled.
            this.signalOnState = RasConnectionState.DeviceConnected;

            this.target.EntryName   = entryName;
            this.target.Credentials = TestUtilities.GetValidCredentials();
            this.target.DialAsync();

            // Wait until the state of the connection has reached the appropriate point.
            this.stateWaitHandle.WaitOne();

            this.target.DialAsyncCancel();

            // Now wait for the call to be completed to prevent a race condition.
            this.waitHandle.WaitOne();

            Assert.IsTrue(this.cancelled);
            Assert.IsFalse(this.connected);
            Assert.IsFalse(this.timedOut);
            Assert.IsNull(this.error);
        }
        public bool OnCallback(IntPtr dwCallbackId, int dwSubEntry, IntPtr hrasconn, uint message, RasConnectionState rascs, int dwError, int dwExtendedError)
        {
            GuardMustNotBeDisposed();
            GuardMustBeInitialized();

            WaitForHandleToBeTransferred();

            try
            {
                GuardRequestShouldNotBeCancelled();
                GuardErrorCodeMustBeZero(dwError);

                ExecuteStateChangedCallback(rascs);

                if (HasConnectionCompleted(rascs))
                {
                    SetConnectionResult();
                }
            }
            catch (Exception ex)
            {
                HangUpConnection();
                SetExceptionResult(ex);
            }

            return(!Completed);
        }
 private static bool HasConnectionCompleted(RasConnectionState connectionState)
 {
     return(connectionState == RasConnectionState.Connected);
 }
 private void ExecuteStateChangedCallback(RasConnectionState connectionState)
 {
     onStateChangedCallback(new StateChangedEventArgs(connectionState));
 }
示例#11
0
 //---------------------------------------------------------------------------------------
 void StateChanged(RasConnectionState state, int sNo)
 {
     labelInfo.Text     = state.ToString();
     progressBar1.Value = (int)((sNo) * (100.0 / 12));
 }
示例#12
0
        private bool RasDialCallback(IntPtr callbackId, int subEntryId, IntPtr dangerousHandle, int message, RasConnectionState state, int errorCode, int extendedErrorCode)
        {
            bool retval = true;

            lock (this.syncRoot)
            {
                RasHandle connectionHandle = null;

                try
                {
                    connectionHandle = new RasHandle(dangerousHandle, subEntryId > 1);

                    if (!this.IsBusy)
                    {
                        // The connection is no longer being dialed, stop receiving notifications for this connection attempt.
                        retval = false;
                    }
                    else
                    {
                        string errorMessage = null;
                        if (errorCode != NativeMethods.SUCCESS)
                        {
                            errorMessage = RasHelper.Default.GetRasErrorString(errorCode);
                        }

                        StateChangedEventArgs e = new StateChangedEventArgs(callbackId, subEntryId, connectionHandle, state, errorCode, errorMessage, extendedErrorCode);
                        this.OnStateChanged(e);

                        if (errorCode != NativeMethods.SUCCESS)
                        {
                            this.Abort();
                            this.PostCompleted(new RasDialException(errorCode, extendedErrorCode), false, false, false);

                            retval = false;
                        }
                        else if (state == RasConnectionState.Connected)
                        {
                            this.PostCompleted(null, false, false, true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.OnError(new System.IO.ErrorEventArgs(ex));
                }
                finally
                {
                    DiagnosticTrace.Default.TraceEvent(TraceEventType.Verbose, new RasDialCallbackTraceEvent(retval, callbackId, subEntryId, dangerousHandle, message, state, errorCode, extendedErrorCode));

                    if (connectionHandle != null)
                    {
                        connectionHandle.Dispose();
                    }
                }
            }

            return(retval);
        }
示例#13
0
        public void DialAsyncCancelTest()
        {
            // Set the state at which to signal the connection should be cancelled.
            this.signalOnState = RasConnectionState.DeviceConnected;

            this.target.EntryName = entryName;
            this.target.Credentials = TestUtilities.GetValidCredentials();
            this.target.DialAsync();

            // Wait until the state of the connection has reached the appropriate point.
            this.stateWaitHandle.WaitOne();

            this.target.DialAsyncCancel();

            // Now wait for the call to be completed to prevent a race condition.
            this.waitHandle.WaitOne();

            Assert.IsTrue(this.cancelled);
            Assert.IsFalse(this.connected);
            Assert.IsFalse(this.timedOut);
            Assert.IsNull(this.error);
        }
示例#14
0
        private bool RasDialCallback(IntPtr callbackId, int subEntryId, IntPtr dangerousHandle, int message, RasConnectionState state, int errorCode, int extendedErrorCode)
        {
            bool retval = true;

            lock (this.syncRoot)
            {
                RasHandle connectionHandle = null;

                try
                {
                    connectionHandle = new RasHandle(dangerousHandle, subEntryId > 1);

                    if (!this.IsBusy)
                    {
                        // The connection is no longer being dialed, stop receiving notifications for this connection attempt.
                        retval = false;
                    }
                    else
                    {
                        string errorMessage = null;
                        if (errorCode != NativeMethods.SUCCESS)
                        {
                            errorMessage = RasHelper.Instance.GetRasErrorString(errorCode);
                        }

                        DME.Dialer.StateChangedEventArgs e = new DME.Dialer.StateChangedEventArgs(callbackId, subEntryId, connectionHandle, state, errorCode, errorMessage, extendedErrorCode);
                        this.OnStateChanged(e);

                        if (errorCode != NativeMethods.SUCCESS)
                        {
                            this.Abort();
                            this.PostCompleted(new RasDialException(errorCode, extendedErrorCode), false, false, false);

                            retval = false;
                        }
                        else if (state == RasConnectionState.Connected)
                        {
                            this.PostCompleted(null, false, false, true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.OnError(new System.IO.ErrorEventArgs(ex));
                }
                finally
                {
                    if (connectionHandle != null)
                    {
                        connectionHandle.Dispose();
                    }
                }
             }

            return retval;
        }
        public bool OnCallback(IntPtr dwCallbackId, int dwSubEntry, IntPtr hrasconn, uint message, RasConnectionState rascs, int dwError, int dwExtendedError)
        {
            var occurredOn = DateTime.Now;
            var result     = AttachedObject.OnCallback(dwCallbackId, dwSubEntry, hrasconn, message, rascs, dwError, dwExtendedError);

            var callbackEvent = new RasDialCallbackCompletedTraceEvent
            {
                OccurredOn = occurredOn,
                Result     = result
            };

            callbackEvent.Args.Add(nameof(dwCallbackId), dwCallbackId);
            callbackEvent.Args.Add(nameof(dwSubEntry), dwSubEntry);
            callbackEvent.Args.Add(nameof(hrasconn), hrasconn);
            callbackEvent.Args.Add(nameof(message), message);
            callbackEvent.Args.Add(nameof(rascs), rascs);
            callbackEvent.Args.Add(nameof(dwError), dwError);
            callbackEvent.Args.Add(nameof(dwExtendedError), dwExtendedError);

            LogVerbose(callbackEvent);
            return(result);
        }
示例#16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="state">The state of the connection.</param>
 public StateChangedEventArgs(RasConnectionState state)
 {
     State = state;
 }
示例#17
0
 protected virtual void OnConnectionStatusChangedEvent(RasConnectionState state)
 {
     if (ConnectionStatusChanged != null)
     {
         ConnectionStatusChanged(state);
     }
 }