@@ -23,20 +23,38 @@ public static async Task Main(string[] args)
2323
2424 try
2525 {
26- Console . WriteLine ( "Hello AWS IoT! Let's list a few of your IoT Things:" ) ;
26+ Console . WriteLine ( "Hello AWS IoT! Let's list your IoT Things:" ) ;
2727 Console . WriteLine ( new string ( '-' , 80 ) ) ;
2828
29- var request = new ListThingsRequest
29+ // Use pages of 10.
30+ var request = new ListThingsRequest ( )
3031 {
3132 MaxResults = 10
3233 } ;
33-
3434 var response = await iotClient . ListThingsAsync ( request ) ;
3535
36- if ( response . Things is { Count : > 0 } )
36+ // Since there is not a built-in paginator, use the NextMarker to paginate.
37+ bool hasMoreResults = true ;
38+
39+ var things = new List < ThingAttribute > ( ) ;
40+ while ( hasMoreResults )
41+ {
42+ things . AddRange ( response . Things ) ;
43+
44+ // If NextMarker is not null, there are more results. Get the next page of results.
45+ if ( ! String . IsNullOrEmpty ( response . NextMarker ) )
46+ {
47+ request . Marker = response . NextMarker ;
48+ response = await iotClient . ListThingsAsync ( request ) ;
49+ }
50+ else
51+ hasMoreResults = false ;
52+ }
53+
54+ if ( things is { Count : > 0 } )
3755 {
38- Console . WriteLine ( $ "Found { response . Things . Count } IoT Things:") ;
39- foreach ( var thing in response . Things )
56+ Console . WriteLine ( $ "Found { things . Count } IoT Things:") ;
57+ foreach ( var thing in things )
4058 {
4159 Console . WriteLine ( $ "- Thing Name: { thing . ThingName } ") ;
4260 Console . WriteLine ( $ " Thing ARN: { thing . ThingArn } ") ;
@@ -62,13 +80,13 @@ public static async Task Main(string[] args)
6280
6381 Console . WriteLine ( "Hello IoT completed successfully." ) ;
6482 }
65- catch ( Exception ex )
83+ catch ( Amazon . IoT . Model . ThrottlingException ex )
6684 {
67- Console . WriteLine ( $ "Error : { ex . Message } ") ;
85+ Console . WriteLine ( $ "Request throttled, please try again later : { ex . Message } ") ;
6886 }
69- finally
87+ catch ( Exception ex )
7088 {
71- iotClient . Dispose ( ) ;
89+ Console . WriteLine ( $ "Couldn't list Things. Here's why: { ex . Message } " ) ;
7290 }
7391 }
7492}
0 commit comments