예제 #1
0
		private Message[] PeekMessages(MessageQueue activeQueue, bool blnDynamicConnection, MessageFormat eMessageFormat, System.Type CustomType)
		{
			Message objMessage;
			Message[] arrCurrentMessages = new Message[0];
			Message[] arrCopyOfMessages = null;
			IMessageFormatter objFormatter = null ;
			MessagePropertyFilter objMessagePropertyFilter = new MessagePropertyFilter();
			int intArrayIndex;

			// Message Formatter
			switch (eMessageFormat)
			{
				case MessageFormat.XMLSerialize:
					if (CustomType == null)
					{
						objFormatter = new XmlMessageFormatter();
					}
					else
					{
					// objFormatter = new XmlMessageFormatter(new Type() [CustomType]);
					}

					break;
				case MessageFormat.ActiveXSerialize:
					objFormatter = new ActiveXMessageFormatter();
					break;
				case MessageFormat.BinarySerialize:
					objFormatter = new BinaryMessageFormatter();
					break;
			}

			// Messages in Private Queue
			// Ensure these properties are received (CorrelationID defaults to False)
			objMessagePropertyFilter.SetDefaults();
			objMessagePropertyFilter.CorrelationId = true;
			objMessagePropertyFilter.AppSpecific = true;
			objMessagePropertyFilter.ArrivedTime = true;
			activeQueue.MessageReadPropertyFilter = objMessagePropertyFilter;

			// Message Formatter
			activeQueue.Formatter = objFormatter;

			// Dynamic Connection whilst gathering messages
			if (blnDynamicConnection == true)
			{
				IEnumerator objMessageEnumerator = activeQueue.GetEnumerator();
				intArrayIndex = 0;
				while (objMessageEnumerator.MoveNext())
				{
					objMessage = (Message) objMessageEnumerator.Current;
					if (intArrayIndex > 0)
					{
						arrCopyOfMessages = new Message[intArrayIndex];
						arrCurrentMessages.CopyTo(arrCopyOfMessages,0);
						arrCurrentMessages=arrCopyOfMessages;
					}
					arrCurrentMessages[intArrayIndex] = objMessage;
					intArrayIndex += 1;
				}
			}
			else // Snapshot of messages currently in Queue
			{
				arrCurrentMessages = null ;
				try
				{
					arrCurrentMessages = activeQueue.GetAllMessages();
				}
				catch (System.Messaging.MessageQueueException excM)
				{
					throw excM;
				}
			}

			return arrCurrentMessages;

		}
예제 #2
0
		/// <summary>
		/// Attempts to extract the content of a message in string format.
		/// </summary>
		/// <param name="message">Message to extract.</param>
		/// <param name="usedMessageFormatterType">Informs which formatter was used to extract the message.</param>
		/// <returns>A string if successful else null.</returns>
		private string ExtractMessageContent(System.Messaging.Message message)
		{
			string result = null;

			//create an array of formatters, ordered as we are going to attempt to use them
			IMessageFormatter[] formatterArray = new IMessageFormatter[3];
			formatterArray[0] = new ActiveXMessageFormatter();
			formatterArray[1] = new XmlMessageFormatter();
			formatterArray[2] = new BinaryMessageFormatter();

			//attempt to read the message body using the different formatters			
			foreach (IMessageFormatter formatter in formatterArray)
			{				
				try
				{
					//attempt to extract the message
					message.Formatter = formatter;					
					if (message.Formatter is ActiveXMessageFormatter)
						result = Convert.ToString(message.Body);
					else
					{
						message.BodyStream.Position=0;									
						StreamReader sr = new StreamReader(message.BodyStream);	//do not dispose this stream else the underlying stream will close				
						result = sr.ReadToEnd(); 				
					}
					
					//message has been successfully extracted (else we would have thrown an exception)					

					//check the xml formatter has given us valid xml
					if (!(formatter is XmlMessageFormatter && !IsXml(result)))						
						break;
				}
				catch 
				{
					result = null;
				}
			}
			if (result == null)
				result = Locale.UserMessages.UnableToDisplayBinaryMessage;
			
			return result;
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="ActiveXMessageConverter"/> class.
 /// </summary>
 /// <param name="messageFormatter">The message formatter.</param>
 public ActiveXMessageConverter(ActiveXMessageFormatter messageFormatter)
 {
     this.messageFormatter = messageFormatter;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ActiveXMessageConverter"/> class.
 /// </summary>
 public ActiveXMessageConverter()
 {
     messageFormatter = new ActiveXMessageFormatter();
 }
예제 #5
0
        private IMessageFormatter SetQueueFormatterAndProperties(MessageQueue activeQueue, eMessageFormat messageFormat, Type customType)
        {
            IMessageFormatter objFormatter = null;
            MessagePropertyFilter objMessagePropertyFilter = new MessagePropertyFilter();

            // Message Formatter
            switch (messageFormat)
            {
                case eMessageFormat.XMLSerialize:
                    if (customType == null)
                    {
                        objFormatter = new XmlMessageFormatter();
                    }
                    else
                    {
                        objFormatter = new XmlMessageFormatter(new Type[] { customType });
                    }

                    break;
                case eMessageFormat.ActiveXSerialize:
                    objFormatter = new ActiveXMessageFormatter();
                    break;
                case eMessageFormat.BinarySerialize:
                    objFormatter = new BinaryMessageFormatter();
                    break;
            }

            // Messages in Private Queue
            // Ensure these properties are received (CorrelationID defaults to False)
            objMessagePropertyFilter.SetDefaults();
            objMessagePropertyFilter.CorrelationId = true;
            objMessagePropertyFilter.AppSpecific = true;
            objMessagePropertyFilter.ArrivedTime = true;
            activeQueue.MessageReadPropertyFilter = objMessagePropertyFilter;

            // Message Formatter
            activeQueue.Formatter = objFormatter;

            return objFormatter;
        }
 public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
 {
     object[] values = new object[4];
     values[0] = new ActiveXMessageFormatter();
     values[1] = new BinaryMessageFormatter();
     values[2] = new XmlMessageFormatter();
     return new TypeConverter.StandardValuesCollection(values);
 }