internal static byte[] Serialize(ActorReminderData reminderData) { var dataSizeInBytes = ComputeSizeInBytes(reminderData); using (var stream = new MemoryStream(dataSizeInBytes)) { using (var writer = new BinaryWriter(stream, DataEncoding)) { writer.Write(CurrentDataVersion); if (reminderData == null) { writer.WriteNullPrefixByte(); } else { writer.WriteNotNullPrefixByte(); writer.Write(reminderData.ActorId); writer.Write(reminderData.Name, DataEncoding); writer.Write(reminderData.DueTime); writer.Write(reminderData.Period); writer.WriteByteArray(reminderData.State); writer.Write(reminderData.LogicalCreationTime); } writer.Flush(); return(stream.GetBuffer()); } } }
Task IActorStateProvider.SaveReminderAsync(ActorId actorId, IActorReminder state, CancellationToken cancellationToken) { var key = CreateReminderStorageKey(actorId, state.Name); var reminderData = new ActorReminderData(actorId, state, TimeSpan.Zero); this.stateDictionary.AddOrUpdate(key, reminderData, (s, o) => reminderData); return(Task.FromResult(true)); }
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); } }
private static int ComputeSizeInBytes(ActorReminderData reminderData) { int size = sizeof(ushort); // Data version size += sizeof(byte); // Null value indicator prefix if (reminderData == null) { return(size); } size += ComputeActorIdSize(reminderData.ActorId); // ActorId. size += ComputeStringSize(reminderData.Name); // Reminder name. size += sizeof(long); // Reminder due time. size += sizeof(long); // Reminder period. size += ComputeByteArraySize(reminderData.State); // Reminder state byte array. size += sizeof(long); // Reminder logical creation time. return(size); }
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); }