Partager via


DeviceManagementClient.GetDeviceClasses(String, RequestContext) Méthode

Définition

Obtient une liste de toutes les classes d’appareils (ensembles d’appareils compatibles avec les mêmes mises à jour en fonction des propriétés d’ID de modèle et de compat signalées dans l’interface Device Update PnP dans IoT Hub) pour tous les appareils connectés à Device Update pour IoT Hub.

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

Paramètres

filter
String

Restreint l’ensemble des classes d’appareil retournées. Vous pouvez filtrer le nom convivial.

context
RequestContext

Contexte de demande, qui peut remplacer les comportements par défaut du pipeline client par appel.

Retours

à Pageable<T> partir du service contenant une liste d’objets BinaryData . Les détails du schéma de corps pour chaque élément de la collection se trouvent dans la section Remarques ci-dessous.

Exceptions

Le service a retourné un code de status non réussi.

Exemples

Cet exemple montre comment appeler GetDeviceClasses et analyser le résultat.

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

Cet exemple montre comment appeler GetDeviceClasses avec tous les paramètres et comment analyser le résultat.

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.GetDeviceClasses("<filter>"))
{
    JsonElement result = JsonDocument.Parse(data.ToStream()).RootElement;
    Console.WriteLine(result.GetProperty("deviceClassId").ToString());
    Console.WriteLine(result.GetProperty("friendlyName").ToString());
    Console.WriteLine(result.GetProperty("deviceClassProperties").GetProperty("contractModel").GetProperty("id").ToString());
    Console.WriteLine(result.GetProperty("deviceClassProperties").GetProperty("contractModel").GetProperty("name").ToString());
    Console.WriteLine(result.GetProperty("deviceClassProperties").GetProperty("compatProperties").GetProperty("<test>").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("updateId").GetProperty("provider").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("updateId").GetProperty("name").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("updateId").GetProperty("version").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("description").ToString());
    Console.WriteLine(result.GetProperty("bestCompatibleUpdate").GetProperty("friendlyName").ToString());
}

Remarques

Voici le schéma JSON d’un élément de la réponse paginable.

Corps de réponse :

Schéma pour DeviceClassesListValue:

{
              deviceClassId: string, # Required. The device class identifier. This is generated from the model Id and the compat properties reported by the device update agent in the Device Update PnP interface in IoT Hub. It is a hex-encoded SHA1 hash.
              friendlyName: string, # Optional. The device class friendly name. This can be updated by callers after the device class has been automatically created.
              deviceClassProperties: {
                contractModel: {
                  id: string, # Required. The Device Update agent contract model Id of the device class. This is also used to calculate the device class Id.
                  name: string, # Required. The Device Update agent contract model name of the device class. Intended to be a more readable form of the contract model Id.
                }, # Optional. The Device Update agent contract model.
                compatProperties: Dictionary<string, string>, # Required. The compat properties of the device class. This object can be thought of as a set of key-value pairs where the key is the name of the compatibility property and the value is the value of the compatibility property. There will always be at least 1 compat property
              }, # Required. The device class properties that are used to calculate the device class Id
              bestCompatibleUpdate: {
                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. Update that is the highest version compatible with this device class.
            }

S’applique à