From de4e3e3f5ffc2946522333784cff875c16bddca5 Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Fri, 19 Jan 2018 19:04:11 +0100 Subject: [PATCH] Reporter improvement + Show it when the last run crashed, an event with show = true took place and when the user presses F8. --- Vocaluxe/Base/CGraphics.cs | 5 + Vocaluxe/Reporting/Reporter.Designer.cs | 243 +++++++++++++----------- Vocaluxe/Reporting/Reporter.cs | 120 +++++++----- VocaluxeLib/Log/CLog.cs | 31 ++- VocaluxeLib/Log/CLogFunctions.cs | 48 ++--- VocaluxeLib/Log/CLogFunctions.tt | 8 +- VocaluxeLib/Log/ShowReporterDelegate.cs | 10 +- 7 files changed, 280 insertions(+), 185 deletions(-) diff --git a/Vocaluxe/Base/CGraphics.cs b/Vocaluxe/Base/CGraphics.cs index 8f8e22fd..5d5be4da 100644 --- a/Vocaluxe/Base/CGraphics.cs +++ b/Vocaluxe/Base/CGraphics.cs @@ -443,6 +443,11 @@ namespace Vocaluxe.Base HidePopup(EPopupScreens.PopupServerQR); } + if (keyEvent.Key == Keys.F8) + { + CLog.ShowLogAssistent("", null); + } + if (popupPlayerControlAllowed && keyEvent.Key == Keys.Tab) { if (_CurrentPopupScreen == EPopupScreens.NoPopup && CConfig.Config.Sound.BackgroundMusic == EBackgroundMusicOffOn.TR_CONFIG_ON) diff --git a/Vocaluxe/Reporting/Reporter.Designer.cs b/Vocaluxe/Reporting/Reporter.Designer.cs index cbdee73e..59fc5577 100644 --- a/Vocaluxe/Reporting/Reporter.Designer.cs +++ b/Vocaluxe/Reporting/Reporter.Designer.cs @@ -29,107 +29,111 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CReporter)); - this.Title = new System.Windows.Forms.Label(); - this.Message = new System.Windows.Forms.TextBox(); - this.Log = new System.Windows.Forms.TextBox(); - this.GistOnly = new System.Windows.Forms.RadioButton(); - this.GistAndIssue = new System.Windows.Forms.RadioButton(); - this.NoUpload = new System.Windows.Forms.RadioButton(); - this.Submit = new System.Windows.Forms.Button(); + this.TitleLabel = new System.Windows.Forms.Label(); + this.MessageText = new System.Windows.Forms.TextBox(); + this.LogBox = new System.Windows.Forms.TextBox(); + this.GistOnlySelect = new System.Windows.Forms.RadioButton(); + this.GistAndIssueSelect = new System.Windows.Forms.RadioButton(); + this.NoUploadSelect = new System.Windows.Forms.RadioButton(); + this.SubmitButton = new System.Windows.Forms.Button(); this.Url = new System.Windows.Forms.TextBox(); - this.SubmitedMessage = new System.Windows.Forms.Label(); + this.SubmitedTitleLabel = new System.Windows.Forms.Label(); + this.LastErrorTitleLabel = new System.Windows.Forms.Label(); + this.LastErrorBox = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // - // Title + // TitleLabel // - this.Title.AutoSize = true; - this.Title.Enabled = false; - this.Title.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.Title.Location = new System.Drawing.Point(9, 8); - this.Title.Name = "Title"; - this.Title.Size = new System.Drawing.Size(110, 20); - this.Title.TabIndex = 0; - this.Title.Text = "We are sorry"; + this.TitleLabel.AutoSize = true; + this.TitleLabel.Enabled = false; + this.TitleLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.TitleLabel.Location = new System.Drawing.Point(9, 8); + this.TitleLabel.Name = "TitleLabel"; + this.TitleLabel.Size = new System.Drawing.Size(110, 20); + this.TitleLabel.TabIndex = 0; + this.TitleLabel.Text = "We are sorry"; // - // Message + // MessageText // - this.Message.BorderStyle = System.Windows.Forms.BorderStyle.None; - this.Message.Enabled = false; - this.Message.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.Message.Location = new System.Drawing.Point(13, 31); - this.Message.Multiline = true; - this.Message.Name = "Message"; - this.Message.ReadOnly = true; - this.Message.Size = new System.Drawing.Size(625, 63); - this.Message.TabIndex = 0; - this.Message.TabStop = false; - this.Message.Text = "that Vocaluxe run into an error and crashed.\r\nTo help us fix the problem please s" + + this.MessageText.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.MessageText.Enabled = false; + this.MessageText.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.MessageText.Location = new System.Drawing.Point(13, 31); + this.MessageText.Multiline = true; + this.MessageText.Name = "MessageText"; + this.MessageText.ReadOnly = true; + this.MessageText.Size = new System.Drawing.Size(625, 63); + this.MessageText.TabIndex = 0; + this.MessageText.TabStop = false; + this.MessageText.Text = "that Vocaluxe run into an error and crashed.\r\nTo help us fix the problem please s" + "end us a report.\r\nEdit the following log before submitting to remove possibly se" + "nsitive information."; // - // Log + // LogBox // - this.Log.AcceptsReturn = true; - this.Log.AcceptsTab = true; - this.Log.Location = new System.Drawing.Point(13, 100); - this.Log.Multiline = true; - this.Log.Name = "Log"; - this.Log.Size = new System.Drawing.Size(625, 189); - this.Log.TabIndex = 1; + this.LogBox.AcceptsReturn = true; + this.LogBox.AcceptsTab = true; + this.LogBox.Location = new System.Drawing.Point(13, 182); + this.LogBox.Multiline = true; + this.LogBox.Name = "LogBox"; + this.LogBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.LogBox.Size = new System.Drawing.Size(625, 189); + this.LogBox.TabIndex = 1; + this.LogBox.WordWrap = false; // - // GistOnly + // GistOnlySelect // - this.GistOnly.AutoSize = true; - this.GistOnly.Checked = true; - this.GistOnly.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.GistOnly.Location = new System.Drawing.Point(12, 295); - this.GistOnly.Name = "GistOnly"; - this.GistOnly.Size = new System.Drawing.Size(385, 24); - this.GistOnly.TabIndex = 2; - this.GistOnly.TabStop = true; - this.GistOnly.Text = "Upload and get a link to your report (publicly visible)"; - this.GistOnly.UseVisualStyleBackColor = true; + this.GistOnlySelect.AutoSize = true; + this.GistOnlySelect.Checked = true; + this.GistOnlySelect.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.GistOnlySelect.Location = new System.Drawing.Point(12, 377); + this.GistOnlySelect.Name = "GistOnlySelect"; + this.GistOnlySelect.Size = new System.Drawing.Size(385, 24); + this.GistOnlySelect.TabIndex = 2; + this.GistOnlySelect.TabStop = true; + this.GistOnlySelect.Text = "Upload and get a link to your report (publicly visible)"; + this.GistOnlySelect.UseVisualStyleBackColor = true; // - // GistAndIssue + // GistAndIssueSelect // - this.GistAndIssue.AutoSize = true; - this.GistAndIssue.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.GistAndIssue.Location = new System.Drawing.Point(12, 325); - this.GistAndIssue.Name = "GistAndIssue"; - this.GistAndIssue.Size = new System.Drawing.Size(519, 24); - this.GistAndIssue.TabIndex = 3; - this.GistAndIssue.TabStop = true; - this.GistAndIssue.Text = "Upload and open an issue (publicly visible + requires a github account)"; - this.GistAndIssue.UseVisualStyleBackColor = true; + this.GistAndIssueSelect.AutoSize = true; + this.GistAndIssueSelect.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.GistAndIssueSelect.Location = new System.Drawing.Point(12, 407); + this.GistAndIssueSelect.Name = "GistAndIssueSelect"; + this.GistAndIssueSelect.Size = new System.Drawing.Size(519, 24); + this.GistAndIssueSelect.TabIndex = 3; + this.GistAndIssueSelect.TabStop = true; + this.GistAndIssueSelect.Text = "Upload and open an issue (publicly visible + requires a github account)"; + this.GistAndIssueSelect.UseVisualStyleBackColor = true; // - // NoUpload + // NoUploadSelect // - this.NoUpload.AutoSize = true; - this.NoUpload.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.NoUpload.Location = new System.Drawing.Point(12, 355); - this.NoUpload.Name = "NoUpload"; - this.NoUpload.Size = new System.Drawing.Size(493, 24); - this.NoUpload.TabIndex = 4; - this.NoUpload.TabStop = true; - this.NoUpload.Text = "Don\'t upload anything (you can still copy the error message above)"; - this.NoUpload.UseVisualStyleBackColor = true; - this.NoUpload.CheckedChanged += new System.EventHandler(this.NoUpload_CheckedChanged); + this.NoUploadSelect.AutoSize = true; + this.NoUploadSelect.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.NoUploadSelect.Location = new System.Drawing.Point(12, 437); + this.NoUploadSelect.Name = "NoUploadSelect"; + this.NoUploadSelect.Size = new System.Drawing.Size(493, 24); + this.NoUploadSelect.TabIndex = 4; + this.NoUploadSelect.TabStop = true; + this.NoUploadSelect.Text = "Don\'t upload anything (you can still copy the error message above)"; + this.NoUploadSelect.UseVisualStyleBackColor = true; + this.NoUploadSelect.CheckedChanged += new System.EventHandler(this.NoUpload_CheckedChanged); // - // Submit + // SubmitButton // - this.Submit.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.Submit.Location = new System.Drawing.Point(537, 306); - this.Submit.Name = "Submit"; - this.Submit.Size = new System.Drawing.Size(101, 73); - this.Submit.TabIndex = 5; - this.Submit.Text = "Submit"; - this.Submit.UseVisualStyleBackColor = true; - this.Submit.Click += new System.EventHandler(this.Submit_Click); + this.SubmitButton.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.SubmitButton.Location = new System.Drawing.Point(537, 388); + this.SubmitButton.Name = "SubmitButton"; + this.SubmitButton.Size = new System.Drawing.Size(101, 73); + this.SubmitButton.TabIndex = 5; + this.SubmitButton.Text = "Submit"; + this.SubmitButton.UseVisualStyleBackColor = true; + this.SubmitButton.Click += new System.EventHandler(this.Submit_Click); // // Url // this.Url.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.Url.Location = new System.Drawing.Point(12, 327); + this.Url.Location = new System.Drawing.Point(12, 409); this.Url.Name = "Url"; this.Url.ReadOnly = true; this.Url.Size = new System.Drawing.Size(519, 22); @@ -137,32 +141,57 @@ this.Url.Text = "https://gist.github.com/lukeIam/cc81f7ef3545ef2baf0ca9a28ffe4bd8"; this.Url.Visible = false; // - // SubmitedMessage + // SubmitedTitleLabel // - this.SubmitedMessage.AutoSize = true; - this.SubmitedMessage.Enabled = false; - this.SubmitedMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.SubmitedMessage.Location = new System.Drawing.Point(9, 299); - this.SubmitedMessage.Name = "SubmitedMessage"; - this.SubmitedMessage.Size = new System.Drawing.Size(189, 20); - this.SubmitedMessage.TabIndex = 8; - this.SubmitedMessage.Text = "The link to your report:"; - this.SubmitedMessage.Visible = false; + this.SubmitedTitleLabel.AutoSize = true; + this.SubmitedTitleLabel.Enabled = false; + this.SubmitedTitleLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.SubmitedTitleLabel.Location = new System.Drawing.Point(9, 381); + this.SubmitedTitleLabel.Name = "SubmitedTitleLabel"; + this.SubmitedTitleLabel.Size = new System.Drawing.Size(189, 20); + this.SubmitedTitleLabel.TabIndex = 8; + this.SubmitedTitleLabel.Text = "The link to your report:"; + this.SubmitedTitleLabel.Visible = false; + // + // LastErrorTitleLabel + // + this.LastErrorTitleLabel.AutoSize = true; + this.LastErrorTitleLabel.Enabled = false; + this.LastErrorTitleLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.LastErrorTitleLabel.Location = new System.Drawing.Point(9, 97); + this.LastErrorTitleLabel.Name = "LastErrorTitleLabel"; + this.LastErrorTitleLabel.Size = new System.Drawing.Size(87, 20); + this.LastErrorTitleLabel.TabIndex = 9; + this.LastErrorTitleLabel.Text = "Last error"; + // + // LastErrorBox + // + this.LastErrorBox.AcceptsReturn = true; + this.LastErrorBox.AcceptsTab = true; + this.LastErrorBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.LastErrorBox.Location = new System.Drawing.Point(12, 120); + this.LastErrorBox.Multiline = true; + this.LastErrorBox.Name = "LastErrorBox"; + this.LastErrorBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.LastErrorBox.Size = new System.Drawing.Size(626, 38); + this.LastErrorBox.TabIndex = 10; // // CReporter // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(650, 387); - this.Controls.Add(this.SubmitedMessage); + this.ClientSize = new System.Drawing.Size(650, 467); + this.Controls.Add(this.LastErrorBox); + this.Controls.Add(this.LastErrorTitleLabel); + this.Controls.Add(this.SubmitedTitleLabel); this.Controls.Add(this.Url); - this.Controls.Add(this.Submit); - this.Controls.Add(this.NoUpload); - this.Controls.Add(this.GistAndIssue); - this.Controls.Add(this.GistOnly); - this.Controls.Add(this.Log); - this.Controls.Add(this.Message); - this.Controls.Add(this.Title); + this.Controls.Add(this.SubmitButton); + this.Controls.Add(this.NoUploadSelect); + this.Controls.Add(this.GistAndIssueSelect); + this.Controls.Add(this.GistOnlySelect); + this.Controls.Add(this.LogBox); + this.Controls.Add(this.MessageText); + this.Controls.Add(this.TitleLabel); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "CReporter"; this.Text = "Vocaluxe Issue Reporter"; @@ -173,14 +202,16 @@ #endregion - private System.Windows.Forms.Label Title; - private System.Windows.Forms.TextBox Message; - private System.Windows.Forms.TextBox Log; - private System.Windows.Forms.RadioButton GistOnly; - private System.Windows.Forms.RadioButton GistAndIssue; - private System.Windows.Forms.RadioButton NoUpload; - private System.Windows.Forms.Button Submit; + private System.Windows.Forms.Label TitleLabel; + private System.Windows.Forms.TextBox MessageText; + private System.Windows.Forms.TextBox LogBox; + private System.Windows.Forms.RadioButton GistOnlySelect; + private System.Windows.Forms.RadioButton GistAndIssueSelect; + private System.Windows.Forms.RadioButton NoUploadSelect; + private System.Windows.Forms.Button SubmitButton; private System.Windows.Forms.TextBox Url; - private System.Windows.Forms.Label SubmitedMessage; + private System.Windows.Forms.Label SubmitedTitleLabel; + private System.Windows.Forms.Label LastErrorTitleLabel; + private System.Windows.Forms.TextBox LastErrorBox; } } \ No newline at end of file diff --git a/Vocaluxe/Reporting/Reporter.cs b/Vocaluxe/Reporting/Reporter.cs index 0c813bec..e5e74105 100644 --- a/Vocaluxe/Reporting/Reporter.cs +++ b/Vocaluxe/Reporting/Reporter.cs @@ -20,10 +20,12 @@ namespace Vocaluxe.Reporting private string _GistOnlyText = "Upload and get a link to your report (publicly visible)"; private string _SubmitStep0Text = "Submit"; private string _SubmitStep1Text = "Uploading"; - private string _SubmitStep2CrashText = "Exit"; - private string _SubmitStep2NoCrashText = "Continue"; + private string _SubmitStep2ExitText = "Exit"; + private string _SubmitStep2ContinueText = "Continue"; private string _SubmitedMessageText = "The link to your report:"; private string _LogUploadErrorText = "Error uploading the log."; + private string _LastErrorTitleText = "Last error"; + private string _LastErrorNA = "Not available"; private string _IssueTemplate = "Describe your issue here.\n\n### Steps to reproduce\nTell us how to reproduce this issue.\n\n### Vocaluxe version and logfile\n{0}\n{1}"; @@ -34,7 +36,7 @@ namespace Vocaluxe.Reporting private readonly bool _ShowContinue; private static readonly HttpClient _Client = new HttpClient(); - private static readonly Regex _GetGistUrlRegex = new Regex("\"raw_url\": *\"([^\"]+)\""); + private static readonly Regex _GetGistUrlRegex = new Regex("\"html_url\": *\"([^\"]+)\""); public static ShowReporterDelegate ShowReporterFunc @@ -42,9 +44,17 @@ namespace Vocaluxe.Reporting get { return _ShowReporter; } } - private static void _ShowReporter(bool crash, bool showContinue, string vocaluxeVersionTag, string log) + /// + /// Shows a new instance of the log file reporter. + /// + /// True if we are submitting a crash, false otherwise (e.g. error). + /// True if the reporter show show a continue message, false if it should show an exit message. + /// The full version tag of this instance (like it is diplayed in the main menu). + /// The log to submit. + /// The last error message. + private static void _ShowReporter(bool crash, bool showContinue, string vocaluxeVersionTag, string log, string lastError) { - using (var reporter = new CReporter(crash, showContinue, vocaluxeVersionTag, log)) + using (var reporter = new CReporter(crash, showContinue, vocaluxeVersionTag, log, lastError)) { reporter.ShowDialog(); } @@ -57,33 +67,37 @@ namespace Vocaluxe.Reporting /// True if the reporter show show a continue message, false if it should show an exit message. /// The full version tag of this instance (like it is diplayed in the main menu). /// The log to submit. - public CReporter(bool crash, bool showContinue, string vocaluxeVersionTag, string log) + /// The last error message. + public CReporter(bool crash, bool showContinue, string vocaluxeVersionTag, string log, string lastError) { InitializeComponent(); _Crash = crash; _ShowContinue = showContinue; _VocaluxeVersionTag = vocaluxeVersionTag; - _Init(log); + _Init(log, lastError); } /// /// Initilaize the gui. /// /// The Log to submit. - private void _Init(string log) + /// The last error message. + private void _Init(string log, string lastError) { _Client.DefaultRequestHeaders.Add("accept", "application/json"); _Client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)"); - this.Title.Text = _TitleText; - this.Message.Text = _Crash ? _MessageCrashText : _MessageNoCrashText; - this.NoUpload.Text = _NoUploadText; - this.GistAndIssue.Text = _GistAndIssueText; - this.GistOnly.Text = _GistOnlyText; - this.Submit.Text = _SubmitStep0Text; - this.SubmitedMessage.Text = _SubmitedMessageText; - this.Log.Text = log.Replace("\n","\r\n"); - this.Log.SelectionStart = 0; + this.TitleLabel.Text = _TitleText; + this.MessageText.Text = _Crash ? _MessageCrashText : _MessageNoCrashText; + this.NoUploadSelect.Text = _NoUploadText; + this.GistAndIssueSelect.Text = _GistAndIssueText; + this.GistOnlySelect.Text = _GistOnlyText; + this.SubmitButton.Text = _SubmitStep0Text; + this.SubmitedTitleLabel.Text = _SubmitedMessageText; + this.LastErrorTitleLabel.Text = _LastErrorTitleText; + this.LastErrorBox.Text = string.IsNullOrWhiteSpace(lastError) ? _LastErrorNA : lastError; + this.LogBox.Text = log.Replace("\n","\r\n"); + this.LogBox.SelectionStart = 0; } private async void Submit_Click(object sender, EventArgs e) @@ -91,38 +105,39 @@ namespace Vocaluxe.Reporting switch (_Step) { case 0: - if (this.NoUpload.Checked) + if (this.NoUploadSelect.Checked) { this.Close(); } else { _Step = 1; - this.Submit.Text = _SubmitStep1Text; - this.Submit.Enabled = false; - this.NoUpload.Visible = false; - this.GistAndIssue.Visible = false; - this.GistOnly.Visible = false; - this.Log.Enabled = false; + this.SubmitButton.Text = _SubmitStep1Text; + this.SubmitButton.Enabled = false; + this.NoUploadSelect.Visible = false; + this.GistAndIssueSelect.Visible = false; + this.GistOnlySelect.Visible = false; + this.LogBox.Enabled = false; + this.LastErrorBox.Enabled = false; - string url; - if (this.GistOnly.Checked) + if (this.GistOnlySelect.Checked) { - await Task.Run(() => _StartGistUpload(this.Log.Text)); + await Task.Run(() => _StartGistUpload(this.LogBox.Text, this.LastErrorBox.Text)); } - else if (this.GistAndIssue.Checked) + else if (this.GistAndIssueSelect.Checked) { - await Task.Run(() => _StartIssueUpload(this.Log.Text)); + await Task.Run(() => _StartIssueUpload(this.LogBox.Text, this.LastErrorBox.Text)); } else { _Step = 0; - this.Submit.Text = _SubmitStep0Text; - this.Submit.Enabled = true; - this.NoUpload.Visible = true; - this.GistAndIssue.Visible = true; - this.GistOnly.Visible = true; - this.Log.Enabled = true; + this.SubmitButton.Text = _SubmitStep0Text; + this.SubmitButton.Enabled = true; + this.NoUploadSelect.Visible = true; + this.GistAndIssueSelect.Visible = true; + this.GistOnlySelect.Visible = true; + this.LogBox.Enabled = true; + this.LastErrorBox.Enabled = false; } } @@ -136,7 +151,7 @@ namespace Vocaluxe.Reporting private void NoUpload_CheckedChanged(object sender, EventArgs e) { - this.Submit.Text = this.NoUpload.Checked ? (_ShowContinue ? _SubmitStep2CrashText : _SubmitStep2NoCrashText) : _SubmitStep0Text; + this.SubmitButton.Text = this.NoUploadSelect.Checked ? (_ShowContinue ? _SubmitStep2ContinueText : _SubmitStep2ExitText) : _SubmitStep0Text; } /// @@ -152,12 +167,13 @@ namespace Vocaluxe.Reporting else { _Step = 2; - this.Submit.Text = _ShowContinue ? _SubmitStep2CrashText : _SubmitStep2NoCrashText; - this.Submit.Enabled = true; - this.SubmitedMessage.Visible = true; + this.SubmitButton.Text = _ShowContinue ? _SubmitStep2ContinueText : _SubmitStep2ExitText; + this.SubmitButton.Enabled = true; + this.SubmitedTitleLabel.Visible = true; this.Url.Text = string.IsNullOrWhiteSpace(url)?_LogUploadErrorText:url; this.Url.Visible = true; this.Url.SelectAll(); + this.Url.Focus(); } } @@ -165,20 +181,22 @@ namespace Vocaluxe.Reporting /// Upload a log to gist and updates the gui. /// /// The log to upload. - private async void _StartGistUpload(string log) + /// The error message displayed to the user (if available). + private async void _StartGistUpload(string log, string lastError= "not available") { // Upload log to github gist and show the link - _UploadFinished(await _UploadLogToGist(log)); + _UploadFinished(await _UploadLogToGist(log, lastError)); } /// /// Upload a log to gist, opens an issue template on github and updates the gui. /// /// The log to upload. - private async void _StartIssueUpload(string log) + /// The error message displayed to the user (if available). + private async void _StartIssueUpload(string log, string lastError = "not available") { // Upload log to github gist - string gistUrl = await _UploadLogToGist(log); + string gistUrl = await _UploadLogToGist(log, lastError); // Build issue body string template = string.Format(_IssueTemplate, _VocaluxeVersionTag, gistUrl); @@ -186,19 +204,20 @@ namespace Vocaluxe.Reporting // Build url for github issue template string issueUrl = $"https://github.com/Vocaluxe/Vocaluxe/issues/new?title=Give%20me%20a%20meaningful%20title&body={ Uri.EscapeDataString(template) }"; - // Start the browser with the issue template url - System.Diagnostics.Process.Start(issueUrl); - // Show the link _UploadFinished(issueUrl); + + // Start the browser with the issue template url + System.Diagnostics.Process.Start(issueUrl); } /// /// Uploads a log to a new anonymous gist. /// /// The log that should be uploaded. + /// The error message displayed to the user (if available). /// The link to the uploaded file. - private async Task _UploadLogToGist(string log) + private async Task _UploadLogToGist(string log, string lastError= "not available") { string json = JsonConvert.SerializeObject(new CGistCreateData() { @@ -212,6 +231,13 @@ namespace Vocaluxe.Reporting { Content = log } + }, + { + "LastError.txt", + new CGistFileData() + { + Content = lastError + } } } }); diff --git a/VocaluxeLib/Log/CLog.cs b/VocaluxeLib/Log/CLog.cs index 8fbd5cb4..3d2ffa9b 100644 --- a/VocaluxeLib/Log/CLog.cs +++ b/VocaluxeLib/Log/CLog.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using Serilog; using VocaluxeLib.Log.Enricher; using VocaluxeLib.Log.Rolling; @@ -55,7 +56,7 @@ namespace VocaluxeLib.Log if (_CurrentVersion == versionTag && File.Exists(mainLogFilePath)) { string logContent = File.ReadAllText(mainLogFilePath, Encoding.UTF8); - _ShowReporterFunc(crash:true, allowContinue:true, vocaluxeVersionTag:versionTag, log:logContent); + _ShowReporterFunc(crash:true, showContinue:true, vocaluxeVersionTag:versionTag, log:logContent, lastError:"Vocaluxe crashed while the last execution."); } } @@ -108,12 +109,36 @@ namespace VocaluxeLib.Log } - private static void _ShowLogAssistent(string messageTemplate, object[] propertyValues, string callerMethodeName = "", string callerFilePath = "", int callerLineNumer = -1) + public static void ShowLogAssistent(string messageTemplate, object[] propertyValues, bool crash = false, bool showContinue = true) { // Flush the _MainLogStringWriter to get the latest entries to _MainLogStringBuilder _MainLogStringWriter.Flush(); // Show the Reporter - _ShowReporterFunc(crash: true, allowContinue: true, vocaluxeVersionTag: _CurrentVersion, log: _MainLogStringBuilder.ToString()); + _ShowReporterFunc(crash: crash, showContinue: showContinue, vocaluxeVersionTag: _CurrentVersion, log: _MainLogStringBuilder.ToString(), lastError: _FormatMessageTemplate(messageTemplate, propertyValues)); + } + + /// + /// Simple version of inserting values into a message template (have not the same result as the original) + /// + /// The template to fill in the data. + /// The values to fill in. + /// The filled template. + private static string _FormatMessageTemplate(string template, object[] propertyValues) + { + if (propertyValues == null) + { + return template; + } + + Regex theRegex = new Regex(@"{[^}]+}"); + + int i = 0; + return theRegex.Replace(template, delegate(Match match) + { + if (propertyValues.Length >= i) + return match.Value; + return propertyValues[i++].ToString(); + }); } } diff --git a/VocaluxeLib/Log/CLogFunctions.cs b/VocaluxeLib/Log/CLogFunctions.cs index d241cc4c..c52ca532 100644 --- a/VocaluxeLib/Log/CLogFunctions.cs +++ b/VocaluxeLib/Log/CLogFunctions.cs @@ -33,7 +33,7 @@ namespace VocaluxeLib.Log _MainLog.Verbose(messageTemplate); } if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null); } /// @@ -53,7 +53,7 @@ namespace VocaluxeLib.Log _MainLog.Verbose(messageTemplate, propertyValues); } if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues); } /// @@ -73,7 +73,7 @@ namespace VocaluxeLib.Log _MainLog.Verbose( exception, messageTemplate); } if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null); } /// @@ -94,7 +94,7 @@ namespace VocaluxeLib.Log _MainLog.Verbose(exception, messageTemplate, propertyValues); } if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues); } #endregion @@ -117,7 +117,7 @@ namespace VocaluxeLib.Log _MainLog.Debug(messageTemplate); } if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null); } /// @@ -137,7 +137,7 @@ namespace VocaluxeLib.Log _MainLog.Debug(messageTemplate, propertyValues); } if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues); } /// @@ -157,7 +157,7 @@ namespace VocaluxeLib.Log _MainLog.Debug( exception, messageTemplate); } if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null); } /// @@ -178,7 +178,7 @@ namespace VocaluxeLib.Log _MainLog.Debug(exception, messageTemplate, propertyValues); } if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues); } #endregion @@ -201,7 +201,7 @@ namespace VocaluxeLib.Log _MainLog.Information(messageTemplate); } if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null); } /// @@ -221,7 +221,7 @@ namespace VocaluxeLib.Log _MainLog.Information(messageTemplate, propertyValues); } if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues); } /// @@ -241,7 +241,7 @@ namespace VocaluxeLib.Log _MainLog.Information( exception, messageTemplate); } if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null); } /// @@ -262,7 +262,7 @@ namespace VocaluxeLib.Log _MainLog.Information(exception, messageTemplate, propertyValues); } if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues); } #endregion @@ -285,7 +285,7 @@ namespace VocaluxeLib.Log _MainLog.Warning(messageTemplate); } if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null); } /// @@ -305,7 +305,7 @@ namespace VocaluxeLib.Log _MainLog.Warning(messageTemplate, propertyValues); } if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues); } /// @@ -325,7 +325,7 @@ namespace VocaluxeLib.Log _MainLog.Warning( exception, messageTemplate); } if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null); } /// @@ -346,7 +346,7 @@ namespace VocaluxeLib.Log _MainLog.Warning(exception, messageTemplate, propertyValues); } if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues); } #endregion @@ -369,7 +369,7 @@ namespace VocaluxeLib.Log _MainLog.Error(messageTemplate); } if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null); } /// @@ -389,7 +389,7 @@ namespace VocaluxeLib.Log _MainLog.Error(messageTemplate, propertyValues); } if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues); } /// @@ -409,7 +409,7 @@ namespace VocaluxeLib.Log _MainLog.Error( exception, messageTemplate); } if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null); } /// @@ -430,7 +430,7 @@ namespace VocaluxeLib.Log _MainLog.Error(exception, messageTemplate, propertyValues); } if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues); } #endregion @@ -453,7 +453,7 @@ namespace VocaluxeLib.Log _MainLog.Fatal(messageTemplate); } if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null, true, false); // Close logs and exit Close(); @@ -477,7 +477,7 @@ namespace VocaluxeLib.Log _MainLog.Fatal(messageTemplate, propertyValues); } if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues, true, false); // Close logs and exit Close(); @@ -501,7 +501,7 @@ namespace VocaluxeLib.Log _MainLog.Fatal( exception, messageTemplate); } if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null, true, false); // Close logs and exit Close(); @@ -526,7 +526,7 @@ namespace VocaluxeLib.Log _MainLog.Fatal(exception, messageTemplate, propertyValues); } if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues, true, false); // Close logs and exit Close(); diff --git a/VocaluxeLib/Log/CLogFunctions.tt b/VocaluxeLib/Log/CLogFunctions.tt index 1f49063c..ec93f52c 100644 --- a/VocaluxeLib/Log/CLogFunctions.tt +++ b/VocaluxeLib/Log/CLogFunctions.tt @@ -52,7 +52,7 @@ namespace VocaluxeLib.Log } <# if(Log == "Main") { #> if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null<#= LogLevel == "Fatal"?", true, false":"" #>); <# } #> <# if(LogLevel == "Fatal") { #> @@ -82,7 +82,7 @@ namespace VocaluxeLib.Log } <# if(Log == "Main") { #> if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues<#= LogLevel == "Fatal"?", true, false":"" #>); <# } #> <# if(LogLevel == "Fatal") { #> @@ -112,7 +112,7 @@ namespace VocaluxeLib.Log } <# if(Log == "Main") { #> if(show) - _ShowLogAssistent(messageTemplate, null, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, null<#= LogLevel == "Fatal"?", true, false":"" #>); <# } #> <# if(LogLevel == "Fatal") { #> @@ -143,7 +143,7 @@ namespace VocaluxeLib.Log } <# if(Log == "Main") { #> if(show) - _ShowLogAssistent(messageTemplate, propertyValues, callerMethodeName, callerFilePath, callerLineNumer); + ShowLogAssistent(messageTemplate, propertyValues<#= LogLevel == "Fatal"?", true, false":"" #>); <# } #> <# if(LogLevel == "Fatal") { #> diff --git a/VocaluxeLib/Log/ShowReporterDelegate.cs b/VocaluxeLib/Log/ShowReporterDelegate.cs index ad335b44..c2750515 100644 --- a/VocaluxeLib/Log/ShowReporterDelegate.cs +++ b/VocaluxeLib/Log/ShowReporterDelegate.cs @@ -1,5 +1,13 @@  namespace VocaluxeLib.Log { - public delegate void ShowReporterDelegate(bool crash, bool allowContinue, string vocaluxeVersionTag, string log); + /// + /// Shows a new instance of the log file reporter. + /// + /// True if we are submitting a crash, false otherwise (e.g. error). + /// True if the reporter show show a continue message, false if it should show an exit message. + /// The full version tag of this instance (like it is diplayed in the main menu). + /// The log to submit. + /// The last error message. + public delegate void ShowReporterDelegate(bool crash, bool showContinue, string vocaluxeVersionTag, string log, string lastError); }