Esempio n. 1
0
        private DequeueMessagesDto RetrieveItems(DeviceListDto devices, Func <IEnumerable <DeviceIdWithOpHint>, DequeueResults> retrieveFunc)
        {
            EnsureSingleDevice(devices.DeviceIds);

            var dequeueHint = DeviceEntryRegistry.Instance.GetDequeueHint(devices.DeviceIds);

            var cacheItems = _messageCache.Get(dequeueHint.ToCacheIndices());

            var deviceIdWithOpHintList = ItemConverters.ToDeviceIdWithOpHint(dequeueHint);

            foreach (var hint in deviceIdWithOpHintList)
            {
                if (hint.Index.HasValue && cacheItems.MissingDevices.Contains(hint.DeviceId))
                {
                    hint.Index = null;
                }
            }

            var dequeueEntries = retrieveFunc(deviceIdWithOpHintList);

            DeviceEntryRegistry.Instance.Merge(dequeueEntries.Messages);
            DeviceEntryRegistry.Instance.Merge(dequeueEntries.UnknownEntries);

            _messageCache.Remove(cacheItems.CacheItems.Keys);

            return(ItemConverters.GetDequeueMessagesDto(dequeueEntries.Messages, cacheItems));
        }
Esempio n. 2
0
        public DeviceListDto Commit(DeviceListDto devices)
        {
            EnsureSingleDevice(devices.DeviceIds);

            var commitHint = DeviceEntryRegistry.Instance.GetCommitHint(devices.DeviceIds);

            var commitEntries = _persistentStorage.Commit(commitHint);

            DeviceEntryRegistry.Instance.Merge(commitEntries);

            return(ItemConverters.ToDeviceList(commitEntries));
        }
Esempio n. 3
0
        public DeviceListDto Enqueue(EnqueueMessagesDto messages)
        {
            EnsureSingleDevice(messages.Messages.Select(m => m.DeviceId));

            var enqueueItems = ItemConverters.ToEnqueueItemList(messages);

            var deviceEntries = _persistentStorage.Enqueue(enqueueItems);

            var cacheItems = ItemConverters.ToCacheItems(deviceEntries, enqueueItems);

            _messageCache.Put(cacheItems);

            DeviceEntryRegistry.Instance.Merge(deviceEntries);

            return(ItemConverters.ToDeviceListDto(deviceEntries));
        }