Revert "Improving performance of Adding and Removing Packaged Apps" (#4898)

* Revert "Adding newline to end of file for IProgramRepository"

This reverts commit d55cac80bf.

* Revert "Fixing comments"

This reverts commit a1ecdc9bfa.

* Revert "Restoring checks for invalid uwp apps based on PR feedback. This was accidentally removed when moving the initialize outside the constructor."

This reverts commit 0e8c1cb0fd.

* Revert "Removing unecessary implementation of IRepository interface as this is implemented by the base class."

This reverts commit 1c724280f5.

* Revert "Fixing potential race condition in ListRepository.  Now internally implemented as a concurrent dictionary."

This reverts commit 9ff8246a9d.

* Revert "Updating packagerepository comment based on pr feedback"

This reverts commit 2c45956030.

* Revert "Changing test structure.  Need to add unit tests."

This reverts commit 1c267a55d5.

* Revert "Fixing message format for exception"

This reverts commit f60bdc3dd4.

* Revert "Merging in Theme changes and moving win32Tests to Microsoft.Plugin.Program.UnitTests"

This reverts commit 030dfc2370.
This commit is contained in:
ryanbodrug-microsoft
2020-07-09 12:10:48 -07:00
committed by GitHub
parent b13e719ab3
commit 12d9d59d85
18 changed files with 734 additions and 1137 deletions

View File

@@ -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> : IStorage<T>
public class BinaryStorage<T>
{
// This storage helper returns whether or not to delete the binary storage items
private static readonly int BINARY_STORAGE = 0;

View File

@@ -1,16 +0,0 @@
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();
}
}

View File

@@ -1,23 +0,0 @@
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);
}
}

View File

@@ -1,80 +0,0 @@
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();
}
}
}