/// <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); }
/// <summary> /// Retrieves the entities matching the provided filter group. /// </summary> /// <param name="group"></param> /// <returns></returns> public virtual T[] Index <T>(IDataFilterGroup group) where T : IEntity { T[] entities = new T[] {}; if (EnablePaging) { entities = Collection <T> .ConvertAll(DataAccess.Data.Indexer.GetPageOfEntities <T>(group, Location, SortExpression)); } else { entities = Collection <T> .ConvertAll(DataAccess.Data.Indexer.GetEntities <T>(group, SortExpression)); } if (RequireAuthorisation) { AuthoriseIndexStrategy.New <T>().EnsureAuthorised(ref entities); } AssignStrategies(entities); React(entities); return(entities); }
/// <summary> /// Retrieves the entities with the specified IDs. /// </summary> /// <param name="ids">The IDs of the entities to retrieve.</param> /// <returns>An array of the entities matching the provided IDs.</returns> public virtual T[] Index <T>(Guid[] ids) where T : IEntity { Collection <T> list = new Collection <T>(); IRetrieveStrategy retriever = RetrieveStrategy.New <T>(RequireAuthorisation); foreach (Guid id in ids) { T entity = retriever.Retrieve <T>(id); list.Add(entity); } T[] entities = list.ToArray(); if (RequireAuthorisation) { AuthoriseIndexStrategy.New <T>().EnsureAuthorised(ref entities); } React(entities); return(entities); }
/// <summary> /// Ensures that the user is authorised to index entities of the specified type. /// </summary> /// <param name="entities">The entities involved in the authorisation check.</param> /// <returns>A value indicating whether the user is authorised.</returns> public IEntity[] Authorise(IEntity[] entities) { IEntity[] output = new IEntity[] {}; using (LogGroup logGroup = LogGroup.StartDebug("Authorising the display of the provided entities.")) { LogWriter.Debug("# before: " + entities.Length); output = AuthoriseIndexStrategy.New(Command.TypeName, Container.RequireAuthorisation).Authorise(entities); LogWriter.Debug("# after: " + output.Length); } return(output); }
/// <summary> /// Retrieves the entities of the specified type with the sort expression applied. /// </summary> /// <param name="sortExpression"></param> /// <returns></returns> public virtual IEntity[] Index() { CheckTypeName(); Type type = EntityState.GetType(TypeName); IEntity[] entities = Collection <IEntity> .ConvertAll(Reflector.InvokeGenericMethod(this, // Source object "Index", // Method name new Type[] { type }, // Generic types new object[] {})); // Method arguments); if (RequireAuthorisation) { AuthoriseIndexStrategy.New(TypeName).EnsureAuthorised(ref entities); } React(entities); return(entities); }
/// <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); }
/// <summary> /// Retrieves the entities matching the provided filter values. /// </summary> /// <param name="filterValues"></param> /// <returns></returns> public virtual IEntity[] Index(Dictionary <string, object> filterValues) { Type type = EntityState.GetType(TypeName); if (type == null) { throw new InvalidOperationException("Type not found."); } IEntity[] entities = Collection <IEntity> .ConvertAll( Reflector.InvokeGenericMethod(this, // Source object "Index", // Method name new Type[] { type }, // Generic types new object[] { filterValues })); // Method arguments); if (RequireAuthorisation) { AuthoriseIndexStrategy.New(TypeName).EnsureAuthorised(ref entities); } React(entities); return(entities); }