예제 #1
0
        private async Task WebAccountInvokedHandlerCoreAsync(WebAccountCommand command, WebAccountInvokedArgs eventArgs)
        {
            if (eventArgs.Action == WebAccountAction.Remove)
            {
                string loginProvider = command.WebAccount.WebAccountProvider.DisplayName;
                string providerKey   = command.WebAccount.UserName;

                RemoveLogin removeLogin = new RemoveLogin()
                {
                    LoginProvider = loginProvider,
                    ProviderKey   = providerKey
                };

                HttpResult result;
                using (AccountClient accountClient = ClientFactory.CreateAccountClient())
                {
                    result = await accountClient.RemoveLoginAsync(removeLogin);
                }

                if (result.Succeeded)
                {
                    if (loginProvider == localProvider)
                    {
                        settings.ClearPasswordCredentials();
                    }
                }
                else
                {
                    await ErrorDialog.ShowErrorsAsync(result.Errors);
                }
            }
        }
예제 #2
0
        private async void NewTodoTextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox       newTodoTextBox = (TextBox)sender;
            TodoListModel todoList       = GetDataContext <TodoListModel>(sender);

            if (!String.IsNullOrWhiteSpace(newTodoTextBox.Text))
            {
                HttpResult <TodoItem> result;
                using (TodoClient todoClient = ClientFactory.CreateTodoClient())
                {
                    result = await todoClient.AddTodoItemAsync(new TodoItem()
                    {
                        TodoListId = todoList.TodoListId, Title = newTodoTextBox.Text
                    });
                }

                if (result.Succeeded)
                {
                    todoList.Todos.Add(new TodoItemModel(result.Content)
                    {
                        TodoList = todoList
                    });
                }
                else
                {
                    await ErrorDialog.ShowErrorsAsync(result.Errors);
                }
            }
            newTodoTextBox.Text = "Add New Todo";
        }
예제 #3
0
        private async void WebAccountProviderInvokedHandler(WebAccountProviderCommand command)
        {
            string externalLoginUri = command.WebAccountProvider.Id;
            ExternalLoginResult loginExternalResult = await ExternalLoginManager.GetExternalAccessTokenAsync(externalLoginUri);

            string accessToken = loginExternalResult.AccessToken;

            if (accessToken != null)
            {
                HttpResult result;
                using (AccountClient accountClient = ClientFactory.CreateAccountClient())
                {
                    result = await accountClient.AddExternalLoginAsync(new AddExternalLogin()
                    {
                        ExternalAccessToken = accessToken
                    });
                }
                if (result.Succeeded)
                {
                    AccountsSettingsPane.Show();
                }
                else
                {
                    await ErrorDialog.ShowErrorsAsync(result.Errors);
                }
            }
            else
            {
                await ErrorDialog.ShowErrorAsync("Failed to connect to external account.");
            }
        }
예제 #4
0
        private async void AccountCommandsRequested(AccountsSettingsPane accountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs eventArgs)
        {
            AccountsSettingsPaneEventDeferral deferral = eventArgs.GetDeferral();

            HttpResult <ExternalLogin[]> result;

            using (AccountClient accountClient = ClientFactory.CreateAccountClient())
            {
                result = await accountClient.GetExternalLoginsAsync();
            }

            if (result.Succeeded)
            {
                eventArgs.HeaderText = "Please select a login provider.";
                WebAccountProviderCommandInvokedHandler providerCmdHandler = new WebAccountProviderCommandInvokedHandler(WebAccountProviderInvokedHandler);
                foreach (ExternalLogin externalLogin in result.Content)
                {
                    WebAccountProvider        provider        = new WebAccountProvider(externalLogin.Url, externalLogin.Name, App.LoginIcons[externalLogin.Name]);
                    WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, providerCmdHandler);
                    eventArgs.WebAccountProviderCommands.Add(providerCommand);
                }
            }
            else
            {
                await ErrorDialog.ShowErrorsAsync("Error connecting to external accounts.", result.Errors);
            }

            deferral.Complete();
        }
예제 #5
0
        private async void WebAccountProviderInvokedHandler(WebAccountProviderCommand command)
        {
            string externalLoginUri = command.WebAccountProvider.Id;
            ExternalLoginResult loginExternalResult = await ExternalLoginManager.GetExternalAccessTokenAsync(externalLoginUri);

            if (loginExternalResult.AccessToken != null)
            {
                // Save the access token so we can check if the user has registered
                AppSettings settings = new AppSettings();
                settings.AccessToken = loginExternalResult.AccessToken;

                HttpResult <UserInfo> result;
                using (AccountClient accountClient = ClientFactory.CreateAccountClient())
                {
                    result = await accountClient.GetUserInfoAsync();
                }
                if (result.Succeeded)
                {
                    if (result.Content.HasRegistered)
                    {
                        accessTokenSource.TrySetResult(loginExternalResult.AccessToken);
                        this.Frame.GoBack();
                    }
                    else
                    {
                        RegisterExternalPageParameters parameters = new RegisterExternalPageParameters()
                        {
                            AccessTokenSource = accessTokenSource,
                            ExternalLoginUri  = externalLoginUri,
                            UserInfo          = result.Content
                        };
                        this.Frame.Navigate(typeof(RegisterExternalPage), parameters);
                    }
                }
                else
                {
                    await ErrorDialog.ShowErrorsAsync("Failed to connected to external account.", result.Errors);
                }
            }
            else
            {
                await ErrorDialog.ShowErrorAsync("Failed to connected to external account.");
            }
        }
예제 #6
0
        private async void TodoListTitleTextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox       todoListTitleTextBox = (TextBox)sender;
            TodoListModel todoList             = GetDataContext <TodoListModel>(sender);

            string newTitle = todoListTitleTextBox.Text;

            if (newTitle != todoList.OriginalTitle)
            {
                HttpResult result;
                using (TodoClient todoClient = ClientFactory.CreateTodoClient())
                {
                    if (String.IsNullOrWhiteSpace(newTitle))
                    {
                        result = await todoClient.DeleteTodoListAsync(todoList.TodoListId);

                        if (result.Succeeded)
                        {
                            TodoPageModel.TodoLists.Remove(todoList);
                        }
                    }
                    else
                    {
                        TodoList update = new TodoList()
                        {
                            TodoListId = todoList.TodoListId, Title = newTitle
                        };
                        result = await todoClient.UpdateTodoListAsync(update);

                        if (!result.Succeeded)
                        {
                            todoList.Title = todoList.OriginalTitle;
                        }
                    }
                }

                if (!result.Succeeded)
                {
                    await ErrorDialog.ShowErrorsAsync(result.Errors);
                }
            }
        }
예제 #7
0
        private async void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox      checkBox = (CheckBox)sender;
            TodoItemModel todo     = GetDataContext <TodoItemModel>(sender);
            TodoItem      todoItem = new TodoItem()
            {
                TodoItemId = todo.TodoItemId, TodoListId = todo.TodoListId, IsDone = checkBox.IsChecked.Value
            };
            HttpResult result;

            using (TodoClient todoClient = ClientFactory.CreateTodoClient())
            {
                result = await todoClient.UpdateTodoAsync(todoItem);
            }

            if (!result.Succeeded)
            {
                await ErrorDialog.ShowErrorsAsync(result.Errors);
            }
        }
예제 #8
0
        private async void DeleteAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            TodoListModel todoList = GetSelectedTodoList();

            HttpResult result;

            using (TodoClient todoClient = ClientFactory.CreateTodoClient())
            {
                result = await todoClient.DeleteTodoListAsync(todoList.TodoListId);
            }

            if (result.Succeeded)
            {
                TodoPageModel.TodoLists.Remove(todoList);
            }
            else
            {
                await ErrorDialog.ShowErrorsAsync(result.Errors);
            }
        }
예제 #9
0
        private async void AddAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            HttpResult <TodoList> result;

            using (TodoClient todoClient = ClientFactory.CreateTodoClient())
            {
                result = await todoClient.AddTodoListAsync(new TodoList()
                {
                    Title = "New Todo List"
                });
            }

            if (result.Succeeded)
            {
                TodoPageModel.TodoLists.Add(new TodoListModel(result.Content));
            }
            else
            {
                await ErrorDialog.ShowErrorsAsync(result.Errors);
            }
        }
예제 #10
0
        async Task GetTodoListsAsync()
        {
            TodoPageModel.TodoLists.Clear();
            HttpResult <TodoList[]> todoListResult;

            using (TodoClient todoClient = ClientFactory.CreateTodoClient())
            {
                todoListResult = await todoClient.GetTodoListsAsync();
            }

            if (todoListResult.Succeeded)
            {
                foreach (TodoList todoList in todoListResult.Content)
                {
                    TodoPageModel.TodoLists.Add(new TodoListModel(todoList));
                }
            }
            else
            {
                await ErrorDialog.ShowErrorsAsync(todoListResult.Errors);
            }
        }
예제 #11
0
        /// <summary>
        /// Populates the page with content passed during navigation. Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session. The state will be null the first time a page is visited.</param>
        private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            TodoPageModel.TodoLists.Clear();
            HttpResult <UserInfo> result;

            using (AccountClient accountClient = ClientFactory.CreateAccountClient())
            {
                result = await accountClient.GetUserInfoAsync();
            }

            if (result.Succeeded)
            {
                UserInfo userInfo = result.Content;
                this.pageTitle.Text = String.Format("{0}'s Todos", userInfo.UserName);

                await GetTodoListsAsync();
            }
            else
            {
                await ErrorDialog.ShowErrorsAsync(result.Errors);
            }
        }
예제 #12
0
        public async void AccountCommandsRequested(AccountsSettingsPane accountsSettingsPane, AccountsSettingsPaneCommandsRequestedEventArgs eventArgs)
        {
            AccountsSettingsPaneEventDeferral deferral = eventArgs.GetDeferral();

            HttpResult <ManageInfo> result;

            using (AccountClient accountClient = ClientFactory.CreateAccountClient())
            {
                result = await accountClient.GetManageInfoAsync();
            }

            if (!result.Succeeded)
            {
                await ErrorDialog.ShowErrorsAsync(result.Errors);

                // The log off command is not available on the account settings page if there are no accounts, so log off now
                LogOff();
                deferral.Complete();
                return;
            }

            ManageInfo manageInfo = result.Content;

            this.username      = manageInfo.UserName;
            this.localProvider = manageInfo.LocalLoginProvider;

            eventArgs.HeaderText = "Manage your account logins";

            ////Add WebAccountProviders
            Dictionary <string, WebAccountProvider> webProviders           = new Dictionary <string, WebAccountProvider>();
            WebAccountProviderCommandInvokedHandler providerCommandHandler = new WebAccountProviderCommandInvokedHandler(WebAccountProviderInvokedHandler);

            foreach (ExternalLogin externalLogin in manageInfo.ExternalLoginProviders)
            {
                WebAccountProvider        provider        = new WebAccountProvider(externalLogin.Url, externalLogin.Name, App.LoginIcons[externalLogin.Name]);
                WebAccountProviderCommand providerCommand = new WebAccountProviderCommand(provider, providerCommandHandler);
                eventArgs.WebAccountProviderCommands.Add(providerCommand);
                webProviders[provider.DisplayName] = provider;
            }

            WebAccountProvider localLoginProvider = new WebAccountProvider(manageInfo.LocalLoginProvider, manageInfo.LocalLoginProvider, null);

            webProviders[manageInfo.LocalLoginProvider] = localLoginProvider;

            ////Add WebAccounts and local accounts if available.
            bool hasLocalLogin = false;

            foreach (UserLoginInfo userLoginInfo in manageInfo.Logins)
            {
                WebAccountCommandInvokedHandler accountCommandHandler;
                SupportedWebAccountActions      supportedActions = SupportedWebAccountActions.None;
                if (manageInfo.Logins.Length > 1)
                {
                    supportedActions |= SupportedWebAccountActions.Remove;
                }
                if (userLoginInfo.LoginProvider == manageInfo.LocalLoginProvider)
                {
                    hasLocalLogin         = true;
                    supportedActions     |= SupportedWebAccountActions.Manage;
                    accountCommandHandler = new WebAccountCommandInvokedHandler(LocalWebAccountInvokedHandler);
                }
                else
                {
                    accountCommandHandler = new WebAccountCommandInvokedHandler(WebAccountInvokedHandler);
                }
                WebAccount webAccount = new WebAccount(webProviders[userLoginInfo.LoginProvider], userLoginInfo.ProviderKey, WebAccountState.Connected);

                WebAccountCommand webAccountCommand = new WebAccountCommand(webAccount, accountCommandHandler, supportedActions);
                eventArgs.WebAccountCommands.Add(webAccountCommand);
            }

            if (!hasLocalLogin)
            {
                WebAccountProviderCommandInvokedHandler localProviderCmdHandler = new WebAccountProviderCommandInvokedHandler(LocalProviderInvokedHandler);
                WebAccountProviderCommand localProviderCommand = new WebAccountProviderCommand(localLoginProvider, localProviderCmdHandler);
                eventArgs.WebAccountProviderCommands.Add(localProviderCommand);
            }

            SettingsCommand logOffCommand = new SettingsCommand("Logoff", "Log off", new UICommandInvokedHandler(LogOffHandler));

            eventArgs.Commands.Add(logOffCommand);

            deferral.Complete();
        }