public DrwBlock ExtractDrwBlockFromNav(XPathNavigator nav, ReplacementConfiguration config)
        {
            if (!nav.HasChildren)
            {
                return(null);
            }

            int    id          = -1;
            string description = null;

            nav.MoveToFirstChild();

            do
            {
                if (nav.Name.ToLower() == "id")
                {
                    try
                    {
                        id = int.Parse(nav.Value.Trim());
                    }
                    catch (Exception e) { throw new Exception("Id not an integer in DrwFile", e); }
                }
                else if (nav.Name.ToLower() == "description")
                {
                    description = ReplacementConfigurationSanitizer(nav.Value, config);
                }
            } while (nav.MoveToNext());

            DrwBlock block = new DrwBlock(id, description);

            return(block);
        }
Beispiel #2
0
        public FBPGraph(List <DrwBlock> blocks, List <DrwConnection> connections)
        {
            this.blocks      = blocks;
            this.connections = connections;

            // Build block from id
            foreach (var block in blocks)
            {
                GetBlockFromId[block.id] = block;

                if (block.description.Trim().ToLower() == "start")
                {
                    StartNode = block;
                }
            }

            // Build GetFromBlock and GetToBlock
            foreach (var connection in connections)
            {
                if (!GetFromBlocks.ContainsKey(connection.toId))
                {
                    GetFromBlocks[connection.toId] = new List <DrwBlock>();
                }

                GetFromBlocks[connection.toId].Add(GetBlockFromId[connection.fromId]);

                if (!GetToBlocks.ContainsKey(connection.fromId))
                {
                    GetToBlocks[connection.fromId] = new List <DrwBlock>();
                }

                GetToBlocks[connection.fromId].Add(GetBlockFromId[connection.toId]);
            }
        }
        public FBPGraph GenerateFBPGraphFromDrwFile(Stream drwFileStream, ReplacementConfiguration configuration)
        {
            XPathDocument  xmlPathDoc = new XPathDocument(drwFileStream);
            XPathNavigator navigator  = xmlPathDoc.CreateNavigator();

            XPathNodeIterator blockIterator      = navigator.SelectDescendants("block", "", false);
            XPathNodeIterator connectionIterator = navigator.SelectDescendants("connection", "", false);

            int count = connectionIterator.Count;

            List <DrwBlock>      blocks      = new List <DrwBlock>();
            List <DrwConnection> connections = new List <DrwConnection>();

            while (blockIterator.MoveNext())
            {
                XPathNavigator nav = blockIterator.Current.Clone();

                DrwBlock block = utility.ExtractDrwBlockFromNav(nav, configuration);

                if (block != null)
                {
                    blocks.Add(block);
                }
            }

            while (connectionIterator.MoveNext())
            {
                XPathNavigator nav = connectionIterator.Current.Clone();

                DrwConnection connection = utility.ExtractDrwConnectionFromNav(nav);

                if (connection != null)
                {
                    connections.Add(connection);
                }
            }

            FBPGraph graph = new FBPGraph(blocks, connections);

            return(graph);
        }
Beispiel #4
0
        private void DfsTraversal(DrwBlock currentNode, ref Dictionary <int, bool> nodeVisited, ref List <DrwBlock> result)
        {
            if (result == null)
            {
                result = new List <DrwBlock>();
            }

            if (nodeVisited.ContainsKey(currentNode.id) && nodeVisited[currentNode.id] == true)
            {
                return;
            }

            result.Add(currentNode);

            if (GetToBlocks.ContainsKey(currentNode.id))
            {
                foreach (var node in GetToBlocks[currentNode.id])
                {
                    DfsTraversal(node, ref nodeVisited, ref result);
                }
            }
        }