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

            m_log.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.Wait = Convert.ToInt32(rest);
                        }
                        foreach (XmlNode child in xThen.ChildNodes)
                        {                         // MakeShell adds the ins to thenCon
                            Instructionator.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.Wait = Convert.ToInt32(rest);
                        }
                        foreach (XmlNode child in xElse.ChildNodes)
                        {                         // MakeShell adds the ins to elseCon
                            Instructionator.MakeShell(child, elseCon);
                        }
                        SetElse(elseCon);
                    }
                    m_else.Execute();
                }
            }
            Logger.getOnly().result(this);
            Finished = true;             // tell do-once it's done
        }
Beispiel #2
0
        /// <summary>
        /// Read the var nodes from the model and add them as
        /// child instructions to this context.
        /// </summary>
        private void ReadModelVars()
        {
            XmlNodeList vars = m_model_root.SelectNodes("var");

            if (vars != null)
            {
                foreach (XmlNode varNode in vars)
                {
                    Var varObj = (Var)Instructionator.MakeShell(varNode, this);
                }
            }
        }
Beispiel #3
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(makeNameTag() + "PrepareChildren: Context is not yet defined.");
         }
         else
         {
             m_log.paragraph(makeNameTag() + "PrepareChildren: Context is &quot;" + m_ah.Role + ":" + m_ah.Name + "&quot;");
         }
     }
     // m_instructions 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_instructions.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)
             {                       // MakeShell can add multiple instructions to m_instructions.
                 Instruction ins = Instructionator.MakeShell(xn, this);
                 // pass higher log levels to the children
                 if (ins != null && ins.Log < Log)
                 {
                     ins.Log = Log;
                 }
                 count += 1;
                 if (count < m_elt.ChildNodes.Count)
                 {
                     xn = m_elt.ChildNodes[count];
                 }
                 else
                 {
                     xn = null;
                 }
             }
         }
     }
 }
Beispiel #4
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));

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

            m_log.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_select = Utilities.evalExpr(m_select);
                m_log.paragraph(makeNameTag() + " creating selection targets via " + m_select);
                XmlNodeList pathNodes = Instructionator.selectNodes(con, m_select, makeNameTag());
                m_log.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 = Instructionator.selectNodes(con, xPath, makeNameTag() + " selecting " + xPath);
                    m_log.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
                            Instructionator.MakeShell(xnChild, model);
                        }
                    }
                }
            }
            Finished = true;             // tell do-once it's done
        }