-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use WarningsService from Boilerplate
- Loading branch information
Showing
2 changed files
with
21 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, string> { | ||
[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<Exception> 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<Exception> potentiallyFailingTask, string prefix = "Warning: ") | ||
=> WarningsService.ReportAsWarning(potentiallyFailingTask, prefix); | ||
public static void ReportAsWarning(this Task potentiallyFailingTask, string prefix = "Warning: ") | ||
=> WarningsService.ReportAsWarning(potentiallyFailingTask, prefix); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters