Table of Contents

Class EntityObject

Namespace
TimeCockpit.Data
Assembly
TimeCockpit.Data.dll

Represents an instance of a ModelEntityBase.

public class EntityObject : DynamicObject, IDynamicMetaObjectProvider, INotifyPropertyChanged, IEntityObject, IComparable
Inheritance
Object
EntityObject
Implements
IDynamicMetaObjectProvider
INotifyPropertyChanged
IComparable
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Extension Methods

Constructors

EntityObject()

Initializes a new instance of the EntityObject class.

public EntityObject()

Properties

CreationVersion

Gets the creation version of the EntityObject

public ulong CreationVersion { get; }

Property Value

UInt64

Entity

Gets or sets the ModelEntityBase of the object.

public ModelEntityBase Entity { get; protected set; }

Property Value

ModelEntityBase

IsChanged

Gets a value indicating whether the object was changed. See also OnPropertyChanged(String, Object, Object).

public bool IsChanged { get; }

Property Value

Boolean

IsCloned

Gets a value indicating whether this instance is cloned.

public bool IsCloned { get; }

Property Value

Boolean

IsDeleted

Gets a value indicating whether the object was deleted. See also OnPropertyChanged(String, Object, Object).

public bool IsDeleted { get; }

Property Value

Boolean

IsNew

Gets a value indicating whether the object is new. See also OnPropertyChanged(String, Object, Object).

public bool IsNew { get; }

Property Value

Boolean

IsReadOnly

Gets a value indicating whether an EntityObject is locked depending on the TimeCockpit.Data.DataModel.ModelEntityBase.ReadOnlyFunction.

public bool IsReadOnly { get; }

Property Value

Boolean

Remarks

If the ModelEntityBase that underlies the current EntityObject has no ReadOnlyExpression set the property always returns false. If the ModelEntityBase has a ReadOnlyExpression set, it is evaluated with the values of the current EntityObject an returns a boolean value accordingly.

Item[String]

Gets the value of a specified member

public object this[string propertyName] { get; set; }

Parameters

propertyName String

The name of the member to get the value for.

Property Value

Object

Returns the value of the specified member.

Remarks

Internally, this indexer calls GetMember(String) and SetMember(String, Object). The indexer was introduced for the use in IronPython, where no GetMember(String) or SetMember(String, Object) can be called. Without the indexer it was not possible in Python to run through the properties/ relations of a ModelEntityBase and set the values of a dependent EntityObject.

LastUpdateVersion

Gets the update version of the EntityObject

public ulong LastUpdateVersion { get; }

Property Value

UInt64

LocalizedPropertyValues

Gets the localized property values.

public LocalizedTextPropertyCollection LocalizedPropertyValues { get; }

Property Value

LocalizedTextPropertyCollection

Me

Gets the it self

public EntityObject Me { get; }

Property Value

EntityObject

Remarks

This property is needed for DataBinding reasons. Whenever a property of an EntityObject is changed (e.g. via z.SetMember("X", "Y")), the OnPropertyChanged(String, Object, Object) event of that property + the OnPropertyChanged(String, Object, Object) event of the Me property is fired.

ModelEntityName

Gets the name of the current instance of EntityObject

public string ModelEntityName { get; }

Property Value

String

ObjectUuid

Gets the unique id of the object.

public Guid ObjectUuid { get; }

Property Value

Guid

Permission

Gets the permissions of an EntityObject

public PermissionType Permission { get; }

Property Value

PermissionType

RelationIdentifiers

Gets the relation identifiers for the EntityObject

public RelationIdentifiers RelationIdentifiers { get; }

Property Value

RelationIdentifiers

States

Gets a dictionary of property states for an object.

protected MemberStatus[] States { get; }

Property Value

MemberStatus[]

Values

Gets a dictionary of values for an object.

protected object[] Values { get; }

Property Value

Object[]

Methods

CalculateMember(String)

Evaluates a formla, applies it to this EntityObject and returns the result.

public object CalculateMember(string formula)

Parameters

formula String

Formla to evaluate

Returns

Object

Result of the formula

Exceptions

System.NullReferenceException

might throw a NullReferenceException.

See Also

Clone()

Makes a deep clone an EntityObject while preserving the type of the underlying ModelEntityBase.

public EntityObject Clone()

Returns

EntityObject

A cloned entity object

Clone(Boolean)

Makes a deep clone an EntityObject while preserving the type of the underlying ModelEntityBase.

public EntityObject Clone(bool deepClone)

Parameters

deepClone Boolean

if set to true the instances of EntityObject are created with a new id.

Returns

EntityObject

A cloned entity object

Clone(Boolean, Boolean)

Makes a deep clone an EntityObject while preserving the type of the underlying ModelEntityBase.

public EntityObject Clone(bool deepClone, bool resetMembersInReadonlyExpression)

Parameters

deepClone Boolean

if set to true the instances of EntityObject are created with a new id.

resetMembersInReadonlyExpression Boolean

if set to true [reset members in readonly expression].

Returns

EntityObject

A cloned entity object

Clone(Boolean, Boolean, Environment)

Makes a deep clone an EntityObject while preserving the type of the underlying ModelEntityBase.

public EntityObject Clone(bool deepClone, bool resetMembersInReadonlyExpression, Environment environment)

Parameters

deepClone Boolean

if set to true the instances of EntityObject are created with a new id.

resetMembersInReadonlyExpression Boolean

if set to true [reset members in readonly expression].

environment Environment

An instance of environment to perform permission validation.

Returns

EntityObject

A cloned entity object

Clone(ModelEntityBase)

Makes a deep clone of an EntityObject but does not preserve the orignial ModelEntityBase.

public EntityObject Clone(ModelEntityBase entity)

Parameters

entity ModelEntityBase

The ModelEntityBase that the cloned EntityObject should base on.

Returns

EntityObject

A cloned instance of an EntityObject.

CompareTo(Object)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

public int CompareTo(object obj)

Parameters

obj Object

An object to compare with this instance.

Returns

Int32

A value that indicates the relative order of the objects being compared.

CopyTo(EntityObject)

Copies the values of an instance of an EntityObject to another instance. This method only copies first level relations and properties. ///

public void CopyTo(EntityObject target)

Parameters

target EntityObject

The target EntityObject.

Deserialize(String, EntityObject, Model)

Deserializes an EntityObject from a string in XML format.

public static EntityObject Deserialize(string data, EntityObject parentEntity, Model model)

Parameters

data String

An instance of EntityObject in XML representation.

parentEntity EntityObject

The parent EntityObject

model Model

An instance of Model to fetch type information about the EntityObject's underlying ModelEntityBase.

Returns

EntityObject

An instance of EntityObject deserialized from XML

Deserialize(XElement, EntityObject, Model)

Deserializes an EntityObject from a string in XML format.

public static EntityObject Deserialize(XElement root, EntityObject parentEntity, Model model)

Parameters

root XElement

System.Xml.Linq.XElement from the XML parser

parentEntity EntityObject

The parent EntityObject

model Model

An instance of Model

Returns

EntityObject

The deserialized instance of EntityObject

Remarks

For EntityObject that have relations, this method calls itself recursively to deserialize all the properties/ relations of an EntityObject. See also Serialize().

Exceptions

UnknownEncodingException

If the propertyEncoding attribute is present in the XML to deserialize and it is set to another value than 'Base64' this method throws a UnknownEncodingException.

Evaluate<T>(String)

Evaluates the specified expression and returns a compiled function

public T Evaluate<T>(string expression)

Parameters

expression String

The expression that should be compiled.

Returns

T

The result of the expression when applied to the instance of the EntityObject.

Type Parameters

T

The datatype the result of the expression should be casted to

Evaluate<T>(String, Environment, IEnumerable<QueryParameter>)

Evaluates the specified expression and returns a compiled function

public T Evaluate<T>(string expression, Environment environment, IEnumerable<QueryParameter> parameters = null)

Parameters

expression String

The expression that should be compiled.

environment Environment

An instance of Environment that has to be supplied, if the expression referenes Environment variables

parameters IEnumerable<QueryParameter>

The parameters that are passed to the expression.

Returns

T

The result of the expression when applied to the instance of the EntityObject.

Type Parameters

T

The datatype the result of the expression should be casted to

GetActualMember(String)

Gets the actual value of the specified member.

public virtual object GetActualMember(string name)

Parameters

name String

Name of the member.

Returns

Object

Returns the actual value of the specified member. The default implementation of this method calls GetMember(String). However, classes that implement specific business logic in GetMember(String) that should be available from scripts but should NOT be used for saving objects' values to the database can override GetActualMember.

GetChangedMembers()

Gets a list of member names that have the status Changed

public IEnumerable<string> GetChangedMembers()

Returns

IEnumerable<String>

A list of member name that have the status Changed

GetMember(Int32)

Gets the value of the specified member.

public object GetMember(int index)

Parameters

index Int32

Index of the member.

Returns

Object

Returns the value of the specified member.

GetMember(String)

Gets the value of the specified member.

public override object GetMember(string name)

Parameters

name String

Name of the member.

Returns

Object

Returns the value of the specified member.

Remarks

This method also returns the clr properties '{ModelEntityName}Uuid' and 'IsReadOnly' of an EntityObject.

GetMembersByState(MemberStatus)

Gets a list of member names that have the requested state.

public IEnumerable<string> GetMembersByState(MemberStatus state)

Parameters

state MemberStatus

Reqested state.

Returns

IEnumerable<String>

A list of member name that have the requested state.

GetMetaObject(Expression)

Gets the meta object of the dynamic object.

public override DynamicMetaObject GetMetaObject(Expression parameter)

Parameters

parameter Expression

Provided by the DLR (Dynamic Language Runtime).

Returns

DynamicMetaObject

System.Dynamic.DynamicMetaObject that represents this specific object’s binding logic.

GetPropertyIndex(String)

Gets ContentMap index for a name.

protected virtual int GetPropertyIndex(string name)

Parameters

name String

Name of the property to get ContentMap index for.

Returns

Int32

The ContentMap index of the Prooperty. Value is -1 if property does not exists in ContentMap

GetValidationMessages(NameLocalizer)

Gets the validation messages.

public IEnumerable<ValidationMessage> GetValidationMessages(NameLocalizer localizer)

Parameters

localizer NameLocalizer

The localizer to use for localizing validation rules.

Returns

IEnumerable<ValidationMessage>

Iterates the validation messages.

HasPermission(String, PermissionType)

Checks if a user has a permission of a certain type.

public bool HasPermission(string memberName, PermissionType permissionType)

Parameters

memberName String

The name of the property to check for permission.

permissionType PermissionType

The type of the permission (see also PermissionType)

Returns

Boolean

True, if the property has the same permission as permissionIdentifier, else false.

MarkAsDeleted()

Marks the object as deleted.

public void MarkAsDeleted()

MarkAsNew(Boolean)

Marks an entity object as new

public void MarkAsNew(bool resetMemberStates = true)

Parameters

resetMemberStates Boolean

Indicates whether the member states and IssChanged should be adjusted.

OnPropertyChanged(Int32, Object, Object)

Invoked whenever the value of any property on this object has been updated. The specific property that changed is reported in the event data.

protected virtual void OnPropertyChanged(int index, object previousValue, object currentValue)

Parameters

index Int32

Index of the property that has been updated.

previousValue Object

the previous value of the property.

currentValue Object

the currentValue of the property.

Remarks

This method sets a property in the Values collection of an EntityObject to MemberStatus.Changed. Each call of the method calls OnPropertyChanged for the clr properties 'IsNew', 'IsChanged', 'Me', 'IsReadonly'.

OnPropertyChanged(String, Object, Object)

Invoked whenever the value of any property on this object has been updated. The specific property that changed is reported in the event data.

protected virtual void OnPropertyChanged(string propertyName, object previousValue, object currentValue)

Parameters

propertyName String

Name of the property that has been updated.

previousValue Object

the previous value of the property.

currentValue Object

the current value of the property.

Remarks

This method sets a property in the Values collection of an EntityObject to MemberStatus.Changed. Each call of the method calls OnPropertyChanged for the clr properties 'Me', 'IsReadonly'.

Serialize()

Serializes an EntityObject in XML

public XmlReader Serialize()

Returns

XmlReader

An instance of an System.Xml.XmlReader representing the serialized EntityObject.

Serialize(Boolean)

Serializes an EntityObject in XML.

public XmlReader Serialize(bool idsOnly)

Parameters

idsOnly Boolean

Determines whether to serialize the whole entity object in case of a relation or just the identifier or the relation.

Returns

XmlReader

An instance of an System.Xml.XmlReader representig EntityObject.

Remarks

If the EntityObject that should be serialized has not been attatched to an instance of Model the method serializes the type information of the underlying ModelEntityBase as well. During deserialization (see Deserialize(String, EntityObject, Model)) the ModelEntityBase type is reconstructed and the EntityObject can be deserialized on its basis.

This method serializes an EntityObject in UTF8 XML

This method serializes properties of a EntityObject by converting their value into a Base64 string. Therefore, e.g. a TextProperty can contain all ASCII character. If the values would not be encoded, control characters e.g. would lead to invalid XML.

Serialize(XmlWriter, Boolean)

Writes the XML representation of an EntityObject to a predifined instance of System.Xml.XmlWriter.

public void Serialize(XmlWriter xmlWriter, bool idsOnly)

Parameters

xmlWriter XmlWriter

The System.Xml.XmlWriter to write to.

idsOnly Boolean

Determines whether to serialize the whole EntityObject in case of a relation or just the identifier of the relations.

Remarks

If the EntityObject that should be serialized has not been attatched to an instance of Model the method serializes the type information of the underlying ModelEntityBase as well. During deserialization (see Deserialize(String, EntityObject, Model)) the ModelEntityBase type is reconstructed and the EntityObject can be deserialized on its basis.

This method serializes an EntityObject in UTF8 XML

This method serializes properties of a EntityObject by converting their value into a Base64 string. Therefore, e.g. a TextProperty can contain all ASCII character. If the values would not be encoded, control characters e.g. would lead to invalid XML.

SetMember(Int32, Object)

Sets a dynamic member.

public void SetMember(int index, object value)

Parameters

index Int32

Index of the member to set.

value Object

Value to set.

SetMember(String, Object)

Sets a dynamic member.

public override void SetMember(string name, object value)

Parameters

name String

Name of the member to set.

value Object

Value to set.

SetMember(String, Object, Boolean, Boolean)

Sets a dynamic member.

public void SetMember(string name, object value, bool initialization, bool ignoreDefaultValues = false)

Parameters

name String

Name of the member to set.

value Object

Value to set.

initialization Boolean

Indicates if SetMember is called during initialization of the object.

ignoreDefaultValues Boolean

Indicates that no default values are set if this flag is set to true. Default is false

ToString()

Returns a System.String that represents this instance.

public override string ToString()

Returns

String

A System.String that represents this instance.

Remarks

This methods returns the value of the default display property as string. If the default display property happens to be a relation, it returns the value of the default display property of the EntityObject that is behind the relation.

Validate(out List<String>, out List<ValidationRule>, NameLocalizer)

Validates all values (properties and relations) of an instance of an EntityObject

public bool Validate(out List<string> errorMessages, out List<ValidationRule> failingValidationRules, NameLocalizer localizer)

Parameters

errorMessages List<String>

The error messages provided by the failing ValidationRules.

failingValidationRules List<ValidationRule>

The ValidationRules that raised the validation error

localizer NameLocalizer

The NameLocalizer used to get the correct localizations for properties and validation rules.

Returns

Boolean

True if the EntityObject validates o.k, else false

Remarks

Validate(String, out String, out ValidationRule, NameLocalizer)

Validates a property of an instance of EntityObject in accordance to the ValidationRules defined in the underlying ModelEntityBase.

public bool Validate(string name, out string message, out ValidationRule failingValidationRule, NameLocalizer localizer)

Parameters

name String

The name of the property that is to be validated.

message String

An error message provided by the failing ValidationRule.

failingValidationRule ValidationRule

The ValidationRule that raised the validation error.

localizer NameLocalizer

The NameLocalizer used to get the correct localizations for properties and validation rules.

Returns

Boolean

True if the EntityObject validates o.k, else false.

Exceptions

System.NullReferenceException

This method throws a System.NullReferenceException if a ValidationRule contains a condition that contains a reference to a relation which is null. :Iif(Current.Project.ProjectUuid = Current.Task.Project.ProjectUuid, True, False) If 'Project' in Current.Task.Project is null, the latter example throws a System.NullReferenceException. This is because up to now nullable/notnullable relations do no exists (NOT YET).

Events

PropertyChanged

Occurs after the value of an application settings property is changed.

public event PropertyChangedEventHandler PropertyChanged

Event Type

PropertyChangedEventHandler