mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Created a Settings Service
Created a Recent Service Created a Resources Service Code refactor Updated tests
This commit is contained in:
45
ModernKeePass/Services/RecentService.cs
Normal file
45
ModernKeePass/Services/RecentService.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using ModernKeePass.Interfaces;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.AccessCache;
|
||||
using ModernKeePass.ViewModels;
|
||||
|
||||
namespace ModernKeePass.Services
|
||||
{
|
||||
public class RecentService : IRecent
|
||||
{
|
||||
private readonly StorageItemMostRecentlyUsedList _mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
|
||||
public int EntryCount => _mru.Entries.Count;
|
||||
|
||||
public ObservableCollection<IRecentItem> GetAllFiles(bool removeIfNonExistant = true)
|
||||
{
|
||||
var result = new ObservableCollection<IRecentItem>();
|
||||
foreach (var entry in _mru.Entries)
|
||||
{
|
||||
try
|
||||
{
|
||||
var file = _mru.GetFileAsync(entry.Token, AccessCacheOptions.SuppressAccessTimeUpdate).GetAwaiter().GetResult();
|
||||
result.Add(new RecentItemVm(entry.Token, entry.Metadata, file));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (removeIfNonExistant) _mru.Remove(entry.Token);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Add(IStorageItem file, string metadata)
|
||||
{
|
||||
_mru.Add(file, metadata);
|
||||
}
|
||||
|
||||
public async Task<IStorageItem> GetFileAsync(string token)
|
||||
{
|
||||
return await _mru.GetFileAsync(token);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user