public bool DeleteSingleByDate(string potName, DateTime dateTime) { PotDirectory potDirectory = PotDirectory.FromPotName(potName); if (!potDirectory.IsValid) { throw new Exception($"There is no pot with name '{potName}'."); } SnapshotFile[] snapshotFiles = potDirectory.GetSnapshotFiles() .Where(x => x.CreationTime.HasValue && x.CreationTime.Value.Date == dateTime.Date) .ToArray(); if (snapshotFiles.Length == 0) { return(false); } if (snapshotFiles.Length > 1) { throw new Exception($"There are multiple snapshots that match the specified date. Pot = {potName}; Date = {dateTime}"); } snapshotFiles.First().Delete(); return(true); }
public void DeleteByIndex(string potName, int index = 0) { PotDirectory potDirectory = PotDirectory.FromPotName(potName); if (!potDirectory.IsValid) { throw new Exception($"There is no pot with name '{potName}'."); } SnapshotFile snapshotFile = potDirectory.GetSnapshotFiles() .Skip(index) .FirstOrDefault(); snapshotFile?.Delete(); }
public IEnumerable <Snapshot> GetByPot(string potName) { PotDirectory potDirectory = PotDirectory.FromPotName(potName); if (!potDirectory.IsValid) { throw new Exception($"There is no pot with name '{potName}'."); } IEnumerable <SnapshotFile> allSnapshotFiles = potDirectory.GetSnapshotFiles(); foreach (SnapshotFile snapshotFile in allSnapshotFiles) { snapshotFile.Open(); yield return(snapshotFile.Snapshot.ToSnapshot()); } }
public IEnumerable <Snapshot> GetByDate(string potName, DateTime dateTime) { PotDirectory potDirectory = PotDirectory.FromPotName(potName); if (!potDirectory.IsValid) { throw new Exception($"There is no pot with name '{potName}'."); } IEnumerable <SnapshotFile> snapshotFiles = potDirectory.GetSnapshotFiles() .Where(x => x.CreationTime.HasValue && x.CreationTime.Value.Date == dateTime.Date); foreach (SnapshotFile snapshotFile in snapshotFiles) { snapshotFile.Open(); yield return(snapshotFile.Snapshot.ToSnapshot()); } }
public bool DeleteByExactDateTime(string potName, DateTime dateTime) { PotDirectory potDirectory = PotDirectory.FromPotName(potName); if (!potDirectory.IsValid) { throw new Exception($"There is no pot with name '{potName}'."); } SnapshotFile snapshotFile = potDirectory.GetSnapshotFiles() .FirstOrDefault(x => x.CreationTime.HasValue && x.CreationTime.Value == dateTime); if (snapshotFile == null) { return(false); } snapshotFile.Delete(); return(true); }
public Snapshot GetByIndex(string potName, int index = 0) { PotDirectory potDirectory = PotDirectory.FromPotName(potName); if (!potDirectory.IsValid) { throw new Exception($"There is no pot with name '{potName}'."); } SnapshotFile snapshotFile = potDirectory.GetSnapshotFiles() .Skip(index) .FirstOrDefault(); if (snapshotFile == null) { return(null); } snapshotFile.Open(); return(snapshotFile.Snapshot.ToSnapshot()); }