2015-10-31 07:17:34 +08:00
|
|
|
|
using System.Collections.Generic;
|
2015-02-05 23:29:41 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using Wox.Infrastructure.Storage;
|
2016-01-07 05:34:42 +08:00
|
|
|
|
using Wox.Plugin;
|
2015-02-05 23:29:41 +08:00
|
|
|
|
|
|
|
|
|
namespace Wox.Storage
|
|
|
|
|
{
|
|
|
|
|
public class TopMostRecordStorage : JsonStrorage<TopMostRecordStorage>
|
|
|
|
|
{
|
|
|
|
|
public Dictionary<string, TopMostRecord> records = new Dictionary<string, TopMostRecord>();
|
|
|
|
|
|
2016-01-07 10:31:17 +08:00
|
|
|
|
protected override string FileName { get; } = "TopMostRecords";
|
2015-02-05 23:29:41 +08:00
|
|
|
|
|
2016-01-07 05:34:42 +08:00
|
|
|
|
internal bool IsTopMost(Result result)
|
2015-02-05 23:29:41 +08:00
|
|
|
|
{
|
|
|
|
|
return records.Any(o => o.Value.Title == result.Title
|
|
|
|
|
&& o.Value.SubTitle == result.SubTitle
|
2015-02-07 20:17:49 +08:00
|
|
|
|
&& o.Value.PluginID == result.PluginID
|
|
|
|
|
&& o.Key == result.OriginQuery.RawQuery);
|
2015-02-05 23:29:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 05:34:42 +08:00
|
|
|
|
internal void Remove(Result result)
|
2015-02-05 23:29:41 +08:00
|
|
|
|
{
|
|
|
|
|
if (records.ContainsKey(result.OriginQuery.RawQuery))
|
|
|
|
|
{
|
|
|
|
|
records.Remove(result.OriginQuery.RawQuery);
|
|
|
|
|
Save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 05:34:42 +08:00
|
|
|
|
internal void AddOrUpdate(Result result)
|
2015-02-05 23:29:41 +08:00
|
|
|
|
{
|
|
|
|
|
if (records.ContainsKey(result.OriginQuery.RawQuery))
|
|
|
|
|
{
|
|
|
|
|
records[result.OriginQuery.RawQuery].Title = result.Title;
|
|
|
|
|
records[result.OriginQuery.RawQuery].SubTitle = result.SubTitle;
|
|
|
|
|
records[result.OriginQuery.RawQuery].PluginID = result.PluginID;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
records.Add(result.OriginQuery.RawQuery, new TopMostRecord
|
|
|
|
|
{
|
2016-01-07 10:31:17 +08:00
|
|
|
|
PluginID = result.PluginID,
|
|
|
|
|
Title = result.Title,
|
|
|
|
|
SubTitle = result.SubTitle
|
|
|
|
|
});
|
2015-02-05 23:29:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class TopMostRecord
|
|
|
|
|
{
|
|
|
|
|
public string Title { get; set; }
|
|
|
|
|
public string SubTitle { get; set; }
|
|
|
|
|
public string PluginID { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|