Skip to content

Commit

Permalink
merged boilerplate changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lostmsu committed Jan 20, 2020
2 parents 160f962 + 6031ccb commit a56a4c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
53 changes: 18 additions & 35 deletions Warning.cs
Original file line number Diff line number Diff line change
@@ -1,47 +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.AppCenter.Crashes;
using LostTech.App;

public static class WarningExtensions
{
public static void ReportAsWarning(this Exception exception, string prefix = "Warning: ") {
if (exception != null) {
Crashes.TrackError(exception, 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(),
["IsWarning"] = "true",
["Prefix"] = prefix,
});
}
}
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);
}
}
5 changes: 3 additions & 2 deletions WindowManagement.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>LostTech.Stack.WindowManagement</AssemblyName>
<RootNamespace>LostTech.Stack.WindowManagement</RootNamespace>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<Deterministic>False</Deterministic>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="2.4.0-preview" />
<PackageReference Include="System.Drawing.Primitives" Version="4.3.0" />
<PackageReference Include="LostTech.App.Boilerplate" Version="0.1.0" />
</ItemGroup>

</Project>

0 comments on commit a56a4c7

Please sign in to comment.