/// <summary> /// Get the default display report for the given <see cref="EntityType" />. /// If there is no display report, do a breadth-first recursion through /// the inherited types to find a suitable display report. /// </summary> /// <param name="securableEntity"> /// The type (or other <see cref="SecurableEntity" /> the report will be for. /// Note that the current implementation requires this to be an <see cref="EntityType" />. /// </param> /// <param name="structuredQuery"> /// An optional <see cref="StructuredQuery" /> to use for the report.. /// </param> /// <returns> /// A <see cref="ReadiNow.Model.Report" /> or null, if not report is found. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="securableEntity" /> cannot be null. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="securableEntity" /> must be an <see cref="EntityType" />. /// </exception> public Report GetDisplayReportForSecurableEntity(SecurableEntity securableEntity, StructuredQuery structuredQuery = null) { if (securableEntity == null) { throw new ArgumentNullException("securableEntity"); } // TODO: Test the RootEntity of structuredQuery to ensure it is the correct ype. var entityType = securableEntity.As <EntityType>( ); if (entityType == null) { throw new ArgumentException(@"securableEntity is not an EntityType", "securableEntity"); } // Place in separate, uniquely named folder to ensure (1) security reports // do not appear inthe UI elsewhere and (2) the report name resource key // does not block the saving of the report. Folder folder = Model.Entity.Create <Folder>( ); folder.Name = string.Format("{0}{1}", Guid.NewGuid( ), DateTime.Now); folder.Save( ); // The report creation code is hardly the most efficient but // it has been working reliably in automated tests. This operation // also occurs rarely. if (structuredQuery == null) { string typeName = entityType.Name ?? "Name"; structuredQuery = CreateEntitiesQuery(entityType, typeName); } Report result = ToReport(structuredQuery); result.Name = entityType.Name ?? DefaultReportName; result.Description = string.Empty; result.ResourceInFolder.Add(folder.As <NavContainer>( )); // For cascading deletes result.Save( ); return(result); }