/* * Process Hacker - * history manager * * Copyright (C) 2009 wj32 * * This file is part of Process Hacker. * * Process Hacker is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Process Hacker is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Process Hacker. If not, see . */ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; namespace ProcessHacker { public class HistoryManager { private Dictionary> _history = new Dictionary>(); private int _maxCount = 400; public int MaxCount { get { return _maxCount; } set { _maxCount = value; } } public ReadOnlyCollection this[TKey key] { get { return GetHistory(key); } } public void Add(TKey key) { _history.Add(key, new List()); } public ReadOnlyCollection GetHistory(TKey key) { return new ReadOnlyCollection(_history[key]); } public void Update(TKey key, TValue value) { _history[key].Insert(0, value); if (_history[key].Count > _maxCount) _history[key].RemoveRange(_history[key].Count - 1, _history[key].Count - _maxCount); } } }