Try our conversational search powered by Generative AI!

Class ContentTypeModelRegister

Synchronizes ContentTypeModels defined in code with ContentTypes stored in the repository.

Inheritance
System.Object
ContentTypeModelRegister
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.DataAbstraction.RuntimeModel
Assembly: EPiServer.dll
Version: 8.11.0
Syntax
public class ContentTypeModelRegister
Remarks

Model synchronization is automatically performed by this class at site initialization. Please see the examples section for instructions on how you can manually synchronize a content model.

Examples

The following code example demonstrate how to manually synchronize a model using the ContentTypeModelRegister class.

In this example we create a ContentTypeModel from a known class that looks like this

The MyModel class is decorated with the [ContentType] attribute containing various settings that will be applied to the content type that will be created from it. The class also contains one string property. Since the property is public and has public get and set accessors it will be turned into a property on the MyModel content type. Since the property is not decorated with any attributes the resulting content type property will be set up with the default values for string properties, i.e. the data will be stored in a PropertyString, the property will be searchable etc.

The synchronization process is performed in three steps; Validate, Analyze and Commit, each of which is represented by a method. The Validate step verifies that the model itself is correct. The Analyze step decides if the model represents a new content type or if it is an updated or identical version of an existing content type. The Commit step saves any changes to the repository.

Constructors

ContentTypeModelRegister(ContentTypeSynchronizer, PropertyDefinitionSynchronizer, IContentLoader)

Initializes a new instance of the ContentTypeModelRegister class.

Declaration
public ContentTypeModelRegister(ContentTypeSynchronizer typeSynchronizer, PropertyDefinitionSynchronizer propertyDefinitionSynchronizer, IContentLoader contentLoader)
Parameters
Type Name Description
ContentTypeSynchronizer typeSynchronizer

The type synchronizer that should be used by this instance.

PropertyDefinitionSynchronizer propertyDefinitionSynchronizer

The property definition synchronizer that should be used by this instance.

IContentLoader contentLoader

The content loader.

Properties

RunSynchronously

If methods should run without parallellism

Declaration
public bool RunSynchronously { get; set; }
Property Value
Type Description
System.Boolean

TypeModels

Gets the type models that will be used in the Analyze and Commit operations.

Declaration
public IList<ContentTypeModel> TypeModels { get; }
Property Value
Type Description
System.Collections.Generic.IList<ContentTypeModel>

Methods

AnalyzeProperties()

Compares the model's properties to the repository ones

Declaration
public virtual void AnalyzeProperties()

AnalyzeTypes()

Gets the type models properties that will be used in the Analyze of type models properties

Declaration
public virtual void AnalyzeTypes()

CommitProperties(Boolean)

Commits the type models' properties changes detected in the Analyze operation to the repository.

Declaration
public virtual void CommitProperties(bool deleteUnusedTypes)
Parameters
Type Name Description
System.Boolean deleteUnusedTypes

if set to true any types that are no longer used are deleted.

Exceptions
Type Condition
AlreadyInUseException

A definition without an ID, and with a name that already existing definition, tries to be saved.

CommitTypes(Boolean)

Commits any changes detected in the Analyze operation to the repository.

Declaration
public virtual void CommitTypes(bool deleteUnusedTypes)
Parameters
Type Name Description
System.Boolean deleteUnusedTypes

if set to true any types that are no longer used are deleted.

Exceptions
Type Condition
AlreadyInUseException

A definition without an ID, and with a name that already existing definition, tries to be saved.

EnsureContentTypeVersionUpToDate()

Ensures that if there was changes to a content type or its properties, then the assembly version must be updated to reflect which code version that was used to update the database.

Declaration
public void EnsureContentTypeVersionUpToDate()

Validate(ContentModelValidator)

The Validate method checks the contenttypemodels guid and its modeltype. If the guid for the contenttypemodel is not assigned or is empty then it passes validation. If two contenttypes has same guid with different modeltype then SynchronizationException be thrown the validation checks on both contenttypemodels in memory and against repository.

Declaration
public virtual void Validate(ContentModelValidator modelValidator)
Parameters
Type Name Description
ContentModelValidator modelValidator
Exceptions
Type Condition
SynchronizationException

If two or more contenttypes has same guid with different modeltype then SynchronizationException be thrown.

Extension Methods