示例#1
0
    public static void Start(SchemaBuilder sb)
    {
        if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
        {
            sb.Include <OrderEntity>()
            .WithQuery(() => o => new
            {
                Entity = o,
                o.Id,
                o.State,
                o.Customer,
                o.Employee,
                o.OrderDate,
                o.RequiredDate,
                o.ShipAddress,
                o.ShipVia,
            });

            QueryLogic.Queries.Register(OrderQuery.OrderLines, () =>
                                        from o in Database.Query <OrderEntity>()
                                        from od in o.Details
                                        select new
            {
                Entity = o,
                o.Id,
                od.Product,
                od.Quantity,
                od.UnitPrice,
                od.Discount,
                od.SubTotalPrice,
            });

            OrderGraph.Register();

            ProcessLogic.Register(OrderProcess.CancelOrders, new CancelOrderAlgorithm());

            SimpleTaskLogic.Register(OrderTask.CancelOldOrdersWithProcess, ctx =>
            {
                var package = new PackageEntity().CreateLines(Database.Query <OrderEntity>().Where(a => a.OrderDate < DateTime.Now.AddDays(-7) && a.State != OrderState.Canceled));

                var process = ProcessLogic.Create(OrderProcess.CancelOrders, package);

                process.Execute(ProcessOperation.Execute);

                return(process.ToLite());
            });

            SimpleTaskLogic.Register(OrderTask.CancelOldOrders, ctx =>
            {
                Database.Query <OrderEntity>()
                .Where(a => a.OrderDate < DateTime.Now.AddDays(-7))
                .UnsafeUpdate()
                .Set(o => o.CancelationDate, o => DateTime.Now)
                .Set(o => o.State, o => OrderState.Canceled)
                .Execute();

                return(null);
            });//CancelOldOrdersProcess
        }
    }
示例#2
0
        public static void Start(SchemaBuilder sb, FileTypeSymbol?testFileType = null)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                TestFileType = testFileType;

                sb.Include <PrintLineEntity>()
                .WithQuery(() => p => new
                {
                    Entity = p,
                    p.CreationDate,
                    p.File,
                    p.State,
                    p.Package,
                    p.PrintedOn,
                    p.Referred,
                });

                sb.Include <PrintPackageEntity>()
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Name
                });

                ProcessLogic.AssertStarted(sb);
                ProcessLogic.Register(PrintPackageProcess.PrintPackage, new PrintPackageAlgorithm());
                PermissionAuthLogic.RegisterPermissions(PrintPermission.ViewPrintPanel);
                PrintLineGraph.Register();

                SimpleTaskLogic.Register(PrintTask.RemoveOldFiles, (ScheduledTaskContext ctx) =>
                {
                    var lines = Database.Query <PrintLineEntity>().Where(a => a.State == PrintLineState.Printed).Where(b => b.CreationDate <= DateTime.Now.AddMinutes(-DeleteFilesAfter));
                    foreach (var line in lines)
                    {
                        try
                        {
                            using (Transaction tr = new Transaction())
                            {
                                line.File.DeleteFileOnCommit();
                                line.State = PrintLineState.PrintedAndDeleted;
                                using (OperationLogic.AllowSave <PackageLineEntity>())
                                    line.Save();

                                tr.Commit();
                            }
                        }
                        catch (Exception e)
                        {
                            e.LogException();
                        }
                    }
                    return(null);
                });
            }
        }
示例#3
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <SMSSendPackageEntity>();
                sb.Include <SMSUpdatePackageEntity>();
                SMSLogic.AssertStarted(sb);
                ProcessLogic.AssertStarted(sb);
                ProcessLogic.Register(SMSMessageProcess.Send, new SMSMessageSendProcessAlgortihm());
                ProcessLogic.Register(SMSMessageProcess.UpdateStatus, new SMSMessageUpdateStatusProcessAlgorithm());
                SimpleTaskLogic.Register(SMSMessageTask.UpdateSMSStatus, ctx => UpdateAllSentSMS()?.ToLite());

                new Graph <ProcessEntity> .ConstructFromMany <SMSMessageEntity>(SMSMessageOperation.CreateUpdateStatusPackage)
                {
                    Construct = (messages, _) => UpdateMessages(messages.RetrieveFromListOfLite())
                }

                .Register();

                QueryLogic.Queries.Register(typeof(SMSSendPackageEntity), () =>
                                            from e in Database.Query <SMSSendPackageEntity>()
                                            let p = e.LastProcess()
                                                    select new
                {
                    Entity = e,
                    e.Id,
                    e.Name,
                    NumLines    = e.SMSMessages().Count(),
                    LastProcess = p,
                    NumErrors   = e.SMSMessages().Count(s => s.Exception(p) != null),
                });

                QueryLogic.Queries.Register(typeof(SMSUpdatePackageEntity), () =>
                                            from e in Database.Query <SMSUpdatePackageEntity>()
                                            let p = e.LastProcess()
                                                    select new
                {
                    Entity = e,
                    e.Id,
                    e.Name,
                    NumLines    = e.SMSMessages().Count(),
                    LastProcess = p,
                    NumErrors   = e.SMSMessages().Count(s => s.Exception(p) != null),
                });
            }
        }
示例#4
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;
        }
    }
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, Func <Pop3ConfigurationEntity, IPop3Client> getPop3Client)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                GetPop3Client = getPop3Client;

                MixinDeclarations.AssertDeclared(typeof(EmailMessageEntity), typeof(EmailReceptionMixin));

                sb.Include <Pop3ConfigurationEntity>()
                .WithSave(Pop3ConfigurationOperation.Save)
                .WithQuery(dqm, () => s => new
                {
                    Entity = s,
                    s.Id,
                    s.Host,
                    s.Port,
                    s.Username,
                    s.EnableSSL
                });
                sb.Include <Pop3ReceptionEntity>();
                sb.Include <Pop3ReceptionExceptionEntity>();

                sb.Include <EmailMessageEntity>()
                .WithQuery(dqm, () => e => new
                {
                    Entity = e,
                    e.Id,
                    e.From,
                    e.Subject,
                    e.Template,
                    e.State,
                    e.Sent,
                    SentDate = (DateTime?)e.Mixin <EmailReceptionMixin>().ReceptionInfo.SentDate,
                    e.Package,
                    e.Exception,
                });

                dqm.RegisterQuery(typeof(Pop3ReceptionEntity), () => DynamicQueryCore.Auto(
                                      from s in Database.Query <Pop3ReceptionEntity>()
                                      select new
                {
                    Entity = s,
                    s.Id,
                    s.Pop3Configuration,
                    s.StartDate,
                    s.EndDate,
                    s.NewEmails,
                    EmailMessages = s.EmailMessages().Count(),
                    Exceptions    = s.Exceptions().Count(),
                    s.Exception,
                })
                                  .ColumnDisplayName(a => a.EmailMessages, () => typeof(EmailMessageEntity).NicePluralName())
                                  .ColumnDisplayName(a => a.Exceptions, () => typeof(ExceptionEntity).NicePluralName()));

                dqm.RegisterExpression((Pop3ConfigurationEntity c) => c.Receptions(), () => typeof(Pop3ReceptionEntity).NicePluralName());
                dqm.RegisterExpression((Pop3ReceptionEntity r) => r.EmailMessages(), () => typeof(EmailMessageEntity).NicePluralName());
                dqm.RegisterExpression((Pop3ReceptionEntity r) => r.Exceptions(), () => typeof(ExceptionEntity).NicePluralName());
                dqm.RegisterExpression((ExceptionEntity r) => r.Pop3Reception(), () => typeof(Pop3ReceptionEntity).NiceName());

                new Graph <Pop3ReceptionEntity> .ConstructFrom <Pop3ConfigurationEntity>(Pop3ConfigurationOperation.ReceiveEmails)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Construct = (e, _) =>
                    {
                        using (Transaction tr = Transaction.None())
                        {
                            var result = e.ReceiveEmails();
                            return(tr.Commit(result));
                        }
                    }
                }

                .Register();

                SchedulerLogic.ExecuteTask.Register((Pop3ConfigurationEntity smtp, ScheduledTaskContext ctx) => smtp.ReceiveEmails().ToLite());

                SimpleTaskLogic.Register(Pop3ConfigurationAction.ReceiveAllActivePop3Configurations, (ScheduledTaskContext ctx) =>
                {
                    if (!EmailLogic.Configuration.ReciveEmails)
                    {
                        throw new InvalidOperationException("EmailLogic.Configuration.ReciveEmails is set to false");
                    }

                    foreach (var item in Database.Query <Pop3ConfigurationEntity>().Where(a => a.Active).ToList())
                    {
                        item.ReceiveEmails();
                    }

                    return(null);
                });
            }
        }