示例#1
0
        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);
        }
示例#2
0
        public DiskPathCollection Get(string potName)
        {
            PotDirectory potDirectory = PotDirectory.FromPotName(potName);

            if (!potDirectory.IsValid)
            {
                throw new Exception($"There is no pot with name '{potName}'.");
            }

            BlackListFile blackListFile = potDirectory.OpenBlackListFile("bl");

            return(new DiskPathCollection(blackListFile.Items));
        }
示例#3
0
        public void Delete(string name)
        {
            PotDirectory potDirectory = PotDirectory.FromPotName(name);

            if (potDirectory.IsValid)
            {
                potDirectory.Delete();
            }
            else
            {
                throw new Exception($"Pot '{name}' does not exist.");
            }
        }
示例#4
0
        public ISnapshotWriter CreateWriter(string potName)
        {
            PotDirectory potDirectory = PotDirectory.FromPotName(potName);

            if (!potDirectory.IsValid)
            {
                throw new Exception($"There is no pot with name '{potName}'.");
            }

            SnapshotFile    snapshotFile    = potDirectory.CreateSnapshotFile(DateTime.UtcNow);
            JSnapshotWriter jSnapshotWriter = snapshotFile.OpenWriter();

            return(new JsonSnapshotWriter(jSnapshotWriter));
        }
示例#5
0
        public void Delete(string potName, DiskPath path)
        {
            PotDirectory potDirectory = PotDirectory.FromPotName(potName);

            if (!potDirectory.IsValid)
            {
                throw new Exception($"There is no pot with name '{potName}'.");
            }

            BlackListFile blackListFile = potDirectory.OpenBlackListFile("bl");

            blackListFile.Remove(path);
            blackListFile.Save();
        }
示例#6
0
        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();
        }
示例#7
0
        public void Add(string potName, Snapshot snapshot)
        {
            PotDirectory potDirectory = PotDirectory.FromPotName(potName);

            if (!potDirectory.IsValid)
            {
                throw new Exception($"There is no pot with name '{potName}'.");
            }

            SnapshotFile snapshotFile = potDirectory.CreateSnapshotFile(snapshot.CreationTime);

            snapshotFile.Open();
            snapshotFile.Snapshot = snapshot.ToJSnapshot();
            snapshotFile.Save();
        }
示例#8
0
        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());
            }
        }
示例#9
0
        public void Add(Pot pot)
        {
            PotDirectory potDirectory = PotDirectory.FromPotName(pot.Name);

            potDirectory.Create();

            JPotInfoFile jPotInfoFile = potDirectory.GetInfoFile();

            jPotInfoFile.JPotInfo = new JPotInfo
            {
                Name        = pot.Name,
                Path        = pot.Path,
                Description = pot.Description
            };

            jPotInfoFile.Save();
        }
示例#10
0
        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());
            }
        }
示例#11
0
        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);
        }
示例#12
0
        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());
        }
示例#13
0
        private static Pot ToPot(PotDirectory potDirectory)
        {
            if (!potDirectory.IsValid)
            {
                return(null);
            }

            JPotInfoFile jPotInfoFile = potDirectory.GetInfoFile();
            bool         success      = jPotInfoFile.TryOpen();

            if (!success)
            {
                return(null);
            }

            return(new Pot
            {
                Guid = potDirectory.PotGuid,
                Name = jPotInfoFile.JPotInfo.Name,
                Path = jPotInfoFile.JPotInfo.Path,
                Description = jPotInfoFile.JPotInfo.Description
            });
        }
示例#14
0
        public bool Exists(string name)
        {
            PotDirectory potDirectory = PotDirectory.FromPotName(name);

            return(potDirectory.IsValid);
        }
示例#15
0
        public Pot Get(string name)
        {
            PotDirectory potDirectory = PotDirectory.FromPotName(name);

            return(ToPot(potDirectory));
        }