Skip to content

Commit a74d145

Browse files
committed
Initial CodeLoom project and file creation.
1 parent 2dfeb48 commit a74d145

File tree

8 files changed

+1186
-0
lines changed

8 files changed

+1186
-0
lines changed

dotnetv4/IoT/Actions/HelloIoT.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
using Amazon.IoT;
5+
using Amazon.IoT.Model;
6+
7+
namespace IoTActions;
8+
9+
// snippet-start:[iot.dotnetv4.Hello]
10+
/// <summary>
11+
/// Hello AWS IoT example.
12+
/// </summary>
13+
public class HelloIoT
14+
{
15+
/// <summary>
16+
/// Main method to run the Hello IoT example.
17+
/// </summary>
18+
/// <param name="args">Command line arguments.</param>
19+
/// <returns>A Task object.</returns>
20+
public static async Task Main(string[] args)
21+
{
22+
var iotClient = new AmazonIoTClient();
23+
24+
try
25+
{
26+
Console.WriteLine("Hello AWS IoT! Let's list your IoT Things:");
27+
Console.WriteLine(new string('-', 80));
28+
29+
var request = new ListThingsRequest
30+
{
31+
MaxResults = 10
32+
};
33+
34+
var response = await iotClient.ListThingsAsync(request);
35+
36+
if (response.Things.Count > 0)
37+
{
38+
Console.WriteLine($"Found {response.Things.Count} IoT Things:");
39+
foreach (var thing in response.Things)
40+
{
41+
Console.WriteLine($"- Thing Name: {thing.ThingName}");
42+
Console.WriteLine($" Thing ARN: {thing.ThingArn}");
43+
Console.WriteLine($" Thing Type: {thing.ThingTypeName ?? "No type specified"}");
44+
Console.WriteLine($" Version: {thing.Version}");
45+
46+
if (thing.Attributes?.Count > 0)
47+
{
48+
Console.WriteLine(" Attributes:");
49+
foreach (var attr in thing.Attributes)
50+
{
51+
Console.WriteLine($" {attr.Key}: {attr.Value}");
52+
}
53+
}
54+
Console.WriteLine();
55+
}
56+
}
57+
else
58+
{
59+
Console.WriteLine("No IoT Things found in your account.");
60+
Console.WriteLine("You can create IoT Things using the IoT Basics scenario example.");
61+
}
62+
63+
Console.WriteLine("Hello IoT completed successfully.");
64+
}
65+
catch (Exception ex)
66+
{
67+
Console.WriteLine($"Error: {ex.Message}");
68+
}
69+
finally
70+
{
71+
iotClient.Dispose();
72+
}
73+
}
74+
}
75+
// snippet-end:[iot.dotnetv4.Hello]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="AWSSDK.IoT" Version="4.0.3.7" />
12+
<PackageReference Include="AWSSDK.IotData" Version="4.0.2.7" />
13+
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.3.14" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" />
15+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
16+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
18+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
20+
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
21+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
22+
</ItemGroup>
23+
24+
</Project>

0 commit comments

Comments
 (0)