Esempio n. 1
0
        private void RunTheClient()
        {
            IResponse         theResponse = new GenericResponse(false);
            REQUEST_TYPE_ENUM sendThis;

            while (connected)
            {
                OutputClientInfo();
                Console.WriteLine("\nPlease select an option:");
                if (youHaveTheStock)
                {
                    sendThis = StockholderOptions();
                }
                else
                {
                    sendThis = StocklessOptions();
                }

                switch (sendThis)
                {
                case REQUEST_TYPE_ENUM.SEND_INFO:
                    Console.WriteLine("Requesting updated market info. Please wait for the market to update.");
                    theResponse = theConnection.GetInfo();
                    break;

                case REQUEST_TYPE_ENUM.SEND_TRADE:
                    Console.WriteLine("Please enter the ID of the trader you want to give the stock to.");
                    string sendTo = Console.ReadLine();
                    Console.WriteLine($"Sending stock to {sendTo}");
                    theResponse = theConnection.GiveStock(sendTo);
                    break;

                case REQUEST_TYPE_ENUM.SEND_QUIT:
                    Console.WriteLine("bye");
                    connected = false;
                    break;
                }

                if (connected)
                {
                    marketInfo = theResponse.GetMarket();
                    Console.WriteLine(theResponse.GetInfo());
                }
            }
            theConnection.Dispose();
            Console.WriteLine("That's all, folks!");
        }
Esempio n. 2
0
        private ConsoleClient(string hostname, int port)
        {
            theConnection = new ClientConnection(hostname, port);

            Console.WriteLine("Sending connect request");

            ConnectResponse connResponse = theConnection.Connect();

            if (connResponse.success)
            {
                connected  = true;
                id         = connResponse.id;
                marketInfo = connResponse.marketInfo;
                Console.WriteLine("Connected successfully.");
            }
            else
            {
                Console.WriteLine("Connection unsuccessful.");
                Console.WriteLine("Aborting");
                throw new Exception();
            }
        }
Esempio n. 3
0
 public void LogMarketInfo(LoggableMarket market)
 {
     Console.WriteLine($"\nMarket Info:\n{market}\n");
 }