Пример #1
0
 public void SetUp()
 {
     cm.Clear(false);
     cm.LoadFile(CONF);
     cm.LoadFile("../../test_files/accuracyTests/ObjectFactory.xml");
     parser           = new XmlMessageParser("TopCoder.MSMQ.MessageProcessingWorkflow.Parsers.XmlMessageParser");
     persistence      = new ConversationManagerPersistence();
     configParameters = new List <IMessageTypeDetector>();
     configParameters.Add(new XmlMessageTypeDetector("type.detector.XmlMessageTypeDetector"));
     xmlMessage = new XmlDocument();
 }
Пример #2
0
        /// <summary>
        /// Reads the message type from message and creates a MessageType instance.
        /// </summary>
        /// <param name="messageTypeNode">The MessageType node in the recipe file.</param>
        /// <param name="message">The message from which to extract the Message type.</param>
        /// <returns>The MessageType instance created</returns>
        /// <exception cref="MessageParsingException">
        /// If xpath attribute in messageTypeNode is not found or is empty string.
        /// If no node is found in the message at the specified xpath in recipe.
        /// </exception>
        /// <exception cref="MessageValidationException">
        /// If MessageType constructor throws exception.
        /// </exception>
        private static MessageType CreateMessageType(XmlNode messageTypeNode, XmlDocument message)
        {
            //Get the xpath expression to run on the message for finding message type.
            string xpathNodeVal = GetXmlAttributeValue(messageTypeNode, "XPath", true, true);

            //Get the node containing the message type information
            XmlNode typeNode = SelectSingleNode(message, xpathNodeVal, true, "message");

            //Get the message type value
            string typeName = typeNode.InnerText.Trim();

            //Create MessageType
            try
            {
                //Create MessageType using persistence.
                ConversationManagerPersistence persistence = new ConversationManagerPersistence();
                return(persistence.FindOrCreateMessageType(typeName));
            }
            catch (Exception e)
            {
                throw new MessageValidationException("Could not load MessageType from persistence.", e);
            }
        }
Пример #3
0
        /// <summary>
        /// Creates a MessageQueue instance based on a SourceMessageQueue or DestinationMessageQueue node
        /// specified in a recipe file.
        /// </summary>
        /// <param name="messageQueueNode">The node specified in the recipe</param>
        /// <param name="message">The message to read information from.</param>
        /// <param name="isSourceQueue">Whether this method has been called for creating the source queue
        /// or the destination queue.</param>
        /// <returns>A MessageQueue instance read from the message</returns>
        /// <exception cref="MessageParsingException">
        /// If XPath attribute of messageQueueNode is null or empty.
        /// </exception>
        /// <exception cref="MessageValidationException">
        /// If exception is thrown by MessageQueue constructor.
        /// </exception>
        private static MessageQueue ReadMessageQueue(XmlNode messageQueueNode, XmlDocument message, bool isSourceQueue)
        {
            //XPath must be present for SourceQueue as it is not optional
            string xPath = GetXmlAttributeValue(messageQueueNode, "XPath", isSourceQueue, isSourceQueue);

            //Node must be found for SourceQueue as it is not optional
            XmlNode queueNodeFound = SelectSingleNode(message, xPath, isSourceQueue, "message");

            string name = null;

            if (isSourceQueue || (!isSourceQueue && queueNodeFound != null))
            {
                name = queueNodeFound.InnerText.Trim();
            }

            //Throw exception if name is empty and it is a sourceQueue
            if (isSourceQueue && name.Equals(String.Empty))
            {
                throw new MessageParsingException("Name of SourceQueue cannot be empty string.");
            }
            //return null if this is destination queue.
            else if (!isSourceQueue && name.Equals(String.Empty))
            {
                return(null);
            }

            //Exceptions thrown by FindMessageQueue must be caught and rethrown as ConfigurationException
            try
            {
                ConversationManagerPersistence persistence = new ConversationManagerPersistence();
                return(persistence.FindMessageQueue(name));
            }
            catch (Exception e)
            {
                throw new ConfigurationException("Could not load MessageQueue from persistence", e);
            }
        }