Ejemplo n.º 1
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                AuthLogic.AssertStarted(sb);
                OperationLogic.AssertStarted(sb);

                OperationLogic.AllowOperation += OperationLogic_AllowOperation;

                cache = new AuthCache <RuleOperationEntity, OperationAllowedRule, OperationSymbol, OperationSymbol, OperationAllowed>(sb,
                                                                                                                                      s => s,
                                                                                                                                      s => s,
                                                                                                                                      merger: new OperationMerger(),
                                                                                                                                      invalidateWithTypes: true,
                                                                                                                                      coercer:  OperationCoercer.Instance);

                AuthLogic.ExportToXml += exportAll => cache.ExportXml("Operations", "Operation", s => s.Key, b => b.ToString(),
                                                                      exportAll ? OperationLogic.RegisteredOperations.ToList() : null);
                AuthLogic.ImportFromXml += (x, roles, replacements) =>
                {
                    string replacementKey = "AuthRules:" + typeof(OperationSymbol).Name;

                    replacements.AskForReplacements(
                        x.Element("Operations").Elements("Role").SelectMany(r => r.Elements("Operation")).Select(p => p.Attribute("Resource").Value).ToHashSet(),
                        SymbolLogic <OperationSymbol> .AllUniqueKeys(),
                        replacementKey);

                    return(cache.ImportXml(x, "Operations", "Operation", roles,
                                           s => SymbolLogic <OperationSymbol> .TryToSymbol(replacements.Apply(replacementKey, s)), EnumExtensions.ToEnum <OperationAllowed>));
                };
            }
        }
Ejemplo n.º 2
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <ProcessAlgorithmSymbol>()
                .WithQuery(dqm, () => pa => new
                {
                    Entity = pa,
                    pa.Id,
                    pa.Key
                });

                sb.Include <ProcessEntity>()
                .WithQuery(dqm, () => p => new
                {
                    Entity = p,
                    p.Id,
                    p.Algorithm,
                    p.Data,
                    p.State,
                    p.MachineName,
                    p.ApplicationName,
                    p.CreationDate,
                    p.PlannedDate,
                    p.CancelationDate,
                    p.QueuedDate,
                    p.ExecutionStart,
                    p.ExecutionEnd,
                    p.SuspendDate,
                    p.ExceptionDate,
                });

                sb.Include <ProcessExceptionLineEntity>()
                .WithQuery(dqm, () => p => new
                {
                    Entity = p,
                    p.Line,
                    p.Process,
                    p.Exception,
                });

                PermissionAuthLogic.RegisterPermissions(ProcessPermission.ViewProcessPanel);

                SymbolLogic <ProcessAlgorithmSymbol> .Start(sb, dqm, () => registeredProcesses.Keys.ToHashSet());

                OperationLogic.AssertStarted(sb);

                ProcessGraph.Register();

                dqm.RegisterExpression((ProcessAlgorithmSymbol p) => p.Processes(), () => typeof(ProcessEntity).NicePluralName());
                dqm.RegisterExpression((ProcessAlgorithmSymbol p) => p.LastProcess(), () => ProcessMessage.LastProcess.NiceToString());

                dqm.RegisterExpression((IProcessDataEntity p) => p.Processes(), () => typeof(ProcessEntity).NicePluralName());
                dqm.RegisterExpression((IProcessDataEntity p) => p.LastProcess(), () => ProcessMessage.LastProcess.NiceToString());

                dqm.RegisterExpression((IProcessLineDataEntity p) => p.ExceptionLines(), () => ProcessMessage.ExceptionLines.NiceToString());

                PropertyAuthLogic.AvoidAutomaticUpgradeCollection.Add(PropertyRoute.Construct((ProcessEntity p) => p.User));

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;
            }
        }
Ejemplo n.º 3
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.NiceToString());
                QueryLogic.Expressions.Register((ITaskEntity ct) => ct.LastExecution(), () => ITaskMessage.LastExecution.NiceToString());
                QueryLogic.Expressions.Register((ScheduledTaskEntity ct) => ct.Executions(), () => ITaskMessage.Executions.NiceToString());
                QueryLogic.Expressions.Register((ScheduledTaskLogEntity ct) => ct.ExceptionLines(), () => ITaskMessage.ExceptionLines.NiceToString());

                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);
                };

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;
            }
        }