91 lines
3.4 KiB
C#
91 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using gehGassi.Dto;
|
|
using gehGassiApp.Core.Interfaces;
|
|
using gehGassiApp.Core.Mapper;
|
|
using gehGassiApp.Core.Resources;
|
|
using gehGassiApp.Domain.AppVersions;
|
|
using Platform = gehGassiApp.Domain.Common.Platform;
|
|
|
|
namespace gehGassiApp.Core.Services
|
|
{
|
|
/// <summary>
|
|
/// Service der die aktuelle AppVersion am Server ermitteln kann
|
|
/// </summary>
|
|
public class AppVersionService : IAppVersionService
|
|
{
|
|
private readonly ICommunicationService _communicationService;
|
|
|
|
/// <summary>
|
|
/// Erstellt eine Instanz
|
|
/// </summary>
|
|
/// <param name="communicationService">Instanz eines ICommunicationService</param>
|
|
public AppVersionService(ICommunicationService communicationService)
|
|
{
|
|
_communicationService = communicationService;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Holen der aktuellen Version am Server für die gewählte Plattform
|
|
/// </summary>
|
|
/// <param name="platform">Plattform</param>
|
|
/// <param name="language">Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<AppVersionCheck>> CheckCurrentAppVersionAsync(Platform platform, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<AppVersionCheck>() { Value = null };
|
|
|
|
var isConnected = await _communicationService.IsConnected();
|
|
if (isConnected)
|
|
{
|
|
var checkResult = await _communicationService.CheckCurrentAppVersionAsync(platform.ToDto(), language, accessToken, token);
|
|
if (checkResult.Success)
|
|
return checkResult;
|
|
}
|
|
else
|
|
{
|
|
result.Success = false;
|
|
result.ErrorCode = CommunicationErrors.ServerNoConnection;
|
|
result.ErrorMessage = Errors.Server_NoConnection;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Holen der aktuellen Version am Server für die gewählte Plattform
|
|
/// </summary>
|
|
/// <param name="platform">Plattform</param>
|
|
/// <param name="language">Sprache</param>
|
|
/// <param name="accessToken">Aktuelles Accesstoken</param>
|
|
/// <param name="token">CancellationToken</param>
|
|
/// <returns>CommunicationResult</returns>
|
|
public async Task<CommunicationResult<AppVersion>> GetCurrentAppVersionAsync(Platform platform, string language, string accessToken, CancellationToken token)
|
|
{
|
|
var result = new CommunicationResult<AppVersion>() { Value = null };
|
|
|
|
var isConnected = await _communicationService.IsConnected();
|
|
if (isConnected)
|
|
{
|
|
var checkResult = await _communicationService.GetCurrentAppVersionAsync(platform.ToDto(), language, accessToken, token);
|
|
if (checkResult.Success)
|
|
return checkResult;
|
|
}
|
|
else
|
|
{
|
|
result.Success = false;
|
|
result.ErrorCode = CommunicationErrors.ServerNoConnection;
|
|
result.ErrorMessage = Errors.Server_NoConnection;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
}
|