예제 #1
0
        /// <summary>
        /// Gets all of the message property keys
        /// </summary>
        /// <returns>Returns an array of strings representing the keys in the message properties</returns>
        public string[] GetPropertyKeys()
        {
            IsDisposed();

            UIntPtr mapHandle = IoTHubMessage_Properties(MessageHandle);
            IntPtr  keys;
            IntPtr  values;
            int     count;

            int res = IoTWrapper.Map_GetInternals(mapHandle, out keys, out values, out count);

            if (res != 0)
            {
                throw new InvalidOperationException("Failed to acquire message properties: " + res.ToString());
            }

            List <string> keyList = new List <string>(count);

            for (int i = 0; i < count; i++)
            {
                IntPtr work = IntPtr.Zero;

                work = Marshal.ReadIntPtr(keys, i * Marshal.SizeOf(work));
                string key = Marshal.PtrToStringAnsi(work);
                keyList.Add(key);
            }

            return(keyList.ToArray());
        }
예제 #2
0
        /// <summary>
        /// Close the connection to the IoT hub
        /// </summary>
        /// <returns>Zero if successful</returns>
        public IOTHUB_CLIENT_RESULT Close()
        {
            IsDisposed();

            IOTHUB_CLIENT_RESULT ret = (IOTHUB_CLIENT_RESULT)IoTWrapper.IoTHubClient_LL_Destroy(_iotHandle);

            return(ret);
        }
예제 #3
0
        /// <summary>
        /// Create an instance of the IoTConnection_LL object
        /// </summary>
        /// <param name="connectionString">Azure IoT device connection string</param>
        /// <param name="protocol">Required communicaton protocol</param>
        /// <param name="userContextCallback">User data</param>
        public IoTConnection_LL(string connectionString, Protocols protocol, UIntPtr userContextCallback)
        {
            _connectionString = connectionString;
            _protocol         = protocol;
            _iotHandle        = UIntPtr.Zero;

            _messageConfirmationCallback    = new MessageConfirmationCallback(confirmationCallback);
            _messageCallback                = new MessageCallback(messageReceived);
            _reportedStateCallback          = new ReportedStateCallback(reportedStateCallback);
            _deviceMethodCallback           = new DeviceMethodCallback(deviceMethodReceived);
            _deviceTwinCallback             = new DeviceTwinCallback(deviceTwinCallback);
            _clientConnectionStatusCallback = new ClientConnectionStatusCallback(clientConnectionStatusCallback);

            int ret;

            ret = IoTWrapper.platform_init();

            if (ret != 0)
            {
                throw new InvalidOperationException("Failed to intialize the platform: " + ret);
            }

            _iotHandle = IoTHubClient_LL_CreateFromConnectionString(_connectionString, getProtocolFunction(protocol));

            if (_iotHandle == UIntPtr.Zero)
            {
                throw new InvalidOperationException("Failed to create IoT handle");
            }

            ret = IoTHubClient_LL_SetMessageCallback(_iotHandle, _messageCallback, userContextCallback);

            if (ret != 0)
            {
                throw new IoTHubException("Failed to set message callback", ret);
            }

            ret = IoTHubClient_LL_SetDeviceMethodCallback(_iotHandle, _deviceMethodCallback, userContextCallback);

            if (ret != 0)
            {
                throw new IoTHubException("Failed to set device method callback", ret);
            }
            ret = IoTHubClient_LL_SetDeviceTwinCallback(_iotHandle, _deviceTwinCallback, userContextCallback);

            if (ret != 0)
            {
                throw new IoTHubException("Failed to set device twin callback", ret);
            }
            ret = IoTHubClient_LL_SetConnectionStatusCallback(_iotHandle, clientConnectionStatusCallback, UIntPtr.Zero);

            if (ret != 0)
            {
                throw new IoTHubException("Failed to set client connection status callback", ret);
            }
        }
예제 #4
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                // Nothing to do here - typically free managed objects
            }

            int ret;

            // Could check for errors here if we care
            ret       = (int)Close();
            ret       = IoTWrapper.platform_deinit();
            _disposed = true;
        }