Skip to content

Commit

Permalink
Added resilience for lacking configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinselohrkater committed Jan 6, 2021
1 parent f43222d commit 204fc97
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Eurofurence.App.Server.Services.Abstractions.PushNotifications
{
public class FirebaseConfiguration
{
public bool IsConfigured => !string.IsNullOrEmpty(AuthorizationKey);
public string AuthorizationKey { get; set; }

public static FirebaseConfiguration FromConfiguration(IConfiguration configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ namespace Eurofurence.App.Server.Services.Abstractions.PushNotifications
{
public class WnsConfiguration
{
public bool IsConfigured => !string.IsNullOrEmpty(ClientId)
&& !string.IsNullOrEmpty(ClientSecret)
&& !string.IsNullOrEmpty(TargetTopic);

public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string TargetTopic { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Eurofurence.App.Server.Services.Abstractions.Telegram
{
public class TelegramConfiguration
{
public bool IsConfigured => !string.IsNullOrEmpty(AccessToken);
public string AccessToken { get; set; }
public string Proxy { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ private Task<IEnumerable<PushNotificationChannelRecord>> GetRecipientChannelAsyn

public Task PushAnnouncementNotificationAsync(AnnouncementRecord announcement)
{
if (!_configuration.IsConfigured) return Task.CompletedTask;

return Task.WhenAll(
SendPushNotificationAsync(new
{
Expand Down Expand Up @@ -82,6 +84,8 @@ public Task PushAnnouncementNotificationAsync(AnnouncementRecord announcement)

public async Task PushPrivateMessageNotificationAsync(string recipientUid, string toastTitle, string toastMessage, Guid relatedId)
{
if (!_configuration.IsConfigured) return;

var recipients = await GetRecipientChannelAsync(recipientUid);

foreach (var recipient in recipients)
Expand Down Expand Up @@ -132,6 +136,8 @@ await SendPushNotificationAsync(new

public Task PushSyncRequestAsync()
{
if (!_configuration.IsConfigured) return Task.CompletedTask;

return Task.WhenAll(
SendPushNotificationAsync(new
{
Expand Down Expand Up @@ -165,7 +171,6 @@ public Task PushSyncRequestAsync()

private async Task SendPushNotificationAsync(object payload)
{

var jsonPayload = JsonConvert.SerializeObject(payload);

using (var client = new HttpClient())
Expand Down
4 changes: 2 additions & 2 deletions src/Eurofurence.App.Server.Services/Telegram/BotManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ ITelegramMessageBroker telegramMessageBroker
_conventionSettings = conventionSettings;
_telegramMessageBroker = telegramMessageBroker;

if (string.IsNullOrWhiteSpace(telegramConfiguration.AccessToken))
if (!telegramConfiguration.IsConfigured)
{
_logger.LogInformation("No access token for Telegram Bot provided - not running bot.");
_logger.LogWarning("Telegram configuration not available. Telegram bot will not be run.");
return;
}

Expand Down

0 comments on commit 204fc97

Please sign in to comment.