Beispiel #1
0
        /// <summary>
        /// Adds an error indicating that this element represents the start of a cycle. Cycles will be detected
        /// by the first recurring element in a path.
        /// </summary>
        /// <param name="element">The element that has just been added to the current depth path.</param>
        private void LogError(object element)
        {
            #region Create & add an error.
            if (s_diagnostics)
            {
                for (int i = 0; i < m_level; i++)
                {
                    Console.Write("  ");
                }
                Console.WriteLine(">>>>>>>>>>>> Element " + element + " represents the start of a cycle.");
            }

            ArrayList elements     = new ArrayList();
            ArrayList pathObjArray = new ArrayList(m_currentPath.ToArray());
            string    narrative    = "Cycle detected - elements are : ";
            int       startOfLoop  = pathObjArray.IndexOf(element);
            for (int i = startOfLoop; i >= 0; i--)
            {
                object elementInPath = pathObjArray[i];
                elements.Add(elementInPath);
                narrative += elementInPath.ToString();
                if (i > 1)
                {
                    narrative += ", ";
                }
                else if (i == 1)
                {
                    narrative += " and ";
                }
            }
            DagStructureError se = new DagStructureError(m_rootEdge, elements, narrative);
            m_errors.Add(se);
            #endregion
        }
Beispiel #2
0
        /// <summary>
        /// Forces this DAGDeadlockChecker to validate the entire DAG by checking for deadlocks.
        /// </summary>
        /// <returns>True if the DAGDeadlockChecker found no errors.</returns>
        public virtual bool Check()
        {
            m_errors   = new ArrayList();
            m_nodes    = new Hashtable();
            m_frontier = new ArrayList();

            Build(m_rootEdge.PreVertex);

            m_frontier.Add(m_nodes[m_rootEdge.PreVertex]);

            while (Advance())
            {
                if (s_diagnostics)
                {
                    Console.WriteLine("There are " + m_frontier.Count + " nodes on the frontier.");
                }
            }

            if (m_frontier.Count > 0)
            {
                ArrayList removees = new ArrayList();
                foreach (Node n in m_frontier)
                {
                    foreach (Node pred in AnyPredecessorsOf(n))
                    {
                        if (m_frontier.Contains(pred))
                        {
                            if (!removees.Contains(n))
                            {
                                //Console.WriteLine("Removing " + n.Name + " because " + pred.Name + " is also on the frontier.");
                                removees.Add(n);
                                break;
                            }
                        }
                    }
                }
                foreach (Node r in removees)
                {
                    m_frontier.Remove(r);
                }

                ArrayList targets = new ArrayList();
                foreach (Node n in m_frontier)
                {
                    targets.Add(n.Element);
                }
                DagStructureError dse = new DagStructureError(m_rootEdge, targets, "A deadlock was detected in the graph.");
                m_errors.Add(dse);
            }

            return(m_errors.Count == 0);
        }