コード例 #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));
                }
            }
        }
コード例 #2
0
        async Task IActorStateProvider.SaveReminderAsync(ActorId actorId, IActorReminder reminder, CancellationToken cancellationToken)
        {
            await this.EnsureStateProviderInitializedAsync(cancellationToken);

            var key          = CreateStorageKey(actorId, reminder.Name);
            var reminderData = new ActorReminderData(actorId, reminder, this.logicalTimeManager.CurrentLogicalTime);
            var data         = ActorReminderDataSerializer.Serialize(reminderData);

            await this.stateProviderHelper.ExecuteWithRetriesAsync(
                async() =>
            {
                using (var tx = this.stateManager.CreateTransaction())
                {
                    await this.GetReminderDictionary(actorId).AddOrUpdateAsync(tx, key, data, (rowKey, rowValue) => data);
                    await this.reminderCompletedDictionary.TryRemoveAsync(tx, key);

                    await tx.CommitAsync();
                }
            },
                string.Format("SaveReminderAsync[{0}]", actorId),
                cancellationToken);
        }