Ejemplo n.º 1
0
 /// <summary>
 /// Instantiate an XPathInstruction
 /// </summary>
 /// <param name="_XPathQuery">The XPath query that is to be executed</param>
 /// <param name="promotion">Whether to write or promote the result</param>
 /// <param name="_XPathResultType">Whether the resulting nodes value, name, or namespace should be considered the result</param>
 /// <param name="propertyName">The name of the context property which will be affected</param>
 /// <param name="propertyNamespace">The namespace of the context property which will be affected</param>
 /// <param name="type">The type that the value should be cast to</param>
 /// <param name="exceptionIfNotFound"></param>
 public XPathInstruction(string _XPathQuery, ContextInstructionTypeEnum promotion, XPathResultTypeEnum _XPathResultType, string propertyName, string propertyNamespace, TypeEnum type, bool exceptionIfNotFound)
 {
     this._XPathQuery       = _XPathQuery;
     this.promotion         = promotion;
     this._XPathResultType  = _XPathResultType;
     this.propertyName      = propertyName;
     this.propertyNamespace = propertyNamespace;
     this.type = type;
     this.exceptionIfNotFound = exceptionIfNotFound;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the result of an XPath expression on the given message
        /// </summary>
        /// <param name="_XPathResultType">Whether the resulting node's value, name, or namspace should be treated as the result</param>
        /// <param name="_XPathQuery">The XPath Expression</param>
        /// <param name="exceptionIfNotFound">Whether or not to thrown an exception if the XPath expression does not evaluate</param>
        /// <returns>The result of an XPath expression on the given message</returns>
        public string GetXPathResult(XPathResultTypeEnum _XPathResultType, string _XPathQuery, bool exceptionIfNotFound)
        {
            XmlTextReader   xmlTextReader   = new XmlTextReader(base.InMsg.BodyPart.GetOriginalDataStream());
            XPathCollection xPathCollection = new XPathCollection();

            xPathCollection.Add(_XPathQuery);

            XPathReader xPathReader = new XPathReader(xmlTextReader, xPathCollection);
            bool        isFound     = false;
            string      value       = null;

            while (xPathReader.ReadUntilMatch())
            {
                if (xPathReader.Match(_XPathQuery))
                {
                    isFound = true;
                    switch (_XPathResultType)
                    {
                    case XPathResultTypeEnum.Name:
                        value = xPathReader.LocalName;
                        break;

                    case XPathResultTypeEnum.Namespace:
                        value = xPathReader.NamespaceURI;
                        break;

                    case XPathResultTypeEnum.Value:
                        value = xPathReader.ReadString();
                        break;
                    }
                }
            }

            if ((isFound == false) && (exceptionIfNotFound))
            {
                base.SetException(new Exception("No result found for XPath query - " + _XPathQuery));
            }

            base.InMsg.BodyPart.Data.Position = 0;
            return(value);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Setup an Instruction that will either promote or write a specified a value that is the result of an XPath Expression to a context property within any namespace
        /// </summary>
        /// <param name="propertyName">The name of the context property</param>
        /// <param name="propertyNamespace">The namespace of the context property</param>
        /// <param name="promotion">Whether to write or promote the context property</param>
        /// <param name="_XPathResultType">Whether the resulting node's value, name, or namspace should be treated as the result</param>
        /// <param name="_XPathQuery">The XPath Expression</param>
        /// <param name="type">The type to cast the value to</param>
        /// <param name="exceptionIfNotFound">Whether or not to thrown an exception if the XPath expression does not evaluate</param>
        public void SetContextPropertyFromXPathResult(string propertyName, string propertyNamespace, ContextInstructionTypeEnum promotion, XPathResultTypeEnum _XPathResultType, string _XPathQuery, TypeEnum type, bool exceptionIfNotFound)
        {
            if (setContextPropertyFromXPathResultPipelineInstruction == null)
            {
                setContextPropertyFromXPathResultPipelineInstruction = new SetContextPropertyFromXPathResultPipelineInstruction();
                base.AddInstruction(setContextPropertyFromXPathResultPipelineInstruction);
            }

            setContextPropertyFromXPathResultPipelineInstruction.AddXPathInstruction(new XPathInstruction(_XPathQuery, promotion, _XPathResultType, propertyName, propertyNamespace, type, exceptionIfNotFound));
        }