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));
 }
Пример #2
0
 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));
     }
 }
Пример #3
0
        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;
        }
Пример #5
0
 public virtual void Compile(Type targetType, CompileContext compileContext)
 {
     FunctionInfo = ReflectionMethodHelper.GetMethodInfo(targetType, FunctionName, typeof(bool));
 }
Пример #6
0
 public new void Compile(Type targetType)
 {
     FunctionInfo = ReflectionMethodHelper.GetMethodInfo(targetType, FunctionName, typeof(bool),
                                                         BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
 }
Пример #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));
 }
Пример #9
0
 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);
 }