コード例 #1
0
 /// <summary>
 /// Initializes a new <see cref="DataCaseDefinitionValidator"/>
 /// </summary>
 /// <param name="workflow">The <see cref="WorkflowDefinition"/> the <see cref="DataCaseDefinition"/> to validate belongs to</param>
 /// <param name="state">The <see cref="SwitchStateDefinition"/> the <see cref="DataCaseDefinition"/> to validate belongs to</param>
 public DataCaseDefinitionValidator(WorkflowDefinition workflow, SwitchStateDefinition state)
     : base(workflow, state)
 {
     this.RuleFor(c => c.Condition)
     .NotEmpty()
     .WithErrorCode($"{nameof(DataCaseDefinition)}.{nameof(DataCaseDefinition.Condition)}");
 }
コード例 #2
0
 /// <summary>
 /// Initializes a new <see cref="EventCaseDefinitionValidator"/>
 /// </summary>
 /// <param name="workflow">The <see cref="WorkflowDefinition"/> the <see cref="EventCaseDefinition"/> to validate belongs to</param>
 /// <param name="state">The <see cref="SwitchStateDefinition"/> the <see cref="EventCaseDefinition"/> to validate belongs to</param>
 public EventCaseDefinitionValidator(WorkflowDefinition workflow, SwitchStateDefinition state)
     : base(workflow, state)
 {
     this.RuleFor(c => c.Event)
     .NotEmpty()
     .WithErrorCode($"{nameof(EventCaseDefinition)}.{nameof(EventCaseDefinition.Event)}");
     this.RuleFor(c => c.Event)
     .Must(ReferenceExistingEvent)
     .When(c => !string.IsNullOrWhiteSpace(c.Event))
     .WithErrorCode($"{nameof(EventCaseDefinition)}.{nameof(EventCaseDefinition.Event)}");
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new <see cref="EventCaseDefinitionValidator"/>
 /// </summary>
 /// <param name="workflow">The <see cref="WorkflowDefinition"/> the <see cref="EventCaseDefinition"/> to validate belongs to</param>
 /// <param name="state">The <see cref="SwitchStateDefinition"/> the <see cref="EventCaseDefinition"/> to validate belongs to</param>
 public EventCaseDefinitionValidator(WorkflowDefinition workflow, SwitchStateDefinition state)
     : base(workflow, state)
 {
     this.RuleFor(c => c.Event)
     .NotEmpty()
     .WithErrorCode($"{nameof(EventCaseDefinition)}.{nameof(EventCaseDefinition.Event)}");
     this.RuleFor(c => c.Event)
     .Must(ReferenceExistingEvent)
     .When(c => !string.IsNullOrWhiteSpace(c.Event))
     .WithErrorCode($"{nameof(EventCaseDefinition)}.{nameof(EventCaseDefinition.Event)}")
     .WithMessage(e => $"Failed to find an event definition with the specified name '{e.Event}'");
 }
コード例 #4
0
 /// <summary>
 /// Attempts to get the <see cref="SwitchCaseDefinition"/> with the specified name
 /// </summary>
 /// <param name="state">The <see cref="SwitchStateDefinition"/> to search for the <see cref="SwitchCaseDefinition"/> with the specified name</param>
 /// <param name="caseName">The name of the <see cref="SwitchCaseDefinition"/> to get</param>
 /// <param name="case">The <see cref="SwitchCaseDefinition"/> with the specified name</param>
 /// <returns>A boolean indicating whether or not the <see cref="SwitchCaseDefinition"/> with the specified name could be found</returns>
 public static bool TryGetCase(this SwitchStateDefinition state, string caseName, out SwitchCaseDefinition @case)
 {
     @case = null !;
     try
     {
         @case = state.GetCase(caseName) !;
     }
     catch
     {
         return(false);
     }
     return(@case != null);
 }
コード例 #5
0
 /// <summary>
 /// Attempts to get the <see cref="EventCaseDefinition"/> that applies to the specified event
 /// </summary>
 /// <param name="state">The <see cref="SwitchStateDefinition"/> to search for the specified <see cref="EventCaseDefinition"/></param>
 /// <param name="eventReference">The reference of the event the <see cref="EventCaseDefinition"/> to get applies to</param>
 /// <param name="case">The <see cref="EventCaseDefinition"/> that applies to the specified event</param>
 /// <returns>A boolean indicating whether or not a <see cref="EventCaseDefinition"/> with the specified id could be found</returns>
 public static bool TryGetEventCondition(this SwitchStateDefinition state, string eventReference, out EventCaseDefinition @case)
 {
     @case = null !;
     try
     {
         @case = state.GetEventCondition(eventReference) !;
     }
     catch
     {
         return(false);
     }
     return(@case != null);
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new <see cref="SwitchCaseDefinitionValidator{TCondition}"/>
 /// </summary>
 /// <param name="workflow">The <see cref="WorkflowDefinition"/> the <see cref="SwitchCaseDefinition"/> to validate belongs to</param>
 /// <param name="state">The <see cref="SwitchStateDefinition"/> the <see cref="SwitchCaseDefinition"/> to validate belongs to</param>
 protected SwitchCaseDefinitionValidator(WorkflowDefinition workflow, SwitchStateDefinition state)
 {
     this.Workflow = workflow;
     this.State    = state;
     this.RuleFor(c => c.Transition)
     .NotNull()
     .When(c => c.End == null)
     .WithErrorCode($"{nameof(DataCaseDefinition)}.{nameof(DataCaseDefinition.Transition)}")
     .WithMessage($"One of either '{nameof(DataCaseDefinition.Transition)}' or '{nameof(DataCaseDefinition.End)}' properties must be set");
     this.RuleFor(c => c.End)
     .NotNull()
     .When(c => c.Transition == null)
     .WithErrorCode($"{nameof(DataCaseDefinition)}.{nameof(DataCaseDefinition.End)}")
     .WithMessage($"One of either '{nameof(DataCaseDefinition.Transition)}' or '{nameof(DataCaseDefinition.End)}' properties must be set");
 }
コード例 #7
0
        /// <summary>
        /// Gets the <see cref="SwitchCaseDefinition"/> with the specified name
        /// </summary>
        /// <param name="state">The <see cref="SwitchStateDefinition"/> to search for the <see cref="SwitchCaseDefinition"/> with the specified name</param>
        /// <param name="caseName">The name of the <see cref="SwitchCaseDefinition"/> to get</param>
        /// <returns>The <see cref="SwitchCaseDefinition"/> with the specified name</returns>
        public static SwitchCaseDefinition?GetCase(this SwitchStateDefinition state, string caseName)
        {
            SwitchCaseDefinition @case;

            switch (state.SwitchType)
            {
            case SwitchStateType.Data:
                if (caseName == "default")
                {
                    @case = new DataCaseDefinition()
                    {
                        Name = "default", Transition = state.DefaultCondition.Transition, End = state.DefaultCondition.End
                    }
                }
                ;
                else
                {
                    @case = state.DataConditions.Single(c => c.Name == caseName);
                }
                break;

            case SwitchStateType.Event:
                if (caseName == "default")
                {
                    @case = new EventCaseDefinition()
                    {
                        Name = "default", Transition = state.DefaultCondition.Transition, End = state.DefaultCondition.End
                    }
                }
                ;
                else
                {
                    @case = state.EventConditions.Single(c => c.Name == caseName);
                }
                break;

            default:
                throw new NotSupportedException($"The specified switch state type '{state.SwitchType}' is not supported in this context");
            }
            return(@case);
        }
コード例 #8
0
 /// <summary>
 /// Gets the <see cref="EventCaseDefinition"/> that applies to the specified event
 /// </summary>
 /// <param name="state">The <see cref="SwitchStateDefinition"/> to search for the <see cref="EventCaseDefinition"/> that applies to the specified event</param>
 /// <param name="eventReference">The name of the event the <see cref="EventCaseDefinition"/> to get applies to</param>
 /// <returns>The <see cref="EventCaseDefinition"/> that applies to the specified event</returns>
 public static EventCaseDefinition?GetEventCondition(this SwitchStateDefinition state, string eventReference)
 {
     return(state.EventConditions?.FirstOrDefault(c => c.Event == eventReference));
 }