Example #1
0
        private async void TxtRepository_Enter(object sender, EventArgs e)
        {
            String owner = TxtOwner.Text;

            if (owner.Length == 0)
            {
                return;
            }

            try
            {
                var tracker = IssueTrackerFactory.CreateIssueTracker(Params);
                if (tracker != null)
                {
                    var repos = await tracker.GetAllRepositories();

                    var repo_list = new AutoCompleteStringCollection();
                    repo_list.AddRange(repos.ToArray());

                    TxtRepository.AutoCompleteCustomSource = repo_list;
                }
            }
            catch
            {
                // Let this silently fail, the user just won't have an autocomplete list
                // This could be due to no network connection, invalid username, etc
            }
        }
Example #2
0
        public bool ValidateParameters(IntPtr hParentWnd, string parameters)
        {
            Logger.LogMessageWithData("ValidateParameters: " + parameters);
            Parameters        parms;
            RepositoryMetrics metrics = null;

            try
            {
                parms = new Parameters(parameters);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "TurtleHub", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (parms.Owner.Length == 0 || parms.Repository.Length == 0)
            {
                MessageBox.Show("Invalid parameters.", "TurtleHub", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            try
            {
                var tracker = IssueTrackerFactory.CreateIssueTracker(parms);
                var task    = tracker.GetRepositoryMetrics();
                if (task != null)
                {
                    task.Wait();
                    metrics = task.Result;
                }
            }
            catch (AggregateException aex)
            {
                // NOTE: since we are waiting on the task, an AggregateException is thrown instead of just an ApiExcpetion
                foreach (Exception ex in aex.InnerExceptions)
                {
                    if (ex is Octokit.NotFoundException)
                    {
                        if (((Octokit.NotFoundException)ex).HttpResponse.StatusCode == HttpStatusCode.NotFound)
                        {
                            var res = MessageBox.Show("This repository cannot be found on the server. Continue anyways?", "TurtleHub", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                            return(res == DialogResult.Yes);
                        }
                    }
                }

                // Some other exception happend. Silently fail, not a big deal
                return(true);
            }

            if (metrics != null)
            {
                // Do a bit more to validate it
                if (!metrics.HasIssues)
                {
                    var res = MessageBox.Show("This repository doesn't allow issues to be created. Continue anyways?", "TurtleHub", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (res == DialogResult.No)
                    {
                        return(false);
                    }
                }
                else if (metrics.OpenIssues == 0)
                {
                    var res = MessageBox.Show("This repository doesn't have any open issues. Continue anyways?", "TurtleHub", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (res == DialogResult.No)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }