mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
Merging in Theme changes and moving win32Tests to Microsoft.Plugin.Program.UnitTests
This commit is contained in:
@@ -12,7 +12,7 @@ namespace Wox.Infrastructure.Storage
|
||||
/// Storage object using binary data
|
||||
/// Normally, it has better performance, but not readable
|
||||
/// </summary>
|
||||
public class BinaryStorage<T>
|
||||
public class BinaryStorage<T> : IStorage<T>
|
||||
{
|
||||
// This storage helper returns whether or not to delete the binary storage items
|
||||
private static readonly int BINARY_STORAGE = 0;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wox.Infrastructure.Storage
|
||||
{
|
||||
public interface IRepository<T>
|
||||
{
|
||||
void Add(T insertedItem);
|
||||
void Remove(T removedItem);
|
||||
bool Contains(T item);
|
||||
void Set(IList<T> list);
|
||||
bool Any();
|
||||
}
|
||||
}
|
||||
23
src/modules/launcher/Wox.Infrastructure/Storage/IStorage.cs
Normal file
23
src/modules/launcher/Wox.Infrastructure/Storage/IStorage.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Wox.Infrastructure.Storage
|
||||
{
|
||||
public interface IStorage<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Saves the data
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
void Save(T data);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to load data, otherwise it will return the default provided
|
||||
/// </summary>
|
||||
/// <param name="defaultData"></param>
|
||||
/// <returns>The loaded data or default</returns>
|
||||
T TryLoad(T defaultData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using NLog.Filters;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Wox.Infrastructure;
|
||||
|
||||
namespace Wox.Infrastructure.Storage
|
||||
{
|
||||
/// <summary>
|
||||
/// The intent of this class is to provide a basic subset of 'list' like operations, without exposing callers to the internal representation
|
||||
/// of the data structure. Currently this is implemented as a list for it's simplicity.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class ListRepository<T> : IRepository<T>, IEnumerable<T>
|
||||
{
|
||||
protected IList<T> _items = new List<T>();
|
||||
protected IStorage<IList<T>> _storage;
|
||||
|
||||
public ListRepository(IStorage<IList<T>> storage)
|
||||
{
|
||||
_storage = storage ?? throw new ArgumentNullException("storage", "StorageRepository requires an initialized storage interface");
|
||||
}
|
||||
|
||||
public void Set(IList<T> items)
|
||||
{
|
||||
//enforce that internal representation
|
||||
_items = items.ToList<T>();
|
||||
}
|
||||
|
||||
public bool Any()
|
||||
{
|
||||
return _items.Any();
|
||||
}
|
||||
|
||||
public void Add(T insertedItem)
|
||||
{
|
||||
_items.Add(insertedItem);
|
||||
}
|
||||
|
||||
public void Remove(T removedItem)
|
||||
{
|
||||
_items.Remove(removedItem);
|
||||
}
|
||||
|
||||
public ParallelQuery<T> AsParallel()
|
||||
{
|
||||
return _items.AsParallel();
|
||||
}
|
||||
|
||||
public bool Contains(T item)
|
||||
{
|
||||
return _items.Contains(item);
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return _items.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return _items.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,10 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using static Wox.Infrastructure.StringMatcher;
|
||||
|
||||
[assembly: InternalsVisibleToAttribute("Microsoft.Plugin.Program.UnitTests")]
|
||||
namespace Wox.Infrastructure
|
||||
{
|
||||
public class StringMatcher
|
||||
|
||||
Reference in New Issue
Block a user