Beispiel #1
0
        public RequestHandler(MethodInfo method, RestClientContext context)
        {
            _returnType        = method.ReturnType;
            _actualReturnType  = GetActualReturnType();
            _parameters        = method.GetParameters();
            _paramConverters   = GetParamConverters(context.ParamConverterManager);
            _converter         = CreateConverter(context);
            _template          = context.BaseTemplate ?? "";
            _serializer        = context.DefaultSerializer;
            _contentTypes      = context.DefaultContentTypes;
            _errorResponseType = context.ErrorResponseType;

            _bodyArgumentIndex = _parameters.Length - 1;

            var templateBuilder = new StringBuilder(context.BaseTemplate ?? "");

            foreach (var attribute in method.GetCustomAttributes(true))
            {
                switch (attribute)
                {
                case HttpMethodAttribute httpMethodAttribute:
                    templateBuilder.Append(httpMethodAttribute.Template);
                    _httpMethod = GetHttpMethod(httpMethodAttribute);
                    break;

                case ErrorResponseAttribute errorResponseAttribute:
                    _errorResponseType = errorResponseAttribute.Type;
                    break;

                case ConsumesAttribute consumesAttribute:
                    _contentTypes = consumesAttribute.ContentTypes;
                    _serializer   = context.SerializationManager.GetSerializer(_contentTypes) ??
                                    throw new InvalidOperationException(
                                              "No serializer for: " + string.Join(",", _contentTypes));
                    break;

                case RouteAttribute routeAttribute:
                    templateBuilder.Append(routeAttribute.Template);
                    break;
                }
            }

            if (context.UseDomainException)
            {
                _domainExceptionMapper = context.DomainExceptionMapperFactory.CreateDomainExceptionMapper(
                    method,
                    _errorResponseType,
                    context.DomainExceptionType);
            }

            _template = templateBuilder.ToString();
            _context  = context;
        }
        public MethodHandler(MethodInfo method, AbstractSqlAttribute sqlAttribute, DatabaseClientContext context)
        {
            Type resultType;

            _method       = method;
            _sqlAttribute = sqlAttribute;
            _isUpdate     = _sqlAttribute is SqlUpdateAttribute;
            _context      = context;

            var returnType = _method.ReturnType;

            if (returnType == typeof(Task))
            {
                resultType = typeof(void);
                _isAsync   = true;
            }
            else if (returnType.BaseType == typeof(Task) && returnType.IsGenericType)
            {
                resultType = returnType.GenericTypeArguments[0];
                _isAsync   = true;
            }
            else
            {
                resultType = returnType;
                _isAsync   = false;
            }

            _taskConverter = _context.TaskConverterFactory.CreateTaskConverter(resultType);

            _isResultEnumerable = resultType.IsGenericType &&
                                  resultType.Namespace == "System.Collections.Generic" &&
                                  resultType.Name == "IEnumerable`1";

            if (_isResultEnumerable)
            {
                _effectiveType = resultType.GenericTypeArguments[0];
            }
            else
            {
                _effectiveType = resultType;
            }
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="sqlSettings">Sql settings.</param>
        /// <param name="taskConverter">The <see cref="ITaskConverter"/> instance.</param>
        /// <param name="connectionFactory">The <see cref="ISqlConnectionFactory"/> instance.</param>
        /// <param name="loggerFactory">The <see cref="ICommonLoggerFactory"/> instance.</param>
        /// <exception cref="ArgumentNullException"><paramref name="sqlSettings"/> is <see langword="null" />.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="taskConverter"/> is <see langword="null" />.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="connectionFactory"/> is <see langword="null" />.</exception>
        public TaskDataContext(MsSqlSettings sqlSettings, ITaskConverter taskConverter, ISqlConnectionFactory connectionFactory, ICommonLoggerFactory loggerFactory)
            : base(loggerFactory)
        {
            if (sqlSettings == null)
            {
                throw new ArgumentNullException("sqlSettings");
            }
            if (taskConverter == null)
            {
                throw new ArgumentNullException("taskConverter");
            }
            if (connectionFactory == null)
            {
                throw new ArgumentNullException("connectionFactory");
            }

            this.sqlSettings       = sqlSettings;
            this.taskConverter     = taskConverter;
            this.connectionFactory = connectionFactory;
        }
Beispiel #4
0
 ///-------------------------------------------------------------------------------------------------
 /// <summary>
 ///     initializes a new instance of the
 ///     WK.Orion.Platform.Examples.Components.Tasks.DataAccessLayer.Repositories.TaskRepository class.
 /// </summary>
 ///
 /// <param name="taskConverter">    The task converter. </param>
 ///-------------------------------------------------------------------------------------------------
 public TaskRepository(ITaskConverter taskConverter)
 {
     _taskConverter = taskConverter;
 }