/// <summary> /// Creates a new instance of the specified type of entity. /// </summary> /// <param name="shortTypeName">The short name of the type of entity to create an instance of.</param> public override IEntity Create() { // TODO: Check if needed. Should be unnecessary ISubEntity entity = null; using (LogGroup logGroup = LogGroup.Start("Creating a new entity of type '" + TypeName + "'.", NLog.LogLevel.Debug)) { if (!EntityState.IsType(TypeName)) { throw new InvalidOperationException("The TypeName property needs to be set to the type of an entity. Invalid type: " + TypeName); } Type type = EntityState.GetType(TypeName); LogWriter.Debug("Authorisation required: " + RequireAuthorisation.ToString()); if (RequireAuthorisation) { AuthoriseCreateStrategy.New(TypeName).EnsureAuthorised(TypeName); } entity = (ISubEntity)base.Create(); entity.ID = Guid.NewGuid(); } return(entity); }
/// <summary> /// Index the entity with a references that matches the provided parameters. /// </summary> /// <param name="propertyName">The name of the property containing the references.</param> /// <param name="referencedEntityType">The type of the entity being referenced.</param> /// <param name="referencedEntityID">The ID of the entity being referenced.</param> /// <returns>The entity matching the provided parameters.</returns> public virtual IEntity[] IndexWithReference(string propertyName, string referencedEntityType, Guid referencedEntityID) { IEntity[] entities = new IEntity[] {}; using (LogGroup logGroup = LogGroup.Start("Indexing entities that have the specified reference.", NLog.LogLevel.Debug)) { LogWriter.Debug("Type name: " + TypeName); LogWriter.Debug("Property name: " + propertyName); LogWriter.Debug("Reference entity type: " + referencedEntityType); LogWriter.Debug("Referenced entity ID: " + referencedEntityID.ToString()); LogWriter.Debug("Enable paging: " + EnablePaging.ToString()); LogWriter.Debug("Require authorisation: " + RequireAuthorisation.ToString()); entities = (IEntity[])Reflector.InvokeGenericMethod(this, "IndexWithReference", new Type[] { EntityState.Entities[TypeName].GetEntityType() }, new object[] { propertyName, referencedEntityType, referencedEntityID }); if (RequireAuthorisation) { AuthoriseIndexStrategy.New(TypeName).EnsureAuthorised(ref entities); } React(entities); LogWriter.Debug("Entity count: " + entities.Length); } return(entities); }
/// <summary> /// Retrieves the entities of the specified type. /// </summary> /// <returns></returns> public virtual T[] Index <T>() where T : IEntity { T[] entities = new T[] {}; using (LogGroup logGroup = LogGroup.Start("Indexing entities that have the specified reference.", NLog.LogLevel.Debug)) { LogWriter.Debug("Type name: " + typeof(T).ToString()); LogWriter.Debug("Enable paging: " + EnablePaging.ToString()); LogWriter.Debug("Require authorisation: " + RequireAuthorisation.ToString()); if (EnablePaging) { entities = DataAccess.Data.Indexer.GetPageOfEntities <T>(Location, SortExpression); } else { entities = DataAccess.Data.Indexer.GetEntities <T>(); } if (RequireAuthorisation) { AuthoriseIndexStrategy.New <T>().EnsureAuthorised(ref entities); } LogWriter.Debug("Entity count: " + entities.Length); AssignStrategies(entities); React(entities); } return(entities); }
public BaseProjection(string action, Type type, bool requireAuthorisation) { using (LogGroup logGroup = LogGroup.StartDebug("Constructing projection object.")) { LogWriter.Debug("Action: " + action); LogWriter.Debug("Type: " + type.Name); LogWriter.Debug("RequireAuthorisation: " + RequireAuthorisation.ToString()); Command = new CommandInfo(action, type.Name); RequireAuthorisation = requireAuthorisation; } }
/// <summary> /// Indexes the entity with a references that matches the provided parameters. /// </summary> /// <param name="propertyName">The name of the property containing the references.</param> /// <param name="referencedEntityType">The type of the entity being referenced.</param> /// <param name="referencedEntityID">The ID of the entity being referenced.</param> /// <returns>The entity matching the provided parameters.</returns> public virtual T[] IndexWithReference <T>(string propertyName, string referencedEntityType, Guid referencedEntityID) where T : IEntity { T[] entities = new T[] {}; using (LogGroup logGroup = LogGroup.Start("Indexing entities that have the specified reference.", NLog.LogLevel.Debug)) { LogWriter.Debug("Type name: " + typeof(T).ToString()); LogWriter.Debug("Property name: " + propertyName); LogWriter.Debug("Reference entity type: " + referencedEntityType); LogWriter.Debug("Referenced entity ID: " + referencedEntityID.ToString()); LogWriter.Debug("Enable paging: " + EnablePaging.ToString()); LogWriter.Debug("Require authorisation: " + RequireAuthorisation.ToString()); if (EnablePaging) { entities = (T[])DataAccess.Data.Indexer.GetPageOfEntitiesWithReference <T>(propertyName, EntityState.GetType(referencedEntityType), referencedEntityID, Location, sortExpression); } else { entities = (T[])DataAccess.Data.Indexer.GetEntitiesWithReference <T>(propertyName, EntityState.GetType(referencedEntityType), referencedEntityID); } if (RequireAuthorisation) { AuthoriseIndexStrategy.New <T>().EnsureAuthorised <T>(ref entities); } LogWriter.Debug("Entity count: " + entities.Length); AssignStrategies(entities); React(entities); } return(entities); }