/// <summary>
        /// Asynchronously authenticates and logs in to the server with the specified parameters.
        /// </summary>
        /// <remarks>
        /// If this method returns normally, a <see cref="LoggedIn"/> event may be raised. Also,
        /// successful completion of this operation will update the <see cref="User"/>.
        /// </remarks>
        /// <param name="parameters">Login parameters that specify the user to authenticate</param>
        /// <param name="completeAction">This action will be invoked immediately after the operation
        /// completes and is called in all cases including success, cancellation, and error. This
        /// parameter is optional.
        /// </param>
        /// <param name="userState">This state will be set into
        /// <see cref="OperationBase.UserState"/>. This parameter is optional.
        /// </param>
        /// <returns>Returns the login operation.</returns>
        /// <exception cref="InvalidOperationException"> is thrown if this method is called while
        /// another asynchronous operation is still being processed.
        /// </exception>
        /// <seealso cref="LoggedIn"/>
        public LoginOperation Login(LoginParameters parameters, Action <LoginOperation> completeAction, object userState)
        {
            this.StartOperation(
                new LoginOperation(this, parameters, this.WrapCompleteAction <LoginOperation>(completeAction), userState));

            return((LoginOperation)this.Operation);
        }
Beispiel #2
0
        /// <summary>
        /// Begins an asynchronous <c>Login</c> operation.
        /// </summary>
        /// <param name="parameters">Login parameters that specify the user to authenticate</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <exception cref="InvalidOperationException"> is thrown if the
        /// <see cref="WebAuthenticationService.DomainContext"/> is <c>null</c> and a new instance
        /// cannot be created.
        /// </exception>
        /// <returns>The result of the login operation in case request was completed without exceptions</returns>
        protected internal override Task <LoginResult> LoginAsync(LoginParameters parameters, CancellationToken cancellationToken)
        {
            this.Initialize();

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            EntityQuery query;

            try
            {
                query = (EntityQuery)this.DomainContext.GetType().GetMethod(
                    WebAuthenticationService.LoginQueryName,
                    new Type[] { typeof(string), typeof(string), typeof(bool), typeof(string) }).Invoke(
                    this.DomainContext,
                    new object[] { parameters.UserName, parameters.Password, parameters.IsPersistent, parameters.CustomData });
            }
            catch (TargetInvocationException tie)
            {
                if (tie.InnerException != null)
                {
                    throw tie.InnerException;
                }
                throw;
            }

            Task <ILoadResult> loadTask = LoadAsync(query, cancellationToken);

            return(LoadUserImplementation(loadTask));

            async Task <LoginResult> LoadUserImplementation(Task <ILoadResult> loadTask)
            {
                var result = await loadTask.ConfigureAwait(false);

                IPrincipal user = (IPrincipal)result.Entities.SingleOrDefault();

                this.PrepareUser(user);
                return(new LoginResult(user, (user != null)));
            }
        }
        /// <summary>
        /// Begins an asynchronous <c>Login</c> operation.
        /// </summary>
        /// <param name="parameters">Login parameters that specify the user to authenticate</param>
        /// <param name="callback">The callback to invoke when the asynchronous call completes</param>
        /// <param name="state">The optional result state</param>
        /// <returns>An <see cref="IAsyncResult"/> that represents the asynchronous call</returns>
        /// <exception cref="InvalidOperationException"> is thrown if the
        /// <see cref="WebAuthenticationService.DomainContext"/> is <c>null</c> and a new instance
        /// cannot be created.
        /// </exception>
        protected override IAsyncResult BeginLogin(LoginParameters parameters, AsyncCallback callback, object state)
        {
            this.Initialize();

            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            WebAsyncResult result = new WebAsyncResult(callback, state);
            EntityQuery    query;

            try
            {
                query = (EntityQuery)this.DomainContext.GetType().GetMethod(
                    WebAuthenticationService.LoginQueryName,
                    new Type[] { typeof(string), typeof(string), typeof(bool), typeof(string) }).Invoke(
                    this.DomainContext,
                    new object[] { parameters.UserName, parameters.Password, parameters.IsPersistent, parameters.CustomData });
            }
            catch (TargetInvocationException tie)
            {
                if (tie.InnerException != null)
                {
                    throw tie.InnerException;
                }
                throw;
            }

            result.InnerOperation = this.DomainContext.Load(
                query,
                LoadBehavior.MergeIntoCurrent,
                (Action <LoadOperation>) this.HandleOperationComplete,
                result);

            return(result);
        }
        /// <summary>
        /// Begins an asynchronous <c>Login</c> operation.
        /// </summary>
        /// <param name="parameters">Login parameters that specify the user to authenticate</param>
        /// <param name="callback">The callback to invoke when the asynchronous call completes</param>
        /// <param name="state">The optional result state</param>
        /// <returns>An <see cref="IAsyncResult"/> that represents the asynchronous call</returns>
        /// <exception cref="InvalidOperationException"> is thrown if the
        /// <see cref="WebAuthenticationService.DomainContext"/> is <c>null</c> and a new instance
        /// cannot be created.
        /// </exception>
        protected override IAsyncResult BeginLogin(LoginParameters parameters, AsyncCallback callback, object state)
        {
            this.Initialize();

            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            WebAsyncResult result = new WebAsyncResult(callback, state);
            EntityQuery query;

            try
            {
                query = (EntityQuery)this.DomainContext.GetType().GetMethod(
                    WebAuthenticationService.LoginQueryName,
                    new Type[] { typeof(string), typeof(string), typeof(bool), typeof(string) }).Invoke(
                    this.DomainContext,
                    new object[] { parameters.UserName, parameters.Password, parameters.IsPersistent, parameters.CustomData });
            }
            catch (TargetInvocationException tie)
            {
                if (tie.InnerException != null)
                {
                    throw tie.InnerException;
                }
                throw;
            }

            result.InnerOperation = this.DomainContext.Load(
                query,
                LoadBehavior.MergeIntoCurrent,
                (Action<LoadOperation>)this.HandleOperationComplete,
                result);

            return result;
        }
 /// <summary>
 /// <c>Login</c> is not an operation supported for Windows authentication
 /// </summary>
 /// <param name="parameters">The parameter is not used.</param>
 /// <param name="callback">The parameter is not used.</param>
 /// <param name="state">The parameter is not used.</param>
 /// <returns>The result.</returns>
 /// <exception cref="NotSupportedException"> is always thrown.</exception>
 protected override IAsyncResult BeginLogin(LoginParameters parameters, AsyncCallback callback, object state)
 {
     throw new NotSupportedException(Resources.ApplicationServices_WANoLogin);
 }
 protected override IAsyncResult BeginLogin(LoginParameters parameters, AsyncCallback callback, object state)
 {
     throw new NotSupportedException(Resources.WebContext_AuthenticationNotSet);
 }
Beispiel #7
0
 protected internal override IAsyncResult BeginLogin(LoginParameters parameters, AsyncCallback callback, object state)
 {
     throw new NotSupportedException(Resources.WebContext_AuthenticationNotSet);
 }
 protected internal override Task <LoginResult> LoginAsync(LoginParameters parameters, CancellationToken cancellationToken)
 {
     throw new NotSupportedException(Resources.WebContext_AuthenticationNotSet);
 }
Beispiel #9
0
 /// <summary>
 /// Asynchronously authenticates and logs in to the server with the specified parameters.
 /// </summary>
 /// <remarks>
 /// This method starts an operation with no complete action or user state. If this method
 /// returns normally, a <see cref="LoggedIn"/> event may be raised. Also, successful
 /// completion of this operation will update the <see cref="User"/>.
 /// </remarks>
 /// <param name="parameters">Login parameters that specify the user to authenticate</param>
 /// <returns>Returns the login operation.</returns>
 /// <exception cref="InvalidOperationException"> is thrown if this method is called while
 /// another asynchronous operation is still being processed.
 /// </exception>
 /// <seealso cref="LoggedIn"/>
 public LoginOperation Login(LoginParameters parameters)
 {
     return(this.Login(parameters, null, null));
 }
        /// <summary>
        /// <c>Login</c> is not an operation supported for Windows authentication
        /// </summary>
        /// <param name="parameters">The parameter is not used.</param>
        /// <param name="cancellationToken">The parameter is not used.</param>
        /// <returns>The result.</returns>
        /// <exception cref="NotSupportedException"> is always thrown.</exception>

        protected internal override Task <LoginResult> LoginAsync(LoginParameters parameters, CancellationToken cancellationToken)
        {
            throw new NotSupportedException(Resources.ApplicationServices_WANoLogin);
        }
Beispiel #11
0
 internal LoginOperation(AuthenticationService service, LoginParameters loginParameters, Action<LoginOperation> completeAction, object userState)
     : base(service, userState)
 {
     this._loginParameters = loginParameters;
     this._completeAction = completeAction;
 }
 /// <summary>
 /// Begins an asynchronous <c>Login</c> operation.
 /// </summary>
 /// <remarks>
 /// This method is invoked from <c>Login</c>. Exceptions thrown from this method will
 /// prevent the operation from starting and then be thrown from <c>Login</c>.
 /// </remarks>
 /// <param name="parameters">Login parameters that specify the user to authenticate. This
 /// parameter is optional.</param>
 /// <param name="callback">This callback should be invoked when the asynchronous call completes.
 /// If the asynchronous call is canceled, the callback should not be invoked. This parameter
 /// is optional.
 /// </param>
 /// <param name="state">The state should be set into the <see cref="IAsyncResult"/> this
 /// method returns. This parameter is optional.
 /// </param>
 /// <returns>An <see cref="IAsyncResult"/> that represents the asynchronous call and
 /// will be passed to the cancel and end methods.
 /// </returns>
 /// <seealso cref="CancelLogin"/>
 /// <seealso cref="EndLogin"/>
 protected internal abstract IAsyncResult BeginLogin(LoginParameters parameters, AsyncCallback callback, object state);
Beispiel #13
0
 /// <summary>
 /// <c>Login</c> is not an operation supported for Windows authentication
 /// </summary>
 /// <param name="parameters">The parameter is not used.</param>
 /// <param name="callback">The parameter is not used.</param>
 /// <param name="state">The parameter is not used.</param>
 /// <returns>The result.</returns>
 /// <exception cref="NotSupportedException"> is always thrown.</exception>
 protected internal override IAsyncResult BeginLogin(LoginParameters parameters, AsyncCallback callback, object state)
 {
     throw new NotSupportedException(Resources.ApplicationServices_WANoLogin);
 }
Beispiel #14
0
 internal LoginOperation(AuthenticationService service, LoginParameters loginParameters, Action <LoginOperation> completeAction, object userState) :
     base(service, userState)
 {
     this._loginParameters = loginParameters;
     this._completeAction  = completeAction;
 }