Removal of unused License Service

This commit is contained in:
BONNEVILLE Geoffroy
2018-06-18 16:19:56 +02:00
parent e9601e8d13
commit 9225732c1a
7 changed files with 8 additions and 127 deletions

View File

@@ -1,12 +0,0 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Windows.ApplicationModel.Store;
namespace ModernKeePass.Interfaces
{
public interface ILicenseService
{
IReadOnlyDictionary<string, ProductListing> Products { get; }
Task<int> Purchase(string addOn);
}
}

View File

@@ -116,7 +116,6 @@
</Compile>
<Compile Include="Converters\IntToSymbolConverter.cs" />
<Compile Include="Exceptions\DatabaseOpenedException.cs" />
<Compile Include="Interfaces\ILicenseService.cs" />
<Compile Include="Interfaces\IProxyInvocationHandler.cs" />
<Compile Include="Interfaces\IRecentService.cs" />
<Compile Include="Interfaces\IRecentItem.cs" />
@@ -135,7 +134,6 @@
<Compile Include="Common\ObservableDictionary.cs" />
<Compile Include="Common\RelayCommand.cs" />
<Compile Include="Common\SuspensionManager.cs" />
<Compile Include="Services\LicenseService.cs" />
<Compile Include="Services\RecentService.cs" />
<Compile Include="Services\ResourcesService.cs" />
<Compile Include="Services\SettingsService.cs" />

View File

@@ -1,73 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Windows.ApplicationModel.Store;
using ModernKeePass.Interfaces;
namespace ModernKeePass.Services
{
public class LicenseService : SingletonServiceBase<LicenseService>, ILicenseService
{
public enum PurchaseResult
{
Succeeded,
NothingToFulfill,
PurchasePending,
PurchaseReverted,
ServerError,
NotPurchased,
AlreadyPurchased
}
public IReadOnlyDictionary<string, ProductListing> Products { get; }
private readonly HashSet<Guid> _consumedTransactionIds = new HashSet<Guid>();
public LicenseService()
{
var listing = CurrentApp.LoadListingInformationAsync().GetAwaiter().GetResult();
Products = listing.ProductListings;
}
public async Task<int> Purchase(string addOn)
{
var purchaseResults = await CurrentApp.RequestProductPurchaseAsync(addOn);
switch (purchaseResults.Status)
{
case ProductPurchaseStatus.Succeeded:
GrantFeatureLocally(purchaseResults.TransactionId);
return (int) await ReportFulfillmentAsync(purchaseResults.TransactionId, addOn);
case ProductPurchaseStatus.NotFulfilled:
// The purchase failed because we haven't confirmed fulfillment of a previous purchase.
// Fulfill it now.
if (!IsLocallyFulfilled(purchaseResults.TransactionId))
{
GrantFeatureLocally(purchaseResults.TransactionId);
}
return (int) await ReportFulfillmentAsync(purchaseResults.TransactionId, addOn);
case ProductPurchaseStatus.NotPurchased:
return (int) PurchaseResult.NotPurchased;
case ProductPurchaseStatus.AlreadyPurchased:
return (int) PurchaseResult.AlreadyPurchased;
default:
throw new IndexOutOfRangeException("Purchase results status does not have a valid value");
}
}
private async Task<PurchaseResult> ReportFulfillmentAsync(Guid transactionId, string productName)
{
var result = await CurrentApp.ReportConsumableFulfillmentAsync(productName, transactionId);
return (PurchaseResult) result;
}
private void GrantFeatureLocally(Guid transactionId)
{
_consumedTransactionIds.Add(transactionId);
}
private bool IsLocallyFulfilled(Guid transactionId)
{
return _consumedTransactionIds.Contains(transactionId);
}
}
}