コード例 #1
0
ファイル: SecurityContext.cs プロジェクト: ktei/MySpace
        public void SignIn(string userName, string password, bool isPersistent, Action<SignInResult> completeAction)
        {
            if (completeAction == null)
                throw new ArgumentNullException("completeAction");
            try
            {
                IsBusy = true;
                Status = AppStrings.SigningInMessage;
                var svc = new SecurityServiceClient();

                svc.SignInCompleted += (sender, e) =>
                {
                    var status = e.Result;
                    SignInResult result = null;
                    if (status == SignInStaus.Success)
                    {
                        User = new IdentityImpl(userName);
                        IsAuthenticated = true;
                        result = new SignInResult(User);
                    }
                    else if (status == SignInStaus.WrongCredentials)
                    {
                        result = new SignInResult(null, false, ErrorStrings.InvalidCredentialsMessage);
                    }
                    else if (status == SignInStaus.Inactive)
                    {
                        result = new SignInResult(null, false, ErrorStrings.InactiveAccountMessage);
                    }
                    else
                    {
                        result = new SignInResult(null, false, ErrorStrings.GenericServerErrorMessage);
                    }
                    completeAction(result);
                    IsBusy = false;
                };
                svc.SignInAsync(userName, password, isPersistent);
            }
            catch
            {
                completeAction(new SignInResult(null, false, ErrorStrings.GenericErrorMessage));
                IsBusy = false;
            }
        }