2017-01-31 11:01:08 +00:00
|
|
|
|
using System;
|
2017-02-16 22:03:07 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-01-31 11:01:08 +00:00
|
|
|
|
using Tapeti.Config;
|
|
|
|
|
|
|
|
|
|
namespace Tapeti.Flow.Default
|
|
|
|
|
{
|
|
|
|
|
internal class FlowContext : IDisposable
|
|
|
|
|
{
|
|
|
|
|
public IMessageContext MessageContext { get; set; }
|
|
|
|
|
public IFlowStateLock FlowStateLock { get; set; }
|
|
|
|
|
public FlowState FlowState { get; set; }
|
|
|
|
|
|
2017-02-05 22:22:34 +00:00
|
|
|
|
public Guid ContinuationID { get; set; }
|
|
|
|
|
public ContinuationMetadata ContinuationMetadata { get; set; }
|
2017-01-31 11:01:08 +00:00
|
|
|
|
|
2017-02-16 22:03:07 +00:00
|
|
|
|
private bool stored;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task EnsureStored()
|
|
|
|
|
{
|
|
|
|
|
if (stored)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (MessageContext == null) throw new ArgumentNullException(nameof(MessageContext));
|
|
|
|
|
if (FlowState == null) throw new ArgumentNullException(nameof(FlowState));
|
|
|
|
|
if (FlowStateLock == null) throw new ArgumentNullException(nameof(FlowStateLock));
|
|
|
|
|
|
|
|
|
|
FlowState.Data = Newtonsoft.Json.JsonConvert.SerializeObject(MessageContext.Controller);
|
|
|
|
|
await FlowStateLock.StoreFlowState(FlowState);
|
|
|
|
|
|
|
|
|
|
stored = true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
FlowStateLock?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|