2015-02-09 19:16:13 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Newtonsoft.Json;
|
2015-11-08 10:50:33 +08:00
|
|
|
|
using Wox.Plugin;
|
2015-02-09 19:16:13 +08:00
|
|
|
|
|
|
|
|
|
namespace Wox.Storage
|
|
|
|
|
{
|
2016-06-24 05:17:47 +08:00
|
|
|
|
public class History
|
2015-02-09 19:16:13 +08:00
|
|
|
|
{
|
2016-06-24 05:17:47 +08:00
|
|
|
|
public List<HistoryItem> Items { get; set; } = new List<HistoryItem>();
|
2015-02-09 19:16:13 +08:00
|
|
|
|
|
2016-06-24 05:17:47 +08:00
|
|
|
|
private int _maxHistory = 300;
|
2015-02-09 19:16:13 +08:00
|
|
|
|
|
|
|
|
|
public void Add(string query)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(query)) return;
|
2016-06-24 05:17:47 +08:00
|
|
|
|
if (Items.Count > _maxHistory)
|
2015-02-09 19:16:13 +08:00
|
|
|
|
{
|
2016-06-24 05:17:47 +08:00
|
|
|
|
Items.RemoveAt(0);
|
2015-02-09 19:16:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-24 05:17:47 +08:00
|
|
|
|
if (Items.Count > 0 && Items.Last().Query == query)
|
2015-02-09 19:16:13 +08:00
|
|
|
|
{
|
2016-06-24 05:17:47 +08:00
|
|
|
|
Items.Last().ExecutedDateTime = DateTime.Now;
|
2015-02-09 19:16:13 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-06-24 05:17:47 +08:00
|
|
|
|
Items.Add(new HistoryItem
|
2015-02-09 19:16:13 +08:00
|
|
|
|
{
|
|
|
|
|
Query = query,
|
|
|
|
|
ExecutedDateTime = DateTime.Now
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|