Exemplo n.º 1
0
        private void ProjectNameBox_TextChanged(object sender, EventArgs e)
        {
            var projectName = _projectNameBox.Text;
            var project     = GoogleCodeProject.IsValidProjectName(projectName)
                        ? new GoogleCodeProject(projectName)
                        : null;

            _okButton.Enabled = _testButton.Enabled = project != null;
            _linkLabel.Text   = (project != null ? project.Url : GoogleCodeProject.HostingUrl).ToString();
        }
Exemplo n.º 2
0
 private void TestButton_Click(object sender, EventArgs e)
 {
     try
     {
         var projectName = _projectNameBox.Text;
         var url         = new GoogleCodeProject(projectName).DnsUrl();
         using (CurrentCursorScope.EnterWait())
             new WebClient().DownloadData(url);
         var message = string.Format("The Google Code project '{0}' appears valid and reachable at {1}.", projectName, url);
         MessageBox.Show(message, "Test Passed", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (WebException we)
     {
         MessageBox.Show(we.Message, "Test Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 3
0
        private static Func <IWin32Window, DialogResult> OnVersionDataDownloaded(string data)
        {
            Debug.Assert(data != null);

            var separators = new[] { ':', '=' };

            var headers = (
                from line in new StringReader(data).ReadLines()
                where line.Length > 0 && line[0] != '#'
                let parts = line.Split(separators, 2)
                            where parts.Length == 2
                            let key = parts[0].Trim()
                                      let value = parts[1].Trim()
                                                  where key.Length > 0 && value.Length > 0
                                                  let pair = new KeyValuePair <string, string>(key, value)
                                                             group pair by pair.Key into g
                                                             select g
                )
                          .ToDictionary(g => g.Key, p => p.Last().Value, StringComparer.OrdinalIgnoreCase);

            Version version;

            try
            {
                version = new Version(headers.Find("version"));

                //
                // Zero out build and revision if not supplied in the string
                // format, e.g. 2.0 -> 2.0.0.0.
                //

                version = new Version(version.Major, version.Minor,
                                      Math.Max(version.Build, 0), Math.Max(0, version.Revision));
            }
            catch (ArgumentException) { return(null); }
            catch (FormatException) { return(null); }
            catch (OverflowException) { return(null); }

            var href = headers.Find("href").MaskNull();

            if (href.Length == 0 || !Uri.IsWellFormedUriString(href, UriKind.Absolute))
            {
                href = new GoogleCodeProject("gurtle").DownloadsListUrl().ToString();
            }

            var thisVersion = typeof(Plugin).Assembly.GetName().Version;

            if (version <= thisVersion)
            {
                return(null);
            }

            return(owner =>
            {
                var message = new StringBuilder()
                              .AppendLine("There is a new version of Gurtle available. Would you like to update now?")
                              .AppendLine()
                              .Append("Your version: ").Append(thisVersion).AppendLine()
                              .Append("New version: ").Append(version).AppendLine()
                              .ToString();

                var reply = MessageBox.Show(owner, message,
                                            "Update Notice", MessageBoxButtons.YesNoCancel,
                                            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

                if (reply == DialogResult.Yes)
                {
                    Process.Start(href);
                }

                return reply;
            });
        }
Exemplo n.º 4
0
        public string GetCommitMessage(
            IWin32Window parentWindow,
            Parameters parameters, string originalMessage)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            try
            {
                var project = parameters.Project;
                if (project.Length == 0)
                {
                    throw new ApplicationException("Missing Google Code project specification.");
                }

                IList <Issue> issues;

                using (var dialog = new IssueBrowserDialog
                {
                    ProjectName = project,
                    UserNamePattern = parameters.User,
                    StatusPattern = parameters.Status,
                    UpdateCheckEnabled = true,
                })
                {
                    var settings = Properties.Settings.Default;
                    new WindowSettings(settings, dialog);

                    var reply = dialog.ShowDialog(parentWindow);
                    issues = dialog.SelectedIssueObjects;

                    settings.Save();

                    if (reply != DialogResult.OK || issues.Count == 0)
                    {
                        return(originalMessage);
                    }

                    _issues  = issues;
                    _project = dialog.Project;
                }

                var message = new StringBuilder(originalMessage);

                if (originalMessage.Length > 0 && !originalMessage.EndsWith("\n"))
                {
                    message.AppendLine();
                }

                foreach (var issue in issues)
                {
                    message
                    .Append("(")
                    .Append(GetIssueTypeAddress(issue.Type)).Append(" issue #")
                    .Append(issue.Id).Append(") : ")
                    .AppendLine(issue.Summary);
                }

                return(message.ToString());
            }
            catch (Exception e)
            {
                ShowErrorBox(parentWindow, e);
                throw;
            }
        }
Exemplo n.º 5
0
        private static void OnCommitFinished(IWin32Window parentWindow, int revision, GoogleCodeProject project, ICollection <Issue> issues)
        {
            if (project == null)
            {
                return;
            }

            if (issues == null || issues.Count == 0)
            {
                return;
            }

            // don't bother users with the issue update dialog if the
            // env variable is not set.
            if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GURTLE_ISSUE_UPDATE_CMD")))
            {
                return;
            }

            var settings = Properties.Settings.Default;

            var updates = issues.Select(e => new IssueUpdate(e)
            {
                Status  = project.ClosedStatuses.FirstOrDefault(),
                Comment = string.Format("{0} in r{1}.", GetIssueTypeAddress(e.Type), revision)
            })
                          .ToList();

            while (updates.Count > 0)
            {
                using (var dialog = new IssueUpdateDialog
                {
                    Project = project,
                    Issues = updates,
                    Revision = revision
                })
                {
                    new WindowSettings(settings, dialog);
                    if (DialogResult.OK != dialog.ShowDialog(parentWindow))
                    {
                        return;
                    }
                }

                if (updates.Count == 0)
                {
                    break;
                }

                var credential = CredentialPrompt.Prompt(parentWindow, "Google Code", project.Name + ".gccred");
                if (credential == null)
                {
                    continue;
                }

                credential = new NetworkCredential(credential.UserName,
                                                   Convert.ToBase64String(Encoding.UTF8.GetBytes(credential.Password)));

                using (var form = new WorkProgressForm
                {
                    Text = "Updating Issues",
                    StartWorkOnShow = true,
                })
                {
                    var worker = form.Worker;
                    worker.DoWork += (sender, args) =>
                    {
                        var startCount = updates.Count;
                        while (updates.Count > 0)
                        {
                            if (worker.CancellationPending)
                            {
                                args.Cancel = true;
                                break;
                            }

                            var issue = updates[0];

                            form.ReportProgress(string.Format(
                                                    @"Updating issue #{0}: {1}",
                                                    issue.Issue.Id,
                                                    issue.Issue.Summary));

                            UpdateIssue(project.Name, issue, credential, form.ReportDetailLine);
                            updates.RemoveAt(0);

                            form.ReportProgress((int)((startCount - updates.Count) * 100.0 / startCount));
                        }
                    };

                    form.WorkFailed += delegate
                    {
                        var error = form.Error;
                        foreach (var line in new StringReader(error.ToString()).ReadLines())
                        {
                            form.ReportDetailLine(line);
                        }
                        ShowErrorBox(form, error);
                    };

                    if (parentWindow == null)
                    {
                        form.StartPosition = FormStartPosition.CenterScreen;
                    }
                    form.ShowDialog(parentWindow);
                }
            }

            settings.Save();
        }
Exemplo n.º 6
0
        public string GetCommitMessage(
            IWin32Window parentWindow,
            Parameters parameters, string originalMessage)
        {
            if (parameters == null) throw new ArgumentNullException("parameters");

            try
            {
                var project = parameters.Project;
                if (project.Length == 0)
                    throw new ApplicationException("Missing Google Code project specification.");

                IList<Issue> issues;

                using (var dialog = new IssueBrowserDialog
                {
                    ProjectName = project,
                    UserNamePattern = parameters.User,
                    StatusPattern = parameters.Status,
                    UpdateCheckEnabled = true,
                })
                {
                    var settings = Properties.Settings.Default;
                    new WindowSettings(settings, dialog);

                    var reply = dialog.ShowDialog(parentWindow);
                    issues = dialog.SelectedIssueObjects;

                    settings.Save();

                    if (reply != DialogResult.OK || issues.Count == 0)
                        return originalMessage;

                    _issues = issues;
                    _project = dialog.Project;
                }

                var message = new StringBuilder(originalMessage);

                if (originalMessage.Length > 0 && !originalMessage.EndsWith("\n"))
                    message.AppendLine();

                foreach (var issue in issues)
                {
                    message
                        .Append("(")
                        .Append(GetIssueTypeAddress(issue.Type)).Append(" issue #")
                        .Append(issue.Id).Append(") : ")
                        .AppendLine(issue.Summary);
                }

                return message.ToString();
            }
            catch (Exception e)
            {
                ShowErrorBox(parentWindow, e);
                throw;
            }
        }
Exemplo n.º 7
0
        private static void OnCommitFinished(IWin32Window parentWindow, int revision, GoogleCodeProject project, ICollection<Issue> issues)
        {
            if (project == null)
                return;

            if (issues == null || issues.Count == 0)
                return;

            // don't bother users with the issue update dialog if the
            // env variable is not set.
            if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GURTLE_ISSUE_UPDATE_CMD")))
                return;

            var settings = Properties.Settings.Default;

            var updates = issues.Select(e => new IssueUpdate(e)
            {
                Status = project.ClosedStatuses.FirstOrDefault(),
                Comment = string.Format("{0} in r{1}.", GetIssueTypeAddress(e.Type), revision)
            })
            .ToList();

            while (updates.Count > 0)
            {
                using (var dialog = new IssueUpdateDialog
                {
                    Project = project,
                    Issues = updates,
                    Revision = revision
                })
                {
                    new WindowSettings(settings, dialog);
                    if (DialogResult.OK != dialog.ShowDialog(parentWindow))
                        return;
                }

                if (updates.Count == 0)
                    break;

                var credential = CredentialPrompt.Prompt(parentWindow, "Google Code", project.Name + ".gccred");
                if (credential == null)
                    continue;

                credential = new NetworkCredential(credential.UserName,
                    Convert.ToBase64String(Encoding.UTF8.GetBytes(credential.Password)));

                using (var form = new WorkProgressForm
                {
                    Text = "Updating Issues",
                    StartWorkOnShow = true,
                })
                {
                    var worker = form.Worker;
                    worker.DoWork += (sender, args) =>
                    {
                        var startCount = updates.Count;
                        while (updates.Count > 0)
                        {
                            if (worker.CancellationPending)
                            {
                                args.Cancel = true;
                                break;
                            }

                            var issue = updates[0];

                            form.ReportProgress(string.Format(
                                @"Updating issue #{0}: {1}",
                                issue.Issue.Id,
                                issue.Issue.Summary));

                            UpdateIssue(project.Name, issue, credential, form.ReportDetailLine);
                            updates.RemoveAt(0);

                            form.ReportProgress((int)((startCount - updates.Count) * 100.0 / startCount));
                        }
                    };

                    form.WorkFailed += delegate
                    {
                        var error = form.Error;
                        foreach (var line in new StringReader(error.ToString()).ReadLines())
                            form.ReportDetailLine(line);
                        ShowErrorBox(form, error);
                    };

                    if (parentWindow == null)
                        form.StartPosition = FormStartPosition.CenterScreen;
                    form.ShowDialog(parentWindow);
                }
            }

            settings.Save();
        }
Exemplo n.º 8
0
 private void TestButton_Click(object sender, EventArgs e)
 {
     try
     {
         var projectName = _projectNameBox.Text;
         var url = new GoogleCodeProject(projectName).DnsUrl();
         using (CurrentCursorScope.EnterWait())
             new WebClient().DownloadData(url);
         var message = string.Format("The Google Code project '{0}' appears valid and reachable at {1}.", projectName, url);
         MessageBox.Show(message, "Test Passed", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (WebException we)
     {
         MessageBox.Show(we.Message, "Test Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }