2018-05-11 00:52:20 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace SharedLibraryCore.Helpers
|
|
|
|
|
{
|
2018-06-05 17:31:36 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This class provides a way to keep track of changes to an entity
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T">Type of entity to keep track of changes to</typeparam>
|
|
|
|
|
public class ChangeTracking<T>
|
2018-05-11 00:52:20 -04:00
|
|
|
|
{
|
2018-06-05 17:31:36 -04:00
|
|
|
|
List<T> Values;
|
2018-05-11 00:52:20 -04:00
|
|
|
|
|
|
|
|
|
public ChangeTracking()
|
|
|
|
|
{
|
2018-06-05 17:31:36 -04:00
|
|
|
|
Values = new List<T>();
|
2018-05-11 00:52:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-05 17:31:36 -04:00
|
|
|
|
public void OnChange(T value)
|
2018-05-11 00:52:20 -04:00
|
|
|
|
{
|
2018-06-05 17:31:36 -04:00
|
|
|
|
// clear the first value when count max count reached
|
2018-05-20 22:35:56 -04:00
|
|
|
|
if (Values.Count > 30)
|
|
|
|
|
Values.RemoveAt(0);
|
2018-06-05 17:31:36 -04:00
|
|
|
|
Values.Add(value);
|
2018-05-11 00:52:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-05 17:31:36 -04:00
|
|
|
|
public List<T> GetChanges() => Values;
|
2018-05-11 00:52:20 -04:00
|
|
|
|
}
|
|
|
|
|
}
|