示例#1
0
		/// <summary>
		/// Select the nodes from the GUI Model xPath select in the script context
		/// con.
		/// </summary>
		/// <param name="con">The script context who's model to use</param>
		/// <param name="select">Gui Model xPath to model nodes</param>
		/// <param name="source">Text to identify the source instruction in asserts</param>
		/// <returns>A list of model nodes matching the query</returns>
		static public XmlNodeList selectNodes(Context con, string select, string source)
		{
			XmlNodeList nodes = null;
			// try to dereference variables in the select expression
			string evalSelect = Utilities.evalExpr(select);
			if (con.ModelNode != null)
			{ // Search from the current model context
				XmlNode current = con.ModelNode.ModelNode;
				Logger.getOnly().isNotNull(current, source + " context model node is null, parent may not have @select");
				XmlNamespaceManager nsmgr = new XmlNamespaceManager(current.OwnerDocument.NameTable);
				//m_log.paragraph("Selecting from model context=" + current.Name);
				nodes = current.SelectNodes(evalSelect, nsmgr);
			}
			else
			{ // Search from the model root
				OnApplication apCon = null;
				if (typeof(OnApplication).IsInstanceOfType(con))
					apCon = (OnApplication)con;
				else
					apCon = (OnApplication)con.Ancestor(typeof(OnApplication));
				Logger.getOnly().isNotNull(apCon, "No on-application context found for " + source + "select to get a model from");
				XmlElement root = apCon.ModelRoot;
				Logger.getOnly().isNotNull(root, "GUI model of " + source + "select has no root");
				// preprocess select for special variables like $name; if there is a model node
				//m_log.paragraph("Selecting from model context=" + root.Name);
				nodes = root.SelectNodes(evalSelect);
			}
			return nodes;
		}
示例#2
0
        /// <summary>
        /// Executes this context with its instructions.
        /// Child instructions are converted from XML the first time this is called.
        /// Each instruction is executed in turn so that
        /// the instruction tree is traversed depth-first.
        /// </summary>
        public override void Execute()
        {
            base.Execute();
            if (m_instructions.Count == 0 && !(this is Model))
            {
                PrepareChildren();
            }
            // Execute the child instructions
            // Insertions may be made by expansion of some instructions into
            // multiple instructions (via @select) so iterators and foreach can't be used.
            int count = 0;

            if (count < m_instructions.Count)
            {
                SetContextVariables();
                Instruction inst = (Instruction)m_instructions[count];
                while (inst != null)
                {
                    if (!inst.Finished)
                    {
                        inst.Execute();
                    }
                    count += 1;
                    if (count < m_instructions.Count)
                    {
                        inst = (Instruction)m_instructions[count];
                    }
                    else
                    {
                        inst = null;
                    }
                }
                // reinstate the parent context's variables
                Context con = (Context)Ancestor(typeof(Context));
                if (con != null)
                {
                    con.SetContextVariables();
                }
                if (con is OnApplication)
                {                 // refress the process data for the application
                    OnApplication app  = (OnApplication)con;
                    Process       proc = app.Application.Process;
                    m_log.paragraph("Application process refreshed.");
                }
            }
            //Logger.getOnly().result(this); derivative classes call this after processing results
        }