Exemplo n.º 1
0
        public static void RegisterUserTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((NoteEntity uq) => uq.CreatedBy, typeof(UserEntity));

            TypeConditionLogic.RegisterCompile <NoteEntity>(typeCondition,
                                                            uq => uq.CreatedBy.Is(UserEntity.Current));
        }
Exemplo n.º 2
0
        public static void RegisterUserTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((UserQueryEntity uq) => uq.Owner, typeof(UserEntity));

            TypeConditionLogic.RegisterCompile <UserQueryEntity>(typeCondition,
                                                                 uq => uq.Owner.RefersTo(UserEntity.Current));
        }
Exemplo n.º 3
0
    public static IQueryable <T> WhereCondition <T>(this IQueryable <T> query, TypeConditionSymbol typeCondition)
        where T : Entity
    {
        Expression <Func <T, bool> > exp = (Expression <Func <T, bool> >)GetCondition(typeof(T), typeCondition);

        return(query.Where(exp));
    }
Exemplo n.º 4
0
        public static void RegisterRecipientTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((AlertEntity a) => a.Recipient, typeof(UserEntity));

            TypeConditionLogic.RegisterCompile <AlertEntity>(typeCondition,
                                                             a => a.Recipient.Is(UserEntity.Current));
        }
Exemplo n.º 5
0
    public static Func <T, bool>?GetInMemoryCondition <T>(TypeConditionSymbol typeCondition)
        where T : Entity
    {
        var pair = infos.GetOrThrow(typeof(T), "There's no TypeCondition registered for type {0}").GetOrThrow(typeCondition);

        return((Func <T, bool>?)pair.InMemoryCondition);
    }
Exemplo n.º 6
0
        public static void RegisterRoleTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((UserChartEntity uq) => uq.Owner, typeof(RoleEntity));

            TypeConditionLogic.RegisterCompile <UserChartEntity>(typeCondition,
                                                                 uq => AuthLogic.CurrentRoles().Contains(uq.Owner) || uq.Owner == null);
        }
Exemplo n.º 7
0
        static SqlPreCommand?AuthCache_PreDeleteSqlSync_Condition(Entity arg)
        {
            TypeConditionSymbol condition = (TypeConditionSymbol)arg;

            var command = Administrator.UnsafeDeletePreCommandMList((RuleTypeEntity rt) => rt.Conditions, Database.MListQuery((RuleTypeEntity rt) => rt.Conditions).Where(mle => mle.Element.Condition == condition));

            return(command);
        }
Exemplo n.º 8
0
        public Expression Expand(Expression?instance, Expression[] arguments, MethodInfo mi)
        {
            Expression          entity        = arguments[0];
            TypeConditionSymbol typeCondition = (TypeConditionSymbol)ExpressionEvaluator.Eval(arguments[1]) !;

            var exp = GetCondition(entity.Type, typeCondition);

            return(Expression.Invoke(exp, entity));
        }
Exemplo n.º 9
0
        public static void RegisterUserTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((DashboardEntity uq) => uq.Owner, typeof(UserEntity));

            TypeConditionLogic.RegisterCompile <DashboardEntity>(typeCondition,
                                                                 uq => uq.Owner.Is(UserEntity.Current));

            RegisterPartsTypeCondition(typeCondition);
        }
Exemplo n.º 10
0
        public Expression Expand(Expression?instance, Expression[] arguments, MethodInfo mi)
        {
            Type type = mi.GetGenericArguments()[0];

            Expression          query         = arguments[0];
            TypeConditionSymbol typeCondition = (TypeConditionSymbol)ExpressionEvaluator.Eval(arguments[1]) !;

            LambdaExpression exp = GetCondition(type, typeCondition);

            return(Expression.Call(null, miWhere.MakeGenericMethod(type), query, exp));
        }
Exemplo n.º 11
0
        public static void RegisterUserTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            TypeConditionLogic.RegisterCompile <ProcessEntity>(typeCondition,
                                                               pe => pe.User.RefersTo(UserEntity.Current));

            TypeConditionLogic.Register <PackageOperationEntity>(typeCondition,
                                                                 po => Database.Query <ProcessEntity>().WhereCondition(typeCondition).Any(pe => pe.Data == po));

            TypeConditionLogic.Register <PackageLineEntity>(typeCondition,
                                                            pl => ((PackageOperationEntity)pl.Package.Entity).InCondition(typeCondition));
        }
Exemplo n.º 12
0
        public static void RegisterRoleTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((ToolbarEntity t) => t.Owner, typeof(RoleEntity));

            TypeConditionLogic.RegisterCompile <ToolbarEntity>(typeCondition,
                                                               t => AuthLogic.CurrentRoles().Contains(t.Owner));

            sb.Schema.Settings.AssertImplementedBy((ToolbarMenuEntity t) => t.Owner, typeof(RoleEntity));

            TypeConditionLogic.RegisterCompile <ToolbarMenuEntity>(typeCondition,
                                                                   t => AuthLogic.CurrentRoles().Contains(t.Owner));
        }
Exemplo n.º 13
0
        public static void RegisterUserTypeCondition(SchemaBuilder sb, TypeConditionSymbol typeCondition)
        {
            sb.Schema.Settings.AssertImplementedBy((ToolbarEntity t) => t.Owner, typeof(UserEntity));

            TypeConditionLogic.RegisterCompile <ToolbarEntity>(typeCondition,
                                                               t => t.Owner.RefersTo(UserEntity.Current));

            sb.Schema.Settings.AssertImplementedBy((ToolbarMenuEntity t) => t.Owner, typeof(UserEntity));

            TypeConditionLogic.RegisterCompile <ToolbarMenuEntity>(typeCondition,
                                                                   t => t.Owner.RefersTo(UserEntity.Current));
        }
Exemplo n.º 14
0
    public static LambdaExpression GetCondition(Type type, TypeConditionSymbol typeCondition)
    {
        var tempExpr = tempConditions.Value?.TryGetC(type)?.TryGetC(typeCondition);

        if (tempExpr != null)
        {
            return(tempExpr);
        }

        var pair = infos.GetOrThrow(type, "There's no TypeCondition registered for type {0}").GetOrThrow(typeCondition);

        return(pair.Condition);
    }
Exemplo n.º 15
0
        public static void RegisterPartsTypeCondition(TypeConditionSymbol typeCondition)
        {
            TypeConditionLogic.Register <ValueUserQueryListPartEntity>(typeCondition,
                                                                       cscp => Database.Query <DashboardEntity>().WhereCondition(typeCondition).Any(cp => cp.ContainsContent(cscp)));

            TypeConditionLogic.Register <LinkListPartEntity>(typeCondition,
                                                             llp => Database.Query <DashboardEntity>().WhereCondition(typeCondition).Any(cp => cp.ContainsContent(llp)));

            TypeConditionLogic.Register <UserChartPartEntity>(typeCondition,
                                                              ucp => Database.Query <DashboardEntity>().WhereCondition(typeCondition).Any(cp => cp.ContainsContent(ucp)));

            TypeConditionLogic.Register <UserQueryPartEntity>(typeCondition,
                                                              uqp => Database.Query <DashboardEntity>().WhereCondition(typeCondition).Any(cp => cp.ContainsContent(uqp)));
        }
Exemplo n.º 16
0
        public static void Register <T>(TypeConditionSymbol typeCondition, Expression <Func <T, bool> > condition, Func <T, bool>?inMemoryCondition)
            where T : Entity
        {
            if (typeCondition == null)
            {
                throw AutoInitAttribute.ArgumentNullException(typeof(TypeConditionSymbol), nameof(typeCondition));
            }

            if (condition == null)
            {
                throw new ArgumentNullException(nameof(condition));
            }

            infos.GetOrCreate(typeof(T))[typeCondition] = new TypeConditionPair(condition, inMemoryCondition);
        }
Exemplo n.º 17
0
    public static void Register <T>(TypeConditionSymbol typeCondition, Expression <Func <T, bool> > condition, Func <T, bool>?inMemoryCondition)
        where T : Entity
    {
        if (Schema.Current.IsCompleted)
        {
            throw new InvalidOperationException("Schema already completed");
        }

        if (typeCondition == null)
        {
            throw AutoInitAttribute.ArgumentNullException(typeof(TypeConditionSymbol), nameof(typeCondition));
        }

        if (condition == null)
        {
            throw new ArgumentNullException(nameof(condition));
        }

        infos.GetOrCreate(typeof(T))[typeCondition] = new TypeConditionPair(condition, inMemoryCondition);
    }
Exemplo n.º 18
0
    public static IDisposable ReplaceTemporally <T>(TypeConditionSymbol typeAllowed, Expression <Func <T, bool> > condition)
        where T : Entity
    {
        var dic = tempConditions.Value ?? (tempConditions.Value = new Dictionary <Type, Dictionary <TypeConditionSymbol, LambdaExpression> >());

        var subDic = dic.GetOrCreate(typeof(T));

        subDic.Add(typeAllowed, condition);

        return(new Disposable(() =>
        {
            subDic.Remove(typeAllowed);

            if (subDic.Count == 0)
            {
                dic.Remove(typeof(T));
            }

            if (dic.Count == 0)
            {
                tempConditions.Value = null;
            }
        }));
    }
Exemplo n.º 19
0
 internal ConditionDebugData(TypeConditionSymbol typeCondition, bool inGroup, TypeAllowed allowed)
 {
     this.TypeCondition = typeCondition;
     this.InGroup       = inGroup;
     this.Allowed       = allowed;
 }
Exemplo n.º 20
0
 public TypeConditionRuleBuilder(TypeConditionSymbol typeCondition, TypeAllowed allowed)
 {
     this.TypeCondition = typeCondition;
     this.Allowed       = new TypeAllowedBuilder(allowed);
 }
Exemplo n.º 21
0
 public TypeAllowedAndConditions WithoutCondition(TypeConditionSymbol typeCondition)
 {
     return(new TypeAllowedAndConditions(this.Fallback, this.Conditions.Where(a => !a.TypeCondition.Is(typeCondition))));
 }
Exemplo n.º 22
0
 public TypeConditionRuleEmbedded(TypeConditionSymbol typeCondition, TypeAllowed allowed)
 {
     this.TypeCondition = typeCondition;
     this.Allowed       = allowed;
 }
Exemplo n.º 23
0
 public static bool InCondition(this Entity entity, TypeConditionSymbol typeCondition)
 {
     throw new InvalidProgramException("InCondition is meant to be used in database only");
 }
Exemplo n.º 24
0
 public static void RegisterCompile <T>(TypeConditionSymbol typeCondition, Expression <Func <T, bool> > condition)
     where T : Entity
 {
     Register <T>(typeCondition, condition, condition.Compile());
 }
Exemplo n.º 25
0
 public static bool IsDefined(Type type, TypeConditionSymbol typeCondition)
 {
     return(infos.TryGetC(type)?.TryGetC(typeCondition) != null);
 }