Search Results for

    Show / Hide Table of Contents

    Class ModelElement

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

    Inheritance
    System.Object
    DynamicObject
    NamedDynamicObject
    ModelElement
    ModelAction
    Culture
    EntityView
    Model
    ModelEntityBase
    ModelEntityInterface
    ModelProperty
    NamedSetDefinition
    RelationBase
    Trigger
    ValidationRule
    Permission
    Implements
    System.Dynamic.IDynamicMetaObjectProvider
    System.ComponentModel.INotifyPropertyChanged
    System.ComponentModel.IDataErrorInfo
    Inherited Members
    NamedDynamicObject.OnPropertyChanged(String)
    NamedDynamicObject.PropertyChanged
    DynamicObject.GetMember(String)
    DynamicObject.SetMember(String, Object)
    DynamicObject.GetMetaObject(Expression)
    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: TimeCockpit.Data.DataModel
    Assembly: TimeCockpit.Data.dll
    Syntax
    public abstract class ModelElement : NamedDynamicObject, IDynamicMetaObjectProvider, INotifyPropertyChanged, IDataErrorInfo
    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

    Declaration
    protected ModelElement()

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

    Initializes a new instance of the ModelElement class.

    Declaration
    protected ModelElement(IEnumerable<KeyValuePair<object, object>> properties)
    Parameters
    Type Name Description
    System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Object, System.Object>> properties

    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.

    Declaration
    protected ModelElement(ModelElement element)
    Parameters
    Type Name Description
    ModelElement element

    The element to copy.

    Remarks

    Copy constructor for copying values of an instance of ModelElement.

    Properties

    Children

    Gets the children of the ModelElement.

    Declaration
    public IEnumerable<ModelElement> Children { get; }
    Property Value
    Type Description
    System.Collections.Generic.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

    Declaration
    public ulong CreationVersion { get; }
    Property Value
    Type Description
    System.UInt64

    ElementGuid

    Gets or sets the unique identifier for the model element.

    Declaration
    public Guid ElementGuid { get; set; }
    Property Value
    Type Description
    System.Guid

    Error

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

    Declaration
    public string Error { get; }
    Property Value
    Type Description
    System.String

    ErrorSummary

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

    Declaration
    public IEnumerable<PropertyValidationMessage> ErrorSummary { get; }
    Property Value
    Type Description
    System.Collections.Generic.IEnumerable<PropertyValidationMessage>

    InvariantFriendlyName

    Gets or sets a language invariant friendly name of the ModelElement

    Declaration
    public string InvariantFriendlyName { get; set; }
    Property Value
    Type Description
    System.String

    IsApplicationSpecificElement

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

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

    IsFullPersistBehavior

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

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

    IsNonePersistBehavior

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

    Declaration
    public bool IsNonePersistBehavior { get; }
    Property Value
    Type Description
    System.Boolean
    Remarks

    This property should be only user for string templating

    IsSystemElement

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

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

    IsSystemOrApplicationSpecificElement

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

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

    IsUserElement

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

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

    IsValid

    Gets a value indicating whether the ModelElement is valid or not

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

    LastUpdateVersion

    Gets the update version of the entity object

    Declaration
    public ulong LastUpdateVersion { get; }
    Property Value
    Type Description
    System.UInt64

    Name

    Gets or sets the name of the model element.

    Declaration
    public override string Name { get; set; }
    Property Value
    Type Description
    System.String
    Overrides
    NamedDynamicObject.Name
    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
    Type Condition
    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.

    Declaration
    public string NonPrefixedName { get; }
    Property Value
    Type Description
    System.String

    Ownership

    Gets or sets the ownership type of a model element.

    Declaration
    public Ownership Ownership { get; set; }
    Property Value
    Type Description
    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

    Declaration
    public string OwnershipPrefix { get; }
    Property Value
    Type Description
    System.String

    Parent

    Gets the parent element.

    Declaration
    public ModelElement Parent { get; }
    Property Value
    Type Description
    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.

    Declaration
    public virtual PersistBehavior PersistBehavior { get; set; }
    Property Value
    Type Description
    PersistBehavior
    Remarks

    The default value for this property is langword_csharp_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.

    Declaration
    public abstract void Accept(ModelElementVisitor visitor)
    Parameters
    Type Name Description
    ModelElementVisitor visitor

    the visitor to accept.

    Attach(ModelElement)

    Attaches a model element to a parent model element.

    Declaration
    protected virtual void Attach(ModelElement newParent)
    Parameters
    Type Name Description
    ModelElement newParent

    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
    Type Condition
    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.

    Declaration
    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.

    Declaration
    public static bool IsValidIdentifier(string identifier)
    Parameters
    Type Name Description
    System.String identifier

    Identifier to check.

    Returns
    Type Description
    System.Boolean

    langword_csharp_True indicates that the identifier is valid. langword_csharp_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

    Declaration
    [OnDeserializing]
    public void OnDeserializing(StreamingContext context)
    Parameters
    Type Name Description
    System.Runtime.Serialization.StreamingContext context

    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.

    Declaration
    protected void SetName(string value)
    Parameters
    Type Name Description
    System.String value

    The value to set the name of a ModelElement to.

    SetOwnership(Ownership)

    Sets the ownership of an instance of ModelElement.

    Declaration
    protected void SetOwnership(Ownership value)
    Parameters
    Type Name Description
    Ownership value

    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.

    Declaration
    protected void SetOwnershipPrefix(string prefix)
    Parameters
    Type Name Description
    System.String prefix

    A string prefix to derive the ownership from.

    SetPersistBehavior(PersistBehavior)

    Sets the persist behavior of the current ModelElement.

    Declaration
    protected virtual void SetPersistBehavior(PersistBehavior persistBehavior)
    Parameters
    Type Name Description
    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.

    Declaration
    protected void UpdateChildren(NotifyCollectionChangedEventArgs e)
    Parameters
    Type Name Description
    System.Collections.Specialized.NotifyCollectionChangedEventArgs e

    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.

    Declaration
    protected virtual void Validate(ref IList<PropertyValidationMessage> messages, bool validateRecursively)
    Parameters
    Type Name Description
    System.Collections.Generic.IList<PropertyValidationMessage> messages

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

    System.Boolean validateRecursively

    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.

    In This Article
    Back to top Copyright © 2020 software architects gmbh