Exemplo n.º 1
0
        public Task SaveAsync()
        {
            ValidationErrors = _advertisement.GetValidationErrors();

            if (!ValidationErrors.Any())
            {
                return(_service.AddAdvertisementAsync(_advertisement));
            }

            return(null);
        }
Exemplo n.º 2
0
        protected virtual void Save()
        {
            IsValid = IsValid && !ValidationErrors.Any();

            if (IsValid)
            {
                SetListMode();
                Get();
            }
            else
            {
                SetDetailsMode();
            }
        }
        public bool Validate()
        {
            IServiceProvider sp = TextEditor;
            var markerService   = (TextMarkerService)sp.GetService(typeof(ITextMarkerService));

            markerService.Clear();

            try
            {
                ValidationErrors.Clear();

                var schema = XmlSchema.Read(File.OpenText("template.xsd"), ValidateErrors);

                var settings = new XmlReaderSettings
                {
                    ValidationType  = ValidationType.Schema,
                    ValidationFlags =
                        XmlSchemaValidationFlags.ProcessInlineSchema |
                        XmlSchemaValidationFlags.ProcessSchemaLocation |
                        XmlSchemaValidationFlags.ReportValidationWarnings,
                };

                settings.Schemas.Add(schema);
                settings.ValidationEventHandler += ValidateErrors;

                var tr = new XmlTextReader(TextEditor.Document.Text, XmlNodeType.Document, null);

                var xr = XmlReader.Create(tr, settings);

                while (xr.Read())
                {
                }

                if (!ValidationErrors.Any())
                {
                    ErrorsRow.Height = new GridLength(0);
                }
            }
            catch (XmlException ex)
            {
                DisplayValidationError(ex.Message, ex.LinePosition, ex.LineNumber);
            }
            catch (Exception)
            {
                // Do Nothing
            }

            return(!ValidationErrors.Any());
        }
        /// <summary>
        /// Validates the method invocation.
        /// </summary>
        public void Validate()
        {
            CheckInitialized();

            if (Parameters.IsNullOrEmpty())
            {
                return;
            }

            if (!Method.IsPublic)
            {
                return;
            }

            if (IsValidationDisabled())
            {
                return;
            }

            if (Parameters.Length != ParameterValues.Length)
            {
                throw new Exception("Method parameter count does not match with argument count!");
            }

            if (ValidationErrors.Any() && HasSingleNullArgument())
            {
                ThrowValidationError();
            }

            for (var i = 0; i < Parameters.Length; i++)
            {
                ValidateMethodParameter(Parameters[i], ParameterValues[i]);
            }

            if (ValidationErrors.Any())
            {
                ThrowValidationError();
            }

            foreach (var objectToBeNormalized in ObjectsToBeNormalized)
            {
                objectToBeNormalized.Normalize();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Enumerates through the <see cref="UsedSnippets" /> but will first throw an exception if there are any <see cref="MissingSnippets" />.
        /// </summary>
        public virtual IEnumerator <Snippet> GetEnumerator()
        {
            if (MissingSnippets.Any())
            {
                throw new MissingSnippetsException(MissingSnippets);
            }

            if (MissingIncludes.Any())
            {
                throw new MissingIncludesException(MissingIncludes);
            }

            if (ValidationErrors.Any())
            {
                throw new ContentValidationException(ValidationErrors);
            }

            return(UsedSnippets.GetEnumerator());
        }
Exemplo n.º 6
0
        string IDataErrorInfo.this[string columnName]
        {
            get
            {
                StringBuilder errors = new StringBuilder();

                if (ValidationErrors != null && ValidationErrors.Any())
                {
                    foreach (ValidationFailure validationError in ValidationErrors)
                    {
                        if (validationError.PropertyName == columnName)
                        {
                            errors.AppendLine(validationError.ErrorMessage);
                        }
                    }
                }

                return(errors.ToString());
            }
        }
 public override bool IsValid()
 {
     return(!ValidationErrors.Any());
 }
Exemplo n.º 8
0
 private bool CanSave()
 {
     return(!ValidationErrors.Any());
 }
Exemplo n.º 9
0
 public bool IsValid() => !ValidationErrors.Any();
Exemplo n.º 10
0
 /// <param name="field">name of the field</param>
 /// <returns>Returns true if given field have error</returns>
 public bool HasError(string field)
 {
     return(ValidationErrors.Any(ve => ve.Field == field));
 }
Exemplo n.º 11
0
 public void AddErrors(List <ValidationError> errors)
 {
     ValidationErrors.AddRange(errors.Where(v => !ValidationErrors.Any(e => e.ErrorMessage == v.ErrorMessage)));
 }