예제 #1
0
        /// <summary>
        /// Returns device connection string
        /// </summary>
        /// <param name="service"></param>
        /// <param name="deviceId"></param>
        /// <param name="primary"></param>
        /// <returns></returns>
        public static async Task <ConnectionString> GetConnectionStringAsync(
            this IIoTHubTwinServices service, string deviceId, bool primary = true)
        {
            var model = await service.GetRegistrationAsync(deviceId);

            if (model == null)
            {
                throw new ResourceNotFoundException("Could not find " + deviceId);
            }
            return(ConnectionString.CreateDeviceConnectionString(service.HostName,
                                                                 deviceId, primary ?
                                                                 model.Authentication.PrimaryKey : model.Authentication.SecondaryKey));
        }