mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Removal of unused License Service
This commit is contained in:
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -116,7 +116,6 @@
|
|||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Converters\IntToSymbolConverter.cs" />
|
<Compile Include="Converters\IntToSymbolConverter.cs" />
|
||||||
<Compile Include="Exceptions\DatabaseOpenedException.cs" />
|
<Compile Include="Exceptions\DatabaseOpenedException.cs" />
|
||||||
<Compile Include="Interfaces\ILicenseService.cs" />
|
|
||||||
<Compile Include="Interfaces\IProxyInvocationHandler.cs" />
|
<Compile Include="Interfaces\IProxyInvocationHandler.cs" />
|
||||||
<Compile Include="Interfaces\IRecentService.cs" />
|
<Compile Include="Interfaces\IRecentService.cs" />
|
||||||
<Compile Include="Interfaces\IRecentItem.cs" />
|
<Compile Include="Interfaces\IRecentItem.cs" />
|
||||||
@@ -135,7 +134,6 @@
|
|||||||
<Compile Include="Common\ObservableDictionary.cs" />
|
<Compile Include="Common\ObservableDictionary.cs" />
|
||||||
<Compile Include="Common\RelayCommand.cs" />
|
<Compile Include="Common\RelayCommand.cs" />
|
||||||
<Compile Include="Common\SuspensionManager.cs" />
|
<Compile Include="Common\SuspensionManager.cs" />
|
||||||
<Compile Include="Services\LicenseService.cs" />
|
|
||||||
<Compile Include="Services\RecentService.cs" />
|
<Compile Include="Services\RecentService.cs" />
|
||||||
<Compile Include="Services\ResourcesService.cs" />
|
<Compile Include="Services\ResourcesService.cs" />
|
||||||
<Compile Include="Services\SettingsService.cs" />
|
<Compile Include="Services\SettingsService.cs" />
|
||||||
|
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -20,7 +20,7 @@ namespace ModernKeePassApp.Test
|
|||||||
_database.DatabaseFile = ApplicationData.Current.TemporaryFolder.CreateFileAsync("NewDatabase.kdbx").GetAwaiter().GetResult();
|
_database.DatabaseFile = ApplicationData.Current.TemporaryFolder.CreateFileAsync("NewDatabase.kdbx").GetAwaiter().GetResult();
|
||||||
Assert.IsTrue(_database.IsFileOpen);
|
Assert.IsTrue(_database.IsFileOpen);
|
||||||
OpenOrCreateDatabase(true);
|
OpenOrCreateDatabase(true);
|
||||||
_database.Close().GetAwaiter().GetResult();
|
_database.Close();
|
||||||
Assert.IsTrue(_database.IsClosed);
|
Assert.IsTrue(_database.IsClosed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ namespace ModernKeePassApp.Test
|
|||||||
TestOpen();
|
TestOpen();
|
||||||
_database.Save(ApplicationData.Current.TemporaryFolder.CreateFileAsync("SaveDatabase.kdbx").GetAwaiter().GetResult());
|
_database.Save(ApplicationData.Current.TemporaryFolder.CreateFileAsync("SaveDatabase.kdbx").GetAwaiter().GetResult());
|
||||||
Assert.IsTrue(_database.IsOpen);
|
Assert.IsTrue(_database.IsOpen);
|
||||||
_database.Close().GetAwaiter().GetResult();
|
_database.Close();
|
||||||
Assert.IsTrue(_database.IsClosed);
|
Assert.IsTrue(_database.IsClosed);
|
||||||
TestOpen();
|
TestOpen();
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ namespace ModernKeePassApp.Test
|
|||||||
private void OpenOrCreateDatabase(bool createNew)
|
private void OpenOrCreateDatabase(bool createNew)
|
||||||
{
|
{
|
||||||
Assert.ThrowsException<ArgumentNullException>(
|
Assert.ThrowsException<ArgumentNullException>(
|
||||||
() => _database.Open(null, createNew).GetAwaiter().GetResult());
|
() => _database.Open(null, createNew));
|
||||||
var compositeKey = new CompositeKeyVm(_database, new ResourceServiceMock())
|
var compositeKey = new CompositeKeyVm(_database, new ResourceServiceMock())
|
||||||
{
|
{
|
||||||
HasPassword = true,
|
HasPassword = true,
|
||||||
|
@@ -1,31 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Windows.ApplicationModel;
|
|
||||||
using Windows.ApplicationModel.Store;
|
|
||||||
using ModernKeePass.Interfaces;
|
|
||||||
|
|
||||||
namespace ModernKeePassApp.Test.Mock
|
|
||||||
{
|
|
||||||
public class LicenseServiceMock: ILicenseService
|
|
||||||
{
|
|
||||||
public IReadOnlyDictionary<string, ProductListing> Products { get; }
|
|
||||||
|
|
||||||
public LicenseServiceMock()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var proxyFile = Package.Current.InstalledLocation.GetFileAsync("data\\WindowsStoreProxy.xml").GetAwaiter().GetResult();
|
|
||||||
CurrentAppSimulator.ReloadSimulatorAsync(proxyFile).GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
var listing = CurrentAppSimulator.LoadListingInformationAsync().GetAwaiter().GetResult();
|
|
||||||
Products = listing.ProductListings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<int> Purchase(string addOn)
|
|
||||||
{
|
|
||||||
throw new System.NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -121,7 +121,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="DatabaseTests.cs" />
|
<Compile Include="DatabaseTests.cs" />
|
||||||
<Compile Include="Mock\DatabaseServiceMock.cs" />
|
<Compile Include="Mock\DatabaseServiceMock.cs" />
|
||||||
<Compile Include="Mock\LicenseServiceMock.cs" />
|
|
||||||
<Compile Include="Mock\RecentServiceMock.cs" />
|
<Compile Include="Mock\RecentServiceMock.cs" />
|
||||||
<Compile Include="Mock\ResourceServiceMock.cs" />
|
<Compile Include="Mock\ResourceServiceMock.cs" />
|
||||||
<Compile Include="Mock\SettingsServiceMock.cs" />
|
<Compile Include="Mock\SettingsServiceMock.cs" />
|
||||||
|
@@ -39,7 +39,7 @@ namespace ModernKeePassApp.Test
|
|||||||
Assert.IsNotNull(mainVm.SelectedItem);
|
Assert.IsNotNull(mainVm.SelectedItem);
|
||||||
Assert.AreEqual(typeof(OpenDatabasePage), ((MainMenuItemVm) mainVm.SelectedItem).PageType);
|
Assert.AreEqual(typeof(OpenDatabasePage), ((MainMenuItemVm) mainVm.SelectedItem).PageType);
|
||||||
|
|
||||||
database.Open(null, false).GetAwaiter().GetResult();
|
database.Open(null);
|
||||||
mainVm = new MainVm(null, null, database, _resource, _recent);
|
mainVm = new MainVm(null, null, database, _resource, _recent);
|
||||||
Assert.IsNotNull(mainVm.SelectedItem);
|
Assert.IsNotNull(mainVm.SelectedItem);
|
||||||
Assert.AreEqual(2, mainVm.MainMenuItems.Count());
|
Assert.AreEqual(2, mainVm.MainMenuItems.Count());
|
||||||
@@ -94,10 +94,10 @@ namespace ModernKeePassApp.Test
|
|||||||
{
|
{
|
||||||
var database = new DatabaseServiceMock();
|
var database = new DatabaseServiceMock();
|
||||||
var saveVm = new SaveVm(database);
|
var saveVm = new SaveVm(database);
|
||||||
database.Open(null, false).GetAwaiter().GetResult();
|
database.Open(null);
|
||||||
saveVm.Save(false).GetAwaiter().GetResult();
|
saveVm.Save(false);
|
||||||
Assert.IsTrue(database.IsOpen);
|
Assert.IsTrue(database.IsOpen);
|
||||||
saveVm.Save().GetAwaiter().GetResult();
|
saveVm.Save();
|
||||||
Assert.IsFalse(database.IsOpen);
|
Assert.IsFalse(database.IsOpen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ namespace ModernKeePassApp.Test
|
|||||||
public void TestEntryVm()
|
public void TestEntryVm()
|
||||||
{
|
{
|
||||||
var database = new DatabaseServiceMock();
|
var database = new DatabaseServiceMock();
|
||||||
var entryVm = new EntryVm(new PwEntry(true, true), new GroupVm(), database)
|
var entryVm = new EntryVm(new PwEntry(true, true), new GroupVm(), database, _resource)
|
||||||
{
|
{
|
||||||
Name = "Test",
|
Name = "Test",
|
||||||
UserName = "login",
|
UserName = "login",
|
||||||
|
Reference in New Issue
Block a user