private string GetAsyncMessageFromInputQueue() { using (pipeInputQueue) { while (OK_TO_RUN) { try { using (Message msg = pipeInputQueue.Receive()) { ActiveXMessageFormatter mft = new ActiveXMessageFormatter(); string mess = mft.Read(msg) as string; return(mess); } } catch (MessageQueueException e) { // Handle no message arriving in the queue. if (e.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout) { } else { logger.Info($"Queue Error: {this.pipeInputQueue.Path} {e.StackTrace}"); } } catch (Exception ex) { logger.Trace(ex.Message); logger.Info(ex, "Unhandled MSMQ listen Error"); } } } return(null); }
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)); }
/// <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); }
public override void Execute(Context context) { _request = MessageBody.Load(context); context.LogXmlData("Message", _request, true); try { if (!UseTransactions) { _transactionType = MessageQueueTransactionType.None; } context.LogInfo("MSMQWriteStep about to write data to the queue: {0}", QueuePath); var queue = new MessageQueue(MSMQHelper.DeNormalizeQueueName(QueuePath)); var msg = new Message(); if (BodyType == VarEnum.VT_EMPTY) { msg.BodyStream = _request; } else { msg.BodyType = (int)BodyType; var formatter = new ActiveXMessageFormatter(); formatter.Write(msg, Common.StreamHelper.WriteStreamToString(_request)); } msg.UseDeadLetterQueue = true; if (!string.IsNullOrEmpty(CorrelationId)) { msg.CorrelationId = CorrelationId; } msg.AppSpecific = AppSpecific; queue.Send(msg, MessageLabel, _transactionType); } finally { if (null != _request) { _request.Close(); } } }
/// <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(); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { try { //search for the weatherLayer first ILayer layer = null; RSSWeatherLayerClass RSSLayer = null; if (m_pHookHelper.FocusMap.LayerCount == 0) { return; } IEnumLayer layers = m_pHookHelper.FocusMap.get_Layers(null, false); layers.Reset(); layer = layers.Next(); while (layer != null) { if (layer is RSSWeatherLayerClass) { RSSLayer = (RSSWeatherLayerClass)layer; break; } layer = layers.Next(); } //In case that the weather layer wasn't found,just return if (null == RSSLayer) { return; } //Launch the layer's properties Type typ; object obj; Guid[] g; // METHOD 1: Instantiating a COM object and displaying its property pages // ONLY WORKS ON TRUE COM OBJECTS! .NET objects that have rolled their own // ISpecifyPropertyPages implementation will error out when you try to cast // the instantiated object to your own ISpecifyPropertyPages implementation. // Get the typeinfo for the ActiveX common dialog control typ = Type.GetTypeFromProgID("MSComDlg.CommonDialog"); // Create an instance of the control. We pass it to the property frame function // so the property pages have an object from which to get current settings and apply // new settings. obj = Activator.CreateInstance(typ); // This handy function calls IPersistStreamInit->New on COM objects to initialize them ActiveXMessageFormatter.InitStreamedObject(obj); // Get the property pages for the control using the direct CAUUID method // This only works for true COM objects and I demonstrate it here only // to show how it is done. Use the static method // PropertyPage.GetPagesForType() method for real-world use. ISpecifyPropertyPages pag = (ISpecifyPropertyPages)obj; CAUUID cau = new CAUUID(0); pag.GetPages(ref cau); g = cau.GetPages(); // Instantiating a .NET object and displaying its property pages // WORKS ON ALL OBJECTS, .NET or COM // Create an instance of the .NET control, MyUserControl typ = Type.GetTypeFromProgID("RSSWeatherLayer.PropertySheet"); // Retrieve the pages for the control g = PropertyPage.GetPagesForType(typ); // Create an instance of the control that we can give to the property pages obj = Activator.CreateInstance(typ); //add the RSS layer to the property-sheet control ((PropertySheet)obj).RSSWatherLayer = RSSLayer; // Display the OLE Property page for the control object[] items = new object[] { obj }; PropertyPage.CreatePropertyFrame(IntPtr.Zero, 500, 500, "RSS Layer properties", items, g); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } }