private void btnRefresh_Click(object sender, EventArgs e)
        {
            btnRefresh.Enabled = false; //prevent spam

              Configuration config = new Configuration();

              string[] connections = config.Read();

              string error = "";

              List<MessageFormat> messages = new List<MessageFormat>();
              List<string> localNames = new List<string>();

              foreach (MessageFormat m in localMessages)
                  localNames.Add(m.Name);

              messages.AddRange(companyMessages);

              foreach (MessageFormat m in messages)
                  RemoveMessageFormat(m);

              messages = new List<MessageFormat>();

              foreach (string connection in connections)
                  messages.AddRange(new SqlMessageConnection(connection).GetMessageList());
              foreach (MessageFormat m in messages)
              {
                  AddMessageFormat(m, MessageType.Company);
                  if (localNames.Contains(m.Name))
                  {
                      MessageFormat dupe = localMessages.Find(d => d.Name == m.Name);
                      error += dupe.ToString() + '\n';
                      RemoveMessageFormat(dupe);
                  }
              }

              if (error != "")
                  MessageBox.Show("The following local messages were removed because they share a name with a company message:\n\n" + error);

              btnRefresh.Enabled = true;
        }
        public MainForm()
        {
            InitializeComponent();

               lstDisplayWindowTwo.Visible = false;
               listBoxOneSelected = true;
               comPortConfigForm = null;
               dataProcessor = new DataProcessor(this);
               lstMessageSummary.Sorted = true;
               cmbViews.Items.Add(ALL_MESSAGES);
               cmbViews.Sorted = true;
               cmbViews.SelectedIndex = 0;
               recordedMessages = new List<String>();

               initialized = false;
               stopReceiving = false;
               this.comPortName = "--";
               this.baudRate = DEFAULT_BAUD_RATE;
               this.parity = DEFAULT_PARITY;
               this.dataBits = DEFAULT_DATA_BITS;
               this.stopBits = DEFAULT_STOP_BITS;
               this.handshake = DEFAULT_HANDSHAKE;
               this.rtsEnable = DEFAULT_RTS;
               this.dtrEnable = DEFAULT_DTR;

               lblvPortName.Text = this.comPortName;
               lblvBaudRate.Text = this.baudRate.ToString();
               lblvParity.Text = this.parity.ToString();
               lblvDataBits.Text = this.dataBits.ToString();
               lblvStopBits.Text = this.stopBits.ToString();
               lblvHandshake.Text = this.handshake.ToString();
               lblvRTSEnable.Text = this.rtsEnable.ToString();
               lblvDTREnable.Text = this.dtrEnable.ToString();

               btnOpenAndClose.BackColor = Color.Red;
               btnOpenAndClose.Text = "Closed";
               comPortClosed = true;

               availableComPortNames = FindAvailableComPorts();

               if(availableComPortNames.Count > 0)
                    OpenComPort(availableComPortNames.ElementAt<String>(0), DEFAULT_BAUD_RATE, DEFAULT_PARITY, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_HANDSHAKE, DEFAULT_RTS, DEFAULT_DTR);

               Configuration config = new Configuration();

               string[] connections = config.Read();

              if (!config.IsAdministrator)
                  btnAddCompanyMessage.Enabled = false;
              else
                  isAdministrator = true;

               string errors = "";
               List<MessageFormat> messages = new List<MessageFormat>();
               foreach (string connection in connections)
               {
                   SqlMessageConnection sql = new SqlMessageConnection(connection);

                   if (sql.isConnected())
                       messages.AddRange(sql.GetMessageList());
                   else
                   {
                       try
                       {
                           errors += connection.Split(';')[0] + ';' + connection.Split(';')[1] + ';' + connection.Split(';')[2] + ";Table=" + connection.Split(';')[4] + '\n';
                       }
                       catch { }
                   }
               }

               if (errors != "")
                   MessageBox.Show("The following SQL connections could not be opened:\n\n" + errors);

               foreach (MessageFormat m in messages)
                   AddMessageFormat(m, MessageType.Company);

              initialized = true;
        }
        public MainForm()
        {
            InitializeComponent();

            lstDisplayWindowTwo.Visible = false;
            listBoxOneSelected          = true;
            comPortConfigForm           = null;
            dataProcessor            = new DataProcessor(this);
            lstMessageSummary.Sorted = true;
            cmbViews.Items.Add(ALL_MESSAGES);
            cmbViews.Sorted        = true;
            cmbViews.SelectedIndex = 0;
            recordedMessages       = new List <String>();

            initialized      = false;
            stopReceiving    = false;
            this.comPortName = "--";
            this.baudRate    = DEFAULT_BAUD_RATE;
            this.parity      = DEFAULT_PARITY;
            this.dataBits    = DEFAULT_DATA_BITS;
            this.stopBits    = DEFAULT_STOP_BITS;
            this.handshake   = DEFAULT_HANDSHAKE;
            this.rtsEnable   = DEFAULT_RTS;
            this.dtrEnable   = DEFAULT_DTR;

            lblvPortName.Text  = this.comPortName;
            lblvBaudRate.Text  = this.baudRate.ToString();
            lblvParity.Text    = this.parity.ToString();
            lblvDataBits.Text  = this.dataBits.ToString();
            lblvStopBits.Text  = this.stopBits.ToString();
            lblvHandshake.Text = this.handshake.ToString();
            lblvRTSEnable.Text = this.rtsEnable.ToString();
            lblvDTREnable.Text = this.dtrEnable.ToString();

            btnOpenAndClose.BackColor = Color.Red;
            btnOpenAndClose.Text      = "Closed";
            comPortClosed             = true;

            availableComPortNames = FindAvailableComPorts();

            if (availableComPortNames.Count > 0)
            {
                OpenComPort(availableComPortNames.ElementAt <String>(0), DEFAULT_BAUD_RATE, DEFAULT_PARITY, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_HANDSHAKE, DEFAULT_RTS, DEFAULT_DTR);
            }

            Configuration config = new Configuration();

            string[] connections = config.Read();

            if (!config.IsAdministrator)
            {
                btnAddCompanyMessage.Enabled = false;
            }
            else
            {
                isAdministrator = true;
            }

            string errors = "";
            List <MessageFormat> messages = new List <MessageFormat>();

            foreach (string connection in connections)
            {
                SqlMessageConnection sql = new SqlMessageConnection(connection);

                if (sql.isConnected())
                {
                    messages.AddRange(sql.GetMessageList());
                }
                else
                {
                    try
                    {
                        errors += connection.Split(';')[0] + ';' + connection.Split(';')[1] + ';' + connection.Split(';')[2] + ";Table=" + connection.Split(';')[4] + '\n';
                    }
                    catch { }
                }
            }

            if (errors != "")
            {
                MessageBox.Show("The following SQL connections could not be opened:\n\n" + errors);
            }

            foreach (MessageFormat m in messages)
            {
                AddMessageFormat(m, MessageType.Company);
            }

            initialized = true;
        }
        /// <summary>
        /// Reads all relevant configuration files. The default file is config.xml in the current directory.
        /// </summary>
        /// <returns>Returns an array of connection strings with the table name concatenated at the end.</returns>
        public string[] Read()
        {
            XmlReader reader = XmlReader.Create(filename);
            bool      flag   = true;

            while (reader.Read() && flag)
            {
                if (!reader.IsStartElement())
                {
                    continue;
                }

                switch (reader.Name)
                {
                case "file":
                    Configuration config = new Configuration(reader.ReadInnerXml());
                    config.Read();
                    Connection[] conn = config.connections;

                    foreach (Connection c in conn)
                    {
                        if (c == null)
                        {
                            break;
                        }
                        count++;
                        if (count > CONNECTION_LIMIT)
                        {
                            flag = false;
                            break;
                        }

                        connections[count] = c;
                    }
                    break;

                case "admin":
                    isAdmin = (reader.ReadInnerXml() == "true" ? true : false);
                    break;

                case "connection":
                    count++;

                    if (count > CONNECTION_LIMIT)
                    {
                        flag = false;
                        break;
                    }
                    connections[count] = new Connection();
                    break;

                case "source":
                    connections[count].source = reader.ReadInnerXml();
                    break;

                case "catalog":
                    connections[count].catalog = reader.ReadInnerXml();
                    break;

                case "table":
                    connections[count].table = reader.ReadInnerXml();
                    break;

                case "user":
                    connections[count].user = reader.ReadInnerXml();
                    break;

                case "password":
                    connections[count].password = reader.ReadInnerXml();
                    break;

                case "config":
                    break;

                default:
                    Console.WriteLine("Configuration defaulted and received the node " + reader.Name + ".");
                    break;
                }
            }

            string[] s = new string[count + 1];

            for (int i = 0; i <= count; i++)
            {
                s[i] = connections[i].getConnectionString();
            }

            return(s);
        }
        private void reset()
        {
            txtVersion1.Text = "01";
            txtVersion2.Text = "00";
            txtID1.Text = "00";
            txtID2.Text = "00";
            txtLength.Text = "00";
            txtName.Text = "";
            txtFormat.Text = "";
            cmbGroup.SelectedIndex = 0;
            cmbCount.SelectedIndex = 0;
            cmbType.SelectedIndex = 0;
            cmbFormat.SelectedIndex = 3;
            cmbUniformFormat.SelectedIndex = 1;
            cmbUniformGroup.SelectedIndex = 0;
            cmbFormatType.SelectedIndex = 0;

            pnlCustomFormat.Location = new Point(271, 135);
            pnlExternalProgram.Location = new Point(271, 135);
            pnlUniformGroup.Location = new Point(271, 135);

            pnlCustomFormat.Hide();
            pnlExternalProgram.Hide();
            pnlUniformGroup.Show();

            lstFormats.Items.Clear();
            txtExternalFile.Text = "";

            cmbConnections.Items.Clear();
            cmbConnections.Hide();
            lblConnection.Hide();

            if (parentForm.IsAdministrator && msgType == MessageType.Company)
            {
                Configuration config = new Configuration();

                string[] connections = config.Read();

                foreach (string connection in connections)
                    cmbConnections.Items.Add(new Connection(connection));

                if (cmbConnections.Items.Count == 1)
                    cmbConnections.SelectedIndex = 0;

                lblConnection.Show();
                cmbConnections.Show();
            }
        }
        private void reset()
        {
            if (msgType == MessageType.Company)
                txtID.Text = "8000";
            else
                txtID.Text = "0000";
            txtLength.Text = "00";
            txtName.Text = "";
            txtFormat.Text = "";
            cmbGroup.SelectedIndex = 0;
            cmbCount.SelectedIndex = 0;
            cmbFormat.SelectedIndex = 2;
            cmbSigned.SelectedIndex = 0;
            cmbUniformSigned.SelectedIndex = 0;
            cmbUniformFormat.SelectedIndex = 2;
            cmbUniformGroup.SelectedIndex = 0;
            cmbFormatType.SelectedIndex = 0;

            cmbUniformSigned.Hide();
            lblUniformSigned.Hide();
            cmbSigned.Hide();
            lblUniformSigned.Hide();

            lblIdError1.Visible = false;
            lblIdError2.Visible = false;
            lblIdError3.Visible = false;
            lblNameError1.Visible = false;
            lblNameError2.Visible = false;
            lblLengthError.Visible = false;
            lblCompanyError1.Visible = false;
            lblCompanyError2.Visible = false;
            lblCustomError.Visible = false;

            Point controlPoint = new Point(CONTROLX, CONTROLY);
            pnlCustomFormat.Location = controlPoint;
            pnlExternalProgram.Location = controlPoint;
            pnlUniformGroup.Location = controlPoint;

            bytes = 0;
            bytes_used = 0;

            pnlCustomFormat.Hide();
            pnlExternalProgram.Hide();
            pnlUniformGroup.Show();

            lstFormats.Items.Clear();
            txtExternalFile.Text = "";

            cmbConnections.Items.Clear();
            cmbConnections.Hide();
            lblConnection.Hide();

            UpdateControls();

            if (parentForm.IsAdministrator && msgType == MessageType.Company)
            {
                Configuration config = new Configuration();

                string[] connections = config.Read();

                foreach (string connection in connections)
                    cmbConnections.Items.Add(new Connection(connection));

                if (cmbConnections.Items.Count == 1)
                    cmbConnections.SelectedIndex = 0;

                lblConnection.Show();
                cmbConnections.Show();
            }

            editIndex = -1;
        }
        private void reset()
        {
            if (msgType == MessageType.Company)
            {
                txtID.Text = "8000";
            }
            else
            {
                txtID.Text = "0000";
            }
            txtLength.Text                 = "00";
            txtName.Text                   = "";
            txtFormat.Text                 = "";
            cmbGroup.SelectedIndex         = 0;
            cmbCount.SelectedIndex         = 0;
            cmbFormat.SelectedIndex        = 2;
            cmbSigned.SelectedIndex        = 0;
            cmbUniformSigned.SelectedIndex = 0;
            cmbUniformFormat.SelectedIndex = 2;
            cmbUniformGroup.SelectedIndex  = 0;
            cmbFormatType.SelectedIndex    = 0;

            cmbUniformSigned.Hide();
            lblUniformSigned.Hide();
            cmbSigned.Hide();
            lblUniformSigned.Hide();

            lblIdError1.Visible      = false;
            lblIdError2.Visible      = false;
            lblIdError3.Visible      = false;
            lblNameError1.Visible    = false;
            lblNameError2.Visible    = false;
            lblLengthError.Visible   = false;
            lblCompanyError1.Visible = false;
            lblCompanyError2.Visible = false;
            lblCustomError.Visible   = false;

            Point controlPoint = new Point(CONTROLX, CONTROLY);

            pnlCustomFormat.Location    = controlPoint;
            pnlExternalProgram.Location = controlPoint;
            pnlUniformGroup.Location    = controlPoint;

            bytes      = 0;
            bytes_used = 0;

            pnlCustomFormat.Hide();
            pnlExternalProgram.Hide();
            pnlUniformGroup.Show();

            lstFormats.Items.Clear();
            txtExternalFile.Text = "";

            cmbConnections.Items.Clear();
            cmbConnections.Hide();
            lblConnection.Hide();

            UpdateControls();

            if (parentForm.IsAdministrator && msgType == MessageType.Company)
            {
                Configuration config = new Configuration();

                string[] connections = config.Read();

                foreach (string connection in connections)
                {
                    cmbConnections.Items.Add(new Connection(connection));
                }

                if (cmbConnections.Items.Count == 1)
                {
                    cmbConnections.SelectedIndex = 0;
                }

                lblConnection.Show();
                cmbConnections.Show();
            }

            editIndex = -1;
        }
        /// <summary>
        /// Reads all relevant configuration files. The default file is config.xml in the current directory.
        /// </summary>
        /// <returns>Returns an array of connection strings with the table name concatenated at the end.</returns>
        public string[] Read()
        {
            XmlReader reader = null;
            try { reader = XmlReader.Create(filename); }
            catch { }
            bool flag = true;
            if (reader != null)
            while (reader.Read() && flag)
            {
                if (!reader.IsStartElement())
                    continue;

                switch (reader.Name)
                {
                    case "file":
                        Configuration config = new Configuration(reader.ReadInnerXml());
                        config.Read();
                        Connection[] conn = config.connections;

                        foreach (Connection c in conn)
                        {
                            if (c == null)
                                break;
                            count++;
                            if (count > CONNECTION_LIMIT)
                            {
                                flag = false;
                                break;
                            }

                            connections[count] = c;
                        }
                        break;
                    case "admin":
                        isAdmin = (reader.ReadInnerXml() == "true" ? true : false);
                        break;
                    case "connection":
                        count++;

                        if (count > CONNECTION_LIMIT)
                        {
                            flag = false;
                            break;
                        }
                        connections[count] = new Connection();
                        break;
                    case "source":
                        connections[count].source = reader.ReadInnerXml();
                        break;
                    case "catalog":
                        connections[count].catalog = reader.ReadInnerXml();
                        break;
                    case "table":
                        connections[count].table = reader.ReadInnerXml();
                        break;
                    case "user":
                        connections[count].user = reader.ReadInnerXml();
                        break;
                    case "password":
                        connections[count].password = reader.ReadInnerXml();
                        break;
                    case "config":
                        break;
                    default:
                        Console.WriteLine("Configuration defaulted and received the node " + reader.Name + ".");
                        break;
                }

            }

            string[] s = new string[count + 1];

            for (int i = 0; i <= count; i++)
                s[i] = connections[i].getConnectionString();

            return s;
        }
Ejemplo n.º 9
0
        public MainForm()
        {
            InitializeComponent();

            comPortConfigForm     = null;
            dataProcessor         = new DataProcessor(this);
            numberOfStatusEntries = 0;
            numberOfEntries       = 0;
            totalNumberOfMessages = 0;

            PrintStatusMessage("Start Initialization");
            initialized = false;

            availablePortNames = new List <String>();
            String[] portNames = SerialPort.GetPortNames();
            foreach (String name in portNames)
            {
                if (name.StartsWith("COM"))
                {
                    PrintStatusMessage("Add Com Port " + name);
                    availablePortNames.Add(name);
                }
            }
            availablePortNames.Sort();

            OpenComPort(availablePortNames.ElementAt <String>(0), DEFAULT_BAUD_RATE, DEFAULT_PARITY, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS);

            PrintStatusMessage("Remaining List");
            foreach (String name in availablePortNames)
            {
                PrintStatusMessage(name);
            }

            initialized = true;

            PrintStatusMessage("End Initialization");

            PrintStatusMessage("Start Configuration");
            Configuration config = new Configuration();

            string[] connections = config.Read();
            PrintStatusMessage("Configuration read complete. Found " + connections.Length + " connection(s).");

            if (!config.IsAdministrator)
            {
                btnAddCompanyMessage.Hide();
            }
            else
            {
                isAdministrator = true;
            }

            PrintStatusMessage("End Configuration");
            PrintStatusMessage("Start SQL Import");

            List <MessageFormat> messages = new List <MessageFormat>();

            foreach (string connection in connections)
            {
                messages.AddRange(new SqlMessageConnection(connection).GetMessageList());
            }

            foreach (MessageFormat m in messages)
            {
                AddMessageFormat(m, MessageType.Company);
            }

            PrintStatusMessage("End SQL Import. " + companyMessages.Count + " custom messages loaded.");

            /*
             * Format testing. form is the format string, b is the random data array.
             * Prints raw data and formatted data to console.
             * string form = "g * 2 h";
             * byte[] b = new byte[13];
             * (new Random()).NextBytes(b);
             *
             * string s = "";
             * foreach (byte a in b)
             *  s += a.ToString() + " ";
             * Console.WriteLine(s);
             * Console.WriteLine(FormatParser.Parse(form, b));
             */
        }
        public MainForm()
        {
            InitializeComponent();

               comPortConfigForm = null;
               dataProcessor = new DataProcessor(this);
               numberOfStatusEntries = 0;
               numberOfEntries = 0;
               totalNumberOfMessages = 0;

               PrintStatusMessage("Start Initialization");
               initialized = false;

               availablePortNames = new List<String>();
               String[] portNames = SerialPort.GetPortNames();
               foreach (String name in portNames)
               {
                    if (name.StartsWith("COM"))
                    {
                         PrintStatusMessage("Add Com Port " + name);
                         availablePortNames.Add(name);
                    }
               }
               availablePortNames.Sort();

               OpenComPort(availablePortNames.ElementAt<String>(0), DEFAULT_BAUD_RATE, DEFAULT_PARITY, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS);

               PrintStatusMessage("Remaining List");
               foreach (String name in availablePortNames)
               {
                    PrintStatusMessage(name);
               }

               initialized = true;

               PrintStatusMessage("End Initialization");

               PrintStatusMessage("Start Configuration");
               Configuration config = new Configuration();

               string[] connections = config.Read();
              PrintStatusMessage("Configuration read complete. Found " + connections.Length + " connection(s).");

              if (!config.IsAdministrator)
                  btnAddCompanyMessage.Hide();
              else
                  isAdministrator = true;

               PrintStatusMessage("End Configuration");
               PrintStatusMessage("Start SQL Import");

               List<MessageFormat> messages = new List<MessageFormat>();
               foreach (string connection in connections)
                   messages.AddRange(new SqlMessageConnection(connection).GetMessageList());

               foreach (MessageFormat m in messages)
                   AddMessageFormat(m, MessageType.Company);

              PrintStatusMessage("End SQL Import. " + companyMessages.Count + " custom messages loaded.");

              /*
               * Format testing. form is the format string, b is the random data array.
               * Prints raw data and formatted data to console.
              string form = "g * 2 h";
              byte[] b = new byte[13];
              (new Random()).NextBytes(b);

              string s = "";
              foreach (byte a in b)
                  s += a.ToString() + " ";
              Console.WriteLine(s);
              Console.WriteLine(FormatParser.Parse(form, b));
               */
        }
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            btnRefresh.Enabled = false; //prevent spam

              Configuration config = new Configuration();

              string[] connections = config.Read();

              List<MessageFormat> messages = new List<MessageFormat>();

              messages.AddRange(companyMessages);

              foreach (MessageFormat m in messages)
                  RemoveMessageFormat(m);

              messages = new List<MessageFormat>();

              foreach (string connection in connections)
                  messages.AddRange(new SqlMessageConnection(connection).GetMessageList());
              foreach (MessageFormat m in messages)
                  AddMessageFormat(m, MessageType.Company);

              btnRefresh.Enabled = true;
        }