public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { UserAssetsImporter.RegisterName <UserChartEntity>("UserChart"); sb.Schema.Synchronizing += Schema_Synchronizing; sb.Include <UserChartEntity>() .WithSave(UserChartOperation.Save) .WithDelete(UserChartOperation.Delete) .WithQuery(() => uq => new { Entity = uq, uq.Id, uq.Query, uq.EntityType, uq.DisplayName, uq.ChartScript, }); sb.Schema.EntityEvents <UserChartEntity>().Retrieved += ChartLogic_Retrieved; sb.Schema.Table <QueryEntity>().PreDeleteSqlSync += e => Administrator.UnsafeDeletePreCommand(Database.Query <UserChartEntity>().Where(a => a.Query == e)); UserCharts = sb.GlobalLazy(() => Database.Query <UserChartEntity>().ToDictionary(a => a.ToLite()), new InvalidateWith(typeof(UserChartEntity))); UserChartsByQuery = sb.GlobalLazy(() => UserCharts.Value.Values.Where(a => a.EntityType == null).SelectCatch(uc => KeyValuePair.Create(uc.Query.ToQueryName(), uc.ToLite())).GroupToDictionary(), new InvalidateWith(typeof(UserChartEntity))); UserChartsByTypeForQuickLinks = sb.GlobalLazy(() => UserCharts.Value.Values.Where(a => a.EntityType != null && !a.HideQuickLink) .SelectCatch(a => KeyValuePair.Create(TypeLogic.IdToType.GetOrThrow(a.EntityType !.Id), a.ToLite())) .GroupToDictionary(), new InvalidateWith(typeof(UserChartEntity))); } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { QueryLogic.Start(sb, dqm); PermissionAuthLogic.RegisterPermissions(UserQueryPermission.ViewUserQuery); UserAssetsImporter.RegisterName <UserQueryEntity>("UserQuery"); sb.Schema.Synchronizing += Schema_Synchronizing; sb.Schema.Table <QueryEntity>().PreDeleteSqlSync += e => Administrator.UnsafeDeletePreCommand(Database.Query <UserQueryEntity>().Where(a => a.Query == e)); sb.Include <UserQueryEntity>() .WithSave(UserQueryOperation.Save) .WithDelete(UserQueryOperation.Delete) .WithQuery(dqm, () => uq => new { Entity = uq, uq.Query, uq.Id, uq.DisplayName, uq.EntityType, }); sb.Schema.EntityEvents <UserQueryEntity>().Retrieved += UserQueryLogic_Retrieved; UserQueries = sb.GlobalLazy(() => Database.Query <UserQueryEntity>().ToDictionary(a => a.ToLite()), new InvalidateWith(typeof(UserQueryEntity))); UserQueriesByQuery = sb.GlobalLazy(() => UserQueries.Value.Values.Where(a => a.EntityType == null).GroupToDictionary(a => a.Query.ToQueryName(), a => a.ToLite()), new InvalidateWith(typeof(UserQueryEntity))); UserQueriesByType = sb.GlobalLazy(() => UserQueries.Value.Values.Where(a => a.EntityType != null).GroupToDictionary(a => TypeLogic.IdToType.GetOrThrow(a.EntityType.Id), a => a.ToLite()), new InvalidateWith(typeof(UserQueryEntity))); } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { GetDashboard = GetDashboardDefault; PermissionAuthLogic.RegisterPermissions(DashboardPermission.ViewDashboard); UserAssetsImporter.RegisterName <DashboardEntity>("Dashboard"); UserAssetsImporter.PartNames.AddRange(new Dictionary <string, Type> { { "UserChartPart", typeof(UserChartPartEntity) }, { "UserQueryPart", typeof(UserQueryPartEntity) }, { "LinkListPart", typeof(LinkListPartEntity) }, { "ValueUserQueryListPart", typeof(ValueUserQueryListPartEntity) }, }); sb.Include <DashboardEntity>() .WithQuery(dqm, () => cp => new { Entity = cp, cp.Id, cp.DisplayName, cp.EntityType, cp.Owner, cp.DashboardPriority, }); sb.Include <LinkListPartEntity>() .WithQuery(dqm, () => cp => new { Entity = cp, ToStr = cp.ToString(), Links = cp.Links.Count }); sb.Include <ValueUserQueryListPartEntity>() .WithQuery(dqm, () => cp => new { Entity = cp, ToStr = cp.ToString(), Links = cp.UserQueries.Count }); if (sb.Settings.ImplementedBy((DashboardEntity cp) => cp.Parts.First().Content, typeof(UserQueryPartEntity))) { sb.Schema.EntityEvents <UserQueryEntity>().PreUnsafeDelete += query => { Database.MListQuery((DashboardEntity cp) => cp.Parts).Where(mle => query.Contains(((UserQueryPartEntity)mle.Element.Content).UserQuery)).UnsafeDeleteMList(); Database.Query <UserQueryPartEntity>().Where(uqp => query.Contains(uqp.UserQuery)).UnsafeDelete(); }; sb.Schema.Table <UserQueryEntity>().PreDeleteSqlSync += arg => { var uq = (UserQueryEntity)arg; var parts = Administrator.UnsafeDeletePreCommand((DashboardEntity cp) => cp.Parts, Database.MListQuery((DashboardEntity cp) => cp.Parts) .Where(mle => ((UserQueryPartEntity)mle.Element.Content).UserQuery == uq)); var parts2 = Administrator.UnsafeDeletePreCommand(Database.Query <UserQueryPartEntity>() .Where(mle => mle.UserQuery == uq)); return(SqlPreCommand.Combine(Spacing.Simple, parts, parts2)); }; } if (sb.Settings.ImplementedBy((DashboardEntity cp) => cp.Parts.First().Content, typeof(UserChartPartEntity))) { sb.Schema.EntityEvents <UserChartEntity>().PreUnsafeDelete += query => { Database.MListQuery((DashboardEntity cp) => cp.Parts).Where(mle => query.Contains(((UserChartPartEntity)mle.Element.Content).UserChart)).UnsafeDeleteMList(); Database.Query <UserChartPartEntity>().Where(uqp => query.Contains(uqp.UserChart)).UnsafeDelete(); }; sb.Schema.Table <UserChartEntity>().PreDeleteSqlSync += arg => { var uc = (UserChartEntity)arg; var parts = Administrator.UnsafeDeletePreCommand((DashboardEntity cp) => cp.Parts, Database.MListQuery((DashboardEntity cp) => cp.Parts) .Where(mle => ((UserChartPartEntity)mle.Element.Content).UserChart == uc)); var parts2 = Administrator.UnsafeDeletePreCommand(Database.Query <UserChartPartEntity>() .Where(mle => mle.UserChart == uc)); return(SqlPreCommand.Combine(Spacing.Simple, parts, parts2)); }; } DashboardGraph.Register(); Dashboards = sb.GlobalLazy(() => Database.Query <DashboardEntity>().ToDictionary(a => a.ToLite()), new InvalidateWith(typeof(DashboardEntity))); DashboardsByType = sb.GlobalLazy(() => Dashboards.Value.Values.Where(a => a.EntityType != null) .GroupToDictionary(a => TypeLogic.IdToType.GetOrThrow(a.EntityType.Id), a => a.ToLite()), new InvalidateWith(typeof(DashboardEntity))); } }