using System; using System.Collections.Generic; using System.Linq; namespace Tapeti.Flow.Default { /// /// Represents the state stored for active flows. /// public class FlowState { private FlowMetadata metadata; private Dictionary continuations; /// /// Contains metadata about the flow. /// public FlowMetadata Metadata { get => metadata ?? (metadata = new FlowMetadata()); set => metadata = value; } /// /// Contains the serialized state which is restored when a flow continues. /// public string Data { get; set; } /// /// Contains metadata about continuations awaiting a response. /// public Dictionary Continuations { get => continuations ?? (continuations = new Dictionary()); set => continuations = value; } /// /// Creates a deep clone of this FlowState. /// public FlowState Clone() { return new FlowState { metadata = metadata.Clone(), Data = Data, continuations = continuations?.ToDictionary(kv => kv.Key, kv => kv.Value.Clone()) }; } } /// /// Contains metadata about the flow. /// public class FlowMetadata { /// /// Contains information about the expected response for this flow. /// public ReplyMetadata Reply { get; set; } /// /// Creates a deep clone of this FlowMetadata. /// public FlowMetadata Clone() { return new FlowMetadata { Reply = Reply?.Clone() }; } } /// /// Contains information about the expected response for this flow. /// public class ReplyMetadata { /// /// The queue to which the response should be sent. /// public string ReplyTo { get; set; } /// /// The correlation ID included in the original request. /// public string CorrelationId { get; set; } /// /// The expected response message class. /// public string ResponseTypeName { get; set; } /// /// Indicates whether the response should be sent a mandatory. /// False for requests originating from a dynamic queue. /// public bool Mandatory { get; set; } /// /// Creates a deep clone of this ReplyMetadata. /// public ReplyMetadata Clone() { return new ReplyMetadata { ReplyTo = ReplyTo, CorrelationId = CorrelationId, ResponseTypeName = ResponseTypeName, Mandatory = Mandatory }; } } /// /// Contains metadata about a continuation awaiting a response. /// public class ContinuationMetadata { /// /// The name of the method which will handle the response. /// public string MethodName { get; set; } /// /// The name of the method which is called when all responses have been processed. /// public string ConvergeMethodName { get; set; } /// /// Determines if the converge method is synchronous or asynchronous. /// public bool ConvergeMethodSync { get; set; } /// /// Creates a deep clone of this ContinuationMetadata. /// public ContinuationMetadata Clone() { return new ContinuationMetadata { MethodName = MethodName, ConvergeMethodName = ConvergeMethodName, ConvergeMethodSync = ConvergeMethodSync }; } } }