Exemplo n.º 1
0
        private void consoleKeyPressed(object sender, System.Windows.Input.KeyEventArgs e)
        {
            if (e.Key.ToString() == "Return")
            {
                if (consoleInBox.Text == "clr")
                {
                    consoleOutBox.Text = "";
                    consoleInBox.Text  = "";
                }
                if (consoleInBox.Text != "") // Processing only non-empty strings
                {
                    try
                    {
                        consoleOutBox.Text += ">" + consoleInBox.Text.ToUpper() + "\n";

                        JObject parseResults = JObject.Parse(NetworkClass.serverResponse(consoleInBox.Text));
                        JArray  jsonArray    = (JArray)parseResults.SelectToken("columns");

                        // Saving input for the history reference
                        consoleHistory.Insert(moduloCounter % HISTORY_LIMIT, consoleInBox.Text);
                        moduloCounter++;
                        historyCounter = consoleHistory.Count;

                        // This part of the code properly displays the data in the console window
                        int rowCount = jsonArray.Count;

                        for (int i = 0; i < jsonArray.Count; i++)
                        {
                            if (i == 0)
                            {
                                consoleOutBox.Text += jsonArray[i].ToString() + "\t\t\t";
                            }
                            else
                            {
                                consoleOutBox.Text += jsonArray[i].ToString() + "\t\t\t";
                            }
                        }

                        jsonArray           = (JArray)parseResults.SelectToken("points");
                        consoleOutBox.Text += "\n";

                        for (int i = 0; i < jsonArray.Count; i++)
                        {
                            for (int j = 0; j < rowCount; j++)
                            {
                                if (j == 0)
                                {
                                    consoleOutBox.Text += PlottingClass.UnixTimeConverter(Convert.ToDouble(jsonArray[i][j].ToString())).ToString() + "\t\t\t";
                                }
                                else
                                {
                                    consoleOutBox.Text += jsonArray[i][j].ToString() + "\t\t\t";
                                }
                            }

                            consoleOutBox.Text += "\n";
                        }

                        consoleOutBox.Text += "\n";
                        consoleInBox.Text   = "";
                    }
                    catch (Exception)
                    {
                        consoleOutBox.Text += "UNRECOGNIZED COMMAND\n\n";

                        // Saving input for the history reference
                        consoleHistory.Insert(moduloCounter % HISTORY_LIMIT, consoleInBox.Text);
                        moduloCounter++;
                        historyCounter    = consoleHistory.Count;
                        consoleInBox.Text = "";
                    }
                }
            }
        }