2021-05-16 22:04:42 +02:00
|
|
|
using System;
|
2021-05-19 16:32:11 +02:00
|
|
|
using Microsoft.JSInterop;
|
2021-05-16 22:04:42 +02:00
|
|
|
using WotBlitzStatisticsPro.Blazor.Model;
|
|
|
|
|
|
|
|
|
|
namespace WotBlitzStatisticsPro.Blazor.Services
|
|
|
|
|
{
|
|
|
|
|
public class NotificationsService: INotificationsService
|
|
|
|
|
{
|
2021-05-19 16:32:11 +02:00
|
|
|
private readonly IJSRuntime _jsRuntime;
|
|
|
|
|
|
|
|
|
|
public NotificationsService(IJSRuntime jsRuntime)
|
|
|
|
|
{
|
|
|
|
|
_jsRuntime = jsRuntime;
|
|
|
|
|
}
|
2021-05-16 22:04:42 +02:00
|
|
|
|
|
|
|
|
public NotificationType Type { get; private set; } = NotificationType.Info;
|
|
|
|
|
|
|
|
|
|
public string Message { get; private set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
public string Summary { get; private set; }
|
|
|
|
|
|
|
|
|
|
public event Action MessageArrived;
|
|
|
|
|
|
|
|
|
|
public void ReportInfo(string summary, string message)
|
|
|
|
|
{
|
|
|
|
|
Type = NotificationType.Info;
|
|
|
|
|
Message = message;
|
|
|
|
|
Summary = summary;
|
|
|
|
|
MessageArrived?.Invoke();
|
2021-05-19 16:32:11 +02:00
|
|
|
_jsRuntime.InvokeVoidAsync("console.log", summary, message);
|
2021-05-16 22:04:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ReportWarning(string summary, string message)
|
|
|
|
|
{
|
|
|
|
|
Type = NotificationType.Warning;
|
|
|
|
|
Message = message;
|
|
|
|
|
Summary = summary;
|
|
|
|
|
MessageArrived?.Invoke();
|
2021-05-19 16:32:11 +02:00
|
|
|
_jsRuntime.InvokeVoidAsync("console.warn", summary, message);
|
2021-05-16 22:04:42 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-20 17:16:57 +02:00
|
|
|
public void ReportError(string summary, string message, string? stacktrace)
|
2021-05-16 22:04:42 +02:00
|
|
|
{
|
|
|
|
|
Type = NotificationType.Error;
|
|
|
|
|
Message = message;
|
|
|
|
|
Summary = summary;
|
|
|
|
|
MessageArrived?.Invoke();
|
2022-08-20 17:16:57 +02:00
|
|
|
Console.WriteLine(message);
|
|
|
|
|
_jsRuntime.InvokeVoidAsync("console.error", summary, string.IsNullOrEmpty(stacktrace) ? message : $"{message}; {stacktrace}");
|
2021-05-16 22:04:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|