private void PromptAndRun(object sender, Diagnostics.Diagnostic diag) { var p = sender as PictureBox; if (p?.Tag == null && diag.Resolution.Resolver != null && MessageBox.Show(this, $"Execute the following patch?\n\n{diag.Resolution.Name}", "Apply Fix", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { diag.Resolution.Resolver?.Invoke(null); if (!diag.Troubleshooter(null)) { if (p != null) { p.Image = Properties.Resources.Fixed; p.Tag = 0; var t = p.Parent as TableLayoutPanel; if (t != null) { var l = t.GetControlFromPosition(1, 1) as Label; if (l != null) { l.Text = "Fixed"; } } } } } }
private Control MakeReportItem(Diagnostics.Diagnostic diag) { var c = MakeStatusItem(diag, false) as TableLayoutPanel; c.RowCount = 2; c.RowStyles.Add(new RowStyle(SizeType.AutoSize)); c.Controls.Add(MakeLabel(diag.Resolution.Name, diag.Resolution.Description, true), 0, 1); string resText; bool canRun = false; if (diag.Resolved.HasValue) { resText = diag.Resolved.Value ? "Completed" : "Issue not present"; } else { resText = diag.Resolution.RequiresConsent ? "Requires consent" : "Not run"; if (diag.Resolution.RequiresConsent && (!diag.Resolution.RequiresElevation || isElevated)) { canRun = true; } } c.Controls.Add(MakeLabel(resText, null, false, false, true), 1, 1); if (canRun) { c.Controls.Add(MakeIcon(Properties.Resources.Run, "Click here to run the repair", diag), 2, 1); } return(c); }
private Control MakeStatusItem(Diagnostics.Diagnostic diag, bool indented = true) { var status = ItemStatus.Detected; if (diag.HasIssue.HasValue && !diag.HasIssue.Value) { status = ItemStatus.Checked; } else { if (diag.Resolved.HasValue) { if (diag.Resolved.Value) { status = ItemStatus.Fixed; } } else { if (diag.Resolution.RequiresConsent || diag.Resolution.RequiresElevation) { status = ItemStatus.NotFixed; } else { status = ItemStatus.None; } } } return(MakeStatusItem(diag.Name, diag.Description, status, indented)); }
private PictureBox MakeIcon(Image image, string tooltip = null, Diagnostics.Diagnostic diag = null) { var p = new PictureBox { Anchor = AnchorStyles.Right, Image = image, Margin = new Padding(4, 2, 10, 2), Size = new Size(16, 16), TabStop = false, }; if (tooltip != null) { toolTip1.SetToolTip(p, tooltip); } if (diag?.Resolution.Resolver != null) { p.Click += (s, e) => PromptAndRun(s, diag); } return(p); }