Esempio n. 1
0
        public static IssueManager Instance(string username, SecureString password)
        {
            instance = new IssueManager();
            instance.SetContextUser(username, password);

            return instance;
        }
        private void LoadRepositories_Click(object sender, RoutedEventArgs e)
        {
            this.InvalidCredentials.Visibility = Visibility.Hidden;
            this.GitHubRepositoryList.ItemsSource = null;

            if (!(string.IsNullOrWhiteSpace(this.GitHubUsername.Text) || this.GitHubPassword.SecurePassword.Length == 0))
            {
                manager = IssueManager.Instance(this.GitHubUsername.Text, this.GitHubPassword.SecurePassword);
                List<Tuple<string, string>> list = null;
                bool isAuthenticationCorrect = true;

                Task task = Task.Factory.StartNew(() =>
                {
                    Action action = () => list = manager.GetRepositories();
                    isAuthenticationCorrect = AreCredentialsCorrectForAction(action);

                });
                task.ContinueWith(next =>
                {
                    // Update the main Thread as it is the owner of the UI elements
                    this.Dispatcher.Invoke((Action)(() =>
                        {
                            if (isAuthenticationCorrect)
                            {
                                this.GitHubRepositoryList.SelectedIndex = 0;
                                this.GitHubRepositoryList.ItemsSource = list;
                                this.CreateIssue.IsEnabled = true;
                            }
                            else
                            {
                                this.InvalidCredentials.Visibility = Visibility.Visible;
                                this.CreateIssue.IsEnabled = false;
                            }
                        }));
                });
            }
        }