Exemplo n.º 1
0
        public Snapshot RetrieveSnapshot(SnapshotLocation location)
        {
            if (string.IsNullOrEmpty(location.PotName))
            {
                throw new Exception("Pot name was not provided.");
            }

            if (location.SnapshotIndex.HasValue)
            {
                return(snapshotRepository.GetByIndex(location.PotName, location.SnapshotIndex.Value));
            }

            if (location.SnapshotDate.HasValue)
            {
                DateTime searchedDate = location.SnapshotDate.Value;

                Snapshot snapshot = snapshotRepository.GetByExactDateTime(location.PotName, searchedDate);

                if (snapshot == null && searchedDate.TimeOfDay == TimeSpan.Zero)
                {
                    List <Snapshot> snapshots = snapshotRepository.GetByDate(location.PotName, searchedDate)
                                                .ToList();

                    if (snapshots.Count == 1)
                    {
                        snapshot = snapshots[0];
                    }
                    else if (snapshots.Count > 1)
                    {
                        throw new Exception($"There are multiple snapshots that match the specified date. Pot = {location.PotName}; Date = {searchedDate}");
                    }
                }

                return(snapshot);
            }

            return(snapshotRepository.GetLast(location.PotName));
        }
Exemplo n.º 2
0
        private static Snapshot GetSnapshot(this ISnapshotRepository snapshotRepository, SnapshotLocation snapshotLocation)
        {
            if (string.IsNullOrEmpty(snapshotLocation.PotName))
            {
                return(null);
            }

            if (snapshotLocation.SnapshotIndex.HasValue)
            {
                return(snapshotRepository.GetByIndex(snapshotLocation.PotName, snapshotLocation.SnapshotIndex.Value));
            }

            if (!snapshotLocation.SnapshotDate.HasValue)
            {
                return(snapshotRepository.GetLast(snapshotLocation.PotName));
            }

            DateTime searchedDate = snapshotLocation.SnapshotDate.Value;

            Snapshot snapshot = snapshotRepository.GetByExactDateTime(snapshotLocation.PotName, searchedDate);

            if (snapshot == null && searchedDate.TimeOfDay == TimeSpan.Zero)
            {
                List <Snapshot> snapshots = snapshotRepository.GetByDate(snapshotLocation.PotName, searchedDate)
                                            .ToList();

                if (snapshots.Count == 1)
                {
                    snapshot = snapshots[0];
                }
                else if (snapshots.Count > 1)
                {
                    throw new Exception($"There are multiple snapshots that match the specified date. Pot = {snapshotLocation.PotName}; Date = {searchedDate}");
                }
            }

            return(snapshot);
        }