Click or drag to resize

IAnalysisModelComparisonService

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

See IAnalysisModelComparisonService for technical documentation

This service is used to compare one AnalysisModel with another.

The comparison result will give you the ids of the objects that have been added, updated or deleted

This page was last updated 2020-07-27

Examples
Retrieving the IAnalysisModelComparisonService from the container
IBootstrapper bootstrapper = new AnalysisDataModelBootstrapper();
using(IScopedServiceProvider scope = bootstrapper.CreateThreadedScope())
{
  IAnalysisModelComparisonService comparisonService = scope.GetService<IAnalysisModelComparisonService>();
}
Comparing two AnalysisModel instances with each other
AnalysisModel model = CreateModel();  // Assume method exists that creates a model
AnalysisModel model2 = CreateModel();

ChangeModel(model2);  // Assume method exists that modifies the provided model (adds 1 new object, changes 1 existing object and removes 1 object)

IBootstrapper bootstrapper = new AnalysisDataModelBootstrapper();
using(IScopedServiceProvider scope = bootstrapper.CreateThreadedScope())
{
  IAnalysisModelComparisonService comparisonService = scope.GetService<IAnalysisModelComparisonService>();

  // Compare the 2 models
  AnalysisModelComparison result = comparisonService.Compare(model, model2);

  Console.WriteLine($"There are {result.New.Count} new objects"); // Outputs "There are 1 new objects"
  Console.WriteLine($"There are {result.Updated.Count} updated objects"); // Outputs "There are 1 updated objects"
  Console.WriteLine($"There are {result.Deleted.Count} deleted objects"); // Outputs "There are 1 deleted objects"
}
Comparing two AnalysisModel instances with each other, but skip certain types
AnalysisModel model = CreateModel();  // Assume method exists that creates a model
AnalysisModel model2 = CreateModel();

ChangeModel(model2);  // Assume method exists that modifies the provided model (adds 1 new object, changes 1 existing object and removes 1 object)

IBootstrapper bootstrapper = new AnalysisDataModelBootstrapper();
using(IScopedServiceProvider scope = bootstrapper.CreateThreadedScope())
{
IAnalysisModelComparisonService comparisonService = scope.GetService<IAnalysisModelComparisonService>();

// Compare the 2 models, but do not compare the Project and Model information objects
AnalysisModelComparison result = comparisonService.Compare(model, model2, typeof(ProjectInformation), typeof(ModelInformation));

Console.WriteLine($"There are {result.New.Count} new objects"); // Outputs "There are 1 new objects"
Console.WriteLine($"There are {result.Updated.Count} updated objects"); // Outputs "There are 1 updated objects"
Console.WriteLine($"There are {result.Deleted.Count} deleted objects"); // Outputs "There are 1 deleted objects"
}

More examples coming soon or on request.

See Also