Ejemplo n.º 1
0
        /// <summary>
        ///     Publish a message to the gateway message broker.
        /// </summary>
        /// <param name="message">Object representing the message to be published to the broker.</param>
        /// <returns></returns>
        public void Publish(Message message)
        {
            /* Codes_SRS_DOTNET_BROKER_04_004: [ Publish shall not catch exception thrown by ToByteArray. ] */
            /* Codes_SRS_DOTNET_BROKER_04_003: [ Publish shall call the Message.ToByteArray() method to get the Message object translated to byte array. ] */
            byte[] messageObject = message.ToByteArray();

            /* Codes_SRS_DOTNET_BROKER_04_005: [ Publish shall call the native method Module_DotNetHost_PublishMessage passing the broker and module value saved by it's constructor, the byte[] got from Message and the size of the byte array. ] */
            /* Codes_SRS_DOTNET_BROKER_04_006: [ If Module_DotNetHost_PublishMessage fails, Publish shall thrown an Application Exception with message saying that Broker Publish failed. ] */
            try
            {
                this.dotnetWrapper.PublishMessage((IntPtr)this.brokerHandle, (IntPtr)this.moduleHandle, messageObject);
            }
            catch (Exception e)
            {
                throw new ApplicationException("Failed to Publish Message.", e);
            }
        }