88 lines
2.9 KiB
C#
88 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using gehGassiApp.Core.Interfaces;
|
|
using gehGassiApp.Core.Mapper;
|
|
using gehGassiApp.Domain.Common;
|
|
using gehGassiApp.Domain.Pushnotifications;
|
|
using Platform = gehGassiApp.Domain.Common.Platform;
|
|
|
|
namespace gehGassiApp.Core.Services
|
|
{
|
|
/// <summary>
|
|
/// Service der alle Funktionen rund um Pushnotifications bereitstellt
|
|
/// </summary>
|
|
public class PushnotificationService : IPushnotificationService
|
|
{
|
|
private readonly ICommunicationService _communicationService;
|
|
|
|
/// <summary>
|
|
/// Erstellt eine Instanz
|
|
/// </summary>
|
|
/// <param name="communicationService">Instanz eines ICommunicationService</param>
|
|
public PushnotificationService(ICommunicationService communicationService)
|
|
{
|
|
_communicationService = communicationService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registrieren / Aktualisieren eines Devices für Push-Notifications
|
|
/// </summary>
|
|
/// <param name="installationId">Eindeutige ID</param>
|
|
/// <param name="channel">Push-Channel / Hub</param>
|
|
/// <param name="language">Sprache des Gerätes</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>True wenn Registrierung erfolgreich, false sonst</returns>
|
|
public async Task<bool> RegisterAsycn(string installationId, string channel, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var isConnected = await _communicationService.IsConnected();
|
|
if (isConnected)
|
|
{
|
|
var deviceInstallation = new DeviceInstallation
|
|
{
|
|
InstallationId = installationId,
|
|
Channel = channel,
|
|
Platform = Platform.Android,
|
|
NotificationPlatform = NotificationPlatform.FcmV1,
|
|
Language = language
|
|
};
|
|
|
|
if (DeviceInfo.Platform == DevicePlatform.iOS)
|
|
{
|
|
deviceInstallation.Platform = Platform.Ios;
|
|
deviceInstallation.NotificationPlatform = NotificationPlatform.Apns;
|
|
}
|
|
|
|
var dto = deviceInstallation.ToDto();
|
|
|
|
var successResult = await _communicationService.RegisterPushnotificationsAsync(dto, accessToken, token);
|
|
return successResult.Value;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deregistrieren eines Devices für Push-Notifications
|
|
/// </summary>
|
|
/// <param name="installationId">Eindeutige ID</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>True wenn Deregistrierung erfolgreich, false sonst</returns>
|
|
public async Task<bool> UnregisterAsycn(string installationId, string accessToken, CancellationToken token)
|
|
{
|
|
var isConnected = await _communicationService.IsConnected();
|
|
if (isConnected)
|
|
{
|
|
var successResult = await _communicationService.UnregisterPushnotificationsAsync(installationId, accessToken, token);
|
|
return successResult.Value;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|