Пример #1
0
        static List <FaultTree> CombineFaultTrees(List <FaultTree> uncombinedFaultTrees)
        {
            List <FaultTree> combinedFaultTrees = new List <FaultTree>();

            Dictionary <string, FaultTree> faultTreeListDictionary = new Dictionary <string, FaultTree>();

            Dictionary <string, int> duplicateNameCount = new Dictionary <string, int>();

            foreach (FaultTree faultTree in uncombinedFaultTrees)
            {
                string outputDeviationChecksum = faultTree.OutputDeviation.TotalChildrenChecksum();

                if (!faultTreeListDictionary.ContainsKey(outputDeviationChecksum))
                {
                    FaultTree newFaultTree = new FaultTree(faultTree.Name);


                    if (duplicateNameCount.ContainsKey(faultTree.Name))
                    {
                        newFaultTree.Name += (++duplicateNameCount[faultTree.Name]).ToString();
                    }
                    else
                    {
                        duplicateNameCount.Add(faultTree.Name, 1);
                    }

                    newFaultTree.Description         = faultTree.Description;
                    newFaultTree.SIL                 = faultTree.SIL;
                    newFaultTree.Unavailability      = faultTree.Unavailability;
                    newFaultTree.UnavailabilitySort  = faultTree.UnavailabilitySort;
                    newFaultTree.Severity            = faultTree.Severity;
                    newFaultTree.OutputDeviation     = faultTree.OutputDeviation;
                    newFaultTree.CutSetsSummary      = faultTree.CutSetsSummary;
                    newFaultTree.HiPHOPSResultsIndex = faultTree.HiPHOPSResultsIndex;
                    newFaultTree.AllCutSets          = ReadCutsSetsFile(FilePaths[faultTree.HiPHOPSResultsIndex] + "/CutSets(" + faultTree.PreviousId + ").xml");

                    faultTreeListDictionary.Add(newFaultTree.OutputDeviation.TotalChildrenChecksum(), newFaultTree);
                    combinedFaultTrees.Add(newFaultTree);

                    Effect newEffect = new Effect();
                    newEffect.Id   = newFaultTree.Id;
                    newEffect.Name = newFaultTree.Name;

                    FaultTreesDictionaryLookup[faultTree.HiPHOPSResultsIndex].Add(faultTree.PreviousId, newEffect);
                }
                else
                {
                    Effect newEffect = new Effect();
                    newEffect.Id   = faultTreeListDictionary[outputDeviationChecksum].Id;
                    newEffect.Name = faultTreeListDictionary[outputDeviationChecksum].Name;

                    FaultTreesDictionaryLookup[faultTree.HiPHOPSResultsIndex].Add(faultTree.PreviousId, newEffect);
                }
            }

            return(combinedFaultTrees);
        }
Пример #2
0
        static FaultTree ReadFaultTree(XmlReader reader)
        {
            int    previousId = int.Parse(reader.GetAttribute("ID"));
            string name       = "";

            reader.ReadStartElement();

            if (reader.Name == "Name")
            {
                name = reader.ReadElementContentAsString();
            }
            FaultTree faultTree = new FaultTree();

            faultTree.Name       = name;
            faultTree.PreviousId = previousId;

            if (reader.Name == "Description")
            {
                faultTree.Description = reader.ReadElementContentAsString();
            }
            if (reader.Name == "SIL")
            {
                faultTree.SIL = reader.ReadElementContentAsString();
            }
            if (reader.Name == "Unavailability")
            {
                faultTree.Unavailability = reader.ReadElementContentAsString();
            }
            if (reader.Name == "UnavailabilitySort")
            {
                faultTree.UnavailabilitySort = reader.ReadElementContentAsString();
            }
            if (reader.Name == "Severity")
            {
                faultTree.Severity = reader.ReadElementContentAsString();
            }

            if (reader.Name == "OutputDeviation")
            {
                faultTree.OutputDeviation = ReadOutputDeviation(reader);
            }

            if (reader.Name == "CutSetsSummary")
            {
                reader.ReadStartElement();

                while (reader.Name == "CutSets")
                {
                    faultTree.CutSetsSummary.Add(ReadCutSetsSummary(reader));
                }
                reader.Read();
            }

            reader.Read();
            return(faultTree);
        }
Пример #3
0
        static FaultTree ReadCutSets(XmlReader reader, int Id)
        {
            FaultTree cutSets = new FaultTree();

            cutSets.PreviousId = Id;

            reader.ReadStartElement();
            if (reader.Name == "Name")
            {
                cutSets.Name = reader.ReadElementContentAsString();
            }
            if (reader.Name == "Description")
            {
                cutSets.Description = reader.ReadElementContentAsString();
            }
            if (reader.Name == "SIL")
            {
                cutSets.SIL = reader.ReadElementContentAsString();
            }
            if (reader.Name == "Unavailability")
            {
                cutSets.Unavailability = reader.ReadElementContentAsString();
            }
            if (reader.Name == "UnavailabilitySort")
            {
                cutSets.UnavailabilitySort = reader.ReadElementContentAsString();
            }
            if (reader.Name == "Severity")
            {
                cutSets.Severity = reader.ReadElementContentAsString();
            }

            if (reader.Name == "CutSetsSummary")
            {
                reader.ReadStartElement();

                while (reader.Name == "CutSets")
                {
                    cutSets.CutSetsSummary.Add(ReadCutSetsSummary(reader));
                }
                reader.Read();
            }


            if (reader.Name == "AllCutSets")
            {
                cutSets.AllCutSets = ReadAllCutSets(reader);
            }

            return(cutSets);
        }
Пример #4
0
        static void WriteCutSets(XmlWriter writer, FaultTree cutSets)
        {
            writer.WriteStartElement("HiP-HOPS_Results");
            writer.WriteAttributeString("model", CombinedHiP_HOPSResults.Model);
            writer.WriteAttributeString("build", CombinedHiP_HOPSResults.Build);
            writer.WriteAttributeString("maorVersion", CombinedHiP_HOPSResults.MajorVersion);
            writer.WriteAttributeString("minorVersion", CombinedHiP_HOPSResults.MinorVersion);
            writer.WriteAttributeString("version", CombinedHiP_HOPSResults.Version);
            writer.WriteAttributeString("versionDate", CombinedHiP_HOPSResults.VersionDate);

            writer.WriteStartElement("FaultTrees");

            WriteFMEA(writer, CombinedHiP_HOPSResults.FMEA);

            WriteFaultTreeCutSet(writer, cutSets);
        }
Пример #5
0
        static List <CutSets> ReassignCutSetsEvents(FaultTree faultTree)
        {
            List <CutSets> oldCutSetsList = faultTree.AllCutSets;

            foreach (CutSets oldCutSets in oldCutSetsList)
            {
                foreach (CutSet oldCutSet in oldCutSets.CutSetList)
                {
                    foreach (BasicEvent oldEvent in oldCutSet.Events)
                    {
                        oldEvent.Id = BasicEventsDictionary[BasicEventsDictionaryList[faultTree.HiPHOPSResultsIndex][oldEvent.PreviousId].Name].Id;
                    }
                }
            }

            return(oldCutSetsList);
        }
Пример #6
0
        static void WriteFaultTreeCutSet(XmlWriter writer, FaultTree faultTree)
        {
            writer.WriteStartElement("FaultTree");
            writer.WriteAttributeString("ID", faultTree.Id.ToString());

            writer.WriteStartElement("Name");
            writer.WriteString(faultTree.Name);
            writer.WriteEndElement();

            writer.WriteStartElement("Description");
            if (!string.IsNullOrEmpty(faultTree.Description))
            {
                writer.WriteString(faultTree.Description);
            }
            writer.WriteEndElement();

            writer.WriteStartElement("SIL");
            if (!string.IsNullOrEmpty(faultTree.SIL))
            {
                writer.WriteString(faultTree.SIL);
            }
            writer.WriteEndElement();

            writer.WriteStartElement("Unavailability");
            writer.WriteString(faultTree.Unavailability);
            writer.WriteEndElement();

            writer.WriteStartElement("UnavailabilitySort");
            writer.WriteString(faultTree.UnavailabilitySort);
            writer.WriteEndElement();

            writer.WriteStartElement("Severity");
            writer.WriteString(faultTree.Severity);
            writer.WriteEndElement();

            writer.WriteStartElement("CutSetsSummary");
            WriteCutSetsSummary(writer, faultTree.CutSetsSummary);
            writer.WriteEndElement();

            writer.WriteStartElement("AllCutSets");
            WriteAllCutSets(writer, faultTree.AllCutSets);
            writer.WriteEndElement();

            writer.WriteEndElement();
        }
Пример #7
0
        static List <CutSets> ReadCutsSetsFile(string pPath)
        {
            FaultTree         cutSets  = new FaultTree();
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.Async            = false;
            settings.IgnoreWhitespace = true;

            string fileName = Path.GetFileName(pPath);

            string[] fileNameParts = fileName.Split(new char[] { '(', ')' }, StringSplitOptions.None);

            if (int.TryParse(fileNameParts[1], out int Id))
            {
                Console.WriteLine("Reading File: " + fileName);
                using (XmlReader reader = XmlReader.Create(new StreamReader(pPath), settings))
                {
                    reader.ReadToFollowing("FaultTree");
                    cutSets = ReadCutSets(reader, Id);
                }
            }

            return(cutSets.AllCutSets);
        }