/// <summary>
        /// Constructor for IotHub service implementation
        /// </summary>
        /// <param name="hubConnectionString"></param>
        public IoTHubService(ConnectionString hubConnectionString)
        {
            _hubConnectionString = hubConnectionString;

            _updateQueue = new BufferBlock <Tuple <INameRecord, NameServiceOperation> >(
                new DataflowBlockOptions {
                NameFormat         = "Update (in IoTHubService) Id={1}",
                EnsureOrdered      = false,
                MaxMessagesPerTask = DataflowBlockOptions.Unbounded,
                CancellationToken  = _open.Token
            });
            _listeners = new BroadcastBlock <Tuple <INameRecord, NameServiceEvent> >(null,
                                                                                     new DataflowBlockOptions {
                NameFormat         = "Notify (in IoTHubService) Id={1}",
                EnsureOrdered      = false,
                MaxMessagesPerTask = DataflowBlockOptions.Unbounded,
                CancellationToken  = _open.Token
            });

            Write = DataflowBlockEx.Encapsulate(_updateQueue, _listeners);

            _registryLoaded = new TaskCompletionSource <bool>();
            _cache          = new ConcurrentDictionary <Reference, IoTHubRecord>();
            _cacheWorker    = CacheWorker();
        }
        /// <summary>
        /// Create service
        /// </summary>
        /// <param name="connectionString"></param>
        public IoTHubService(string connectionString = null)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                connectionString = Environment.GetEnvironmentVariable("_HUB_CS");
            }
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentException("You must provide the iothubowner connection " +
                                            "string, which can be obtained from the Azure IoT Hub portal. You must " +
                                            "then either initialize the DefaultProvider class, or set the _HUB_CS " +
                                            "environment variable.");
            }
            _hubConnectionString = ConnectionString.Parse(connectionString);

            _updateQueue = new BufferBlock <Tuple <INameRecord, NameServiceOperation> >(
                new DataflowBlockOptions {
                NameFormat         = "Update (in IoTHubService) Id={1}",
                EnsureOrdered      = false,
                MaxMessagesPerTask = DataflowBlockOptions.Unbounded,
                CancellationToken  = _open.Token
            });
            _listeners = new BroadcastBlock <Tuple <INameRecord, NameServiceEvent> >(null,
                                                                                     new DataflowBlockOptions {
                NameFormat         = "Notify (in IoTHubService) Id={1}",
                EnsureOrdered      = false,
                MaxMessagesPerTask = DataflowBlockOptions.Unbounded,
                CancellationToken  = _open.Token
            });

            Write = DataflowBlockEx.Encapsulate(_updateQueue, _listeners);

            _registryLoaded = new TaskCompletionSource <bool>();
            _cache          = new ConcurrentDictionary <Reference, IoTHubRecord>();
            _cacheWorker    = CacheWorker();
        }