예제 #1
0
        private object ConvertObject(JToken token, JsonSerializer serializer, OperationSymbol operationSymbol)
        {
            if (token == null)
                return null;

            if (token is JValue)
            {
                var obj = ((JValue)token).Value;
                return obj;
            }

            if (token is JObject)
            {
                var j = (JObject)token;

                if (j.Property("EntityType") != null)
                    return serializer.Deserialize(new JTokenReader(j), typeof(Lite<Entity>));

                if (j.Property("Type") != null)
                    return serializer.Deserialize(new JTokenReader(j), typeof(ModifiableEntity));
            }
            else if (token is JArray)
            {
                var a = (JArray)token;
                var result = a.Select(t => ConvertObject(t, serializer, operationSymbol)).ToList();
                return result;

            }

            var conv = CustomOperationArgsConverters.TryGetC(operationSymbol);

            if (conv == null)
                throw new InvalidOperationException("Impossible to deserialize request before executing {0}.\r\nConsider registering your own converter in 'CustomOperationArgsConverters'.\r\nReceived JSON:\r\n\r\n{1}".FormatWith(operationSymbol, token));

            return conv.GetInvocationListTyped().Select(f => conv(token)).NotNull().FirstOrDefault();
        }
        public static Entity ServiceConstructFromMany(IEnumerable <Lite <IEntity> > lites, Type type, OperationSymbol operationSymbol, params object[] args)
        {
            var onlyType = lites.Select(a => a.EntityType).Distinct().Only();

            return((Entity)Find <IConstructorFromManyOperation>(onlyType ?? type, operationSymbol).Construct(lites, args));
        }
        public static Entity ServiceConstructFrom(IEntity entity, OperationSymbol operationSymbol, params object[] args)
        {
            var op = Find <IConstructorFromOperation>(entity.GetType(), operationSymbol).AssertEntity((Entity)(object)entity);

            return((Entity)op.Construct(entity, args));
        }
예제 #4
0
 internal ConstructorOperationSettings(OperationSymbol symbol)
     : base(symbol)
 {
 }
예제 #5
0
 protected ConstructorOperationSettingsBase(OperationSymbol symbol)
     : base(symbol)
 {
 }
예제 #6
0
 public EntityOperationSettingsBase(OperationSymbol symbol)
     : base(symbol)
 {
 }
예제 #7
0
        public static string GetOperationHelp(OperationSymbol symbol)
        {
            var type = OperationLogic.FindTypes(symbol).First();

            var operationInfo = OperationLogic.GetOperationInfo(type, symbol);

            switch (operationInfo.OperationType)
            {
                case OperationType.Execute: return HelpMessage.Call0Over1OfThe2.NiceToString().ForGenderAndNumber(type.GetGender()).FormatWith(
                    operationInfo.OperationSymbol.NiceToString(),
                    operationInfo.Lite.Value ? HelpMessage.TheDatabaseVersion.NiceToString() : HelpMessage.YourVersion.NiceToString(), 
                    type.NiceName());
                case OperationType.Delete: return HelpMessage.RemovesThe0FromTheDatabase.NiceToString(type.NiceName());
                case OperationType.Constructor: return
                    HelpMessage.ConstructsANew0.NiceToString().ForGenderAndNumber(type.GetGender()).FormatWith(type.NiceName());
                case OperationType.ConstructorFrom: return
                    HelpMessage.ConstructsANew0.NiceToString().ForGenderAndNumber(operationInfo.ReturnType.GetGender()).FormatWith(operationInfo.ReturnType.NiceName()) + " " +
                    HelpMessage.From0OfThe1.NiceToString().ForGenderAndNumber(type.GetGender()).FormatWith(operationInfo.Lite.Value ? HelpMessage.TheDatabaseVersion.NiceToString() : HelpMessage.YourVersion.NiceToString(), type.NiceName());
                case OperationType.ConstructorFromMany: return
                    HelpMessage.ConstructsANew0.NiceToString().ForGenderAndNumber(operationInfo.ReturnType.GetGender()).FormatWith(operationInfo.ReturnType.NiceName()) + " " +
                    HelpMessage.FromMany0.NiceToString().ForGenderAndNumber(type.GetGender()).FormatWith(type.NicePluralName());
            }

            return "";
        }
예제 #8
0
 public static IQueryable <OperationLogEntity> Logs(this OperationSymbol o)
 {
     return(LogsExpression.Evaluate(o));
 }
예제 #9
0
 public void Delete(IEntity entity, OperationSymbol operationSymbol, params object[] args)
 {
     Execute(MethodInfo.GetCurrentMethod(), operationSymbol.ToString(),
             () => OperationLogic.ServiceDelete((Entity)entity, operationSymbol, args));
 }
예제 #10
0
 public Entity ExecuteOperationLite(Lite <IEntity> lite, OperationSymbol operationSymbol, params object[] args)
 {
     return(Return(MethodInfo.GetCurrentMethod(), operationSymbol.ToString(),
                   () => (Entity)OperationLogic.ServiceExecuteLite(lite, operationSymbol, args)));
 }
예제 #11
0
 public Entity ExecuteOperation(IEntity entity, OperationSymbol operationSymbol, params object[] args)
 {
     return(Return(MethodInfo.GetCurrentMethod(), operationSymbol.ToString(),
                   () => OperationLogic.ServiceExecute(entity, operationSymbol, args)));
 }
예제 #12
0
 public string GetCanExecuteLite(Lite <Entity> lite, OperationSymbol operationSymbol)
 {
     return(Return(MethodInfo.GetCurrentMethod(), lite.EntityType.Name + " " + operationSymbol,
                   () => OperationLogic.ServiceCanExecute(lite.Retrieve(), operationSymbol)));
 }
예제 #13
0
 public static void RegisterCustomOperationArgsConverter(OperationSymbol operationSymbol, Func<JToken, object> converter)
 {
     CustomOperationArgsConverters[operationSymbol] =
         CustomOperationArgsConverters.TryGetC(operationSymbol) +
         converter;
 }
 public static bool IsDefined(Type type, OperationSymbol operation)
 {
     return(operations.TryGetValue(type)?.TryGetC(operation) != null);
 }
예제 #15
0
 public Entity ConstructFromLite(Lite <IEntity> lite, OperationSymbol operationSymbol, params object[] args)
 {
     return(Return(MethodInfo.GetCurrentMethod(), operationSymbol.ToString(),
                   () => OperationLogic.ServiceConstructFromLite(lite, operationSymbol, args)));
 }
예제 #16
0
 public static OperationInfo GetOperationInfo(Type type, OperationSymbol operationSymbol)
 {
     return(ToOperationInfo(FindOperation(type, operationSymbol)));
 }
예제 #17
0
 public Entity ConstructFromMany(IEnumerable <Lite <IEntity> > lites, Type type, OperationSymbol operationKey, params object[] args)
 {
     return(Return(MethodInfo.GetCurrentMethod(), operationKey.ToString(),
                   () => OperationLogic.ServiceConstructFromMany(lites, type, operationKey, args)));
 }
예제 #18
0
        public static Entity ServiceConstruct(Type type, OperationSymbol operationSymbol, params object[] args)
        {
            var op = Find <IConstructOperation>(type, operationSymbol);

            return((Entity)op.Construct(args));
        }
예제 #19
0
 public static void RegisterCustomOperationArgsConverter(OperationSymbol operationSymbol, Func <JToken, object> converter)
 {
     CustomOperationArgsConverters[operationSymbol] =
         CustomOperationArgsConverters.TryGetC(operationSymbol) +
         converter;
 }
예제 #20
0
 public static string IdOperation(OperationSymbol operation)
 {
     return "o-" + operation.Key.Replace('.', '_');
 }
예제 #21
0
 protected ConstructFromMany(OperationSymbol operationSymbol, Type baseType)
 {
     this.operationSymbol = operationSymbol ?? throw new ArgumentNullException(nameof(operationSymbol));
     this.baseType        = baseType ?? throw new ArgumentNullException(nameof(baseType));
 }
예제 #22
0
 internal EntityOperationSettings(OperationSymbol symbol)
     : base(symbol)
 {
     this.Contextual         = new ContextualOperationSettings <T>(symbol);
     this.ContextualFromMany = new ContextualOperationSettings <T>(symbol);
 }
예제 #23
0
 protected Construct(OperationSymbol operationSymbol)
 {
     this.operationSymbol = operationSymbol ?? throw new ArgumentNullException(nameof(operationSymbol));
 }
예제 #24
0
 public static ConstructorOperationSettingsBase Create(Type type, OperationSymbol symbol)
 {
     return(giCreate.GetInvoker(type)(symbol));
 }
예제 #25
0
        public static bool GetAllowed(OperationSymbol operationSymbol, bool inUserInterface)
        {
            var allowed = authorizedOperations.GetOrThrow(operationSymbol);

            return allowed == OperationAllowed.Allow || allowed == OperationAllowed.DBOnly && !inUserInterface;
        }
예제 #26
0
 public JsOperationOptions(OperationSymbol operation, string prefix)
 {
     this.operationKey = operation.Key;
     this.prefix = prefix;
 }
예제 #27
0
 public OperationAllowedExtension(object value)
 {
     this.operationKey = (OperationSymbol)value;
 }
        public static Entity ServiceConstructFromLite(Lite <IEntity> lite, OperationSymbol operationSymbol, params object[] args)
        {
            var op = Find <IConstructorFromOperation>(lite.EntityType, operationSymbol);

            return((Entity)op.Construct(Database.RetrieveAndForget(lite), args));
        }
예제 #29
0
 public OperationVisiblityExtension(object value)
 {
     this.operationKey = (value is IOperationSymbolContainer) ? ((IOperationSymbolContainer)value).Symbol : (OperationSymbol)value;
 }
 public static IOperation TryFindOperation(Type type, OperationSymbol operationSymbol)
 {
     return(operations.TryGetValue(type.CleanType())?.TryGetC(operationSymbol));
 }
예제 #31
0
        /// <summary>
        /// 将运算枚举符号转成具体使用方法
        /// </summary>
        public static Expression ChangeOperationSymbol(OperationSymbol symbol, Expression key, object right)
        {
            // 将右边数据类型强行转换成左边一样的类型
            // 两者如果Type不匹配则无法接下去的运算操作,抛出异常
            object newTypeRight;

            if (right == null || string.IsNullOrEmpty(right.ToString()) || right.ToString() == "null")
            {
                newTypeRight = null;
            }
            else
            {
                newTypeRight = Convert.ChangeType(right, key.Type);
            }

            // 根据当前枚举类别判断使用那种比较方法
            switch (symbol)
            {
            case OperationSymbol.Equal:
                return(key.Equal(Expression.Constant(newTypeRight)));

            case OperationSymbol.GreaterThan:
            {
                if (key.Type == typeof(string))
                {
                    return(key.Contains(Expression.Constant(newTypeRight)));        //对string 特殊处理  由于string
                }
                else
                {
                    return(key.GreaterThan(Expression.Constant((newTypeRight))));
                }
            }

            case OperationSymbol.GreaterThanOrEqual:
            {
                if (key.Type == typeof(string))
                {
                    return(key.Contains(Expression.Constant(newTypeRight, typeof(string))));
                }
                else
                {
                    return(key.GreaterThanOrEqual(Expression.Constant(newTypeRight)));
                }
            }

            case OperationSymbol.LessThan:
            {
                if (key.Type == typeof(string))
                {
                    return(key.Contains(Expression.Constant(newTypeRight, typeof(string))));
                }
                else
                {
                    return(key.LessThan(Expression.Constant((newTypeRight))));
                }
            }

            case OperationSymbol.LessThanOrEqual:
            {
                if (key.Type == typeof(string))
                {
                    return(key.Contains(Expression.Constant(newTypeRight, typeof(string))));
                }
                else
                {
                    return(key.LessThanOrEqual(Expression.Constant((newTypeRight))));
                }
            }

            case OperationSymbol.NotEqual:
                return(key.NotEqual(Expression.Constant(newTypeRight)));

            case OperationSymbol.Contains:
                return(key.Contains(Expression.Constant(newTypeRight)));
            }
            throw new Exception("OperationSymbol IS NULL");
        }
 public static OperationType OperationType(Type type, OperationSymbol operationSymbol)
 {
     return(FindOperation(type, operationSymbol).OperationType);
 }
예제 #33
0
        public static void RegisterCustomOperationArgsConverter(OperationSymbol operationSymbol, Func <JToken, object?> converter)
        {
            Func <JToken, object?>?a = CustomOperationArgsConverters.TryGetC(operationSymbol); /*CSBUG*/

            CustomOperationArgsConverters[operationSymbol] = a + converter;
        }
예제 #34
0
        public static string ServiceCanExecute(Entity entity, OperationSymbol operationSymbol)
        {
            var op = Find <IEntityOperation>(entity.GetType(), operationSymbol);

            return(op.CanExecute(entity));
        }
예제 #35
0
 protected ContextualOperationSettingsBase(OperationSymbol symbol)
     : base(symbol)
 {
 }
예제 #36
0
        public static void ServiceDelete(Entity entity, OperationSymbol operationSymbol, params object[] args)
        {
            var op = Find <IDeleteOperation>(entity.GetType(), operationSymbol).AssertEntity((Entity)(IEntity)entity);

            op.Delete(entity, args);
        }
예제 #37
0
 internal ContextualOperationSettings(OperationSymbol symbol)
     : base(symbol)
 {
 }
예제 #38
0
 public ProcessEntity CreatePackageOperation(IEnumerable<Lite<IEntity>> lites, OperationSymbol operationSymbol, params object[] operationArgs)
 {
     return Return(MethodInfo.GetCurrentMethod(), null,
         () => PackageLogic.CreatePackageOperation(lites, operationSymbol, operationArgs));
 }
예제 #39
0
 protected OperationSettings(OperationSymbol symbol)
 {
     this.OperationSymbol = symbol;
 }
예제 #40
0
        public OperationHelp(OperationSymbol operationSymbol, CultureInfo ci, OperationHelpEntity entity)
        {
            this.OperationSymbol = operationSymbol;
            this.Culture = ci;

            this.Info = HelpGenerator.GetOperationHelp(operationSymbol);

            if (entity != null)
            {
                HasEntity = true;

                UserDescription = entity.Description;
            }

            Entity = new Lazy<OperationHelpEntity>(() => HelpLogic.GlobalContext(() =>
            {
                if (entity == null)
                    entity = new OperationHelpEntity
                    {
                        Culture = this.Culture.ToCultureInfoEntity(),
                        Operation = this.OperationSymbol,
                    };

                return entity;
            }));

        }
예제 #41
0
 public static string OperationUrl(Type entityType, OperationSymbol operation)
 {
     return EntityUrl(entityType) + "#" + IdOperation(operation);
 }