public void GetPreparationTime(string wsAddress, ResponseMessageData <StoreModel> response)
        {
            using (var client = new CustomerOrderClient(new BasicHttpBinding(), new EndpointAddress(wsAddress + SettingsData.Constants.StoreOrder.WsCustomerOrder)))
            {
                var iTries = 0;
                while (iTries < 3)
                {
                    try
                    {
                        var result = client.GetPreparationTime();
                        if (response.IsSuccess)
                        {
                            response.IsSuccess = true;
                            response.Message   = String.Format("Entrega {0} mins", result.PrepTime);
                            return;
                        }

                        response.IsSuccess = false;
                        response.Message   = result.ExcMsg;
                        return;
                    }
                    catch (Exception ex)
                    {
                        SharedLogger.LogError(ex);
                    }
                    Thread.Sleep(new Random().Next(50, 300));
                    iTries++;
                }

                client.Close();

                response.IsSuccess = false;
                response.Message   = "No fue posible comunicarse a la sucursal para obtener el tiempo de preparación ";
            }
        }
        private bool StoreIsAlive(OrderModelDto model)
        {
            var iTries = 2;

            using (var client = new CustomerOrderClient(new BasicHttpBinding(), new EndpointAddress(model.Store.WsAddress + SettingsData.Constants.StoreOrder.WsCustomerOrder)))
            {
                while (iTries > 0)
                {
                    try
                    {
                        var result = client.Ping();
                        if (result == SettingsData.Constants.StoreConst.STORE_RESPONSE_PING_WS_OK)
                        {
                            return(true);
                        }
                        iTries--;
                    }
                    catch (Exception)
                    {
                        iTries--;
                    }
                }

                client.Close();
            }
            return(false);
        }
        private static ResponseRd SendOrderToStore(OrderModelDto model, IHubCallerConnectionContext <dynamic> clients, CustomerOrder.Order order)
        {
            using (var client = new CustomerOrderClient(new BasicHttpBinding(), new EndpointAddress(model.Store.WsAddress + SettingsData.Constants.StoreOrder.WsCustomerOrder)))
            {
                var iTries = 0;
                while (iTries < 3)
                {
                    try
                    {
                        var result = client.AddOrder(order);
                        if (result.IsSuccess && result.Order.orderIdField.IsValidId())
                        {
                            clients.Caller.OnSendToStoreEventChange(new ResponseMessage
                            {
                                Code      = SettingsData.Constants.StoreConst.STORE_RESPONSE_CALL_WS_SUCCESS,
                                IsSuccess = true,
                                Message   = String.Format("Pedido (ATO ID {0}) enviado de forma exitosa", result.Order.orderIdField)
                            });
                            client.Close();
                            return(result);
                        }

                        var resultOrderId = result.IsSuccess ? result.Order.orderIdField : "ND";

                        SharedLogger.LogError(new Exception(
                                                  String.Format("SendOrderToStore: {0} | {1} | {2} | {3} | {4}", result.IsSuccess, result.ErrMsg, result.ResultCode, result.ResultData))
                                              , model.PosOrder, model.Store, model.Phone, model.OrderDetails, model.OrderToStoreId, resultOrderId);
                    }
                    catch (Exception ex)
                    {
                        SharedLogger.LogError(ex);
                        clients.Caller.OnSendToStoreEventChange(new ResponseMessage
                        {
                            Code      = SettingsData.Constants.StoreConst.STORE_RESPONSE_CALL_WS_ERROR,
                            IsSuccess = false,
                            Message   = String.Format("Intento {0} fallido. Error: {1}", (iTries + 1), ex.Message)
                        });
                    }
                    Thread.Sleep(1000);
                    iTries++;
                }

                client.Close();
            }

            return(null);
        }