Beispiel #1
0
        public override bool ContinuePipeLineEntry <TA, TB>(
            IValueAndSupplement <TA, TB> pipeInput,
            out PipeBase <TA, TB> wrapInputIntoPipeBase,
            out IPipeOption pipeOption)
        {
            if (pipeInput == null)
            {
                pipeOption            = new PipeOption(null, null);
                wrapInputIntoPipeBase = new None <TA, TB>(pipeOption);
                return(false);
            }
            pipeOption = (IPipeOption)pipeInput;

            if (pipeInput.GetType() == typeof(Option <TA, TB>))
            {
                wrapInputIntoPipeBase = new None <TA, TB>(pipeOption);
                return(false);
            }
            if (pipeInput.GetType() == typeof(SomeException <TA, TB>))
            {
                wrapInputIntoPipeBase = new SomeException <TA, TB>(((SomeException <TA, TB>)pipeInput).ExceptionVal, pipeOption);
                return(false);
            }
            if (pipeInput.GetType() == typeof(Validation <TA, TB>))
            {
                wrapInputIntoPipeBase = new Validation <TA, TB>(new ValueAndSupplement <TA, TB>(pipeInput.Val, pipeInput.SupplementVal), pipeOption, ((Validation <TV, TS>)pipeInput).ValidationRet);
                return(false);
            }

            wrapInputIntoPipeBase = new Some <TA, TB>(new ValueAndSupplement <TA, TB>(pipeInput.Val, pipeInput.SupplementVal), pipeOption);
            return(true);
        }
Beispiel #2
0
        public override bool ContinuePipeLineEntry <TB, TA>(
            IValueAndSupplement <TA, TB> pipeInput,
            out PipeBase <TB, TA> wrapInputIntoPipeBase,
            out IPipeOption pipeOption)
        {
            if (pipeInput == null)
            {
                pipeOption            = PipeOption.PipeOptionNone;
                wrapInputIntoPipeBase = new Validator <TB, TA>(pipeOption, ValidationResult.None, null);
                return(false);
            }

            if (pipeInput.GetType() != typeof(Validator <TA, TB>))
            {
                pipeOption            = PipeOption.PipeOptionNone;
                wrapInputIntoPipeBase = new Validator <TB, TA>(new InvalidCastException(), pipeOption, null);
                return(false);
            }

            pipeOption = (IPipeOption)pipeInput;
            var validatorType = ((Validator <TA, TB>)pipeInput).ValidatorType;

            if (validatorType == ValidationResult.Exception)
            {
                wrapInputIntoPipeBase = new Validator <TB, TA>(((Validator <TA, TB>)pipeInput).ExceptionVal, pipeOption, null);
                return(false);
            }

            wrapInputIntoPipeBase = new Validator <TB, TA>(new ValueAndSupplement <TB, TA>(pipeInput.SupplementVal, pipeInput.Val), pipeOption, ExtractMessages(pipeInput.Val, pipeInput.SupplementVal));
            return(true);
        }
Beispiel #3
0
 internal Validator(Exception ex, IPipeOption pipeOption, List <string> messages)
 {
     ConditionMet        = pipeOption.ConditionIsMet;
     ExtensionInterfaces = pipeOption.Extensions;
     ValidatorType       = ValidationResult.Exception;
     this.ex             = ex;
 }
Beispiel #4
0
 public abstract bool ContinuePipeLineEntry <TA, TB, TC, TD>(
     IValueAndSupplement <TA, TB> pipeInput,
     out PipeBase <TC, TD> wrapInputIntoPipeBaseWhenBreak,
     out IPipeOption pipeOption)
     where TA : new()
     where TB : new()
     where TC : new()
     where TD : new();
Beispiel #5
0
        internal Validator(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption, List <string> messages)
        {
            ConditionMet        = pipeOption.ConditionIsMet;
            ExtensionInterfaces = pipeOption.Extensions;
            ValidatorType       = val == null ? ValidationResult.None : ValidationResult.Some;
            var extractedMessages = messages ?? new List <string>();

            if (extractedMessages.Count > 0)
            {
                this.ValidatorType = ValidationResult.SomeInvalid;
            }

            if (val != null)
            {
                GetValue      = val.Val;
                GetSupplement = val.SupplementVal;
            }
        }
Beispiel #6
0
        protected void ExecuteExtensions(
            IPipeOption pipeOption,
            object val)
        {
            if (val == null)
            {
                return;
            }

            if (pipeOption?.Extensions != null)
            {
                foreach (var ext in pipeOption.Extensions)
                {
                    if (val is IExpose)
                    {
                        ext.PostProcess(val as IExpose);
                    }
                }
                ;
            }
        }
Beispiel #7
0
        public override bool ContinuePipeLineEntry <TA, TB, TC, TD>(
            IValueAndSupplement <TA, TB> pipeInput,
            out PipeBase <TC, TD> wrapInputIntoPipeBaseWhenBreak,
            out IPipeOption pipeOption)
        {
            if (pipeInput == null)
            {
                pipeOption = PipeOption.PipeOptionNone;
                wrapInputIntoPipeBaseWhenBreak = new Validator <TC, TD>(pipeOption, ValidationResult.None, null);
                return(false);
            }

            if (pipeInput.GetType() != typeof(Validator <TA, TB>))
            {
                pipeOption = PipeOption.PipeOptionNone;
                wrapInputIntoPipeBaseWhenBreak = new Validator <TC, TD>(new InvalidCastException(), pipeOption, null);
                return(false);
            }

            pipeOption = (IPipeOption)pipeInput;
            var validatorType = ((Validator <TA, TB>)pipeInput).ValidatorType;

            if (validatorType == ValidationResult.None)
            {
                wrapInputIntoPipeBaseWhenBreak = new Validator <TC, TD>(pipeOption, ValidationResult.None, null);
                return(false);
            }

            if (validatorType == ValidationResult.Exception)
            {
                wrapInputIntoPipeBaseWhenBreak = new Validator <TC, TD>(((Validator <TA, TB>)pipeInput).ExceptionVal, pipeOption, null);
                return(false);
            }

            //Because of the out signature we need to instantiate a wrapInputIntoPipeBase, but it will be ignored because we return true, meaning don't break
            wrapInputIntoPipeBaseWhenBreak = new Validator <TC, TD>(new ValueAndSupplement <TC, TD>(default(TC), default(TD)), pipeOption, new List <string>());
            return(true);
        }
Beispiel #8
0
        public override bool ContinuePipeLineEntry <TA, TB, TC, TD>(
            IValueAndSupplement <TA, TB> pipeInput,
            out PipeBase <TC, TD> wrapInputIntoPipeBaseWhenBreak,
            out IPipeOption pipeOption)
        {
            //Determine pipeBaseWhenContinue
            if (pipeInput == null)
            {
                pipeOption = new PipeOption(null, null);
            }
            else
            {
                pipeOption = (IPipeOption)pipeInput;
            }


            //Determine pipeBaseWhenBreak
            if (pipeInput.GetType() == typeof(Option <TA, TB>))
            {
                wrapInputIntoPipeBaseWhenBreak = new None <TC, TD>(pipeOption);
                return(false);
            }
            if (pipeInput.GetType() == typeof(SomeException <TA, TB>))
            {
                wrapInputIntoPipeBaseWhenBreak = new SomeException <TC, TD>(((SomeException <TA, TB>)pipeInput).ExceptionVal, pipeOption);
                return(false);
            }

            if (pipeInput.GetType() == typeof(Validation <TA, TB>))
            {
                wrapInputIntoPipeBaseWhenBreak = new Validation <TC, TD>(new ValueAndSupplement <TC, TD>(default(TC), default(TD)), pipeOption, ((Validation <TC, TD>)pipeInput).ValidationRet);
                return(false);
            }

            //Because of the out signature we need to instantiate a pipeBaseWhenBreak, but it will be ignored because we return true, meaning don't break
            wrapInputIntoPipeBaseWhenBreak = new Some <TC, TD>(new ValueAndSupplement <TC, TD>(default(TC), default(TD)), pipeOption);
            return(true);
        }
Beispiel #9
0
 public override PipeBase <TV, TS> CreateNone(IPipeOption pipeOption)
 {
     return(new Validator <TV, TS>(pipeOption, ValidationResult.None, null));
 }
Beispiel #10
0
 public override PipeBase <TA, TB> CreateException <TA, TB>(Exception ex, IPipeOption pipeOption)
 {
     return(new Validator <TA, TB>(ex, pipeOption, null));
 }
Beispiel #11
0
        public override PipeBase <TA, TB> WrapPipeLineResult <TA, TB>(TA value, TB supplementedValue, IPipeOption pipeOption)
        {
            if (value == null && supplementedValue == null)
            {
                return(new SomeException <TA, TB>(new InvalidOperationException("Null values for value and supplemented value are not allowed!"), pipeOption));
            }
            if (supplementedValue == null)
            {
                return(new SomeException <TA, TB>(new InvalidOperationException("Null values for supplemented value is not allowed!"), pipeOption));
            }

            try
            {
                ExecuteExtensions(pipeOption, value);
                ExecuteExtensions(pipeOption, supplementedValue);
            }
            catch (Exception ex)
            {
                return(new SomeException <TA, TB>(ex, pipeOption));
            }
            return(new Some <TA, TB>(new ValueAndSupplement <TA, TB>(value, supplementedValue), pipeOption));
        }
Beispiel #12
0
 public override PipeBase <TV, TS> CreateSome(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption)
 {
     return(new Some <TV, TS>(val, pipeOption));
 }
Beispiel #13
0
 public override PipeBase <TV, TS> CreateNone(IPipeOption pipeOption)
 {
     return(new None <TV, TS>(pipeOption));
 }
Beispiel #14
0
 public abstract PipeBase <TV, TS> CreateSome(
     IValueAndSupplement <TV, TS> val,
     IPipeOption pipeOption);
Beispiel #15
0
        public override PipeBase <TA, TB> WrapPipeLineResult <TA, TB>(TA value, TB supplementedValue, IPipeOption pipeOption)
        {
            var msgs = new List <string>();

            if (value == null && supplementedValue == null)
            {
                return(new Validator <TA, TB>(new InvalidOperationException("Null values for value and supplemented value are not allowed!"), pipeOption, new List <string>()));
            }

            if (supplementedValue == null)
            {
                return(new Validator <TA, TB>(new InvalidOperationException("Null values for supplemented value is not allowed!"), pipeOption, new List <string>()));
            }

            try
            {
                ExecuteExtensions(pipeOption, value);
                ExecuteExtensions(pipeOption, supplementedValue);
                msgs = ExtractMessages(value, supplementedValue);
            }
            catch (Exception exExtensions)
            {
                return(new Validator <TA, TB>(exExtensions, pipeOption, ExtractMessages(value, supplementedValue)));
            }

            return(new Validator <TA, TB>(new ValueAndSupplement <TA, TB>(value, supplementedValue), pipeOption, msgs));
        }
Beispiel #16
0
 public Validation(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption, ValidationResult validationResult) : base(pipeOption)
 {
     SomeValAndSupplement = val;
     ValidationRet        = validationResult;
 }
Beispiel #17
0
 public abstract PipeBase <TV, TS> CreateValidation(
     IValueAndSupplement <TV, TS> val,
     IPipeOption pipeOption,
     ValidationResult result);
Beispiel #18
0
 public Some(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption) : base(pipeOption)
 {
     SomeValAndSupplement = val;
 }
Beispiel #19
0
 internal Option(IPipeOption pipeOption)
 {
     ConditionMet        = pipeOption?.ConditionIsMet;
     ExtensionInterfaces = pipeOption?.Extensions;
 }
Beispiel #20
0
 public abstract bool ContinuePipeLineEntry <TB, TA>(
     IValueAndSupplement <TA, TB> pipeInput,
     out PipeBase <TB, TA> wrapInputIntoPipeBase,
     out IPipeOption pipeOption)
     where TA : new()
     where TB : new();
Beispiel #21
0
        public override PipeBase <TV, TS> CreateSome(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption)
        {
            var msgs = ExtractMessages(GetValue, GetSupplement);

            return(new Validator <TV, TS>(val, pipeOption, msgs));
        }
Beispiel #22
0
 public abstract PipeBase <TV, TS> CreateNone(
     IPipeOption pipeOption);
Beispiel #23
0
        public override PipeBase <TV, TS> CreateValidation(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption, System.ComponentModel.DataAnnotations.ValidationResult result)
        {
            var msgs = ExtractMessages(GetValue, GetSupplement);

            return(new Validator <TV, TS>(val, pipeOption, msgs));
        }
Beispiel #24
0
 public override PipeBase <TA, TB> CreateException <TA, TB>(Exception ex, IPipeOption pipeOption)
 {
     return(new SomeException <TA, TB>(ex, pipeOption));
 }
Beispiel #25
0
 public None(IPipeOption pipeOption) : base(pipeOption)
 {
 }
Beispiel #26
0
 public abstract PipeBase <TA, TB> WrapPipeLineResult <TA, TB>(
     TA value,
     TB supplementedValue,
     IPipeOption pipeOption)
     where TA : new()
     where TB : new();
Beispiel #27
0
 internal Validator(IPipeOption pipeOption, ValidationResult type, List <string> messages)
 {
     ConditionMet        = pipeOption.ConditionIsMet;
     ExtensionInterfaces = pipeOption.Extensions;
     ValidatorType       = type;
 }
Beispiel #28
0
 public SomeException(Exception val, IPipeOption pipeOption) : base(pipeOption)
 {
     ExceptionVal = val;
 }
Beispiel #29
0
 public override PipeBase <TV, TS> CreateValidation(IValueAndSupplement <TV, TS> val, IPipeOption pipeOption, ValidationResult result)
 {
     return(new Validation <TV, TS>(val, pipeOption, result));
 }
Beispiel #30
0
 public abstract PipeBase <TA, TB> CreateException <TA, TB>(
     Exception ex,
     IPipeOption pipeOption)
     where TA : new()
     where TB : new();