2017-02-05 23:22:34 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Tapeti.Flow.Default
|
|
|
|
|
{
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents the state stored for active flows.
|
|
|
|
|
/// </summary>
|
2017-02-05 23:22:34 +01:00
|
|
|
|
public class FlowState
|
|
|
|
|
{
|
2022-11-23 09:13:38 +01:00
|
|
|
|
private FlowMetadata? metadata;
|
|
|
|
|
private Dictionary<Guid, ContinuationMetadata>? continuations;
|
2017-02-05 23:22:34 +01:00
|
|
|
|
|
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains metadata about the flow.
|
|
|
|
|
/// </summary>
|
2017-02-05 23:22:34 +01:00
|
|
|
|
public FlowMetadata Metadata
|
|
|
|
|
{
|
2022-11-23 09:13:38 +01:00
|
|
|
|
get => metadata ??= new FlowMetadata(null);
|
2018-12-19 20:50:56 +01:00
|
|
|
|
set => metadata = value;
|
2017-02-05 23:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains the serialized state which is restored when a flow continues.
|
|
|
|
|
/// </summary>
|
2022-11-23 09:13:38 +01:00
|
|
|
|
public string? Data { get; set; }
|
2017-02-05 23:22:34 +01:00
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains metadata about continuations awaiting a response.
|
|
|
|
|
/// </summary>
|
2017-02-05 23:22:34 +01:00
|
|
|
|
public Dictionary<Guid, ContinuationMetadata> Continuations
|
|
|
|
|
{
|
2022-11-22 13:20:47 +01:00
|
|
|
|
get => continuations ??= new Dictionary<Guid, ContinuationMetadata>();
|
2018-12-19 20:50:56 +01:00
|
|
|
|
set => continuations = value;
|
2017-02-05 23:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a deep clone of this FlowState.
|
|
|
|
|
/// </summary>
|
2017-02-05 23:22:34 +01:00
|
|
|
|
public FlowState Clone()
|
|
|
|
|
{
|
2017-10-17 10:34:07 +02:00
|
|
|
|
return new FlowState {
|
2022-11-23 09:13:38 +01:00
|
|
|
|
metadata = metadata?.Clone(),
|
2017-10-17 10:34:07 +02:00
|
|
|
|
Data = Data,
|
|
|
|
|
continuations = continuations?.ToDictionary(kv => kv.Key, kv => kv.Value.Clone())
|
|
|
|
|
};
|
2017-02-05 23:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains metadata about the flow.
|
|
|
|
|
/// </summary>
|
2017-02-05 23:22:34 +01:00
|
|
|
|
public class FlowMetadata
|
|
|
|
|
{
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains information about the expected response for this flow.
|
|
|
|
|
/// </summary>
|
2022-11-23 09:13:38 +01:00
|
|
|
|
public ReplyMetadata? Reply { get; }
|
2017-02-05 23:22:34 +01:00
|
|
|
|
|
|
|
|
|
|
2022-11-23 09:13:38 +01:00
|
|
|
|
/// <inheritdoc cref="FlowMetadata"/>
|
|
|
|
|
public FlowMetadata(ReplyMetadata? reply)
|
|
|
|
|
{
|
|
|
|
|
Reply = reply;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a deep clone of this FlowMetadata.
|
|
|
|
|
/// </summary>
|
2017-02-05 23:22:34 +01:00
|
|
|
|
public FlowMetadata Clone()
|
|
|
|
|
{
|
2022-11-23 09:13:38 +01:00
|
|
|
|
return new FlowMetadata(Reply);
|
2017-02-05 23:22:34 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains information about the expected response for this flow.
|
|
|
|
|
/// </summary>
|
2017-02-05 23:22:34 +01:00
|
|
|
|
public class ReplyMetadata
|
|
|
|
|
{
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The queue to which the response should be sent.
|
|
|
|
|
/// </summary>
|
2022-11-23 09:13:38 +01:00
|
|
|
|
public string? ReplyTo { get; set; }
|
2019-08-14 20:48:40 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The correlation ID included in the original request.
|
|
|
|
|
/// </summary>
|
2022-11-23 09:13:38 +01:00
|
|
|
|
public string? CorrelationId { get; set; }
|
2019-08-14 20:48:40 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The expected response message class.
|
|
|
|
|
/// </summary>
|
2022-11-23 09:13:38 +01:00
|
|
|
|
public string? ResponseTypeName { get; set; }
|
2017-02-05 23:22:34 +01:00
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates whether the response should be sent a mandatory.
|
|
|
|
|
/// False for requests originating from a dynamic queue.
|
|
|
|
|
/// </summary>
|
2019-04-24 18:04:30 +02:00
|
|
|
|
public bool Mandatory { get; set; }
|
|
|
|
|
|
2017-02-05 23:22:34 +01:00
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a deep clone of this ReplyMetadata.
|
|
|
|
|
/// </summary>
|
2017-02-05 23:22:34 +01:00
|
|
|
|
public ReplyMetadata Clone()
|
|
|
|
|
{
|
|
|
|
|
return new ReplyMetadata
|
|
|
|
|
{
|
|
|
|
|
ReplyTo = ReplyTo,
|
|
|
|
|
CorrelationId = CorrelationId,
|
2019-04-24 18:04:30 +02:00
|
|
|
|
ResponseTypeName = ResponseTypeName,
|
|
|
|
|
Mandatory = Mandatory
|
2017-02-05 23:22:34 +01:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Contains metadata about a continuation awaiting a response.
|
|
|
|
|
/// </summary>
|
2017-02-05 23:22:34 +01:00
|
|
|
|
public class ContinuationMetadata
|
|
|
|
|
{
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The name of the method which will handle the response.
|
|
|
|
|
/// </summary>
|
2022-11-23 09:13:38 +01:00
|
|
|
|
public string? MethodName { get; set; }
|
2019-08-14 20:48:40 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The name of the method which is called when all responses have been processed.
|
|
|
|
|
/// </summary>
|
2022-11-23 09:13:38 +01:00
|
|
|
|
public string? ConvergeMethodName { get; set; }
|
2019-08-14 20:48:40 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Determines if the converge method is synchronous or asynchronous.
|
|
|
|
|
/// </summary>
|
2017-02-12 19:04:26 +01:00
|
|
|
|
public bool ConvergeMethodSync { get; set; }
|
2017-02-05 23:22:34 +01:00
|
|
|
|
|
|
|
|
|
|
2019-08-14 20:48:40 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a deep clone of this ContinuationMetadata.
|
|
|
|
|
/// </summary>
|
2017-02-05 23:22:34 +01:00
|
|
|
|
public ContinuationMetadata Clone()
|
|
|
|
|
{
|
|
|
|
|
return new ContinuationMetadata
|
|
|
|
|
{
|
|
|
|
|
MethodName = MethodName,
|
2017-02-12 19:04:26 +01:00
|
|
|
|
ConvergeMethodName = ConvergeMethodName,
|
|
|
|
|
ConvergeMethodSync = ConvergeMethodSync
|
2017-02-05 23:22:34 +01:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|