コード例 #1
0
        private List <IValidatorRunEntry> RunValidatorInstance(ValidatorInstanceInfo info)
        {
            var             startTime      = DateTime.Now;
            IValidatorProxy validatorProxy = null;

            try
            {
                validatorProxy = _validatorProvider.GetValidatorProxy(info.ValidatorId);
                IValidatorInstance validatorInstance = _validatorProvider.GetValidatorInstance(info.ValidatorId, info.ValidatorInstanceId);

                log.Debug("Validator: {ValidatorId}  Version:  {ValidatorVersion}{NewLine}   Description:  {Description}", validatorProxy.ValidatorId, validatorProxy.Version.ToString(), Environment.NewLine, validatorProxy.Description);
                log.Debug("ValidatorInstance: {Name}  Description: {Description} beginning to validate.", validatorInstance.Name, validatorInstance.Description);

                IValidator               validator = validatorProxy.Create(validatorInstance);
                IValidatorContext        vc        = new ValidatorContext();
                IList <IValidatorResult> results   = validator.Execute(vc);

                var endTime = DateTime.Now;

                log.Debug("ValidatorInstance: {Name} finished validating. Start: {start}  End: {end}", validatorInstance.Name, startTime.ToString(), endTime.ToString());
                log.Debug("ValidatorInstance: {Name} returned {resultCount} results.", validatorInstance.Name, results.Count);

                List <IValidatorRunEntry> runEntries = results.Select(x =>
                                                                      new ValidatorRunEntry(startTime, endTime, x, validator.FilterSequence)
                {
                } as IValidatorRunEntry).ToList();

                return(runEntries);
            }
            catch (Exception ex)
            {
                log.Error(ex, "{ValidatorProxy} execution caused Error: {Message}", validatorProxy.ValidatorId, ex.Message);

                var vr = new ValidatorResult(validatorProxy.ValidatorId, ex.Message, ValidatorResultCode.Error, UnhandledExceptionResultCode);

                var vre = new ValidatorRunEntry(startTime, DateTime.Now, vr);

                return(new List <IValidatorRunEntry>()
                {
                    vre
                });
            }
        }
コード例 #2
0
        private void WarnWhenNoValidatorInstancesFound(IValidatorProxy proxy, int validatorInstanceCount)
        {
            if (validatorInstanceCount == 0)
            {
                var message = string.Format("No validators were found for {0}", proxy.ValidatorId);

                var vr = new ValidatorResult(proxy.ValidatorId, message, ValidatorResultCode.Warning, NoValidatorInstancesFound);

                var vre = new ValidatorRunEntry(DateTime.Now, DateTime.Now, vr, new List <string>()
                {
                    proxy.ValidatorId
                })
                {
                } as IValidatorRunEntry;

                //TODO
                // change error ... throw instead
                //this.SendValidatorResults(new List<IValidatorRunEntry>() { vre });
            }
        }