コード例 #1
0
        private async Task EnumerateRemindersAsync(
            IReliableDictionary <string, byte[]> reminderDictionary,
            Dictionary <string, ReminderCompletedData> reminderCompletedDataDict,
            ActorReminderCollection reminderCollection,
            CancellationToken cancellationToken)
        {
            using (var tx = this.stateManager.CreateTransaction())
            {
                var enumerable = await reminderDictionary.CreateEnumerableAsync(tx);

                var enumerator = enumerable.GetAsyncEnumerator();

                while (await enumerator.MoveNextAsync(cancellationToken))
                {
                    var data = enumerator.Current.Value;

                    if (data == null)
                    {
                        continue;
                    }

                    var reminderData = ActorReminderDataSerializer.Deserialize(data);
                    var key          = CreateStorageKey(reminderData.ActorId, reminderData.Name);

                    ReminderCompletedData reminderCompletedData;
                    reminderCompletedDataDict.TryGetValue(key, out reminderCompletedData);

                    reminderCollection.Add(
                        reminderData.ActorId,
                        new ActorReminderState(reminderData, this.logicalTimeManager.CurrentLogicalTime, reminderCompletedData));
                }
            }
        }
        Task <IActorReminderCollection> IActorStateProvider.LoadRemindersAsync(CancellationToken cancellationToken)
        {
            var reminderCollection = new ActorReminderCollection();

            foreach (var kvPair in this.stateDictionary)
            {
                if (kvPair.Key.StartsWith(ReminderKeyPrefix))
                {
                    var reminderData = kvPair.Value as ActorReminderData;
                    reminderCollection.Add(reminderData.ActorId, new ActorReminderState(reminderData, TimeSpan.Zero, null));
                }
            }

            return(Task.FromResult((IActorReminderCollection)reminderCollection));
        }
コード例 #3
0
        private async Task <IActorReminderCollection> EnumerateRemindersAsync(CancellationToken cancellationToken)
        {
            var reminderCollection        = new ActorReminderCollection();
            var reminderCompletedDataDict = await this.GetReminderCompletedDataMapAsync(cancellationToken);

            var enumTasks = new List <Task>();

            foreach (var reminderDict in this.reminderDictionaries)
            {
                var tsk = this.EnumerateRemindersAsync(
                    reminderDict, reminderCompletedDataDict, reminderCollection, cancellationToken);

                enumTasks.Add(tsk);
            }

            await Task.WhenAll(enumTasks);

            return(reminderCollection);
        }