コード例 #1
0
ファイル: ExchangeEvent.cs プロジェクト: lunice/bgo
    void Respond(string resString)
    {
        ExchangeApiResponse response = JsonUtility.FromJson <ExchangeApiResponse>(resString);

        if (response.res == 0)
        {
            //main.addToMyMoney(response.data.Gold - main.money.getValue());
            if (response == null)
            {
                Debug.Log("response == null");
            }
            if (response.data == null)
            {
                Debug.Log("response.data == null");
            }
            if (main.money == null)
            {
                Debug.Log("main.money == null");
            }
            if (main.raffle == null)
            {
                Debug.Log("main.raffle.flyExchengeMoneyToPocket == null");
            }


            HUD.getHUD.flyExchengeMoneyToPocket = response.data.Gold - main.money.getValue();
            main.addToMyRubins(response.data.Crystal - main.rubins.getValue());
            Flickering.set(main.rubins.transform.parent.gameObject, 1.0f, 1);
        }
        else
        {
            Errors.showError(response.res, GameScene.MAIN_MENU);
        }
    }
コード例 #2
0
        /* public const string RESPONSE_GETMARKET = "response_getmarket";
         * public const string RESPONSE_GETOPENORDER = "response_getorderbook";
         * public const string RESPONSE_GETBALANCES = "response_getbalances";
         * public const string RESPONSE_BUYORDER = "response_buyorder";
         * public const string RESPONSE_SELLORDER = "response_sellorder";
         * public const string RESPONSE_CANCELORDER = "response_cancelorder";*/



        public async static Task <ExchangeApiResponse <ApiResponse> > ParseResponse(string exchangeId, ExchangeApiMethodEnum method, HttpResponseMessage httpResponse)
        {
            string         errorMessage = null;
            HttpStatusCode statusCode   = httpResponse.StatusCode;

            if (!httpResponse.IsSuccessStatusCode)
            {
                errorMessage = httpResponse.ReasonPhrase;
                method       = 0;
            }



            var exchangeResponse = new ExchangeApiResponse <ApiResponse>();
            var formObject       = await httpResponse.Content.ReadAsStringAsync();

            JObject res;

            if (!formObject.StartsWith("["))
            {
                res = JObject.Parse(formObject);
                if (res["success"] != null)
                {
                    if (!Boolean.Parse(res["success"].ToString()))
                    {
                        errorMessage = res["message"].ToString();
                        method       = 0;
                    }
                }
            }



            switch (method)
            {
            case ExchangeApiMethodEnum.GetMarket:
                exchangeResponse.Result = GetOrderBookResponse(exchangeId, formObject);
                break;

            case ExchangeApiMethodEnum.GetBalances:
                exchangeResponse.Result = GetBalancesResponse(exchangeId, formObject);
                break;

            case ExchangeApiMethodEnum.GetOpenOrders:
                exchangeResponse.Result = GetOpenOrdersResponse(exchangeId, formObject);
                break;

            case ExchangeApiMethodEnum.PlaceBuyOrder:
                exchangeResponse.Result = PlaceBuyOrderResponse(exchangeId, formObject);
                break;

            case ExchangeApiMethodEnum.PlaceSellOrder:
                exchangeResponse.Result = PlaceSellOrderResponse(exchangeId, formObject);
                break;

            case ExchangeApiMethodEnum.CancelOrder:
                exchangeResponse.Result = CancelOrderResponse(exchangeId, formObject);
                break;

            default:
                break;
            }



            exchangeResponse.StatusCode = statusCode;
            DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond);

            exchangeResponse.Timestamp    = dt;
            exchangeResponse.ErrorMessage = errorMessage;
            //exchangeResponse.Size = responseContent.ToString().Length;

            return(exchangeResponse);
        }