Beispiel #1
0
 public override void OnPropertyChanged(string propertyName = null)
 {
     if (Fields?.All(field => field.HasValue) ?? false)
     {
         Total = GetTotal();
     }
     base.OnPropertyChanged(propertyName);
 }
        public override bool Equals(object obj)
        {
#pragma warning disable IDE0046 // Convert to conditional expression
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }
#pragma warning restore IDE0046 // Convert to conditional expression

            return(Properties.All(x => { return PropertiesAreEqual(obj, x); }) &&
                   Fields.All(x => { return FieldsAreEqual(obj, x); }));
        }
        private void ValidateRecord <T>(JToken node, ICollection <string> errorMessages, KongObject parent) where T : KongObject
        {
            var record = (JObject)node;

            foreach (var field in Fields)
            {
                if (!record.ContainsKey(field.Name) && field.Schema.Required && field.Schema.HasDefault)
                {
                    // Our record has a missing field and schema has a default value, so add that to our record
                    record.Add(field.Name, field.Schema.Default);
                }

                if (field.Schema.Required && (record[field.Name] == null || Equals(record[field.Name], JValue.CreateNull())))
                {
                    var fieldPath = string.IsNullOrEmpty(record.Path)
                        ? field.Name
                        : $"{record.Path}.{field.Name}";
                    errorMessages.Add($"{Violation<T>()} (field '{fieldPath}' is required).");
                }
                else if (field.Schema.Type == FieldType.Foreign || record[field.Name] != null && !Equals(record[field.Name], JValue.CreateNull()))
                {
                    field.Schema.Validate <T>(record[field.Name], errorMessages, parent);
                }
            }
            foreach (var field in record.Properties())
            {
                var key = field.Path.Contains('.')
                    ? field.Path.Substring(field.Path.LastIndexOf('.') + 1)
                    : field.Path;
                if (Fields.All(x => x.Name != key))
                {
                    errorMessages.Add($"{Violation<T>()} (unknown field '{field.Path}').");
                }
            }
            foreach (var entityCheck in EntityChecks)
            {
                if (entityCheck.AtLeastOneOf != null)
                {
                    if (entityCheck.AtLeastOneOf.All(x => !record.ContainsKey(x)))
                    {
                        errorMessages.Add($"{Violation<T>()} (field '{node.Path}' should have at least one of '{string.Join(", ", entityCheck.AtLeastOneOf)}').");
                    }
                }
            }
        }
Beispiel #4
0
 protected override bool IsFormValid()
 {
     try
     {
         return
             (!String.IsNullOrEmpty(Identificator.Trim()) &&
              !String.IsNullOrEmpty(Name.Trim()) &&
              !String.IsNullOrEmpty(Description.Trim()) &&
              RowOffset >= 0 &&
              ColumnOffset >= 0 &&
              WorksheetIndex > 0 &&
              Fields.All(IsValidField));
     }
     catch (Exception)
     {
         return(false);
     }
 }
 /// <summary>
 /// Check if all the fields on the view are correctly filled
 /// </summary>
 /// <returns>Can an instance be created</returns>
 private bool AreFieldsFilled()
 {
     if (!Fields.All(field => field.Value != null) || Fields.Count == 0)
     {
         return(false);
     }
     else
     {
         if (Fields.All(field => field.Value != null))
         {
             return(Fields.All(field => !string.IsNullOrWhiteSpace(field.Value.ToString())));
         }
         else
         {
             return(false);
         }
     }
 }
Beispiel #6
0
        /// <summary>
        /// глубокое сравнение контентов с учетом циклов
        /// </summary>
        /// <param name="other"></param>
        /// <param name="visitedContents">родительские контенты, Key текущего, Value - other</param>
        /// <returns></returns>
        internal bool RecursiveEquals(Content other, ReferenceDictionary <Content, Content> visitedContents)
        {
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (visitedContents.ContainsKey(this))
            {
                return(ReferenceEquals(visitedContents[this], other));
            }

            visitedContents.Add(this, other);

            return(ContentId == other.ContentId &&
                   IsReadOnly == other.IsReadOnly &&
                   LoadAllPlainFields == other.LoadAllPlainFields &&
                   PublishingMode == other.PublishingMode &&
                   Fields.Count == other.Fields.Count &&
                   Fields.All(x => other.Fields
                              .Any(y => y.FieldId == x.FieldId && x.RecursiveEquals(y, visitedContents))));
        }
Beispiel #7
0
 public bool Valid(IEnumerable <Rule> rules) => Fields.All(field => IsFieldValid(field, rules));
 public void NoAttributeIsntIgnored()
 {
     WithPsiFile("SingleSpec.cs", x => Assert.That(Fields.All(y => y.IsIgnored()), Is.False));
 }