Example #1
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);

            ListPlatformApplicationsResponse resp = new ListPlatformApplicationsResponse();

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

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

                foreach (var obj in resp.PlatformApplications)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
Example #2
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);
        }
Example #3
0
        public static void SNSMobilePushAPIsListApplicationsEndpoints()
        {
            #region SNSMobilePushAPIsListApplicationsEndpoints
            var snsClient    = new AmazonSimpleNotificationServiceClient();
            var appsResponse = snsClient.ListPlatformApplications();

            foreach (var app in appsResponse.PlatformApplications)
            {
                Console.WriteLine();

                var appAttrsRequest = new GetPlatformApplicationAttributesRequest
                {
                    PlatformApplicationArn = app.PlatformApplicationArn
                };

                var appAttrsResponse =
                    snsClient.GetPlatformApplicationAttributes(appAttrsRequest);

                var endpointsByAppRequest =
                    new ListEndpointsByPlatformApplicationRequest
                {
                    PlatformApplicationArn = app.PlatformApplicationArn
                };

                var endpointsByAppResponse =
                    snsClient.ListEndpointsByPlatformApplication(
                        endpointsByAppRequest);

                Console.WriteLine("Application: " + app.PlatformApplicationArn);
                Console.WriteLine("  Properties: ");

                foreach (var attr in appAttrsResponse.Attributes)
                {
                    Console.WriteLine("    " + attr.Key + ": " + attr.Value);
                }

                Console.WriteLine("  Endpoints: ");

                foreach (var endpoint in endpointsByAppResponse.Endpoints)
                {
                    Console.WriteLine("     ARN: " + endpoint.EndpointArn);
                    Console.WriteLine("     Attributes: ");

                    foreach (var attr in endpoint.Attributes)
                    {
                        Console.WriteLine("       " + attr.Key + ": " + attr.Value);
                    }
                }
            }
            #endregion

            Console.ReadLine();
        }
Example #4
0
 public IEnumerable <string> ListApplications()
 {
     try
     {
         using (var snsclient = new AmazonSimpleNotificationServiceClient(_accesskey, _secretkey))
         {
             var listapps = snsclient.ListPlatformApplications(new ListPlatformApplicationsRequest());
             return(listapps.PlatformApplications.Select(s => s.PlatformApplicationArn));
         }
     }
     catch (Exception ex)
     {
         throw new Exception("ListApplications " + ex.Message);
     }
 }