Exemple #1
0
        /// <summary>
        /// Ctor for the class.
        /// </summary>
        public IotEdgeHubCommunication()
        {
            // connect to IoT Edge hub
            Logger.Information($"Create module client using '{HubProtocol}' for communication.");
            IHubClient hubClient = HubClient.CreateModuleClientFromEnvironment(HubProtocol);

            if (!InitHubCommunicationAsync(hubClient).Result)
            {
                string errorMessage = $"Cannot create module client. Exiting...";
                Logger.Fatal(errorMessage);
                throw new Exception(errorMessage);
            }
        }
        /// <summary>
        /// Ctor for the class.
        /// </summary>
        public IotEdgeHubCommunication(bool registerMethodHandlers, bool listenMessages)
        {
            // connect to IoT Edge hub
            Logger.Information($"Create module client using '{HubProtocol}' for communication.");
            _hubClient = HubClient.CreateModuleClientFromEnvironment(HubProtocol, Logger);

            if (!InitHubCommunicationAsync(_hubClient, registerMethodHandlers, listenMessages).Result)
            {
                string errorMessage = $"Cannot create module client. Exiting...";
                Logger.Fatal(errorMessage);
                throw new Exception(errorMessage);
            }
        }