Esempio n. 1
0
 public void StartGoogleCloudMessagingPushService(Android.GcmPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
 {
     gcmService = new Android.GcmPushService(channelSettings, serviceSettings);
     gcmService.Events.RegisterProxyHandler(this.Events);
 }
Esempio n. 2
0
        public void TestNotifications(List<GcmNotification> notifications,
		                              List<GcmMessageResponseFilter> responseFilters,
		                              Action<object, INotification> sentCallback,
		                              Action<object, INotification, Exception> failedCallback,
		                              Action<object, string, string, INotification> subscriptionChangedCallback,
		                              Action<object, string, DateTime, INotification> subscriptionExpiredCallback)
        {
            testPort++;

            int pushFailCount = 0;
            int pushSuccessCount = 0;

            int serverReceivedCount = 0;
            int serverReceivedFailCount = 0;
            int serverReceivedSuccessCount = 0;

            var server = new TestServers.GcmTestServer();

            server.MessageResponseFilters.AddRange(responseFilters);

            server.Start(testPort, response => {
                serverReceivedCount += (int)response.NumberOfCanonicalIds;
                serverReceivedSuccessCount += (int) response.NumberOfSuccesses;
                serverReceivedFailCount += (int) response.NumberOfFailures;
            });

            var settings = new GcmPushChannelSettings("SENDERAUTHTOKEN");
            settings.OverrideUrl("http://localhost:" + (testPort) + "/");

            var push = new GcmPushService(settings);
            push.OnNotificationSent += (sender, notification1) => {
                pushSuccessCount++;
                sentCallback(sender, notification1);
            };
            push.OnNotificationFailed += (sender, notification1, error) => {
                pushFailCount++;
                failedCallback(sender, notification1, error);
            };
            push.OnDeviceSubscriptionChanged += (sender, oldSubscriptionId, newSubscriptionId, notification) => subscriptionChangedCallback(sender, oldSubscriptionId, newSubscriptionId, notification);
            push.OnDeviceSubscriptionExpired += (sender, expiredSubscriptionId, expirationDateUtc, notification) => subscriptionExpiredCallback(sender, expiredSubscriptionId, expirationDateUtc, notification);

            foreach (var n in notifications)
                push.QueueNotification(n);

            push.Stop();
            push.Dispose();

            server.Dispose();
            //waitServerFinished.WaitOne();

            Console.WriteLine("TEST-> DISPOSE.");
        }
Esempio n. 3
0
        public void TestNotifications(bool shouldBatch, int toQueue, int expectSuccessful, int expectFailed, int[] indexesToFail = null)
        {
            testPort++;

            int msgIdOn = 1000;

            int pushFailCount = 0;
            int pushSuccessCount = 0;

            int serverReceivedCount = 0;
            int serverReceivedFailCount = 0;
            int serverReceivedSuccessCount = 0;

            //var notification = new GcmNotification();

            var server = new TestServers.GcmTestServer();

            server.MessageResponseFilters.Add(new GcmMessageResponseFilter()
            {
                IsMatch = (request, s) => {
                    return s.Equals("FAIL", StringComparison.InvariantCultureIgnoreCase);
                },
                Status = new GcmMessageResult() {
                    ResponseStatus = GcmMessageTransportResponseStatus.InvalidRegistration,
                    MessageId = "1:" + msgIdOn++
                }
            });

            server.MessageResponseFilters.Add(new GcmMessageResponseFilter()
                                              {
                IsMatch = (request, s) => {
                    return s.Equals("NOTREGISTERED", StringComparison.InvariantCultureIgnoreCase);
                },
                Status = new GcmMessageResult() {
                    ResponseStatus = GcmMessageTransportResponseStatus.NotRegistered,
                    MessageId = "1:" + msgIdOn++
                }
            });
            //var waitServerFinished = new ManualResetEvent(false);

            server.Start(testPort, response =>
                        {
                            serverReceivedCount += (int)response.NumberOfCanonicalIds;
                            serverReceivedSuccessCount += (int) response.NumberOfSuccesses;
                            serverReceivedFailCount += (int) response.NumberOfFailures;
                        });

            var settings = new GcmPushChannelSettings("SENDERAUTHTOKEN");
            settings.OverrideUrl("http://*****:*****@"{""key"":""value1""}";

            if (shouldBatch)
            {
                var regIds = new List<string>();

                for (int i = 0; i < toQueue; i++)
                    regIds.Add((indexesToFail != null && indexesToFail.Contains(i)) ? "FAIL" : "SUCCESS");

                var n = new GcmNotification();
                n.RegistrationIds.AddRange(regIds);
                n.WithJson(json);

                push.QueueNotification(n);
            }
            else
            {
                for (int i = 0; i < toQueue; i++)
                    push.QueueNotification(new GcmNotification()
                        .ForDeviceRegistrationId((indexesToFail != null && indexesToFail.Contains(i)) ? "FAIL" : "SUCCESS")
                        .WithJson(json));
            }

            push.Stop();
            push.Dispose();

            server.Dispose();
            //waitServerFinished.WaitOne();

            Console.WriteLine("TEST-> DISPOSE.");

            Assert.AreEqual(toQueue, serverReceivedCount, "Server - Received Count");
            Assert.AreEqual(expectFailed, serverReceivedFailCount, "Server - Failed Count");
            Assert.AreEqual(expectSuccessful, serverReceivedSuccessCount, "Server - Success Count");

            Assert.AreEqual(expectFailed, pushFailCount, "Client - Failed Count");
            Assert.AreEqual(expectSuccessful, pushSuccessCount, "Client - Success Count");
        }
Esempio n. 4
0
        static TrackService()
        {
            string senderID = "719481524012";
            string senderAuthToken = "AIzaSyA9zRa6qCBuso46zW-PzTiNQUkp4rGjFC4";
            string applicationIdPackageName = "xamarin.TrackMe";

            GcmPushChannelSettings settings = new GcmPushChannelSettings (senderID, senderAuthToken, applicationIdPackageName);
            pushService = new GcmPushService (settings);

            pushService.Events.OnDeviceSubscriptionExpired += delegate(PushSharp.Common.PlatformType platform, string deviceInfo, PushSharp.Common.Notification notification) {
                LogService.Log ("DeviceSubscriptionExpired: " + deviceInfo);
            };
            pushService.Events.OnDeviceSubscriptionIdChanged += delegate(PushSharp.Common.PlatformType platform, string oldDeviceInfo, string newDeviceInfo, PushSharp.Common.Notification notification) {
                LogService.Log ("DeviceSubscriptionIdChanged: " + oldDeviceInfo + " " + newDeviceInfo);
            };
            pushService.Events.OnChannelException += delegate(Exception exception, PushSharp.Common.PlatformType platformType, PushSharp.Common.Notification notification) {
                LogService.Log ("ChannelException: " + exception);
            };
            pushService.Events.OnNotificationSendFailure += delegate(PushSharp.Common.Notification notification, Exception notificationFailureException) {
                LogService.Log ("NotificationSendFailure: " + notificationFailureException);
            };
            pushService.Events.OnNotificationSent += delegate(PushSharp.Common.Notification notification) {
                LogService.Log ("NotificationSent: " + notification);
            };
        }
Esempio n. 5
0
		public void TestNotifications(bool shouldBatch, int toQueue, int expectSuccessful, int expectFailed, int[] indexesToFail = null, bool waitForScaling = false)
		{
			testPort++;

			int msgIdOn = 1000;

			int pushFailCount = 0;
			int pushSuccessCount = 0;

			int serverReceivedCount = 0;
			int serverReceivedFailCount = 0;
			int serverReceivedSuccessCount = 0;

			//var notification = new GcmNotification();

			var server = new TestServers.GcmTestServer();

			server.MessageResponseFilters.Add(new GcmMessageResponseFilter()
			{
				IsMatch = (request, s) => {
					return s.Equals("FAIL", StringComparison.InvariantCultureIgnoreCase);
				},
				Status = new GcmMessageResult() { 
					ResponseStatus = GcmMessageTransportResponseStatus.InvalidRegistration,
					MessageId = "1:" + msgIdOn++
				}
			});

			server.MessageResponseFilters.Add(new GcmMessageResponseFilter()
			                                  {
				IsMatch = (request, s) => {
					return s.Equals("NOTREGISTERED", StringComparison.InvariantCultureIgnoreCase);
				},
				Status = new GcmMessageResult() { 
					ResponseStatus = GcmMessageTransportResponseStatus.NotRegistered,
					MessageId = "1:" + msgIdOn++
				}
			});
			//var waitServerFinished = new ManualResetEvent(false);
			
			server.Start(testPort, response =>
						{
							serverReceivedCount += (int)response.NumberOfCanonicalIds;
							serverReceivedSuccessCount += (int) response.NumberOfSuccesses;
							serverReceivedFailCount += (int) response.NumberOfFailures;
						});

			

			var settings = new GcmPushChannelSettings("SENDERAUTHTOKEN");
			settings.OverrideUrl("http://*****:*****@"{""key"":""value1""}";

			if (shouldBatch)
			{
				var regIds = new List<string>();

				for (int i = 0; i < toQueue; i++)
					regIds.Add((indexesToFail != null && indexesToFail.Contains(i)) ? "FAIL" : "SUCCESS");

				var n = new GcmNotification();
				n.RegistrationIds.AddRange(regIds);
				n.WithJson(json);
				
				push.QueueNotification(n);
			}
			else
			{
				for (int i = 0; i < toQueue; i++)
					push.QueueNotification(new GcmNotification()
						.ForDeviceRegistrationId((indexesToFail != null && indexesToFail.Contains(i)) ? "FAIL" : "SUCCESS")
						.WithJson(json));
			}

			

			

            Console.WriteLine("Avg Queue Wait Time: " + push.AverageQueueWaitTime + " ms");
            Console.WriteLine("Avg Send Time: " + push.AverageSendTime + " ms");

            if (waitForScaling)
            {
               while (push.QueueLength > 0)
                   Thread.Sleep(500);

                Console.WriteLine("Sleeping 3 minutes for autoscaling...");
                Thread.Sleep(TimeSpan.FromMinutes(3));

                Console.WriteLine("Channel Count: " + push.ChannelCount);
                Assert.IsTrue(push.ChannelCount <= 1);
            }

            push.Stop();
			push.Dispose();

			server.Dispose();
			//waitServerFinished.WaitOne();

			Console.WriteLine("TEST-> DISPOSE.");

			Assert.AreEqual(toQueue, serverReceivedCount, "Server - Received Count");
			Assert.AreEqual(expectFailed, serverReceivedFailCount, "Server - Failed Count");
			Assert.AreEqual(expectSuccessful, serverReceivedSuccessCount, "Server - Success Count");

			Assert.AreEqual(expectFailed, pushFailCount, "Client - Failed Count");
			Assert.AreEqual(expectSuccessful, pushSuccessCount, "Client - Success Count");
		}
Esempio n. 6
0
 public void StartGoogleCloudMessagingPushService(Android.GcmPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
 {
     gcmService = new Android.GcmPushService(channelSettings, serviceSettings);
     gcmService.Events.RegisterProxyHandler(this.Events);
 }