Exemplo n.º 1
0
        public static ResultPush Ios(IosMessage iosMessage)
        {
            ResultPush       resultPush  = new ResultPush();
            X509Certificate2 certificate = new X509Certificate2(File.ReadAllBytes(GetConfig.Certificate.IOS), GetConfig.Certificate.IOSPassword);

            var        appleCert = File.ReadAllBytes(GetConfig.Certificate.IOS);
            PushBroker push      = Pusher(resultPush);

            push.RegisterAppleService(new ApplePushChannelSettings(false, certificate));

            AppleNotificationPayload appleNotificationPayload = new AppleNotificationPayload(iosMessage.Alert, iosMessage.Badge.Value, iosMessage.Sound.ToString());

            var appleNotification = new AppleNotification()
                                    .ForDeviceToken(iosMessage.DeviceToken)
                                    .WithPayload(appleNotificationPayload);


            if (iosMessage.Sound.HasValue)
            {
                appleNotification.WithSound(iosMessage.Sound.ToString());
            }

            if (iosMessage.Badge.HasValue)
            {
                appleNotification.WithBadge(iosMessage.Badge.Value);
            }

            push.QueueNotification(appleNotification);

            return(resultPush);
        }
Exemplo n.º 2
0
        private static PushBroker Pusher(ResultPush resultPush)
        {
            PushBroker push = new PushBroker(resultPush);

            push.OnNotificationSent          += NotificationSent;
            push.OnChannelException          += ChannelException;
            push.OnServiceException          += ServiceException;
            push.OnNotificationFailed        += NotificationFailed;
            push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
            push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
            push.OnChannelCreated            += ChannelCreated;
            push.OnChannelDestroyed          += ChannelDestroyed;

            return(push);
        }
Exemplo n.º 3
0
        public static ResultPush Android(AndroidMessage androidMessage)
        {
            ResultPush resultPush = new ResultPush();

            if (androidMessage != null)
            {
                PushBroker push = Pusher(resultPush);

                push.RegisterGcmService(new GcmPushChannelSettings(GetConfig.Key.Android));
                var jsonObject = JsonConvert.SerializeObject(androidMessage, SerializerSettings());

                push.QueueNotification(new GcmNotification()
                                       .ForDeviceRegistrationId(androidMessage.DeviceTokens)
                                       .WithJson(jsonObject));
            }

            return(resultPush);
        }
Exemplo n.º 4
0
 public static void NotificationFailed(object sender, INotification notification, Exception notificationFailureException, ResultPush resultPush)
 {
     resultPush.CallbackFailed(sender, notification, notificationFailureException);
     Console.WriteLine("Failure: " + sender + " -> " + notificationFailureException.Message + " -> " + notification);
 }
Exemplo n.º 5
0
 public static void NotificationSent(object sender, INotification notification, ResultPush resultPush)
 {
     resultPush.CallbackSent(sender, notification);
     Console.WriteLine("Sent: " + sender + " -> " + notification);
 }
Exemplo n.º 6
0
 public void QueueNotification(INotification notification, ResultPush resultPush)
 {
     this.resultPush = resultPush;
     QueueNotification(notification, false);
 }
Exemplo n.º 7
0
 public PushBroker(ResultPush resultPush)
 {
     serviceRegistrations = new List <ServiceRegistration> ();
     this.resultPush      = resultPush;
 }