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 * Fixing message format for exception * Changing test structure. Need to add unit tests. * Updating packagerepository comment based on pr feedback * Fixing potential race condition in ListRepository. Now internally implemented as a concurrent dictionary. * Removing unecessary implementation of IRepository interface as this is implemented by the base class. * Restoring checks for invalid uwp apps based on PR feedback. This was accidentally removed when moving the initialize outside the constructor. * Fixing comments * Adding newline to end of file for IProgramRepository
This commit is contained in:
committed by
GitHub
parent
12d9d59d85
commit
b1d662a5b1
@@ -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,80 @@
|
||||
using NLog.Filters;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Logger;
|
||||
|
||||
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>
|
||||
{
|
||||
public IList<T> Items { get { return _items.Values.ToList(); } }
|
||||
|
||||
private ConcurrentDictionary<int, T> _items = new ConcurrentDictionary<int, T>();
|
||||
|
||||
public ListRepository()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Set(IList<T> items)
|
||||
{
|
||||
//enforce that internal representation
|
||||
_items = new ConcurrentDictionary<int, T>(items.ToDictionary( i => i.GetHashCode()));
|
||||
}
|
||||
|
||||
public bool Any()
|
||||
{
|
||||
return _items.Any();
|
||||
}
|
||||
|
||||
public void Add(T insertedItem)
|
||||
{
|
||||
if (!_items.TryAdd(insertedItem.GetHashCode(), insertedItem))
|
||||
{
|
||||
Log.Error($"|ListRepository.Add| Item Already Exists <{insertedItem}>");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Remove(T removedItem)
|
||||
{
|
||||
|
||||
if (!_items.TryRemove(removedItem.GetHashCode(), out _))
|
||||
{
|
||||
Log.Error($"|ListRepository.Remove| Item Not Found <{removedItem}>");
|
||||
}
|
||||
}
|
||||
|
||||
public ParallelQuery<T> AsParallel()
|
||||
{
|
||||
return _items.Values.AsParallel();
|
||||
}
|
||||
|
||||
public bool Contains(T item)
|
||||
{
|
||||
return _items.ContainsKey(item.GetHashCode());
|
||||
}
|
||||
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return _items.Values.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