Пример #1
0
        /// <summary>
        /// Read the cycle configuration in a XML file
        /// </summary>
        /// <param name="fPath">Path of the file to read</param>
        /// <returns>Reading error flag: True = No Error / False = Error</returns>
        public bool Read_CycleConfiguration(string fPath)
        {
            if (!(fPath.Equals("")))
            {
                XmlDocument oCycleConfig = new XmlDocument();
                oCycleConfig.Load(fPath);

                XmlNode xCycleCfg = oCycleConfig.SelectSingleNode("CycleConfiguration");

                if (!(xCycleCfg == null))
                {
                    //CAN Configuration
                    XmlNode xCanCfg = xCycleCfg.SelectSingleNode("CANConfiguration");

                    if (!(xCanCfg == null))
                    {
                        CanConfiguration = new CANMessagesConfiguration();

                        if (!(CanConfiguration.ReadCANConfigurationXmlNode(xCanCfg)))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);                         //Node CANConfiguration not found
                    }

                    //Virtual channels libraries
                    XmlNode xVirtualLib = xCanCfg.NextSibling;

                    if (xVirtualLib.Name.Equals("CS_VirtualChannelsLibrary"))
                    {
                        VirtualChannelLibCollection = new CS_VCLibrariesCollection();

                        while (xVirtualLib.Name.Equals("CS_VirtualChannelsLibrary"))
                        {
                            CS_VirtualChannelsLibrary oLib = new CS_VirtualChannelsLibrary();
                            oLib.ReadLibraryXmlNode(xVirtualLib);
                            VirtualChannelLibCollection.AddLibrary(oLib);

                            xVirtualLib = xVirtualLib.NextSibling;
                        }
                    }

                    //Built-In signals libraries
                    XmlNode xSignalLib = xVirtualLib;

                    if (xSignalLib.Name.Equals("CS_BuiltInSignalsLibrary"))
                    {
                        BuiltInSignalLibCollection = new CS_BuiltInSignalLibCollection();

                        while (xSignalLib.Name.Equals("CS_BuiltInSignalsLibrary"))
                        {
                            CS_BuiltInSignalLibrary oLib = new CS_BuiltInSignalLibrary();
                            oLib.ReadLibraryXmlNode(xSignalLib);
                            BuiltInSignalLibCollection.AddLibrary(oLib);

                            xSignalLib = xSignalLib.NextSibling;
                        }
                    }

                    //Cycle parts properties
                    XmlNode xPartProps = xCycleCfg.SelectSingleNode("CyclePartsProperties");
                    if (!(xPartProps == null))
                    {
                        //Pre-cycle
                        XmlNode xPreCycleProps = xPartProps.SelectSingleNode("PreCycleProperties");
                        if (!(xPreCycleProps == null))
                        {
                            XmlAttribute xAtr;

                            xAtr = xPreCycleProps.Attributes["TimeLength"];
                            if (!(xAtr == null))
                            {
                                double t = 0;
                                if (double.TryParse(xAtr.Value, out t))
                                {
                                    PreCycleProperties.TimeLength = t;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute TimeLength is not a number
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute TimeLength not found in node PreCycleProperties
                            }

                            xAtr = xPreCycleProps.Attributes["DataFile"];
                            if (!(xAtr == null))
                            {
                                PreCycleProperties.DataFile = xAtr.Value;
                            }
                            else
                            {
                                return(false);                                 //Attribute DataFile not found in node PreCycleProperties
                            }
                        }
                        else
                        {
                            return(false);                             //Node PreCycleProperties not found
                        }

                        //In-Cycle
                        XmlNode xInCycleProps = xPartProps.SelectSingleNode("InCycleProperties");
                        if (!(xInCycleProps == null))
                        {
                            XmlAttribute xAtr;

                            xAtr = xInCycleProps.Attributes["TimeLength"];
                            if (!(xAtr == null))
                            {
                                double t = 0;
                                if (double.TryParse(xAtr.Value, out t))
                                {
                                    InCycleProperties.TimeLength = t;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute TimeLength is not a number
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute TimeLength not found in node InCycleProperties
                            }

                            xAtr = xInCycleProps.Attributes["DataFile"];
                            if (!(xAtr == null))
                            {
                                InCycleProperties.DataFile = xAtr.Value;
                            }
                            else
                            {
                                return(false);                                 //Attribute DataFile not found in node InCycleProperties
                            }
                        }
                        else
                        {
                            return(false);                             //Node InCycleProperties not found
                        }

                        //Post-Cycle
                        XmlNode xPostCycleProps = xPartProps.SelectSingleNode("PostCycleProperties");
                        if (!(xPostCycleProps == null))
                        {
                            XmlAttribute xAtr;

                            xAtr = xPostCycleProps.Attributes["TimeLength"];
                            if (!(xAtr == null))
                            {
                                double t = 0;
                                if (double.TryParse(xAtr.Value, out t))
                                {
                                    PostCycleProperties.TimeLength = t;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute TimeLength is not a number
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute TimeLength not found in node PostCycleProperties
                            }

                            xAtr = xPostCycleProps.Attributes["DataFile"];
                            if (!(xAtr == null))
                            {
                                PostCycleProperties.DataFile = xAtr.Value;
                            }
                            else
                            {
                                return(false);                                 //Attribute DataFile not found in node PostCycleProperties
                            }
                        }
                        else
                        {
                            return(false);                             //Node PostCycleProperties not found
                        }
                    }
                    else
                    {
                        return(false);                         //Node CyclePartsProperties not found
                    }

                    //Cycle parameters
                    XmlNode xCycleParams = xCycleCfg.SelectSingleNode("CycleParameters");
                    if (!(xCycleParams == null))
                    {
                        Parameters = new List <CycleParameter>();

                        foreach (XmlNode xParam in xCycleParams.ChildNodes)
                        {
                            CycleParameter oParam = new CycleParameter();

                            XmlAttribute xAtr;
                            XmlNode      xData;

                            //Parameter Name
                            xAtr = xParam.Attributes["Name"];
                            if (!(xAtr == null))
                            {
                                if (!(xAtr.Value.Equals("")))
                                {
                                    oParam.Name = xAtr.Value;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute Name is empty
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute Name not found in node xParam
                            }

                            //Parameter Message Id
                            xAtr = xParam.Attributes["MessageId"];
                            if (!(xAtr == null))
                            {
                                if (!(xAtr.Value.Equals("")))
                                {
                                    oParam.MsgId = xAtr.Value;
                                }
                                else
                                {
                                    return(false);                                     //Value of attribute MessageId is empty
                                }
                            }
                            else
                            {
                                return(false);                                 //Attribute MessageId not found in node xParam
                            }

                            //Pre-Cycle data
                            xData = xParam.SelectSingleNode("PreCycleData");
                            if (!(xData == null))
                            {
                                //Source
                                xAtr = xData.Attributes["Source"];
                                if (!(xAtr == null))
                                {
                                    CycleDataSource Src = CycleDataSource.None;

                                    if (Enum.TryParse(xAtr.Value, out Src))
                                    {
                                        oParam.PreCycle.Source = Src;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Source is not part of enumeration
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Source not found in node PreCycleData
                                }

                                //Data
                                xAtr = xData.Attributes["Data"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.PreCycle.Data = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Data is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Data not found in node PreCycleData
                                }

                                //Library
                                xAtr = xData.Attributes["Library"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.PreCycle.Library = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Library is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Library not found in node PreCycleData
                                }
                            }
                            else
                            {
                                return(false);                                 //Node PreCycleData not found
                            }

                            //In-cycle data
                            xData = xParam.SelectSingleNode("InCycleData");
                            if (!(xData == null))
                            {
                                //Source
                                xAtr = xData.Attributes["Source"];
                                if (!(xAtr == null))
                                {
                                    CycleDataSource Src = CycleDataSource.None;

                                    if (Enum.TryParse(xAtr.Value, out Src))
                                    {
                                        oParam.InCycle.Source = Src;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Source is not part of enumeration
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Source not found in node InCycleData
                                }

                                //Data
                                xAtr = xData.Attributes["Data"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.InCycle.Data = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Data is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Data not found in node InCycleData
                                }

                                //Library
                                xAtr = xData.Attributes["Library"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.InCycle.Library = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Library is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Library not found in node InCycleData
                                }
                            }
                            else
                            {
                                return(false);                                 //Node InCycleData not found
                            }

                            xData = xParam.SelectSingleNode("PostCycleData");
                            if (!(xData == null))
                            {
                                //Source
                                xAtr = xData.Attributes["Source"];
                                if (!(xAtr == null))
                                {
                                    CycleDataSource Src = CycleDataSource.None;

                                    if (Enum.TryParse(xAtr.Value, out Src))
                                    {
                                        oParam.PostCycle.Source = Src;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Source is not part of enumeration
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Source not found in node PostCycleData
                                }

                                //Data
                                xAtr = xData.Attributes["Data"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.PostCycle.Data = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Data is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Data not found in node PostCycleData
                                }

                                //Library
                                xAtr = xData.Attributes["Library"];
                                if (!(xAtr == null))
                                {
                                    if (!(xAtr.Value.Equals("")))
                                    {
                                        oParam.PostCycle.Library = xAtr.Value;
                                    }
                                    else
                                    {
                                        return(false);                                         //Value of attribute Library is empty
                                    }
                                }
                                else
                                {
                                    return(false);                                     //Attribute Library not found in node PostCycleData
                                }
                            }
                            else
                            {
                                return(false);                                 //Node PostCycleData not found
                            }

                            Parameters.Add(oParam);
                        }
                    }
                    else
                    {
                        return(false);                         //Node CycleParameters not found
                    }
                }
                else
                {
                    return(false);                     //Node CycleConfiguration not found
                }
            }
            else
            {
                return(false);                 //Path empty
            }

            FilePath  = fPath;
            bModified = false;
            return(true);             //No Error
        }
Пример #2
0
        private void Cmd_LibCreateClick(object sender, EventArgs e)
        {
            if (!(Txt_LibName.Text.Equals("")))
            {
                if (Cmd_LibCreate.Text.Equals("Create"))                 //Creation of a new library
                {
                    if (!(oBSLibCollection.LibraryExists(Txt_LibName.Text)))
                    {
                        oActiveLibrary = new CS_BuiltInSignalLibrary();

                        //Create the new library and add it to the library collection
                        if (!(Txt_LibName.Text.Equals("")))
                        {
                            if (!(Txt_LibName.Text.Contains(":")))                             //":" Is used as separator between library & signal name for signal list in Cycle/Data Association form
                            {
                                oActiveLibrary.Name = Txt_LibName.Text;
                            }
                            else
                            {
                                MessageBox.Show("Signal library name cannot contains ':' !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Signal library must have a name !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }


                        oActiveLibrary.Comment  = rTxt_LibComment.Text;
                        oActiveLibrary.ReadOnly = Chk_LibReadOnly.Checked;

                        oBSLibCollection.AddLibrary(oActiveLibrary);

                        //Set flag to make the main form reloading libraries
                        bFrmMain_ReloadLibraries = true;

                        //Show the library in the treeview
                        TreeNode nLib = TV_Libraries.Nodes.Add(oActiveLibrary.Name, oActiveLibrary.Name, 0);
                    }
                    else
                    {
                        MessageBox.Show("Library " + Txt_LibName.Text + " already exists !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else                 //Modification of an existing library
                {
                    int      LibIndex = oBSLibCollection.GetLibraryIndex(oActiveLibrary.Name);
                    TreeNode nLib     = GetLibraryNode(oActiveLibrary.Name);

                    bool bExists = false;
                    for (int i = 0; i < oBSLibCollection.Libraries.Count; i++)
                    {
                        if (!(i == LibIndex))
                        {
                            if (oBSLibCollection.Libraries[i].Name.Equals(Txt_LibName.Text))
                            {
                                bExists = true;
                                break;
                            }
                        }
                    }

                    if (!bExists)
                    {
                        //Update library instance
                        if (!(Txt_LibName.Text.Equals("")))
                        {
                            if (!(Txt_LibName.Text.Contains(":")))                             //":" Is used as separator between library & signal name for signal list in Cycle/Data Association form
                            {
                                oActiveLibrary.Name = Txt_LibName.Text;
                            }
                            else
                            {
                                MessageBox.Show("Signal library name cannot contains ':' !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Signal library must have a name !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }

                        oActiveLibrary.Comment  = rTxt_LibComment.Text;
                        oActiveLibrary.ReadOnly = Chk_LibReadOnly.Checked;

                        oActiveLibrary.bModified = true;

                        //Update library node in the treeview
                        nLib.Text = Txt_LibName.Text;
                    }
                    else
                    {
                        MessageBox.Show("Library " + Txt_LibName.Text + " already exists !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            else
            {
                MessageBox.Show("Library must have a name !", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }