Table of Contents

Class ModelElement

Namespace
TimeCockpit.Data.DataModel
Assembly
TimeCockpit.Data.dll

Acts as the base class for metadata elements in the Time Cockpit data model.

public abstract class ModelElement : NamedDynamicObject, IDynamicMetaObjectProvider, INotifyPropertyChanged, IDataErrorInfo
Inheritance
Object
ModelElement
Implements
IDynamicMetaObjectProvider
INotifyPropertyChanged
IDataErrorInfo
Derived
Inherited Members
Object.ToString()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()

Remarks

Time Cockpit supports a flexible data model that can be customized and extended by users. The metadata about the data model is represented as a tree data structure. The type of every object in this tree must be derived from ModelElement.

Every element in the model element tree is identified using a universal unique identifier (see ElementGuid. Additionally every element has a name. This name needs not to be globally unique (e.g. two different entites can include properties with the same name). However, it has to be unique in the corresponding collection of model elements (e.g. element names of properties inside a single dimension must be unique inside that dimension).

Beside acting as the base class for model elements, ModelElement also contains various static helper functions and properties that can be used to check conventions (e.g. IsValidIdentifier(String), etc.).

Important note to implementers: Note that ModelElement instances can be created through deserialization. Therefore make sure your fields are properly initialized. You cannot rely on your constructor being called neither can you rely on fields initializers. If you have fields and/or properties that must be initialized you have to use the System.Runtime.Serialization.OnDeserializingAttribute!

Constructors

ModelElement()

Initializes a new instance of the ModelElement class

protected ModelElement()

ModelElement(IEnumerable<KeyValuePair<Object, Object>>)

Initializes a new instance of the ModelElement class.

protected ModelElement(IEnumerable<KeyValuePair<object, object>> properties)

Parameters

properties IEnumerable<KeyValuePair<Object, Object>>

Collection of properties.

Remarks

You can use this constructor to initialize a new instance of the ModelElement class by specifying its properties in a list of key/value pairs. This is especially useful for dynamic languages like python.

ModelElement(ModelElement)

Initializes a new instance of the ModelElement class.

protected ModelElement(ModelElement element)

Parameters

element ModelElement

The element to copy.

Remarks

Copy constructor for copying values of an instance of ModelElement.

Properties

Children

Gets the children of the ModelElement.

public IEnumerable<ModelElement> Children { get; }

Property Value

IEnumerable<ModelElement>

Remarks

When Attach(ModelElement) is called on a ModelElement, the modelelement that is to be attatched is added to the Children collection of Parent. Detach() removes modelelement from the Children collection of the Parent modelelement.

CreationVersion

Gets the creation version of the entity object

public ulong CreationVersion { get; }

Property Value

UInt64

ElementGuid

Gets or sets the unique identifier for the model element.

public Guid ElementGuid { get; set; }

Property Value

Guid

Error

Gets an error message indicating why validation fails for this object.

public string Error { get; }

Property Value

String

ErrorSummary

Gets a summary of all validation errors that occurred in the ModelElement and its children model elements

public IEnumerable<PropertyValidationMessage> ErrorSummary { get; }

Property Value

IEnumerable<PropertyValidationMessage>

InvariantFriendlyName

Gets or sets a language invariant friendly name of the ModelElement

public string InvariantFriendlyName { get; set; }

Property Value

String

IsApplicationSpecificElement

Gets a value indicating whether the element is a application specific element.

public bool IsApplicationSpecificElement { get; }

Property Value

Boolean

IsFullPersistBehavior

Gets a value indicating whether the modelelement is persisted fully or not.

public bool IsFullPersistBehavior { get; }

Property Value

Boolean

IsNonePersistBehavior

Gets a value indicating whether the modelelement is PersistBehavior.None.

public bool IsNonePersistBehavior { get; }

Property Value

Boolean

Remarks

This property should be only user for string templating

IsSystemElement

Gets a value indicating whether the element is a system element.

public bool IsSystemElement { get; }

Property Value

Boolean

IsSystemOrApplicationSpecificElement

Gets a value indicating whether the element is a application specific or system element.

public bool IsSystemOrApplicationSpecificElement { get; }

Property Value

Boolean

IsUserElement

Gets a value indicating whether the element is a application specific element.

public bool IsUserElement { get; }

Property Value

Boolean

IsValid

Gets a value indicating whether the ModelElement is valid or not

public bool IsValid { get; }

Property Value

Boolean

LastUpdateVersion

Gets the update version of the entity object

public ulong LastUpdateVersion { get; }

Property Value

UInt64

Name

Gets or sets the name of the model element.

public override string Name { get; set; }

Property Value

String

Remarks

Note that once the model element has been added to a tree (e.g. by adding it to a parent object's collection) the name cannot be changed any more.

When the name is set and the name contains USR, SYS or APP, the ownership is set to the according value.

Exceptions

System.InvalidOperationException

You tried to change the name once it has been set on a persisted model element.

System.ArgumentException

Specified name is not a valid identifier.

NonPrefixedName

Gets the name of the model element without its prefix.

public string NonPrefixedName { get; }

Property Value

String

Ownership

Gets or sets the ownership type of a model element.

public Ownership Ownership { get; set; }

Property Value

Ownership

Remarks

If the ownership for the current model element is Ownership.None, this property returns Ownership.User, as this ownership type is the specified default value for the ownership property.

The ownership property should be set before any properties, relations, validationrules or modelentityinterfaces are added to a modelentity. This is because, to a certain extent, the latter elements derive the ownership from their parent element. That is, if properties, relations etc. are added to a modelentity which is either System or User, properties, relations, etc. inherit the ownership from their parent.

When the ownership property is not set explicitely by the user, the system sets the ownership automatically to user. This behavior is especially important when using application specific elements. In contrast to system and user model entities which force their children to be of the same ownership as themselves, application specific entites can contain both, user and appspecific children. That is, they do not change the ownership of their children. When adding a property or relation to an applicationspecific entity without specifying the ownership of the property/relation, the property/relation will keep user as default ownership!

OwnershipPrefix

Gets the database prefix of the element

public string OwnershipPrefix { get; }

Property Value

String

Parent

Gets the parent element.

public ModelElement Parent { get; }

Property Value

ModelElement

Remarks

To set the parent of a given model element you have to use the function Attach(ModelElement). To remove the parent use Detach(). Parent is always null for detached model elements.

PersistBehavior

Gets or sets a value indicating whether the ModelElement instance should be persisted in the database.

public virtual PersistBehavior PersistBehavior { get; set; }

Property Value

PersistBehavior

Remarks

The default value for this property is True.

You should use this property if you need to create temporary model elements. These objects should not result in changes in the database. Therefore they are marked as non-persistent.

Note that you have to set this property to false immediately after object creation if you do not want it to be stored in the database. Changing the property value to false at a later point in time only prevents further changes to the object to be written to the database. However, changing the value to false does never remove anything from the database that has been written before!

Methods

Accept(ModelElementVisitor)

Accepts a visitor dispatching the corresponding operation to the concrete type.

public abstract void Accept(ModelElementVisitor visitor)

Parameters

visitor ModelElementVisitor

the visitor to accept.

Attach(ModelElement)

Attaches a model element to a parent model element.

protected virtual void Attach(ModelElement newParent)

Parameters

newParent ModelElement

Parent model element.

Remarks

Note to implementers: If your model element has sub-elements, your implementation of Attach should call the base class' implementation and afterwards attach all sub-elements.

Exceptions

System.ArgumentNullException

newParent is null.

System.ArgumentException

Thrown in case of a recursion in the model element tree.

Detach()

Detaches a model element from a parent model element.

protected virtual void Detach()

Remarks

Note to implementers: If your model element has sub-elements your implementation of Detach should detach all sub-elements and afterwards call the base class' implementation.

If you call Detach for a model element that has no parent the call is ignored. No exception is thrown in this case.

IsValidIdentifier(String)

Can be used to check if an identifier is valid.

public static bool IsValidIdentifier(string identifier)

Parameters

identifier String

Identifier to check.

Returns

Boolean

True indicates that the identifier is valid. False means that the provided string value cannot be used as an identifier.

Remarks

Identifiers in Time Cockpit must comply with the following rules:

  • Must not be null or empty.
  • Must start with an uppercase letter followed by a combination of upper/lowercase letters, digits or underscores.
  • Must not be a reserved word.
  • Must not start with a reserved identifier prefix.
  • Length must be <= 64 characters.

OnDeserializing(StreamingContext)

Called whenever deserialization of the model element is happening

[OnDeserializing]
public void OnDeserializing(StreamingContext context)

Parameters

context StreamingContext

Stream context used for deserialization.

Remarks

This method is part of the internal infrastructure of the TimeCockpit.Data and must not be called from outside.

SetName(String)

Sets the name of an instance of ModelElement.

protected void SetName(string value)

Parameters

value String

The value to set the name of a ModelElement to.

SetOwnership(Ownership)

Sets the ownership of an instance of ModelElement.

protected void SetOwnership(Ownership value)

Parameters

value Ownership

The value to set the ownership of a ModelElement to.

SetOwnershipPrefix(String)

Sets the ownership of a model element according to a certain string prefix.

protected void SetOwnershipPrefix(string prefix)

Parameters

prefix String

A string prefix to derive the ownership from.

SetPersistBehavior(PersistBehavior)

Sets the persist behavior of the current ModelElement.

protected virtual void SetPersistBehavior(PersistBehavior persistBehavior)

Parameters

persistBehavior PersistBehavior

The new persist behavior of the ModelElement.

Remarks

This method's only purpose is to make it possible to override a ModelElement's persist behavior in the context of a memberwise clone

UpdateChildren(NotifyCollectionChangedEventArgs)

Attaches or detaches added or removed collection items.

protected void UpdateChildren(NotifyCollectionChangedEventArgs e)

Parameters

e NotifyCollectionChangedEventArgs

Provides data for the CollectionChanged event.

Remarks

Quite frequently descendant classes will contain collections of child items (ModelCollection<T>). These child items descend from ModelElement, too. UpdateChildren is typically used in descendant classes to attach/detach ModelElement instances that have been added/removed from such collections.

Validate(ref IList<PropertyValidationMessage>, Boolean)

Validates a ModelElement according to certain rules.

protected virtual void Validate(ref IList<PropertyValidationMessage> messages, bool validateRecursively)

Parameters

messages IList<PropertyValidationMessage>

An list of strings that stores that picks up the validation errors of a model element.

validateRecursively Boolean

Indicates wheter to validate only the current model element or all its children (recursively) as well.

Remarks

The rules the ModelElement is validated against are dependent on the type of ModelElement that is validated. This method can be overridden to provide custom validation behavior for subclasses of ModelElement

When Validate(ref IList<PropertyValidationMessage>, Boolean) is called on a modelelement, the Validate(ref IList<PropertyValidationMessage>, Boolean) method of all children attatched to the modelelemnt are validated recursivly.