Files
BeWoPlaner/Service/ServiceImplementations/DownloadBeWoServiceImp.cs

91 lines
3.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.ServiceModel;
using System.Xml;
using BeWo.Data;
using BeWo.Service.ServiceContracts;
using BeWo.Service.ServiceUtils.Paths;
using BeWo.Service.ServiceUtils.Update;
using BS.SharedLauncher.DataContract;
using BS.SharedLauncher.Enums;
using BS.SharedLauncher.Exceptions;
using BS.SharedLauncher.Extensions;
using BS.SharedLauncher.Logic;
using BS.SharedLauncher.Update;
namespace BeWo.Service.ServiceImplementations
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
public class DownloadBeWoServiceImp : IDownloadBeWoService
{
public string Tenant => MultitenancyOperationContextExt.Current.Tenant;
public DownloadPlanerResponseDC Download2(DownloadPlanerRequestDC request)
{
try
{
DownloadPlanerResponseBuilder builder = new DownloadPlanerResponseBuilder(request);
builder.Calculate(Tenant);
if (!request.ApplyFolderIsEmpty)
if (request.ApplyPackage is object)
builder.Substract(request.ApplyPackage.ToPlanerPackageInfo());
if (!request.DownloadFolderIsEmpty)
if (request.DownloadedPackages is object)
builder.AnalyseDownload(request.DownloadedPackages.ToDictionary(pair => pair.Key, pair => pair.Value.ToPlanerPackageInfo()));
return builder.CreateResponse(request);
}
catch (UpdateException update)
{
throw update;
}
catch (Exception ex)
{
throw new UpdateException("Update - Download - Exception", ex);
}
}
public DownloadPlanerResponseInfoDC DownloadInfo(DownloadPlanerRequestDC request)
{
try
{
var responseInfo = new DownloadPlanerResponseInfoDC();
var response = Download2(request);
responseInfo.DownloadSize = response.NewZipData?.LongLength ?? 0;
responseInfo.FileCount = 0;
if (response.DownloadFilesToKeep is object)
responseInfo.FileCount += response.DownloadFilesToKeep.Sum(kv => kv.Value.Count);
if (response.NewZipInfo is object)
{
responseInfo.FileCount += response.NewZipInfo.Files.Count;
responseInfo.NewFileCount = response.NewZipInfo.Files.Count;
}
responseInfo.HasSomethingToDo = response.HasToDo();
responseInfo.Version = response.LatestApplicationInfo.Version;
return responseInfo;
}
catch (UpdateException update)
{
throw update;
}
catch (Exception ex)
{
throw new UpdateException("Update - DownloadInfo - Exception", ex);
}
}
}
}