private async Task ClearStylingAndCopy() { string html = this.SourceValue; #pragma warning disable CA1031 // Do not catch general exception types try { html = TextCleaner.ClearStylingFromHtml( html, CleanerSettings.Instance); } catch (Exception ex) { Logger.Log(LogLevel.Error, nameof(ClearStylingAndCopy), "Error cleaning HTML:" + Environment.NewLine + html, ex); MessageBox.Show("There was an error cleaning the HTML", "error", MessageBoxButton.OK, MessageBoxImage.Error); return; } try { ClipboardHelper.CopyToClipboard(html, html); this.SourceValue = html; Logger.Log(LogLevel.Debug, nameof(ClearStylingAndCopy), "Cleaned HTML and copied to clipboard"); } catch (Exception ex) { Logger.Log(LogLevel.Error, nameof(ClearStylingAndCopy), "Error writing HTML to clipboard", ex); MessageBox.Show("There was an error writing the cleand HTML to the clipboard", "error", MessageBoxButton.OK, MessageBoxImage.Error); return; } #pragma warning restore CA1031 // Do not catch general exception types await this.SetStatus("The cleaned HTML is on the clipboard, use Ctrl-V to paste.").ConfigureAwait(false); }
private async Task ClearStylingAndCopyAsync() { Logger.Log(LogLevel.Debug, nameof(MainPage), "Start clearing styling"); string html = this.SourceValue; Logger.Log(LogLevel.Debug, nameof(MainPage), $"HTML size before processing: {html?.Length ?? 0}"); #pragma warning disable CA1031 // Do not catch general exception types try { html = TextCleaner.ClearStylingFromHtml( html, CleanerSettings.Instance); } catch (Exception ex) { Logger.Log(LogLevel.Error, nameof(ClearStylingAndCopyAsync), "Error cleaning HTML:" + Environment.NewLine + html, ex); await this.SetStatusAsync("There was an error cleaning the HTML"); return; } Logger.Log(LogLevel.Debug, nameof(MainPage), $"HTML size after processing: {html?.Length ?? 0}"); try { ClipboardHelper.CopyToClipboard(html, html); this.SourceValue = html; Logger.Log(LogLevel.Debug, nameof(ClearStylingAndCopyAsync), "Cleaned HTML and copied to clipboard"); } catch (Exception ex) { Logger.Log(LogLevel.Error, nameof(ClearStylingAndCopyAsync), "Error writing HTML to clipboard", ex); await this.SetStatusAsync("There was an error writing the cleand HTML to the clipboard"); return; } #pragma warning restore CA1031 // Do not catch general exception types await this.SetStatusAsync("The cleaned HTML is on the clipboard, use Ctrl-V to paste.").ConfigureAwait(false); Logger.Log(LogLevel.Debug, nameof(MainPage), "Done clearing styling"); }