/// <summary> /// Constructor. /// </summary> /// <param name="factTypes">Fact types.</param> /// <param name="option">FactWork option.</param> protected FactWorkBase(List <IFactType> factTypes, FactWorkOption option) { InputFactTypes = !factTypes.IsNullOrEmpty() ? factTypes.AsReadOnly() : new List <IFactType>(0).AsReadOnly(); Option = option; }
/// <inheritdoc cref="GetFactRule{TFact1, TFact2, TFact3, TFactResult}(Func{TFact1, TFact2, TFact3, TFactResult}, FactWorkOption)"/> protected FactRule GetFactRule <TFactResult>(Func <TFactResult> func, FactWorkOption option = FactWorkOption.CanExecuteSync) where TFactResult : IFact { return(new FactRule( facts => func(), new List <IFactType>(), GetFactType <TFactResult>(), option)); }
/// <inheritdoc/> public FactRule(Func <IEnumerable <IFact>, ValueTask <IFact> > funcAsync, List <IFactType> inputFactTypes, IFactType outputFactType, FactWorkOption option) : base(funcAsync, inputFactTypes, outputFactType, option) { }
/// <inheritdoc/> protected override FactRule CreateFactRule(Func <IEnumerable <IFact>, ValueTask <IFact> > func, List <IFactType> inputFactTypes, IFactType outputFactType, FactWorkOption option) { return(new FactRule(func, inputFactTypes, outputFactType, option)); }
/// <inheritdoc/> public WantAction(Func <IEnumerable <IFact>, ValueTask> wantActionAsync, List <IFactType> factTypes, FactWorkOption option) : base(wantActionAsync, factTypes, option) { }
/// <inheritdoc/> public WantAction(Action <IEnumerable <IFact> > wantAction, List <IFactType> factTypes, FactWorkOption option) : base(wantAction, factTypes, option) { }
/// <summary> /// Constructor. /// </summary> /// <param name="wantActionAsync">Action taken after deriving a fact.</param> /// <param name="factTypes">Facts required to launch an action.</param> /// <param name="option">WantAction options.</param> protected WantActionBase(Func <IEnumerable <IFact>, ValueTask> wantActionAsync, List <IFactType> factTypes, FactWorkOption option) : base(factTypes, option) { _actionAsync = wantActionAsync ?? throw new ArgumentNullException(nameof(wantActionAsync)); Validate(factTypes); }
/// <summary> /// Constructor. /// </summary> /// <param name="wantAction">Action taken after deriving a fact.</param> /// <param name="factTypes">Facts required to launch an action.</param> /// <param name="option">WantAction options.</param> protected WantActionBase(Action <IEnumerable <IFact> > wantAction, List <IFactType> factTypes, FactWorkOption option) : base(factTypes, option) { _action = wantAction ?? throw new ArgumentNullException(nameof(wantAction)); Validate(factTypes); }
/// <summary> /// Constructor. /// </summary> /// <param name="funcAsync">Func for calculate.</param> /// <param name="inputFactTypes">Information on input factacles rules.</param> /// <param name="outputFactType">Information on output fact.</param> /// <param name="option">Options for a rule.</param> /// <exception cref="ArgumentNullException"><paramref name="funcAsync"/> or <paramref name="outputFactType"/> is null.</exception> /// <exception cref="ArgumentException">The fact is requested at the input, which the rule calculates.</exception> protected FactRuleBase(Func <IEnumerable <IFact>, ValueTask <IFact> > funcAsync, List <IFactType> inputFactTypes, IFactType outputFactType, FactWorkOption option) : base(inputFactTypes, option) { _funcAsync = funcAsync ?? throw new ArgumentNullException(nameof(funcAsync)); ValidateParam(inputFactTypes, outputFactType); OutputFactType = outputFactType; }
/// <inheritdoc/> protected override WantAction CreateWantAction(Func <IEnumerable <IFact>, ValueTask> wantAction, List <IFactType> factTypes, FactWorkOption option) { return(new WantAction(wantAction, factTypes, option)); }
protected override Rule CreateFactRule(Func <IEnumerable <IFact>, ValueTask <IFact> > func, List <IFactType> inputFactTypes, IFactType outputFactType, FactWorkOption option) { throw new NotImplementedException(); }
/// <inheritdoc/> public TWantAction CreateWantAction <TWantAction>(Func <IEnumerable <IFact>, ValueTask> wantAction, List <IFactType> factTypes, FactWorkOption option) where TWantAction : IWantAction { var result = new WantAction(wantAction, factTypes, option); if (result is TWantAction converted) { return(converted); } throw CommonHelper.CreateException( ErrorCode.InvalidData, $"The result of the ISingleEntityOperations.CreateWantAction cannot be converted to the type {typeof(TWantAction).Name}."); }
/// <summary> /// Get fact rule. /// </summary> /// <typeparam name="TFact1">Fact rule parametr 1</typeparam> /// <typeparam name="TFact2">Fact rule parametr 2</typeparam> /// <typeparam name="TFact3">Fact rule parametr 3</typeparam> /// <typeparam name="TFactResult">Type result for fact rule</typeparam> /// <param name="func">Func for <typeparamref name="TFactResult"/></param> /// <param name="option">Options for fact rule</param> /// <returns>Fact rule.</returns> protected FactRule GetFactRule <TFact1, TFact2, TFact3, TFactResult>(Func <TFact1, TFact2, TFact3, TFactResult> func, FactWorkOption option = FactWorkOption.CanExecuteSync) where TFact1 : IFact where TFact2 : IFact where TFact3 : IFact where TFactResult : IFact { return(new FactRule( facts => func(facts.GetFact <TFact1>(), facts.GetFact <TFact2>(), facts.GetFact <TFact3>()), new List <IFactType> { GetFactType <TFact1>(), GetFactType <TFact2>(), GetFactType <TFact3>() }, GetFactType <TFactResult>(), option)); }