你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

DeviceManagementClient.GetGroups(String, RequestContext) 方法

定义

获取所有设备组的列表。 始终首先返回$default组。

public virtual Azure.Pageable<BinaryData> GetGroups (string orderBy = default, Azure.RequestContext context = default);
abstract member GetGroups : string * Azure.RequestContext -> Azure.Pageable<BinaryData>
override this.GetGroups : string * Azure.RequestContext -> Azure.Pageable<BinaryData>
Public Overridable Function GetGroups (Optional orderBy As String = Nothing, Optional context As RequestContext = Nothing) As Pageable(Of BinaryData)

参数

orderBy
String

对返回的组集进行排序。 可以按 groupId、deviceCount、createdDate、subgroupsWithNewUpdatesAvailableCount、subgroupsWithUpdatesInProgressCount 或 subgroupsOnLatestUpdateCount 排序。

context
RequestContext

请求上下文,可以基于每个调用替代客户端管道的默认行为。

返回

Pageable<T>包含对象列表的服务中的 BinaryData 。 集合中每个项的正文架构的详细信息,请参阅下面的“备注”部分。

例外

服务返回了非成功状态代码。

示例

此示例演示如何调用 GetGroups 并分析结果。

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);

foreach (var data in client.GetGroups())
{
    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());
}

此示例演示如何使用所有参数调用 GetGroups,以及如何分析结果。

var credential = new DefaultAzureCredential();
var endpoint = new Uri("<https://my-service.azure.com>");
var client = new DeviceManagementClient(endpoint, "<instanceId>", credential);

foreach (var data in client.GetGroups("<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
            }

适用于