public async Task EnumerateRegistrationsInGroup(QuerySpecification querySpecification, EnrollmentGroup group) { _logger.LogInformation($"Creating a query for registrations within group '{group.EnrollmentGroupId}'..."); using (Query registrationQuery = _provisioningServiceClient.CreateEnrollmentGroupRegistrationStateQuery(querySpecification, group.EnrollmentGroupId)) { _logger.LogInformation($"Querying the next registrations within group '{group.EnrollmentGroupId}'..."); QueryResult registrationQueryResult = await registrationQuery.NextAsync().ConfigureAwait(false); _logger.LogInformation($"{registrationQueryResult}"); } }
/// <summary> /// Enumerates all registrations within an enrollment group. /// </summary> /// <param name="provisioningServiceClient">The ProvisioningServiceClient object.</param> /// <param name="querySpecification">The query specification.</param> /// <param name="group">The EnrollmentGroup object.</param> /// <returns></returns> private static async Task EnumerateRegistrationsInGroup(ProvisioningServiceClient provisioningServiceClient, QuerySpecification querySpecification, EnrollmentGroup group) { Console.WriteLine($"\nCreating a query for registrations within group '{group.EnrollmentGroupId}'..."); using (Query registrationQuery = provisioningServiceClient.CreateEnrollmentGroupRegistrationStateQuery(querySpecification, group.EnrollmentGroupId)) { Console.WriteLine($"\nQuerying the next registrations within group '{group.EnrollmentGroupId}'..."); QueryResult registrationQueryResult = await registrationQuery.NextAsync().ConfigureAwait(false); Console.WriteLine(registrationQueryResult); } }
public override void ExecuteCmdlet() { ProvisioningServiceDescription provisioningServiceDescription; if (ParameterSetName.Equals(InputObjectParameterSet)) { this.ResourceGroupName = this.DpsObject.ResourceGroupName; this.DpsName = this.DpsObject.Name; provisioningServiceDescription = IotDpsUtils.ConvertObject <PSProvisioningServiceDescription, ProvisioningServiceDescription>(this.DpsObject); } else { if (ParameterSetName.Equals(ResourceIdParameterSet)) { this.ResourceGroupName = IotDpsUtils.GetResourceGroupName(this.ResourceId); this.DpsName = IotDpsUtils.GetIotDpsName(this.ResourceId); } provisioningServiceDescription = GetIotDpsResource(this.ResourceGroupName, this.DpsName); } IEnumerable <SharedAccessSignatureAuthorizationRuleAccessRightsDescription> authPolicies = this.IotDpsClient.IotDpsResource.ListKeys(this.DpsName, this.ResourceGroupName); SharedAccessSignatureAuthorizationRuleAccessRightsDescription policy = IotDpsUtils.GetPolicy(authPolicies, PSAccessRightsDescription.EnrollmentWrite); PSIotDpsConnectionString psIotDpsConnectionString = IotDpsUtils.ToPSIotDpsConnectionString(policy, provisioningServiceDescription.Properties.ServiceOperationsHostName); ProvisioningServiceClient client = ProvisioningServiceClient.CreateFromConnectionString(psIotDpsConnectionString.PrimaryConnectionString); if ((!this.IsParameterBound(c => c.RegistrationId) && !this.IsParameterBound(c => c.EnrollmentId)) || (this.IsParameterBound(c => c.RegistrationId) && this.IsParameterBound(c => c.EnrollmentId))) { throw new ArgumentException("Please provide either RegistrationId or EnrollmentId."); } if (this.IsParameterBound(c => c.RegistrationId)) { DeviceRegistrationState result = client.GetDeviceRegistrationStateAsync(this.RegistrationId).GetAwaiter().GetResult(); this.WriteObject(IotDpsUtils.ToPSDeviceRegistrationState(result)); } if (this.IsParameterBound(c => c.EnrollmentId)) { string query = this.IsParameterBound(c => c.Query) ? this.Query : "select * from enrollments"; QueryResult results = client.CreateEnrollmentGroupRegistrationStateQuery(new QuerySpecification(query), this.EnrollmentId).NextAsync().GetAwaiter().GetResult(); this.WriteObject(IotDpsUtils.ToPSDeviceRegistrationStates(results.Items), true); } }