Beispiel #1
0
        public GcmPushChannel(GcmPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) : base(channelSettings, serviceSettings)
        {
            gcmSettings = channelSettings;

            transport = new GcmMessageTransportAsync();

            transport.MessageResponseReceived += new Action <GcmMessageTransportResponse>(transport_MessageResponseReceived);

            transport.UnhandledException += new Action <GcmNotification, Exception>(transport_UnhandledException);
        }
Beispiel #2
0
        public GcmPushChannel(GcmPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
            : base(channelSettings, serviceSettings)
        {
            gcmSettings = channelSettings;

            transport = new GcmMessageTransportAsync();

            transport.MessageResponseReceived += new Action<GcmMessageTransportResponse>(transport_MessageResponseReceived);

            transport.UnhandledException += new Action<GcmNotification, Exception>(transport_UnhandledException);
        }
Beispiel #3
0
		public GcmPushChannel(GcmPushChannelSettings channelSettings)
		{
			gcmSettings = channelSettings;

            if (gcmSettings != null && gcmSettings.ValidateServerCertificate)
            {
                ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
            }
            else
            {
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, policyErrs) => true; //Don't validate remote cert
            }
        }
Beispiel #4
0
        public GcmPushChannel(GcmPushChannelSettings channelSettings)
        {
            gcmSettings = channelSettings;

            if (gcmSettings != null && gcmSettings.ValidateServerCertificate)
            {
                ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
            }
            else
            {
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, policyErrs) => true; //Don't validate remote cert
            }
        }
Beispiel #5
0
        private void CreateAndroidPushSettings()
        {
            if (needAndroidPush == false)
            {
                return;
            }
            // Start service.
            string senderId = ConfigurationManager.AppSettings["AndroidAppPushSenderID"];    // 82654747314
            string apiKey   = ConfigurationManager.AppSettings["AndroidAppPushApiKey"];      // "AIzaSyCnmCx9MISzmx8G_XcnWI8DwsuIX7wjzac"
            string pkgName  = ConfigurationManager.AppSettings["AndroidAppPushPkgName"];     // "com.google.android.gcm.demo.app"

            androidPushChannelSettings = new PushSharp.Android.GcmPushChannelSettings(senderId, apiKey, pkgName);

            push.RegisterGcmService(androidPushChannelSettings);
        }
Beispiel #6
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");
        }
Beispiel #7
0
 public GcmPushChannel(GcmPushChannelSettings channelSettings)
 {
     gcmSettings = channelSettings as GcmPushChannelSettings;
 }
Beispiel #8
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);
            };
        }
Beispiel #9
0
 public GcmPushService(IPushChannelFactory pushChannelFactory, GcmPushChannelSettings channelSettings, IPushServiceSettings serviceSettings)
     : base(pushChannelFactory ?? new GcmPushChannelFactory(), channelSettings, serviceSettings)
 {
 }
Beispiel #10
0
 public GcmPushService(GcmPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
     : base(channelSettings, serviceSettings)
 {
 }
Beispiel #11
0
 public GcmPushChannel(GcmPushChannelSettings channelSettings)
 {
     gcmSettings = channelSettings as GcmPushChannelSettings;
 }
Beispiel #12
0
		public GcmPushService(IPushChannelFactory pushChannelFactory, GcmPushChannelSettings channelSettings)
			: this(pushChannelFactory, channelSettings, default(IPushServiceSettings))
		{
		}
Beispiel #13
0
 public void SetAndroidPushChannelSettings(string senderId, string apiKey, string pkgName)
 {
     androidPushChannelSettings = new PushSharp.Android.GcmPushChannelSettings(senderId, apiKey, pkgName);
     push.RegisterGcmService(androidPushChannelSettings);
 }
Beispiel #14
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");
		}
Beispiel #15
0
 public GcmPushChannel(GcmPushChannelSettings channelSettings) : this(channelSettings, null)
 {
 }
Beispiel #16
0
 public void StartGoogleCloudMessagingPushService(Android.GcmPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
 {
     gcmService = new Android.GcmPushService(channelSettings, serviceSettings);
     gcmService.Events.RegisterProxyHandler(this.Events);
 }
 public GcmPushChannelFactory(GcmPushChannelSettings channelSettings)
 {
     this.channelSettings = channelSettings;
 }
Beispiel #18
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.");
        }
Beispiel #19
0
        private void CreateAndroidPushSettings()
        {
            if (needAndroidPush == false)
            {
                return;
            }
            // Start service.
            string senderId = ConfigurationManager.AppSettings["AndroidAppPushSenderID"];    // 82654747314
            string apiKey = ConfigurationManager.AppSettings["AndroidAppPushApiKey"];        // "AIzaSyCnmCx9MISzmx8G_XcnWI8DwsuIX7wjzac"
            string pkgName = ConfigurationManager.AppSettings["AndroidAppPushPkgName"];      // "com.google.android.gcm.demo.app"
            androidPushChannelSettings = new PushSharp.Android.GcmPushChannelSettings(senderId, apiKey, pkgName);

            push.RegisterGcmService(androidPushChannelSettings);
        }
Beispiel #20
0
		public GcmPushService(GcmPushChannelSettings channelSettings, IPushServiceSettings serviceSettings)
			: this(default(IPushChannelFactory), channelSettings, serviceSettings)
		{
		}
		public static void RegisterGcmService(this IPushBroker broker, GcmPushChannelSettings channelSettings, string applicationId, IPushServiceSettings serviceSettings = null)
		{
			broker.RegisterService<GcmNotification>(new GcmPushService(new GcmPushChannelFactory(), channelSettings, serviceSettings), applicationId);
		}
Beispiel #22
0
		public GcmPushService(IPushChannelFactory pushChannelFactory, GcmPushChannelSettings channelSettings, IPushServiceSettings serviceSettings)
			: base(pushChannelFactory ?? new GcmPushChannelFactory(), channelSettings, serviceSettings)
		{
		}
Beispiel #23
0
 public GcmPushService(IPushChannelFactory pushChannelFactory, GcmPushChannelSettings channelSettings)
     : this(pushChannelFactory, channelSettings, default(IPushServiceSettings))
 {
 }
Beispiel #24
0
 public GcmPushService(GcmPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
     : base(new GcmPushChannelFactory(channelSettings), serviceSettings)
 {
 }
Beispiel #25
0
 public void SetAndroidPushChannelSettings(string senderId, string apiKey, string pkgName)
 {
     androidPushChannelSettings = new PushSharp.Android.GcmPushChannelSettings(senderId, apiKey, pkgName);
     push.RegisterGcmService(androidPushChannelSettings);
 }
Beispiel #26
0
 public GcmPushService(GcmPushChannelSettings channelSettings, IPushServiceSettings serviceSettings)
     : this(default(IPushChannelFactory), channelSettings, serviceSettings)
 {
 }
		public static void RegisterGcmService(this IPushBroker broker, GcmPushChannelSettings channelSettings, IPushServiceSettings serviceSettings = null)
		{
			RegisterGcmService (broker, channelSettings, null, serviceSettings);
		}