public ApplePushChannel(ApplePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) : base(channelSettings, serviceSettings) { this.appleSettings = channelSettings; certificate = this.appleSettings.Certificate; certificates = new X509CertificateCollection(); if (appleSettings.AddLocalAndMachineCertificateStores) { var store = new X509Store(StoreLocation.LocalMachine); certificates.AddRange(store.Certificates); store = new X509Store(StoreLocation.CurrentUser); certificates.AddRange(store.Certificates); } certificates.Add(certificate); if (this.appleSettings.AdditionalCertificates != null) { foreach (var addlCert in this.appleSettings.AdditionalCertificates) { certificates.Add(addlCert); } } //Start our cleanup task taskCleanup = new Task(() => Cleanup(), TaskCreationOptions.LongRunning); taskCleanup.ContinueWith((t) => { var ex = t.Exception; }, TaskContinuationOptions.OnlyOnFaulted); taskCleanup.Start(); }
public void SetupFixture() { var channelSettings = Substitute.For<PushChannelSettings>(); var serviceSettings = new PushServiceSettings(); this.pushChannel = Substitute.For<PushChannelBase>(channelSettings, serviceSettings); var notification = Substitute.For<Notification>(); pushChannel.QueueNotification(notification); }
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); }
public WindowsPushChannel(WindowsPushChannelSettings channelSettings, PushServiceSettings serviceSettings) : base(channelSettings, serviceSettings) { windowsSettings = channelSettings; transport = new WindowsMessageTransportAsync(); transport.MessageResponseReceived += new Action <WindowsNotificationStatus>(transport_MessageResponseReceived); transport.UnhandledException += new Action <WindowsNotification, Exception>(transport_UnhandledException); }
public ApplePushChannel(ApplePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) : base(channelSettings, serviceSettings) { this.appleSettings = channelSettings; certificate = this.appleSettings.Certificate; certificates = new X509CertificateCollection(); certificates.Add(certificate); //Start our cleanup task taskCleanup = new Task(() => Cleanup(), TaskCreationOptions.LongRunning); taskCleanup.ContinueWith((t) => { var ex = t.Exception; }, TaskContinuationOptions.OnlyOnFaulted); taskCleanup.Start(); }
public void ThenTheScalerShouldAddAChannelToTheLoadBalancer() { var channelLoadBalancer = Substitute.For<ChannelLoadBalancer>(); channelLoadBalancer.HasActiveChannels.Returns(true); channelLoadBalancer.ChannelCount.Returns(1, 2, 3, 4, 5); var pushServiceSettings = new PushServiceSettings { AutoScaleChannels = false, Channels = 5 }; var channelScalerImp = new ChannelScalerImpl(pushServiceSettings, channelLoadBalancer); channelScalerImp.Start(); channelScalerImp.CheckScale(); channelLoadBalancer.Received(3).AddChannels(1); }
private Mock <PushServiceBase> MockUpService(PushServiceSettings serviceSettings, Action <INotification, SendNotificationCallbackDelegate> callback) { var mockChanSettings = new Mock <IPushChannelSettings>(); var mockChanFactory = new Mock <IPushChannelFactory>(); mockChanFactory.Setup(cf => cf.CreateChannel(It.IsAny <IPushChannelSettings>())) .Returns(() => MockUpChannel(callback).Object); var mockPushService = new Mock <PushServiceBase>(mockChanFactory.Object, mockChanSettings.Object, serviceSettings); mockPushService.Setup(ps => ps.BlockOnMessageResult).Returns(true); return(mockPushService); }
public void ThenTheScalerShouldAddAChannelToTheLoadBalancer() { var channelLoadBalancer = Substitute.For<ChannelLoadBalancer>(); channelLoadBalancer.HasActiveChannels.Returns(true); var pushServiceSettings = new PushServiceSettings(); var channelScalerImp = new ChannelScalerImpl(pushServiceSettings, channelLoadBalancer); channelScalerImp.Start(); int measurementCounter = 0; while (measurementCounter < 1000) { channelScalerImp.RecordQueueTime(pushServiceSettings.MinAvgTimeToScaleChannels + 1); measurementCounter++; } channelScalerImp.CheckScale(); channelLoadBalancer.Received(1).AddChannels(1); }
public ApplePushService(ApplePushChannelSettings channelSettings, PushServiceSettings serviceSettings) : base(channelSettings, serviceSettings) { var appleChannelSettings = channelSettings as ApplePushChannelSettings; //cancelTokenSource = new CancellationTokenSource(); feedbackService = new FeedbackService(); feedbackService.OnFeedbackReceived += new FeedbackService.FeedbackReceivedDelegate(feedbackService_OnFeedbackReceived); //allow control over feedback call interval, if set to zero, don't make feedback calls automatically if (appleChannelSettings.FeedbackIntervalMinutes > 0) { timerFeedback = new Timer(new TimerCallback((state) => { try { feedbackService.Run(channelSettings as ApplePushChannelSettings /*, this.cancelTokenSource.Token*/); } catch (Exception ex) { this.Events.RaiseChannelException(ex); } //Timer will run first after 10 seconds, then every 10 minutes to get feedback! }), null, TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(appleChannelSettings.FeedbackIntervalMinutes)); } }
public PushNotify Configure() { if (_pushBroker == null) { _pushBroker = new PushBroker(); _pushBroker.OnNotificationSent += NotificationSent; _pushBroker.OnChannelException += ChannelException; _pushBroker.OnServiceException += ServiceException; _pushBroker.OnNotificationFailed += NotificationFailed; _pushBroker.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired; _pushBroker.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged; _pushBroker.OnChannelCreated += ChannelCreated; _pushBroker.OnChannelDestroyed += ChannelDestroyed; var settings = new PushServiceSettings(); settings.MaxNotificationRequeues = 1000; settings.MinAvgTimeToScaleChannels = 1000; settings.NotificationSendTimeout = 15000; settings.IdleTimeout = TimeSpan.FromMinutes(10); settings.AutoScaleChannels = true; _pushBroker.RegisterGcmService(new GcmPushChannelSettings(Config.BrowserKey), settings); } return(this); }
public C2dmPushChannel(C2dmPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) : base(channelSettings, serviceSettings) { androidSettings = channelSettings; //Go get the auth token from google try { RefreshGoogleAuthToken(); } catch (GoogleLoginAuthorizationException glaex) { this.Events.RaiseChannelException(glaex, PlatformType.AndroidC2dm); } transport = new C2dmMessageTransportAsync(); transport.UpdateGoogleClientAuthToken += new Action <string>((newToken) => { this.googleAuthToken = newToken; }); transport.MessageResponseReceived += new Action <C2dmMessageTransportResponse>(transport_MessageResponseReceived); transport.UnhandledException += new Action <C2dmNotification, Exception>(transport_UnhandledException); }
public WindowsPushChannel(WindowsPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) : base(channelSettings, serviceSettings) { this.channelSettings = channelSettings; }
public GcmPushService(GcmPushChannelSettings channelSettings, PushServiceSettings serviceSettings) : base(channelSettings, serviceSettings) { }
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 svcSettings = new PushServiceSettings() { AutoScaleChannels = false, Channels = 1 }; var settings = new GcmPushChannelSettings("SENDERAUTHTOKEN"); settings.OverrideUrl("http://localhost:" + (testPort) + "/"); var push = new GcmPushService(settings, svcSettings); 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(); Console.WriteLine("Avg Queue Wait Time: " + push.AverageQueueWaitTime + " ms"); Console.WriteLine("Avg Send Time: " + push.AverageSendTime + " ms"); push.Dispose(); server.Dispose(); //waitServerFinished.WaitOne(); Console.WriteLine("TEST-> DISPOSE."); }
public TestablePushService(PushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) : base(channelSettings, serviceSettings) { }
public void StartApplePushService(Apple.ApplePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) { appleService = new Apple.ApplePushService(channelSettings, serviceSettings); appleService.Events.RegisterProxyHandler(this.Events); }
public static void RegisterWindowsService(this PushBroker broker, WindowsPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) { var service = new WindowsPushService(new WindowsPushChannelFactory(), channelSettings, serviceSettings); broker.RegisterService <WindowsRawNotification>(service); broker.RegisterService <WindowsTileNotification>(service); broker.RegisterService <WindowsToastNotification>(service); broker.RegisterService <WindowsBadgeNumericNotification>(service); broker.RegisterService <WindowsBadgeGlyphNotification>(service); }
public static void RegisterWindowsPhoneService(this PushBroker broker, WindowsPhonePushChannelSettings channelSettings = null, PushServiceSettings serviceSettings = null) { var service = new WindowsPhonePushService(new WindowsPhonePushChannelFactory(), channelSettings, serviceSettings); broker.RegisterService <WindowsPhoneCycleTileNotification>(service); broker.RegisterService <WindowsPhoneFlipTileNotification>(service); broker.RegisterService <WindowsPhoneIconicTileNotification>(service); broker.RegisterService <WindowsPhoneTileNotification>(service); broker.RegisterService <WindowsPhoneToastNotification>(service); broker.RegisterService <WindowsPhoneRawNotification>(service); }
public void StartWindowsPhonePushService(WindowsPhone.WindowsPhonePushChannelSettings channelSettings = null, PushServiceSettings serviceSettings = null) { wpService = new WindowsPhone.WindowsPhonePushService(channelSettings, serviceSettings); wpService.Events.RegisterProxyHandler(this.Events); }
public void StartGoogleCloudMessagingPushService(Android.GcmPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) { gcmService = new Android.GcmPushService(channelSettings, serviceSettings); gcmService.Events.RegisterProxyHandler(this.Events); }
public void StartAndroidPushService(Android.C2dmPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) { androidService = new Android.C2dmPushService(channelSettings, serviceSettings); androidService.Events.RegisterProxyHandler(this.Events); }
public void TestNotifications(int toQueue, int expectSuccessful, int expectFailed, int[] idsToFail = null, bool waitForScaling = false, bool autoScale = false) { var testServer = new ApnsNodeTestServer("http://localhost:8888/"); testServer.Reset(); testServer.Setup(idsToFail ?? new int[] {}); var started = DateTime.UtcNow; int pushFailCount = 0; int pushSuccessCount = 0; AppleNotification.ResetIdentifier(); var settings = new ApplePushChannelSettings(false, appleCert, "pushsharp", true); settings.OverrideServer("localhost", 2195); settings.SkipSsl = true; settings.MillisecondsToWaitBeforeMessageDeclaredSuccess = 5000; var serviceSettings = new PushServiceSettings(); if (!autoScale) { serviceSettings.AutoScaleChannels = false; serviceSettings.Channels = 1; } var push = new ApplePushService(settings, serviceSettings); push.OnNotificationFailed += (sender, notification1, error) => { Console.WriteLine("NOTIFICATION FAILED: " + ((AppleNotification)notification1).Identifier); pushFailCount++; }; push.OnNotificationSent += (sender, notification1) => { pushSuccessCount++; }; push.OnNotificationRequeue += (sender, e) => { Console.WriteLine("REQUEUE: " + ((AppleNotification)e.Notification).Identifier); }; for (int i = 0; i < toQueue; i++) { var n = new AppleNotification("aff441e214b2b2283df799f0b8b16c17a59b7ac077e2867ea54ebf6086e55866").WithAlert("Test"); push.QueueNotification(n); } 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(); Console.WriteLine("Avg Queue Wait Time: " + push.AverageQueueWaitTime + " ms"); Console.WriteLine("Avg Send Time: " + push.AverageSendTime + " ms"); var span = DateTime.UtcNow - started; var info = testServer.GetInfo(); Console.WriteLine("Test Time: " + span.TotalMilliseconds + " ms"); Console.WriteLine("Client Failed: {0} Succeeded: {1} Sent: {2}", pushFailCount, pushSuccessCount, toQueue); Console.WriteLine("Server Failed: {0} Succeeded: {1} Received: {2} Discarded: {3}", info.FailedIds.Length, info.SuccessIds.Length, info.Received, info.Discarded); //Assert.AreEqual(toQueue, info.Received, "Server - Received Count"); Assert.AreEqual(expectFailed, info.FailedIds.Length, "Server - Failed Count"); Assert.AreEqual(expectSuccessful, info.SuccessIds.Length, "Server - Success Count"); Assert.AreEqual(expectFailed, pushFailCount, "Client - Failed Count"); Assert.AreEqual(expectSuccessful, pushSuccessCount, "Client - Success Count"); }
public static void RegisterAdmService(this PushBroker broker, AdmPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) { broker.RegisterService <AdmNotification>(new AdmPushService(new AdmPushChannelFactory(), channelSettings, serviceSettings)); }
public void StartBlackberryPushService(Blackberry.BlackberryPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) { bbService = new Blackberry.BlackberryPushService(channelSettings, serviceSettings); bbService.Events.RegisterProxyHandler(this.Events); }
public WindowsPhonePushService(WindowsPhonePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) : base(channelSettings, serviceSettings) { }
public C2dmPushService(C2dmPushChannelSettings channelSettings, PushServiceSettings serviceSettings = null) : base(channelSettings, serviceSettings) { }