/// <summary> /// calculates a plausibility rating based on the amount of allowed items on the model /// </summary> /// <returns>amount of allowed items</returns> public int CalculateRating() { if (AllowedItems != null) { return(ObjectList.Count(t => AllowedItems.Exists(x => x == t.GetType()))); } else { return(ObjectList.Count); } }
/// <summary> /// validates basic intra model spezifications. Can be overwritten and extended by calling base.Validate() /// </summary> public virtual void Verify() { //check if sheet is not empty if (ObjectList.Count < 1) { ValidationFailedEvent?.Invoke(new ValidationFailedMessage(1, $"model {this.PageName} is empty")); return; } //check if elements are allowed on model if (AllowedItems != null) { foreach (var element in ObjectList) { if (AllowedItems.All(t => t != element.GetType()) && element.GetType() != typeof(NRO)) { ValidationFailedEvent?.Invoke(new ValidationFailedMessage(1, "element not allowed", element)); } } } //check if elements exist double on any sheet List <BaseObject> objects = ObjectList.Where(t => t is Item && !String.IsNullOrEmpty(t.Text) && !((t as Item).CanHaveDuplicateText)).ToList(); foreach (var obj in objects) { if (objects.Count(t => t.Text == obj.Text) > 1) { ValidationFailedEvent?.Invoke(new ValidationFailedMessage(2, $"{this.PageName} contains elements with duplicate text", obj)); } } //do checks on objects, if implemented ObjectList.ForEach(t => { try { t.Verify(); } catch (ValidationFailedException ex) { ValidationFailedEvent?.Invoke(new ValidationFailedMessage(2, ex)); } }); }