IoTEdgeObjectModel 1.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package IoTEdgeObjectModel --version 1.1.2                
NuGet\Install-Package IoTEdgeObjectModel -Version 1.1.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IoTEdgeObjectModel" Version="1.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IoTEdgeObjectModel --version 1.1.2                
#r "nuget: IoTEdgeObjectModel, 1.1.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install IoTEdgeObjectModel as a Cake Addin
#addin nuget:?package=IoTEdgeObjectModel&version=1.1.2

// Install IoTEdgeObjectModel as a Cake Tool
#tool nuget:?package=IoTEdgeObjectModel&version=1.1.2                

Overview

This library provides extensions methods of azure-iot-sdk to support the following scenarios:

  1. Instantiate a new deployment manifest with default EdgeAgent and EdgeHub values (e.g. create options, restart policy, et. al.).
  2. Clone an At-Scale deployment.
  3. Extract a deployment manifest from $EdgeAgent and $EdgeHub module twin desired properties.
  4. Extract IoT Edge module status (e.g. last updated time, exit code) from $EdgeAgent and $EdgeHub module twin reported properties.

The object model supplies a common API to view and edit deployment manifests regardless of whether they originate from an At-Scale or single device deployment.

Installation

The library is available via nuget.org

https://www.nuget.org/packages/IoTEdgeObjectModel

How To Use

The following are samples of how to use the extension methods.

Create a new deployment manifest

You can generate desired properties for edgeAgent with default values using the following snippet:

EdgeAgentDesiredProperties edgeAgentDesiredProperties = new EdgeAgentDesiredProperties();

If you want to change some of the default values, add registry credentials or custom modules properties, you can configure as the following:

EdgeAgentDesiredProperties edgeAgentDesiredProperties = new EdgeAgentDesiredProperties()
{
    SystemModuleVersion = "1.3",
    RegistryCredentials = new List<RegistryCredential>()
    {
       new RegistryCredential("AcrAdmin", "address", "userName", "password"),
    },
    EdgeModuleSpecifications = new List<EdgeModuleSpecification>()
    {
       new EdgeModuleSpecification("custom-module-name", "image-uri"),
    },
};

You can generate desired properties for edgeHub with default values using the following snippet:

EdgeHubDesiredProperties edgeHubConfig = new EdgeHubDesiredProperties();

If you want to change some of the default values, for example the default value of StoreAndForwardTimeToLiveSecs is 7200, you can change it to 3600 by configure it as the following:

EdgeHubDesiredProperties edgeHubConfig = new EdgeHubDesiredProperties()
{
    StoreAndForwardTimeToLiveSecs = 3600,
};

Generate desired properties for custom module:

ModuleSpecificationDesiredProperties moduleSpecificationDesiredProperties = new ModuleSpecificationDesiredProperties()
{
    Name = "custom-module",
    DesiredProperty = new
    {
        dummy_a = new
        {
            dummy_b = "dummy"
        },
    }
};

Finally, setup all desired properties to ConfigurationContent

ConfigurationContent configurationContent = new ConfigurationContent()
                .SetEdgeHub(edgeHubConfig)
                .SetEdgeAgent(edgeAgentDesiredProperties)
                .SetModuleDesiredProperty(moduleSpecificationDesiredProperties);

Then the configurationContent can be appied to IoTEdge device

// apply the configurationContent through SDK.
await registryManager.ApplyConfigurationContentOnDeviceAsync({IoTEdgeId}, configurationContent).ConfigureAwait(false);

Clone an At-Scale Deployment

At Scale deployments are immutable but must occassionally be cloned with updates. Once the source deployment has been retrieved from the IoT Hub API, modulesContent can be edited:

RegistryManager registryManager = RegistryManager.CreateFromConnectionString("<IoTHub ConnectionString>");

// optional: Add new modulesContent
IDictionary<string, IDictionary<string, object>> newModulesContent = await registryManager.GetModulesContent("<CurrentDeploymentId>");

// Clone deployment-at-scale
await registryManager.CloneDeploymentAtScale("<CurrentDeploymentId>", "<NewDeploymentId>", newModulesContent);

Extract a deployment manifest from $EdgeAgent and $EdgeHub module twins

A deployment manifest must sometimes be extracted from the desired properties of the device's $EdgeAgent and $EdgeHub module twins. The library supports this scenario:

RegistryManager registryManager = RegistryManager.CreateFromConnectionString("<IoTHub ConnectionString>");

// Get deployment manifest for edge deviceId
string manifest = await registryManager.GetDeploymentManifest("<IoTEdgeId>");

Extract IoT Edge Module Status

The reported properties from $EdgeAgent and $EdgeHub module twins can be used to examine the state of a deployment on a device.

// get $EdgeHub and $EdgeAgent module twin through SDK.
Twin edgeAgentTwin = await registryManager.GetTwinAsync(IoTEdgeId, "$edgeAgent").ConfigureAwait(false);
Twin edgeHubTwin = await registryManager.GetTwinAsync(IoTEdgeId, "$edgeHub").ConfigureAwait(false);

EdgeAgentReportedProperties edgeAgentReportedProperties = edgeAgentTwin.GetEdgeAgentReportedProperties();
EdgeHubReportedProperties edgeHubReportedProperties = edgeHubTwin.GetEdgeHubReportedProperties();

Dependencies

Microsoft.Azure.Devices (>= 1.37.1)

StyleCop.Analyzers (>=1.1.118)

Azure IoT Edge: 1.1, 1.2, 1.3

References

iot-edge-object-model

Properties of the IoT Edge agent and IoT Edge hub module twins

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.11 134 2/28/2024
1.1.10 118 2/2/2024
1.1.9 102 2/2/2024
1.1.8 161 12/22/2023
1.1.7 696 1/16/2023
1.1.6 250 1/16/2023
1.1.5 264 12/21/2022
1.1.4 308 12/13/2022
1.1.3 334 11/11/2022
1.1.2 306 11/10/2022
1.1.1 317 11/1/2022
1.1.0 370 10/6/2022
1.0.1 378 8/23/2022
1.0.0 390 8/22/2022

Add new features:
   Clone an At-Scale deployment.
   Extract a deployment manifest from $EdgeAgent and $EdgeHub module twin desired properties.