diff --git a/dotnetv3/SNS/ListSNSSubscriptionsExample/ListSNSSubscriptionsExample/ListSNSSubscriptionsExample.csproj b/dotnetv3/SNS/ListSNSSubscriptionsExample/ListSNSSubscriptionsExample/ListSNSSubscriptionsExample.csproj index 2d1d87d4ed8..b88634556f2 100644 --- a/dotnetv3/SNS/ListSNSSubscriptionsExample/ListSNSSubscriptionsExample/ListSNSSubscriptionsExample.csproj +++ b/dotnetv3/SNS/ListSNSSubscriptionsExample/ListSNSSubscriptionsExample/ListSNSSubscriptionsExample.csproj @@ -6,8 +6,8 @@ - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/dotnetv3/SNS/ListSNSSubscriptionsExample/ListSNSSubscriptionsExample/ListSubscriptions.cs b/dotnetv3/SNS/ListSNSSubscriptionsExample/ListSNSSubscriptionsExample/ListSubscriptions.cs index b76b98f9266..4faba4a35fc 100644 --- a/dotnetv3/SNS/ListSNSSubscriptionsExample/ListSNSSubscriptionsExample/ListSubscriptions.cs +++ b/dotnetv3/SNS/ListSNSSubscriptionsExample/ListSNSSubscriptionsExample/ListSubscriptions.cs @@ -20,22 +20,53 @@ public static async Task Main() { IAmazonSimpleNotificationService client = new AmazonSimpleNotificationServiceClient(); - var subscriptions = await GetSubscriptionsListAsync(client); + Console.WriteLine("Enter a topic ARN to list subscriptions for a specific topic, " + + "or press Enter to list subscriptions for all topics."); + var topicArn = Console.ReadLine(); + Console.WriteLine(); + + var subscriptions = await GetSubscriptionsListAsync(client, topicArn); DisplaySubscriptionList(subscriptions); } /// - /// Gets a list of the existing Amazon SNS subscriptions. + /// Gets a list of the existing Amazon SNS subscriptions, optionally by specifying a topic ARN. /// /// The initialized Amazon SNS client object used /// to obtain the list of subscriptions. - /// A List containing information about each subscription. - public static async Task> GetSubscriptionsListAsync(IAmazonSimpleNotificationService client) + /// The optional ARN of a specific topic. Defaults to null. + /// A list containing information about each subscription. + public static async Task> GetSubscriptionsListAsync(IAmazonSimpleNotificationService client, string topicArn = null) { - var response = await client.ListSubscriptionsAsync(); + var results = new List(); + + if (!string.IsNullOrEmpty(topicArn)) + { + var paginateByTopic = client.Paginators.ListSubscriptionsByTopic( + new ListSubscriptionsByTopicRequest() + { + TopicArn = topicArn, + }); - return response.Subscriptions; + // Get the entire list using the paginator. + await foreach (var subscription in paginateByTopic.Subscriptions) + { + results.Add(subscription); + } + } + else + { + var paginateAllSubscriptions = client.Paginators.ListSubscriptions(new ListSubscriptionsRequest()); + + // Get the entire list using the paginator. + await foreach (var subscription in paginateAllSubscriptions.Subscriptions) + { + results.Add(subscription); + } + } + + return results; } /// @@ -56,5 +87,6 @@ public static void DisplaySubscriptionList(List subscriptionList) } } } + // snippet-end:[SNS.dotnetv3.ListSNSSubscriptionsExample] }