<commit_before>.NET bindings for Azure IoT Gateway Modules - Message Bus Class
===============================================================

Overview
--------


This document specifies the requirements for the .NET Message Bus Class which is part of Microsoft.Azure.IoT.Gateway namespace. 
An object of this class represents the bus, to where a message is going to be published. 
More details on the [high level design](./dotnet_bindings_hld.md).

Types
-----
```C#
namespace Microsoft.Azure.IoT.Gateway
{
    /// <summary> Object that represents the bus, to where a messsage is going to be published </summary>
    public class MessageBus
    {
        private long msgBusHandle;

        /// <summary>
        ///     Constructor for MessageBus. This is used by the Native level, the .NET User will receive an object of this. 
        /// </summary>
        /// <param name="msgBus">Adress of the native created msgBus, used internally.</param>
        public MessageBus(long msgBus);

        /// <summary>
        ///     Publish a message into the gateway message bus. 
        /// </summary>
        /// <param name="message">Object representing the message to be published into the bus.</param>
        /// <returns></returns>
        public void Publish(Message message);
    }
}
```

MessageBus Constructor
----------------------
```C#
public MessageBus(long msgBus);
```
Creates a .NET Object of type Microsoft.Azure.IoT.Gateway.MessageBus

**SRS_DOTNET_MESSAGEBUS_04_001: [** If msgBus is <= 0, MessageBus constructor shall throw a new ArgumentException **]**

**SRS_DOTNET_MESSAGEBUS_04_002: [** If msgBus is greater than 0, MessageBus constructor shall save this value and succeed. **]**


Publish
-------
```C#
public void Publish(Message message);
```

Gets a byte array from a Message object and calls exported native function to publish a message. 

**SRS_DOTNET_MESSAGEBUS_04_003: [** Publish shall call the Message.ToByteArray() method to get the Message object translated to byte array.  **]**

**SRS_DOTNET_MESSAGEBUS_04_004: [** Publish shall not catch exception thrown by ToByteArray.  **]**

**SRS_DOTNET_MESSAGEBUS_04_005: [** Publish shall call the native method `dotnetHost_PublishMessage` passing the msgBus value saved by it's constructor, the byte[] got from Message and the size of the byte array. **]**

**SRS_DOTNET_MESSAGEBUS_04_006: [** If `Module_DotNetHost_PublishMessage` fails, Publish shall thrown an Application Exception with message saying that MessageBus Publish failed. **]**<commit_msg>Added Module Handle to Message Bus Constructor.<commit_after>.NET bindings for Azure IoT Gateway Modules - Message Bus Class
===============================================================

Overview
--------


This document specifies the requirements for the .NET Message Bus Class which is part of Microsoft.Azure.IoT.Gateway namespace. 
An object of this class represents the bus, to where a message is going to be published. 
More details on the [high level design](./dotnet_bindings_hld.md).

Types
-----
```C#
namespace Microsoft.Azure.IoT.Gateway
{
    /// <summary> Object that represents the bus, to where a messsage is going to be published </summary>
    public class MessageBus
    {
        private long msgBusHandle;

        private long moduleHandle

        /// <summary>
        ///     Constructor for MessageBus. This is used by the Native level, the .NET User will receive an object of this. 
        /// </summary>
        /// <param name="msgBus">Adress of the native created msgBus, used internally.</param>
        /// <param name="sourceModuleHandle">Adress of the native moduleHandle, used internally.</param>
        public MessageBus(long msgBus, long moduleHandle);

        /// <summary>
        ///     Publish a message into the gateway message bus. 
        /// </summary>
        /// <param name="message">Object representing the message to be published into the bus.</param>
        /// <returns></returns>
        public void Publish(Message message);
    }
}
```

MessageBus Constructor
----------------------
```C#
public MessageBus(long msgBus);
```
Creates a .NET Object of type Microsoft.Azure.IoT.Gateway.MessageBus

**SRS_DOTNET_MESSAGEBUS_04_001: [** If msgBus is <= 0, MessageBus constructor shall throw a new ArgumentException **]**

**SRS_DOTNET_MESSAGEBUS_04_007: [** If moduleHandle is <= 0, MessageBus constructor shall throw a new ArgumentException  **]**

**SRS_DOTNET_MESSAGEBUS_04_002: [** If msgBus and moduleHandle is greater than 0, MessageBus constructor shall save this value and succeed. **]**


Publish
-------
```C#
public void Publish(Message message);
```

Gets a byte array from a Message object and calls exported native function to publish a message. 

**SRS_DOTNET_MESSAGEBUS_04_003: [** Publish shall call the Message.ToByteArray() method to get the Message object translated to byte array.  **]**

**SRS_DOTNET_MESSAGEBUS_04_004: [** Publish shall not catch exception thrown by ToByteArray.  **]**

**SRS_DOTNET_MESSAGEBUS_04_005: [** Publish shall call the native method `Module_DotNetHost_PublishMessage` passing the msgBus and moduleHandle  value saved by it's constructor, the byte[] got from Message and the size of the byte array. **]**

**SRS_DOTNET_MESSAGEBUS_04_006: [** If `Module_DotNetHost_PublishMessage` fails, Publish shall thrown an Application Exception with message saying that MessageBus Publish failed. **]**
{'fraction_non_alphanumeric': 0.12829007914595988, 'fraction_numerical': 0.012884226026136572, 'mean_word_length': 3.589527027027027, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6271942', 'n_tokens_mistral': 1499, 'n_tokens_neox': 1424, 'n_words': 575}