Ejemplo n.º 1
0
        public async Task <RemoteInvokeResultMessage> SendAsync(CancellationToken cancellationToken)
        {
            var command     = _app.Model;
            var httpMessage = new HttpResultMessage <Object>();

            switch (command.Method.ToLower())
            {
            case "post":
            {
                var formData = command.FormData.ToDictionary();
                if (formData.ContainsKey("type") && formData["type"] == "application/octet-stream")
                {
                    httpMessage = await _httpClientProvider.UploadFileAsync <HttpResultMessage <Object> >(command.Address, command.FormData.ToDictionary(), command.Header.ToDictionary());
                }
                else
                {
                    httpMessage = await _httpClientProvider.PostJsonMessageAsync <HttpResultMessage <Object> >(command.Address, command.Data, command.Header.ToDictionary());
                }
                break;
            }

            case "get":
            {
                httpMessage = await _httpClientProvider.GetJsonMessageAsync <HttpResultMessage <Object> >(command.Address, command.Header.ToDictionary());

                break;
            }

            case "put":
            {
                httpMessage = await _httpClientProvider.PutJsonMessageAsync <HttpResultMessage <Object> >(command.Address, command.Data, command.Header.ToDictionary());

                break;
            }

            case "delete":
            {
                httpMessage = await _httpClientProvider.DeleteJsonMessageAsync <HttpResultMessage <Object> >(command.Address, command.Data, command.Header.ToDictionary());

                break;
            }
            }
            return(new RemoteInvokeResultMessage
            {
                ExceptionMessage = httpMessage.Message,
                Result = httpMessage.Entity,
                StatusCode = httpMessage.StatusCode
            });
        }
Ejemplo n.º 2
0
        public async Task <string> SendAsync(string address, IDictionary <string, object> parameters, HttpContext httpContext)
        {
            var httpMessage = "";

            switch (httpContext.Request.Method)
            {
            case "POST":
            {
                httpMessage = await _httpClientProvider.PostJsonMessageAsync <string>($"{address}{httpContext.Request.QueryString.Value}", _serializer.Serialize(parameters.Values.FirstOrDefault()), httpContext.Request.Headers.ToDictionary(p => p.Key, p => p.Value.ToString()));

                break;
            }

            case "GET":
            {
                httpMessage = await _httpClientProvider.GetJsonMessageAsync <string>($"{address}{httpContext.Request.QueryString.Value}", httpContext.Request.Headers.ToDictionary(p => p.Key, p => p.Value.ToString()));

                break;
            }

            case "PUT":
            {
                httpMessage = await _httpClientProvider.PutJsonMessageAsync <string>($"{address}{httpContext.Request.QueryString.Value}", _serializer.Serialize(parameters), httpContext.Request.Headers.ToDictionary(p => p.Key, p => p.Value.ToString()));

                break;
            }

            case "Delete":
            {
                httpMessage = await _httpClientProvider.DeleteJsonMessageAsync <string>($"{address}{httpContext.Request.QueryString.Value}", _serializer.Serialize(parameters), httpContext.Request.Headers.ToDictionary(p => p.Key, p => p.Value.ToString()));

                break;
            }
            }
            return(httpMessage);
        }