你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
DeviceManagementClient.GetGroupsAsync(String, RequestContext) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取所有设备组的列表。 始终先返回$default组。
public virtual Azure.AsyncPageable<BinaryData> GetGroupsAsync (string orderBy = default, Azure.RequestContext context = default);
abstract member GetGroupsAsync : string * Azure.RequestContext -> Azure.AsyncPageable<BinaryData>
override this.GetGroupsAsync : string * Azure.RequestContext -> Azure.AsyncPageable<BinaryData>
Public Overridable Function GetGroupsAsync (Optional orderBy As String = Nothing, Optional context As RequestContext = Nothing) As AsyncPageable(Of BinaryData)
参数
- orderBy
- String
对返回的组集进行排序。 可以按 groupId、deviceCount、createdDate、subgroupsWithNewUpdatesAvailableCount、subgroupsWithUpdatesInProgressCount 或 subgroupsOnLatestUpdateCount 排序。
- context
- RequestContext
请求上下文,它可以基于每个调用替代客户端管道的默认行为。
返回
AsyncPageable<T>包含对象列表的服务中的 BinaryData 。 集合中每个项目的正文架构的详细信息,请参阅下面的“备注”部分。
例外
服务返回了不成功状态代码。
示例
此示例演示如何调用 GetGroupsAsync 并分析结果。
var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);
await foreach (var data in client.GetGroupsAsync())
{
JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("groupId").ToString());
Console.WriteLine(result.GetProperty("groupType").ToString());
Console.WriteLine(result.GetProperty("createdDateTime").ToString());
}
此示例演示如何使用所有参数调用 GetGroupsAsync,以及如何分析结果。
var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);
await foreach (var data in client.GetGroupsAsync("<orderBy>"))
{
JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("groupId").ToString());
Console.WriteLine(result.GetProperty("groupType").ToString());
Console.WriteLine(result.GetProperty("createdDateTime").ToString());
Console.WriteLine(result.GetProperty("deviceCount").ToString());
Console.WriteLine(result.GetProperty("subgroupsWithNewUpdatesAvailableCount").ToString());
Console.WriteLine(result.GetProperty("subgroupsWithUpdatesInProgressCount").ToString());
Console.WriteLine(result.GetProperty("subgroupsWithOnLatestUpdateCount").ToString());
Console.WriteLine(result.GetProperty("deployments")[0].ToString());
}
注解
下面是可分页响应中一项的 JSON 架构。
响应正文:
的 GroupsListValue
架构:
{
groupId: string, # Required. Group identity. This is created from the value of the ADUGroup tag in the Iot Hub's device/module twin or $default for devices with no tag.
groupType: "IoTHubTag" | "DefaultNoTag", # Required. Group type.
createdDateTime: string, # Required. Date and time when the update was created.
deviceCount: number, # Optional. The number of devices in the group.
subgroupsWithNewUpdatesAvailableCount: number, # Optional. The count of subgroups with new updates available.
subgroupsWithUpdatesInProgressCount: number, # Optional. The count of subgroups with updates in progress.
subgroupsWithOnLatestUpdateCount: number, # Optional. The count of subgroups with devices on the latest update.
deployments: [string], # Optional. The active deployment Ids for the group
}