DeviceManagementClient.GetDevicesAsync(String, RequestContext) メソッド

定義

IoT Hubの Device Update に接続されているデバイスの一覧を取得します。

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

パラメーター

filter
String

返されるデバイスのセットを制限します。 GroupId、DeviceClassId、または GroupId と DeploymentStatus でフィルター処理できます。 DeploymentStatus eq null を使用して、展開状態のない (デプロイされていない) デバイスに対してクエリを実行します。

context
RequestContext

要求コンテキスト。これは、呼び出しごとにクライアント パイプラインの既定の動作をオーバーライドできます。

戻り値

AsyncPageable<T>オブジェクトの一覧を含むサービスの BinaryData 。 コレクション内の各項目の本文スキーマの詳細については、以下の「解説」セクションを参照してください。

例外

サービスから成功以外の状態コードが返されました。

このサンプルでは、GetDevicesAsync を呼び出して結果を解析する方法を示します。

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.GetDevicesAsync())
{
    JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("deviceId").ToString());
    Console.WriteLine(result.GetProperty("deviceClassId").ToString());
    Console.WriteLine(result.GetProperty("onLatestUpdate").ToString());
}

このサンプルでは、すべてのパラメーターを使用して GetDevicesAsync を呼び出す方法と、結果を解析する方法を示します。

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.GetDevicesAsync("<filter>"))
{
    JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("deviceId").ToString());
    Console.WriteLine(result.GetProperty("moduleId").ToString());
    Console.WriteLine(result.GetProperty("deviceClassId").ToString());
    Console.WriteLine(result.GetProperty("groupId").ToString());
    Console.WriteLine(result.GetProperty("lastAttemptedUpdate").GetProperty("updateId").GetProperty("provider").ToString());
    Console.WriteLine(result.GetProperty("lastAttemptedUpdate").GetProperty("updateId").GetProperty("name").ToString());
    Console.WriteLine(result.GetProperty("lastAttemptedUpdate").GetProperty("updateId").GetProperty("version").ToString());
    Console.WriteLine(result.GetProperty("lastAttemptedUpdate").GetProperty("description").ToString());
    Console.WriteLine(result.GetProperty("lastAttemptedUpdate").GetProperty("friendlyName").ToString());
    Console.WriteLine(result.GetProperty("deploymentStatus").ToString());
    Console.WriteLine(result.GetProperty("installedUpdate").GetProperty("updateId").GetProperty("provider").ToString());
    Console.WriteLine(result.GetProperty("installedUpdate").GetProperty("updateId").GetProperty("name").ToString());
    Console.WriteLine(result.GetProperty("installedUpdate").GetProperty("updateId").GetProperty("version").ToString());
    Console.WriteLine(result.GetProperty("installedUpdate").GetProperty("description").ToString());
    Console.WriteLine(result.GetProperty("installedUpdate").GetProperty("friendlyName").ToString());
    Console.WriteLine(result.GetProperty("onLatestUpdate").ToString());
    Console.WriteLine(result.GetProperty("lastDeploymentId").ToString());
    Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("resultCode").ToString());
    Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("extendedResultCode").ToString());
    Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("resultDetails").ToString());
    Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("update").GetProperty("updateId").GetProperty("provider").ToString());
    Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("update").GetProperty("updateId").GetProperty("name").ToString());
    Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("update").GetProperty("updateId").GetProperty("version").ToString());
    Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("update").GetProperty("description").ToString());
    Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("update").GetProperty("friendlyName").ToString());
    Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("description").ToString());
    Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("resultCode").ToString());
    Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("extendedResultCode").ToString());
    Console.WriteLine(result.GetProperty("lastInstallResult").GetProperty("stepResults")[0].GetProperty("resultDetails").ToString());
}

注釈

ページング可能な応答の 1 つの項目の JSON スキーマを次に示します。

応答本文:

DevicesListValueスキーマ:

{
              deviceId: string, # Required. Device identity.
              moduleId: string, # Optional. Device module identity.
              deviceClassId: string, # Required. Device class identity.
              groupId: string, # Optional. Device group identity.
              lastAttemptedUpdate: {
                updateId: {
                  provider: string, # Required. Update provider.
                  name: string, # Required. Update name.
                  version: string, # Required. Update version.
                }, # Required. Update identifier.
                description: string, # Optional. Update description.
                friendlyName: string, # Optional. Friendly update name.
              }, # Optional. The update that device last attempted to install.
              deploymentStatus: "Succeeded" | "InProgress" | "Canceled" | "Failed", # Optional. State of the device in its last deployment.
              installedUpdate: UpdateInfo, # Optional. Currently installed update on device.
              onLatestUpdate: boolean, # Required. Boolean flag indicating whether the latest update (the best compatible update for the device's device class and group) is installed on the device
              lastDeploymentId: string, # Optional. The deployment identifier for the last deployment to the device
              lastInstallResult: {
                resultCode: number, # Required. Install result code.
                extendedResultCode: number, # Required. Install extended result code
                resultDetails: string, # Optional. A string containing further details about the install result
                stepResults: [
                  {
                    update: UpdateInfo, # Optional. The update that this step installs if it is of reference type.
                    description: string, # Optional. Step description.
                    resultCode: number, # Required. Install result code.
                    extendedResultCode: number, # Required. Install extended result code
                    resultDetails: string, # Optional. A string containing further details about the install result
                  }
                ], # Optional. Array of step results
              }, # Optional. Last install result.
            }

適用対象