Beispiel #1
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <AlbumEntity>()
                .WithExpressionFrom((IAuthorEntity au) => au.Albums())
                .WithQuery(() => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.Author,
                    a.Label,
                    a.Year
                });
                AlbumGraph.Register();


                sb.Include <NoteWithDateEntity>()
                .WithSave(NoteWithDateOperation.Save)
                .WithQuery(() => 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)
                .WithVirtualMList(a => a.Nominations, n => (Lite <ArtistEntity>)n.Author)
                .WithQuery(() => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.IsMale,
                    a.Sex,
                    a.Dead,
                    a.LastAward,
                });

                new Graph <ArtistEntity> .Execute(ArtistOperation.AssignPersonalAward)
                {
                    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(() => a => new
                {
                    Entity = a,
                    a.Id,
                    a.Name,
                    a.LastAward,
                });

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

                .Register();

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


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

                RegisterAwards(sb);

                QueryLogic.Queries.Register(typeof(IAuthorEntity), () => DynamicQueryCore.Manual(async(request, description, cancellationToken) =>
                {
                    var one = await(from a in Database.Query <ArtistEntity>()
                                    select new
                    {
                        Entity = (IAuthorEntity)a,
                        a.Id,
                        Type = "Artist",
                        a.Name,
                        Lonely    = a.Lonely(),
                        LastAward = a.LastAward
                    })
                              .ToDQueryable(description)
                              .AllQueryOperationsAsync(request, cancellationToken);

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

                    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 <NotNullValidatorAttribute>(n => Corruption.Strict);
            }
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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);
            }
        }
Beispiel #4
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();
            }
        }