Example #1
0
        private static Scripts.ConditionalStep CreateConditionalStep(ConditionalContext context, XmlNode node)
        {
            System.Diagnostics.Debug.Assert(node.Name.Equals("conditional"));

            System.Diagnostics.Debug.Assert(node.FirstChild.Name.Equals("if"));

            /// first: read the conditionals (the "if" part)
            /// the terms are in an implicit conjunction
            Scripts.Logic.Conditional conditional = new Scripts.Logic.Conjunction();
            foreach (XmlNode childNode in node.ChildNodes[0].ChildNodes)
            {
                conditional.SubTerms.Add(CreateConditionalSubStep(childNode));
            }

            /// second: read the steps (the "then" part)
            System.Diagnostics.Debug.Assert(node.ChildNodes [1].Name.Equals("then"));

            Scripts.CompositeStep thenStep = new Scripts.CompositeStep();
            switch (context)
            {
            case ConditionalContext.TopLevel:
                foreach (XmlNode childNode in node.ChildNodes[1].ChildNodes)
                {
                    thenStep.SubSteps.Add(CreateStep(childNode));
                }
                break;

            case ConditionalContext.ExportSection:
                foreach (XmlNode childNode in node.ChildNodes[1].ChildNodes)
                {
                    thenStep.SubSteps.Add(CreateExportSubStep(childNode));
                }
                break;
            }

            /// lastly: read the else section (if it exists)
            Scripts.CompositeStep elseStep = new Scripts.CompositeStep();
            if (node.ChildNodes [2] != null)
            {
                System.Diagnostics.Debug.Assert(node.ChildNodes [1].Name.Equals("else"));
                switch (context)
                {
                case ConditionalContext.TopLevel:
                    foreach (XmlNode childNode in node.ChildNodes[1].ChildNodes)
                    {
                        elseStep.SubSteps.Add(CreateStep(childNode));
                    }
                    break;

                case ConditionalContext.ExportSection:
                    foreach (XmlNode childNode in node.ChildNodes[1].ChildNodes)
                    {
                        elseStep.SubSteps.Add(CreateExportSubStep(childNode));
                    }
                    break;
                }
            }

            return(new Scripts.ConditionalStep(conditional, thenStep, elseStep));
        }
        private static Scripts.ConditionalStep CreateConditionalStep(ConditionalContext context, XmlNode node)
        {
            System.Diagnostics.Debug.Assert(node.Name.Equals("conditional"));

            System.Diagnostics.Debug.Assert(node.FirstChild.Name.Equals("if"));

            /// first: read the conditionals (the "if" part)
            /// the terms are in an implicit conjunction
            Scripts.Logic.Conditional conditional = new Scripts.Logic.Conjunction ();
            foreach (XmlNode childNode in node.ChildNodes[0].ChildNodes)
                conditional.SubTerms.Add(CreateConditionalSubStep(childNode));

            /// second: read the steps (the "then" part)
            System.Diagnostics.Debug.Assert(node.ChildNodes [1].Name.Equals("then"));

            Scripts.CompositeStep thenStep = new Scripts.CompositeStep();
            switch (context)
            {
                case ConditionalContext.TopLevel:
                    foreach (XmlNode childNode in node.ChildNodes[1].ChildNodes)
                        thenStep.SubSteps.Add(CreateStep(childNode));
                    break;

                case ConditionalContext.ExportSection:
                    foreach (XmlNode childNode in node.ChildNodes[1].ChildNodes)
                        thenStep.SubSteps.Add(CreateExportSubStep(childNode));
                    break;
            }

            /// lastly: read the else section (if it exists)
            Scripts.CompositeStep elseStep = new Scripts.CompositeStep();
            if (node.ChildNodes [2] != null)
            {
                System.Diagnostics.Debug.Assert(node.ChildNodes [1].Name.Equals("else"));
                switch (context)
                {
                    case ConditionalContext.TopLevel:
                        foreach (XmlNode childNode in node.ChildNodes[1].ChildNodes)
                            elseStep.SubSteps.Add(CreateStep(childNode));
                        break;

                    case ConditionalContext.ExportSection:
                        foreach (XmlNode childNode in node.ChildNodes[1].ChildNodes)
                            elseStep.SubSteps.Add(CreateExportSubStep(childNode));
                        break;

                }
            }

            return new Scripts.ConditionalStep(conditional, thenStep, elseStep);
        }