public async Task StoreFlowState(FlowState newFlowState, bool persistent) { if (flowLock == null) { throw new ObjectDisposedException("FlowStateLock"); } // Ensure no one has a direct reference to the protected state in the dictionary newFlowState = newFlowState.Clone(); // Update the lookup dictionary for the ContinuationIDs if (cachedFlowState != null) { foreach (var removedContinuation in cachedFlowState.FlowState.Continuations.Keys.Where(k => !newFlowState.Continuations.ContainsKey(k))) { owner.continuationLookup.TryRemove(removedContinuation, out _); } } foreach (var addedContinuation in newFlowState.Continuations.Where(c => cachedFlowState == null || !cachedFlowState.FlowState.Continuations.ContainsKey(c.Key))) { owner.continuationLookup.TryAdd(addedContinuation.Key, FlowID); } var isNew = cachedFlowState == null; var wasPersistent = cachedFlowState?.IsPersistent ?? false; cachedFlowState = new CachedFlowState(newFlowState, persistent); owner.flowStates[FlowID] = cachedFlowState; if (persistent) { // Storing the flowstate in the underlying repository if (isNew) { var now = DateTime.UtcNow; await owner.repository.CreateState(FlowID, cachedFlowState.FlowState, now); } else { await owner.repository.UpdateState(FlowID, cachedFlowState.FlowState); } } else if (wasPersistent) { // We transitioned from a durable queue to a dynamic queue, // remove the persistent state but keep the in-memory version await owner.repository.DeleteState(FlowID); } }
public async Task StoreFlowState(FlowState newFlowState) { if (flowLock == null) { throw new ObjectDisposedException("FlowStateLock"); } // Ensure no one has a direct reference to the protected state in the dictionary newFlowState = newFlowState.Clone(); // Update the lookup dictionary for the ContinuationIDs if (flowState != null) { foreach (var removedContinuation in flowState.Continuations.Keys.Where(k => !newFlowState.Continuations.ContainsKey(k))) { Guid removedValue; owner.ContinuationLookup.TryRemove(removedContinuation, out removedValue); } } foreach (var addedContinuation in newFlowState.Continuations.Where(c => flowState == null || !flowState.Continuations.ContainsKey(c.Key))) { owner.ContinuationLookup.TryAdd(addedContinuation.Key, flowID); } var isNew = flowState == null; flowState = newFlowState; owner.FlowStates[flowID] = newFlowState; // Storing the flowstate in the underlying repository if (isNew) { var now = DateTime.UtcNow; await owner.repository.CreateState(flowID, flowState, now); } else { await owner.repository.UpdateState(flowID, flowState); } }
public CachedFlowState(FlowState flowState, bool isPersistent) { FlowState = flowState; IsPersistent = isPersistent; }