static ResultTable ExecuteChart <T>(ChartRequest request, DynamicQueryCore <T> dq) { List <Column> columns = request.Columns.Where(c => c.Token != null).Select(t => t.CreateColumn()).ToList(); var multiplications = request.Multiplications;; using (ExecutionMode.UserInterface()) { if (!request.GroupResults) { return(dq.ExecuteQuery(new QueryRequest { QueryName = request.QueryName, Columns = columns, Filters = request.Filters, Orders = request.Orders, Pagination = new Pagination.All(), })); } else { return(dq.ExecuteQueryGroup(new QueryGroupRequest { QueryName = request.QueryName, Columns = columns, Filters = request.Filters, Orders = request.Orders })); } } }
public void MetaAnonymousType() { var dic = DynamicQueryCore.QueryMetadata(Database.Query <NoteWithDateEntity>().Select(a => new { a.Target, a.Text, a.ToString().Length, Sum = a.ToString() + a.ToString() })); Assert.IsType <CleanMeta>(dic["Target"]); Assert.IsType <CleanMeta>(dic["Text"]); Assert.IsType <DirtyMeta>(dic["Length"]); Assert.IsType <DirtyMeta>(dic["Sum"]); }
public void MetaNamedType() { var dic = DynamicQueryCore.QueryMetadata(Database.Query <NoteWithDateEntity>().Select(a => new Bla { ToStr = a.ToString(), Length = a.ToString().Length })); Assert.IsType <CleanMeta>(dic["ToStr"]); Assert.IsType <DirtyMeta>(dic["Length"]); }
public AutoDynamicQueryCore(IQueryable <T> query) { this.Query = query; metas = DynamicQueryCore.QueryMetadata(Query).ThrowIfNull("Query should be an anoynmous type"); StaticColumns = MemberEntryFactory.GenerateList <T>(MemberOptions.Properties | MemberOptions.Fields) .Select((e, i) => new ColumnDescriptionFactory(i, e.MemberInfo, metas[e.MemberInfo.Name])).ToArray(); }
public void MetaCoalesce() { var dic = DynamicQueryCore.QueryMetadata( from a in Database.Query <AlbumEntity>() select new { Author = (ArtistEntity?)a.Author ?? (IAuthorEntity?)(BandEntity?)a.Author } ) !; DirtyMeta meta = (DirtyMeta)dic["Author"] !; Assert.Equal(meta.Implementations, Implementations.By(typeof(ArtistEntity), typeof(BandEntity))); }
public void MetaConditional() { var dic = DynamicQueryCore.QueryMetadata( from a in Database.Query <AlbumEntity>() select new { Author = a.Id > 1 ? (ArtistEntity)a.Author : (IAuthorEntity)(BandEntity)a.Author } ); DirtyMeta meta = (DirtyMeta)dic["Author"]; Assert.Equal(meta.Implementations, Implementations.By(typeof(ArtistEntity), typeof(BandEntity))); }
public void MetaComplexJoinGroup() { var dic = DynamicQueryCore.QueryMetadata( from l in Database.Query <LabelEntity>() join a in Database.Query <AlbumEntity>() on l equals a.Label into g select new { l.Name, Num = g.Count() }); Assert.IsType <CleanMeta>(dic["Name"]); Assert.IsType <DirtyMeta>(dic["Num"]); Assert.True(((DirtyMeta)dic["Num"]).CleanMetas.Count == 0); }
public void MetaComplexGroup() { var dic = DynamicQueryCore.QueryMetadata( from a in Database.Query <AlbumEntity>() group a by a.Label into g select new { g.Key, Num = g.Count() }); Assert.IsType <CleanMeta>(dic["Key"]); Assert.IsType <DirtyMeta>(dic["Num"]); Assert.True(((DirtyMeta)dic["Num"]).CleanMetas.Count == 0); }
public void MetaSelectMany() { var dic = DynamicQueryCore.QueryMetadata( from a in Database.Query <AlbumEntity>() from s in a.Songs select new { a.Name, Song = s.Name } ); Assert.IsInstanceOfType(dic["Name"], typeof(CleanMeta)); Assert.IsInstanceOfType(dic["Song"], typeof(CleanMeta)); Assert.IsNotNull(((CleanMeta)dic["Song"]).PropertyRoutes[0].ToString(), "(AlbumEntity).Songs/Name"); }
public void MetaComplexJoin() { var dic = DynamicQueryCore.QueryMetadata( from l in Database.Query <LabelEntity>() join a in Database.Query <AlbumEntity>() on l equals a.Label select new { Label = l.Name, Name = a.Name, Sum = l.Name.Length + a.Name }); Assert.IsInstanceOfType(dic["Label"], typeof(CleanMeta)); Assert.IsInstanceOfType(dic["Name"], typeof(CleanMeta)); Assert.IsInstanceOfType(dic["Sum"], typeof(DirtyMeta)); Assert.AreEqual(((DirtyMeta)dic["Sum"]).CleanMetas.Select(cm => cm.PropertyRoutes[0].ToString()).OrderBy().ToString(","), "(Album).Name,(Label).Name"); }
public void MetaSelectMany() { var dic = DynamicQueryCore.QueryMetadata( from a in Database.Query <AlbumEntity>() from s in a.Songs select new { a.Name, Song = s.Name } ); Assert.IsType <CleanMeta>(dic["Name"]); Assert.IsType <CleanMeta>(dic["Song"]); Assert.Equal(((CleanMeta)dic["Song"]).PropertyRoutes[0].ToString(), "(Album).Songs/Name"); }
public void MetaComplexJoin() { var dic = DynamicQueryCore.QueryMetadata( from l in Database.Query <LabelEntity>() join a in Database.Query <AlbumEntity>() on l equals a.Label select new { Label = l.Name, Name = a.Name, Sum = l.Name.Length + a.Name }); Assert.IsType <CleanMeta>(dic["Label"]); Assert.IsType <CleanMeta>(dic["Name"]); Assert.IsType <DirtyMeta>(dic["Sum"]); var metas = ((DirtyMeta)dic["Sum"]).CleanMetas; Assert.Equal(metas.SelectMany(cm => cm.PropertyRoutes).Distinct().ToString(","), "(Album).Name,(Label).Name"); }
static ResultTable ExecuteChart <T>(ChartRequestModel request, DynamicQueryCore <T> dq) { using (ExecutionMode.UserInterface()) { return(dq.ExecuteQuery(new QueryRequest { GroupResults = request.HasAggregates(), QueryName = request.QueryName, Columns = request.GetQueryColumns(), Filters = request.Filters, Orders = request.GetQueryOrders(), Pagination = new Pagination.All(), })); } }
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); } }
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); } }
static async Task <ResultTable> ExecuteChartAsync <T>(ChartRequestModel request, DynamicQueryCore <T> dq, CancellationToken token) { using (ExecutionMode.UserInterface()) { var result = await dq.ExecuteQueryAsync(new QueryRequest { GroupResults = request.HasAggregates(), QueryName = request.QueryName, Columns = request.GetQueryColumns(), Filters = request.Filters, Orders = request.GetQueryOrders(), Pagination = request.MaxRows.HasValue ? new Pagination.Firsts(request.MaxRows.Value + 1) : new Pagination.All(), }, token); if (request.MaxRows.HasValue && result.Rows.Length == request.MaxRows.Value) { throw new InvalidOperationException($"The chart request for ${request.QueryName} exceeded the max rows ({request.MaxRows})"); } return(result); } }
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(); } }
//public static FluentInclude<T> WithQuery<T, A>(this FluentInclude<T> fi, Func<Expression<Func<T, A>>> lazyQuerySelector) <-- C# Generic argument inference not so smart as to do this public static FluentInclude <T> WithQuery <T>(this FluentInclude <T> fi, Func <Expression <Func <T, object?> > > lazyQuerySelector) where T : Entity { QueryLogic.Queries.Register(typeof(T), new DynamicQueryBucket(typeof(T), () => DynamicQueryCore.FromSelectorUntyped(lazyQuerySelector()), Implementations.By(typeof(T)))); return(fi); }
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 void MetaRawEntity() { var dic = DynamicQueryCore.QueryMetadata(Database.Query <NoteWithDateEntity>()); Assert.NotNull(dic); }
public void Register <T>(object queryName, Func <IQueryable <T> > lazyQuery, Implementations?entityImplementations = null) { Register(queryName, new DynamicQueryBucket(queryName, () => DynamicQueryCore.Auto(lazyQuery()), entityImplementations ?? DefaultImplementations(typeof(T), queryName))); }
static async Task <ResultTable> ExecuteChartAsync <T>(ChartRequestModel request, DynamicQueryCore <T> dq, CancellationToken token) { using (ExecutionMode.UserInterface()) { return(await dq.ExecuteQueryAsync(new QueryRequest { GroupResults = request.HasAggregates(), QueryName = request.QueryName, Columns = request.GetQueryColumns(), Filters = request.Filters, Orders = request.GetQueryOrders(), Pagination = new Pagination.All(), }, token)); } }
public void MetaNoMetadata() { Assert.Null(DynamicQueryCore.QueryMetadata(Database.Query <NoteWithDateEntity>().Select(a => a.Target))); }
public static void Start(SchemaBuilder sb, Func <WorkflowConfigurationEmbedded> getConfiguration) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { PermissionAuthLogic.RegisterPermissions(WorkflowPermission.ViewWorkflowPanel); PermissionAuthLogic.RegisterPermissions(WorkflowPermission.ViewCaseFlow); WorkflowLogic.getConfiguration = getConfiguration; sb.Include <WorkflowEntity>() .WithQuery(() => DynamicQueryCore.Auto( from e in Database.Query <WorkflowEntity>() select new { Entity = e, e.Id, e.Name, e.MainEntityType, HasExpired = e.HasExpired(), e.ExpirationDate, }) .ColumnDisplayName(a => a.HasExpired, () => WorkflowMessage.HasExpired.NiceToString())) .WithExpressionFrom((CaseActivityEntity ca) => ca.Workflow()); WorkflowGraph.Register(); QueryLogic.Expressions.Register((WorkflowEntity wf) => wf.WorkflowStartEvent()); QueryLogic.Expressions.Register((WorkflowEntity wf) => wf.HasExpired(), () => WorkflowMessage.HasExpired.NiceToString()); sb.AddIndex((WorkflowEntity wf) => wf.ExpirationDate); DynamicCode.GetCustomErrors += GetCustomErrors; sb.Include <WorkflowPoolEntity>() .WithUniqueIndex(wp => new { wp.Workflow, wp.Name }) .WithSave(WorkflowPoolOperation.Save) .WithDelete(WorkflowPoolOperation.Delete) .WithExpressionFrom((WorkflowEntity p) => p.WorkflowPools()) .WithQuery(() => e => new { Entity = e, e.Id, e.Name, e.BpmnElementId, e.Workflow, }); sb.Include <WorkflowLaneEntity>() .WithUniqueIndex(wp => new { wp.Pool, wp.Name }) .WithSave(WorkflowLaneOperation.Save) .WithDelete(WorkflowLaneOperation.Delete) .WithExpressionFrom((WorkflowPoolEntity p) => p.WorkflowLanes()) .WithQuery(() => e => new { Entity = e, e.Id, e.Name, e.BpmnElementId, e.Pool, e.Pool.Workflow, }); sb.Include <WorkflowActivityEntity>() .WithUniqueIndex(w => new { w.Lane, w.Name }) .WithSave(WorkflowActivityOperation.Save) .WithDelete(WorkflowActivityOperation.Delete) .WithExpressionFrom((WorkflowEntity p) => p.WorkflowActivities()) .WithExpressionFrom((WorkflowLaneEntity p) => p.WorkflowActivities()) .WithVirtualMList(wa => wa.BoundaryTimers, e => e.BoundaryOf, WorkflowEventOperation.Save, WorkflowEventOperation.Delete) .WithQuery(() => e => new { Entity = e, e.Id, e.Name, e.BpmnElementId, e.Comments, e.Lane, e.Lane.Pool.Workflow, }); sb.Include <WorkflowEventEntity>() .WithExpressionFrom((WorkflowEntity p) => p.WorkflowEvents()) .WithExpressionFrom((WorkflowLaneEntity p) => p.WorkflowEvents()) .WithQuery(() => e => new { Entity = e, e.Id, e.Type, e.Name, e.BpmnElementId, e.Lane, e.Lane.Pool.Workflow, }); new Graph <WorkflowEventEntity> .Execute(WorkflowEventOperation.Save) { CanBeNew = true, CanBeModified = true, Execute = (e, _) => { if (e.Timer == null && e.Type.IsTimer()) { throw new InvalidOperationException(ValidationMessage._0IsMandatoryWhen1IsSetTo2.NiceToString(e.NicePropertyName(a => a.Timer), e.NicePropertyName(a => a.Type), e.Type.NiceToString())); } if (e.Timer != null && !e.Type.IsTimer()) { throw new InvalidOperationException(ValidationMessage._0ShouldBeNullWhen1IsSetTo2.NiceToString(e.NicePropertyName(a => a.Timer), e.NicePropertyName(a => a.Type), e.Type.NiceToString())); } if (e.BoundaryOf == null && e.Type.IsBoundaryTimer()) { throw new InvalidOperationException(ValidationMessage._0IsMandatoryWhen1IsSetTo2.NiceToString(e.NicePropertyName(a => a.BoundaryOf), e.NicePropertyName(a => a.Type), e.Type.NiceToString())); } if (e.BoundaryOf != null && !e.Type.IsBoundaryTimer()) { throw new InvalidOperationException(ValidationMessage._0ShouldBeNullWhen1IsSetTo2.NiceToString(e.NicePropertyName(a => a.BoundaryOf), e.NicePropertyName(a => a.Type), e.Type.NiceToString())); } e.Save(); }, } .Register(); new Graph <WorkflowEventEntity> .Delete(WorkflowEventOperation.Delete) { Delete = (e, _) => { if (e.Type.IsScheduledStart()) { var scheduled = e.ScheduledTask(); if (scheduled != null) { WorkflowEventTaskLogic.DeleteWorkflowEventScheduledTask(scheduled); } } e.Delete(); }, } .Register(); sb.Include <WorkflowGatewayEntity>() .WithSave(WorkflowGatewayOperation.Save) .WithDelete(WorkflowGatewayOperation.Delete) .WithExpressionFrom((WorkflowEntity p) => p.WorkflowGateways()) .WithExpressionFrom((WorkflowLaneEntity p) => p.WorkflowGateways()) .WithQuery(() => e => new { Entity = e, e.Id, e.Type, e.Name, e.BpmnElementId, e.Lane, e.Lane.Pool.Workflow, }); sb.Include <WorkflowConnectionEntity>() .WithSave(WorkflowConnectionOperation.Save) .WithDelete(WorkflowConnectionOperation.Delete) .WithExpressionFrom((WorkflowEntity p) => p.WorkflowConnections()) .WithExpressionFrom((WorkflowEntity p) => p.WorkflowMessageConnections(), null !) .WithExpressionFrom((WorkflowPoolEntity p) => p.WorkflowConnections()) .WithExpressionFrom((IWorkflowNodeEntity p) => p.NextConnections(), null !) .WithExpressionFrom((IWorkflowNodeEntity p) => p.PreviousConnections(), null !) .WithQuery(() => e => new { Entity = e, e.Id, e.Name, e.BpmnElementId, e.From, e.To, }); WorkflowEventTaskEntity.GetWorkflowEntity = lite => WorkflowGraphLazy.Value.GetOrThrow(lite).Workflow; WorkflowGraphLazy = sb.GlobalLazy(() => { using (new EntityCache()) { var events = Database.RetrieveAll <WorkflowEventEntity>().GroupToDictionary(a => a.Lane.Pool.Workflow.ToLite()); var gateways = Database.RetrieveAll <WorkflowGatewayEntity>().GroupToDictionary(a => a.Lane.Pool.Workflow.ToLite()); var activities = Database.RetrieveAll <WorkflowActivityEntity>().GroupToDictionary(a => a.Lane.Pool.Workflow.ToLite()); var connections = Database.RetrieveAll <WorkflowConnectionEntity>().GroupToDictionary(a => a.From.Lane.Pool.Workflow.ToLite()); var result = Database.RetrieveAll <WorkflowEntity>().ToDictionary(workflow => workflow.ToLite(), workflow => { var w = workflow.ToLite(); var nodeGraph = new WorkflowNodeGraph { Workflow = workflow, Events = events.TryGetC(w).EmptyIfNull().ToDictionary(e => e.ToLite()), Gateways = gateways.TryGetC(w).EmptyIfNull().ToDictionary(g => g.ToLite()), Activities = activities.TryGetC(w).EmptyIfNull().ToDictionary(a => a.ToLite()), Connections = connections.TryGetC(w).EmptyIfNull().ToDictionary(c => c.ToLite()), }; nodeGraph.FillGraphs(); return(nodeGraph); }); return(result); } }, new InvalidateWith(typeof(WorkflowConnectionEntity))); WorkflowGraphLazy.OnReset += (e, args) => DynamicCode.OnInvalidated?.Invoke(); Validator.PropertyValidator((WorkflowConnectionEntity c) => c.Condition).StaticPropertyValidation = (e, pi) => { if (e.Condition != null && e.From != null) { var conditionType = Conditions.Value.GetOrThrow(e.Condition).MainEntityType; var workflowType = e.From.Lane.Pool.Workflow.MainEntityType; if (!conditionType.Is(workflowType)) { return(WorkflowMessage.Condition0IsDefinedFor1Not2.NiceToString(conditionType, workflowType)); } } return(null); }; StartWorkflowConditions(sb); StartWorkflowTimerConditions(sb); StartWorkflowActions(sb); StartWorkflowScript(sb); } }
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); }); } }