Пример #1
0
        private async void buyShoppingBasketHandler(JObject msgObj, string message)
        {
            JsonResponse response;
            string       purchaseInfo = null;
            int          month = -1, year = -1, ccv = -1, id = -1;
            string       cardNumber = null, holder = null, name = null, address = null, city = null, country = null, zip = null;
            int          requestId = (int)msgObj["id"];

            //{int cardNumber, int month,int year, string holder, int ccv, int id, string name, string address, string city, string country, string zip}
            try
            {
                cardNumber = (string)msgObj["data"]["cardNumber"];
                month      = (int)msgObj["data"]["month"];
                year       = (int)msgObj["data"]["year"];
                holder     = (string)msgObj["data"]["holder"];
                ccv        = (int)msgObj["data"]["cvv"];
                id         = (int)msgObj["data"]["id"];
                name       = (string)msgObj["data"]["name"];
                address    = (string)msgObj["data"]["address"];
                city       = (string)msgObj["data"]["city"];
                country    = (string)msgObj["data"]["country"];
                zip        = (string)msgObj["data"]["zip"];
            }
            catch (WorkShopDbException dbExc)
            {
                response = JsonResponse.generateActionError(requestId, "DB is down please try again in few minutes\n" + dbExc.Message);
                //Console.WriteLine("F 5");
            }
            catch (Exception e)
            {
                Logger.Log("error", logLevel.ERROR, "can't parse info from server");
                response = JsonResponse.generateActionError(requestId, "can't parse the input please check the legality of your input");
                sendMyselfAMessage(JsonHandler.SerializeObject(response));
                //Console.WriteLine("F 4" + e.Message);
                return;
            }

            try
            {
                purchaseInfo = await user.BuyShoppingBasket(cardNumber, month, year, holder, ccv, id, name, address, city, country, zip);

                var x = new { data = "purchase succeeded:\n" + purchaseInfo };
                response = JsonResponse.generateActionSucces(requestId, JsonHandler.SerializeObject(x));

                /*var purchaseInfoNotificaiton = new { type = "notification", info = "message", data = purchaseInfo, requestId = -1 };
                 * purchaseInfo = JsonHandler.SerializeObject(purchaseInfoNotificaiton);*/
                //Console.WriteLine("T");
            }
            catch (WorkShopDbException dbExc)
            {
                response = JsonResponse.generateActionError(requestId, "DB is down please try again in few minutes\n" + dbExc.Message);
                //Console.WriteLine("F 1");
            }
            catch (Exception e)
            {
                response = JsonResponse.generateActionError(requestId, e.Message);
                //Console.WriteLine("F 2");
            }

            sendMyselfAMessage(JsonHandler.SerializeObject(response));

            /* for (int i = 0; i < 10_000; i++) ;
             * if (purchaseInfo != null)
             *   sendMyselfAMessage(purchaseInfo);*/
        }