Esempio n. 1
0
        public BaseStartup(IConfiguration configuration, IHostingEnvironment hostingEnvironment)
        {
            Configuration      = configuration;
            HostingEnvironment = hostingEnvironment;

            _swaggerOptions = new SwaggerOptions();
            Configuration.GetSection(nameof(SwaggerOptions)).Bind(_swaggerOptions);

            _oauthOptions = new OAuthOptions();
            Configuration.GetSection(nameof(OAuthOptions)).Bind(_oauthOptions);

            _httpServiceOptions = new HttpServiceOptions();
            Configuration.GetSection(nameof(HttpServiceOptions)).Bind(_httpServiceOptions);
        }
Esempio n. 2
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            _swaggerOptions = new SwaggerOptions();
            Configuration.GetSection(nameof(SwaggerOptions)).Bind(_swaggerOptions);

            _realTimeOptions = new RealTimeOptions();
            Configuration.GetSection(nameof(RealTimeOptions)).Bind(_realTimeOptions);

            _OAuthOptions = new OAuthOptions();
            Configuration.GetSection(nameof(OAuthOptions)).Bind(_OAuthOptions);

            _httpServiceOptions = new HttpServiceOptions();
            Configuration.GetSection(nameof(HttpServiceOptions)).Bind(_httpServiceOptions);
        }
Esempio n. 3
0
        public async Task <HttpResultModel> ExecuteHttp(HttpServiceOptions httpServiceOptions)
        {
            var successCodes             = httpServiceOptions.HttpSuccessCode.Split(";").Select(a => int.Parse(a));
            var httpResult               = new HttpResultModel();
            HttpResponseMessage response = null;

            switch (httpServiceOptions.HttpMethod)
            {
            case "Get":
                response = await _httpClient.GetAsync(httpServiceOptions.HttpServiceUrl);

                break;

            case "Post":
                using (var stringContent = new StringContent(httpServiceOptions.JsonBody, Encoding.UTF8))
                {
                    response = await _httpClient.PostAsync(httpServiceOptions.HttpServiceUrl, stringContent);
                }
                break;

            case "Put":
                using (var stringContent = new StringContent(httpServiceOptions.JsonBody, Encoding.UTF8))
                {
                    response = await _httpClient.PutAsync(httpServiceOptions.HttpServiceUrl, stringContent);
                }
                break;

            case "Delete":
                response = await _httpClient.DeleteAsync(httpServiceOptions.HttpServiceUrl);

                break;
            }

            if (successCodes.Any(a => a == (int)response.StatusCode))
            {
                httpResult.IsSuccess = true;
                httpResult.Result    = await response.Content.ReadAsJsonAsync <dynamic>();
            }
            return(httpResult);
        }
Esempio n. 4
0
        public static async Task <PopulationResultCollection> CollectData <T>(AnalyticalObject <T> focusedObject,
                                                                              IServiceInput serviceInput)
        {
            if (focusedObject.ServiceName == null)
            {
                throw new Exception("Root analyzer object must have a service defined.");
            }

            if (!FluentOlapConfiguration.ServiceDefinitions.ContainsKey(focusedObject.ServiceName))
            {
                throw new Exception($"Service {focusedObject.ServiceName} not defined.");
            }

            IService <IServiceInput, IServiceOutput> focusedService = FluentOlapConfiguration.ServiceDefinitions[focusedObject.ServiceName];
            PopulationResultCollection results = new PopulationResultCollection();

            PopulationResult rootResult = await CallService(focusedService, serviceInput);

            results.Add(rootResult);

            foreach (var expandable in focusedObject.ExpandableChildren)
            {
                if (expandable.Value.ServiceName == null)
                {
                    throw new Exception("Child analyzer object must have a service defined.");
                }

                if (!FluentOlapConfiguration.ServiceDefinitions.ContainsKey(expandable.Value.ServiceName))
                {
                    throw new Exception($"Service {expandable.Value.ServiceName} not defined.");
                }

                IService <IServiceInput, IServiceOutput> expandableService = FluentOlapConfiguration.ServiceDefinitions[expandable.Value.ServiceName];

                IServiceInput input = null;

                switch (expandableService.Type)
                {
                case ServiceType.HttpCall:
                    HttpService expandableHttpService       = expandableService as HttpService;
                    IDictionary <string, string> parameters = new Dictionary <string, string>();
                    foreach (string innerParam in expandableHttpService.GetRequiredParameters())
                    {
                        JToken parsedRoot = JToken.Parse(rootResult.Raw);
                        parameters.Add(innerParam, parsedRoot[innerParam].Value <string>());
                    }

                    input = new HttpServiceOptions
                    {
                        PrefixKey  = expandable.Value.NodeName,
                        Parameters = parameters
                    };

                    await expandableHttpService.InvokeAsync((HttpServiceOptions)input);

                    break;
                }

                results.Add(await CallService(expandableService, input));
            }

            return(results);
        }