Esempio n. 1
0
        public void Add(string name, List <string> subNames)
        {
            if (Contains(name))
            {
                return;
            }

            base.Add(name);

            if (subNames.Count > 0)
            {
                SubNames.Add(name, subNames);
            }
        }
Esempio n. 2
0
        public static List <SubsystemClass> XMLSub(OpenFileDialog ofd)           // Read in subsystem information within XML file
        {
            XDocument xDoc = XDocument.Load(ofd.FileName);                       // Opens XML file within framework and loads chosen XML file

            //LINQ query to read the xml file details
            var modelDetails = from readInfo in xDoc.Descendants("MODEL")        // Find the Model and read-in its descendant elements
                               select new
            {
                subInfo   = readInfo.Descendants("SUBSYSTEM").DescendantsAndSelf(),                         // Find all subsystems and read-in their descendant elements
                assetInfo = readInfo.DescendantsAndSelf("ASSET").DescendantsAndSelf()                       // Find all assets and read-in in their descendant elements
            };

            // Asset details retrieval
            Asset          asset  = new Asset(null, null);                  // New asset class
            SubsystemClass subSys = new SubsystemClass(null, null, null);   // New subsystem class

            List <Asset>          assetsList = new List <Asset>();          // New list of information for each asset
            List <SubsystemClass> subsysList = new List <SubsystemClass>(); // New list of information for each subsystem

            int           i         = 0;                                    // Declare counter
            string        SubName   = null;
            string        StateVar  = null;
            string        AssetName = null;
            List <string> StateVars = new List <string>();
            List <string> SubNames  = new List <string>();

            // Using foreach loop to retrieve all details by iterating through each element with the MODEL element
            foreach (var modelElem in modelDetails)
            {
                // Using foreach loop to retrieve each asset's details by iterating through each element with the ASSET element
                foreach (XElement ae in modelElem.assetInfo)
                {
                    string assetName = ae.Attribute("AssetName") != null?ae.Attribute("AssetName").Value : String.Empty;               // Extract asset name data

                    string subName = ae.Attribute("SubsystemName") != null?ae.Attribute("SubsystemName").Value : String.Empty;         // Extract subsystem name data

                    if (assetName != String.Empty)                                                                                     // If the element is an asset name
                    {
                        if (i > 0)                                                                                                     // If there is a new asset
                        {
                            asset = new Asset(AssetName, SubNames);
                            assetsList.Add(asset);                                                                                     // Add asset to asset list
                            asset    = new Asset(AssetName, SubNames);                                                                 // Populate asset class
                            SubNames = new List <string>();
                        }
                        AssetName = assetName;                                                                                         // Record asset name
                    }

                    if (subName != String.Empty)                                                                                       // If the element is a subsystem name
                    {
                        SubNames.Add(subName);                                                                                         // Record subsystem name in subsystem names list
                        i++;
                    }
                }
                asset = new Asset(AssetName, SubNames);                                                                                // Populate asset class
                assetsList.Add(asset);                                                                                                 // Add asset to asset list

                i = 0;

                // Using foreach loop to retrieve each subsystem and dependecies respective details by iterating through each element with the SUBSYSTEM element
                foreach (XElement se in modelElem.subInfo)
                {
                    string stateName = se.Attribute("key") != null?se.Attribute("key").Value : String.Empty;                   // Extract state variable data

                    string subName = se.Attribute("SubsystemName") != null?se.Attribute("SubsystemName").Value : String.Empty; // Extract subsystem name data

                    if (subName != String.Empty)                                                                               // If the element is a subsystem name
                    {
                        if (i > 0)                                                                                             // If there is a new subsystem
                        {
                            foreach (Asset item in assetsList)                                                                 // Check each asset
                            {
                                if (item.SubNames.Contains(SubName))                                                           // Find subsystem name within asset
                                {
                                    AssetName = item.AssetName;                                                                // Record asset name for subsystem class
                                }
                            }
                            subSys = new SubsystemClass(SubName, AssetName, StateVars);                     // Populate subsystem class
                            subsysList.Add(subSys);                                                         // Add subsystem class to subsystem list
                            StateVars = new List <string>();
                        }
                        SubName = subName;                                                                  // Record subsystem name for subsystem class
                        i++;
                    }


                    if (stateName != String.Empty)                                                          // If the element is a state variable
                    {
                        StateVar = stateName;
                        StateVars.Add(stateName);                                                           // Record state variable requirement for subsystem class
                    }
                }
                subSys = new SubsystemClass(SubName, AssetName, StateVars);                                 // Populate subsystem class
                subsysList.Add(subSys);                                                                     // Add subsystem class to subsystem list
            }
            return(subsysList);
        }
Esempio n. 3
0
 public override void Clear()
 {
     base.Clear();
     SubNames.Clear();
 }