Ejemplo n.º 1
0
        public JsonResult Submit(FormData data)
        {
            List <PublishResponse> publishResponses = new List <PublishResponse>();


            string accessKey = GetConfigValue("AWSAccessKeyId");
            string secretKey = GetConfigValue("AWSSecretKeyValue");
            var    client    = new AmazonSimpleNotificationServiceClient(accessKey, secretKey, Amazon.RegionEndpoint.USEast1);

            var request = new ListTopicsRequest();

            // only want the ContactUs Topic Arn
            // for now this is hard-coded - future refactor should place it in web config or database.
            // Looks like IAWSChannelLoader etc got wiped. For now, just run with web.config
            string contactUsARN = GetConfigValue("AWContactUsARN");

            /* Only one ARN, so following proof of concept not needed, commented out
             * var listTopicsResponse = client.ListTopics(request);
             * foreach (var topic in listTopicsResponse.Topics)
             * {
             *
             * }
             */

            // Basic functionality works. Need to parse the publishResponse collection for specific service messages (failed, success, etc)
            // but for now simply assume if it published it was a success.
            publishResponses.Add(client.Publish(new PublishRequest
            {
                TopicArn = contactUsARN,
                Message  = data.ToString()
            }));
            return(Json(publishResponses, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        // public List<PublishResponse> Submit(FormData data)
        public async Task <IHttpActionResult> Submit(FormatException data)
        {
            IHttpActionResult result = null;

            string accessKey = String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["AWSAccessKey"].ToString()) ? string.Empty : System.Configuration.ConfigurationManager.AppSettings["AWSAccessKey"].ToString();
            string secretKey = String.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["AWSSecretKey"].ToString()) ? string.Empty : System.Configuration.ConfigurationManager.AppSettings["AWSSecretKey"].ToString();
            var    client    = new AmazonSimpleNotificationServiceClient(accessKey, secretKey, Amazon.RegionEndpoint.USEast1);


            var request = new ListTopicsRequest();

            var listTopicsResponse = client.ListTopics(request);

            List <PublishResponse> publishResponses = new List <PublishResponse>();

            foreach (var topic in listTopicsResponse.Topics)
            {
                publishResponses.Add(client.Publish(new PublishRequest
                {
                    TopicArn = topic.TopicArn,
                    Message  = "This is a test from the ContactUs Web MVC Controller"
                })
                                     );
            }
            return(result);
        }
        public async Task <ListTopicsResponse> ListTopics()
        {
            var request  = new ListTopicsRequest();
            var response = await snsClient.ListTopicsAsync(request);

            return(response);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Notification configuration window load event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NcWindow_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                AmazonAutoScalingConfig config = new AmazonAutoScalingConfig();
                config.ServiceURL = ((ViewModel)this.DataContext).Region.Url;
                AmazonAutoScalingClient client = new AmazonAutoScalingClient(config);
                DescribeAutoScalingNotificationTypesRequest  dasntreq  = new DescribeAutoScalingNotificationTypesRequest();
                DescribeAutoScalingNotificationTypesResponse dasntresp = client.DescribeAutoScalingNotificationTypes(dasntreq);
                foreach (string asnt in dasntresp.DescribeAutoScalingNotificationTypesResult.AutoScalingNotificationTypes)
                {
                    this.notificationTypes.Add(asnt);
                }

                AmazonSimpleNotificationServiceConfig snsconfig = new AmazonSimpleNotificationServiceConfig();
                config.ServiceURL = ((ViewModel)this.DataContext).Region.Url;
                AmazonSimpleNotificationServiceClient snsclient = new AmazonSimpleNotificationServiceClient(snsconfig);
                ListTopicsRequest  ltrequest = new ListTopicsRequest();
                ListTopicsResponse ltresp    = snsclient.ListTopics(ltrequest);
                foreach (Topic topic in ltresp.ListTopicsResult.Topics)
                {
                    this.snstopics.Add(topic.TopicArn);
                }

                rlbNcTypes.ItemsSource = this.notificationTypes;
                cboTopics.ItemsSource  = this.snstopics;
            }
            catch
            {
                MessageBox.Show(Window.GetWindow(this), "Error occured while loading the notification configuration options.", "Error", MessageBoxButton.OK);
                this.Close();
            }
        }
Ejemplo n.º 5
0
        public async void passwordreset([FromBody] Users u)
        {
            Users a = _context.Users.Find(u.Email);

            _log.LogInformation("Listing all items");

            Console.WriteLine("Hello inside the reset");
            if (a != null)
            {
                var client   = new AmazonSimpleNotificationServiceClient(RegionEndpoint.USEast1);
                var request  = new ListTopicsRequest();
                var response = new ListTopicsResponse();
                _log.LogInformation("going inside for");

                response = await client.ListTopicsAsync();

                foreach (var topic in response.Topics)
                {
                    _log.LogInformation(topic.TopicArn);
                    if (topic.TopicArn.EndsWith("SNSTopicResetPassword"))
                    {
                        _log.LogInformation(topic.TopicArn);
                        var respose = new PublishRequest
                        {
                            TopicArn = topic.TopicArn,
                            Message  = a.Email
                        };

                        await client.PublishAsync(respose);
                    }
                }
            }
        }
        /// <summary>
        /// Initiates the asynchronous execution of the ListTopics operation.
        /// <seealso cref="Amazon.SimpleNotificationService.IAmazonSimpleNotificationService"/>
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the ListTopics operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task <ListTopicsResponse> ListTopicsAsync(ListTopicsRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new ListTopicsRequestMarshaller();
            var unmarshaller = ListTopicsResponseUnmarshaller.Instance;

            return(Invoke <IRequest, ListTopicsRequest, ListTopicsResponse>(request, marshaller, unmarshaller, signer, cancellationToken));
        }
Ejemplo n.º 7
0
        private static void RetrieveAllTopics(AmazonSimpleNotificationServiceClient sns)
        {
            Console.WriteLine("Retrieving all topics...");
            var listTopicsRequest = new ListTopicsRequest();

            ListTopicsResponse listTopicsResponse;

            do
            {
                listTopicsResponse = sns.ListTopics(listTopicsRequest);
                foreach (var topic in listTopicsResponse.Topics)
                {
                    Console.WriteLine(" Topic: {0}", topic.TopicArn);

                    // Get topic attributes
                    var topicAttributes = sns.GetTopicAttributes(new GetTopicAttributesRequest
                    {
                        TopicArn = topic.TopicArn
                    }).Attributes;

                    if (topicAttributes.Count > 0)
                    {
                        Console.WriteLine(" Topic attributes");
                        foreach (var topicAttribute in topicAttributes)
                        {
                            Console.WriteLine(" -{0} : {1}", topicAttribute.Key, topicAttribute.Value);
                        }
                    }
                    Console.WriteLine();
                }
                listTopicsRequest.NextToken = listTopicsResponse.NextToken;
            } while (listTopicsResponse.NextToken != null);
        }
Ejemplo n.º 8
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            ListTopicsRequest request;

            try
            {
                request = new ListTopicsRequest
                {
                    CompartmentId  = CompartmentId,
                    Id             = Id,
                    Name           = Name,
                    Page           = Page,
                    Limit          = Limit,
                    SortBy         = SortBy,
                    SortOrder      = SortOrder,
                    LifecycleState = LifecycleState,
                    OpcRequestId   = OpcRequestId
                };
                IEnumerable <ListTopicsResponse> responses = GetRequestDelegate().Invoke(request);
                foreach (var item in responses)
                {
                    response = item;
                    WriteOutput(response, response.Items, true);
                }
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        private List <Topic> GetAllTopics()
        {
            var            allTopics         = new List <Topic>();
            AutoResetEvent ars               = new AutoResetEvent(false);
            Exception      responseException = new Exception();
            var            listRequest       = new ListTopicsRequest();

            do
            {
                Client.ListTopicsAsync(listRequest, (response) =>
                {
                    responseException = response.Exception;
                    if (responseException == null)
                    {
                        allTopics.AddRange(response.Response.Topics);
                        listRequest.NextToken = response.Response.NextToken;
                    }
                    ars.Set();
                }, new AsyncOptions {
                    ExecuteCallbackOnMainThread = false
                });
                ars.WaitOne();
                Assert.IsNull(responseException);
            } while (!string.IsNullOrEmpty(listRequest.NextToken));
            return(allTopics);
        }
Ejemplo n.º 11
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonSimpleNotificationServiceConfig config = new AmazonSimpleNotificationServiceConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonSimpleNotificationServiceClient client = new AmazonSimpleNotificationServiceClient(creds, config);

            ListTopicsResponse resp = new ListTopicsResponse();

            do
            {
                ListTopicsRequest req = new ListTopicsRequest
                {
                    NextToken = resp.NextToken
                };

                resp = client.ListTopics(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Topics)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Lists topics in the specified compartment.
        /// &lt;br/&gt;
        /// Transactions Per Minute (TPM) per-tenancy limit for this operation: 120.
        ///
        /// </summary>
        /// <param name="request">The request object containing the details to send. Required.</param>
        /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param>
        /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param>
        /// <returns>A response object containing details about the completed operation</returns>
        /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/ons/ListTopics.cs.html">here</a> to see an example of how to use ListTopics API.</example>
        public async Task <ListTopicsResponse> ListTopics(ListTopicsRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
        {
            logger.Trace("Called listTopics");
            Uri                uri            = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/topics".Trim('/')));
            HttpMethod         method         = new HttpMethod("GET");
            HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request);

            requestMessage.Headers.Add("Accept", "application/json");
            GenericRetrier      retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration);
            HttpResponseMessage responseMessage;

            try
            {
                if (retryingClient != null)
                {
                    responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false);
                }
                this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage);

                return(Converter.FromHttpResponseMessage <ListTopicsResponse>(responseMessage));
            }
            catch (Exception e)
            {
                logger.Error($"ListTopics failed with error: {e.Message}");
                throw;
            }
        }
Ejemplo n.º 13
0
        internal ListTopicsResponse ListTopics(ListTopicsRequest request)
        {
            var marshaller   = new ListTopicsRequestMarshaller();
            var unmarshaller = ListTopicsResponseUnmarshaller.Instance;

            return(Invoke <ListTopicsRequest, ListTopicsResponse>(request, marshaller, unmarshaller));
        }
Ejemplo n.º 14
0
        /**
         * Convert ListTopicsRequest to name value pairs
         */
        private static IDictionary<string, string> ConvertListTopics(ListTopicsRequest request)
        {
            IDictionary<string, string> parameters = new Dictionary<string, string>();
            parameters["Action"] = "ListTopics";
            if (request.IsSetNextToken())
            {
                parameters["NextToken"] = request.NextToken;
            }

            return parameters;
        }
Ejemplo n.º 15
0
        private static IDictionary <string, string> ConvertListTopics(ListTopicsRequest request)
        {
            IDictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary["Action"] = "ListTopics";
            if (request.IsSetNextToken())
            {
                dictionary["NextToken"] = request.NextToken;
            }
            return(dictionary);
        }
Ejemplo n.º 16
0
        public async Task GetAWSTopics(AWSCredentials credentials)
        {
            var client   = new AmazonSimpleNotificationServiceClient(credentials.AccessKey, credentials.SecretKey, credentials.Region);
            var request  = new ListTopicsRequest();
            var response = new ListTopicsResponse();

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

                foreach (var topic in response.Topics)
                {
                    Console.WriteLine("Topic: {0}", topic.TopicArn);
                    await SendAWSNotification(credentials, topic.TopicArn, String.Format("Message from topic: {0}", topic.TopicArn));

                    var subs = await client.ListSubscriptionsByTopicAsync(
                        new ListSubscriptionsByTopicRequest
                    {
                        TopicArn = topic.TopicArn
                    });

                    var ss = subs.Subscriptions;

                    if (ss.Any())
                    {
                        Console.WriteLine("  Subscriptions:");
                        foreach (var sub in ss)
                        {
                            Console.WriteLine("    {0}", sub.SubscriptionArn);
                        }
                    }

                    var attrs = await client.GetTopicAttributesAsync(
                        new GetTopicAttributesRequest
                    {
                        TopicArn = topic.TopicArn
                    });

                    if (attrs.Attributes.Any())
                    {
                        Console.WriteLine("  Attributes:");

                        foreach (var attr in attrs.Attributes)
                        {
                            Console.WriteLine("    {0} = {1}", attr.Key, attr.Value);
                        }
                    }
                    Console.WriteLine();
                }
                request.NextToken = response.NextToken;
            } while (!string.IsNullOrEmpty(response.NextToken));
        }
Ejemplo n.º 17
0
 public SNSPublishService(string serverName)
 {
     try
     {
         // null-coalescing-operator
         SNSClient           = SNSClient ?? new AmazonSimpleNotificationServiceClient();
         ListOfTopicsRequest = ListOfTopicsRequest ?? new ListTopicsRequest();
     }
     catch (Exception ex)
     {
         // Logger.logException(ex.Message, ex);
     }
 }
        internal ListTopicsResponse ListTopics(ListTopicsRequest request)
        {
            var task = ListTopicsAsync(request);

            try
            {
                return(task.Result);
            }
            catch (AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return(null);
            }
        }
Ejemplo n.º 19
0
        public void ListTopics()
        {
            ListTopicsRequest request = new ListTopicsRequest();
            var response = client.ListTopics(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                foreach (var item in response.Topics)
                {
                    Console.WriteLine(item.TopicArn);
                }
            }
            //Console.ReadLine();
        }
Ejemplo n.º 20
0
        private static List <Topic> GetAllTopics()
        {
            var allTopics   = new List <Topic>();
            var listRequest = new ListTopicsRequest();

            do
            {
                var listResponse = Client.ListTopics(listRequest);
                allTopics.AddRange(listResponse.Topics);

                listRequest.NextToken = listResponse.NextToken;
            } while (!string.IsNullOrEmpty(listRequest.NextToken));
            return(allTopics);
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Creates a new enumerable which will iterate over the responses received from the ListTopics operation. This enumerable
 /// will fetch more data from the server as needed.
 /// </summary>
 /// <param name="request">The request object containing the details to send</param>
 /// <param name="retryConfiguration">The configuration for retrying, may be null</param>
 /// <param name="cancellationToken">The cancellation token object</param>
 /// <returns>The enumerator, which supports a simple iteration over a collection of a specified type</returns>
 public IEnumerable <ListTopicsResponse> ListTopicsResponseEnumerator(ListTopicsRequest request, Common.Retry.RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
 {
     return(new Common.Utils.ResponseEnumerable <ListTopicsRequest, ListTopicsResponse>(
                response => response.OpcNextPage,
                input =>
     {
         if (!string.IsNullOrEmpty(input))
         {
             request.Page = input;
         }
         return request;
     },
                request => client.ListTopics(request, retryConfiguration, cancellationToken)
                ));
 }
Ejemplo n.º 22
0
        public void ListTopics()
        {
            ListTopicsRequest request = new ListTopicsRequest
            {
            };
            var response = client.ListTopics(request);

            if (response.HttpStatusCode.IsSuccess())
            {
                foreach (var topic in response.Topics)
                {
                    Console.WriteLine(topic.TopicArn);
                }
            }
        }
Ejemplo n.º 23
0
        /// <summary>Snippet for ListTopics</summary>
        public async Task ListTopicsRequestObjectAsync()
        {
            // Snippet: ListTopicsAsync(ListTopicsRequest, CallSettings)
            // Create client
            PublisherServiceApiClient publisherServiceApiClient = await PublisherServiceApiClient.CreateAsync();

            // Initialize request argument(s)
            ListTopicsRequest request = new ListTopicsRequest
            {
                ProjectAsProjectName = ProjectName.FromProject("[PROJECT]"),
            };
            // Make the request
            PagedAsyncEnumerable <ListTopicsResponse, Topic> response = publisherServiceApiClient.ListTopicsAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((Topic item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListTopicsResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Topic item in page)
                {
                    // Do something with each item
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int          pageSize   = 10;
            Page <Topic> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Topic item in singlePage)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Lists matching topics.
        /// </summary>
        /// <param name="project">The name of the cloud project that topics belong to.</param>
        /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
        /// <returns>The RPC response.</returns>
        public override IEnumerable <Topic> ListTopics(
            string project,
            CallSettings callSettings = null)
        {
            ListTopicsRequest request = new ListTopicsRequest
            {
                Project = project,
            };

            return(s_listTopicsPageStreamer.Fetch(
                       request,
                       pageStreamRequest => GrpcClient.ListTopics(
                           pageStreamRequest,
                           _clientHelper.BuildCallOptions(null, callSettings))
                       ));
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Lists matching topics.
        /// </summary>
        /// <param name="project">The name of the cloud project that topics belong to.</param>
        /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
        /// <returns>A Task containing the RPC response.</returns>
        public override IAsyncEnumerable <Topic> ListTopicsAsync(
            string project,
            CallSettings callSettings = null)
        {
            ListTopicsRequest request = new ListTopicsRequest
            {
                Project = project,
            };

            return(s_listTopicsPageStreamer.FetchAsync(
                       request,
                       (pageStreamRequest, cancellationToken) => GrpcClient.ListTopicsAsync(
                           pageStreamRequest,
                           _clientHelper.BuildCallOptions(cancellationToken, callSettings)
                           ).ResponseAsync
                       ));
        }
Ejemplo n.º 26
0
        private bool IsTopicExists(AmazonSimpleNotificationServiceClient client, string Topic, out string TopicArn)
        {
            ListTopicsRequest  lstTopicRequest  = new ListTopicsRequest();
            ListTopicsResponse lstTopicResponse = client.ListTopics(lstTopicRequest);
            ListTopicsResult   lstTopicResult   = lstTopicResponse.ListTopicsResult;
            List <Topic>       TopicsList       = lstTopicResult.Topics;

            TopicArn = string.Empty;
            bool IsTopicExists = TopicsList.Exists(x => x.TopicArn.Split(':')[x.TopicArn.Split(':').Count() - 1] == Topic);

            if (IsTopicExists)
            {
                string topicarn = TopicsList.Where(x => x.IsSetTopicArn() & x.TopicArn.Split(':')[x.TopicArn.Split(':').Count() - 1] == Topic).Select(s => s.TopicArn).First();
                TopicArn = topicarn;
            }
            return(IsTopicExists);
        }
Ejemplo n.º 27
0
        public void TestListTopicWithoutNextToken()
        {
            LogClient client = new LogClient(ClientTestData.TEST_ENDPOINT, ClientTestData.TEST_ACCESSKEYID, ClientTestData.TEST_ACCESSKEY);

            client.SetWebSend(MockSend);
            ListTopicsRequest request = new ListTopicsRequest();

            request.Project  = ClientTestData.TEST_PROJECT;
            request.Logstore = "testlogstore_without_nexttoken";
            request.Token    = "atoken";
            request.Lines    = 100;
            ListTopicsResponse response = client.ListTopics(request);;

            Assert.IsTrue(DicToString(Headers).CompareTo("[x-sls-apiversion:0.4.0][x-sls-bodyrawsize:0][x-sls-signaturemethod:hmac-sha1][User-Agent:aliyun-sdk-dotnet/1.0.0.0]") == 0);
            Assert.IsTrue(response != null && response.Count == 2);
            Assert.IsTrue(Host.CompareTo("mock_project.mockhost.aliyuncs.com") == 0);
            Assert.IsTrue(RequestUri.CompareTo("http://mock_project.mockhost.aliyuncs.com/logstores/testlogstore_without_nexttoken?type=topic&token=atoken&line=100") == 0);
        }
Ejemplo n.º 28
0
        private static void ListSNSTopics(AmazonSimpleNotificationServiceClient sns)
        {
            // List all topics
            try
            {
                Console.WriteLine();
                Console.WriteLine("Retrieving all topics...");
                var listTopicsRequest = new ListTopicsRequest();
                ListTopicsResponse listTopicsResponse;
                do
                {
                    listTopicsResponse = sns.ListTopics(listTopicsRequest);
                    foreach (var topic in listTopicsResponse.Topics)
                    {
                        Console.WriteLine(" Topic: {0}", topic.TopicArn);

                        // Get topic attributes
                        var topicAttributes = sns.GetTopicAttributes(new GetTopicAttributesRequest
                        {
                            TopicArn = topic.TopicArn
                        }).Attributes;
                        if (topicAttributes.Count > 0)
                        {
                            Console.WriteLine(" Topic attributes");
                            foreach (var topicAttribute in topicAttributes)
                            {
                                Console.WriteLine(" -{0} : {1}", topicAttribute.Key, topicAttribute.Value);
                            }
                        }
                        Console.WriteLine();
                    }
                    listTopicsRequest.NextToken = listTopicsResponse.NextToken;
                } while (listTopicsResponse.NextToken != null);
            }
            catch (AmazonSimpleNotificationServiceException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
            }
            Console.ReadLine();
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> Get()
        {
            var topicList = new List <Dictionary <string, string> >();
            Dictionary <string, string> dictAttributes = null;

            using (_SnsClient = new AmazonSimpleNotificationServiceClient(_AwsCredentials, RegionEndpoint.USEast2))
            {
                try
                {
                    _SnsRequest = new ListTopicsRequest();
                    do
                    {
                        _SnsResponse = await _SnsClient.ListTopicsAsync(_SnsRequest);

                        foreach (var topic in _SnsResponse.Topics)
                        {
                            // Get topic attributes
                            var topicAttributes = await _SnsClient.GetTopicAttributesAsync(request : new GetTopicAttributesRequest
                            {
                                TopicArn = topic.TopicArn
                            });

                            // this is see attributes of topic
                            if (topicAttributes.Attributes.Count > 0)
                            {
                                dictAttributes = new Dictionary <string, string>();
                                foreach (var topicAttribute in topicAttributes.Attributes)
                                {
                                    dictAttributes.Add(topicAttribute.Key, topicAttribute.Value.ToString());
                                }
                                topicList.Add(dictAttributes);
                            }
                        }
                        _SnsRequest.NextToken = _SnsResponse.NextToken;
                    } while (_SnsResponse.NextToken != null);
                }
                catch (AmazonSimpleNotificationServiceException ex)
                {
                    return(Content(HandleSNSError(ex)));
                }
            }

            return(Ok(JsonConvert.SerializeObject(topicList)));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// List the SNS Topics.
        /// </summary>
        /// <param name="nextToken"></param>
        /// <returns></returns>
        public string[] ListTopics(string nextToken)
        {
            ListTopicsRequest request = new ListTopicsRequest();

            request.NextToken = nextToken;
            ListTopicsResponse response = Client.ListTopics(request);

            var topics = new List <string>();

            foreach (Topic topic in response.ListTopicsResult.Topics)
            {
                Debug.WriteLine(topic.TopicArn, "TopicArn");
                topics.Add(topic.TopicArn);
            }

            Debug.WriteLine(response.ListTopicsResult.NextToken, "NextToken");

            return(topics.ToArray());
        }