コード例 #1
0
ファイル: Step.cs プロジェクト: AustinWise/CSC431
        public static void DoAll(Step s)
        {
            while (s.parent != null)
            {
                s = s.parent;
            }

            Queue<Step> toDos = new Queue<Step>();
            toDos.Enqueue(s);

            while (toDos.Count != 0)
            {
                s = toDos.Dequeue();
                s.Process();

                if (isOut(s.GetType()))
                {
                    //it ~should~ be ok to use dynamic like this as the
                    //FollowWith functions should have ensured that types lined up
                    dynamic ds = s;
                    dynamic res = ds.Output;
                    foreach (var n in s.nexts)
                    {
                        dynamic dn = n;
                        dn.Input = res;
                        toDos.Enqueue(n);
                    }
                }
                else
                {
                    if (s.nexts.Count != 0)
                        throw new NotSupportedException("non-output steps should not be followed");
                }

                s.Dispose();
            }
        }
コード例 #2
0
ファイル: Step.cs プロジェクト: AustinWise/CSC431
        public static string MakeGraph(Step s)
        {
            while (s.parent != null)
            {
                s = s.parent;
            }

            Queue<Step> toDos = new Queue<Step>();
            toDos.Enqueue(s);

            var allSteps = new List<Step>();

            while (toDos.Count != 0)
            {
                s = toDos.Dequeue();
                allSteps.Add(s);

                if (isOut(s.GetType()))
                {
                    foreach (var n in s.nexts)
                    {
                        toDos.Enqueue(n);
                    }
                }
                else
                {
                    if (s.nexts.Count != 0)
                        throw new NotSupportedException("non-output steps should not be followed");
                }
            }

            var sb = new StringBuilder();

            sb.AppendLine("digraph {");
            for (int i = 0; i < allSteps.Count; i++)
            {
                sb.AppendFormat("\tn{0} [label=\"{1}\"];", i, allSteps[i].Name);
                sb.AppendLine();
            }
            sb.AppendLine();
            for (int i = 0; i < allSteps.Count; i++)
            {
                foreach (var next in allSteps[i].nexts)
                {
                    sb.AppendFormat("\tn{0} -> n{1}", i, allSteps.IndexOf(next));
                    sb.AppendLine();
                }
            }
            sb.AppendLine("}");

            return sb.ToString();
        }