示例#1
0
        /// <summary>
        /// Sends notifications to the specified device token and device platform .
        /// </summary>
        /// <param name="notificationType">An enum specifying the notification type.</param>
        /// <param name="devicePlatform">An enum specifying the device platform.</param>
        /// <param name="deviceToken">A string containing the device token.</param>
        /// <param name="data">A dictionary containing the notification data.</param>
        public void SendNotification()
        {
            //string dToken = "69b81fdb67b24b8141f4a4539a558ffe8b19216de0d8ea2985dc1ca1653e75ef";
            //var appleCert = System.IO.File.ReadAllBytes(@"E:\Zohaib\Projects\Neeo\Services\Certificate\apn_identity.p12");
            //_push.RegisterAppleService(new ApplePushChannelSettings(true, appleCert, "PowerfulP1234"));
            //_push.QueueNotification(new AppleNotification()
            //                           .ForDeviceToken(dToken)
            //                           .WithAlert("Hello World!")
            //                           .WithBadge(7)
            //                           .WithSound("default"));

            //Thread.Sleep(10000);

            //-------------------------
            // WINDOWS NOTIFICATIONS
            //-------------------------
            //Configure and start Windows Notifications
            _push.RegisterWindowsService(new WindowsPushChannelSettings("POWERFULPALLTD.Neeo",
                                                                        "ms-app://s-1-15-2-1027086546-3793768442-914081366-159525117-234043670-2279954648-2289932992", "zwj31+N0gDU2gFwXXTSFN4wrLkGtKZ1/"));
            //Fluent construction of a Windows Toast Notification
            _push.QueueNotification(new WindowsToastNotification()
                                    .AsToastText01("Hy i am WNS")
                                    .ForChannelUri("https://db3.notify.windows.com/?token=AwYAAAC2cuRUeNPTE1OQAAwC1Lmb5BAD98Mk02%2fGY1HvP360VaRtVQqTWRVHWWfJY6RYwzeUICclQbT2nYKGRui18FGlI%2bM9zQW2vqcb7crbULg4GI7XvrSeJTwdKq9k9waOxAs%3d"));

            Thread.Sleep(20000);
        }
        /// <summary>
        /// Initilizes the push broker instance and creates a new DbContext, checks for both if there is no instance, if so creates a new one.
        /// </summary>
        private void InitBroker()
        {
            _broker          = _broker ?? new PushBroker();
            _databaseContext = _databaseContext ?? new PushSharpDatabaseContext();

            // subscribe to the push brokers API events
            _broker.OnNotificationSent          += broker_OnNotificationSent;
            _broker.OnNotificationFailed        += broker_OnNotificationFailed;
            _broker.OnServiceException          += broker_OnServiceException;
            _broker.OnNotificationRequeue       += broker_OnNotificationRequeue;
            _broker.OnDeviceSubscriptionExpired += broker_OnDeviceSubscriptionExpired;
            _broker.OnDeviceSubscriptionChanged += broker_OnDeviceSubscriptionChanged;
            _broker.OnChannelCreated            += broker_OnChannelCreated;
            _broker.OnChannelDestroyed          += broker_OnChannelDestroyed;
            _broker.OnChannelException          += broker_OnChannelException;

            _broker.RegisterGcmService(new GcmPushChannelSettings(_googlePushNotificationAuthToken));

            // NOTE: in this case we are skipping apple stuff,
            // if you wish to use apple iOS notifications uncomment below and use the proper cert i.e. dev/prod
            // _broker.RegisterAppleService(new ApplePushChannelSettings(false, _applePushNotificationCertificate, "Password"));

            _broker.RegisterWindowsService(_windowsPushNotificationChannelSettings);

            On(DisplayMessage, "Push Broker successfully initialized.");
        }
 /// <summary>
 ///
 /// </summary>
 public NotificationManager()
 {
     if (_push == null)
     {
         //Console.WriteLine("Constructor fired.");
         LogManager.CurrentInstance.InfoLogger.LogInfo(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Notification constructor is running.");
         try
         {
             _push = new PushBroker();
             //Registring events.
             _notificationMsgLength             = 0;
             _push.OnNotificationSent          += NotificationSent;
             _push.OnChannelException          += ChannelException;
             _push.OnServiceException          += ServiceException;
             _push.OnNotificationFailed        += NotificationFailed;
             _push.OnNotificationRequeue       += NotificationRequeue;
             _push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
             _push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
             _push.OnChannelCreated            += ChannelCreated;
             _push.OnChannelDestroyed          += ChannelDestroyed;
             var appleCertificate =
                 File.ReadAllBytes(ConfigurationManager.AppSettings[NeeoConstants.AppleCertificatePath]);
             var channelSettings = new ApplePushChannelSettings(IsProductionCertificate(), appleCertificate,
                                                                ConfigurationManager.AppSettings[NeeoConstants.AppleCertificatePwd], true);
             channelSettings.ConnectionTimeout = 36000;
             _push.RegisterAppleService(channelSettings);
             _push.RegisterGcmService(
                 new GcmPushChannelSettings(ConfigurationManager.AppSettings[NeeoConstants.GoogleApiKey]));
             _push.RegisterWindowsService(new WindowsPushChannelSettings(ConfigurationManager.AppSettings[NotificationConstants.WindowsPackageName],
                                                                         ConfigurationManager.AppSettings[NotificationConstants.WindowsSId],
                                                                         ConfigurationManager.AppSettings[NotificationConstants.WindowsClientSecret]));
         }
         catch (Exception exception)
         {
             LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, exception.Message, exception, System.Reflection.MethodBase.GetCurrentMethod().Name);
             //Console.WriteLine(exception);
         }
     }
 }
示例#4
0
        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();
        }
示例#5
0
        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();
        }
        /// <summary>
        /// Initilizes the push broker instance and creates a new DbContext, checks for both if there is no instance, if so creates a new one.
        /// </summary>
        private void InitBroker()
        {
            _broker = _broker ?? new PushBroker();
            _databaseContext = _databaseContext ?? new PushSharpDatabaseContext();

            // subscribe to the push brokers API events
            _broker.OnNotificationSent += broker_OnNotificationSent;
            _broker.OnNotificationFailed += broker_OnNotificationFailed;
            _broker.OnServiceException += broker_OnServiceException;
            _broker.OnNotificationRequeue += broker_OnNotificationRequeue;
            _broker.OnDeviceSubscriptionExpired += broker_OnDeviceSubscriptionExpired;
            _broker.OnDeviceSubscriptionChanged += broker_OnDeviceSubscriptionChanged;
            _broker.OnChannelCreated += broker_OnChannelCreated;
            _broker.OnChannelDestroyed += broker_OnChannelDestroyed;
            _broker.OnChannelException += broker_OnChannelException;

            _broker.RegisterGcmService(new GcmPushChannelSettings(_googlePushNotificationAuthToken));

            // NOTE: in this case we are skipping apple stuff, 
            // if you wish to use apple iOS notifications uncomment below and use the proper cert i.e. dev/prod
            // _broker.RegisterAppleService(new ApplePushChannelSettings(false, _applePushNotificationCertificate, "Password"));

            _broker.RegisterWindowsService(_windowsPushNotificationChannelSettings);

            On(DisplayMessage, "Push Broker successfully initialized.");
        }