Ejemplo n.º 1
0
        /// <summary>
        /// Interprets a model path (selection), selects the node and returns its path.
        /// </summary>
        /// <param name="con">Current context of the action instruction.</param>
        /// <returns>A "path" string</returns>
        protected string SelectToPath(Context con, string modelPath)
        {
            if (modelPath == null || modelPath == "")
            {
                return(null);
            }
            // only one node or attribute selected gets clicked
            m_log = Logger.getOnly();
            m_log.paragraph(makeNameTag() + " creating one select-path target via " + modelPath);
            XmlNodeList pathNodes = XmlInstructionBuilder.selectNodes(con, modelPath, makeNameTag());

            isNotNull(pathNodes, makeNameTag() + " select-path='" + modelPath + "' returned no model node");
            // The modelPath 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 xPathImage = pathNodes.Item(0).Value;
                m_log.paragraph(makeNameTag() + " selected a text node with more XPATH: " + xPathImage);
                pathNodes = XmlInstructionBuilder.selectNodes(con, xPathImage, makeNameTag() + " selecting " + xPathImage);
                isNotNull(pathNodes, makeNameTag() + " selecting " + xPathImage + " from select='" + modelPath + "' returned no model node");
            }
            // Click the first node returned
            XmlNode node  = pathNodes[0];
            XmlPath xPath = new XmlPath(node);

            if (!xPath.isValid())
            {
                fail(makeNameTag() + " XmlPath not constructable from " + node.OuterXml);
            }
            return(xPath.Path);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a variable to be referenced by other instruction attributes.
 /// </summary>
 /// <param name="xn">The XML repersentation of the instruction to be checked</param>
 /// <param name="con">The current context object</param>
 public static Var CreateVar(XmlNode xn, Context con)
 {
     Var var  = new Var();
     var.Id   = XmlFiler.getAttribute(xn, "id");
     Logger.getOnly().isNotNull(var.Id, "Var instruction must have a id.");
     Logger.getOnly().isTrue(var.Id != "", "Var instruction must have a non-empty id.");
     string s = XmlFiler.getAttribute(xn, "set");
     // select should be move to var.execute so it is dynamic!
     string select = XmlFiler.getAttribute(xn, "select");
     if (select != null && select != "")
     { // the variable can only have one text node or one other node assigned to it.
         XmlNodeList pathNodes = selectNodes(con, select, "var"+var.Id);
         Logger.getOnly().isNotNull(pathNodes, "var " + var.Id + " select='" + select + "' returned no result");
         if (pathNodes.Count > 0)
         { // append first node to set string
             XmlNode modNode = pathNodes.Item(0);
             // which property of the node to get?
             string prop = null;
             string propName = XmlFiler.getAttribute(xn, "prop");
             if (propName == null && modNode is XmlElement) propName = "path";
             if (propName == null) propName = "value";
             if (propName != null && propName == "value") prop = XmlPath.ResolveModelPath(modNode, modNode.Value);
             if (propName != null && propName == "name") prop = modNode.Name;
             if (propName != null && propName == "type") prop = modNode.NodeType.ToString();
             if (propName != null && propName == "path")
             {
                 XmlPath xp = new XmlPath(modNode);
                 if (xp.isValid()) prop = xp.Path;
                 else prop = null;
             }
             s += prop;
         }
         else s += "#NoSelection#";
     }
     var.Set = s;
     string when = XmlFiler.getAttribute(xn, "when");
     string add = XmlFiler.getAttribute(xn, "add");
     if (add != null) var.Add = add;
     if (var.Set == null && when == null)
     { // if there is a select/when then don't complain if the select found nothing
         Logger.getOnly().isNotNull(var.Add, "Var " + var.Id +
             @" set, select or add must result in a string or number value unless when=""exists"" is set.");
         if (select != null && select != "") var.Set = @"#not-"+when+@"#";
     }
     string exists = XmlFiler.getAttribute(xn, "file-exists");
     if (exists != null) var.FileExists = exists;
     string rest = XmlFiler.getAttribute(xn, "wait");
     if (rest != null) var.Rest = Convert.ToInt32(rest);
     AddInstruction(xn, var, con);
     return var;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Called to finish construction when an instruction has been instantiated by
 /// a factory and had its properties set.
 /// This can check the integrity of the instruction or perform other initialization tasks.
 /// </summary>
 /// <param name="xn">XML node describing the instruction</param>
 /// <param name="con">Parent xml node instruction</param>
 /// <returns></returns>
 public override bool finishCreation(XmlNode xn, Context con)
 {
     // finish factory construction
     m_log.isNotNull(Id, makeNameTag() + " instruction must have a id.");
     m_log.isTrue(Id != "", makeNameTag() + " instruction must have a non-empty id.");
     if (m_select != null && m_select != "")
     { // the variable can only have one text node or one other node assigned to it.
         m_log.isNotNull(con, "makeNameTag() + select has no context.");
         XmlNodeList pathNodes = Instructionator.selectNodes(con, m_select, "var" + Id);
         m_log.isNotNull(pathNodes, makeNameTag() + "var " + Id + " select='" + m_select + "' returned no result");
         if (pathNodes.Count > 0)
         { // append first node to set string
             XmlNode modNode = pathNodes.Item(0);
             string prop = null;
             // which property of the node to get?
             if (m_prop == null && modNode is XmlElement) m_prop = "path";
             if (m_prop == null) m_prop = "value";
             if (m_prop != null && m_prop == "value") prop = XmlPath.ResolveModelPath(modNode, modNode.Value);
             if (m_prop != null && m_prop == "name") prop = modNode.Name;
             if (m_prop != null && m_prop == "type") prop = modNode.NodeType.ToString();
             if (m_prop != null && m_prop == "path")
             {
                 XmlPath xp = new XmlPath(modNode);
                 if (xp.isValid()) prop = xp.Path;
                 else prop = null;
             }
             m_set += prop;
         }
         else m_set += "#NoSelection#";
     }
     if (Set == null && m_when == null)
     { // if there is a select/when then don't complain if the select found nothing
         m_log.isNotNull(Add, makeNameTag() + Id +
             @" set, select or add must result in a string or number value unless when=""exists"" is set.");
         if (m_select != null && m_select != "") Set = @"#not-" + m_when + @"#";
     }
     return true;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a variable to be referenced by other instruction attributes.
        /// </summary>
        /// <param name="xn">The XML repersentation of the instruction to be checked</param>
        /// <param name="con">The current context object</param>
        public static Var CreateVar(XmlNode xn, Context con)
        {
            Var var = new Var();

            var.Id = XmlFiler.getAttribute(xn, "id");
            Logger.getOnly().isNotNull(var.Id, "Var instruction must have a id.");
            Logger.getOnly().isTrue(var.Id != "", "Var instruction must have a non-empty id.");
            string s = XmlFiler.getAttribute(xn, "set");
            // select should be move to var.execute so it is dynamic!
            string select = XmlFiler.getAttribute(xn, "select");

            if (select != null && select != "")
            {             // the variable can only have one text node or one other node assigned to it.
                XmlNodeList pathNodes = selectNodes(con, select, "var" + var.Id);
                Logger.getOnly().isNotNull(pathNodes, "var " + var.Id + " select='" + select + "' returned no result");
                if (pathNodes.Count > 0)
                {                 // append first node to set string
                    XmlNode modNode = pathNodes.Item(0);
                    // which property of the node to get?
                    string prop     = null;
                    string propName = XmlFiler.getAttribute(xn, "prop");
                    if (propName == null && modNode is XmlElement)
                    {
                        propName = "path";
                    }
                    if (propName == null)
                    {
                        propName = "value";
                    }
                    if (propName != null && propName == "value")
                    {
                        prop = XmlPath.ResolveModelPath(modNode, modNode.Value);
                    }
                    if (propName != null && propName == "name")
                    {
                        prop = modNode.Name;
                    }
                    if (propName != null && propName == "type")
                    {
                        prop = modNode.NodeType.ToString();
                    }
                    if (propName != null && propName == "path")
                    {
                        XmlPath xp = new XmlPath(modNode);
                        if (xp.isValid())
                        {
                            prop = xp.Path;
                        }
                        else
                        {
                            prop = null;
                        }
                    }
                    s += prop;
                }
                else
                {
                    s += "#NoSelection#";
                }
            }
            var.Set = s;
            string when = XmlFiler.getAttribute(xn, "when");
            string add  = XmlFiler.getAttribute(xn, "add");

            if (add != null)
            {
                var.Add = add;
            }
            if (var.Set == null && when == null)
            {             // if there is a select/when then don't complain if the select found nothing
                Logger.getOnly().isNotNull(var.Add, "Var " + var.Id +
                                           @" set, select or add must result in a string or number value unless when=""exists"" is set.");
                if (select != null && select != "")
                {
                    var.Set = @"#not-" + when + @"#";
                }
            }
            string exists = XmlFiler.getAttribute(xn, "file-exists");

            if (exists != null)
            {
                var.FileExists = exists;
            }
            string rest = XmlFiler.getAttribute(xn, "wait");

            if (rest != null)
            {
                var.Rest = Convert.ToInt32(rest);
            }
            AddInstruction(xn, var, con);
            return(var);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Interprets a model path (selection), selects the node and returns its path.
 /// </summary>
 /// <param name="con">Current context of the action instruction.</param>
 /// <returns>A "path" string</returns>
 protected XmlPath SelectToPath(Context con, string modelPath)
 {
     if (modelPath == null || modelPath == "") return null;
     // only one node or attribute selected gets clicked
     m_log.paragraph(makeNameTag() + " creating one select-path target via " + modelPath);
     XmlNodeList pathNodes = Instructionator.selectNodes(con, modelPath, makeNameTag());
     m_log.isNotNull(pathNodes, makeNameTag() + " select-path='" + modelPath + "' returned no model node");
     m_log.isTrue(pathNodes.Count > 0, makeNameTag() + " select-path='" + modelPath + "' returned no nodes");
     // The modelPath 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
         m_log.isNotNull(pathNodes.Item(0).Value, makeNameTag() + " select-path='" + modelPath + "was a null string");
         m_log.isTrue(pathNodes.Item(0).Value != "", makeNameTag() + " select-path='" + modelPath + "was an empty string");
         string xPathImage = pathNodes.Item(0).Value;
         m_log.paragraph(makeNameTag() + " selected a text node with more XPATH: " + xPathImage);
         pathNodes = Instructionator.selectNodes(con, xPathImage, makeNameTag() + " selecting " + xPathImage);
         m_log.isNotNull(pathNodes, makeNameTag() + " selecting " + xPathImage + " from select='" + modelPath + "' returned no model node");
     }
     // Click the first node returned
     XmlNode node = pathNodes[0];
     XmlPath xPath = new XmlPath(node);
     if (!xPath.isValid()) m_log.fail(makeNameTag() + " XmlPath not constructable from " + node.OuterXml);
     return xPath;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Called to finish construction when an instruction has been instantiated by
 /// a factory and had its properties set.
 /// This can check the integrity of the instruction or perform other initialization tasks.
 /// </summary>
 /// <param name="xn">XML node describing the instruction</param>
 /// <param name="con">Parent xml node instruction</param>
 /// <returns></returns>
 public override bool finishCreation(XmlNode xn, Context con)
 {          // finish factory construction
     m_log.isNotNull(Id, makeNameTag() + " instruction must have a id.");
     m_log.isTrue(Id != "", makeNameTag() + " instruction must have a non-empty id.");
     if (m_select != null && m_select != "")
     {             // the variable can only have one text node or one other node assigned to it.
         m_log.isNotNull(con, "makeNameTag() + select has no context.");
         XmlNodeList pathNodes = Instructionator.selectNodes(con, m_select, "var" + Id);
         m_log.isNotNull(pathNodes, makeNameTag() + "var " + Id + " select='" + m_select + "' returned no result");
         if (pathNodes.Count > 0)
         {                 // append first node to set string
             XmlNode modNode = pathNodes.Item(0);
             string  prop    = null;
             // which property of the node to get?
             if (m_prop == null && modNode is XmlElement)
             {
                 m_prop = "path";
             }
             if (m_prop == null)
             {
                 m_prop = "value";
             }
             if (m_prop != null && m_prop == "value")
             {
                 prop = XmlPath.ResolveModelPath(modNode, modNode.Value);
             }
             if (m_prop != null && m_prop == "name")
             {
                 prop = modNode.Name;
             }
             if (m_prop != null && m_prop == "type")
             {
                 prop = modNode.NodeType.ToString();
             }
             if (m_prop != null && m_prop == "path")
             {
                 XmlPath xp = new XmlPath(modNode);
                 if (xp.isValid())
                 {
                     prop = xp.Path;
                 }
                 else
                 {
                     prop = null;
                 }
             }
             m_set += prop;
         }
         else
         {
             m_set += "#NoSelection#";
         }
     }
     if (Set == null && m_when == null)
     {             // if there is a select/when then don't complain if the select found nothing
         m_log.isNotNull(Add, makeNameTag() + Id +
                         @" set, select or add must result in a string or number value unless when=""exists"" is set.");
         if (m_select != null && m_select != "")
         {
             Set = @"#not-" + m_when + @"#";
         }
     }
     return(true);
 }