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)); }
internal ConstructorOperationSettings(OperationSymbol symbol) : base(symbol) { }
protected ConstructorOperationSettingsBase(OperationSymbol symbol) : base(symbol) { }
public EntityOperationSettingsBase(OperationSymbol symbol) : base(symbol) { }
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 ""; }
public static IQueryable <OperationLogEntity> Logs(this OperationSymbol o) { return(LogsExpression.Evaluate(o)); }
public void Delete(IEntity entity, OperationSymbol operationSymbol, params object[] args) { Execute(MethodInfo.GetCurrentMethod(), operationSymbol.ToString(), () => OperationLogic.ServiceDelete((Entity)entity, operationSymbol, args)); }
public Entity ExecuteOperationLite(Lite <IEntity> lite, OperationSymbol operationSymbol, params object[] args) { return(Return(MethodInfo.GetCurrentMethod(), operationSymbol.ToString(), () => (Entity)OperationLogic.ServiceExecuteLite(lite, operationSymbol, args))); }
public Entity ExecuteOperation(IEntity entity, OperationSymbol operationSymbol, params object[] args) { return(Return(MethodInfo.GetCurrentMethod(), operationSymbol.ToString(), () => OperationLogic.ServiceExecute(entity, operationSymbol, args))); }
public string GetCanExecuteLite(Lite <Entity> lite, OperationSymbol operationSymbol) { return(Return(MethodInfo.GetCurrentMethod(), lite.EntityType.Name + " " + operationSymbol, () => OperationLogic.ServiceCanExecute(lite.Retrieve(), operationSymbol))); }
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); }
public Entity ConstructFromLite(Lite <IEntity> lite, OperationSymbol operationSymbol, params object[] args) { return(Return(MethodInfo.GetCurrentMethod(), operationSymbol.ToString(), () => OperationLogic.ServiceConstructFromLite(lite, operationSymbol, args))); }
public static OperationInfo GetOperationInfo(Type type, OperationSymbol operationSymbol) { return(ToOperationInfo(FindOperation(type, operationSymbol))); }
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))); }
public static Entity ServiceConstruct(Type type, OperationSymbol operationSymbol, params object[] args) { var op = Find <IConstructOperation>(type, operationSymbol); return((Entity)op.Construct(args)); }
public static void RegisterCustomOperationArgsConverter(OperationSymbol operationSymbol, Func <JToken, object> converter) { CustomOperationArgsConverters[operationSymbol] = CustomOperationArgsConverters.TryGetC(operationSymbol) + converter; }
public static string IdOperation(OperationSymbol operation) { return "o-" + operation.Key.Replace('.', '_'); }
protected ConstructFromMany(OperationSymbol operationSymbol, Type baseType) { this.operationSymbol = operationSymbol ?? throw new ArgumentNullException(nameof(operationSymbol)); this.baseType = baseType ?? throw new ArgumentNullException(nameof(baseType)); }
internal EntityOperationSettings(OperationSymbol symbol) : base(symbol) { this.Contextual = new ContextualOperationSettings <T>(symbol); this.ContextualFromMany = new ContextualOperationSettings <T>(symbol); }
protected Construct(OperationSymbol operationSymbol) { this.operationSymbol = operationSymbol ?? throw new ArgumentNullException(nameof(operationSymbol)); }
public static ConstructorOperationSettingsBase Create(Type type, OperationSymbol symbol) { return(giCreate.GetInvoker(type)(symbol)); }
public static bool GetAllowed(OperationSymbol operationSymbol, bool inUserInterface) { var allowed = authorizedOperations.GetOrThrow(operationSymbol); return allowed == OperationAllowed.Allow || allowed == OperationAllowed.DBOnly && !inUserInterface; }
public JsOperationOptions(OperationSymbol operation, string prefix) { this.operationKey = operation.Key; this.prefix = prefix; }
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)); }
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)); }
/// <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); }
public static void RegisterCustomOperationArgsConverter(OperationSymbol operationSymbol, Func <JToken, object?> converter) { Func <JToken, object?>?a = CustomOperationArgsConverters.TryGetC(operationSymbol); /*CSBUG*/ CustomOperationArgsConverters[operationSymbol] = a + converter; }
public static string ServiceCanExecute(Entity entity, OperationSymbol operationSymbol) { var op = Find <IEntityOperation>(entity.GetType(), operationSymbol); return(op.CanExecute(entity)); }
protected ContextualOperationSettingsBase(OperationSymbol symbol) : base(symbol) { }
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); }
internal ContextualOperationSettings(OperationSymbol symbol) : base(symbol) { }
public ProcessEntity CreatePackageOperation(IEnumerable<Lite<IEntity>> lites, OperationSymbol operationSymbol, params object[] operationArgs) { return Return(MethodInfo.GetCurrentMethod(), null, () => PackageLogic.CreatePackageOperation(lites, operationSymbol, operationArgs)); }
protected OperationSettings(OperationSymbol symbol) { this.OperationSymbol = symbol; }
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; })); }
public static string OperationUrl(Type entityType, OperationSymbol operation) { return EntityUrl(entityType) + "#" + IdOperation(operation); }