Exemplo n.º 1
0
        public void TestCreatePlatformApplication()
        {
            // of the array is one line of the file.
            string[] lines = System.IO.File.ReadAllLines(@"C:\keys.txt");
            string   accK  = lines[0];
            string   secK  = lines[1];

            NotificationManager nm = new NotificationManager(accK, secK, Amazon.RegionEndpoint.USEast1);

            nm.init();
            string topicArn1 = nm.createPlatformApplicationAndAttachToTopic("exampletoken", "username");
            string topicArn2 = nm.createPlatformApplicationAndAttachToTopic("exampletoken1", "username1");

            AmazonSimpleNotificationServiceClient snsClient = new AmazonSimpleNotificationServiceClient(accK, secK, Amazon.RegionEndpoint.USEast1);

            var topic = snsClient.FindTopic(nm.getTopicName("username"));

            Assert.AreEqual(topic.TopicArn, topicArn1);

            var topic1 = snsClient.FindTopic(nm.getTopicName("username1"));

            Assert.AreEqual(topic1.TopicArn, topicArn2);

            string topicArn3 = nm.createPlatformApplicationAndAttachToTopic("exampletoken2", "username");
            string topicArn4 = nm.createPlatformApplicationAndAttachToTopic("exampletoken3", "username1");

            Assert.AreEqual(topicArn1, topicArn3);
            Assert.AreEqual(topicArn2, topicArn4);

            try
            {
                topicArn1 = nm.createPlatformApplicationAndAttachToTopic("exampletoken", "username");
                Assert.Fail("Created a platform for same username and device token");
            }

            catch (Exception e)
            {
                Assert.IsTrue(e != null);
            }

            var appsResponse = snsClient.ListPlatformApplications();
            int i            = 0;

            foreach (var app in appsResponse.PlatformApplications)
            {
                var appAttrsRequest = new GetPlatformApplicationAttributesRequest
                {
                    PlatformApplicationArn = app.PlatformApplicationArn
                };

                i++;
                var appAttrsResponse = snsClient.GetPlatformApplicationAttributes(appAttrsRequest);
                System.Diagnostics.Trace.WriteLine(app.PlatformApplicationArn);
            }

            //Assert.AreEqual(2, i);
        }
Exemplo n.º 2
0
 public Topic CheckSnsTopic(string topicName)
 {
     using (var client = new AmazonSimpleNotificationServiceClient())
     {
         return(client.FindTopic(topicName));
     }
 }
Exemplo n.º 3
0
 public void DeleteTopic(string topicName)
 {
     using (var client = new AmazonSimpleNotificationServiceClient())
     {
         var topic = client.FindTopic(topicName);
         client.DeleteTopic(topic.TopicArn);
     }
 }
Exemplo n.º 4
0
        private string GetTopicArn(string topicName)
        {
            var topic = _client.FindTopic(topicName);

            if (topic != null)
            {
                return(topic.TopicArn);
            }

            var response = _client.CreateTopic(topicName);

            return(response?.TopicArn);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Ensures the topic.
        /// </summary>
        /// <param name="topicName">Name of the topic.</param>
        /// <param name="client">The client.</param>
        /// <returns>System.String.</returns>
        private string EnsureTopic(string topicName, AmazonSimpleNotificationServiceClient client)
        {
            var topic = client.FindTopic(topicName);

            if (topic != null)
            {
                return(topic.TopicArn);
            }

            _logger.DebugFormat("Topic with name {0} does not exist. Creating new topic", topicName);
            var topicResult = client.CreateTopic(topicName);

            return(topicResult.HttpStatusCode == HttpStatusCode.OK ? topicResult.TopicArn : string.Empty);
        }
        private void publishToSns(string subject, string message)
        {
            try {
                // Get the error SNS Topic
                var   sns   = new AmazonSimpleNotificationServiceClient(FatalErrorUserAccessKeyId, FatalErrorUserSecretAccessKey, RegionEndpoint.USEast2);
                Topic topic = sns.FindTopic(FatalErrorSnsTopic);

                // Publish to that Topic
                var             request  = new PublishRequest(topic.TopicArn, message, subject);
                PublishResponse response = sns.Publish(request);
            }

            // At this point, just tell the user about any publish errors...and exit
            catch (Exception e) {
                string msg = string.Format(FatalErrorReportFailedText, e.ToString());
                MessageBox.Show(msg, FatalErrorReportFailedCaption, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }