Esempio n. 1
0
        public override void Execute()
        {
            base.Execute();
            Context con = (Context)Ancestor(typeof(Context));

            isNotNull(con, makeNameTag() + " must occur in some context");
            m_Result = Condition.EvaluateList(m_conditions);
            if (m_Result == true)
            {
                XmlNode xThen = m_elt.SelectSingleNode("then");
                if (xThen != null)
                {                 // then may have been created via do-once before this
                    if (m_then == null)
                    {             // not created yet
                        Context thenCon = new Context();
                        thenCon.ModelNode = con.ModelNode;
                        thenCon.Parent    = this;
                        string rest = XmlFiler.getAttribute(xThen, "wait");
                        if (rest != null)
                        {
                            thenCon.Rest = Convert.ToInt32(rest);
                        }
                        foreach (XmlNode child in xThen.ChildNodes)
                        {                         // MakeShell adds the ins to thenCon
                            XmlInstructionBuilder.MakeShell(child, thenCon);
                        }
                        SetThen(thenCon);
                    }
                    m_then.Execute();
                }
            }
            else
            {
                XmlNode xElse = m_elt.SelectSingleNode("else");
                if (xElse != null)
                {                 // else may have been created via do-once before this
                    if (m_else == null)
                    {             // not created yet
                        Context elseCon = new Context();
                        elseCon.ModelNode = con.ModelNode;
                        elseCon.Parent    = this;
                        string rest = XmlFiler.getAttribute(xElse, "wait");
                        if (rest != null)
                        {
                            elseCon.Rest = Convert.ToInt32(rest);
                        }
                        foreach (XmlNode child in xElse.ChildNodes)
                        {                         // MakeShell adds the ins to elseCon
                            XmlInstructionBuilder.MakeShell(child, elseCon);
                        }
                        SetElse(elseCon);
                    }
                    m_else.Execute();
                }
            }
            Logger.getOnly().result(this);
            Finished = true;             // tell do-once it's done
        }
Esempio n. 2
0
 /// <summary>
 /// Converts child instructions from XML the first time this is called.
 /// Some contexts need to build their children but control execution
 /// themselves. They don't call this. Execute, which calls this internally.
 /// </summary>
 public void PrepareChildren(bool addMore)
 {
     if (1 == m_logLevel)
     {
         if (m_ah == null)
         {
             m_log.paragraph("PrepareChildren: Context is not yet defined.");
         }
         else
         {
             m_log.paragraph("PrepareChildren: Context is &quot;" + m_ah.Role + ":" + m_ah.Name + "&quot;");
         }
     }
     // m_components may have been stocked before execution as by click.
     // They also may have been built on a previous execution via do-once.
     if (addMore || m_components.Count == 0)
     {             // Build the child instructions
         // Insertions may be made by expansion of some instructions into
         // multiple instructions (via include) so iterators and foreach can't be used.
         int count = 0;
         if (count < m_elt.ChildNodes.Count)
         {
             XmlNode xn = m_elt.ChildNodes[count];
             while (xn != null)
             {
                 Instruction ins = XmlInstructionBuilder.MakeShell(xn, this);
                 // pass higher log levels to the children
                 if (ins != null && ins.LogLevel < LogLevel)
                 {
                     ins.LogLevel = LogLevel;
                 }
                 count += 1;
                 if (count < m_elt.ChildNodes.Count)
                 {
                     xn = m_elt.ChildNodes[count];
                 }
                 else
                 {
                     xn = null;
                 }
             }
         }
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Execute this model node context, specified by @select and
        /// creating and executing child instructions.
        /// </summary>
        public override void Execute()
        {
            base.Execute();
            if (m_created)
            {
                Finished = true;        // tell do-once it's done
                return;                 // all has been done in the base Context.Execute().
            }
            Context con = (Context)Ancestor(typeof(Context));

            isNotNull(con, makeNameTag() + " must occur in some context");
            AccessibilityHelper ah = con.Accessibility;

            isNotNull(ah, makeNameTag() + " context is not accessible");

            // If there is a @select, select the nodes
            if (m_select != null && m_select != "")
            {             // each node or attribute selected creates a context
                m_log.paragraph(makeNameTag() + " creating selection targets via " + m_select);
                XmlNodeList pathNodes = XmlInstructionBuilder.selectNodes(con, m_select, makeNameTag());
                isNotNull(pathNodes, makeNameTag() + " select='" + m_select + "' returned no model nodes");
                // The select text may have selected a string that is itself xPath!
                // If so, select on that xPath
                if (pathNodes.Count == 1 && pathNodes.Item(0).NodeType == XmlNodeType.Text)
                {                 // this text node should be an xpath statement
                    string xPath = pathNodes.Item(0).Value;
                    m_log.paragraph(makeNameTag() + " selected a text node with more XPATH: " + xPath);
                    pathNodes = XmlInstructionBuilder.selectNodes(con, xPath, makeNameTag() + " selecting " + xPath);
                    isNotNull(pathNodes, makeNameTag() + " selecting " + xPath + " from select='" + m_select + "' returned no model nodes");
                }
                // Create a list of paths to loop over
                Model lastModel = this; // use as an insert reference node
                foreach (XmlNode node in pathNodes)
                {                       // build the path via each model node
                    XmlPath xPath = new XmlPath(node);
                    // xPath may be invalid - it means it has no guiPath
                    //if (!xPath.isValid()) fail(makeNameTag() + " XmlPath not constructable from " + node.OuterXml);
                    if (1 == m_logLevel)
                    {
                        m_log.paragraph(makeNameTag() + " appPath " + xPath.xPath());
                        m_log.paragraph(makeNameTag() + " guiPath " + xPath.Path);
                    }
                    Model model = new Model();
                    model.m_created   = true;
                    model.m_modelNode = xPath;
                    model.m_path      = xPath.Path;
                    model.m_select    = xPath.xPath();
                    model.m_when      = m_when;
                    model.m_name      = XmlFiler.getAttribute(node, "name");
                    model.m_role      = XmlFiler.getAttribute(node, "role");
                    model.m_nodeName  = node.Name;
                    model.Number      = TestState.getOnly().IncInstructionCount;
                    model.Id         += (model.Number - Number).ToString();
                    model.Parent      = con;
                    con.Add(lastModel, model);
                    lastModel = model;                     // insert the next one after this one.
                    m_log.mark(model);                     // log the progress of interpretation
                    // if there is content, add instructions to the new model context
                    if (m_elt.HasChildNodes)
                    {
                        foreach (XmlNode xnChild in m_elt.ChildNodes)
                        {                         // a side-effect of MakeShell is to add the instruction to the model
                            XmlInstructionBuilder.MakeShell(xnChild, model);
                        }
                    }
                }
            }
            Finished = true;             // tell do-once it's done
        }