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
|
|
|
|
|
{
|
2019-08-13 18:30:04 +00:00
|
|
|
|
public IControllerMessageContext MessageContext { 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
|
|
|
|
|
|
|
|
|
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);
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|