示例#1
0
        public IActionResult GetConfiguration(string configurationName)
        {
            var configurationType = typeResolver.GetByName(configurationName);

            if (configurationType == null)
            {
                return(BadRequest($"Could not resolve type '{configurationName}"));
            }

            var configurationInstance = configuration.GetSection(configurationType.Name).Get(configurationType) ??
                                        Activator.CreateInstance(configurationType);

            var vmConverterType = configurationType
                                  .GetAttribute <ViewModelConverterAttribute>()?
                                  .ViewModelConverterType;

            if (vmConverterType != null)
            {
                var vmConverter            = Activator.CreateInstance(vmConverterType) as ViewModelConverter;
                var jsonSerializerSettings = new JsonSerializerSettings
                {
                    ContractResolver = new DefaultContractResolver()
                };
                return(new JsonResult(vmConverter.ToViewModel(configurationInstance), jsonSerializerSettings));
            }
            return(Ok(configurationInstance));
        }
示例#2
0
        public IActionResult GetConfiguration(string configurationName)
        {
            var configurationType = typeResolver.GetByName(configurationName);

            if (configurationType == null)
            {
                return(BadRequest($"Could not resolve type '{configurationName}"));
            }

            var configurationInstance = configuration.GetSection(configurationType.Name).Get(configurationType) ??
                                        Activator.CreateInstance(configurationType);

            return(Ok(configurationInstance));
        }
示例#3
0
        public async Task <ActionResult> Execute(string requestType, [FromBody] JToken requestInst)
        {
            if (requestInst == null)
            {
                return(BadRequest("Body of request cannot be null!"));
            }

            var type = typeResolver.GetByName(requestType);

            if (type == null)
            {
                return(BadRequest($"Could not resolve type: {requestType}"));
            }

            var instance = requestInst.ToObject(type);

            if (instance == null)
            {
                return(BadRequest($"Given instance is not a valid JSON object of type '{requestType}'"));
            }

            var result = await mediator.Send(instance) as Result;

            if (result.ExceptionThrown != null)
            {
                throw new Exception($"Request execution failed!{Environment.NewLine}{requestInst}", result.ExceptionThrown);
            }
            if (result.HasErrors)
            {
                return(BadRequest(result.Message));
            }

            return(Ok(result));
        }
        public override async Task ExecuteInternal(IJobExecutionContext context)
        {
            var jobParams = context
                            .JobDetail
                            .JobDataMap
                            .Where(d => d.Value is string)
                            .ToDictionary(kv => kv.Key, kv => kv.Value as string);

            if (!jobParams.TryGetValue(Request_Type, out var requestTypeName))
            {
                throw new ArgumentException("No request type defined!");
            }

            var requestType = typeResolver.GetByName(requestTypeName);

            if (requestType == null)
            {
                throw new ArgumentException($"Could not resolve type {requestTypeName}!");
            }

            if (!jobParams.TryGetValue(Request_Instance, out var requestInstanceRaw))
            {
                throw new ArgumentException("No request instance defined!");
            }

            var requestInstance = serializer.Deserialize(requestInstanceRaw, requestType);

            if (requestInstance == null)
            {
                throw new ArgumentException("Could not create request instance!");
            }

            logger.LogInformation($"Executing '{requestType.Name}', {requestInstance} ...");
            var requestResponse = await mediator.Send(requestInstance);

            if (requestResponse is IResult)
            {
                var result = requestResponse as IResult;
                if (result.HasErrors)
                {
                    if (result.ExceptionThrown == null)
                    {
                        logger.LogWarning(result.Message);
                    }
                    else
                    {
                        logger.LogError(result.ExceptionThrown, result.ExceptionThrown.Message);
                    }
                }
                else
                {
                    logger.LogInformation(result.Message);
                    DispatchResult(result.Response /*, jobParams*/);
                }
            }
        }
        public void Save(string configTypeName, object configInstance)
        {
            var configType = _typeResolver.GetByName(configTypeName);

            if (configTypeName == null)
            {
                throw new ArgumentException($"Could not resolve type '{configTypeName}'.");
            }

            Save(configType, configInstance);
        }
示例#6
0
        public IActionResult GetSample(string providerName)
        {
            var type = typeResolver.GetByName(providerName);

            if (type == null)
            {
                return(BadRequest($"Could not create provider '{providerName}'!"));
            }

            using var scope = scopeFactory.CreateScope();
            var provider = scope.ServiceProvider.GetService(type) as IRequestSampleProvider;
            var jsonSerializerSettings = new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver()
            };

            return(new JsonResult(provider.GetSample(), jsonSerializerSettings));
        }
示例#7
0
        protected override async Task ExecuteInternal(IJobExecutionContext context)
        {
            var jobParams = context
                            .JobDetail
                            .JobDataMap
                            .Where(d => d.Value is string)
                            .ToDictionary(kv => kv.Key, kv => kv.Value as string);

            if (!jobParams.TryGetValue(Request_Type, out var requestTypeName))
            {
                throw new ArgumentException("No request type defined!");
            }

            var requestType = typeResolver.GetByName(requestTypeName);

            if (requestType == null)
            {
                throw new ArgumentException($"Could not resolve type {requestTypeName}!");
            }

            if (!jobParams.TryGetValue(Request_Instance, out var requestInstanceRaw))
            {
                throw new ArgumentException("No request instance defined!");
            }

            var requestInstance = serializer.Deserialize(requestInstanceRaw, requestType);

            if (requestInstance == null)
            {
                throw new ArgumentException("Could not create request instance!");
            }

            logger.LogInformation($"Executing '{requestType.Name}', {requestInstance} ...");
            var requestResponse = await mediator.Send(requestInstance);

            if (requestResponse is Result result)
            {
                if (result.HasErrors)
                {
                    if (result.ExceptionThrown == null)
                    {
                        logger.LogWarning(result.Message);
                        context.Put(Scheduler.MessageKey, result.Message);
                    }
                    else
                    {
                        logger.LogError(result.ExceptionThrown, result.ExceptionThrown.Message);
                        context.Put(Scheduler.MessageKey, result.ExceptionThrown.Message);
                        context.Put(Scheduler.ResultKey, Boolean.TrueString);
                    }
                }
                else
                {
                    logger.LogInformation(result.Message);
                    object response = ((dynamic)result).Response;
                    if (response == null)
                    {
                        logger.LogWarning("Cannot dispatch null object! {@result}", result);
                        return;
                    }
                    else
                    {
                        DispatchResult(response /*, jobParams*/);
                        context.Put(Scheduler.MessageKey, result.Message);
                    }
                }
            }
        }