コード例 #1
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <EmailMasterTemplateEntity>()
                .WithQuery(() => t => new
                {
                    Entity = t,
                    t.Id,
                    t.Name,
                });

                EmailMasterTemplateGraph.Register();
                Validator.PropertyValidator <EmailMasterTemplateEntity>(et => et.Messages).StaticPropertyValidation += (et, pi) =>
                {
                    var dc = EmailLogic.Configuration.DefaultCulture;

                    if (!et.Messages.Any(m => dc.Name.StartsWith(m.CultureInfo.Name)))
                    {
                        return(EmailTemplateMessage.ThereMustBeAMessageFor0.NiceToString().FormatWith(CultureInfoLogic.EntityToCultureInfo.Value.Keys.Where(c => dc.Name.StartsWith(c.EnglishName)).CommaOr(a => a.EnglishName)));
                    }

                    return(null);
                };

                UserAssetsImporter.Register <EmailMasterTemplateEntity>("EmailMasterTemplate", EmailMasterTemplateOperation.Save);
            }
        }
コード例 #2
0
    public static void Start(SchemaBuilder sb)
    {
        if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
        {
            sb.Schema.Generating    += Schema_Generating;
            sb.Schema.Synchronizing += Schema_Synchronizing;
            sb.Include <EmailModelEntity>()
            .WithQuery(() => se => new
            {
                Entity = se,
                se.Id,
                se.FullClassName,
            });

            UserAssetsImporter.Register <EmailTemplateEntity>("EmailTemplate", EmailTemplateOperation.Save);


            new Graph <EmailTemplateEntity> .ConstructFrom <EmailModelEntity>(EmailTemplateOperation.CreateEmailTemplateFromModel)
            {
                Construct = (se, _) => CreateDefaultTemplateInternal(se)
            }

            .Register();

            EmailModelToTemplates = sb.GlobalLazy(() => (
                                                      from et in Database.Query <EmailTemplateEntity>()
                                                      where et.Model != null
                                                      select new { se = et.Model, et })
                                                  .GroupToDictionary(pair => pair.se !.ToLite(), pair => pair.et !), /*CSBUG*/
                                                  new InvalidateWith(typeof(EmailModelEntity), typeof(EmailTemplateEntity)));

            typeToEntity = sb.GlobalLazy(() =>
            {
                var dbModels = Database.RetrieveAll <EmailModelEntity>();
                return(EnumerableExtensions.JoinRelaxed(
                           dbModels,
                           registeredModels.Keys,
                           entity => entity.FullClassName,
                           type => type.FullName !,
                           (entity, type) => KeyValuePair.Create(type, entity),
                           "caching " + nameof(EmailModelEntity))
                       .ToDictionary());
            }, new InvalidateWith(typeof(EmailModelEntity)));


            sb.Schema.Initializing += () => typeToEntity.Load();

            entityToType = sb.GlobalLazy(() => typeToEntity.Value.Inverse(),
                                         new InvalidateWith(typeof(EmailModelEntity)));
        }
    }
コード例 #3
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <JoyrideEntity>()
                .WithSave(JoyrideOperation.Save)
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Name,
                    e.Culture
                });

                sb.Include <JoyrideStepEntity>()
                .WithSave(JoyrideStepOperation.Save)
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Title,
                    e.Culture,
                    e.Selector,
                    e.Type,
                    e.Position,
                });

                sb.Include <JoyrideStepStyleEntity>()
                .WithSave(JoyrideStepStyleOperation.Save)
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Name
                });

                UserAssetsImporter.Register <JoyrideEntity>("Joyride", JoyrideOperation.Save);
                UserAssetsImporter.Register <JoyrideStepEntity>("JoyrideStep", JoyrideStepOperation.Save);
                UserAssetsImporter.Register <JoyrideStepStyleEntity>("JoyrideStepStyle", JoyrideStepStyleOperation.Save);
            }
        }
コード例 #4
0
    public static void Start(SchemaBuilder sb)
    {
        if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
        {
            UserAssetsImporter.Register <UserChartEntity>("UserChart", UserChartOperation.Save);

            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,
                uq.Owner,
            });

            sb.Schema.EntityEvents <UserChartEntity>().Retrieved += ChartLogic_Retrieved;

            sb.Schema.Table <QueryEntity>().PreDeleteSqlSync += e =>
                                                                Administrator.UnsafeDeletePreCommand(Database.Query <UserChartEntity>().Where(a => a.Query.Is(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)));
        }
    }
コード例 #5
0
ファイル: WorkflowLogic.cs プロジェクト: goldenauge/framework
    public static void Start(SchemaBuilder sb, Func <WorkflowConfigurationEmbedded> getConfiguration)
    {
        if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
        {
            PermissionAuthLogic.RegisterPermissions(WorkflowPermission.ViewWorkflowPanel);
            PermissionAuthLogic.RegisterPermissions(WorkflowPermission.ViewCaseFlow);
            PermissionAuthLogic.RegisterPermissions(WorkflowPermission.WorkflowToolbarMenu);

            WorkflowLogic.getConfiguration = getConfiguration;

            UserAssetsImporter.Register <WorkflowEntity>("Workflow", WorkflowOperation.Save);
            UserAssetsImporter.Register <WorkflowScriptEntity>("WorkflowScript", WorkflowScriptOperation.Save);
            UserAssetsImporter.Register <WorkflowTimerConditionEntity>("WorkflowTimerCondition", WorkflowTimerConditionOperation.Save);
            UserAssetsImporter.Register <WorkflowConditionEntity>("WorkflowCondition", WorkflowConditionOperation.Save);
            UserAssetsImporter.Register <WorkflowActionEntity>("WorkflowAction", WorkflowActionOperation.Save);
            UserAssetsImporter.Register <WorkflowScriptRetryStrategyEntity>("WorkflowScriptRetryStrategy", WorkflowScriptRetryStrategyOperation.Save);

            sb.Include <WorkflowEntity>()
            .WithConstruct(WorkflowOperation.Create)
            .WithQuery(() => DynamicQueryCore.Auto(
                           from e in Database.Query <WorkflowEntity>()
                           select new
            {
                Entity = e,
                e.Id,
                e.Name,
                e.MainEntityType,
                HasExpired = e.HasExpired(),
                e.ExpirationDate,
            })
                       .ColumnDisplayName(a => a.HasExpired, () => WorkflowMessage.HasExpired.NiceToString()))
            .WithExpressionFrom((CaseActivityEntity ca) => ca.Workflow());

            WorkflowGraph.Register();
            QueryLogic.Expressions.Register((WorkflowEntity wf) => wf.WorkflowStartEvent());
            QueryLogic.Expressions.Register((WorkflowEntity wf) => wf.HasExpired(), WorkflowMessage.HasExpired);
            sb.AddIndex((WorkflowEntity wf) => wf.ExpirationDate);

            DynamicCode.GetCustomErrors += GetCustomErrors;

            Workflows = sb.GlobalLazy(() => Database.Query <WorkflowEntity>().ToDictionary(a => a.ToLite()),
                                      new InvalidateWith(typeof(WorkflowEntity)));


            sb.Include <WorkflowPoolEntity>()
            .WithUniqueIndex(wp => new { wp.Workflow, wp.Name })
            .WithSave(WorkflowPoolOperation.Save)
            .WithDelete(WorkflowPoolOperation.Delete)
            .WithExpressionFrom((WorkflowEntity p) => p.WorkflowPools())
            .WithQuery(() => e => new
            {
                Entity = e,
                e.Id,
                e.Name,
                e.BpmnElementId,
                e.Workflow,
            });

            sb.Include <WorkflowLaneEntity>()
            .WithUniqueIndex(wp => new { wp.Pool, wp.Name })
            .WithSave(WorkflowLaneOperation.Save)
            .WithDelete(WorkflowLaneOperation.Delete)
            .WithExpressionFrom((WorkflowPoolEntity p) => p.WorkflowLanes())
            .WithQuery(() => e => new
            {
                Entity = e,
                e.Id,
                e.Name,
                e.BpmnElementId,
                e.Pool,
                e.Pool.Workflow,
            });

            sb.Include <WorkflowActivityEntity>()
            .WithUniqueIndex(w => new { w.Lane, w.Name })
            .WithSave(WorkflowActivityOperation.Save)
            .WithDelete(WorkflowActivityOperation.Delete)
            .WithExpressionFrom((WorkflowEntity p) => p.WorkflowActivities())
            .WithExpressionFrom((WorkflowLaneEntity p) => p.WorkflowActivities())
            .WithVirtualMList(wa => wa.BoundaryTimers, e => e.BoundaryOf, WorkflowEventOperation.Save, WorkflowEventOperation.Delete)
            .WithQuery(() => e => new
            {
                Entity = e,
                e.Id,
                e.Name,
                e.BpmnElementId,
                e.Comments,
                e.Lane,
                e.Lane.Pool.Workflow,
            });

            sb.Include <WorkflowEventEntity>()
            .WithExpressionFrom((WorkflowEntity p) => p.WorkflowEvents())
            .WithExpressionFrom((WorkflowLaneEntity p) => p.WorkflowEvents())
            .WithQuery(() => e => new
            {
                Entity = e,
                e.Id,
                e.Type,
                e.Name,
                e.BpmnElementId,
                e.Lane,
                e.Lane.Pool.Workflow,
            });


            new Graph <WorkflowEventEntity> .Execute(WorkflowEventOperation.Save)
            {
                CanBeNew      = true,
                CanBeModified = true,
                Execute       = (e, _) =>
                {
                    if (e.Timer == null && e.Type.IsTimer())
                    {
                        throw new InvalidOperationException(ValidationMessage._0IsMandatoryWhen1IsSetTo2.NiceToString(e.NicePropertyName(a => a.Timer), e.NicePropertyName(a => a.Type), e.Type.NiceToString()));
                    }

                    if (e.Timer != null && !e.Type.IsTimer())
                    {
                        throw new InvalidOperationException(ValidationMessage._0ShouldBeNullWhen1IsSetTo2.NiceToString(e.NicePropertyName(a => a.Timer), e.NicePropertyName(a => a.Type), e.Type.NiceToString()));
                    }

                    if (e.BoundaryOf == null && e.Type.IsBoundaryTimer())
                    {
                        throw new InvalidOperationException(ValidationMessage._0IsMandatoryWhen1IsSetTo2.NiceToString(e.NicePropertyName(a => a.BoundaryOf), e.NicePropertyName(a => a.Type), e.Type.NiceToString()));
                    }

                    if (e.BoundaryOf != null && !e.Type.IsBoundaryTimer())
                    {
                        throw new InvalidOperationException(ValidationMessage._0ShouldBeNullWhen1IsSetTo2.NiceToString(e.NicePropertyName(a => a.BoundaryOf), e.NicePropertyName(a => a.Type), e.Type.NiceToString()));
                    }

                    e.Save();
                },
            }

            .Register();

            new Graph <WorkflowEventEntity> .Delete(WorkflowEventOperation.Delete)
            {
                Delete = (e, _) =>
                {
                    if (e.Type.IsScheduledStart())
                    {
                        var scheduled = e.ScheduledTask();
                        if (scheduled != null)
                        {
                            WorkflowEventTaskLogic.DeleteWorkflowEventScheduledTask(scheduled);
                        }
                    }

                    e.Delete();
                },
            }

            .Register();

            sb.Include <WorkflowGatewayEntity>()
            .WithSave(WorkflowGatewayOperation.Save)
            .WithDelete(WorkflowGatewayOperation.Delete)
            .WithExpressionFrom((WorkflowEntity p) => p.WorkflowGateways())
            .WithExpressionFrom((WorkflowLaneEntity p) => p.WorkflowGateways())
            .WithQuery(() => e => new
            {
                Entity = e,
                e.Id,
                e.Type,
                e.Name,
                e.BpmnElementId,
                e.Lane,
                e.Lane.Pool.Workflow,
            });

            sb.Include <WorkflowConnectionEntity>()
            .WithSave(WorkflowConnectionOperation.Save)
            .WithDelete(WorkflowConnectionOperation.Delete)
            .WithExpressionFrom((WorkflowEntity p) => p.WorkflowConnections())
            .WithExpressionFrom((WorkflowEntity p) => p.WorkflowMessageConnections(), null !)
            .WithExpressionFrom((WorkflowPoolEntity p) => p.WorkflowConnections())
            .WithExpressionFrom((IWorkflowNodeEntity p) => p.NextConnections(), null !)
            .WithExpressionFrom((IWorkflowNodeEntity p) => p.PreviousConnections(), null !)
            .WithQuery(() => e => new
            {
                Entity = e,
                e.Id,
                e.Name,
                e.BpmnElementId,
                e.From,
                e.To,
            });

            WorkflowEventTaskEntity.GetWorkflowEntity = lite => WorkflowGraphLazy.Value.GetOrThrow(lite).Workflow;

            WorkflowGraphLazy = sb.GlobalLazy(() =>
            {
                using (new EntityCache())
                {
                    var events      = Database.RetrieveAll <WorkflowEventEntity>().GroupToDictionary(a => a.Lane.Pool.Workflow.ToLite());
                    var gateways    = Database.RetrieveAll <WorkflowGatewayEntity>().GroupToDictionary(a => a.Lane.Pool.Workflow.ToLite());
                    var activities  = Database.RetrieveAll <WorkflowActivityEntity>().GroupToDictionary(a => a.Lane.Pool.Workflow.ToLite());
                    var connections = Database.RetrieveAll <WorkflowConnectionEntity>().GroupToDictionary(a => a.From.Lane.Pool.Workflow.ToLite());

                    var result = Database.RetrieveAll <WorkflowEntity>().ToDictionary(workflow => workflow.ToLite(), workflow =>
                    {
                        var w         = workflow.ToLite();
                        var nodeGraph = new WorkflowNodeGraph
                        {
                            Workflow    = workflow,
                            Events      = events.TryGetC(w).EmptyIfNull().ToDictionary(e => e.ToLite()),
                            Gateways    = gateways.TryGetC(w).EmptyIfNull().ToDictionary(g => g.ToLite()),
                            Activities  = activities.TryGetC(w).EmptyIfNull().ToDictionary(a => a.ToLite()),
                            Connections = connections.TryGetC(w).EmptyIfNull().ToDictionary(c => c.ToLite()),
                        };

                        nodeGraph.FillGraphs();
                        return(nodeGraph);
                    });

                    return(result);
                }
            }, new InvalidateWith(typeof(WorkflowConnectionEntity)));
            WorkflowGraphLazy.OnReset += (e, args) => DynamicCode.OnInvalidated?.Invoke();

            Validator.PropertyValidator((WorkflowConnectionEntity c) => c.Condition).StaticPropertyValidation = (e, pi) =>
            {
                if (e.Condition != null && e.From != null)
                {
                    var conditionType = (e.Condition.EntityOrNull ?? Conditions.Value.GetOrThrow(e.Condition)).MainEntityType;
                    var workflowType  = e.From.Lane.Pool.Workflow.MainEntityType;

                    if (!conditionType.Is(workflowType))
                    {
                        return(WorkflowMessage.Condition0IsDefinedFor1Not2.NiceToString(conditionType, workflowType));
                    }
                }

                return(null);
            };

            StartWorkflowConditions(sb);

            StartWorkflowTimerConditions(sb);

            StartWorkflowActions(sb);

            StartWorkflowScript(sb);
        }
    }
コード例 #6
0
    public static void Start(SchemaBuilder sb)
    {
        if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
        {
            AuthLogic.AssertStarted(sb);
            OperationLogic.AssertStarted(sb);

            Implementations imp  = sb.Settings.GetImplementations((ScheduledTaskEntity st) => st.Task);
            Implementations imp2 = sb.Settings.GetImplementations((ScheduledTaskLogEntity st) => st.Task);

            if (!imp2.Equals(imp2))
            {
                throw new InvalidOperationException("Implementations of ScheduledTaskEntity.Task should be the same as in ScheduledTaskLogEntity.Task");
            }

            PermissionAuthLogic.RegisterPermissions(SchedulerPermission.ViewSchedulerPanel);

            ExecuteTask.Register((ITaskEntity t, ScheduledTaskContext ctx) => { throw new NotImplementedException("SchedulerLogic.ExecuteTask not registered for {0}".FormatWith(t.GetType().Name)); });

            SimpleTaskLogic.Start(sb);
            sb.Include <ScheduledTaskEntity>()
            .WithQuery(() => st => new
            {
                Entity = st,
                st.Id,
                st.Task,
                st.Rule,
                st.Suspended,
                st.MachineName,
                st.ApplicationName
            });

            sb.Include <ScheduledTaskLogEntity>()
            .WithIndex(s => s.ScheduledTask, includeFields: s => s.StartTime)
            .WithQuery(() => cte => new
            {
                Entity = cte,
                cte.Id,
                cte.Task,
                cte.ScheduledTask,
                cte.StartTime,
                cte.EndTime,
                cte.ProductEntity,
                cte.MachineName,
                cte.User,
                cte.Exception,
            });

            sb.Include <SchedulerTaskExceptionLineEntity>()
            .WithQuery(() => cte => new
            {
                Entity = cte,
                cte.Id,
                cte.ElementInfo,
                cte.Exception,
                cte.SchedulerTaskLog,
            });

            new Graph <ScheduledTaskLogEntity> .Execute(ScheduledTaskLogOperation.CancelRunningTask)
            {
                CanExecute = e => RunningTasks.ContainsKey(e) ? null : SchedulerMessage.TaskIsNotRunning.NiceToString(),
                Execute    = (e, _) => { RunningTasks[e].CancellationTokenSource.Cancel(); },
            }

            .Register();

            sb.Include <HolidayCalendarEntity>()
            .WithQuery(() => st => new
            {
                Entity = st,
                st.Id,
                st.Name,
                Holidays = st.Holidays.Count,
            });

            QueryLogic.Expressions.Register((ITaskEntity ct) => ct.Executions(), ITaskMessage.Executions);
            QueryLogic.Expressions.Register((ITaskEntity ct) => ct.LastExecution(), ITaskMessage.LastExecution);
            QueryLogic.Expressions.Register((ScheduledTaskEntity ct) => ct.Executions(), ITaskMessage.Executions);
            QueryLogic.Expressions.Register((ScheduledTaskLogEntity ct) => ct.ExceptionLines(), ITaskMessage.ExceptionLines);

            new Graph <HolidayCalendarEntity> .Execute(HolidayCalendarOperation.Save)
            {
                CanBeNew      = true,
                CanBeModified = true,
                Execute       = (c, _) => { },
            }

            .Register();

            new Graph <HolidayCalendarEntity> .Delete(HolidayCalendarOperation.Delete)
            {
                Delete = (c, _) => { c.Delete(); },
            }

            .Register();

            new Graph <ScheduledTaskEntity> .Execute(ScheduledTaskOperation.Save)
            {
                CanBeNew      = true,
                CanBeModified = true,
                Execute       = (st, _) => { },
            }

            .Register();

            new Graph <ScheduledTaskEntity> .Delete(ScheduledTaskOperation.Delete)
            {
                Delete = (st, _) =>
                {
                    st.Executions().UnsafeUpdate().Set(l => l.ScheduledTask, l => null).Execute();
                    var rule = st.Rule; st.Delete(); rule.Delete();
                },
            }

            .Register();


            new Graph <ScheduledTaskLogEntity> .ConstructFrom <ITaskEntity>(ITaskOperation.ExecuteSync)
            {
                Construct = (task, _) => ExecuteSync(task, null, UserHolder.Current)
            }

            .Register();

            new Graph <ITaskEntity> .Execute(ITaskOperation.ExecuteAsync)
            {
                Execute = (task, _) => ExecuteAsync(task, null, UserHolder.Current)
            }

            .Register();

            ScheduledTasksLazy = sb.GlobalLazy(() =>
                                               Database.Query <ScheduledTaskEntity>().Where(a => !a.Suspended &&
                                                                                            (a.MachineName == ScheduledTaskEntity.None || a.MachineName == Environment.MachineName && a.ApplicationName == Schema.Current.ApplicationName)).ToList(),
                                               new InvalidateWith(typeof(ScheduledTaskEntity)));

            ScheduledTasksLazy.OnReset += ScheduledTasksLazy_OnReset;

            sb.Schema.EntityEvents <ScheduledTaskLogEntity>().PreUnsafeDelete += query =>
            {
                query.SelectMany(e => e.ExceptionLines()).UnsafeDelete();
                return(null);
            };

            UserAssetsImporter.Register <ScheduleRuleMinutelyEntity>("ScheduleRuleMinutely", e => e.Save());
            UserAssetsImporter.Register <ScheduleRuleMonthsEntity>("ScheduleRuleMonths", e => e.Save());
            UserAssetsImporter.Register <ScheduleRuleWeekDaysEntity>("ScheduleRuleWeekDays", e => e.Save());
            UserAssetsImporter.Register <HolidayCalendarEntity>("HolidayCalendar", HolidayCalendarOperation.Save);

            ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;
        }
    }
コード例 #7
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <ToolbarEntity>()
                .WithSave(ToolbarOperation.Save)
                .WithDelete(ToolbarOperation.Delete)
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Name,
                    e.Owner,
                    e.Priority
                });

                sb.Include <ToolbarMenuEntity>()
                .WithSave(ToolbarMenuOperation.Save)
                .WithDelete(ToolbarMenuOperation.Delete)
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Name
                });

                UserAssetsImporter.Register <ToolbarEntity>("Toolbar", ToolbarOperation.Save);
                UserAssetsImporter.Register <ToolbarMenuEntity>("ToolbarMenu", ToolbarMenuOperation.Save);

                RegisterDelete <UserQueryEntity>(sb);
                RegisterDelete <UserChartEntity>(sb);
                RegisterDelete <QueryEntity>(sb);
                RegisterDelete <DashboardEntity>(sb);
                RegisterDelete <ToolbarMenuEntity>(sb);
                RegisterDelete <WorkflowEntity>(sb);

                RegisterContentConfig <ToolbarMenuEntity>(
                    lite => true,
                    lite => TranslatedInstanceLogic.TranslatedField(ToolbarMenus.Value.GetOrCreate(lite), a => a.Name));

                RegisterContentConfig <UserQueryEntity>(
                    lite => { var uq = UserQueryLogic.UserQueries.Value.GetOrCreate(lite); return(InMemoryFilter(uq) && QueryLogic.Queries.QueryAllowed(uq.Query.ToQueryName(), true)); },
                    lite => TranslatedInstanceLogic.TranslatedField(UserQueryLogic.UserQueries.Value.GetOrCreate(lite), a => a.DisplayName));

                RegisterContentConfig <UserChartEntity>(
                    lite => { var uc = UserChartLogic.UserCharts.Value.GetOrCreate(lite); return(InMemoryFilter(uc) && QueryLogic.Queries.QueryAllowed(uc.Query.ToQueryName(), true)); },
                    lite => TranslatedInstanceLogic.TranslatedField(UserChartLogic.UserCharts.Value.GetOrCreate(lite), a => a.DisplayName));

                RegisterContentConfig <QueryEntity>(
                    lite => IsQueryAllowed(lite),
                    lite => QueryUtils.GetNiceName(QueryLogic.QueryNames.GetOrThrow(lite.ToString() !)));

                RegisterContentConfig <DashboardEntity>(
                    lite => InMemoryFilter(DashboardLogic.Dashboards.Value.GetOrCreate(lite)),
                    lite => TranslatedInstanceLogic.TranslatedField(DashboardLogic.Dashboards.Value.GetOrCreate(lite), a => a.DisplayName));

                RegisterContentConfig <PermissionSymbol>(
                    lite => PermissionAuthLogic.IsAuthorized(SymbolLogic <PermissionSymbol> .ToSymbol(lite.ToString() !)),
                    lite => SymbolLogic <PermissionSymbol> .ToSymbol(lite.ToString() !).NiceToString());

                RegisterContentConfig <WorkflowEntity>(
                    lite => { var wf = WorkflowLogic.WorkflowGraphLazy.Value.GetOrCreate(lite); return(InMemoryFilter(wf.Workflow) && wf.IsStartCurrentUser()); },
                    lite => TranslatedInstanceLogic.TranslatedField(WorkflowLogic.WorkflowGraphLazy.Value.GetOrCreate(lite).Workflow, a => a.Name));



                //    { typeof(QueryEntity), a => IsQueryAllowed((Lite<QueryEntity>)a) },
                //{ typeof(PermissionSymbol), a => PermissionAuthLogic.IsAuthorized((PermissionSymbol)a.RetrieveAndRemember()) },
                //{ typeof(UserQueryEntity), a => ,
                //{ typeof(UserChartEntity), a => { var uc = UserChartLogic.UserCharts.Value.GetOrCreate((Lite<UserChartEntity>)a); return InMemoryFilter(uc) && QueryLogic.Queries.QueryAllowed(uc.Query.ToQueryName(), true); } },
                //{ typeof(DashboardEntity), a => InMemoryFilter(DashboardLogic.Dashboards.Value.GetOrCreate((Lite<DashboardEntity>)a)) },
                //{ typeof(WorkflowEntity), a => { var wf = WorkflowLogic.WorkflowGraphLazy.Value.GetOrCreate((Lite<WorkflowEntity>)a); return InMemoryFilter(wf.Workflow) && wf.IsStartCurrentUser(); } },


                Toolbars = sb.GlobalLazy(() => Database.Query <ToolbarEntity>().ToDictionary(a => a.ToLite()),
                                         new InvalidateWith(typeof(ToolbarEntity)));

                ToolbarMenus = sb.GlobalLazy(() => Database.Query <ToolbarMenuEntity>().ToDictionary(a => a.ToLite()),
                                             new InvalidateWith(typeof(ToolbarMenuEntity)));
            }
        }
コード例 #8
0
        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)));
            }
        }