private void RunCodeLinkReport_Click(object sender, EventArgs e) { Enabled = false; Cursor = Cursors.WaitCursor; rtb_Output.Clear(); var report = new CodeLinkReport(rtb_Output, dlg_ChooseRepoRoot, dlg_SaveOutput) { DocPath = tb_DocRepoRoot.Text, }; if (dateTimePicker.Checked) { report.FreshnessDate = dateTimePicker.Value; } var(codeInfo, codeRoot) = SelectCodeRepo(report); if (codeRoot != null) { report.SetCodeTarget(codeInfo, codeRoot); report.Run(); } rtb_Output.ScrollToCaret(); Cursor = DefaultCursor; Enabled = true; }
private (RepositoryInfo, string) SelectCodeRepo(CodeLinkReport report) { var depRepos = report.GetPotentialTargets(); RepositoryInfo codeInfo = null; string codeRoot = null; DialogResult result; switch (depRepos.Count) { case 0: // No linked code repos! break; case 1: // Just one linked [potential] code repo. codeInfo = depRepos[0]; if (!string.IsNullOrWhiteSpace(LastCodeRepoRoot)) { // Is this the right directory? if (MessageBox.Show( $"{LastCodeRepoRoot}, is this the correct code directory?", "Verify directory", MessageBoxButtons.YesNo) == DialogResult.Yes) { codeRoot = LastCodeRepoRoot; break; } } dlg_ChooseRepoRoot.Description = $"Select the local root for the {codeInfo.Branch} " + $"branch of the '{codeInfo.PathToRoot}' repo."; result = dlg_ChooseRepoRoot.ShowDialog(); if (result != DialogResult.OK) { // Abort. break; } codeRoot = dlg_ChooseRepoRoot.SelectedPath; break; default: // More than one to choose from. // TODO // - rework this as a loop where each is resolved or ignored. // - will require rewiring the report logic to work against multiple repos. dlg_ItemPicker.SetItems(depRepos); result = dlg_ItemPicker.ShowDialog(); if (result != DialogResult.OK) { break; } codeInfo = depRepos[dlg_ItemPicker.SelectedIndex]; dlg_ChooseRepoRoot.Description = $"Select the local root for the {codeInfo.Branch} " + $"branch of the '{codeInfo.PathToRoot}' repo."; result = dlg_ChooseRepoRoot.ShowDialog(); if (result != DialogResult.OK) { break; } codeRoot = dlg_ChooseRepoRoot.SelectedPath; LastCodeRepoRoot = codeRoot; tb_CodeRepoRoot.Text = codeRoot; Properties.Settings.Default.LastCodeRepoRoot = codeRoot; Properties.Settings.Default.Save(); break; } return(codeInfo, codeRoot); }