Exemple #1
0
        public static IValueOf getStrategy(Expression expr)
        {
            IValueOf strategy = ValueOfConst.clone();

            if (expr is MemberExpression)
            {
                MemberExpression member = (MemberExpression)expr;

                if (member.Expression is MemberExpression) // expr là một property trong object
                {
                    strategy = ValueOfObject.clone();
                }
                else if (member.Expression is ConstantExpression) // expr là một biến
                {
                    strategy = ValueOfVariable.clone();
                }
                else
                {
                    strategy = ValueOfDatetime.clone();
                }
            }
            else if (expr is MethodCallExpression) // expr là 1 fuction
            {
                strategy = ValueOfMethod.clone();
            }
            else if (expr is UnaryExpression)
            {
                strategy = ValueOfUnary.clone();
            }
            return(strategy);
        }
Exemple #2
0
 public AlphaBetaSearch(IValueOf <T> valuer, IAlphaBetaOptions maxDepth, ISearchNodeVisitor <T> nodeVisitor)
 {
     _valuer       = valuer;
     _maxDepth     = maxDepth.SearchDepth;
     _depthCounter = new DepthCounterNodeVisitor <T>();
     _nodeVisitor  = _depthCounter.FollowedBy(nodeVisitor);
 }
Exemple #3
0
 public ObservingValueOfDecoration(IValueOf <T> decorated, LogicOf <IValueOf <T> > preObservation,
                                   LogicOf <IValueOf <T> > postObservation)
     : base(decorated)
 {
     this.PostObservation = postObservation;
     this.PreObservation  = preObservation;
 }
Exemple #4
0
        /// <summary>
        /// builds up the arg as a ValueOf with a bunch of adjustments and observers
        /// </summary>
        private void BuildArgDecoration()
        {
            this.Logger.Do((x) => x.LogVerbose("BuildArgDecoration started", null));
            var intercepts = this.Layers;

            //decorate the argument
            IValueOf <TArg> argOf = null;

            if (this.Arg != null)
            {
                argOf = this.Arg.AsNaturalValue();

                //decorate the adjustments
                intercepts.WithEach((intercept) =>
                {
                    if (intercept.ArgDecorator != null)
                    {
                        argOf = argOf.Adjust(intercept.ArgDecorator);
                    }
                });
                //decorate the observations
                intercepts.WithEach((intercept) =>
                {
                    if (intercept.ArgValidator != null)
                    {
                        argOf = argOf.Observe(null, LogicOf <IValueOf <TArg> > .New((x) =>
                        {
                            intercept.ArgValidator.Perform(argOf);
                        }));
                    }
                });
                this.DecoratedArg = argOf;
            }
            this.Logger.Do((x) => x.LogVerbose("BuildArgDecoration completed", null));
        }
Exemple #5
0
 public PolyfacingValueOfDecoration(IValueOf <T> decorated, Polyface rootFace = null)
     : base(decorated)
 {
     //if no polyface is set we create new one
     this.RootFace = (rootFace == null) ? Polyface.New() : rootFace;
     //register the face
     this.RootFace.Is(typeof(Tface), this);
 }
Exemple #6
0
 private StrategizedTaskOf(string id, IValueOf <T> context, ILogicOf <T> performLogic, ILogicOf <T> cancelLogic = null)
     : base(id)
 {
     Condition.Requires(performLogic).IsNotNull();
     this.PerformLogic = performLogic;
     this.CancelLogic  = cancelLogic;
     this.Context      = context;
 }
        public override IDecorationOf <IValueOf <T> > ApplyThisDecorationTo(IValueOf <T> thing)
        {
            var returnValue = new PollingValueOfDecoration <T>(thing);

            if (this.BackgroundHost != null)
            {
                returnValue.SetBackgroundAction(this.BackgroundStrategy, this.BackgroundHost.BackgroundIntervalMSecs);
            }
            return(returnValue);
        }
Exemple #8
0
        /// <summary>
        /// invokes the arg decorations, then the logic decorations, then invokes the logic
        /// </summary>
        private TResult InvokeDecoratedArgAndLogic()
        {
            this.Logger.Do((x) => x.LogVerbose("InvokeDecoratedArgAndLogic started", null));

            this.Logger.Do((x) => x.LogVerbose("Arg", this.Arg));
            this.ProcessedArg = this.DecoratedArg.GetValue(); //invoke arg decoration chain (adjusters and observers)
            this.Logger.Do((x) => x.LogVerbose("ProcessedArg", this.ProcessedArg));

            ILogicOf <TArg> logicOf      = (ILogicOf <TArg>) this.DecoratedLogic;
            var             logicResults = logicOf.Perform(this.ProcessedArg) as LogicOfTo <TArg, TResult>;

            this.Logger.Do((x) => x.LogVerbose("Logic performed", null));
            this.Result = logicResults.Result;
            this.Logger.Do((x) => x.LogVerbose("Result", this.Result));

            //decorate the result
            this.Logger.Do((x) => x.LogVerbose("Decorate result started", null));
            var intercepts = this.Layers;

            if (this.Result != null)
            {
                IValueOf <TResult> resultOf = this.Result.AsNaturalValue();

                //decorate the adjustments
                intercepts.WithEach((intercept) =>
                {
                    if (intercept.ResultDecorator != null)
                    {
                        resultOf = resultOf.Adjust(intercept.ResultDecorator);
                    }
                });
                //decorate the observations
                intercepts.WithEach((intercept) =>
                {
                    if (intercept.ResultValidator != null)
                    {
                        resultOf = resultOf.Observe(null, LogicOf <IValueOf <TResult> > .New((x) =>
                        {
                            intercept.ResultValidator.Perform(resultOf);
                        }));
                    }
                });
                this.Logger.Do((x) => x.LogVerbose("Decorate result completed", null));

                this.DecoratedResult = resultOf;
                this.ProcessedResult = resultOf.GetValue(); //invoke the decorations

                this.Logger.Do((x) => x.LogVerbose("ProcessedResult", this.ProcessedResult));
            }

            return(this.ProcessedResult);
        }
Exemple #9
0
        public static StrategizedTaskOf <Targ> New <Targ>(string id, IValueOf <Targ> context, ILogicOf <Targ> performLogic, ILogicOf <Targ> cancelLogic = null)
        {
            var rv = new StrategizedTaskOf <Targ>(id, context, performLogic, cancelLogic);

            ////now some fancy stuff...
            ////if the context is IConditionalValueOf<T>, it means there's a condition that prevents the getting of the context value
            ////apply a conditional constraint to the task's Perform indicating this condition must be true
            //if (context is IConditionalValueOf<Targ>)
            //{
            //    IConditionalValueOf<Targ> cContext = context as IConditionalValueOf<Targ>;
            //    var rTask = rv.ANDPerformCondition(cContext.CheckCondition);
            //    return rTask;
            //}

            return(rv);
        }
Exemple #10
0
        /// <summary>
        /// decorates with polyfacingness if it's not already there
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="valueOf"></param>
        /// <param name="rootFace"></param>
        /// <returns></returns>
        public static PolyfacingValueOfDecoration <T, Tface> Polyfacing <T, Tface>(this IValueOf <T> decorated, Polyface rootFace = null)
            where Tface : IValueOf <T>
        {
            Condition.Requires(decorated).IsNotNull();

            PolyfacingValueOfDecoration <T, Tface> rv = null;

            //if we have polyface in our chain, we return that
            if (decorated.HasDecoration <PolyfacingValueOfDecoration <T, Tface> >())
            {
                rv = decorated.As <PolyfacingValueOfDecoration <T, Tface> >();
            }
            else
            {
                rv = new PolyfacingValueOfDecoration <T, Tface>(decorated, rootFace);
            }

            return(rv);
        }
Exemple #11
0
        public override IDecorationOf <IValueOf <T> > ApplyThisDecorationTo(IValueOf <T> thing)
        {
            this.Logger.LogVerbose("ApplyThisDecorationTo started", thing);

            IDecorationOf <IValueOf <T> > rv = null;

            try
            {
                rv = new LoggingValueOfDecoration <T>(thing, this.Logger);
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ex.Message, null, ex);
                throw;
            }
            finally
            {
                this.Logger.LogVerbose("ApplyThisDecorationTo completed", null);
            }

            return(rv);
        }
Exemple #12
0
 public override IDecorationOf <IValueOf <T> > ApplyThisDecorationTo(IValueOf <T> thing)
 {
     return(new PolyfacingValueOfDecoration <T, Tface>(thing, this.RootFace));
 }
Exemple #13
0
 public static PolyfacingValueOfDecoration <T, Tface> New(IValueOf <T> decorated, Polyface rootFace = null)
 {
     return(new PolyfacingValueOfDecoration <T, Tface>(decorated, rootFace));
 }
Exemple #14
0
 public DecoratedValueOfBase(IValueOf <T> decorated)
     : base(decorated)
 {
 }
 public static ThrottlingValueOfDecoration <T> Throttle <T>(this IValueOf <T> decorated, int maxConcurrency)
 {
     Condition.Requires(decorated).IsNotNull();
     return(new ThrottlingValueOfDecoration <T>(decorated, maxConcurrency));
 }
Exemple #16
0
 public static ExpiringValueOfDecoration <T> HasExpirable <T>(this IValueOf <T> decorated, IExpirable expirable)
 {
     Condition.Requires(decorated).IsNotNull();
     return(new ExpiringValueOfDecoration <T>(decorated, expirable));
 }
Exemple #17
0
 public static ErrorCatchingValueOfDecoration <T> Traps <T>(this IValueOf <T> decorated)
 {
     return(new ErrorCatchingValueOfDecoration <T>(decorated));
 }
 public static EventingValueOfDecoration <T> Eventing <T>(this IValueOf <T> decorated)
 {
     return(new EventingValueOfDecoration <T>(decorated));
 }
 public override IDecorationOf <IValueOf <T> > ApplyThisDecorationTo(IValueOf <T> thing)
 {
     return(new CountingValueOfDecoration <T>(thing));
 }
 public static ConditionalWaitingValueOfDecoration <T> WaitUntil <T>(this IValueOf <T> decorated, ICondition Condition, ICondition stopWaitingCondition)
 {
     return(new ConditionalWaitingValueOfDecoration <T>(decorated, Condition, stopWaitingCondition));
 }
 public override IDecorationOf <IValueOf <T> > ApplyThisDecorationTo(IValueOf <T> thing)
 {
     return(new ConditionalWaitingValueOfDecoration <T>(thing, this.Waiter.Condition, this.Waiter.StopWaitingCondition));
 }
 public ConditionalWaitingValueOfDecoration(IValueOf <T> decorated, ICondition Condition, ICondition stopWaitingCondition = null)
     : base(decorated)
 {
     this.Waiter = new ConditionalWaiter(Condition, stopWaitingCondition);
 }
Exemple #23
0
 public static ExpiringValueOfDecoration <T> HasExpirable <T>(this IValueOf <T> decorated)
 {
     Condition.Requires(decorated).IsNotNull();
     return(new ExpiringValueOfDecoration <T>(decorated, NaturalFalseExpirable.New()));
 }
 public ThrottlingValueOfDecoration(IValueOf <T> decorated, int maxConcurrency)
     : base(decorated)
 {
     this.Throttle = new NaturalThrottle(maxConcurrency);
 }
Exemple #25
0
 public ErrorCatchingValueOfDecoration(IValueOf <T> decorated)
     : base(decorated)
 {
 }
 public override IDecorationOf <IValueOf <T> > ApplyThisDecorationTo(IValueOf <T> thing)
 {
     return(new ThrottlingValueOfDecoration <T>(thing, this.Throttle.ConcurrencyLimit));
 }
 public CountingValueOfDecoration(IValueOf <T> decorated)
     : base(decorated)
 {
     Counter = new Counter();
 }
Exemple #28
0
 public override IDecorationOf <IValueOf <T> > ApplyThisDecorationTo(IValueOf <T> thing)
 {
     return(new ExpiringValueOfDecoration <T>(thing, this.Expirable));
 }
 /// <summary>
 /// Adds a Counter to track number of times evaluation has been invoked
 /// </summary>
 public static CountingValueOfDecoration <T> Counted <T>(this IValueOf <T> decorated)
 {
     return(new CountingValueOfDecoration <T>(decorated));
 }
 public EventingValueOfDecoration(IValueOf <T> decorated)
     : base(decorated)
 {
 }