using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Timeline.Services { public class DataEntry { #pragma warning disable CA1819 // Properties should not return arrays public byte[] Data { get; set; } = default!; #pragma warning restore CA1819 // Properties should not return arrays public DataInfo Info { get; set; } = default!; } public class DataInfo { public DateTime Time { get; set; } public string Type { get; set; } = default!; } /// /// A data manager controling data. /// /// /// All data to be saved will be checked identity. /// Identical data will be saved as one copy and return the same tag. /// Every data has a ref count. When data is saved, ref count increase. /// When data is removed, ref count decease. If ref count is decreased /// to 0, the data entry will be destroyed and no longer occupy space. /// /// Type is just an attached attribute for convenience and not participate /// in identity verification. This should be only used to save blobs but not /// strings. It will be rare for identity blob with different type, I think. /// public interface IDataManager { /// /// Saves the data to a new entry if it does not exist, /// increases its ref count and returns a tag to the entry. /// /// The data. Can't be null. /// The type of the data. Can't be null. /// The tag of the created entry. /// Thrown when or is null. /// Thrown when a saved copy of data already exists but type is different. public Task RetainEntry(byte[] data, string type); /// /// Decrease the the ref count of the entry. /// Remove it if ref count is zero. /// /// The tag of the entry. /// Thrown when is null. /// /// It's no-op if entry with tag does not exist. /// public Task FreeEntry(string tag); /// /// Retrieve the entry with given tag. /// /// The tag of the entry. /// The entry. /// Thrown when is null. /// Thrown when entry with given tag does not exist. public Task GetEntry(string tag); /// /// Retrieve info of the entry with given tag. /// /// The tag of the entry. /// The entry info. /// Thrown when is null. /// Thrown when entry with given tag does not exist. public Task GetEntryInfo(string tag); } }