Exemplo n.º 1
0
        /// <summary>
        /// Create a new Device and call <see cref="MWController.CreateInterfaceOnClick(MWInterface)"/> of the <see cref="mWController"/>
        /// </summary>
        /// <param name="sender">Event arg, not used</param>
        /// <param name="e">Event arg, not used</param>
        private void createInterfaceBtn_Click(object sender, System.EventArgs e)
        {
            // Creating a new object (interface) and giving it the values of the textfields/input
            MWInterface interfaceObject = new MWInterface();

            interfaceObject.pinList = new List <MWPin>();

            try { interfaceObject.numberOfInterface = Convert.ToInt32(txtInterfaceNumber.Text); } catch (Exception ex) { MessageBox.Show("Vendor ID is in an invalid format (Expected only numbers)!"); return; }
            interfaceObject.interfaceDescription = txtInterfaceDescription.Text;
            interfaceObject.connectorType        = cmbConnectorType.Text;
            if (!String.IsNullOrWhiteSpace(txtPinCount.Text))
            {
                try { interfaceObject.amountPins = Convert.ToInt32(txtPinCount.Text); } catch (Exception ex) { MessageBox.Show("Pin Count is in an invalid format (Expected only numbers)! Ignoring!"); }
            }

            // getting the values of the DataGridView and inserting it into the pinList of the object (Interface)
            int i = (interfaceObject.amountPins - 1);

            while (i >= 0)
            {
                var pinItem = new MWPin();
                try
                {
                    pinItem.pinNumber = Convert.ToInt32(interfacePortMappingGrid.Rows[i].Cells[0].Value);
                    pinItem.attribute = Convert.ToString(interfacePortMappingGrid.Rows[i].Cells[1].Value);
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }

                interfaceObject.pinList.Add(pinItem);
                i += -1;
            }


            string result = mWController.CreateInterfaceOnClick(interfaceObject, isEditing);

            clear();
            if (result != null)
            {
                // Display error Dialog
                MessageBox.Show(result);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Read the all attributes in <paramref name="attributes"/> and write the values into <paramref name="mWInterface"/>
        /// </summary>
        /// <param name="mWInterface">the object to write the data into</param>
        /// <param name="attributes">the list of attributes</param>
        private void fillInterfaceWithData(MWInterface mWInterface, AttributeSequence attributes)
        {
            List <MWPin> pinlist = new List <MWPin>();

            // iterate over all attributes
            foreach (AttributeType attribute in attributes)
            {
                // apply the value of the attribute to the correct interface parameter
                switch (attribute.Name)
                {
                case "InterfaceNumber":
                    mWInterface.numberOfInterface = Int32.Parse(attribute.Value);
                    break;

                case "Description":
                    mWInterface.interfaceDescription = attribute.Value;
                    break;

                case "ConnectorType":
                    mWInterface.connectorType = attribute.Value;
                    break;

                case "PinCount":
                    mWInterface.amountPins = Int32.Parse(attribute.Value);
                    break;

                case "PinAttributes":
                    // Read the pinlist attribute

                    for (int i = 0; i < mWInterface.amountPins; i++)
                    {
                        MWPin pin = new MWPin(Int32.Parse(attribute.Attribute[i].Name), attribute.Attribute[i].Value);
                        pinlist.Add(pin);
                    }
                    // sort the pinlist after ascending pin Number
                    pinlist = pinlist.OrderBy(o => o.pinNumber).ToList();
                    break;
                }
            }
            mWInterface.pinList = pinlist;
        }