internal static byte[] Serialize(ReminderCompletedData reminderCompletedData)
        {
            var dataSizeInBytes = ComputeSizeInBytes(reminderCompletedData);

            using (var stream = new MemoryStream(dataSizeInBytes))
            {
                using (var writer = new BinaryWriter(stream, DataEncoding))
                {
                    writer.Write(CurrentDataVersion);

                    if (reminderCompletedData == null)
                    {
                        writer.WriteNullPrefixByte();
                    }
                    else
                    {
                        writer.WriteNotNullPrefixByte();
                        writer.Write(reminderCompletedData.LogicalTime);
                        writer.Write(reminderCompletedData.UtcTime);
                    }

                    writer.Flush();
                    return(stream.GetBuffer());
                }
            }
        }
        private static int ComputeSizeInBytes(ReminderCompletedData reminderCompletedData)
        {
            int size = sizeof(ushort); // Data version

            size += sizeof(byte);      // Null value indicator prefix

            if (reminderCompletedData != null)
            {
                size += 2 * sizeof(long); // LogicalTime + UtcTime;
            }

            return(size);
        }
Esempio n. 3
0
        async Task IActorStateProvider.ReminderCallbackCompletedAsync(ActorId actorId, IActorReminder reminder, CancellationToken cancellationToken)
        {
            await this.EnsureStateProviderInitializedAsync(cancellationToken);

            var key          = CreateStorageKey(actorId, reminder.Name);
            var reminderData = new ReminderCompletedData(this.logicalTimeManager.CurrentLogicalTime, DateTime.UtcNow);
            var data         = ReminderCompletedDataSerializer.Serialize(reminderData);

            await this.stateProviderHelper.ExecuteWithRetriesAsync(
                async() =>
            {
                using (var tx = this.stateManager.CreateTransaction())
                {
                    await this.reminderCompletedDictionary.AddOrUpdateAsync(tx, key, data, (k, v) => data);
                    await tx.CommitAsync();
                }
            },
                string.Format("ReminderCallbackCompletedAsync[{0}]", actorId),
                cancellationToken);
        }
Esempio n. 4
0
        public ActorReminderState(ActorReminderData reminder, TimeSpan currentLogicalTime, ReminderCompletedData reminderCompletedData)
        {
            this.reminder = reminder;

            if (reminderCompletedData != null)
            {
                this.nextDueTime = ComputeRemainingTime(currentLogicalTime, reminderCompletedData.LogicalTime, reminder.Period);
            }
            else
            {
                this.nextDueTime = ComputeRemainingTime(currentLogicalTime, reminder.LogicalCreationTime, reminder.DueTime);
            }
        }