From 6031ccbb48e5aed5cbb5b5c19ff6c34ff3a3e839 Mon Sep 17 00:00:00 2001 From: Victor Milovanov Date: Sun, 19 Jan 2020 18:59:09 -0800 Subject: [PATCH] use WarningsService from Boilerplate --- Warning.cs | 52 ++++++++++++++--------------------------- WindowManagement.csproj | 5 ++-- 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/Warning.cs b/Warning.cs index 75096ca..199d73a 100644 --- a/Warning.cs +++ b/Warning.cs @@ -1,46 +1,30 @@ -namespace LostTech.Stack.Utils +namespace LostTech.Stack.WindowManagement { using System; using System.Collections.Generic; - using System.ComponentModel; - using System.Globalization; + using System.Threading; using System.Threading.Tasks; - using JetBrains.Annotations; - using Microsoft.HockeyApp; + using LostTech.App; public static class WarningExtensions { - public static void ReportAsWarning(this Exception exception, string prefix = "Warning: ") { - if (exception != null) { - string message = prefix + exception.Message; - HockeyClient.Current.TrackTrace(message, SeverityLevel.Warning, properties: new SortedDictionary { - [nameof(exception.StackTrace)] = exception.StackTrace, - [nameof(exception.Source)] = exception.Source, - [nameof(exception.HResult)] = exception.HResult.ToString(CultureInfo.InvariantCulture), - [nameof(exception.InnerException)] = exception.InnerException?.ToString(), - }); - } - } + static IWarningsService? warningsService; - public static void ReportAsWarning([NotNull] this Task potentiallyFailingTask, string prefix = "Warning: ") { - if (potentiallyFailingTask == null) - throw new ArgumentNullException(nameof(potentiallyFailingTask)); - potentiallyFailingTask.ContinueWith(t => { - if (t.IsFaulted) - t.Exception.ReportAsWarning(prefix); - if (t.IsCompleted) - t.Result.ReportAsWarning(prefix); - }); + public static IWarningsService WarningsService { + get => warningsService ?? throw new InvalidOperationException($"{nameof(WarningsService)} is not initialized."); + set { + if (value is null) + throw new ArgumentNullException(nameof(WarningsService)); + if (Interlocked.CompareExchange(ref warningsService, value, null) != null) + throw new InvalidOperationException(); + } } - public static void ReportAsWarning([NotNull] this Task potentiallyFailingTask, string prefix = "Warning: ") - { - if (potentiallyFailingTask == null) - throw new ArgumentNullException(nameof(potentiallyFailingTask)); - potentiallyFailingTask.ContinueWith(t => { - if (t.IsFaulted) - t.Exception.ReportAsWarning(prefix); - }); - } + public static void ReportAsWarning(this Exception exception, string prefix = "Warning: ") + => WarningsService.ReportAsWarning(exception, prefix); + public static void ReportAsWarning(this Task potentiallyFailingTask, string prefix = "Warning: ") + => WarningsService.ReportAsWarning(potentiallyFailingTask, prefix); + public static void ReportAsWarning(this Task potentiallyFailingTask, string prefix = "Warning: ") + => WarningsService.ReportAsWarning(potentiallyFailingTask, prefix); } } diff --git a/WindowManagement.csproj b/WindowManagement.csproj index 726cb10..755063f 100644 --- a/WindowManagement.csproj +++ b/WindowManagement.csproj @@ -4,14 +4,15 @@ netstandard2.0 LostTech.Stack.WindowManagement LostTech.Stack.WindowManagement + 8.0 + enable False False - - +