Example #1
0
        private IEnumerable <DynamicStorageLookupResult <TKey, List <TKey>, TEntry> > LookupDynamicStorages(IEnumerable <TKey> ids, DateTime from, DateTime to)
        {
            var result = new Dictionary <StorageSelection <TKey, TEntry, IDynamicStorage <TKey, TEntry> >, DynamicStorageLookupResult <TKey, List <TKey>, TEntry> >();

            foreach (var id in ids)
            {
                var storages = _dynamicStorageSelector.GetStorage(id, from, to);
                foreach (var storage in storages)
                {
                    DynamicStorageLookupResult <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 DynamicStorageLookupResult <TKey, List <TKey>, TEntry>(storage.Storage, from, to);
                        existingStorage.Lookups = new List <TKey>();
                        result.Add(storage, existingStorage);
                    }

                    existingStorage.Lookups.Add(id);
                }
            }

            return(result.Values);
        }
Example #2
0
        private IEnumerable <DynamicStorageLookupResult <TKey, List <Serie <TKey, TEntry> >, TEntry> > LookupDynamicStorages(IEnumerable <ISerie <TKey, TEntry> > series)
        {
            var fr = new Dictionary <StorageKey <TKey, TEntry>, DynamicStorageLookupResult <TKey, Serie <TKey, TEntry>, TEntry> >();

            foreach (var serie in series)
            {
                var key = serie.GetKey();
                foreach (var entry in serie.GetEntries())
                {
                    var storage    = _dynamicStorageSelector.GetStorage(key, entry);
                    var storageKey = new StorageKey <TKey, TEntry>(key, storage);

                    DynamicStorageLookupResult <TKey, Serie <TKey, TEntry>, TEntry> existingStorage;
                    if (!fr.TryGetValue(storageKey, out existingStorage))
                    {
                        existingStorage         = new DynamicStorageLookupResult <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>, DynamicStorageLookupResult <TKey, List <Serie <TKey, TEntry> >, TEntry> >();
            DynamicStorageLookupResult <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 DynamicStorageLookupResult <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);
        }
Example #3
0
        private IEnumerable <DynamicStorageLookupResult <TKey, List <TKey>, TEntry> > LookupDynamicStorages(IEnumerable <TKey> ids)
        {
            var result = new Dictionary <StorageSelection <TKey, TEntry, IDynamicStorage <TKey, TEntry> >, DynamicStorageLookupResult <TKey, List <TKey>, TEntry> >();

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

                    existingStorage.Lookups.Add(id);
                }
            }

            return(result.Values);
        }