Click or drag to resize

IAnalysisModelValidator

[This is preliminary documentation and is subject to change.]

See IAnalysisModelValidator for technical documentation

This service is used to validate an AnalysisModel or IAnalysisObject objects

This page was last updated 2020-06-15

How does it work?

Validation in ADM has been added after the request was made by partners to have the ability to change object properties after object creation.

In the very beginning, we had very strict object creation and absolutely no object mutations, meaning you were not allowed to change any property on an instance. You literally had to re-create the object.

To facilitate this, we introduced the following changes in ADM:

  • StructuralAnalysisObjectBase now implements INotifyPropertyChanged, which is triggered automatically whenever a property changes.

  • StructuralAnalysisObjectBase now has an internal AnalysisModel property, which is assigned as soon as the object is added to a model. When the PropertyChanged event is triggered, the object will mark itself as "pending validation" on the model it has been added to.

  • AnalysisModel now stores a list of each object's GUID and its validation state (Pending, Valid or Invalid) along with a list of validation errors per GUID.

  • IAnalysisModelService will now automatically trigger validation when adding/updating/deleting and set the validation state of the object on the model accordingly.

  • IAnalysisModelService has also been extended with a ValidateModel(AnalysisModel) method which will reset the validation state of all objects to pending and re-validate the entire model.

If you follow the following guideline, you should have no issues when processing a model:

Usage

There are only a few edge cases in which it makes sense to directly use the validator:

  • To test and see if an item is correct before moving forward with your workflow

  • To perform intermediary validation after changes have been made to objects

  • To test and see if the model you have is valid or not

It is important to note that running an item through the validator will not update its validation state on the model.

It is recommended that you use ValidateModel(AnalysisModel) from IAnalysisModelService to validate your entire model, as this will re-validate the entire model again and reset the validation states on all objects.

There's also a difference in behaviour when it comes to the ValidationMode. Certain validations are not performed when adding versus when updating and vice versa.

Examples
Retrieving the IAnalysisModelValidator from the container
IBootstrapper bootstrapper = new AnalysisDataModelBootstrapper();
using(IScopedServiceProvider scope = bootstrapper.CreateThreadedScope())
{
    IAnalysisModelValidator validator = scope.GetService<IAnalysisModelValidator>();
}
Validating an object
IBootstrapper bootstrapper = new AnalysisDataModelBootstrapper();
AnalysisModel model = new AnalysisModel();
using(IScopedServiceProvider scope = bootstrapper.CreateThreadedScope())
{
  IAnalysisModelValidator validator = scope.GetService<IAnalysisModelValidator>();

  StructuralPointConnection node = new StructuralPointConnection(Guid.NewGuid(), "N1", Length.Zero, Length.Zero, Length.Zero);

  ValidationResult result = validator.Validate(ValidationMode.Adding, node);

  if(result != null)
  {
    Console.WriteLine(result.ToString());
  }
}

More examples coming soon or on request.

See Also