Esempio n. 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
        }
    }
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Schema.Settings.AssertImplementedBy((ProcessEntity p) => p.Data, typeof(EmailPackageEntity));
                sb.Include <EmailPackageEntity>()
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Name,
                });

                QueryLogic.Expressions.Register((EmailPackageEntity ep) => ep.Messages(), () => EmailMessageMessage.Messages.NiceToString());
                QueryLogic.Expressions.Register((EmailPackageEntity ep) => ep.RemainingMessages(), () => EmailMessageMessage.RemainingMessages.NiceToString());
                QueryLogic.Expressions.Register((EmailPackageEntity ep) => ep.ExceptionMessages(), () => EmailMessageMessage.ExceptionMessages.NiceToString());

                ProcessLogic.AssertStarted(sb);
                ProcessLogic.Register(EmailMessageProcess.CreateEmailsSendAsync, new CreateEmailsSendAsyncProcessAlgorithm());
                ProcessLogic.Register(EmailMessageProcess.SendEmails, new SendEmailProcessAlgorithm());

                new Graph <ProcessEntity> .ConstructFromMany <EmailMessageEntity>(EmailMessageOperation.ReSendEmails)
                {
                    Construct = (messages, args) =>
                    {
                        if (!messages.Any())
                        {
                            return(null);
                        }

                        EmailPackageEntity emailPackage = new EmailPackageEntity()
                        {
                            Name = args.TryGetArgC <string>()
                        }.Save();

                        foreach (var m in messages.Select(m => m.RetrieveAndForget()))
                        {
                            new EmailMessageEntity()
                            {
                                Package         = emailPackage.ToLite(),
                                From            = m.From,
                                Recipients      = m.Recipients.ToMList(),
                                Target          = m.Target,
                                Body            = new BigStringEmbedded(m.Body.Text),
                                IsBodyHtml      = m.IsBodyHtml,
                                Subject         = m.Subject,
                                Template        = m.Template,
                                EditableMessage = m.EditableMessage,
                                State           = EmailMessageState.RecruitedForSending,
                                Attachments     = m.Attachments.Select(a => a.Clone()).ToMList()
                            }.Save();
                        }

                        return(ProcessLogic.Create(EmailMessageProcess.SendEmails, emailPackage));
                    }
                }

                .Register();
            }
        }
Esempio n. 3
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);
                });
            }
        }
Esempio n. 4
0
        public static void Start(SchemaBuilder sb, Func <NewsletterEntity, EmailSenderConfigurationEntity> getEmailSenderConfiguration)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <NewsletterEntity>();
                sb.Include <NewsletterDeliveryEntity>();

                NewsletterLogic.GetEmailSenderConfiguration = getEmailSenderConfiguration;

                ProcessLogic.AssertStarted(sb);
                ProcessLogic.Register(NewsletterProcess.SendNewsletter, new NewsletterProcessAlgorithm());

                QueryLogic.Queries.Register(typeof(NewsletterEntity), () =>
                                            from n in Database.Query <NewsletterEntity>()
                                            let p = n.LastProcess()
                                                    select new
                {
                    Entity = n,
                    n.Id,
                    n.Name,
                    n.Subject,
                    Text = n.Text.Try(a => a.Etc(100)),
                    n.State,
                    NumDeliveries = n.Deliveries().Count(),
                    LastProcess   = p,
                    NumErrors     = n.Deliveries().Count(d => d.Exception(p) != null)
                });

                QueryLogic.Queries.Register(typeof(NewsletterDeliveryEntity), () =>
                                            from e in Database.Query <NewsletterDeliveryEntity>()
                                            let p = e.Newsletter.Entity.LastProcess()
                                                    select new
                {
                    Entity = e,
                    e.Id,
                    e.Newsletter,
                    e.Recipient,
                    e.Sent,
                    e.SendDate,
                    LastProcess = p,
                    Exception   = e.Exception(p)
                });

                NewsletterGraph.Register();

                sb.AddUniqueIndex <NewsletterDeliveryEntity>(nd => new { nd.Newsletter, nd.Recipient });

                Validator.PropertyValidator((NewsletterEntity news) => news.Text).StaticPropertyValidation    += (sender, pi) => ValidateTokens(sender, sender.Text);
                Validator.PropertyValidator((NewsletterEntity news) => news.Subject).StaticPropertyValidation += (sender, pi) => ValidateTokens(sender, sender.Subject);

                sb.Schema.EntityEvents <NewsletterEntity>().PreSaving += Newsletter_PreSaving;
            }
        }
Esempio n. 5
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <EmailPackageEntity>()
                .WithQuery(dqm, () => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Name,
                });

                dqm.RegisterExpression((EmailPackageEntity ep) => ep.Messages(), () => EmailMessageMessage.Messages.NiceToString());
                dqm.RegisterExpression((EmailPackageEntity ep) => ep.RemainingMessages(), () => EmailMessageMessage.RemainingMessages.NiceToString());
                dqm.RegisterExpression((EmailPackageEntity ep) => ep.ExceptionMessages(), () => EmailMessageMessage.ExceptionMessages.NiceToString());

                ProcessLogic.AssertStarted(sb);
                ProcessLogic.Register(EmailMessageProcess.CreateEmailsSendAsync, new CreateEmailsSendAsyncProcessAlgorithm());
                ProcessLogic.Register(EmailMessageProcess.SendEmails, new SendEmailProcessAlgorithm());

                new Graph <ProcessEntity> .ConstructFromMany <EmailMessageEntity>(EmailMessageOperation.ReSendEmails)
                {
                    Construct = (messages, args) =>
                    {
                        EmailPackageEntity emailPackage = new EmailPackageEntity()
                        {
                            Name = args.TryGetArgC <string>()
                        }.Save();

                        foreach (var m in messages.Select(m => m.RetrieveAndForget()))
                        {
                            new EmailMessageEntity()
                            {
                                Package         = emailPackage.ToLite(),
                                From            = m.From,
                                Recipients      = m.Recipients.ToMList(),
                                Target          = m.Target,
                                Body            = m.Body,
                                IsBodyHtml      = m.IsBodyHtml,
                                Subject         = m.Subject,
                                Template        = m.Template,
                                EditableMessage = m.EditableMessage,
                                State           = EmailMessageState.RecruitedForSending
                            }.Save();
                        }

                        return(ProcessLogic.Create(EmailMessageProcess.SendEmails, emailPackage));
                    }
                }

                .Register();
            }
        }
Esempio n. 6
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),
                });
            }
        }
Esempio n. 7
0
    public static void Start(SchemaBuilder sb, bool packages, bool packageOperations)
    {
        if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
        {
            ProcessLogic.AssertStarted(sb);

            sb.Settings.AssertImplementedBy((ProcessExceptionLineEntity pel) => pel.Line, typeof(PackageLineEntity));

            sb.Include <PackageLineEntity>()
            .WithQuery(() => pl => new
            {
                Entity = pl,
                pl.Package,
                pl.Id,
                pl.Target,
                pl.Result,
                pl.FinishTime,
            });

            QueryLogic.Queries.Register(PackageQuery.PackageLineLastProcess, () =>
                                        from pl in Database.Query <PackageLineEntity>()
                                        let p = pl.Package.Entity.LastProcess()
                                                select new
            {
                Entity = pl,
                pl.Package,
                pl.Id,
                pl.Target,
                pl.Result,
                pl.FinishTime,
                LastProcess = p,
                Exception   = pl.Exception(p),
            });


            QueryLogic.Expressions.Register((PackageEntity p) => p.Lines(), ProcessMessage.Lines);

            if (packages)
            {
                sb.Settings.AssertImplementedBy((PackageLineEntity pl) => pl.Package, typeof(PackageEntity));
                sb.Settings.AssertImplementedBy((ProcessEntity pe) => pe.Data, typeof(PackageEntity));

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

                QueryLogic.Queries.Register(PackageQuery.PackageLastProcess, () =>
                                            from pk in Database.Query <PackageEntity>()
                                            let pe = pk.LastProcess()
                                                     select new
                {
                    Entity = pk,
                    pk.Id,
                    pk.Name,
                    NumLines    = pk.Lines().Count(),
                    LastProcess = pe,
                    NumErrors   = pk.Lines().Count(l => l.Exception(pe) != null),
                });

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeletePackages <PackageEntity>;
            }

            if (packageOperations)
            {
                sb.Settings.AssertImplementedBy((PackageLineEntity pl) => pl.Package, typeof(PackageOperationEntity));
                sb.Settings.AssertImplementedBy((ProcessEntity pe) => pe.Data, typeof(PackageOperationEntity));

                sb.Include <PackageOperationEntity>()
                .WithQuery(() => pk => new
                {
                    Entity = pk,
                    pk.Id,
                    pk.Name,
                    pk.Operation,
                });

                QueryLogic.Queries.Register(PackageQuery.PackageOperationLastProcess, () =>
                                            from p in Database.Query <PackageOperationEntity>()
                                            let pe = p.LastProcess()
                                                     select new
                {
                    Entity = p,
                    p.Id,
                    p.Name,
                    p.Operation,
                    NumLines    = p.Lines().Count(),
                    LastProcess = pe,
                    NumErrors   = p.Lines().Count(l => l.Exception(pe) != null),
                });

                ProcessLogic.Register(PackageOperationProcess.PackageOperation, new PackageOperationAlgorithm());
                ExceptionLogic.DeleteLogs += ExceptionLogic_DeletePackages <PackageOperationEntity>;
            }
        }
    }
Esempio n. 8
0
    public static void Start(SchemaBuilder sb, IFileTypeAlgorithm predictorFileAlgorithm)
    {
        if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
        {
            sb.Settings.AssertIgnored((PredictorEntity p) => p.MainQuery.Filters.Single().Pinned, "use PredictorLogic", "by calling PredictorLogic.IgnorePinned in Starter.OverrideAttributes");
            sb.Settings.AssertIgnored((PredictorSubQueryEntity p) => p.Filters.Single().Pinned, "use PredictorLogic", "by calling PredictorLogic.IgnorePinned in Starter.OverrideAttributes");

            sb.Include <PredictorEntity>()
            .WithVirtualMList(p => p.SubQueries, mc => mc.Predictor)
            .WithQuery(() => e => new
            {
                Entity = e,
                e.Id,
                e.Name,
                e.MainQuery.Query,
                e.Algorithm,
                e.State,
                e.TrainingException,
            });

            PredictorGraph.Register();

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

            sb.Include <PredictorCodificationEntity>()
            .WithUniqueIndex(pc => new { pc.Predictor, pc.Index, pc.Usage })
            .WithExpressionFrom((PredictorEntity e) => e.Codifications())
            .WithQuery(() => e => new
            {
                Entity = e,
                e.Id,
                e.Predictor,
                e.Index,
                e.Usage,
                e.OriginalColumnIndex,
                e.SubQueryIndex,
                e.SplitKey0,
                e.SplitKey1,
                e.SplitKey2,
                e.IsValue,
                e.Min,
                e.Max,
                e.Average,
                e.StdDev,
            });

            sb.Include <PredictorEpochProgressEntity>()
            .WithExpressionFrom((PredictorEntity e) => e.EpochProgresses())
            .WithQuery(() => e => new
            {
                Entity = e,
                e.Predictor,
                e.Id,
                e.Epoch,
                e.Ellapsed,
                e.LossTraining,
                e.AccuracyTraining,
                e.LossValidation,
                e.AccuracyValidation,
            });

            FileTypeLogic.Register(PredictorFileType.PredictorFile, predictorFileAlgorithm);

            SymbolLogic <PredictorAlgorithmSymbol> .Start(sb, () => Algorithms.Keys);

            SymbolLogic <PredictorColumnEncodingSymbol> .Start(sb, () => Algorithms.Values.SelectMany(a => a.GetRegisteredEncodingSymbols()).Distinct());

            SymbolLogic <PredictorResultSaverSymbol> .Start(sb, () => ResultSavers.Keys);

            SymbolLogic <PredictorPublicationSymbol> .Start(sb, () => Publications.Keys);

            sb.Schema.EntityEvents <PredictorEntity>().Retrieved         += PredictorEntity_Retrieved;
            sb.Schema.EntityEvents <PredictorSubQueryEntity>().Retrieved += PredictorMultiColumnEntity_Retrieved;

            Validator.PropertyValidator((PredictorColumnEmbedded c) => c.Encoding).StaticPropertyValidation      += Column_StaticPropertyValidation;
            Validator.PropertyValidator((PredictorSubQueryColumnEmbedded c) => c.Token).StaticPropertyValidation += GroupKey_StaticPropertyValidation;
            Validator.PropertyValidator((PredictorSubQueryEntity c) => c.Columns).StaticPropertyValidation       += SubQueryColumns_StaticPropertyValidation;

            sb.Include <PredictSimpleResultEntity>()
            .WithQuery(() => e => new
            {
                Entity = e,
                e.Id,
                e.Predictor,
                e.Target,
                e.Type,
                e.OriginalValue,
                e.PredictedValue,
                e.OriginalCategory,
                e.PredictedCategory,
            });

            RegisterResultSaver(PredictorSimpleResultSaver.StatisticsOnly, new PredictorSimpleSaver {
                SaveAllResults = false
            });
            RegisterResultSaver(PredictorSimpleResultSaver.Full, new PredictorSimpleSaver {
                SaveAllResults = true
            });

            sb.Schema.EntityEvents <PredictorEntity>().PreUnsafeDelete += query =>
            {
                Database.Query <PredictSimpleResultEntity>().Where(a => query.Contains(a.Predictor.Entity)).UnsafeDelete();
                return(null);
            };

            sb.Schema.WhenIncluded <ProcessEntity>(() =>
            {
                sb.Schema.Settings.AssertImplementedBy((ProcessEntity p) => p.Data, typeof(PredictorEntity));
                sb.Schema.Settings.AssertImplementedBy((ProcessEntity p) => p.Data, typeof(AutoconfigureNeuralNetworkEntity));
                ProcessLogic.Register(PredictorProcessAlgorithm.AutoconfigureNeuralNetwork, new AutoconfigureNeuralNetworkAlgorithm());

                new Graph <ProcessEntity> .ConstructFrom <PredictorEntity>(PredictorOperation.AutoconfigureNetwork)
                {
                    CanConstruct = p => p.AlgorithmSettings is NeuralNetworkSettingsEntity ? null : ValidationMessage._0ShouldBeOfType1.NiceToString(p.NicePropertyName(_ => _.AlgorithmSettings), typeof(NeuralNetworkSettingsEntity).NiceName()),
                    Construct    = (p, _) =>
                    {
                        return(ProcessLogic.Create(PredictorProcessAlgorithm.AutoconfigureNeuralNetwork, new AutoconfigureNeuralNetworkEntity
                        {
                            InitialPredictor = p.ToLite()
                        }));
                    }
                }.Register();
            });
        }
    }