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
|
|
|
|
|
|
|
|
|
namespace Tapeti.Flow.Default
|
|
|
|
|
{
|
|
|
|
|
internal class FlowContext : IDisposable
|
|
|
|
|
{
|
2019-08-15 10:04:03 +00:00
|
|
|
|
public IFlowHandlerContext HandlerContext { get; set; }
|
2017-01-31 11:01:08 +00:00
|
|
|
|
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-10-17 08:34:07 +00:00
|
|
|
|
private bool storeCalled;
|
|
|
|
|
private bool deleteCalled;
|
2017-02-16 22:03:07 +00:00
|
|
|
|
|
|
|
|
|
|
2017-10-17 08:34:07 +00:00
|
|
|
|
public async Task Store()
|
2017-02-16 22:03:07 +00:00
|
|
|
|
{
|
2017-10-17 08:34:07 +00:00
|
|
|
|
storeCalled = true;
|
2017-02-16 22:03:07 +00:00
|
|
|
|
|
2019-08-15 10:04:03 +00:00
|
|
|
|
if (HandlerContext == null) throw new ArgumentNullException(nameof(HandlerContext));
|
2017-02-16 22:03:07 +00:00
|
|
|
|
if (FlowState == null) throw new ArgumentNullException(nameof(FlowState));
|
|
|
|
|
if (FlowStateLock == null) throw new ArgumentNullException(nameof(FlowStateLock));
|
|
|
|
|
|
2019-08-15 10:04:03 +00:00
|
|
|
|
FlowState.Data = Newtonsoft.Json.JsonConvert.SerializeObject(HandlerContext.Controller);
|
2017-02-16 22:03:07 +00:00
|
|
|
|
await FlowStateLock.StoreFlowState(FlowState);
|
2017-10-17 08:34:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Delete()
|
|
|
|
|
{
|
|
|
|
|
deleteCalled = true;
|
2017-02-16 22:03:07 +00:00
|
|
|
|
|
2017-10-17 08:34:07 +00:00
|
|
|
|
if (FlowStateLock != null)
|
|
|
|
|
await FlowStateLock.DeleteFlowState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EnsureStoreOrDeleteIsCalled()
|
|
|
|
|
{
|
|
|
|
|
if (!storeCalled && !deleteCalled)
|
|
|
|
|
throw new InvalidProgramException("Neither Store nor Delete are called for the state of the current flow. FlowID = " + FlowStateLock?.FlowID);
|
2017-02-16 22:03:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-31 11:01:08 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
FlowStateLock?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|