@@ -43,13 +43,13 @@ public static async Task Main(string[] args)
4343 // Set up dependency injection for the Amazon service.
4444 using var host = Host . CreateDefaultBuilder ( args )
4545 . ConfigureServices ( ( _ , services ) =>
46- services . AddAWSService < IAmazonIoT > ( new AWSOptions ( ) { Region = RegionEndpoint . USEast1 } )
46+ services . AddAWSService < IAmazonIoT > ( new AWSOptions ( ) { Region = RegionEndpoint . USEast1 } )
4747 . AddAWSService < IAmazonCloudFormation > ( )
4848 . AddTransient < IoTWrapper > ( )
4949 . AddLogging ( builder => builder . AddConsole ( ) )
5050 . AddSingleton < IAmazonIotData > ( sp =>
5151 {
52- var iotService = sp . GetService < IAmazonIoT > ( ) ;
52+ var iotService = sp . GetRequiredService < IAmazonIoT > ( ) ;
5353 var request = new DescribeEndpointRequest
5454 {
5555 EndpointType = "iot:Data-ATS"
@@ -133,7 +133,7 @@ private static async Task RunScenarioInternalAsync(IoTWrapper iotWrapper, IAmazo
133133 Console . WriteLine ( "1. Create an AWS IoT Thing." ) ;
134134 Console . WriteLine ( "An AWS IoT Thing represents a virtual entity in the AWS IoT service that can be associated with a physical device." ) ;
135135 Console . WriteLine ( ) ;
136-
136+
137137 if ( IsInteractive )
138138 {
139139 Console . Write ( "Enter Thing name: " ) ;
@@ -145,7 +145,7 @@ private static async Task RunScenarioInternalAsync(IoTWrapper iotWrapper, IAmazo
145145 {
146146 Console . WriteLine ( $ "Using default Thing name: { thingName } ") ;
147147 }
148-
148+
149149 var thingArn = await iotWrapper . CreateThingAsync ( thingName ) ;
150150 Console . WriteLine ( $ "{ thingName } was successfully created. The ARN value is { thingArn } ") ;
151151 Console . WriteLine ( new string ( '-' , 80 ) ) ;
@@ -155,7 +155,7 @@ private static async Task RunScenarioInternalAsync(IoTWrapper iotWrapper, IAmazo
155155 Console . WriteLine ( "2. Generate a device certificate." ) ;
156156 Console . WriteLine ( "A device certificate performs a role in securing the communication between devices (Things) and the AWS IoT platform." ) ;
157157 Console . WriteLine ( ) ;
158-
158+
159159 var createCert = "y" ;
160160 if ( IsInteractive )
161161 {
@@ -327,7 +327,7 @@ private static async Task RunScenarioInternalAsync(IoTWrapper iotWrapper, IAmazo
327327 Console . WriteLine ( "Creates a rule that is an administrator-level action." ) ;
328328 Console . WriteLine ( "Any user who has permission to create rules will be able to access data processed by the rule." ) ;
329329 Console . WriteLine ( ) ;
330-
330+
331331 if ( IsInteractive )
332332 {
333333 Console . Write ( "Enter Rule name: " ) ;
@@ -342,7 +342,7 @@ private static async Task RunScenarioInternalAsync(IoTWrapper iotWrapper, IAmazo
342342
343343 // Deploy CloudFormation stack to create SNS topic and IAM role
344344 Console . WriteLine ( "Deploying CloudFormation stack to create SNS topic and IAM role..." ) ;
345-
345+
346346 var deployStack = ! IsInteractive || GetYesNoResponse ( "Would you like to deploy the CloudFormation stack? (y/n) " ) ;
347347 if ( deployStack )
348348 {
@@ -358,10 +358,10 @@ private static async Task RunScenarioInternalAsync(IoTWrapper iotWrapper, IAmazo
358358 {
359359 snsTopicArn = stackOutputs [ "SNSTopicArn" ] ;
360360 string roleArn = stackOutputs [ "RoleArn" ] ;
361-
361+
362362 Console . WriteLine ( $ "Successfully deployed stack. SNS topic: { snsTopicArn } ") ;
363363 Console . WriteLine ( $ "Successfully deployed stack. IAM role: { roleArn } ") ;
364-
364+
365365 // Now create the IoT rule with the CloudFormation outputs
366366 var ruleResult = await iotWrapper . CreateTopicRuleAsync ( ruleName , snsTopicArn , roleArn ) ;
367367 if ( ruleResult )
@@ -489,7 +489,7 @@ private static async Task RunScenarioInternalAsync(IoTWrapper iotWrapper, IAmazo
489489 Console . WriteLine ( new string ( '-' , 80 ) ) ;
490490 Console . WriteLine ( "13. Clean up CloudFormation stack." ) ;
491491 Console . WriteLine ( "Deleting the CloudFormation stack and all resources..." ) ;
492-
492+
493493 var cleanup = ! IsInteractive || GetYesNoResponse ( "Do you want to delete the CloudFormation stack and all resources? (y/n) " ) ;
494494 if ( cleanup )
495495 {
@@ -513,7 +513,7 @@ private static async Task RunScenarioInternalAsync(IoTWrapper iotWrapper, IAmazo
513513 catch ( Exception ex )
514514 {
515515 scenarioLogger . LogError ( ex , "Error occurred during scenario execution." ) ;
516-
516+
517517 // Cleanup on error
518518 if ( ! string . IsNullOrEmpty ( certificateArn ) && ! string . IsNullOrEmpty ( thingName ) )
519519 {
@@ -527,7 +527,7 @@ private static async Task RunScenarioInternalAsync(IoTWrapper iotWrapper, IAmazo
527527 scenarioLogger . LogError ( cleanupEx , "Error during cleanup." ) ;
528528 }
529529 }
530-
530+
531531 if ( ! string . IsNullOrEmpty ( thingName ) )
532532 {
533533 try
@@ -552,7 +552,7 @@ private static async Task RunScenarioInternalAsync(IoTWrapper iotWrapper, IAmazo
552552 scenarioLogger . LogError ( cleanupEx , "Error during CloudFormation stack cleanup." ) ;
553553 }
554554 }
555-
555+
556556 throw ;
557557 }
558558 }
@@ -574,7 +574,7 @@ private static async Task<bool> DeployCloudFormationStack(string stackName, IAma
574574 {
575575 StackName = stackName ,
576576 TemplateBody = await File . ReadAllTextAsync ( _stackResourcePath ) ,
577- Capabilities = new List < string > { Capability . CAPABILITY_NAMED_IAM }
577+ Capabilities = new List < string > { Capability . CAPABILITY_NAMED_IAM }
578578 } ;
579579
580580 var response = await cloudFormationClient . CreateStackAsync ( request ) ;
@@ -676,7 +676,7 @@ private static async Task<bool> WaitForStackCompletion(string stackId, IAmazonCl
676676 } ;
677677
678678 var response = await cloudFormationClient . DescribeStacksAsync ( describeStacksRequest ) ;
679-
679+
680680 if ( response . Stacks . Count > 0 )
681681 {
682682 var outputs = new Dictionary < string , string > ( ) ;
@@ -686,7 +686,7 @@ private static async Task<bool> WaitForStackCompletion(string stackId, IAmazonCl
686686 }
687687 return outputs ;
688688 }
689-
689+
690690 return null ;
691691 }
692692 catch ( Exception ex )
@@ -813,4 +813,4 @@ private static string PromptUserForStackName()
813813 return _stackName ;
814814 }
815815}
816- // snippet-end:[iot.dotnetv4.IoTScenario]
816+ // snippet-end:[iot.dotnetv4.IoTScenario]
0 commit comments