public void Compile(Type declaredType, Type modelType = null)
 {
     BeforeFunction     = ReflectionMethodHelper.GetMethodInfo(declaredType, Before, typeof(void));
     BeforeSaveFunction = ReflectionMethodHelper.GetMethodInfo(declaredType, BeforeSave, typeof(void));
     AfterFunction      = ReflectionMethodHelper.GetMethodInfo(declaredType, After, typeof(void));
     InsteadOfFunction  = ReflectionMethodHelper.GetMethodInfo(declaredType, InsteadOf, typeof(void));
 }
 public override void Compile(Type targetType, CompileContext compileContext)
 {
     if (compileContext == CompileContext.Class)
     {
         FunctionInfo = ReflectionMethodHelper.GetMethodInfo(targetType, FunctionName, typeof(bool),
                                                             BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
     }
     else if (compileContext == CompileContext.Property)
     {
         FunctionInfo = ReflectionMethodHelper.GetMethodInfo(targetType, FunctionName, typeof(bool));
     }
 }
        public async Task <ResponseBase> Handle(HttpInformation context, InvokeCommand command, ExecutionContext executionContext)
        {
            SapphireDbContext           db       = GetContext(command.ContextName);
            KeyValuePair <Type, string> property = db.GetType().GetDbSetType(command.CollectionName);

            if (property.Key == null)
            {
                throw new CollectionNotFoundException(command.ContextName, command.CollectionName);
            }

            object[] primaryKeys = property.Key.GetPrimaryKeyValues(db, command.PrimaryKeys);
            object   value       = db.Find(property.Key, primaryKeys);

            if (value == null)
            {
                throw new ValueNotFoundException(command.ContextName, command.CollectionName, primaryKeys);
            }

            MethodInfo methodInfo = ReflectionMethodHelper.GetMethodInfo(property.Key, command.Action);

            if (methodInfo == null)
            {
                throw new MethodNotFoundException(property.Key.Name, command.Action);
            }

            if (methodInfo.GetCustomAttribute <InvokableAttribute>() == null)
            {
                throw new NotInvokableException(command.ContextName, command.CollectionName, command.Action);
            }

            object result = methodInfo.Invoke(value, methodInfo.CreateParameters(context, serviceProvider, command.Parameters, db));

            if (result != null)
            {
                result = await ActionHelper.HandleAsyncResult(result);
            }

            logger.LogInformation("Executed {CollectionName}.{ActionName}. ExecutionId: {ExecutionId}", property.Value, methodInfo.Name, executionContext.Id);

            return(new InvokeResponse()
            {
                ReferenceId = command.ReferenceId,
                Result = result
            });
        }
        public void Compile(Type declaredType, Type modelType)
        {
            MethodInfo functionInfo = ReflectionMethodHelper.GetMethodInfo(declaredType, FunctionName, null,
                                                                           BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

            Type queryBuilderType = typeof(SapphireQueryBuilder <>).MakeGenericType(modelType);

            if (!functionInfo.IsGenericMethod)
            {
                throw new WrongReturnTypeException(declaredType.Name, FunctionName, queryBuilderType.Name);
            }

            MethodInfo functionInfoGeneric = functionInfo.MakeGenericMethod(modelType);

            if (!queryBuilderType.IsAssignableFrom(functionInfoGeneric.ReturnType))
            {
                throw new WrongReturnTypeException(declaredType.Name, FunctionName, queryBuilderType.Name);
            }

            FunctionInfo = functionInfoGeneric;
        }
Exemple #5
0
 public virtual void Compile(Type targetType, CompileContext compileContext)
 {
     FunctionInfo = ReflectionMethodHelper.GetMethodInfo(targetType, FunctionName, typeof(bool));
 }
 public new void Compile(Type targetType)
 {
     FunctionInfo = ReflectionMethodHelper.GetMethodInfo(targetType, FunctionName, typeof(bool),
                                                         BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
 }
Exemple #7
0
 public void Compile(Type targetType)
 {
     FunctionInfo = ReflectionMethodHelper.GetMethodInfo(targetType, FunctionName, typeof(bool));
 }
 public void Compile(Type modelType)
 {
     BeforeFunction     = ReflectionMethodHelper.GetMethodInfo(modelType, Before, typeof(void));
     BeforeSaveFunction = ReflectionMethodHelper.GetMethodInfo(modelType, BeforeSave, typeof(void));
     AfterFunction      = ReflectionMethodHelper.GetMethodInfo(modelType, After, typeof(void));
 }
 public void Compile(Type declaredType, Type modelType = null)
 {
     FunctionInfo = ReflectionMethodHelper.GetMethodInfo(declaredType, FunctionName, typeof(SapphireQueryBuilderBase <>).MakeGenericType(declaredType),
                                                         BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
 }