Exemple #1
0
        /// <summary>Starts and runs the shell, waiting for commands and executing them, until it exits.</summary>
        /// <param name="arguments">Argument line provided with the shell invocation in the parent program or shell.</param>
        public void Run(IList <string> arguments)
        {
            isRunning = true;
            Initialize(arguments);

            while (isRunning)
            {
                Output.Write(Prompt);

                try
                {
                    commandInterpreter.ExecuteCommand(Input.ReadLine());
                }
                catch (Exception exception)
                {
                    if (exception is TargetInvocationException)
                    {
                        exception = exception.InnerException;
                    }
                    WriteError(exception);
                }

                Output.Write(Separator);
            }
        }
Exemple #2
0
 private void ServerService()
 {
     _tcpListener.Start();
     Socket = _tcpListener.AcceptSocket();
     try
     {
         Stream = new NetworkStream(Socket);
         var buffer = new byte[1024];
         var commandInterpreter = new CommandInterpreter();
         while (true)
         {
             if (!Stream.DataAvailable) continue;
             var bytesRead = Stream.Read(buffer, 0, buffer.Length);
             var receivedMessage = Encoding.UTF8.GetString(buffer, 0, bytesRead);
             if (commandInterpreter.ExecuteCommand(receivedMessage))
             {
                 MessageBox.Show("Remote Client Disconnected");
                 break;
             }
         }
         Stream.Close();
         _tcpListener.Stop();
     }
     catch (Exception e)
     {
         MessageBox.Show("Something went wrong with the connection " + e.Message);
     }
 }
        public static void Main()
        {
            var dataStructure = new GenericDataStructure <string>();

            var command = new CommandInterpreter(dataStructure);

            command.ExecuteCommand();
        }
 private void SubmitInput(string text)
 {
     if (!text.Contains("~"))
     {
         string response    = CommandInterpreter.ExecuteCommand(text);
         string currentText = output.text;
         string newText     = response;
         //string newText = currentText + "\n" + response;
         output.text = newText;
     }
     inField.text = "";
     PauseManager.UnPauseGame();
     manager.deactivateOut();
     gameObject.SetActive(false);
 }
Exemple #5
0
        //--------------- Methods ------------------
        public void Run()
        {
            string[] carData   = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            string[] truckData = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            string[] busData   = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

            try
            {
                Vehicle car   = new Car(double.Parse(carData[1]), double.Parse(carData[2]), double.Parse(carData[3]));
                Vehicle truck = new Truck(double.Parse(truckData[1]), double.Parse(truckData[2]), double.Parse(truckData[3]));
                Vehicle bus   = new Bus(double.Parse(busData[1]), double.Parse(busData[2]), double.Parse(busData[3]));
                this.vehicles.Add(car);
                this.vehicles.Add(truck);
                this.vehicles.Add(bus);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }

            int n = int.Parse(Console.ReadLine());

            while (n-- > 0)
            {
                string[] args    = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string   command = args[0];

                try
                {
                    commandInterpreter.ExecuteCommand(command, args, vehicles);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            Console.WriteLine(String.Join(Environment.NewLine, this.vehicles));
        }
Exemple #6
0
 private void ClientService()
 {
     try
     {
         Stream = _tcpClient.GetStream();
         var buffer = new byte[1024];
         var commandInterpreter = new CommandInterpreter();
         while (true)
         {
             if (!Stream.DataAvailable) continue;
             var bytesRead = Stream.Read(buffer, 0, buffer.Length);
             var receivedMessage = Encoding.UTF8.GetString(buffer, 0, bytesRead);
             commandInterpreter.ExecuteCommand(receivedMessage);
         }
     }
     catch (Exception e)
     {
         MessageBox.Show("Something went wrong with the client connection:" + e.Message);
     }
     finally
     {
         _tcpClient.Close();
     }
 }
Exemple #7
0
        private void ServerService()
        {
            try
            {
                _tcpListener.Start();
                _tcpClient = _tcpListener.AcceptTcpClient();
                Stream = _tcpClient.GetStream();
                var commandInterpreter = new CommandInterpreter();
                var connectValidation = true;
                while (true)
                {
                    if (connectValidation)
                    {
                        Common.GameBoardController.ConnectionEstablished();
                        connectValidation = false;
                        _isConnected = true;
                    }

                    var streamReader = new StreamReader(Stream);
                    var receivedMessage = streamReader.ReadLine();

                    if (commandInterpreter.ExecuteCommand(receivedMessage))
                    {
                        _isConnected = false;
                        MessageBox.Show(@"Oponent bailed!");
                        break;
                    }
                }
                Stream.Close();
                _tcpListener.Stop();
            }
            catch (Exception exception)
            {
                MessageBox.Show(@"Connection Error: " + exception.Message);
            }
        }