Пример #1
0
        private IEnumerable <VolumeStorageLookupResult <TKey, List <TKey>, TEntry> > LookupVolumeStorages(IEnumerable <TKey> ids, DateTime from, DateTime to)
        {
            var result = new Dictionary <StorageSelection <TKey, TEntry, IVolumeStorage <TKey, TEntry> >, VolumeStorageLookupResult <TKey, List <TKey>, TEntry> >();

            foreach (var id in ids)
            {
                var storages = _volumeStorageSelector.GetStorage(id, from, to);
                foreach (var storage in storages)
                {
                    VolumeStorageLookupResult <TKey, List <TKey>, TEntry> existingStorage;
                    if (!result.TryGetValue(storage, out existingStorage))
                    {
                        var actualFrom = storage.From ?? from;
                        if (actualFrom < from)
                        {
                            actualFrom = from;
                        }

                        var actualTo = storage.To ?? to;
                        if (actualTo > to)
                        {
                            actualTo = to;
                        }

                        existingStorage         = new VolumeStorageLookupResult <TKey, List <TKey>, TEntry>(storage.Storage, actualFrom, actualTo);
                        existingStorage.Lookups = new List <TKey>();
                        result.Add(storage, existingStorage);
                    }

                    existingStorage.Lookups.Add(id);
                }
            }

            return(result.Values);
        }
Пример #2
0
        private IEnumerable <VolumeStorageLookupResult <TKey, List <Serie <TKey, TEntry> >, TEntry> > LookupVolumeStorages(IEnumerable <ISerie <TKey, TEntry> > series)
        {
            var fr = new Dictionary <StorageKey <TKey, TEntry>, VolumeStorageLookupResult <TKey, Serie <TKey, TEntry>, TEntry> >();

            foreach (var serie in series)
            {
                var key = serie.GetKey();

                foreach (var entry in serie.GetEntries())
                {
                    var storage = _volumeStorageSelector.GetStorage(key, entry);
                    if (storage != null)
                    {
                        var storageKey = new StorageKey <TKey, TEntry>(key, storage);

                        VolumeStorageLookupResult <TKey, Serie <TKey, TEntry>, TEntry> existingStorage;
                        if (!fr.TryGetValue(storageKey, out existingStorage))
                        {
                            existingStorage         = new VolumeStorageLookupResult <TKey, Serie <TKey, TEntry>, TEntry>(storage);
                            existingStorage.Lookups = new Serie <TKey, TEntry>(key);
                            fr.Add(storageKey, existingStorage);
                        }

                        existingStorage.Lookups.Entries.Add(entry);
                    }
                }
            }

            // collect series into groupings of storage
            var sr = new Dictionary <IStorage <TKey, TEntry>, VolumeStorageLookupResult <TKey, List <Serie <TKey, TEntry> >, TEntry> >();
            VolumeStorageLookupResult <TKey, List <Serie <TKey, TEntry> >, TEntry> current = null;

            foreach (var kvp in fr)
            {
                var key = kvp.Key.Storage;
                if (current?.Storage != key && !sr.TryGetValue(key, out current))
                {
                    current         = new VolumeStorageLookupResult <TKey, List <Serie <TKey, TEntry> >, TEntry>(kvp.Value.Storage);
                    current.Lookups = new List <Serie <TKey, TEntry> >();
                    sr.Add(key, current);
                }
                current.Lookups.Add(kvp.Value.Lookups);
            }

            return(sr.Values);
        }
Пример #3
0
        private IEnumerable <VolumeStorageLookupResult <TKey, List <TKey>, TEntry> > LookupVolumeStorages(IEnumerable <TKey> ids)
        {
            var result = new Dictionary <StorageSelection <TKey, TEntry, IVolumeStorage <TKey, TEntry> >, VolumeStorageLookupResult <TKey, List <TKey>, TEntry> >();

            foreach (var id in ids)
            {
                var storages = _volumeStorageSelector.GetStorage(id, null, null);
                foreach (var storage in storages)
                {
                    VolumeStorageLookupResult <TKey, List <TKey>, TEntry> existingStorage;
                    if (!result.TryGetValue(storage, out existingStorage))
                    {
                        existingStorage         = new VolumeStorageLookupResult <TKey, List <TKey>, TEntry>(storage.Storage);
                        existingStorage.Lookups = new List <TKey>();
                        result.Add(storage, existingStorage);
                    }

                    existingStorage.Lookups.Add(id);
                }
            }

            return(result.Values);
        }