Example #1
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);
        }