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))); } }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { PermissionAuthLogic.RegisterPermissions(DashboardPermission.ViewDashboard); UserAssetsImporter.Register <DashboardEntity>("Dashboard", DashboardOperation.Save); UserAssetsImporter.PartNames.AddRange(new Dictionary <string, Type> { { "UserChartPart", typeof(UserChartPartEntity) }, { "CombinedUserChartPart", typeof(CombinedUserChartPartEntity) }, { "UserQueryPart", typeof(UserQueryPartEntity) }, { "LinkListPart", typeof(LinkListPartEntity) }, { "ValueUserQueryListPart", typeof(ValueUserQueryListPartEntity) }, { "UserTreePart", typeof(UserTreePartEntity) }, }); sb.Include <DashboardEntity>() .WithQuery(() => cp => new { Entity = cp, cp.Id, cp.DisplayName, cp.EntityType, cp.Owner, cp.DashboardPriority, }); 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(); return(null); }; sb.Schema.Table <UserQueryEntity>().PreDeleteSqlSync += arg => { var uq = (UserQueryEntity)arg; var parts = Administrator.UnsafeDeletePreCommandMList((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(); Database.MListQuery((DashboardEntity cp) => cp.Parts).Where(mle => ((CombinedUserChartPartEntity)mle.Element.Content).UserCharts.Any(uc => query.Contains(uc))).UnsafeDeleteMList(); Database.Query <CombinedUserChartPartEntity>().Where(cuqp => cuqp.UserCharts.Any(uc => query.Contains(uc))).UnsafeDelete(); return(null); }; sb.Schema.Table <UserChartEntity>().PreDeleteSqlSync += arg => { var uc = (UserChartEntity)arg; var mlistElems = Administrator.UnsafeDeletePreCommandMList((DashboardEntity cp) => cp.Parts, Database.MListQuery((DashboardEntity cp) => cp.Parts) .Where(mle => ((UserChartPartEntity)mle.Element.Content).UserChart == uc)); var parts = Administrator.UnsafeDeletePreCommand(Database.Query <UserChartPartEntity>() .Where(mle => mle.UserChart == uc)); var mlistElems2 = Administrator.UnsafeDeletePreCommandMList((DashboardEntity cp) => cp.Parts, Database.MListQuery((DashboardEntity cp) => cp.Parts) .Where(mle => ((CombinedUserChartPartEntity)mle.Element.Content).UserCharts.Contains(uc))); var parts2 = Administrator.UnsafeDeletePreCommand(Database.Query <CombinedUserChartPartEntity>() .Where(mle => mle.UserCharts.Contains(uc))); return(SqlPreCommand.Combine(Spacing.Simple, mlistElems, parts, mlistElems2, 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) .SelectCatch(d => KeyValuePair.Create(TypeLogic.IdToType.GetOrThrow(d.EntityType !.Id), d.ToLite())) .GroupToDictionary(), new InvalidateWith(typeof(DashboardEntity))); } }