internal OperationResult <T> CallServicePost <R, T>(R request, string method)
        {
            InitializeClient();
            var jsonRequestProcess = serialize.Execute(request);

            if (jsonRequestProcess.Failure)
            {
                return(new OperationResult <T>(jsonRequestProcess.ErrorList));
            }
            HttpContent content = new StringContent(jsonRequestProcess.Result, Encoding.UTF8, "application/json");

            string responseString;
            var    url = Path.Combine(serviceSecurity.Url, method);

            try
            {
                var response = client.PostAsync(url, content).Result;
                responseString = response.Content.ReadAsStringAsync().Result;
            }
            catch (Exception ex)
            {
                return(new OperationResult <T>(ErrorDto.BuildTechnical(ex.Message)));
            }

            return(deserialize.Execute <T>(responseString));
        }
Exemplo n.º 2
0
        private OperationResult <SellOrdersRequestDto> MapAndValidateFileStructure(IEnumerable <string> fileLines)
        {
            if (fileLines == null || fileLines.Count() < 2)
            {
                return(new OperationResult <SellOrdersRequestDto>(ErrorDto.BuildUser("Structure file {0}, is incorrect")));
            }

            var fileProcess = fileLines.ToArray();

            var initialBalance = new InitialBalanceDto();
            var orderList      = new List <OrderDto>();

            for (int i = 0; i < fileProcess.Length; i++)
            {
                if (i == 0)
                {
                    var processInitiBalalance = deserialize.Execute <InitialBalanceJsonDto>(fileProcess[i]);
                    if (processInitiBalalance.Failure)
                    {
                        return(new OperationResult <SellOrdersRequestDto>(processInitiBalalance.ErrorList));
                    }
                    initialBalance = processInitiBalalance.Result.InitialBalance;
                }
                else
                {
                    var processOrder = deserialize.Execute <OrderDto>(fileProcess[i]);
                    if (processOrder.Failure)
                    {
                        return(new OperationResult <SellOrdersRequestDto>(processOrder.ErrorList));
                    }
                    if (processOrder.Result != null)
                    {
                        orderList.Add(processOrder.Result);
                    }
                }
            }



            var response = new SellOrdersRequestDto()
            {
                InitialBalance = initialBalance,
                OrderList      = orderList
            };

            return(new OperationResult <SellOrdersRequestDto>(response));
        }