コード例 #1
0
        public void Test_StopAll()
        {
            var b = new PushBroker();

            b.RegisterWindowsPhoneService("APP1");
            b.RegisterWindowsPhoneService("APP2");

            Assert.AreEqual(b.GetAllRegistrations().Count(), 12, "Expected Registrations");

            b.StopAllServices();

            Assert.AreEqual(b.GetAllRegistrations().Count(), 0, "Expected 0 Registrations");
        }
コード例 #2
0
ファイル: Pusher.cs プロジェクト: Ontropix/whowhat
        public Pusher()
        {
            broker = new PushBroker();

            broker.OnChannelException += BrokerOnOnChannelException;
            broker.OnNotificationFailed += BrokerOnOnNotificationFailed;
            broker.OnChannelCreated += BrokerOnOnChannelCreated;
            broker.OnNotificationSent += BrokerOnOnNotificationSent;

            broker.RegisterWindowsPhoneService();
        }
コード例 #3
0
 public static PushBroker GetBroker()
 {
     PushBroker pushBroker;
     if (HttpContext.Current.Application["PushBroker"] == null)
     {
         pushBroker = new PushBroker();
         pushBroker.RegisterWindowsPhoneService();
         HttpContext.Current.Application["PushBroker"] = pushBroker;
     }
     else
     {
         pushBroker = HttpContext.Current.Application["PushBroker"] as PushBroker;
     }
     return pushBroker;
 }
コード例 #4
0
        public static PushBroker GetBroker()
        {
            PushBroker pushBroker;

            if (HttpContext.Current.Application["PushBroker"] == null)
            {
                pushBroker = new PushBroker();
                pushBroker.RegisterWindowsPhoneService();
                HttpContext.Current.Application["PushBroker"] = pushBroker;
            }
            else
            {
                pushBroker = HttpContext.Current.Application["PushBroker"] as PushBroker;
            }
            return(pushBroker);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: FragCoder/PushSharp
        static void Main(string[] args)
        {
            //Create our push services broker
            var push = new PushBroker();

            //Wire up the events for all the services that the broker registers
            push.OnNotificationSent += NotificationSent;
            push.OnChannelException += ChannelException;
            push.OnServiceException += ServiceException;
            push.OnNotificationFailed += NotificationFailed;
            push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
            push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
            push.OnChannelCreated += ChannelCreated;
            push.OnChannelDestroyed += ChannelDestroyed;

            //------------------------------------------------
            //IMPORTANT NOTE about Push Service Registrations
            //------------------------------------------------
            //Some of the methods in this sample such as 'RegisterAppleServices' depend on you referencing the correct
            //assemblies, and having the correct 'using PushSharp;' in your file since they are extension methods!!!

            // If you don't want to use the extension method helpers you can register a service like this:
            //push.RegisterService<WindowsPhoneToastNotification>(new WindowsPhonePushService());

            //If you register your services like this, you must register the service for each type of notification
            //you want it to handle.  In the case of WindowsPhone, there are several notification types!

            //-------------------------
            // APPLE NOTIFICATIONS
            //-------------------------
            //Configure and start Apple APNS
            // IMPORTANT: Make sure you use the right Push certificate.  Apple allows you to generate one for connecting to Sandbox,
            //   and one for connecting to Production.  You must use the right one, to match the provisioning profile you build your
            //   app with!
            var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Resources/PushSharp.Apns.Sandbox.p12"));
            //IMPORTANT: If you are using a Development provisioning Profile, you must use the Sandbox push notification server
            //  (so you would leave the first arg in the ctor of ApplePushChannelSettings as 'false')
            //  If you are using an AdHoc or AppStore provisioning profile, you must use the Production push notification server
            //  (so you would change the first arg in the ctor of ApplePushChannelSettings to 'true')
            push.RegisterAppleService(new ApplePushChannelSettings(appleCert, "CERTIFICATE PASSWORD HERE")); //Extension method
            //Fluent construction of an iOS notification
            //IMPORTANT: For iOS you MUST MUST MUST use your own DeviceToken here that gets generated within your iOS app itself when the Application Delegate
            //  for registered for remote notifications is called, and the device token is passed back to you
            push.QueueNotification(new AppleNotification()
                                       .ForDeviceToken("DEVICE TOKEN HERE")
                                       .WithAlert("Hello World!")
                                       .WithBadge(7)
                                       .WithSound("sound.caf"));

            //---------------------------
            // ANDROID GCM NOTIFICATIONS
            //---------------------------
            //Configure and start Android GCM
            //IMPORTANT: The API KEY comes from your Google APIs Console App, under the API Access section,
            //  by choosing 'Create new Server key...'
            //  You must ensure the 'Google Cloud Messaging for Android' service is enabled in your APIs Console
            push.RegisterGcmService(new GcmPushChannelSettings("YOUR Google API's Console API Access  API KEY for Server Apps HERE"));
            //Fluent construction of an Android GCM Notification
            //IMPORTANT: For Android you MUST use your own RegistrationId here that gets generated within your Android app itself!
            push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("DEVICE REGISTRATION ID HERE")
                                  .WithJson("{\"alert\":\"Hello World!\",\"badge\":7,\"sound\":\"sound.caf\"}"));

            //-----------------------------
            // WINDOWS PHONE NOTIFICATIONS
            //-----------------------------
            //Configure and start Windows Phone Notifications
            push.RegisterWindowsPhoneService();
            //Fluent construction of a Windows Phone Toast notification
            //IMPORTANT: For Windows Phone you MUST use your own Endpoint Uri here that gets generated within your Windows Phone app itself!
            push.QueueNotification(new WindowsPhoneToastNotification()
                .ForEndpointUri(new Uri("DEVICE REGISTRATION CHANNEL URI HERE"))
                .ForOSVersion(WindowsPhoneDeviceOSVersion.MangoSevenPointFive)
                .WithBatchingInterval(BatchingInterval.Immediate)
                .WithNavigatePath("/MainPage.xaml")
                .WithText1("PushSharp")
                .WithText2("This is a Toast"));

            //-------------------------
            // WINDOWS NOTIFICATIONS
            //-------------------------
            //Configure and start Windows Notifications
            push.RegisterWindowsService(new WindowsPushChannelSettings("WINDOWS APP PACKAGE NAME HERE",
                "WINDOWS APP PACKAGE SECURITY IDENTIFIER HERE", "CLIENT SECRET HERE"));
            //Fluent construction of a Windows Toast Notification
            push.QueueNotification(new WindowsToastNotification()
                .AsToastText01("This is a test")
                .ForChannelUri("DEVICE CHANNEL URI HERE"));

            Console.WriteLine("Waiting for Queue to Finish...");

            //Stop and wait for the queues to drains
            push.StopAllServices();

            Console.WriteLine("Queue Finished, press return to exit...");
            Console.ReadLine();
        }
コード例 #6
0
ファイル: PushBid.aspx.cs プロジェクト: giangonz/GovBids
        protected void btnPush_Click(object sender, EventArgs e)
        {
            //Create our push services broker
            var push = new PushBroker();
            try
            {
                if (ddlBids.SelectedItem.Value != null && Convert.ToInt32(ddlBids.SelectedItem.Value) != 0)
                {
                    //Wire up the events for all the services that the broker registers
                    push.OnNotificationSent += NotificationSent;
                    push.OnNotificationFailed += NotificationFailed;

                    //Apple settings for push
                    string appdatafolder = Server.MapPath("~\\App_Data\\");
                    var appleCert = File.ReadAllBytes(Path.Combine(appdatafolder, ConfigurationManager.AppSettings["AppleCert"]));

                    //Development = false; Production = True
                    push.RegisterAppleService(new ApplePushChannelSettings(Convert.ToBoolean(ConfigurationManager.AppSettings["IsProduction"]), appleCert, ConfigurationManager.AppSettings["AppleCertPWD"]));

                    push.RegisterWindowsPhoneService();

                    //fetch all devices for push
                    foreach (var item in GovBidsDAL.FetchDataDeviceTokens())
                    {

                        switch (item.DeviceType)
                        {
                            case "iOS":
                                //Queue notification
                                push.QueueNotification(new AppleNotification()
                                                     .ForDeviceToken(item.DeviceToken)
                                                     .WithAlert(ConfigurationManager.AppSettings["NotificationLabel"] + " : " + GovBidsDAL.FetchDataBidByID(Convert.ToInt32(ddlBids.SelectedItem.Value)).Title)
                                                     .WithBadge(1)
                                                     .WithSound(ConfigurationManager.AppSettings["AppleSoundName"]));
                                break;
                            case "WP8":
                                push.QueueNotification(new WindowsPhoneToastNotification()
                                                     .ForEndpointUri(new Uri(item.DeviceToken))
                                                     .ForOSVersion(WindowsPhoneDeviceOSVersion.Eight)
                                                     .WithBatchingInterval(BatchingInterval.Immediate)
                                                     .WithNavigatePath("/MainPage.xaml")
                                                     .WithText1(ConfigurationManager.AppSettings["NotificationLabel"])
                                                     .WithText2(GovBidsDAL.FetchDataBidByID(Convert.ToInt32(ddlBids.SelectedItem.Value)).Title));
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                //Stop and wait for the queues to drains
                try
                {
                    push.StopAllServices();
                }
                catch (Exception) { }

                push = null;
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: genesissupsup/nkd
        static void Main(string[] args)
        {
            //Create our push services broker
            var push = new PushBroker();

            //Wire up the events for all the services that the broker registers
            push.OnNotificationSent          += NotificationSent;
            push.OnChannelException          += ChannelException;
            push.OnServiceException          += ServiceException;
            push.OnNotificationFailed        += NotificationFailed;
            push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
            push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
            push.OnChannelCreated            += ChannelCreated;
            push.OnChannelDestroyed          += ChannelDestroyed;


            //------------------------------------------------
            //IMPORTANT NOTE about Push Service Registrations
            //------------------------------------------------
            //Some of the methods in this sample such as 'RegisterAppleServices' depend on you referencing the correct
            //assemblies, and having the correct 'using PushSharp;' in your file since they are extension methods!!!

            // If you don't want to use the extension method helpers you can register a service like this:
            //push.RegisterService<WindowsPhoneToastNotification>(new WindowsPhonePushService());

            //If you register your services like this, you must register the service for each type of notification
            //you want it to handle.  In the case of WindowsPhone, there are several notification types!



            //-------------------------
            // APPLE NOTIFICATIONS
            //-------------------------
            //Configure and start Apple APNS
            // IMPORTANT: Make sure you use the right Push certificate.  Apple allows you to generate one for connecting to Sandbox,
            //   and one for connecting to Production.  You must use the right one, to match the provisioning profile you build your
            //   app with!
            var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Resources/PushSharp.Apns.Sandbox.p12"));

            //IMPORTANT: If you are using a Development provisioning Profile, you must use the Sandbox push notification server
            //  (so you would leave the first arg in the ctor of ApplePushChannelSettings as 'false')
            //  If you are using an AdHoc or AppStore provisioning profile, you must use the Production push notification server
            //  (so you would change the first arg in the ctor of ApplePushChannelSettings to 'true')
            push.RegisterAppleService(new ApplePushChannelSettings(appleCert, "CERTIFICATE PASSWORD HERE")); //Extension method
            //Fluent construction of an iOS notification
            //IMPORTANT: For iOS you MUST MUST MUST use your own DeviceToken here that gets generated within your iOS app itself when the Application Delegate
            //  for registered for remote notifications is called, and the device token is passed back to you
            push.QueueNotification(new AppleNotification()
                                   .ForDeviceToken("DEVICE TOKEN HERE")
                                   .WithAlert("Hello World!")
                                   .WithBadge(7)
                                   .WithSound("sound.caf"));


            //---------------------------
            // ANDROID GCM NOTIFICATIONS
            //---------------------------
            //Configure and start Android GCM
            //IMPORTANT: The API KEY comes from your Google APIs Console App, under the API Access section,
            //  by choosing 'Create new Server key...'
            //  You must ensure the 'Google Cloud Messaging for Android' service is enabled in your APIs Console
            push.RegisterGcmService(new GcmPushChannelSettings("YOUR Google API's Console API Access  API KEY for Server Apps HERE"));
            //Fluent construction of an Android GCM Notification
            //IMPORTANT: For Android you MUST use your own RegistrationId here that gets generated within your Android app itself!
            push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("DEVICE REGISTRATION ID HERE")
                                   .WithJson("{\"alert\":\"Hello World!\",\"badge\":7,\"sound\":\"sound.caf\"}"));


            //-----------------------------
            // WINDOWS PHONE NOTIFICATIONS
            //-----------------------------
            //Configure and start Windows Phone Notifications
            push.RegisterWindowsPhoneService();
            //Fluent construction of a Windows Phone Toast notification
            //IMPORTANT: For Windows Phone you MUST use your own Endpoint Uri here that gets generated within your Windows Phone app itself!
            push.QueueNotification(new WindowsPhoneToastNotification()
                                   .ForEndpointUri(new Uri("DEVICE REGISTRATION CHANNEL URI HERE"))
                                   .ForOSVersion(WindowsPhoneDeviceOSVersion.MangoSevenPointFive)
                                   .WithBatchingInterval(BatchingInterval.Immediate)
                                   .WithNavigatePath("/MainPage.xaml")
                                   .WithText1("PushSharp")
                                   .WithText2("This is a Toast"));


            //-------------------------
            // WINDOWS NOTIFICATIONS
            //-------------------------
            //Configure and start Windows Notifications
            push.RegisterWindowsService(new WindowsPushChannelSettings("WINDOWS APP PACKAGE NAME HERE",
                                                                       "WINDOWS APP PACKAGE SECURITY IDENTIFIER HERE", "CLIENT SECRET HERE"));
            //Fluent construction of a Windows Toast Notification
            push.QueueNotification(new WindowsToastNotification()
                                   .AsToastText01("This is a test")
                                   .ForChannelUri("DEVICE CHANNEL URI HERE"));



            Console.WriteLine("Waiting for Queue to Finish...");

            //Stop and wait for the queues to drains
            push.StopAllServices();

            Console.WriteLine("Queue Finished, press return to exit...");
            Console.ReadLine();
        }
コード例 #8
0
        protected void btnPush_Click(object sender, EventArgs e)
        {
            //Create our push services broker
            var push = new PushBroker();

            try
            {
                if (ddlBids.SelectedItem.Value != null && Convert.ToInt32(ddlBids.SelectedItem.Value) != 0)
                {
                    //Wire up the events for all the services that the broker registers
                    push.OnNotificationSent   += NotificationSent;
                    push.OnNotificationFailed += NotificationFailed;

                    //Apple settings for push
                    string appdatafolder = Server.MapPath("~\\App_Data\\");
                    var    appleCert     = File.ReadAllBytes(Path.Combine(appdatafolder, ConfigurationManager.AppSettings["AppleCert"]));


                    //Development = false; Production = True
                    push.RegisterAppleService(new ApplePushChannelSettings(Convert.ToBoolean(ConfigurationManager.AppSettings["IsProduction"]), appleCert, ConfigurationManager.AppSettings["AppleCertPWD"]));

                    push.RegisterWindowsPhoneService();


                    //fetch all devices for push
                    foreach (var item in GovBidsDAL.FetchDataDeviceTokens())
                    {
                        switch (item.DeviceType)
                        {
                        case "iOS":
                            //Queue notification
                            push.QueueNotification(new AppleNotification()
                                                   .ForDeviceToken(item.DeviceToken)
                                                   .WithAlert(ConfigurationManager.AppSettings["NotificationLabel"] + " : " + GovBidsDAL.FetchDataBidByID(Convert.ToInt32(ddlBids.SelectedItem.Value)).Title)
                                                   .WithBadge(1)
                                                   .WithSound(ConfigurationManager.AppSettings["AppleSoundName"]));
                            break;

                        case "WP8":
                            push.QueueNotification(new WindowsPhoneToastNotification()
                                                   .ForEndpointUri(new Uri(item.DeviceToken))
                                                   .ForOSVersion(WindowsPhoneDeviceOSVersion.Eight)
                                                   .WithBatchingInterval(BatchingInterval.Immediate)
                                                   .WithNavigatePath("/MainPage.xaml")
                                                   .WithText1(ConfigurationManager.AppSettings["NotificationLabel"])
                                                   .WithText2(GovBidsDAL.FetchDataBidByID(Convert.ToInt32(ddlBids.SelectedItem.Value)).Title));
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                //Stop and wait for the queues to drains
                try
                {
                    push.StopAllServices();
                }
                catch (Exception) { }

                push = null;
            }
        }
コード例 #9
0
ファイル: CoreTests.cs プロジェクト: 89sos98/PushSharp
		public void Test_StopAll()
		{
			var b = new PushBroker();

			b.RegisterWindowsPhoneService ("APP1");
			b.RegisterWindowsPhoneService ("APP2");

			Assert.AreEqual (b.GetAllRegistrations ().Count (), 12, "Expected Registrations");

			b.StopAllServices ();

			Assert.AreEqual (b.GetAllRegistrations ().Count (), 0, "Expected 0 Registrations");
		}