Ejemplo n.º 1
0
        public static void cancelRequestAction()
        {
            Console.WriteLine("please enter the Id of the request you want to cancel");
            string Id = Console.ReadLine();
            int    id = ezer(Id);

            while (id == -1)
            {
                Id = Console.ReadLine();
                id = ezer(Id);
            }
            DAL.MarketClient m = new DAL.MarketClient();
            try
            {
                m.SendCancelBuySellRequest(id);
            }
            catch (DAL.Utils.MarketException mx)
            {
                Console.WriteLine(mx.Message.ToString());
            }
            catch (AggregateException ax)
            {
                Console.WriteLine("The server isn't working at the momment, please try again later");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Canceles a buy/sell by refunding commodity/funds.
        /// </summary>
        public static void cancelRequestAction()
        {
            Console.WriteLine("> Please enter the Id of the request you wish to cancel:");
            string Id = Console.ReadLine();
            int    id = inputCheck1(Id);

            if (id == -1)
            {
                return;
            }

            DAL.MarketClient m = new DAL.MarketClient();
            try
            {
                m.SendCancelBuySellRequest(id);
            }
            catch (DAL.Utils.MarketException mx)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(mx.Message.ToString());
                Console.ResetColor();
            }
            catch (AggregateException ax)
            {
                ServerCrashError();
            }
        }
Ejemplo n.º 3
0
        public static void sellAction()
        {
            Console.WriteLine("please enter the commodity Id");
            string commodityInput = Console.ReadLine();
            int    commodity      = ezer(commodityInput);

            while (commodity == -1)
            {
                commodityInput = Console.ReadLine();
                commodity      = ezer(commodityInput);
            }

            Console.WriteLine("please enter the amount");
            string amountInput = Console.ReadLine();
            int    amount      = ezer(amountInput);

            while (amount == -1)
            {
                amountInput = Console.ReadLine();
                amount      = ezer(amountInput);
            }

            Console.WriteLine("please enter the price");
            string priceInput = Console.ReadLine();
            int    price      = ezer(priceInput);

            while (price == -1)
            {
                priceInput = Console.ReadLine();
                price      = ezer(priceInput);
            }

            DAL.MarketClient m = new DAL.MarketClient();
            try
            {
                m.SendSellRequest(price, commodity, amount);
            }
            catch (DAL.Utils.MarketException mx)
            {
                Console.WriteLine(mx.Message.ToString());
            }
            catch (AggregateException ax)
            {
                Console.WriteLine("The server isn't working at the momment, please try again later");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sends a requet to purchase given amount of commodity for given price.
        /// </summary>
        public static void buyAction()
        {
            Console.WriteLine("> Please enter the commodity Id:");
            string commodityInput = Console.ReadLine();
            int    commodity      = inputCheck2(commodityInput);

            if (commodity == -1)
            {
                return;
            }

            Console.WriteLine("> Please enter the amount:");
            string amountInput = Console.ReadLine();
            int    amount      = inputCheck1(amountInput);

            if (amount == -1)
            {
                return;
            }

            Console.WriteLine("> Please enter the price:");
            string priceInput = Console.ReadLine();
            int    price      = inputCheck1(priceInput);

            if (price == -1)
            {
                return;
            }

            DAL.MarketClient m = new DAL.MarketClient();
            try
            {
                m.SendBuyRequest(price, commodity, amount);
            }
            catch (DAL.Utils.MarketException mx)
            {
                Console.WriteLine(mx.Message.ToString());
            }
            catch (AggregateException ax)
            {
                ServerCrashError();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Describes user information, including inventory, funds and active request ID's description.
        /// </summary>
        public static void userRequestAction()
        {
            DAL.MarketClient m = new DAL.MarketClient();
            DAL.DataEntries.IMarketUserData info = new DAL.DataEntries.MarketUserData();
            bool flag = true;

            try
            {
                info = m.SendQueryUserRequest();
            }
            catch (AggregateException ax)
            {
                ServerCrashError();
                flag = false;
            }

            if (flag)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Dictionary <string, int> dic = info.getCommodities();
                Console.WriteLine("You have the following commodities:");

                for (int i = 0; i < dic.Count; i++)
                {
                    Console.WriteLine("* The amount of commodities with the Id of " + dic.Keys.ElementAt(i) + " is " + dic[dic.Keys.ElementAt(i)]);
                }
                Console.WriteLine("You have " + info.getFunds() + " funds.");
                List <int> requests = info.getRequests();
                Console.WriteLine("Your requests Id's are: ");
                for (int i = 0; i < requests.Count; i++)
                {
                    Console.Write(requests.ElementAt(i));
                    if (i < requests.Count - 1)
                    {
                        Console.Write(",");
                    }
                }
                Console.ResetColor();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Offers best Bid price and best Ask price for a given commodity.
        /// </summary>
        public static void marketRequestAction()
        {
            Console.WriteLine("> Please enter the commodity Id:");
            string commodityInput = Console.ReadLine();
            int    commodity      = inputCheck2(commodityInput);

            if (commodity == -1)
            {
                return;
            }

            DAL.MarketClient m = new DAL.MarketClient();
            DAL.DataEntries.IMarketCommodityOffer info = new DAL.DataEntries.MarketCommodityOffer();

            bool flag = true;

            try
            {
                info = m.SendQueryMarketRequest(commodity);
            }
            catch (DAL.Utils.MarketException mx)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(mx.Message.ToString());
                Console.ResetColor();
                flag = false;
            }
            catch (AggregateException ax)
            {
                ServerCrashError();
                flag = false;
            }
            if (flag)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("The best bid price is: " + info.getBestBidPrice() + ", the best ask price is: " + info.getBestAskPrice());
                Console.ResetColor();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Describes a Sell/Purchase by given request id.
        /// </summary>
        public static void sellBuyAction()
        {
            Console.WriteLine("> Please enter the Id of the request you wish to see information of:");
            string Id = Console.ReadLine();
            int    id = inputCheck1(Id);

            if (id == -1)
            {
                return;
            }

            DAL.MarketClient m = new DAL.MarketClient();
            DAL.DataEntries.IMarketItemQuery info = new DAL.DataEntries.MarketItemQuery();

            bool flag = true;

            try
            {
                info = m.SendQueryBuySellRequest(id);
            }
            catch (DAL.Utils.MarketException mx)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(mx.Message.ToString());
                Console.ResetColor();
                flag = false;
            }
            catch (AggregateException ax)
            {
                ServerCrashError();
                flag = false;
            }
            if (flag)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("The user that sent the request is " + info.getUser() + ", the request's type is " + info.getType() + ", the request's commodity id is " + info.getCommodity() + ", the request's price is " + info.getPrice() + ", the request's amount is " + info.getAmount());
                Console.ResetColor();
            }
        }
Ejemplo n.º 8
0
        public static void userRequestAction()
        {
            DAL.MarketClient m = new DAL.MarketClient();
            DAL.DataEntries.IMarketUserData info = new DAL.DataEntries.MarketUserData();
            bool flag = true;

            try
            {
                info = m.SendQueryUserRequest();
            }
            catch (AggregateException ax)
            {
                Console.WriteLine("The server isn't working at the momment, please try again later");
                flag = false;
            }

            if (flag)
            {
                Dictionary <string, int> dic = info.getCommodities();
                Console.WriteLine("You have the following commodities: ");

                for (int i = 0; i < dic.Count; i++)
                {
                    Console.WriteLine("The amount of commodities with the Id " + dic.Keys.ElementAt(i) + " is " + dic[dic.Keys.ElementAt(i)]);
                }
                Console.WriteLine("you have " + info.getFunds() + " funds.");
                List <int> requests = info.getRequests();
                Console.WriteLine("Your requestes's id are: ");
                for (int i = 0; i < requests.Count; i++)
                {
                    Console.Write(requests.ElementAt(i));
                    if (i < requests.Count - 1)
                    {
                        Console.Write(",");
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public static void sellBuyAction()
        {
            Console.WriteLine("please enter the Id of the request you want to see information about");
            string Id = Console.ReadLine();
            int    id = ezer(Id);

            while (id == -1)
            {
                Id = Console.ReadLine();
                id = ezer(Id);
            }


            DAL.MarketClient m = new DAL.MarketClient();
            DAL.DataEntries.IMarketItemQuery info = new DAL.DataEntries.MarketItemQuery();

            bool flag = true;

            try
            {
                info = m.SendQueryBuySellRequest(id);
            }
            catch (DAL.Utils.MarketException mx)
            {
                Console.WriteLine(mx.Message.ToString());
                flag = false;
            }
            catch (AggregateException ax)
            {
                Console.WriteLine("The server isn't working at the momment, please try again later");
                flag = false;
            }
            if (flag)
            {
                Console.WriteLine("The user that sent the request is: " + info.getUser() + ", the request's type is " + info.getType() + ", the request's commodity id is " + info.getCommodity() + ", the request's price is " + info.getPrice() + ", the request's amount is " + info.getAmount());
            }
        }
Ejemplo n.º 10
0
        public static void marketRequestAction()
        {
            Console.WriteLine("please enter the commodity Id");
            string commodityInput = Console.ReadLine();
            int    commodity      = ezer(commodityInput);

            while (commodity == -1)
            {
                commodityInput = Console.ReadLine();
                commodity      = ezer(commodityInput);
            }

            DAL.MarketClient m = new DAL.MarketClient();
            DAL.DataEntries.IMarketCommodityOffer info = new DAL.DataEntries.MarketCommodityOffer();

            bool flag = true;

            try
            {
                info = m.SendQueryMarketRequest(commodity);
            }
            catch (DAL.Utils.MarketException mx)
            {
                Console.WriteLine(mx.Message.ToString());
                flag = false;
            }
            catch (AggregateException ax)
            {
                Console.WriteLine("The server isn't working at the momment, please try again later");
                flag = false;
            }
            if (flag)
            {
                Console.WriteLine("the best bid price is: " + info.getBestBidPrice() + ", the best ask price is: " + info.getBestAskPrice());
            }
        }