Class EntityObject
- Namespace
- TimeCockpit.Data
- Assembly
- TimeCockpit.Data.dll
Represents an instance of a ModelEntityBase.
public class EntityObject : DynamicObject, IDynamicMetaObjectProvider, INotifyPropertyChanged, IEntityObject, IComparable
- Inheritance
-
ObjectEntityObject
- Implements
-
IDynamicMetaObjectProviderINotifyPropertyChangedIComparable
- 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
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
propertyNameStringThe 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
Me
Gets the it self
public EntityObject Me { get; }
Property Value
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
RelationIdentifiers
Gets the relation identifiers for the EntityObject
public RelationIdentifiers RelationIdentifiers { get; }
Property Value
States
Gets a dictionary of property states for an object.
protected MemberStatus[] States { get; }
Property Value
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
formulaStringFormla 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
deepCloneBooleanif set to
truethe 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
deepCloneBooleanif set to
truethe instances of EntityObject are created with a new id.resetMembersInReadonlyExpressionBooleanif 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
deepCloneBooleanif set to
truethe instances of EntityObject are created with a new id.resetMembersInReadonlyExpressionBooleanif set to
true[reset members in readonly expression].environmentEnvironmentAn 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
entityModelEntityBaseThe 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
objObjectAn 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
targetEntityObjectThe 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
dataStringAn instance of EntityObject in XML representation.
parentEntityEntityObjectThe parent EntityObject
modelModelAn 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
rootXElementSystem.Xml.Linq.XElement from the XML parser
parentEntityEntityObjectThe parent EntityObject
modelModelAn 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
expressionStringThe expression that should be compiled.
Returns
- T
The result of the expression when applied to the instance of the EntityObject.
Type Parameters
TThe 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
expressionStringThe expression that should be compiled.
environmentEnvironmentAn instance of Environment that has to be supplied, if the expression referenes Environment variables
parametersIEnumerable<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
TThe 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
nameStringName 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
indexInt32Index 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
nameStringName 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
stateMemberStatusReqested 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
parameterExpressionProvided 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
nameStringName 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
localizerNameLocalizerThe 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
memberNameStringThe name of the property to check for permission.
permissionTypePermissionTypeThe 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
resetMemberStatesBooleanIndicates 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
indexInt32Index of the property that has been updated.
previousValueObjectthe previous value of the property.
currentValueObjectthe 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
propertyNameStringName of the property that has been updated.
previousValueObjectthe previous value of the property.
currentValueObjectthe 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
idsOnlyBooleanDetermines 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
xmlWriterXmlWriterThe System.Xml.XmlWriter to write to.
idsOnlyBooleanDetermines 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
indexInt32Index of the member to set.
valueObjectValue to set.
SetMember(String, Object)
Sets a dynamic member.
public override void SetMember(string name, object value)
Parameters
nameStringName of the member to set.
valueObjectValue to set.
SetMember(String, Object, Boolean, Boolean)
Sets a dynamic member.
public void SetMember(string name, object value, bool initialization, bool ignoreDefaultValues = false)
Parameters
nameStringName of the member to set.
valueObjectValue to set.
initializationBooleanIndicates if SetMember is called during initialization of the object.
ignoreDefaultValuesBooleanIndicates 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
errorMessagesList<String>The error messages provided by the failing ValidationRules.
failingValidationRulesList<ValidationRule>The ValidationRules that raised the validation error
localizerNameLocalizerThe NameLocalizer used to get the correct localizations for properties and validation rules.
Returns
- Boolean
True if the EntityObject validates o.k, else false
Remarks
Internally, this method calls Validate(String, out String, out ValidationRule, NameLocalizer)
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
nameStringThe name of the property that is to be validated.
messageStringAn error message provided by the failing ValidationRule.
failingValidationRuleValidationRuleThe ValidationRule that raised the validation error.
localizerNameLocalizerThe 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