예제 #1
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <ExceptionEntity>();

                dqm.RegisterQuery(typeof(ExceptionEntity), () =>
                                  from r in Database.Query <ExceptionEntity>()
                                  select new
                {
                    Entity = r,
                    r.Id,
                    r.CreationDate,
                    r.ExceptionType,
                    ExcepcionMessage = r.ExceptionMessage,
                    r.StackTraceHash,
                });

                dqm.RegisterQuery(typeof(ExceptionEntity), () =>
                                  from r in Database.Query <ExceptionEntity>()
                                  select new
                {
                    Entity = r,
                    r.Id,
                    r.CreationDate,
                    r.ExceptionType,
                    ExcepcionMessage = r.ExceptionMessage,
                    r.StackTraceHash,
                });

                DefaultEnvironment = "Default";
            }
        }
예제 #2
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<ExceptionEntity>();

                dqm.RegisterQuery(typeof(ExceptionEntity),()=>
                    from r in Database.Query<ExceptionEntity>()
                    select new
                    {
                        Entity = r,
                        r.Id,
                        r.CreationDate,
                        r.ExceptionType,
                        ExcepcionMessage = r.ExceptionMessage,
                        r.StackTraceHash,
                    });

                dqm.RegisterQuery(typeof(ExceptionEntity), ()=>
                     from r in Database.Query<ExceptionEntity>()
                     select new
                     {
                         Entity = r,
                         r.Id,
                         r.CreationDate,
                         r.ExceptionType,
                         ExcepcionMessage = r.ExceptionMessage,
                         r.StackTraceHash,
                     });

                DefaultEnvironment = "Default"; 
            }
        }
예제 #3
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, Func <NewsletterEntity, SmtpConfigurationEntity> getSmtpConfiguration)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <NewsletterEntity>();
                sb.Include <NewsletterDeliveryEntity>();

                NewsletterLogic.GetStmpConfiguration = getSmtpConfiguration;

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

                dqm.RegisterQuery(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.Etc(100),
                    n.State,
                    NumDeliveries = n.Deliveries().Count(),
                    LastProcess   = p,
                    NumErrors     = n.Deliveries().Count(d => d.Exception(p) != null)
                });

                dqm.RegisterQuery(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;
            }
        }
예제 #4
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <OrderEntity>()
                .WithQuery(dqm, () => o => new
                {
                    Entity = o,
                    o.Id,
                    o.State,
                    o.Customer,
                    o.Employee,
                    o.OrderDate,
                    o.RequiredDate,
                    o.ShipAddress,
                    o.ShipVia,
                });

                dqm.RegisterQuery(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
            }
        }
예제 #5
0
        internal static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<ChartScriptEntity>();

                dqm.RegisterQuery(typeof(ChartScriptEntity), () =>
                    from uq in Database.Query<ChartScriptEntity>()
                    select new
                    {
                        Entity = uq,
                        uq.Id,
                        uq.Name,
                        uq.GroupBy,
                        uq.Columns.Count,
                        uq.Icon,
                    });

                Scripts = sb.GlobalLazy(() =>
                {
                    var result = Database.Query<ChartScriptEntity>().ToDictionary(a => a.Name);
                    foreach (var e in result.Values)
                        if (e.Icon != null)
                            e.Icon.Retrieve();

                    return result;
                }, new InvalidateWith(typeof(ChartScriptEntity)));

                RegisterOperations();
            }
        }
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<SmtpConfigurationEntity>();

                dqm.RegisterQuery(typeof(SmtpConfigurationEntity), () =>
                    from s in Database.Query<SmtpConfigurationEntity>()
                    select new
                    {
                        Entity = s,
                        s.Id,
                        s.DeliveryMethod,
                        s.Network.Host,
                        s.Network.Username,
                        s.PickupDirectoryLocation
                    });

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

                new Graph<SmtpConfigurationEntity>.Execute(SmtpConfigurationOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (sc, _) => { },
                }.Register();
            }
        }
예제 #7
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, HashSet<Type> registerExpression)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<ViewLogEntity>();

                dqm.RegisterQuery(typeof(ViewLogEntity), () =>
                    from e in Database.Query<ViewLogEntity>()
                    select new
                    {
                        Entity = e,
                        e.Id,
                        e.Target,
                        e.ViewAction,
                        e.User,
                        e.Duration,
                        e.StartDate,
                        e.EndDate,
                    });

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;

                var exp = Signum.Utilities.ExpressionTrees.Linq.Expr((Entity entity) => entity.ViewLogs());

                foreach (var t in registerExpression)
                {
                    dqm.RegisterExpression(new ExtensionInfo(t, exp, exp.Body.Type, "ViewLogs", () => typeof(ViewLogEntity).NicePluralName()));
                }

                DynamicQueryManager.Current.QueryExecuted += Current_QueryExecuted;
                sb.Schema.Table<TypeEntity>().PreDeleteSqlSync += Type_PreDeleteSqlSync;
            }
        }
예제 #8
0
        private static void StartSouthwindConfiguration(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            sb.Include <ApplicationConfigurationEntity>();
            Configuration = sb.GlobalLazy <ApplicationConfigurationEntity>(
                () => Database.Query <ApplicationConfigurationEntity>().Single(a => a.Environment == Settings.Default.Environment),
                new InvalidateWith(typeof(ApplicationConfigurationEntity)));

            new Graph <ApplicationConfigurationEntity> .Execute(ApplicationConfigurationOperation.Save)
            {
                AllowsNew = true,
                Lite      = false,
                Execute   = (e, _) => { },
            }

            .Register();

            dqm.RegisterQuery(typeof(ApplicationConfigurationEntity), () =>
                              from s in Database.Query <ApplicationConfigurationEntity>()
                              select new
            {
                Entity = s,
                s.Id,
                s.Environment,
                s.Email.SendEmails,
                s.Email.OverrideEmailAddress,
                s.Email.DefaultCulture,
                s.Email.UrlLeft
            });
        }
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                IsStarted = true;

                AuthLogic.AssertStarted(sb);
                sb.Include<UserTicketEntity>();

                dqm.RegisterQuery(typeof(UserTicketEntity), () =>
                    from ut in Database.Query<UserTicketEntity>()
                    select new
                    {
                        Entity = ut,
                        ut.Id,
                        ut.User,
                        ut.Ticket,
                        ut.ConnectionDate,
                        ut.Device,
                    });

                dqm.RegisterExpression((UserEntity u) => u.UserTickets(), () => typeof(UserTicketEntity).NicePluralName());

                sb.Schema.EntityEvents<UserEntity>().Saving += UserTicketLogic_Saving; 
            }
        }
예제 #10
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                AuthLogic.AssertStarted(sb);

                sb.Include<SessionLogEntity>();

                PermissionAuthLogic.RegisterPermissions(SessionLogPermission.TrackSession);

                dqm.RegisterQuery(typeof(SessionLogEntity), () =>
                    from sl in Database.Query<SessionLogEntity>()
                    select new
                    {
                        Entity = sl,
                        sl.Id,
                        sl.User,
                        sl.SessionStart,
                        sl.SessionEnd,
                        sl.SessionTimeOut
                    });

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;
            }
        }
예제 #11
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <ShipperEntity>();

                dqm.RegisterQuery(typeof(ShipperEntity), () =>
                                  from a in Database.Query <ShipperEntity>()
                                  select new
                {
                    Entity = a,
                    a.Id,
                    a.CompanyName,
                    a.Phone
                });

                new Graph <ShipperEntity> .Execute(ShipperOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (e, _) => { }
                }

                .Register();
            }
        }
예제 #12
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, bool excelReport)
        {
            if (excelReport)
            {
                QueryLogic.Start(sb);

                sb.Include<ExcelReportEntity>();
                dqm.RegisterQuery(typeof(ExcelReportEntity), () =>
                    from s in Database.Query<ExcelReportEntity>()
                    select new
                    {
                        Entity = s,
                        s.Id,
                        s.Query,
                        s.File.FileName,
                        s.DisplayName,
                    });

                new Graph<ExcelReportEntity>.Execute(ExcelReportOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (er, _) => { }
                }.Register();

                new Graph<ExcelReportEntity>.Delete(ExcelReportOperation.Delete)
                {
                    Lite = true,
                    Delete = (er, _) => { er.Delete(); }
                }.Register();
            }
        }
예제 #13
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                FileTypeLogic.Start(sb, dqm);

                sb.Include<FilePathEntity>();

                sb.Schema.EntityEvents<FilePathEntity>().Retrieved += FilePathLogic_Retrieved;
                sb.Schema.EntityEvents<FilePathEntity>().PreSaving += FilePath_PreSaving;
                sb.Schema.EntityEvents<FilePathEntity>().PreUnsafeDelete += new PreUnsafeDeleteHandler<FilePathEntity>(FilePathLogic_PreUnsafeDelete);

                dqm.RegisterQuery(typeof(FilePathEntity), () =>
                    from p in Database.Query<FilePathEntity>()
                    select new
                    {
                        Entity = p,
                        p.Id,
                        p.FileName,
                        p.FileType,
                        p.Sufix
                    });

                new Graph<FilePathEntity>.Execute(FilePathOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (fp, _) =>
                    {
                        if (!fp.IsNew)
                        {

                            var ofp = fp.ToLite().Retrieve();


                            if (fp.FileName != ofp.FileName || fp.Sufix != ofp.Sufix || fp.FullPhysicalPath != ofp.FullPhysicalPath)
                            {
                                using (Transaction tr = new Transaction())
                                {
                                    var preSufix = ofp.Sufix.Substring(0, ofp.Sufix.Length - ofp.FileName.Length);
                                    fp.Sufix = Path.Combine(preSufix, fp.FileName);
                                    fp.Save();
                                    System.IO.File.Move(ofp.FullPhysicalPath, fp.FullPhysicalPath);
                                    tr.Commit();
                                }
                            }
                        }
                    }
                }.Register();

                OperationLogic.SetProtectedSave<FilePathEntity>(false);

                sb.AddUniqueIndex<FilePathEntity>(f => new { f.Sufix, f.FileType }); //With mixins, add AttachToUniqueIndexes to field

                dqm.RegisterExpression((FilePathEntity fp) => fp.WebImage(), () => typeof(WebImage).NiceName(), "Image");
                dqm.RegisterExpression((FilePathEntity fp) => fp.WebDownload(), () => typeof(WebDownload).NiceName(), "Download");

            }
        }
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<PasswordExpiresIntervalEntity>();

                dqm.RegisterQuery(typeof(PasswordExpiresIntervalEntity), ()=>
                    from e in Database.Query<PasswordExpiresIntervalEntity>()
                     select new
                     {
                         Entity = e,
                         e.Id,
                         e.Enabled,
                         e.Days,
                         e.DaysWarning
                     });

                new Graph<PasswordExpiresIntervalEntity>.Execute(PasswordExpiresIntervalOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (pei, _) => { },
                }.Register();

                AuthLogic.UserLogingIn += (u =>
                {
                    if (u.PasswordNeverExpires)
                        return;

                    var ivp = Database.Query<PasswordExpiresIntervalEntity>().Where(p => p.Enabled).FirstOrDefault();
                    if (ivp == null)
                        return;
                    
                    if (TimeZoneManager.Now > u.PasswordSetDate.AddDays((double)ivp.Days))
                        throw new PasswordExpiredException(AuthMessage.ExpiredPassword.NiceToString());
                });

                AuthLogic.LoginMessage += (() =>
                {
                    UserEntity u = UserEntity.Current;

                    if (u.PasswordNeverExpires)
                        return null;

                    PasswordExpiresIntervalEntity ivp = null;
                    using (AuthLogic.Disable())
                        ivp = Database.Query<PasswordExpiresIntervalEntity>().Where(p => p.Enabled).FirstOrDefault();
                    
                    if (ivp == null)
                        return null;

                    if (TimeZoneManager.Now > u.PasswordSetDate.AddDays((double)ivp.Days).AddDays((double)-ivp.DaysWarning))
                        return AuthMessage.YourPasswordIsNearExpiration.NiceToString();

                    return null;
                });
            }
        }
예제 #15
0
        public static void StartProcesses(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            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());

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

                .Register();

                dqm.RegisterQuery(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),
                });

                dqm.RegisterQuery(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),
                });
            }
        }
예제 #16
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <OperationLogEntity>();

                SymbolLogic <OperationSymbol> .Start(sb, () => RegisteredOperations);

                dqm.RegisterQuery(typeof(OperationSymbol), () =>
                                  from os in Database.Query <OperationSymbol>()
                                  select new
                {
                    Entity = os,
                    os.Id,
                    os.Key
                });

                dqm.RegisterQuery(typeof(OperationLogEntity), () =>
                                  from lo in Database.Query <OperationLogEntity>()
                                  select new
                {
                    Entity = lo,
                    lo.Id,
                    lo.Target,
                    lo.Operation,
                    lo.User,
                    lo.Start,
                    lo.End,
                    lo.Exception
                });

                dqm.RegisterExpression((OperationSymbol o) => o.Logs(), () => OperationMessage.Logs.NiceToString());
                dqm.RegisterExpression((Entity o) => o.OperationLogs(), () => typeof(OperationLogEntity).NicePluralName());

                sb.Schema.EntityEventsGlobal.Saving += EntityEventsGlobal_Saving;

                sb.Schema.Table <OperationSymbol>().PreDeleteSqlSync += new Func <Entity, SqlPreCommand>(Operation_PreDeleteSqlSync);
                sb.Schema.Table <TypeEntity>().PreDeleteSqlSync      += new Func <Entity, SqlPreCommand>(Type_PreDeleteSqlSync);

                sb.Schema.SchemaCompleted += OperationLogic_Initializing;

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;
            }
        }
예제 #17
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            sb.Include<ExcelAttachmentEntity>();
            dqm.RegisterQuery(typeof(ExcelAttachmentEntity), () =>
                from s in Database.Query<ExcelAttachmentEntity>()
                select new
                {
                    Entity = s,
                    s.Id,
                    s.FileName,
                    s.UserQuery,
                    s.Related,
                });


            EmailTemplateLogic.FillAttachmentTokens.Register((ExcelAttachmentEntity uqe, EmailTemplateLogic.FillAttachmentTokenContext ctx) =>
            {
                if (uqe.FileName != null)
                    EmailTemplateParser.Parse(uqe.FileName, ctx.QueryDescription, ctx.ModelType).FillQueryTokens(ctx.QueryTokens);

                if (uqe.Title != null)
                    EmailTemplateParser.Parse(uqe.Title, ctx.QueryDescription, ctx.ModelType).FillQueryTokens(ctx.QueryTokens);
            });

            Validator.PropertyValidator((ExcelAttachmentEntity e) => e.FileName).StaticPropertyValidation = ExcelAttachmentFileName_StaticPropertyValidation;
            Validator.PropertyValidator((ExcelAttachmentEntity e) => e.Title).StaticPropertyValidation = ExcelAttachmentTitle_StaticPropertyValidation;

            EmailTemplateLogic.GenerateAttachment.Register((ExcelAttachmentEntity uqe, EmailTemplateLogic.GenerateAttachmentContext ctx) =>
            {
                var finalEntity = uqe.Related?.Retrieve() ?? (Entity)ctx.Entity;

                using (finalEntity == null ? null : CurrentEntityConverter.SetCurrentEntity(finalEntity))
                using (CultureInfoUtils.ChangeBothCultures(ctx.Culture))
                {
                    QueryRequest request = UserQueryLogic.ToQueryRequest(uqe.UserQuery.Retrieve());

                    var title = GetTemplateString(uqe.Title, ref uqe.TitleNode, ctx);
                    var fileName = GetTemplateString(uqe.FileName, ref uqe.FileNameNode, ctx);

                    var bytes = ExcelLogic.ExecutePlainExcel(request, title);

                    return new List<EmailAttachmentEntity>
                        {
                            new EmailAttachmentEntity
                            {
                                File = Files.EmbeddedFilePathLogic.SaveFile(new Entities.Files.EmbeddedFilePathEntity(EmailFileType.Attachment, fileName, bytes)),
                                Type = EmailAttachmentType.Attachment,
                            }
                        };
                }
            });
        }
예제 #18
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <EmployeeEntity>()
                .WithSave(EmployeeOperation.Save)
                .WithQuery(dqm, () => e => new
                {
                    Entity = e,
                    e.Id,
                    e.FirstName,
                    e.LastName,
                    e.BirthDate,
                    e.Photo,     //1
                });

                dqm.RegisterQuery(EmployeeQuery.EmployeesByTerritory, () =>
                                  from e in Database.Query <EmployeeEntity>()
                                  from t in e.Territories
                                  select new
                {
                    Entity = e,
                    e.Id,
                    e.FirstName,
                    e.LastName,
                    e.BirthDate,
                    e.Photo,     //2
                    Territory = t,
                });

                sb.Include <RegionEntity>()
                .WithSave(RegionOperation.Save)
                .WithQuery(dqm, () => r => new
                {
                    Entity = r,
                    r.Id,
                    r.Description,
                });

                sb.Include <TerritoryEntity>()
                .WithSave(TerritoryOperation.Save)
                .WithExpressionFrom(dqm, (RegionEntity r) => r.Territories())
                .WithQuery(dqm, () => t => new
                {
                    Entity = t,
                    t.Id,
                    t.Description,
                    t.Region
                });
            }
        }
예제 #19
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                if (sb.Schema.Tables.ContainsKey(typeof(UserChartEntity)))
                    throw new InvalidOperationException("UserChart has already been registered");

                UserAssetsImporter.RegisterName<UserChartEntity>("UserChart");

                sb.Schema.Synchronizing += Schema_Synchronizing;

                sb.Include<UserChartEntity>();

                dqm.RegisterQuery(typeof(UserChartEntity), () =>
                    from uq in Database.Query<UserChartEntity>()
                    select new
                    {
                        Entity = uq,
                        uq.Query,
                        uq.EntityType,
                        uq.Id,
                        uq.DisplayName,
                        uq.ChartScript,
                        uq.GroupResults,
                    });

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

                new Graph<UserChartEntity>.Execute(UserChartOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (uc, _) => { }
                }.Register();

                new Graph<UserChartEntity>.Delete(UserChartOperation.Delete)
                {
                    Delete = (uc, _) => { uc.Delete(); }
                }.Register();

                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).GroupToDictionary(a => a.Query.ToQueryName(), a => a.ToLite()),
                    new InvalidateWith(typeof(UserChartEntity)));

                UserChartsByType = sb.GlobalLazy(() => UserCharts.Value.Values.Where(a => a.EntityType != null).GroupToDictionary(a => TypeLogic.IdToType.GetOrThrow(a.EntityType.Id), a => a.ToLite()),
                    new InvalidateWith(typeof(UserChartEntity)));
            }
        }
예제 #20
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                QueryLogic.Start(sb);

                PermissionAuthLogic.RegisterPermissions(UserQueryPermission.ViewUserQuery);

                UserAssetsImporter.RegisterName<UserQueryEntity>("UserQuery");

                sb.Schema.Synchronizing += Schema_Synchronizing;

                sb.Include<UserQueryEntity>();

                dqm.RegisterQuery(typeof(UserQueryEntity), () =>
                    from uq in Database.Query<UserQueryEntity>()
                    select new
                    {
                        Entity = uq,
                        uq.Query,
                        uq.Id,
                        uq.DisplayName,
                        uq.EntityType,
                    });

                sb.Schema.EntityEvents<UserQueryEntity>().Retrieved += UserQueryLogic_Retrieved;

                new Graph<UserQueryEntity>.Execute(UserQueryOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (uq, _) => { }
                }.Register();

                new Graph<UserQueryEntity>.Delete(UserQueryOperation.Delete)
                {
                    Lite = true,
                    Delete = (uq, _) => uq.Delete()
                }.Register();

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

                UserQueriesByQuery = sb.GlobalLazy(() => UserQueries.Value.Values.Where(a => a.EntityType == null).GroupToDictionary(a => a.Query.ToQueryName(), a => a.ToLite()),
                    new InvalidateWith(typeof(UserQueryEntity)));

                UserQueriesByType = sb.GlobalLazy(() => UserQueries.Value.Values.Where(a => a.EntityType != null).GroupToDictionary(a => TypeLogic.IdToType.GetOrThrow(a.EntityType.Id), a => a.ToLite()),
                    new InvalidateWith(typeof(UserQueryEntity)));
            }
        }
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<TranslationReplacementEntity>();

                sb.AddUniqueIndex<TranslationReplacementEntity>(tr => new { tr.CultureInfo, tr.WrongTranslation });

                dqm.RegisterQuery(typeof(TranslationReplacementEntity), () =>
                   from e in Database.Query<TranslationReplacementEntity>()
                   select new
                   {
                       Entity = e,
                       e.Id,
                       e.CultureInfo,
                       e.WrongTranslation,
                       e.RightTranslation,
                   });

                new Graph<TranslationReplacementEntity>.Execute(TranslationReplacementOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { },
                }.Register();

                new Graph<TranslationReplacementEntity>.Delete(TranslationReplacementOperation.Delete)
                {
                    Delete = (e, _) => { e.Delete(); },
                }.Register();

                ReplacementsLazy = sb.GlobalLazy(() => Database.Query<TranslationReplacementEntity>()
                    .AgGroupToDictionary(a => a.CultureInfo.ToCultureInfo(),
                    gr =>
                    {
                        var dic = gr.ToDictionary(a => a.WrongTranslation, a => a.RightTranslation, StringComparer.InvariantCultureIgnoreCase, "wrong translations");

                        var regex = new Regex(dic.Keys.ToString(Regex.Escape, "|"), RegexOptions.IgnoreCase);

                        return new TranslationReplacementPack { Dictionary = dic, Regex = regex };
                    }),
                    new InvalidateWith(typeof(TranslationReplacementEntity)));

            }
        }
예제 #22
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                SymbolLogic<FileTypeSymbol>.Start(sb, () => FileTypes.Keys.ToHashSet());

                dqm.RegisterQuery(typeof(FileTypeSymbol), () =>
                    from f in Database.Query<FileTypeSymbol>()
                    select new
                    {
                        Entity = f,
                        f.Key
                    });


                sb.Schema.SchemaCompleted += Schema_SchemaCompleted;
            }
        }
예제 #23
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                Schema current = Schema.Current;

                current.SchemaCompleted += () =>
                {
                    var attributes = current.Tables.Keys.Select(t => KVP.Create(t, t.GetCustomAttribute <EntityKindAttribute>(true))).ToList();

                    var errors = attributes.Where(a => a.Value == null).ToString(a => "Type {0} does not have an EntityTypeAttribute".FormatWith(a.Key.Name), "\r\n");

                    if (errors.HasText())
                    {
                        throw new InvalidOperationException(errors);
                    }
                };

                current.Initializing += () =>
                {
                    current.typeCachesLazy.Load();
                };

                current.typeCachesLazy = sb.GlobalLazy(() => new TypeCaches(current),
                                                       new InvalidateWith(typeof(TypeEntity)));

                dqm.RegisterQuery(typeof(TypeEntity), () =>
                                  from t in Database.Query <TypeEntity>()
                                  select new
                {
                    Entity = t,
                    t.Id,
                    t.TableName,
                    t.CleanName,
                    t.FullClassName,
                });

                TypeEntity.SetTypeDNCallbacks(
                    t => TypeToEntity.GetOrThrow(t),
                    t => DnToType.GetOrThrow(t));
            }
        }
예제 #24
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<FileEntity>();

                dqm.RegisterQuery(typeof(FileEntity), () =>
                    from a in Database.Query<FileEntity>()
                    select new
                    {
                        Entity = a,
                        a.Id,
                        a.FileName,
                    });


                dqm.RegisterExpression((FileEntity f) => f.WebImage(), () => typeof(WebImage).NiceName(), "Image");
                dqm.RegisterExpression((FileEntity f) => f.WebDownload(), () => typeof(WebDownload).NiceName(), "Download");
            }
        }
예제 #25
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, bool countLocalizationHits)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                CultureInfoLogic.AssertStarted(sb);

                sb.Include<TranslatorUserEntity>();

                dqm.RegisterQuery(typeof(TranslatorUserEntity), () =>
                    from e in Database.Query<TranslatorUserEntity>()
                    select new
                    {
                        Entity = e,
                        e.Id,
                        e.User,
                        Cultures = e.Cultures.Count,
                    });


                PermissionAuthLogic.RegisterTypes(typeof(TranslationPermission));

                dqm.RegisterExpression((IUserEntity e) => e.TranslatorUser(), () => typeof(TranslatorUserEntity).NiceName());

                new Graph<TranslatorUserEntity>.Execute(TranslatorUserOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { }
                }.Register();

                new Graph<TranslatorUserEntity>.Delete(TranslatorUserOperation.Delete)
                {
                    Delete = (e, _) => { e.Delete(); }
                }.Register();

                if (countLocalizationHits)
                    DescriptionManager.NotLocalizedMemeber += DescriptionManager_NotLocalizedMemeber;


            }
        }
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<ApplicationEventLogEntity>();
                dqm.RegisterQuery(typeof(ApplicationEventLogEntity), () =>
                   from s in Database.Query<ApplicationEventLogEntity>()
                   select new
                   {
                       Entity = s,
                       s.Id,
                       s.MachineName,
                       s.GlobalEvent,
                       s.Date,
                   });


                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;

            }
        }
예제 #27
0
        internal static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                SymbolLogic<SimpleTaskSymbol>.Start(sb, () => tasks.Keys.ToHashSet());

                SchedulerLogic.ExecuteTask.Register((SimpleTaskSymbol st) =>
                {
                    Func<Lite<IEntity>> func = tasks.GetOrThrow(st);
                    return func();
                });


                dqm.RegisterQuery(typeof(SimpleTaskSymbol), ()=>
                      from ct in Database.Query<SimpleTaskSymbol>()
                       select new
                       {
                           Entity = ct,
                           ct.Id,
                           ct.Key,
                       });
            }
        }
예제 #28
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<ShipperEntity>();

                dqm.RegisterQuery(typeof(ShipperEntity), () =>
                    from a in Database.Query<ShipperEntity>()
                    select new
                    {
                        Entity = a,
                        a.Id,
                        a.CompanyName,
                        a.Phone
                    });

                new Graph<ShipperEntity>.Execute(ShipperOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { }
                }.Register();
            }
        }
예제 #29
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Settings.AssertImplementedBy((OrderEntity o) => o.Customer, typeof(CompanyEntity));
                sb.Settings.AssertImplementedBy((OrderEntity o) => o.Customer, typeof(PersonEntity));

                sb.Include<PersonEntity>();
                sb.Include<CompanyEntity>();

                dqm.RegisterQuery(typeof(PersonEntity), () =>
                    from r in Database.Query<PersonEntity>()
                    select new
                    {
                        Entity = r,
                        r.Id,
                        r.FirstName,
                        r.LastName,
                        r.DateOfBirth,
                        r.Phone,
                        r.Fax,
                        r.Address,
                    });

                dqm.RegisterQuery(typeof(CompanyEntity), () =>
                    from r in Database.Query<CompanyEntity>()
                    select new
                    {
                        Entity = r,
                        r.Id,
                        r.CompanyName,
                        r.ContactName,
                        r.ContactTitle,
                        r.Phone,
                        r.Fax,
                        r.Address,
                    });

                new Graph<CustomerEntity>.Execute(CustomerOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { }
                }.Register();

                new Graph<CompanyEntity>.Execute(CustomerOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { }
                }.RegisterReplace();

                new Graph<PersonEntity>.Execute(CustomerOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { }
                }.RegisterReplace();

                dqm.RegisterQuery(CustomerQuery.Customer, () => DynamicQueryCore.Manual((QueryRequest request, QueryDescription descriptions) =>
                {
                    var persons = Database.Query<PersonEntity>().Select(p => new
                    {
                        Entity = p.ToLite<CustomerEntity>(),
                        Id = "P " + p.Id,
                        Name = p.FirstName + " " + p.LastName,
                        p.Address,
                        p.Phone,
                        p.Fax
                    }).ToDQueryable(descriptions).AllQueryOperations(request);

                    var companies = Database.Query<CompanyEntity>().Select(p => new
                    {
                        Entity = p.ToLite<CustomerEntity>(),
                        Id = "C " + p.Id,
                        Name = p.CompanyName,
                        p.Address,
                        p.Phone,
                        p.Fax
                    }).ToDQueryable(descriptions).AllQueryOperations(request);

                    return persons.Concat(companies)
                        .OrderBy(request.Orders)
                        .TryPaginate(request.Pagination);

                })
                .ColumnProperyRoutes(a => a.Id,
                    PropertyRoute.Construct((PersonEntity comp) => comp.Id),
                    PropertyRoute.Construct((CompanyEntity p) => p.Id))
                .ColumnProperyRoutes(a => a.Name,
                    PropertyRoute.Construct((PersonEntity comp) => comp.FirstName),
                    PropertyRoute.Construct((PersonEntity comp) => comp.LastName),
                    PropertyRoute.Construct((CompanyEntity p) => p.CompanyName))
                .ColumnProperyRoutes(a => a.Address,
                    PropertyRoute.Construct((PersonEntity comp) => comp.Address),
                    PropertyRoute.Construct((PersonEntity comp) => comp.Address))
                .ColumnProperyRoutes(a => a.Phone,
                    PropertyRoute.Construct((PersonEntity comp) => comp.Phone),
                    PropertyRoute.Construct((CompanyEntity p) => p.Phone))
                .ColumnProperyRoutes(a => a.Fax,
                    PropertyRoute.Construct((PersonEntity comp) => comp.Fax),
                    PropertyRoute.Construct((CompanyEntity p) => p.Fax))
                , entityImplementations: Implementations.By(typeof(PersonEntity), typeof(CompanyEntity)));

                dqm.RegisterExpression((CustomerEntity c) => c.Address).ForcePropertyRoute = PropertyRoute.Construct((PersonEntity p) => p.Address);
                dqm.RegisterExpression((CustomerEntity c) => c.Phone).ForcePropertyRoute = PropertyRoute.Construct((PersonEntity p) => p.Address);
                dqm.RegisterExpression((CustomerEntity c) => c.Fax).ForcePropertyRoute = PropertyRoute.Construct((PersonEntity p) => p.Address);

            }
        }
예제 #30
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<EmployeeEntity>();

                dqm.RegisterQuery(typeof(RegionEntity), () =>
                    from r in Database.Query<RegionEntity>()
                    select new
                    {
                        Entity = r.ToLite(),
                        r.Id,
                        r.Description,
                    });

                dqm.RegisterExpression((RegionEntity r) => r.Territories(), () => typeof(TerritoryEntity).NiceName());

                dqm.RegisterQuery(typeof(TerritoryEntity), () =>
                    from t in Database.Query<TerritoryEntity>()
                    select new
                    {
                        Entity = t.ToLite(),
                        t.Id,
                        t.Description,
                        Region = t.Region.ToLite()
                    });

                dqm.RegisterQuery(typeof(EmployeeEntity), () =>
                    from e in Database.Query<EmployeeEntity>()
                    select new
                    {
                        Entity = e.ToLite(),
                        e.Id,
                        e.FirstName,
                        e.LastName,
                        e.BirthDate,
                        e.Photo, //1
                    });

                dqm.RegisterQuery(EmployeeQuery.EmployeesByTerritory, () =>
                    from e in Database.Query<EmployeeEntity>()
                    from t in e.Territories
                    select new
                    {
                        Entity = e.ToLite(),
                        e.Id,
                        e.FirstName,
                        e.LastName,
                        e.BirthDate,
                        e.Photo, //2
                        Territory = t.ToLite(),
                    });

                new Graph<EmployeeEntity>.Execute(EmployeeOperation.Save)
                {
                    Lite = false,
                    AllowsNew = true,
                    Execute = (e, _) => { }
                }.Register();

                new Graph<TerritoryEntity>.Execute(TerritoryOperation.Save)
                {
                    Lite = false,
                    AllowsNew = true,
                    Execute = (e, _) => { }
                }.Register();

                new Graph<RegionEntity>.Execute(RegionOperation.Save)
                {
                    Lite = false,
                    AllowsNew = true,
                    Execute = (e, _) => { }
                }.Register();
            }
        }
예제 #31
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            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) => { throw new NotImplementedException("SchedulerLogic.ExecuteTask not registered for {0}".FormatWith(t.GetType().Name)); });

                SimpleTaskLogic.Start(sb, dqm);
                sb.Include<ScheduledTaskEntity>();
                sb.Include<ScheduledTaskLogEntity>();

                dqm.RegisterQuery(typeof(HolidayCalendarEntity), () =>
                     from st in Database.Query<HolidayCalendarEntity>()
                     select new
                     {
                         Entity = st,
                         st.Id,
                         st.Name,
                         Holidays = st.Holidays.Count,
                     });


                dqm.RegisterQuery(typeof(ScheduledTaskEntity), () =>
                    from st in Database.Query<ScheduledTaskEntity>()
                    select new
                    {
                        Entity = st,
                        st.Id,
                        st.Task,
                        st.Rule,
                        st.Suspended,
                        st.MachineName,
                        st.ApplicationName
                    });

                dqm.RegisterQuery(typeof(ScheduledTaskLogEntity), () =>
                    from cte in Database.Query<ScheduledTaskLogEntity>()
                    select new
                    {
                        Entity = cte,
                        cte.Id,
                        cte.Task,
                        cte.ScheduledTask,
                        cte.StartTime,
                        cte.EndTime,
                        cte.ProductEntity,
                        cte.MachineName,
                        cte.User,
                        cte.Exception,

                    });

                dqm.RegisterExpression((ITaskEntity ct) => ct.Executions(), () => TaskMessage.Executions.NiceToString());
                dqm.RegisterExpression((ITaskEntity ct) => ct.LastExecution(), () => TaskMessage.LastExecution.NiceToString());
                dqm.RegisterExpression((ScheduledTaskEntity ct) => ct.Executions(), () => TaskMessage.Executions.NiceToString());

                new Graph<HolidayCalendarEntity>.Execute(HolidayCalendarOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (c, _) => { },
                }.Register();

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

                new Graph<ScheduledTaskEntity>.Execute(ScheduledTaskOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    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<IEntity>.ConstructFrom<ITaskEntity>(TaskOperation.ExecuteSync)
                {
                    Construct = (task, _) => ExecuteSync(task, null, UserHolder.Current)?.Retrieve()
                }.Register();

                new Graph<ITaskEntity>.Execute(TaskOperation.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;

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;
            }
        }
예제 #32
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, string systemUserName, string anonymousUserName)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                SystemUserName = systemUserName;
                AnonymousUserName = anonymousUserName;

                CultureInfoLogic.AssertStarted(sb); 

                sb.Include<UserEntity>();

                sb.Include<RoleEntity>()
                    .WithSave(RoleOperation.Save)
                    .WithDelete(RoleOperation.Delete)
                    .WithQuery(dqm, r => new
                    {
                        Entity = r,
                        r.Id,
                        r.Name,
                    });


                sb.Include<LastAuthRulesImportEntity>(); 

                roles = sb.GlobalLazy(CacheRoles, new InvalidateWith(typeof(RoleEntity)), AuthLogic.NotifyRulesChanged);
                mergeStrategies = sb.GlobalLazy(() =>
                {
                    var strategies = Database.Query<RoleEntity>().Select(r => KVP.Create(r.ToLite(), r.MergeStrategy)).ToDictionary();

                    var graph = roles.Value;

                    Dictionary<Lite<RoleEntity>, RoleData> result = new Dictionary<Lite<RoleEntity>, RoleData>();
                    foreach (var r in graph.CompilationOrder())
                    {
                        var strat = strategies.GetOrThrow(r);

                        var baseValues = graph.RelatedTo(r).Select(r2=>result[r2].DefaultAllowed);

                        result.Add(r, new RoleData
                        {
                            MergeStrategy = strat,
                            DefaultAllowed = strat == MergeStrategy.Union ? baseValues.Any(a => a) : baseValues.All(a => a)
                        }); 
                    }

                    return result;
                }, new InvalidateWith(typeof(RoleEntity)), AuthLogic.NotifyRulesChanged);

                sb.Schema.EntityEvents<RoleEntity>().Saving += Schema_Saving;
                
                dqm.RegisterQuery(RoleQuery.RolesReferedBy, () =>
                    from r in Database.Query<RoleEntity>()
                    from rc in r.Roles
                    select new
                    {
                        Entity = r,
                        r.Id,
                        r.Name,
                        Refered = rc,
                    });

                dqm.RegisterQuery(typeof(UserEntity), () =>
                    from e in Database.Query<UserEntity>()
                    select new
                    {
                        Entity = e,
                        e.Id,
                        e.UserName,
                        e.Email,
                        e.Role,
                        e.State,
                    });

                UserGraph.Register();

             
            }
        }
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, Func<Pop3ConfigurationEntity, IPop3Client> getPop3Client, FileTypeAlgorithm attachment)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                GetPop3Client = getPop3Client;

                FilePathLogic.Register(EmailFileType.Attachment, attachment);

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

                MimeType.CacheExtension.TryAdd("message/rfc822", ".eml");

                sb.Include<Pop3ConfigurationEntity>();
                sb.Include<Pop3ReceptionEntity>();
                sb.Include<Pop3ReceptionExceptionEntity>();

                dqm.RegisterQuery(typeof(EmailMessageEntity), () =>
                   from e in Database.Query<EmailMessageEntity>()
                   select 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(Pop3ConfigurationEntity), () =>
                    from s in Database.Query<Pop3ConfigurationEntity>()
                    select new
                    {
                        Entity = s,
                        s.Id,
                        s.Host,
                        s.Port,
                        s.Username,
                        s.EnableSSL
                    });

                dqm.RegisterQuery(typeof(Pop3ReceptionEntity), () => DynamicQuery.DynamicQuery.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.RegisterQuery(typeof(Pop3ConfigurationEntity), () =>
                    from s in Database.Query<Pop3ConfigurationEntity>()
                    select new
                    {
                        Entity = s,
                        s.Id,
                        s.Host,
                        s.Port,
                        s.Username,
                        s.EnableSSL
                    });

                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<Pop3ConfigurationEntity>.Execute(Pop3ConfigurationOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { }
                }.Register();

                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) => smtp.ReceiveEmails().ToLite());

                SimpleTaskLogic.Register(Pop3ConfigurationAction.ReceiveAllActivePop3Configurations, () =>
                {
                    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;
                });
            }
        }
예제 #34
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, string systemUserName, string anonymousUserName)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                SystemUserName    = systemUserName;
                AnonymousUserName = anonymousUserName;

                CultureInfoLogic.AssertStarted(sb);

                sb.Include <UserEntity>();

                sb.Include <RoleEntity>()
                .WithSave(RoleOperation.Save)
                .WithDelete(RoleOperation.Delete)
                .WithQuery(dqm, () => r => new
                {
                    Entity = r,
                    r.Id,
                    r.Name,
                });


                sb.Include <LastAuthRulesImportEntity>();

                roles           = sb.GlobalLazy(CacheRoles, new InvalidateWith(typeof(RoleEntity)), AuthLogic.NotifyRulesChanged);
                mergeStrategies = sb.GlobalLazy(() =>
                {
                    var strategies = Database.Query <RoleEntity>().Select(r => KVP.Create(r.ToLite(), r.MergeStrategy)).ToDictionary();

                    var graph = roles.Value;

                    Dictionary <Lite <RoleEntity>, RoleData> result = new Dictionary <Lite <RoleEntity>, RoleData>();
                    foreach (var r in graph.CompilationOrder())
                    {
                        var strat = strategies.GetOrThrow(r);

                        var baseValues = graph.RelatedTo(r).Select(r2 => result[r2].DefaultAllowed);

                        result.Add(r, new RoleData
                        {
                            MergeStrategy  = strat,
                            DefaultAllowed = strat == MergeStrategy.Union ? baseValues.Any(a => a) : baseValues.All(a => a)
                        });
                    }

                    return(result);
                }, new InvalidateWith(typeof(RoleEntity)), AuthLogic.NotifyRulesChanged);

                sb.Schema.EntityEvents <RoleEntity>().Saving += Schema_Saving;

                dqm.RegisterQuery(RoleQuery.RolesReferedBy, () =>
                                  from r in Database.Query <RoleEntity>()
                                  from rc in r.Roles
                                  select new
                {
                    Entity = r,
                    r.Id,
                    r.Name,
                    Refered = rc,
                });
                sb.Include <UserEntity>()
                .WithQuery(dqm, () => e => new
                {
                    Entity = e,
                    e.Id,
                    e.UserName,
                    e.Email,
                    e.Role,
                    e.State,
                });

                UserGraph.Register();
            }
        }
예제 #35
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <EmployeeEntity>();

                dqm.RegisterQuery(typeof(RegionEntity), () =>
                                  from r in Database.Query <RegionEntity>()
                                  select new
                {
                    Entity = r,
                    r.Id,
                    r.Description,
                });

                dqm.RegisterExpression((RegionEntity r) => r.Territories(), () => typeof(TerritoryEntity).NiceName());

                dqm.RegisterQuery(typeof(TerritoryEntity), () =>
                                  from t in Database.Query <TerritoryEntity>()
                                  select new
                {
                    Entity = t,
                    t.Id,
                    t.Description,
                    t.Region
                });

                dqm.RegisterQuery(typeof(EmployeeEntity), () =>
                                  from e in Database.Query <EmployeeEntity>()
                                  select new
                {
                    Entity = e,
                    e.Id,
                    e.FirstName,
                    e.LastName,
                    e.BirthDate,
                    e.Photo,     //1
                });

                dqm.RegisterQuery(EmployeeQuery.EmployeesByTerritory, () =>
                                  from e in Database.Query <EmployeeEntity>()
                                  from t in e.Territories
                                  select new
                {
                    Entity = e,
                    e.Id,
                    e.FirstName,
                    e.LastName,
                    e.BirthDate,
                    e.Photo,     //2
                    Territory = t,
                });

                new Graph <EmployeeEntity> .Execute(EmployeeOperation.Save)
                {
                    Lite      = false,
                    AllowsNew = true,
                    Execute   = (e, _) => { }
                }

                .Register();

                new Graph <TerritoryEntity> .Execute(TerritoryOperation.Save)
                {
                    Lite      = false,
                    AllowsNew = true,
                    Execute   = (e, _) => { }
                }

                .Register();

                new Graph <RegionEntity> .Execute(RegionOperation.Save)
                {
                    Lite      = false,
                    AllowsNew = true,
                    Execute   = (e, _) => { }
                }

                .Register();
            }
        }
예제 #36
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                if (!Schema.Current.Settings.TypeValues.ContainsKey(typeof(TimeSpan)))
                {
                    sb.Settings.FieldAttributes((AlbumEntity a) => a.Songs[0].Duration).Add(new Signum.Entities.IgnoreAttribute());
                    sb.Settings.FieldAttributes((AlbumEntity a) => a.BonusTrack.Duration).Add(new Signum.Entities.IgnoreAttribute());
                }

                sb.Include <AlbumEntity>()
                .WithExpressionFrom(dqm, (IAuthorEntity au) => Database.Query <AlbumEntity>().Where(a => a.Author == au))
                .WithQuery(dqm, () => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.Author,
                    a.Label,
                    a.Year
                });
                AlbumGraph.Register();


                sb.Include <NoteWithDateEntity>()
                .WithSave(NoteWithDateOperation.Save)
                .WithQuery(dqm, () => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Text,
                    a.Target,
                    a.CreationTime,
                });

                sb.Include <ConfigEntity>()
                .WithSave(ConfigOperation.Save);

                MinimumExtensions.IncludeFunction(sb.Schema.Assets);
                sb.Include <ArtistEntity>()
                .WithSave(ArtistOperation.Save)
                .WithQuery(dqm, () => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.IsMale,
                    a.Sex,
                    a.Dead,
                    a.LastAward,
                });

                new Graph <ArtistEntity> .Execute(ArtistOperation.AssignPersonalAward)
                {
                    Lite       = true,
                    AllowsNew  = false,
                    CanExecute = a => a.LastAward != null ? "Artist already has an award" : null,
                    Execute    = (a, para) => a.LastAward = new PersonalAwardEntity()
                    {
                        Category = "Best Artist", Year = DateTime.Now.Year, Result = AwardResult.Won
                    }.Execute(AwardOperation.Save)
                }

                .Register();

                sb.Include <BandEntity>()
                .WithQuery(dqm, () => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.LastAward,
                });

                new Graph <BandEntity> .Execute(BandOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (b, _) =>
                    {
                        using (OperationLogic.AllowSave <ArtistEntity>())
                        {
                            b.Save();
                        }
                    }
                }

                .Register();

                sb.Include <LabelEntity>()
                .WithSave(LabelOperation.Save)
                .WithQuery(dqm, () => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                });

                RegisterAwards(sb, dqm);

                dqm.RegisterQuery(typeof(IAuthorEntity), () => DynamicQueryCore.Manual(async(request, descriptions, token) =>
                {
                    var one = (from a in Database.Query <ArtistEntity>()
                               select new
                    {
                        Entity = (IAuthorEntity)a,
                        a.Id,
                        Type = "Artist",
                        a.Name,
                        Lonely = a.Lonely(),
                        LastAward = a.LastAward
                    })
                              .ToDQueryable(descriptions)
                              .AllQueryOperationsAsync(request, token);

                    var two = (from a in Database.Query <BandEntity>()
                               select new
                    {
                        Entity = (IAuthorEntity)a,
                        a.Id,
                        Type = "Band",
                        a.Name,
                        Lonely = a.Lonely(),
                        LastAward = a.LastAward
                    })
                              .ToDQueryable(descriptions)
                              .AllQueryOperationsAsync(request, token);

                    return((await one).Concat(await two).OrderBy(request.Orders).TryPaginate(request.Pagination));
                })
                                  .Column(a => a.LastAward, cl => cl.Implementations = Implementations.ByAll)
                                  .ColumnProperyRoutes(a => a.Id, PropertyRoute.Construct((ArtistEntity a) => a.Id), PropertyRoute.Construct((BandEntity a) => a.Id)),
                                  entityImplementations: Implementations.By(typeof(ArtistEntity), typeof(BandEntity)));

                Validator.PropertyValidator((NoteWithDateEntity n) => n.Text)
                .IsApplicableValidator <StringLengthValidatorAttribute>(n => Corruption.Strict);
            }
        }
예제 #37
0
        private static void StartSouthwindConfiguration(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            sb.Include<ApplicationConfigurationEntity>();
            Configuration = sb.GlobalLazy<ApplicationConfigurationEntity>(
                () => Database.Query<ApplicationConfigurationEntity>().Single(a => a.Environment == Settings.Default.Environment),
                new InvalidateWith(typeof(ApplicationConfigurationEntity)));

            new Graph<ApplicationConfigurationEntity>.Execute(ApplicationConfigurationOperation.Save)
            {
                AllowsNew = true,
                Lite = false,
                Execute = (e, _) => { },
            }.Register();

            dqm.RegisterQuery(typeof(ApplicationConfigurationEntity), () =>
                from s in Database.Query<ApplicationConfigurationEntity>()
                select new
                {
                    Entity = s,
                    s.Id,
                    s.Environment,
                    s.Email.SendEmails,
                    s.Email.OverrideEmailAddress,
                    s.Email.DefaultCulture,
                    s.Email.UrlLeft
                });
        }
예제 #38
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Settings.AssertImplementedBy((OrderEntity o) => o.Customer, typeof(CompanyEntity));
                sb.Settings.AssertImplementedBy((OrderEntity o) => o.Customer, typeof(PersonEntity));

                sb.Include <PersonEntity>()
                .WithSave(CustomerOperation.Save)
                .WithQuery(dqm, () => r => new
                {
                    Entity = r,
                    r.Id,
                    r.FirstName,
                    r.LastName,
                    r.DateOfBirth,
                    r.Phone,
                    r.Fax,
                    r.Address,
                });

                sb.Include <CompanyEntity>()
                .WithSave(CustomerOperation.Save)
                .WithQuery(dqm, () => r => new
                {
                    Entity = r,
                    r.Id,
                    r.CompanyName,
                    r.ContactName,
                    r.ContactTitle,
                    r.Phone,
                    r.Fax,
                    r.Address,
                });

                dqm.RegisterQuery(CustomerQuery.Customer, () => DynamicQueryCore.Manual(async(request, descriptions, token) =>
                {
                    var persons = Database.Query <PersonEntity>().Select(p => new
                    {
                        Entity = p.ToLite <CustomerEntity>(),
                        Id     = "P " + p.Id,
                        Name   = p.FirstName + " " + p.LastName,
                        p.Address,
                        p.Phone,
                        p.Fax
                    }).ToDQueryable(descriptions).AllQueryOperationsAsync(request, token);

                    var companies = Database.Query <CompanyEntity>().Select(p => new
                    {
                        Entity = p.ToLite <CustomerEntity>(),
                        Id     = "C " + p.Id,
                        Name   = p.CompanyName,
                        p.Address,
                        p.Phone,
                        p.Fax
                    }).ToDQueryable(descriptions).AllQueryOperationsAsync(request, token);

                    return((await persons).Concat(await companies)
                           .OrderBy(request.Orders)
                           .TryPaginate(request.Pagination));
                })
                                  .ColumnProperyRoutes(a => a.Id,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Id),
                                                       PropertyRoute.Construct((CompanyEntity p) => p.Id))
                                  .ColumnProperyRoutes(a => a.Name,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.FirstName),
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.LastName),
                                                       PropertyRoute.Construct((CompanyEntity p) => p.CompanyName))
                                  .ColumnProperyRoutes(a => a.Address,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Address),
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Address))
                                  .ColumnProperyRoutes(a => a.Phone,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Phone),
                                                       PropertyRoute.Construct((CompanyEntity p) => p.Phone))
                                  .ColumnProperyRoutes(a => a.Fax,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Fax),
                                                       PropertyRoute.Construct((CompanyEntity p) => p.Fax))
                                  , entityImplementations: Implementations.By(typeof(PersonEntity), typeof(CompanyEntity)));

                dqm.RegisterExpression((CustomerEntity c) => c.Address).ForcePropertyRoute = PropertyRoute.Construct((PersonEntity p) => p.Address);
                dqm.RegisterExpression((CustomerEntity c) => c.Phone).ForcePropertyRoute   = PropertyRoute.Construct((PersonEntity p) => p.Address);
                dqm.RegisterExpression((CustomerEntity c) => c.Fax).ForcePropertyRoute     = PropertyRoute.Construct((PersonEntity p) => p.Address);
            }
        }
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<WordTemplateEntity>();
                SystemWordTemplateLogic.Start(sb, dqm);

                SymbolLogic<WordTransformerSymbol>.Start(sb, () => Transformers.Keys.ToHashSet());
                SymbolLogic<WordConverterSymbol>.Start(sb, () => Converters.Keys.ToHashSet());

                dqm.RegisterQuery(typeof(WordTemplateEntity), ()=>
                    from e in Database.Query<WordTemplateEntity>()
                    select new
                    {
                        Entity = e,
                        e.Id,
                        e.Query,
                        e.Template.Entity.FileName
                    });

                dqm.RegisterQuery(typeof(WordTransformerSymbol), () =>
                    from f in Database.Query<WordTransformerSymbol>()
                    select new
                    {
                        Entity = f,
                        f.Key
                    });

                dqm.RegisterQuery(typeof(WordConverterSymbol), () =>
                    from f in Database.Query<WordConverterSymbol>()
                    select new
                    {
                        Entity = f,
                        f.Key
                    });

                dqm.RegisterExpression((SystemWordTemplateEntity e) => e.WordTemplates(), () => typeof(WordTemplateEntity).NiceName());

                new Graph<WordTemplateEntity>.Execute(WordTemplateOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { }
                }.Register();

                new Graph<WordTemplateEntity>.Execute(WordTemplateOperation.CreateWordReport)
                {
                    CanExecute = et =>
                    {
                        if (et.SystemWordTemplate != null && SystemWordTemplateLogic.RequiresExtraParameters(et.SystemWordTemplate))
                            return "SystemWordTemplate ({1}) requires extra parameters".FormatWith(et.SystemWordTemplate);

                        return null;
                    },
                    Execute = (et, args) =>
                    {
                        throw new InvalidOperationException("UI-only operation");
                    }
                }.Register();

                TemplatesByType = sb.GlobalLazy(() =>
                {
                    var list = Database.Query<WordTemplateEntity>().Select(r => KVP.Create(r.Query, r.ToLite())).ToList();

                    return (from kvp in list
                            let imp = dqm.GetEntityImplementations(kvp.Key.ToQueryName())
                            where !imp.IsByAll
                            from t in imp.Types
                            group kvp.Value by t into g
                            select KVP.Create(g.Key.ToTypeEntity(), g.ToList())).ToDictionary();

                }, new InvalidateWith(typeof(WordTemplateEntity)));

                WordTemplatesLazy = sb.GlobalLazy(() => Database.Query<WordTemplateEntity>()
                   .ToDictionary(et => et.ToLite()), new InvalidateWith(typeof(WordTemplateEntity)));

                Schema.Current.Synchronizing += Schema_Synchronize_Tokens;

                Validator.PropertyValidator((WordTemplateEntity e) => e.Template).StaticPropertyValidation += ValidateTemplate;
            }
        }
예제 #40
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, bool packages, bool packageOperations)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                ProcessLogic.AssertStarted(sb);

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

                sb.Include <PackageLineEntity>();
                dqm.RegisterQuery(typeof(PackageLineEntity), () =>
                                  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),
                });


                dqm.RegisterExpression((PackageEntity p) => p.Lines(), () => ProcessMessage.Lines.NiceToString());

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

                    sb.Include <PackageEntity>();

                    dqm.RegisterQuery(typeof(PackageEntity), () =>
                                      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),
                    });
                }

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

                    sb.Include <PackageOperationEntity>();

                    dqm.RegisterQuery(typeof(PackageOperationEntity), () =>
                                      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_DeleteLogs;
            }
        }
예제 #41
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<ProductEntity>();

                ActiveProducts = sb.GlobalLazy(() =>
                    Database.Query<ProductEntity>()
                    .Where(a => !a.Discontinued)
                    .Select(p => new { Category = p.Category.Entity, Product = p })
                    .GroupToDictionary(a => a.Category, a => a.Product),
                    new InvalidateWith(typeof(ProductEntity)));

                dqm.RegisterQuery(typeof(ProductEntity), () =>
                    from p in Database.Query<ProductEntity>()
                    select new
                    {
                        Entity = p.ToLite(),
                        p.Id,
                        p.ProductName,
                        p.Supplier,
                        p.Category,
                        p.QuantityPerUnit,
                        p.UnitPrice,
                        p.UnitsInStock,
                        p.Discontinued
                    });

                dqm.RegisterQuery(ProductQuery.Current, () =>
                    from p in Database.Query<ProductEntity>()
                    where !p.Discontinued
                    select new
                    {
                        Entity = p.ToLite(),
                        p.Id,
                        p.ProductName,
                        p.Supplier,
                        p.Category,
                        p.QuantityPerUnit,
                        p.UnitPrice,
                        p.UnitsInStock,
                    });

                dqm.RegisterQuery(typeof(SupplierEntity), () =>
                    from s in Database.Query<SupplierEntity>()
                    select new
                    {
                        Entity = s.ToLite(),
                        s.Id,
                        s.CompanyName,
                        s.ContactName,
                        s.Phone,
                        s.Fax,
                        s.HomePage,
                        s.Address
                    });

                dqm.RegisterQuery(typeof(CategoryEntity), () =>
                    from s in Database.Query<CategoryEntity>()
                    select new
                    {
                        Entity = s.ToLite(),
                        s.Id,
                        s.CategoryName,
                        s.Description,
                        s.Picture
                    });

                new Graph<ProductEntity>.Execute(ProductOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { }
                }.Register();

                new Graph<SupplierEntity>.Execute(SupplierOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { }
                }.Register();

                new Graph<CategoryEntity>.Execute(CategoryOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { }
                }.Register();
            }
        }
예제 #42
0
        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);
                });
            }
        }
예제 #43
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <ProductEntity>();

                ActiveProducts = sb.GlobalLazy(() =>
                                               Database.Query <ProductEntity>()
                                               .Where(a => !a.Discontinued)
                                               .Select(p => new { Category = p.Category.Entity, Product = p })
                                               .GroupToDictionary(a => a.Category, a => a.Product),
                                               new InvalidateWith(typeof(ProductEntity)));

                dqm.RegisterQuery(typeof(ProductEntity), () =>
                                  from p in Database.Query <ProductEntity>()
                                  select new
                {
                    Entity = p,
                    p.Id,
                    p.ProductName,
                    p.Supplier,
                    p.Category,
                    p.QuantityPerUnit,
                    p.UnitPrice,
                    p.UnitsInStock,
                    p.Discontinued
                });

                dqm.RegisterQuery(ProductQuery.Current, () =>
                                  from p in Database.Query <ProductEntity>()
                                  where !p.Discontinued
                                  select new
                {
                    Entity = p,
                    p.Id,
                    p.ProductName,
                    p.Supplier,
                    p.Category,
                    p.QuantityPerUnit,
                    p.UnitPrice,
                    p.UnitsInStock,
                });

                dqm.RegisterQuery(typeof(SupplierEntity), () =>
                                  from s in Database.Query <SupplierEntity>()
                                  select new
                {
                    Entity = s,
                    s.Id,
                    s.CompanyName,
                    s.ContactName,
                    s.Phone,
                    s.Fax,
                    s.HomePage,
                    s.Address
                });

                dqm.RegisterQuery(typeof(CategoryEntity), () =>
                                  from s in Database.Query <CategoryEntity>()
                                  select new
                {
                    Entity = s,
                    s.Id,
                    s.CategoryName,
                    s.Description,
                    s.Picture
                });



                new Graph <ProductEntity> .Execute(ProductOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (e, _) => { }
                }

                .Register();

                new Graph <SupplierEntity> .Execute(SupplierOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (e, _) => { }
                }

                .Register();

                new Graph <CategoryEntity> .Execute(CategoryOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (e, _) => { }
                }

                .Register();
            }
        }
예제 #44
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Settings.AssertImplementedBy((OrderEntity o) => o.Customer, typeof(CompanyEntity));
                sb.Settings.AssertImplementedBy((OrderEntity o) => o.Customer, typeof(PersonEntity));

                sb.Include <PersonEntity>();
                sb.Include <CompanyEntity>();

                dqm.RegisterQuery(typeof(PersonEntity), () =>
                                  from r in Database.Query <PersonEntity>()
                                  select new
                {
                    Entity = r,
                    r.Id,
                    r.FirstName,
                    r.LastName,
                    r.DateOfBirth,
                    r.Phone,
                    r.Fax,
                    r.Address,
                });

                dqm.RegisterQuery(typeof(CompanyEntity), () =>
                                  from r in Database.Query <CompanyEntity>()
                                  select new
                {
                    Entity = r,
                    r.Id,
                    r.CompanyName,
                    r.ContactName,
                    r.ContactTitle,
                    r.Phone,
                    r.Fax,
                    r.Address,
                });

                new Graph <CustomerEntity> .Execute(CustomerOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (e, _) => { }
                }

                .Register();

                new Graph <CompanyEntity> .Execute(CustomerOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (e, _) => { }
                }

                .RegisterReplace();

                new Graph <PersonEntity> .Execute(CustomerOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (e, _) => { }
                }

                .RegisterReplace();

                dqm.RegisterQuery(typeof(CustomerEntity), () => DynamicQuery.Manual((QueryRequest request, QueryDescription descriptions) =>
                {
                    var persons = Database.Query <PersonEntity>().Select(p => new
                    {
                        Entity = p.ToLite <CustomerEntity>(),
                        Id     = "P " + p.Id,
                        Name   = p.FirstName + " " + p.LastName,
                        p.Address,
                        p.Phone,
                        p.Fax
                    }).ToDQueryable(descriptions).AllQueryOperations(request);

                    var companies = Database.Query <CompanyEntity>().Select(p => new
                    {
                        Entity = p.ToLite <CustomerEntity>(),
                        Id     = "C " + p.Id,
                        Name   = p.CompanyName,
                        p.Address,
                        p.Phone,
                        p.Fax
                    }).ToDQueryable(descriptions).AllQueryOperations(request);

                    return(persons.Concat(companies)
                           .OrderBy(request.Orders)
                           .TryPaginate(request.Pagination));
                })
                                  .ColumnProperyRoutes(a => a.Id,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Id),
                                                       PropertyRoute.Construct((CompanyEntity p) => p.Id))
                                  .ColumnProperyRoutes(a => a.Name,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.FirstName),
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.LastName),
                                                       PropertyRoute.Construct((CompanyEntity p) => p.CompanyName))
                                  .ColumnProperyRoutes(a => a.Address,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Address),
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Address))
                                  .ColumnProperyRoutes(a => a.Phone,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Phone),
                                                       PropertyRoute.Construct((CompanyEntity p) => p.Phone))
                                  .ColumnProperyRoutes(a => a.Fax,
                                                       PropertyRoute.Construct((PersonEntity comp) => comp.Fax),
                                                       PropertyRoute.Construct((CompanyEntity p) => p.Fax))
                                  , entityImplementations: Implementations.By(typeof(PersonEntity), typeof(CompanyEntity)));

                dqm.RegisterExpression((CustomerEntity c) => c.Address).ForcePropertyRoute = PropertyRoute.Construct((PersonEntity p) => p.Address);
                dqm.RegisterExpression((CustomerEntity c) => c.Phone).ForcePropertyRoute   = PropertyRoute.Construct((PersonEntity p) => p.Address);
                dqm.RegisterExpression((CustomerEntity c) => c.Fax).ForcePropertyRoute     = PropertyRoute.Construct((PersonEntity p) => p.Address);
            }
        }
예제 #45
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, bool excelReport, bool userQueryExcel)
        {
            if (excelReport)
            {
                QueryLogic.Start(sb);

                sb.Include<ExcelReportEntity>();
                dqm.RegisterQuery(typeof(ExcelReportEntity), () =>
                    from s in Database.Query<ExcelReportEntity>()
                    select new
                    {
                        Entity = s,
                        s.Id,
                        s.Query,
                        s.File.FileName,
                        s.DisplayName,
                    });

                new Graph<ExcelReportEntity>.Execute(ExcelReportOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (er, _) => { }
                }.Register();

                new Graph<ExcelReportEntity>.Delete(ExcelReportOperation.Delete)
                {
                    Lite = true,
                    Delete = (er, _) => { er.Delete(); }
                }.Register();
            }

            if (userQueryExcel)
            {
                sb.Include<ExcelAttachmentEntity>();
                dqm.RegisterQuery(typeof(ExcelAttachmentEntity), () =>
                    from s in Database.Query<ExcelAttachmentEntity>()
                    select new
                    {
                        Entity = s,
                        s.Id,
                        s.FileName,
                        s.UserQuery,
                        s.Related,
                    });

                new Graph<ExcelAttachmentEntity>.Execute(ExcelAttachmentOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (er, _) => { }
                }.Register();


                EmailTemplateLogic.GenerateAttachment.Register((ExcelAttachmentEntity uqe, EmailTemplateEntity template, IEntity entity) =>
                {
                    var finalEntity = uqe.Related?.Retrieve() ?? (Entity)entity;

                    using (finalEntity == null ? null : CurrentEntityConverter.SetCurrentEntity(finalEntity))
                    {
                        QueryRequest request = UserQueryLogic.ToQueryRequest(uqe.UserQuery.Retrieve());

                        var bytes = ExcelLogic.ExecutePlainExcel(request);

                        return new List<EmailAttachmentEntity>
                        {
                            new EmailAttachmentEntity
                            {
                                File = Files.EmbeddedFilePathLogic.SaveFile(new Entities.Files.EmbeddedFilePathEntity(EmailFileType.Attachment, uqe.FileName, bytes)),
                                Type = EmailAttachmentType.Attachment,
                            }
                        };
                    }
                });
            }
        }
예제 #46
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                if (!Schema.Current.Settings.TypeValues.ContainsKey(typeof(TimeSpan)))
                {
                    sb.Settings.FieldAttributes((AlbumEntity a) => a.Songs[0].Duration).Add(new Signum.Entities.IgnoreAttribute());
                    sb.Settings.FieldAttributes((AlbumEntity a) => a.BonusTrack.Duration).Add(new Signum.Entities.IgnoreAttribute());
                }

                sb.Include <AlbumEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.Author,
                    a.Label,
                    a.Year
                });

                sb.Include <NoteWithDateEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Text,
                    a.Target,
                    a.CreationTime,
                });

                sb.Include <PersonalAwardEntity>();
                sb.Include <AwardNominationEntity>();
                sb.Include <ConfigEntity>();

                MinimumExtensions.IncludeFunction(sb.Schema.Assets);
                sb.Include <ArtistEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.IsMale,
                    a.Sex,
                    a.Dead,
                    a.LastAward,
                });

                dqm.RegisterExpression((IAuthorEntity au) => Database.Query <AlbumEntity>().Where(a => a.Author == au), () => typeof(AlbumEntity).NicePluralName(), "Albums");

                sb.Include <BandEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.LastAward,
                });

                sb.Include <LabelEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                });

                sb.Include <AmericanMusicAwardEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Year,
                    a.Category,
                    a.Result,
                });

                sb.Include <GrammyAwardEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Year,
                    a.Category,
                    a.Result
                });

                sb.Include <PersonalAwardEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Year,
                    a.Category,
                    a.Result
                });

                sb.Include <AwardNominationEntity>()
                .WithQuery(dqm, a => new
                {
                    Entity = a,
                    a.Id,
                    a.Award,
                    a.Author
                });

                dqm.RegisterQuery(typeof(IAuthorEntity), () => DynamicQueryCore.Manual((request, descriptions) =>
                {
                    var one = (from a in Database.Query <ArtistEntity>()
                               select new
                    {
                        Entity = (IAuthorEntity)a,
                        a.Id,
                        Type = "Artist",
                        a.Name,
                        Lonely = a.Lonely(),
                        LastAward = a.LastAward
                    }).ToDQueryable(descriptions).AllQueryOperations(request);

                    var two = (from a in Database.Query <BandEntity>()
                               select new
                    {
                        Entity = (IAuthorEntity)a,
                        a.Id,
                        Type = "Band",
                        a.Name,
                        Lonely = a.Lonely(),
                        LastAward = a.LastAward
                    }).ToDQueryable(descriptions).AllQueryOperations(request);

                    return(one.Concat(two).OrderBy(request.Orders).TryPaginate(request.Pagination));
                })
                                  .Column(a => a.LastAward, cl => cl.Implementations = Implementations.ByAll)
                                  .ColumnProperyRoutes(a => a.Id, PropertyRoute.Construct((ArtistEntity a) => a.Id), PropertyRoute.Construct((BandEntity a) => a.Id)),
                                  entityImplementations: Implementations.By(typeof(ArtistEntity), typeof(BandEntity)));

                Validator.PropertyValidator((NoteWithDateEntity n) => n.Text)
                .IsApplicableValidator <StringLengthValidatorAttribute>(n => Corruption.Strict);

                AlbumGraph.Register();

                RegisterOperations();
            }
        }
예제 #47
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<SendEmailTaskEntity>();

                dqm.RegisterQuery(typeof(SendEmailTaskEntity), () =>
                    from e in Database.Query<SendEmailTaskEntity>()
                    select new
                    {
                        Entity = e,
                        e.Id,
                        e.Name,
                        e.EmailTemplate,
                        e.UniqueTarget,
                    });

                Validator.PropertyValidator((SendEmailTaskEntity er) => er.UniqueTarget).StaticPropertyValidation += (er, pi) =>
                {
                    if (er.UniqueTarget != null && er.TargetsFromUserQuery != null)
                        return ValidationMessage._0And1CanNotBeSetAtTheSameTime.NiceToString(pi.NiceName(), ReflectionTools.GetPropertyInfo(()=> er.TargetsFromUserQuery).NiceName());

                    Implementations? implementations = er.EmailTemplate == null ? null : GetImplementations(er.EmailTemplate.InDB(a => a.Query));
                    if (implementations != null && er.UniqueTarget == null && er.TargetsFromUserQuery == null)
                        return ValidationMessage._0IsNotSet.NiceToString(pi.NiceName());

                    if (er.UniqueTarget != null)
                    {
                        if (!implementations.Value.Types.Contains(er.UniqueTarget.EntityType))
                            return ValidationMessage._0ShouldBeOfType1.NiceToString(pi.NiceName(), implementations.Value.Types.CommaOr(t => t.NiceName()));
                    }

                    return null;
                };

                Validator.PropertyValidator((SendEmailTaskEntity er) => er.TargetsFromUserQuery).StaticPropertyValidation += (SendEmailTaskEntity er, PropertyInfo pi) =>
                {
                    Implementations? implementations = er.EmailTemplate == null ? null : GetImplementations(er.EmailTemplate.InDB(a => a.Query));
                    if (implementations != null && er.TargetsFromUserQuery == null && er.UniqueTarget == null)
                        return ValidationMessage._0IsNotSet.NiceToString(pi.NiceName());

                    if (er.TargetsFromUserQuery != null)
                    {
                        var uqImplementations = GetImplementations(er.TargetsFromUserQuery.InDB(a => a.Query));
                        if (!implementations.Value.Types.Intersect(uqImplementations.Value.Types).Any())
                            return ValidationMessage._0ShouldBeOfType1.NiceToString(pi.NiceName(), implementations.Value.Types.CommaOr(t => t.NiceName()));
                    }

                    return null;
                };

                new Graph<SendEmailTaskEntity>.Execute(SendEmailTaskOperation.Save)
                {
                    AllowsNew = true,
                    Lite = false,
                    Execute = (e, _) => { }
                }.Register();

                SchedulerLogic.ExecuteTask.Register((SendEmailTaskEntity er) =>
                {
                    if (er.UniqueTarget != null)
                    {
                        var email = er.EmailTemplate.CreateEmailMessage(er.UniqueTarget?.Retrieve()).SingleEx();
                        email.SendMailAsync();
                        return email.ToLite();
                    }
                    else
                    {
                        var qr = er.TargetsFromUserQuery.Retrieve().ToQueryRequest();
                        qr.Columns.Clear();
                        var result = DynamicQueryManager.Current.ExecuteQuery(qr);

                        var entities = result.Rows.Select(a => a.Entity).ToList();
                        if (entities.IsEmpty())
                            return null;

                        return EmailPackageLogic.SendMultipleEmailsAsync(er.EmailTemplate, entities).Execute(ProcessOperation.Execute).ToLite();
                    }
                });
            }
        }
예제 #48
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include<EmailPackageEntity>();

                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.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();

                dqm.RegisterQuery(typeof(EmailPackageEntity), () =>
                    from e in Database.Query<EmailPackageEntity>()
                    select new
                    {
                        Entity = e,
                        e.Id,
                        e.Name,
                    });
            }
        }