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. 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);
                });
            }
        }
Esempio n. 3
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. 4
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. 5
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. 6
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>;
            }
        }
    }