public bool SaveQuery(string path)
        {
            var fileName   = GenerateFileName(path);
            var parameters = new StorageParameters {
                FileName = fileName
            };
            var query = GenerateQuery();

            if (query == null)
            {
                return(false);
            }

            _storage.SaveQuery(query, parameters);

            LinqQuery = "";
            SqlQuery  = "";

            if (!ValidationResults.Any())
            {
                var schemaFileName = Path.Combine(path, $"Schema.json");
                LinqQuery = _linqGenerator.GenerateQuery(schemaFileName, fileName);
            }

            return(true);
        }
        public StoreQuery GenerateQuery()
        {
            ErrorLog.Clear();
            Validate();

            if (ValidationResults.Any())
            {
                return(null);
            }

            var subQueries = new List <StoreQuery>();

            try
            {
                for (int i = 1; i < SubQueryList.Count; i++)
                {
                    var q   = SubQueryList[i];
                    var gen = _engine.GenerateQuery(q);
                    subQueries.Add(gen);
                }

                var result = _engine.GenerateQuery(MainQuery, StoreParameters);
                result.Query.SubQueries = subQueries.ToDictionary(s => s.Name, s => s.Query);
                return(result);
            }
            catch (Exception exc)
            {
                ErrorLog.AppendLine($"Cannot generate query: {exc.Message}");
                return(null);
            }
        }
Exemple #3
0
        protected override void DoValidate(ManualJournal objectToValidate, object currentTarget, string key, ValidationResults validationResults)
        {
            if (string.IsNullOrEmpty(objectToValidate.Narration))
            {
                validationResults.AddResult(new ValidationResult("Document Narration must be specified.", currentTarget, key, "Narration", this));
            }

            if (objectToValidate.Lines == null || !objectToValidate.Lines.Any())
            {
                validationResults.AddResult(new ValidationResult("The document has no LineItems", currentTarget, key, "JournalLines", this));
            }
            else
            {
                ValidationResults vr = new ValidationResults();
                foreach (var item in objectToValidate.Lines)
                {
                    lineItemValidator.Validate(item, vr);
                }

                if (vr.Any())
                {
                    validationResults.AddResult(new ValidationResult("Invalid LineItems", currentTarget, key, "LineItems", this, vr));
                }

                if (objectToValidate.Lines.GetLineItemTotal() != 0)
                {
                    validationResults.AddResult(new ValidationResult("LineItems don't balance", currentTarget, key, "LineItems", this, vr));
                }
            }
        }
        public void CanValidateObjectWithValidationAttributes()
        {
            ValidationResults validationResults =
                Validation.Validate(
                    new TestObjectWithMultipleSourceValidationAttributesOnProperties
            {
                PropertyWithDataAnnotationsAttributes = "invalid",
                PropertyWithMixedAttributes           = "invalid"
            },
                    ValidationSpecificationSource.DataAnnotations);

            Assert.IsFalse(validationResults.IsValid);
            Assert.AreEqual(2, validationResults.Count);
            Assert.IsTrue(
                validationResults.Any(vr =>
                                      vr.Message == "data annotations-only" && vr.Key == "PropertyWithDataAnnotationsAttributes"));
            Assert.IsTrue(
                validationResults.Any(vr =>
                                      vr.Message == "data annotations-mixed" && vr.Key == "PropertyWithMixedAttributes"));
        }
        public StoreQuery GenerateQuery()
        {
            Validate();

            if (ValidationResults.Any())
            {
                return(null);
            }

            return(_engine.GenerateQuery(this));
        }
Exemple #6
0
 public void ListResults(ValidationResults results)
 {
     if (!results.Any())
     {
         Console.WriteLine("Keine Fehler");
     }
     foreach (ValidationResult result in results)
     {
         // Logging.LogWrite("Feld:{0}:{1}", result.Key, result.Message);
         Console.WriteLine("Feld:{0}:{1}", result.Key, result.Message);
     }
     Console.WriteLine("-".PadLeft(15, '-'));
 }
Exemple #7
0
        private void ValidateUrlTitle(object sender, ConditionalEventArgs e)
        {
            IPage newPage = this.GetBinding <IPage>("NewPage");

            if (this.CurrentStateName == "step1State")
            {
                SetDefaultValues(newPage);
            }

            e.Result = true;

            if (!UrlTitleIsUniqueAmongSiblings())
            {
                string fieldName = "NewPage.UrlTitle";

                if (this.CurrentStateName == "step1State")
                {
                    fieldName = "NewPage.Title";
                }

                this.ShowFieldMessage(fieldName, GetText("UrlTitleNotUniqueError"));
                e.Result = false;
            }
            else
            {
                ValidationResults validationResults = ValidationFacade.Validate <IPage>(newPage);

                if (!validationResults.IsValid && validationResults.Any(f => f.Key == "UrlTitle"))
                {
                    this.ShowFieldMessage("NewPage.Title", "${Composite.Plugins.PageElementProvider, UrlTitleNotValidError}");
                    e.Result = false;
                }
            }

            DataTypeDescriptor dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(typeof(IPage));

            if (newPage.UrlTitle.Length > dataTypeDescriptor.Fields["UrlTitle"].StoreType.MaximumLength)
            {
                this.ShowFieldMessage("NewPage.UrlTitle", GetText("UrlTitleTooLong"));
                e.Result = false;
                return;
            }

            if (newPage.MenuTitle.Length > dataTypeDescriptor.Fields["MenuTitle"].StoreType.MaximumLength)
            {
                this.ShowFieldMessage("NewPage.MenuTitle", GetText("AddNewPageStep1.MenuTitleTooLong"));
                e.Result = false;
                return;
            }
        }
Exemple #8
0
        public string GetFirstErrorMessage()
        {
            var errorMessage = string.Empty;

            if (ValidationResults.Any())
            {
                var commandValidationResult = ValidationResults.FirstOrDefault();
                if (commandValidationResult != null)
                {
                    errorMessage = commandValidationResult.ErrorMessage;
                }
            }

            return(errorMessage);
        }
Exemple #9
0
        protected override void Validate()
        {
            if (this.NeedValidation == true)
            {
                DESchemaPropertyValidatorContext context = DESchemaPropertyValidatorContext.Current;

                try
                {
                    context.Target    = this.Data;
                    context.Container = this._Container;

                    ValidationResults validationResult = new ValidationResults();

                    if (this.Data.Status == SchemaObjectStatus.Normal)
                    {
                        validationResult = this.Data.Validate();
                    }

                    //haoyk 2014-2-8
                    if (this.SaveMemberData && this.Members.Any())
                    {
                        this.Members.Where(p => p.Status == SchemaObjectStatus.Normal).ForEach(p =>
                        {
                            ValidationResults results = p.Validate();

                            if (results != null && results.Any())
                            {
                                results.ForEach(validationResult.AddResult);
                            }
                        });
                    }

                    ExceptionHelper.TrueThrow(validationResult.ResultCount > 0, validationResult.ToString());

                    CheckStatus();
                }
                finally
                {
                    DESchemaPropertyValidatorContext.Clear();
                }
            }
        }
 public void SetValidationErrors(IEnumerable <ValidationResult> validationResults)
 {
     this.SetEmptyResult();
     ValidationResults = validationResults ?? Enumerable.Empty <ValidationResult>();
     this.HasError     = ValidationResults.Any();
 }
Exemple #11
0
        /// <summary>
        /// Valide l'état du model de façon synchrone
        /// </summary>
        void InternalUpdateValidationState()
        {
            IsValidating = true;

            try
            {
                bool?wasValid = null;

                // Stocke les propriétés qui étaient en erreur
                IList <string> invalidKeys = null;

                // Récupère les propriétés qui étaient en erreur
                if (_validationResults != null)
                {
                    invalidKeys = _validationResults.Select(vr => vr.Key).ToList();

                    if (!invalidKeys.Any())
                    {
                        invalidKeys = null;
                    }

                    wasValid = _validationResults.IsValid;
                }

                // Valide l'objet
                _validationResults = _validator.Validate(this);

                if (invalidKeys != null)
                {
                    // Parcourt les propriétés qui étaient en erreur auparavant
                    foreach (string key in invalidKeys)
                    {
                        // S'il y a eu un changement d'état, il faut en prévenir les bindings
                        if (!_validationResults.Any(vr => vr.Key == key))
                        {
                            OnPropertyChanged(key, false);
                        }
                    }
                }

                if (!_validationResults.IsValid)
                {
                    // Parcourt des propriétés qui sont en erreur
                    foreach (var result in _validationResults.Where(vr => vr.Target == this))
                    {
                        OnPropertyChanged(result.Key, false);
                    }
                }

                // Si l'objet change d'état de validité, on prévient les bindings
                if (!wasValid.HasValue || wasValid.Value != _validationResults.IsValid)
                {
                    OnIsValidChanged();
                }

                if (!(invalidKeys == null && _validationResults.IsValid))
                {
                    OnPropertyChanged(nameof(Error), false);
                    OnPropertyChanged(nameof(Errors), false);
                }
            }
            finally
            {
                IsValidating = false;
            }
        }
Exemple #12
0
        protected override void DoValidate(CreditNote objectToValidate, object currentTarget, string key, ValidationResults validationResults)
        {
            if (objectToValidate.Contact == null)
            {
                validationResults.AddResult(new ValidationResult("The document has no Contact", currentTarget, key, "Contact", this));
            }

            if (objectToValidate.LineItems == null || !objectToValidate.LineItems.Any())
            {
                validationResults.AddResult(new ValidationResult("The document has no LineItems", currentTarget, key, "LineItems", this));
            }
            else
            {
                ValidationResults vr = new ValidationResults();
                foreach (var item in objectToValidate.LineItems)
                {
                    lineItemValidator.Validate(item, vr);
                }
                if (vr.Any())
                {
                    validationResults.AddResult(new ValidationResult("Invalid LineItems", currentTarget, key, "LineItems", this, vr));
                }

                if (objectToValidate.LineItems.GetLineItemTotal() < 0)
                {
                    validationResults.AddResult(new ValidationResult("The LineItems total must be greater than or equal to 0.", currentTarget, key, "LineItems", this));
                }
            }

            if (objectToValidate.Total.HasValue)
            {
                if (objectToValidate.Total.Value != objectToValidate.LineItems.Sum(a => a.GetLineItemTotal()))
                {
                    validationResults.AddResult(new ValidationResult("The document total does not equal the sum of the lines.", currentTarget, key, "Total", this));
                }
                if (objectToValidate.Total.Value < 0)
                {
                    validationResults.AddResult(new ValidationResult("The document total must be greater than or equal to 0.", currentTarget, key, "Total", this));
                }
            }

            if (objectToValidate.SubTotal.HasValue)
            {
                if (objectToValidate.SubTotal.Value != objectToValidate.LineItems.GetLineItemSubTotal())
                {
                    validationResults.AddResult(new ValidationResult("The document subtotal does not equal the sum of the lines.", currentTarget, key, "SubTotal", this));
                }
                if (objectToValidate.SubTotal.Value <= 0)
                {
                    validationResults.AddResult(new ValidationResult("The document subtotal must be greater than 0.", currentTarget, key, "SubTotal", this));
                }
            }

            if (objectToValidate.TotalTax.HasValue)
            {
                if (objectToValidate.TotalTax.Value != objectToValidate.LineItems.Sum(a => a.TaxAmount))
                {
                    validationResults.AddResult(new ValidationResult("The document totaltax does not equal the sum of the lines.", currentTarget, key, "TotalTax", this));
                }
                if (objectToValidate.TotalTax.Value < 0)
                {
                    validationResults.AddResult(new ValidationResult("The document totaltax must be greater than or equal to 0.", currentTarget, key, "TotalTax", this));
                }
            }

            if (string.IsNullOrEmpty(objectToValidate.Number))
            {
                validationResults.AddResult(new ValidationResult("Document CreditNoteNumber must be specified.", currentTarget, key, "CreditNoteNumber", this));
            }
        }
Exemple #13
0
        protected override void DoValidate(BankTransaction objectToValidate, object currentTarget, string key, ValidationResults validationResults)
        {
            if (objectToValidate.Contact == null)
            {
                validationResults.AddResult(new ValidationResult("The document has no Contact", currentTarget, key, "Contact", this));
            }

            if (objectToValidate.LineItems == null || !objectToValidate.LineItems.Any())
            {
                validationResults.AddResult(new ValidationResult("The document has no LineItems", currentTarget, key, "LineItems", this));
            }
            else
            {
                ValidationResults vr = new ValidationResults();
                foreach (var item in objectToValidate.LineItems)
                {
                    var valResults = lineItemValidator.Validate(item).AsEnumerable();
                    if (objectToValidate.Type.IsOverpayment())
                    {
                        valResults = valResults.Where(a => a.Tag != LineItemValidator.AccountCode);
                    }

                    vr.AddAllResults(valResults);

                    bool?isValidTax = item.IsValidTax();
                    if (isValidTax.HasValue && !isValidTax.Value)
                    {
                        var msg = string.Format("Invalid Tax Amount ({0} expected: {1})", item.TaxAmount, item.CalculateTaxAmount());
                        vr.AddResult(new ValidationResult(msg, currentTarget, key, "TaxAmount", this));
                    }
                }
                if (vr.Any())
                {
                    validationResults.AddResult(new ValidationResult("Invalid LineItems", currentTarget, key, "LineItems", this, vr));
                }

                if (objectToValidate.LineItems.GetLineItemTotal() <= 0)
                {
                    validationResults.AddResult(new ValidationResult("The LineItems total must be greater than 0.", currentTarget, key, "LineItems", this));
                }
            }

            if (objectToValidate.Total.HasValue)
            {
                if (objectToValidate.Total.Value != objectToValidate.LineItems.Sum(a => a.GetLineItemTotal()))
                {
                    validationResults.AddResult(new ValidationResult("The document total does not equal the sum of the lines.", currentTarget, key, "Total", this));
                }
                if (objectToValidate.Total.Value <= 0)
                {
                    validationResults.AddResult(new ValidationResult("The document total must be greater than 0.", currentTarget, key, "Total", this));
                }
            }

            if (objectToValidate.SubTotal.HasValue)
            {
                if (objectToValidate.SubTotal.Value != objectToValidate.LineItems.GetLineItemSubTotal())
                {
                    validationResults.AddResult(new ValidationResult("The document subtotal does not equal the sum of the lines.", currentTarget, key, "SubTotal", this));
                }
                if (objectToValidate.SubTotal.Value <= 0)
                {
                    validationResults.AddResult(new ValidationResult("The document subtotal must be greater than 0.", currentTarget, key, "SubTotal", this));
                }
            }

            if (objectToValidate.TotalTax.HasValue)
            {
                if (objectToValidate.TotalTax.Value != objectToValidate.LineItems.Sum(a => a.TaxAmount))
                {
                    validationResults.AddResult(
                        new ValidationResult("The document totaltax does not equal the sum of the lines.", currentTarget,
                                             key, "TotalTax", this));
                }
                if (objectToValidate.TotalTax.Value < 0)
                {
                    validationResults.AddResult(
                        new ValidationResult("The document totaltax must be greater than or equal to 0.", currentTarget,
                                             key, "TotalTax", this));
                }
            }
        }
        /// <summary>
        /// Binds form values to a data item and sends messages to client to display validation messages.
        /// </summary>
        /// <param name="helper">Form binding helper</param>
        /// <param name="data">An IData instance</param>
        /// <returns>True, if there were no binding/validation errors</returns>
        protected bool BindAndValidate(DataTypeDescriptorFormsHelper helper, IData data)
        {
            Dictionary <string, string> errorMessages = helper.BindingsToObject(this.Bindings, data);

            ValidationResults validationResults = ValidationFacade.Validate(data.DataSourceId.InterfaceType, data);

            bool isValid = true;

            if (!validationResults.IsValid)
            {
                foreach (ValidationResult result in validationResults)
                {
                    if (!result.Key.IsNullOrEmpty())
                    {
                        this.ShowFieldMessage(result.Key, result.Message);
                    }
                    else
                    {
                        this.ShowMessage(DialogType.Error, "Validation error", result.Message);
                    }

                    isValid = false;
                }
            }

            // Checking that required strings are not empty
            var dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(data.DataSourceId.InterfaceType);

            foreach (var fieldName in dataTypeDescriptor.Fields
                     .Where(f => !f.IsNullable &&
                            f.InstanceType == typeof(string) &&
                            !(f.Inherited && f.Name == "FieldName"))                                        // Skipping validation for inherited IPageMetaData.FieldName
                     .Select(f => f.Name))
            {
                string bindingName = (helper.BindingNamesPrefix ?? "").Replace('.', '_') + fieldName;
                if (validationResults.Any(r => r.Key == bindingName))
                {
                    continue;
                }

                object fieldValue = this.Bindings[bindingName];
                if (fieldValue is string &&
                    (fieldValue as string) == string.Empty &&
                    !helper.BindingIsOptional(bindingName))
                {
                    this.ShowFieldMessage(bindingName, LocalizationFiles.Composite_Management.Validation_RequiredField);

                    isValid = false;
                }
            }


            if (errorMessages != null)
            {
                isValid = false;

                foreach (var kvp in errorMessages)
                {
                    this.ShowFieldMessage(kvp.Key, kvp.Value);
                }
            }

            return(isValid);
        }