Esempio n. 1
0
        public TisValidationsResult FilterBy(TisValidationsResultFilter filter)
        {
            TisValidationsResult finalValidationsResult = new TisValidationsResult();

            foreach (KeyValuePair <TisValidationMethod, TisValidationMethodResult> kpv in this)
            {
                if (filter.Accepts(kpv.Key, kpv.Value))
                {
                    finalValidationsResult.Add(kpv.Key, kpv.Value);
                }
            }

            return(finalValidationsResult);
        }
Esempio n. 2
0
        public ValidationStatus Validate(
            ITisValidationProvider validationsProvider,
            TisValidationsSource validationsSource,
            object validationsTarget,
            TisValidationPolicy validationPolicy,
            TisValidationsResult validationsResult)
        {
            if (validationsSource == null)
            {
                throw new TisException("Validations source does not exist.");
            }

            if (validationsResult == null)
            {
                throw new TisException("Validations result is not allocated.");
            }

            ParallelCall parallelCall = new ParallelCall();

            List <TisValidationMethod> supportedValidations =
                GetSupportedValidations(validationsProvider);

            parallelCall.ThreadsToUse = supportedValidations.Count;

            TisValidationMethodResult  validationMethodResult;
            List <TisValidationMethod> performedValidations = new List <TisValidationMethod>();

            List <ITisValidationContext> validationContexts =
                m_validationContextMngr.GetValidationContextsByType(validationsSource.ValidationType);

            foreach (TisValidationMethod supportedValidation in supportedValidations)
            {
                if (IsValidationConfirmed(supportedValidation, validationContexts))
                {
                    if (validationPolicy.RunPolicy == ValidationRunPolicy.Sync)
                    {
                        validationMethodResult = ExecuteValidationMethod(
                            supportedValidation,
                            validationsSource.Source,
                            validationsTarget,
                            validationContexts);

                        validationsResult.Add(supportedValidation, validationMethodResult);

                        if (ShouldStopValidation(
                                validationMethodResult.Status,
                                validationPolicy.StopPolicy,
                                validationPolicy.ResultPolicy))
                        {
                            break;
                        }
                    }
                    else
                    {
                        performedValidations.Add(supportedValidation);

                        parallelCall.Add(
                            new ExecuteValidationMethodDelegate(ExecuteValidationMethod),
                            new object[] { supportedValidation,
                                           validationsSource.Source,
                                           validationsTarget,
                                           validationContexts });
                    }
                }
                else
                {
                    parallelCall.ThreadsToUse--;
                }
            }

            if (validationPolicy.RunPolicy == ValidationRunPolicy.Async)
            {
                object[] asyncValidationResults = parallelCall.Perform(true);

                for (int i = 0; i < performedValidations.Count; i++)
                {
                    validationsResult.Add(performedValidations[i], (TisValidationMethodResult)asyncValidationResults[i]);
                }
            }

            return(TisValidationsResult.GetFinalValidationStatus(
                       validationsResult,
                       validationPolicy.ResultPolicy));
        }