Ejemplo n.º 1
0
        public ExtensionDictionaryInfo <T, KVP, K, V> RegisterDictionary <T, KVP, K, V>(
            Expression <Func <T, IEnumerable <KVP> > > collectionSelector,
            Expression <Func <KVP, K> > keySelector,
            Expression <Func <KVP, V> > valueSelector,
            Expression <Func <T, EmbeddedEntity> > forEmbedded = null,
            ResetLazy <HashSet <K> > allKeys = null)
            where T : Entity
        {
            var mei = new ExtensionDictionaryInfo <T, KVP, K, V>
            {
                CollectionSelector = collectionSelector,
                KeySelector        = keySelector,
                ValueSelector      = valueSelector,

                AllKeys = allKeys ?? GetAllKeysLazy <T, KVP, K>(collectionSelector, keySelector)
            };

            var route = forEmbedded == null?
                        PropertyRoute.Root(typeof(T)) :
                            PropertyRoute.Construct(forEmbedded);

            RegisteredExtensionsDictionaries.Add(route, mei);

            return(mei);
        }
Ejemplo n.º 2
0
        public static int BulkInsertMListTable <E, V>(
            List <E> entities,
            Expression <Func <E, MList <V> > > mListProperty,
            SqlBulkCopyOptions copyOptions = SqlBulkCopyOptions.Default,
            int?timeout    = null,
            string?message = null)
            where E : Entity
        {
            using (HeavyProfiler.Log(nameof(BulkInsertMListTable), () => $"{mListProperty} ({typeof(E).TypeName()})"))
            {
                try
                {
                    var func = PropertyRoute.Construct(mListProperty).GetLambdaExpression <E, MList <V> >(safeNullAccess: true).Compile();

                    var mlistElements = (from e in entities
                                         from mle in func(e).EmptyIfNull().Select((iw, i) => new MListElement <E, V>
                    {
                        Order = i,
                        Element = iw,
                        Parent = e,
                    })
                                         select mle).ToList();

                    return(BulkInsertMListTable(mlistElements, mListProperty, copyOptions, timeout, updateParentTicks: false, message: message));
                }
                catch (InvalidOperationException e) when(e.Message.Contains("has no Id"))
                {
                    throw new InvalidOperationException($"{nameof(BulkInsertMListTable)} requires that you set the Id of the entities manually using {nameof(UnsafeEntityExtensions.SetId)}");
                }
            }
        }
Ejemplo n.º 3
0
        /// <param name="valueFunction">For Caching scenarios</param>
        public void RegisterBinding <M>(Expression <Func <T, M> > field, Func <bool> shouldSet, Expression <Func <T, PrimaryKey? /*rowId*/, M> > valueExpression, Func <T, PrimaryKey? /*rowId*/, IRetriever, M>?valueFunction = null)
        {
            var ma = (MemberExpression)field.Body;

            var pr = PropertyRoute.Construct(field);

            RegisterBinding(pr, shouldSet, valueExpression, valueFunction);
        }
Ejemplo n.º 4
0
        public void AssertNotIgnored <T, S>(Expression <Func <T, S> > propertyRoute, string errorContext) where T : Entity
        {
            var pr = PropertyRoute.Construct <T, S>(propertyRoute);

            if (FieldAttribute <IgnoreAttribute>(pr) != null)
            {
                throw new InvalidOperationException("In order to {0} you need to override the attributes for {1} by using SchemaBuilderSettings.FieldAttributes to remove IgnoreAttribute".FormatWith(errorContext, pr));
            }
        }
Ejemplo n.º 5
0
        public void AssertIgnored <T, S>(Expression <Func <T, S> > propertyRoute, string errorContext, string solution = "by using SchemaBuilderSettings.FieldAttributes to add IgnoreAttribute") where T : Entity
        {
            var pr = PropertyRoute.Construct <T, S>(propertyRoute);

            if (FieldAttribute <IgnoreAttribute>(pr) == null)
            {
                throw new InvalidOperationException($"In order to {errorContext} you need to override the attributes for {pr} {solution}");
            }
        }
Ejemplo n.º 6
0
        public void AssertImplementedBy <T>(Expression <Func <T, object> > propertyRoute, Type typeToImplement) where T : Entity
        {
            var propRoute = PropertyRoute.Construct(propertyRoute);

            Implementations imp = GetImplementations(propRoute);

            if (imp.IsByAll || !imp.Types.Contains(typeToImplement))
            {
                throw new InvalidOperationException("Route {0} is not ImplementedBy {1}".FormatWith(propRoute, typeToImplement.Name));
            }
        }
Ejemplo n.º 7
0
        public void AssertImplementedBy <T>(Expression <Func <T, object> > propertyRoute, Type typeToImplement) where T : Entity
        {
            var route = PropertyRoute.Construct(propertyRoute);

            Implementations imp = GetImplementations(route);

            if (imp.IsByAll || !imp.Types.Contains(typeToImplement))
            {
                throw new InvalidOperationException("Route {0} is not ImplementedBy {1}".FormatWith(route, typeToImplement.Name) +
                                                    "\r\n" +
                                                    Implementations.ConsiderMessage(route, imp.Types.And(typeToImplement).ToString(t => $"typeof({t.TypeName()})", ", ")));
            }
        }
Ejemplo n.º 8
0
        public static IEnumerable <TranslatableElement <T> > TranslatedMList <E, T>(this E entity, Expression <Func <E, MList <T> > > mlistProperty) where E : Entity
        {
            var mlist = GetPropertyRouteAccesor(mlistProperty);

            PropertyRoute route = PropertyRoute.Construct(mlistProperty).Add("Item");

            var lite = entity.ToLite();

            foreach (var item in ((IMListPrivate <T>)mlist(entity)).InnerList)
            {
                yield return(new TranslatableElement <T>(lite, route, item));
            }
        }
Ejemplo n.º 9
0
        /// <param name="valueFunction">For Caching scenarios</param>
        public void RegisterBinding <M>(Expression <Func <T, M> > field, Func <bool> shouldSet, Expression <Func <T, M> > valueExpression, Func <T, IRetriever, M>?valueFunction = null)
        {
            if (AdditionalBindings == null)
            {
                AdditionalBindings = new Dictionary <PropertyRoute, IAdditionalBinding>();
            }

            var ma = (MemberExpression)field.Body;

            var pr = PropertyRoute.Construct(field);

            AdditionalBindings.Add(pr, new AdditionalBinding <T, M>(pr, shouldSet, valueExpression, valueFunction));
        }
Ejemplo n.º 10
0
        public static T SaveTranslation <T>(this T entity, CultureInfoEntity ci, Expression <Func <T, string> > propertyRoute, string translatedText)
            where T : Entity
        {
            entity.Save();

            if (translatedText.HasText())
            {
                new TranslatedInstanceEntity
                {
                    PropertyRoute  = PropertyRoute.Construct(propertyRoute).ToPropertyRouteEntity(),
                    Culture        = ci,
                    TranslatedText = translatedText,
                    OriginalText   = GetPropertyRouteAccesor(propertyRoute)(entity),
                    Instance       = entity.ToLite(),
                }
            }
Ejemplo n.º 11
0
        public ExtensionDictionaryInfo <M, KVP, K, V> RegisterDictionaryInEmbedded <T, M, KVP, K, V>(
            Expression <Func <T, M> > embeddedSelector,
            Expression <Func <M, IEnumerable <KVP> > > collectionSelector,
            Expression <Func <KVP, K> > keySelector,
            Expression <Func <KVP, V> > valueSelector,
            ResetLazy <HashSet <K> >?allKeys = null)
            where T : Entity
            where M : ModifiableEntity
            where K : notnull
        {
            var mei = new ExtensionDictionaryInfo <M, KVP, K, V>(collectionSelector, keySelector, valueSelector,
                                                                 allKeys ?? GetAllKeysLazy <T, KVP, K>(CombineSelectors(embeddedSelector, collectionSelector), keySelector));

            RegisteredExtensionsDictionaries.Add(PropertyRoute.Construct(embeddedSelector), mei);

            return(mei);
        }
Ejemplo n.º 12
0
        private object EntityRepeater_Creating()
        {
            var imp = (Implementations)PropertyRoute.Construct((DashboardEntity cp) => cp.Parts.First().Content).GetImplementations();

            var type = Navigator.SelectType(Window.GetWindow(this), imp.Types, t => Navigator.IsCreable(t, isSearch: false));

            if (type == null)
            {
                return(null);
            }

            return(new PanelPartEmbedded
            {
                Row = Panel.Parts.IsEmpty() ? 0 : Panel.Parts.Max(a => Math.Max(a.Row, 0)) + 1,
                Columns = 12,
                StartColumn = 0,
                Content = (IPartEntity) new ConstructorContext(this).ConstructUntyped(type),
                Title = null,
            });
        }
Ejemplo n.º 13
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                var ib = sb.Schema.Settings.FieldAttribute <ImplementedByAttribute>(PropertyRoute.Construct((ScheduledTaskEntity e) => e.Rule));
                sb.Schema.Settings.FieldAttributes((WorkflowEventTaskModel a) => a.Rule).Replace(new ImplementedByAttribute(ib.ImplementedTypes));

                sb.Include <WorkflowEventTaskEntity>()
                .WithDelete(WorkflowEventTaskOperation.Delete)
                .WithQuery(dqm, () => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Workflow,
                    e.TriggeredOn,
                    e.Event,
                });

                new Graph <WorkflowEventTaskEntity> .Execute(WorkflowEventTaskOperation.Save)
                {
                    AllowsNew = true,
                    Lite      = false,
                    Execute   = (e, _) => {
                        if (e.TriggeredOn == TriggeredOn.Always)
                        {
                            e.Condition = null;
                        }

                        e.Save();
                    },
                }

                .Register();

                sb.Schema.EntityEvents <WorkflowEventTaskEntity>().PreUnsafeDelete += tasks => tasks.SelectMany(a => a.ConditionResults()).UnsafeDelete();

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;

                sb.Include <WorkflowEventTaskConditionResultEntity>()
                .WithQuery(dqm, () => e => new
                {
                    Entity = e,
                    e.Id,
                    e.CreationDate,
                    e.WorkflowEventTask,
                    e.Result,
                });

                SchedulerLogic.ExecuteTask.Register((WorkflowEventTaskEntity wet, ScheduledTaskContext ctx) => ExecuteTask(wet));
                sb.AddIndex((WorkflowEventTaskConditionResultEntity e) => e.CreationDate);

                WorkflowEventTaskModel.GetModel = (@event) =>
                {
                    if ([email protected]())
                    {
                        return(null);
                    }

                    var schedule    = @event.ScheduledTask();
                    var task        = (schedule?.Task as WorkflowEventTaskEntity);
                    var triggeredOn = task?.TriggeredOn ?? TriggeredOn.Always;

                    return(new WorkflowEventTaskModel
                    {
                        Suspended = schedule?.Suspended ?? true,
                        Rule = schedule?.Rule,
                        TriggeredOn = triggeredOn,
                        Condition = triggeredOn == TriggeredOn.Always ? null : new WorkflowEventTaskConditionEval()
                        {
                            Script = task.Condition.Script
                        },
                        Action = new WorkflowEventTaskActionEval()
                        {
                            Script = task?.Action.Script ?? ""
                        }
                    });
                };

                WorkflowEventTaskModel.ApplyModel = (@event, model) =>
                {
                    var schedule = @event.IsNew ? null : @event.ScheduledTask();

                    if ([email protected]())
                    {
                        if (schedule != null)
                        {
                            DeleteWorkflowEventScheduledTask(schedule);
                        }
                        return;
                    }

                    if (schedule != null)
                    {
                        var task = (schedule.Task as WorkflowEventTaskEntity);
                        schedule.Suspended = model.Suspended;
                        if (!object.ReferenceEquals(schedule.Rule, model.Rule))
                        {
                            schedule.Rule = null;
                            schedule.Rule = model.Rule;
                        }
                        task.TriggeredOn = model.TriggeredOn;


                        if (model.TriggeredOn == TriggeredOn.Always)
                        {
                            task.Condition = null;
                        }
                        else
                        {
                            if (task.Condition == null)
                            {
                                task.Condition = new WorkflowEventTaskConditionEval();
                            }
                            task.Condition.Script = model.Condition.Script;
                        };

                        task.Action.Script = model.Action.Script;
                        if (GraphExplorer.IsGraphModified(schedule))
                        {
                            task.Execute(WorkflowEventTaskOperation.Save);
                            schedule.Execute(ScheduledTaskOperation.Save);
                        }
                    }
                    else
                    {
                        var newTask = new WorkflowEventTaskEntity()
                        {
                            Workflow    = @event.Lane.Pool.Workflow.ToLite(),
                            Event       = @event.ToLite(),
                            TriggeredOn = model.TriggeredOn,
                            Condition   = model.TriggeredOn == TriggeredOn.Always ? null : new WorkflowEventTaskConditionEval()
                            {
                                Script = model.Condition.Script
                            },
                            Action = new WorkflowEventTaskActionEval()
                            {
                                Script = model.Action.Script
                            },
                        }.Execute(WorkflowEventTaskOperation.Save);

                        schedule = new ScheduledTaskEntity()
                        {
                            Suspended = model.Suspended,
                            Rule      = model.Rule,
                            Task      = newTask,
                            User      = AuthLogic.SystemUser.ToLite(),
                        }.Execute(ScheduledTaskOperation.Save);
                    }
                };
            }
        }
Ejemplo n.º 14
0
 public AttributeCollection FieldAttributes <T, S>(Expression <Func <T, S> > propertyRoute)
     where T : IRootEntity
 {
     return(FieldAttributes(PropertyRoute.Construct(propertyRoute)) !);
 }
Ejemplo n.º 15
0
        public static void Start(IApplicationBuilder app)
        {
            if (started)
            {
                return;
            }

            started = true;

            SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod());
            ReflectionServer.RegisterLike(typeof(QueryTokenEmbedded));
            EntityJsonConverter.DefaultPropertyRoutes.Add(typeof(QueryFilterEmbedded), PropertyRoute.Construct((UserQueryEntity e) => e.Filters.FirstEx()));
            EntityJsonConverter.DefaultPropertyRoutes.Add(typeof(PinnedQueryFilterEmbedded), PropertyRoute.Construct((UserQueryEntity e) => e.Filters.FirstEx().Pinned));

            var pcs = PropertyConverter.GetPropertyConverters(typeof(QueryTokenEmbedded));

            pcs.Add("token", new PropertyConverter()
            {
                CustomWriteJsonProperty = ctx =>
                {
                    var qte = (QueryTokenEmbedded)ctx.Entity;

                    ctx.JsonWriter.WritePropertyName(ctx.LowerCaseName);
                    ctx.JsonSerializer.Serialize(ctx.JsonWriter, qte.TryToken == null ? null : new QueryTokenTS(qte.TryToken, true));
                },
                AvoidValidate          = true,
                CustomReadJsonProperty = ctx =>
                {
                    var result = ctx.JsonSerializer.Deserialize(ctx.JsonReader);
                    //Discard
                }
            });
            pcs.Add("parseException", new PropertyConverter()
            {
                CustomWriteJsonProperty = ctx =>
                {
                    var qte = (QueryTokenEmbedded)ctx.Entity;

                    ctx.JsonWriter.WritePropertyName(ctx.LowerCaseName);
                    ctx.JsonSerializer.Serialize(ctx.JsonWriter, qte.ParseException?.Message);
                },
                AvoidValidate          = true,
                CustomReadJsonProperty = ctx =>
                {
                    var result = ctx.JsonSerializer.Deserialize(ctx.JsonReader);
                    //Discard
                }
            });
            pcs.GetOrThrow("tokenString").CustomWriteJsonProperty = ctx =>
            {
                var qte = (QueryTokenEmbedded)ctx.Entity;

                ctx.JsonWriter.WritePropertyName(ctx.LowerCaseName);
                ctx.JsonWriter.WriteValue(qte.TryToken?.FullKey() ?? qte.TokenString);
            };
        }
Ejemplo n.º 16
0
        public static string TranslatedField <T>(this Lite <T> lite, Expression <Func <T, string> > property, string fallbackString) where T : Entity
        {
            PropertyRoute route = PropertyRoute.Construct(property);

            return(TranslatedField(lite, route, fallbackString));
        }
Ejemplo n.º 17
0
 public static ValueLineModalProxy AsValueLineModal <T, V>(this IWebElement element, Expression <Func <T, V> > propertyRoute)
     where T : IRootEntity
 {
     return(new ValueLineModalProxy(element, PropertyRoute.Construct(propertyRoute)));
 }
Ejemplo n.º 18
0
 public Implementations GetImplementations <T>(Expression <Func <T, object> > propertyRoute) where T : Entity
 {
     return(GetImplementations(PropertyRoute.Construct(propertyRoute)));
 }
Ejemplo n.º 19
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);
            }
        }
Ejemplo n.º 20
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();
            }
        }
Ejemplo n.º 21
0
 public static void AddRoute <T, S>(Expression <Func <T, S> > propertyRoute) where T : Entity
 {
     AddRoute(PropertyRoute.Construct <T, S>(propertyRoute));
 }
Ejemplo n.º 22
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);
            }
        }
Ejemplo n.º 23
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);
            }
        }
Ejemplo n.º 24
0
 public void SetPropertyRoutes <T>(params Expression <Func <T, object> >[] propertyRoutes)
     where T : Entity
 {
     PropertyRoutes = propertyRoutes.Select(exp => PropertyRoute.Construct(exp)).ToArray();
 }
Ejemplo n.º 25
0
 public static void Register <T>(SchemaBuilder sb, Expression <Func <T, BigStringEmbedded> > expression, BigStringConfiguration config)
     where T : Entity
 {
     Register(sb, PropertyRoute.Construct(expression), config);
 }
Ejemplo n.º 26
0
        public static FluentInclude <T> WithVirtualMList <T, L>(this FluentInclude <T> fi,
                                                                Expression <Func <T, MList <L> > > mListField,
                                                                Expression <Func <L, Lite <T>?> > backReference,
                                                                Action <L, T>?onSave   = null,
                                                                Action <L, T>?onRemove = null,
                                                                bool?lazyRetrieve      = null,
                                                                bool?lazyDelete        = null) //To avoid StackOverflows
            where T : Entity
            where L : Entity
        {
            fi.SchemaBuilder.Include <L>();

            var mListPropertRoute  = PropertyRoute.Construct(mListField);
            var backReferenceRoute = PropertyRoute.Construct(backReference, avoidLastCasting: true);

            if (fi.SchemaBuilder.Settings.FieldAttribute <IgnoreAttribute>(mListPropertRoute) == null)
            {
                throw new InvalidOperationException($"The property {mListPropertRoute} should have an IgnoreAttribute to be used as Virtual MList");
            }

            RegisteredVirtualMLists.GetOrCreate(typeof(T)).Add(mListPropertRoute, new VirtualMListInfo(mListPropertRoute, backReferenceRoute));

            var defLazyRetrieve = lazyRetrieve ?? (typeof(L) == typeof(T));
            var defLazyDelete   = lazyDelete ?? (typeof(L) == typeof(T));

            Func <T, MList <L> >  getMList = GetAccessor(mListField);
            Action <L, Lite <T> >?setter   = null;
            bool preserveOrder             = fi.SchemaBuilder.Settings.FieldAttributes(mListPropertRoute) !
                                             .OfType <PreserveOrderAttribute>()
                                             .Any();

            if (preserveOrder && !typeof(ICanBeOrdered).IsAssignableFrom(typeof(L)))
            {
                throw new InvalidOperationException($"'{typeof(L).Name}' should implement '{nameof(ICanBeOrdered)}' because '{ReflectionTools.GetPropertyInfo(mListField).Name}' contains '[{nameof(PreserveOrderAttribute)}]'");
            }

            var sb = fi.SchemaBuilder;

            if (defLazyRetrieve)
            {
                sb.Schema.EntityEvents <T>().Retrieved += (T e, PostRetrievingContext ctx) =>
                {
                    if (ShouldAvoidMListType(typeof(L)))
                    {
                        return;
                    }

                    var mlist = getMList(e);

                    if (mlist == null)
                    {
                        return;
                    }

                    var query = Database.Query <L>()
                                .Where(line => backReference.Evaluate(line) == e.ToLite());

                    MList <L> newList = preserveOrder ?
                                        query.ToVirtualMListWithOrder() :
                                        query.ToVirtualMList();

                    mlist.AssignAndPostRetrieving(newList, ctx);
                };
            }

            if (preserveOrder)
            {
                sb.Schema.EntityEvents <T>().RegisterBinding <MList <L> >(mListField,
                                                                          shouldSet: () => !defLazyRetrieve && !VirtualMList.ShouldAvoidMListType(typeof(L)),
                                                                          valueExpression: (e, rowId) => Database.Query <L>().Where(line => backReference.Evaluate(line) == e.ToLite()).ExpandLite(line => backReference.Evaluate(line), ExpandLite.ToStringLazy).ToVirtualMListWithOrder(),
                                                                          valueFunction: (e, rowId, retriever) => Schema.Current.CacheController <L>() !.Enabled ?
                                                                          Schema.Current.CacheController <L>() !.RequestByBackReference <T>(retriever, backReference, e.ToLite()).ToVirtualMListWithOrder():
                                                                          Database.Query <L>().Where(line => backReference.Evaluate(line) == e.ToLite()).ExpandLite(line => backReference.Evaluate(line), ExpandLite.ToStringLazy).ToVirtualMListWithOrder()

                                                                          );
            }
            else
            {
                sb.Schema.EntityEvents <T>().RegisterBinding(mListField,
                                                             shouldSet: () => !defLazyRetrieve && !VirtualMList.ShouldAvoidMListType(typeof(L)),
                                                             valueExpression: (e, rowId) => Database.Query <L>().Where(line => backReference.Evaluate(line) == e.ToLite()).ExpandLite(line => backReference.Evaluate(line), ExpandLite.ToStringLazy).ToVirtualMList(),
                                                             valueFunction: (e, rowId, retriever) => Schema.Current.CacheController <L>() !.Enabled ?
                                                             Schema.Current.CacheController <L>() !.RequestByBackReference <T>(retriever, backReference, e.ToLite()).ToVirtualMList() :
                                                             Database.Query <L>().Where(line => backReference.Evaluate(line) == e.ToLite()).ExpandLite(line => backReference.Evaluate(line), ExpandLite.ToStringLazy).ToVirtualMList()
                                                             );
            }

            sb.Schema.EntityEvents <T>().PreSaving += (T e, PreSavingContext ctx) =>
            {
                if (VirtualMList.ShouldAvoidMListType(typeof(L)))
                {
                    return;
                }

                var mlist = getMList(e);
                if (mlist == null)
                {
                    return;
                }

                if (mlist.Count > 0)
                {
                    var graph = Saver.PreSaving(() => GraphExplorer.FromRoot(mlist).RemoveAllNodes(ctx.Graph));
                    GraphExplorer.PropagateModifications(graph.Inverse());
                    var errors = GraphExplorer.FullIntegrityCheck(graph);
                    if (errors != null)
                    {
#if DEBUG
                        var withEntites = errors.WithEntities(graph);
                        throw new IntegrityCheckException(withEntites);
#else
                        throw new IntegrityCheckException(errors);
#endif
                    }
                }

                if (mlist.IsGraphModified)
                {
                    e.SetSelfModified();
                }
            };

            sb.Schema.EntityEvents <T>().Saving += (T e) =>
            {
                if (VirtualMList.ShouldAvoidMListType(typeof(L)))
                {
                    return;
                }

                var mlist = getMList(e);
                if (mlist == null)
                {
                    return;
                }

                if (preserveOrder)
                {
                    mlist.ForEach((o, i) => ((ICanBeOrdered)o).Order = i);
                }

                if (GraphExplorer.IsGraphModified(mlist))
                {
                    e.SetModified();
                }
            };
            sb.Schema.EntityEvents <T>().Saved += (T e, SavedEventArgs args) =>
            {
                if (VirtualMList.ShouldAvoidMListType(typeof(L)))
                {
                    return;
                }

                var mlist = getMList(e);

                if (mlist != null && !GraphExplorer.IsGraphModified(mlist))
                {
                    return;
                }

                if (!(args.WasNew || ShouldConsiderNew(typeof(T))))
                {
                    var oldElements = mlist.EmptyIfNull().Where(line => !line.IsNew);
                    var query       = Database.Query <L>()
                                      .Where(p => backReference.Evaluate(p) == e.ToLite());

                    if (onRemove == null)
                    {
                        query.Where(p => !oldElements.Contains(p)).UnsafeDelete();
                    }
                    else
                    {
                        query.Where(p => !oldElements.Contains(p)).ToList().ForEach(line => onRemove !(line, e));
                    }
                }

                if (mlist != null)
                {
                    if (mlist.Any())
                    {
                        if (setter == null)
                        {
                            setter = CreateSetter(backReference);
                        }

                        mlist.ForEach(line => setter !(line, e.ToLite()));
                        if (onSave == null)
                        {
                            mlist.SaveList();
                        }
                        else
                        {
                            mlist.ForEach(line => { if (GraphExplorer.IsGraphModified(line))
                                                    {
                                                        onSave !(line, e);
                                                    }
                                          });
                        }

                        var priv = (IMListPrivate)mlist;
                        for (int i = 0; i < mlist.Count; i++)
                        {
                            if (priv.GetRowId(i) == null)
                            {
                                priv.SetRowId(i, mlist[i].Id);
                            }
                        }
                    }
                    mlist.SetCleanModified(false);
                }
            };


            sb.Schema.EntityEvents <T>().PreUnsafeDelete += query =>
            {
                if (VirtualMList.ShouldAvoidMListType(typeof(L)))
                {
                    return(null);
                }

                //You can do a VirtualMList to itself at the table level, but there should not be cycles inside the instances
                var toDelete = Database.Query <L>().Where(se => query.Any(e => backReference.Evaluate(se).Is(e)));
                if (defLazyDelete)
                {
                    if (toDelete.Any())
                    {
                        toDelete.UnsafeDelete();
                    }
                }
                else
                {
                    toDelete.UnsafeDelete();
                }
                return(null);
            };

            return(fi);
        }
Ejemplo n.º 27
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);
            }
        }
Ejemplo n.º 28
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                var ib = sb.Schema.Settings.FieldAttribute <ImplementedByAttribute>(PropertyRoute.Construct((ScheduledTaskEntity e) => e.Rule)) !;
                sb.Schema.Settings.FieldAttributes((WorkflowEventTaskModel a) => a.Rule).Replace(new ImplementedByAttribute(ib.ImplementedTypes));

                sb.Include <WorkflowEventTaskEntity>()
                .WithDelete(WorkflowEventTaskOperation.Delete)
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Workflow,
                    e.TriggeredOn,
                    e.Event,
                });

                new Graph <WorkflowEventTaskEntity> .Execute(WorkflowEventTaskOperation.Save)
                {
                    CanBeNew      = true,
                    CanBeModified = true,
                    Execute       = (e, _) => {
                        if (e.TriggeredOn == TriggeredOn.Always)
                        {
                            e.Condition = null;
                        }

                        e.Save();
                    },
                }

                .Register();

                sb.Schema.EntityEvents <WorkflowEventTaskEntity>().PreUnsafeDelete += tasks =>
                {
                    tasks.SelectMany(a => a.ConditionResults()).UnsafeDelete();
                    return(null);
                };

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;

                sb.Include <WorkflowEventTaskConditionResultEntity>()
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.CreationDate,
                    e.WorkflowEventTask,
                    e.Result,
                });

                SchedulerLogic.ExecuteTask.Register((WorkflowEventTaskEntity wet, ScheduledTaskContext ctx) => ExecuteTask(wet));
                sb.AddIndex((WorkflowEventTaskConditionResultEntity e) => e.CreationDate);

                WorkflowEventTaskModel.GetModel = (@event) =>
                {
                    if ([email protected]())
                    {
                        return(null);
                    }

                    var schedule    = @event.ScheduledTask();
                    var task        = (schedule?.Task as WorkflowEventTaskEntity);
                    var triggeredOn = task?.TriggeredOn ?? TriggeredOn.Always;

                    return(new WorkflowEventTaskModel
                    {
                        Suspended = schedule?.Suspended ?? true,
                        Rule = schedule?.Rule,
                        TriggeredOn = triggeredOn,
                        Condition = triggeredOn == TriggeredOn.Always ? null : new WorkflowEventTaskConditionEval()
                        {
                            Script = task !.Condition !.Script
                        },
                        Action = new WorkflowEventTaskActionEval()
                        {
                            Script = task?.Action !.Script ?? ""
                        }
                    });
Ejemplo n.º 29
0
 public static void RegisterPropertyFormat <T>(Expression <Func <T, object> > property, Func <Binding, DataTemplate> formatter)
     where T : IRootEntity
 {
     PropertyFormatters.Add(PropertyRoute.Construct(property), formatter);
 }
Ejemplo n.º 30
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <ProcessAlgorithmSymbol>()
                .WithQuery(dqm, () => pa => new
                {
                    Entity = pa,
                    pa.Id,
                    pa.Key
                });

                sb.Include <ProcessEntity>()
                .WithQuery(dqm, () => p => new
                {
                    Entity = p,
                    p.Id,
                    p.Algorithm,
                    p.Data,
                    p.State,
                    p.MachineName,
                    p.ApplicationName,
                    p.CreationDate,
                    p.PlannedDate,
                    p.CancelationDate,
                    p.QueuedDate,
                    p.ExecutionStart,
                    p.ExecutionEnd,
                    p.SuspendDate,
                    p.ExceptionDate,
                });

                sb.Include <ProcessExceptionLineEntity>()
                .WithQuery(dqm, () => p => new
                {
                    Entity = p,
                    p.Line,
                    p.Process,
                    p.Exception,
                });

                PermissionAuthLogic.RegisterPermissions(ProcessPermission.ViewProcessPanel);

                SymbolLogic <ProcessAlgorithmSymbol> .Start(sb, dqm, () => registeredProcesses.Keys.ToHashSet());

                OperationLogic.AssertStarted(sb);

                ProcessGraph.Register();

                dqm.RegisterExpression((ProcessAlgorithmSymbol p) => p.Processes(), () => typeof(ProcessEntity).NicePluralName());
                dqm.RegisterExpression((ProcessAlgorithmSymbol p) => p.LastProcess(), () => ProcessMessage.LastProcess.NiceToString());

                dqm.RegisterExpression((IProcessDataEntity p) => p.Processes(), () => typeof(ProcessEntity).NicePluralName());
                dqm.RegisterExpression((IProcessDataEntity p) => p.LastProcess(), () => ProcessMessage.LastProcess.NiceToString());

                dqm.RegisterExpression((IProcessLineDataEntity p) => p.ExceptionLines(), () => ProcessMessage.ExceptionLines.NiceToString());

                PropertyAuthLogic.AvoidAutomaticUpgradeCollection.Add(PropertyRoute.Construct((ProcessEntity p) => p.User));

                ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs;
            }
        }