Beispiel #1
0
        public async Task <IReadOnlyList <TopicDetail> > GetAllTopicsAsync()
        {
            var topics  = new List <TopicDetail>();
            var request = new ListTopicsRequest();
            ListTopicsResponse response;

            do
            {
                response = await _sns.ListTopicsAsync(request);

                if (response.HttpStatusCode != HttpStatusCode.OK)
                {
                    throw new InvalidOperationException($"Unable to list all topics.");
                }

                foreach (var topic in response.Topics)
                {
                    var topicArn = new TopicArn(topic.TopicArn);

                    topics.Add(new TopicDetail
                    {
                        Attributes = await GetTopicAttributesAsync(topic.TopicArn),
                        Name       = topicArn.TopicName,
                        Region     = topicArn.Region
                    });
                }

                request.NextToken = response.NextToken;
            } while (response.NextToken != null);

            return(topics);
        }
Beispiel #2
0
        public Task <TopicDetail> GetTopicAsync(string topicName)
        {
            if (string.IsNullOrWhiteSpace(topicName))
            {
                throw new ArgumentException($"A non-null/empty '{topicName}' is required.", nameof(topicName));
            }

            return(getTopicAsync());

            async Task <TopicDetail> getTopicAsync()
            {
                var topic = await _sns.FindTopicAsync(topicName);

                if (topic == null)
                {
                    return(null);
                }

                var topicArn = new TopicArn(topic.TopicArn);

                return(new TopicDetail
                {
                    Attributes = await GetTopicAttributesAsync(topic.TopicArn),
                    Name = topicArn.TopicName,
                    Region = topicArn.Region
                });
            }
        }