Ejemplo n.º 1
0
        public async Task <IResponse> CreateCustomer(NewCustomer newCustomer)
        {
            var response = _validationProvider.Validate(newCustomer);

            if (response.IsInvalid)
            {
                return(response.ToResponse());
            }

            var dbContext = _entityFactory.Create();

            var customer = new Customer
            {
                FirstName   = newCustomer.FirstName,
                LastName    = newCustomer.LastName,
                Email       = newCustomer.Email,
                DateOfBirth = newCustomer.DateOfBirth
            };

            dbContext.Customers.Add(customer);

            await dbContext.SaveChangesAsync();

            return(ResponseType.Success);
        }
Ejemplo n.º 2
0
        public void Add(Models.Flag model)
        {
            _validationProvider.Validate(model);

            if (!_validationProvider.HasErrors)
            {
                _repository.Add(model);
            }
        }
Ejemplo n.º 3
0
        public void Add(T model)
        {
            _validationProvider.Validate(model);

            if (!_validationProvider.HasErrors)
            {
                _repository.Add(model);

                LuceneSearch.AddOrUpdateLuceneIndex(model);
            }
        }
Ejemplo n.º 4
0
        public async ValueTask Validate <TCommand>(TCommand command, CancellationToken canclationToken = default) where TCommand : ICommand
        {
            command.NotNull();

            var response = await _validationProvider.Validate(command, canclationToken).ConfigureAwait(false);

            if (!response.IsValid)
            {
                throw new ValidationException(response.Error);
            }
        }
Ejemplo n.º 5
0
 public void CreateUser(UserViewModel user)
 {
     _validationProvider.Validate(user);
     _context.Add(new User()
     {
         Login        = user.Login.Trim(),
         PasswordHash = HashPassword(user.Password),
         Name         = user.Name.Trim(),
         Role         = user.Role,
         ApiKey       = GenerateApiKey()
     });
     _context.SaveChanges();
 }
Ejemplo n.º 6
0
        protected override bool Validate(IValidationTarget <IEnumerable <T> > target)
        {
            foreach (var item in target.Value)
            {
                validation.Validate(target, item);
                if (!target.Continue)
                {
                    return(true);
                }
            }

            return(true);
        }
Ejemplo n.º 7
0
        /// <inheritdoc />
        public void Validate(ICommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var validationResponse = _validationProvider.Validate(command);

            if (!validationResponse.IsValid)
            {
                throw new ValidationException(BuildErrorMessage(validationResponse.Errors));
            }
        }
Ejemplo n.º 8
0
        private IValidationResult Validate(T value)
        {
            if (Find(value.Guid, out var same) && same != value)
            {
                return(new ValidationResult("Duplicate Guid"));
            }

            if (validation != null)
            {
                return(validation.Validate(value));
            }

            return(ValidationResult.Success);
        }
Ejemplo n.º 9
0
        protected override DoNext performInvoke()
        {
            var inputModel   = _request.Get <T>();
            var notification = _provider.Validate(inputModel);

            if (notification.IsValid())
            {
                return(DoNext.Continue);
            }

            _request.Set(notification);
            _failureHandler.Handle(typeof(T));

            return(DoNext.Stop);
        }
Ejemplo n.º 10
0
        public void Add(Models.Comment comment)
        {
            _validationProvider.Validate(comment);

            if (!_validationProvider.HasErrors)
            {
                if (comment.OriginalCommentId.HasValue)
                {
                    var originalComment = _repository.GetAll().BuildComment()
                                          .Single(x => x.Id == comment.OriginalCommentId.Value);

                    originalComment.Replies.Add(comment);
                }

                _repository.Add(comment);
            }
        }
Ejemplo n.º 11
0
        public void Add(Models.Comment comment)
        {
            _validationProvider.Validate(comment);

            if (!_validationProvider.HasErrors)
            {
                if (comment.OriginalComment != null)
                {
                    var originalComment = AllComments.GetValueOrDefault(comment.OriginalComment.Id);

                    comment.OriginalComment = originalComment;
                }

                comment.Audio.Comments.Add(comment);

                AllComments.TryAdd(comment.Id, comment);
                _commentStream.OnNext(comment);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Validates the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <exception cref="ps.dmv.common.Exceptions.BusinessValidationException"></exception>
        protected void Validate(T entity)
        {
            IValidationProvider validator = ServiceLocator.Instance.Resolve <IValidationProvider>();

            ValidationResults validationResults = new ValidationResults();

            ValidationResults validationResultsEntity = validator.Validate(entity);

            validationResults.AddAllResults(validationResultsEntity);

            ValidationResults validationResultsSpecial = ValidateSpecial(entity);

            validationResults.AddAllResults(validationResultsSpecial);

            if (!validationResults.IsValid)
            {
                throw new BusinessValidationException(validationResults);
            }
        }
Ejemplo n.º 13
0
        private ValidationProviderResult ExecuteValidation <T>(T target,
                                                               ValidationCallContext callContext,
                                                               IValidationProvider <T> validator,
                                                               out double duration)
        {
            ValidationProviderResult result = null;

            duration = With.PerformanceCounter(() => {
                result = validator.Validate(target, callContext);
            }) * 1000;
            Logger.DebugFormat("Validator '{0}' executed in '{1}ms'", validator, duration);
            if (PerformanceThresholds.IndividualValidatorInMilliseconds > 0 &&
                PerformanceThresholds.IndividualValidatorInMilliseconds < duration)
            {
                Logger.WarnFormat(
                    "Performance of validator '{0}' exceeds threshold; threshold: '{1}ms', actual: '{2}ms'",
                    validator,
                    PerformanceThresholds.IndividualValidatorInMilliseconds,
                    duration);
            }
            return(result);
        }
Ejemplo n.º 14
0
 public void CreateAlbum(AlbumDto dto)
 {
     //ValidateAlbum(dto);
     _validationProvider.Validate(dto);
 }
Ejemplo n.º 15
0
        private static void ProcessInputFile(string filename, IValidationProvider validationProvider)
        {
            Log.Instance.Info("Processing File {0}", filename);

            var            inputStream = new StreamReader(filename);
            JsonTextReader reader      = new JsonTextReader(inputStream);

            var obj = JToken.ReadFrom(reader);

            var validationResult = validationProvider.Validate(obj);


            Log.Instance.Info("Valid: {0}", validationResult.IsValid);

            if (!validationResult.IsValid)
            {
                validationResult.PrintValidationMessages(Log.Instance);
                return;
            }

            var           contextToken  = obj["context"];
            var           context       = DataReference.CurrentContext();
            ObjectFactory objectFactory = new ObjectFactory();

            foreach (var item in contextToken.Children())
            {
                string type = (string)item["type"];
                string name = (string)item.TryGet("name");

                Console.WriteLine("{0}:{1}", name ?? "<unnamed>", type);

                if (name != null)
                {
                    var contextItem = objectFactory.Create(item);
                    if (contextItem != null)
                    {
                        context[name] = contextItem;
                    }
                }
            }

            var ouputToken = obj["output"];

            IList <IRootOutput> outputs = new List <IRootOutput>();

            foreach (var item in ouputToken)
            {
                string type = (string)item["type"];

                Log.Instance.Trace("{0}:{1}", "output", type);

                var outputItem = (IRootOutput)objectFactory.Create(item);

                outputs.Add(outputItem);
            }

            var toExecute = outputs.ToList();

            if (!toExecute.Any())
            {
                Log.Instance.Warn("No root outputs found. No output will be generated. Choose one of (fileOutput)");
            }
            else
            {
                toExecute.ForEach(p => p.Evaluate());
            }

            inputStream.Dispose();
        }
Ejemplo n.º 16
0
        public async Task <UnifiedOrderResponse> UnifiedOrderAsync(UnifiedOrderRequest order)
        {
            if (order == null)
            {
                throw new ArgumentException("order cannot be null", nameof(order));
            }

            if (order.EmbedTradeType == TradeType.App)
            {
                if ((order.Detail ?? "").Length > 8192)
                {
                    throw new ValidationException("detail field cannot exceed 8192 characters");
                }

                if (order.EmbedDetail != null)
                {
                    foreach (var d in order.EmbedDetail.GoodsDetail)
                    {
                        if (string.IsNullOrEmpty(d.GoodsCategory))
                        {
                            throw new ValidationException("goods_category is required");
                        }
                        if (string.IsNullOrEmpty(d.Body))
                        {
                            throw new ValidationException("body is required");
                        }
                    }
                }
            }

            if (order.EmbedTradeType == TradeType.Jsapi)
            {
                if ((order.Detail ?? "").Length > 6000)
                {
                    throw new ValidationException("detail field cannot exceed 6000 characters");
                }

                if (order.OpenId == null)
                {
                    throw new ValidationException($"{nameof(order.OpenId)}is reqiured");
                }
            }

            if (order.EmbedTradeType == TradeType.Native)
            {
                if ((order.Detail ?? "").Length > 6000)
                {
                    throw new ValidationException("detail field cannot exceed 6000 characters");
                }
            }

            order.Preparing(_paymentContext);

            _signatureService
            .GenNonce(nonce => { order.NonceStr = nonce; })
            .GenSign(_paymentContext.MchKey, order, sign => { order.Sign = sign; });

            _validationProvider.Validate(order);

            var response = await _httpClient.PostAsync <UnifiedOrderResponse>("api_url", async writer => {
                await _xmlSerializer.SerializeAsync(order, writer);
            });

            return(response);
        }
Ejemplo n.º 17
0
        private static void ProcessInputFile(string filename, IValidationProvider validationProvider)
        {
            Log.Instance.Info("Processing File {0}", filename);

            var inputStream = new StreamReader(filename);
            JsonTextReader reader = new JsonTextReader(inputStream);

            var obj = JToken.ReadFrom(reader);

            var validationResult = validationProvider.Validate(obj);

            Log.Instance.Info("Valid: {0}", validationResult.IsValid);

            if (!validationResult.IsValid)
            {
                validationResult.PrintValidationMessages(Log.Instance);
                return;
            }

            var contextToken = obj["context"];
            var context = DataReference.CurrentContext();
            ObjectFactory objectFactory = new ObjectFactory();

            foreach (var item in contextToken.Children())
            {
                string type = (string)item["type"];
                string name = (string)item.TryGet("name");

                Console.WriteLine("{0}:{1}", name ?? "<unnamed>", type);

                if (name != null)
                {
                    var contextItem = objectFactory.Create(item);
                    if (contextItem != null)
                    {
                        context[name] = contextItem;
                    }
                }
            }

            var ouputToken = obj["output"];

            IList<IRootOutput> outputs = new List<IRootOutput>();
            foreach (var item in ouputToken)
            {
                string type = (string)item["type"];

                Log.Instance.Trace("{0}:{1}", "output", type);

                var outputItem = (IRootOutput)objectFactory.Create(item);

               outputs.Add(outputItem);
            }

            var toExecute = outputs.ToList();

            if (!toExecute.Any())
            {
                Log.Instance.Warn("No root outputs found. No output will be generated. Choose one of (fileOutput)");
            }
            else
            {
                toExecute.ForEach(p => p.Evaluate());
            }

            inputStream.Dispose();
        }