Ejemplo n.º 1
0
        public PushNotificationObject SettingConfigurationPushNotification(string strServer)
        {
            PushNotificationObject push = new PushNotificationObject();

            push.AppleDeviceSoundNotify = ConfigurationManager.AppSettings[strServer + "_AppleDeviceSoundNotify"];
            push.BundleId        = ConfigurationManager.AppSettings[strServer + "_BundleId"];
            push.FileP12Name     = ConfigurationManager.AppSettings[strServer + "_FileP12Name"];
            push.FileP12Password = ConfigurationManager.AppSettings[strServer + "_FileP12Password"];

            return(push);
        }
Ejemplo n.º 2
0
 private void UpdateEnvironmentPushNotification()
 {
     if (rdPushInternal.Checked)
     {
         pushObj = new Commons().SettingConfigurationPushNotification("INTERNAL");
     }
     else if (rdPushPublic.Checked)
     {
         pushObj = new Commons().SettingConfigurationPushNotification("PUBLIC");
     }
     else
     {
         pushObj = new Commons().SettingConfigurationPushNotification("ENTERPRISE");
     }
     pushObj.ListDevice = txtListDevicePush.Text.Split('\n');
     pushObj.Badge      = txtPushBadge.Text;
     pushObj.Alert      = txtPushMessages.Text;
 }
Ejemplo n.º 3
0
        public async Task SendIOSPushNotify(PushNotificationObject pushObject)
        {
            resultPush = "";
            //Task<string> getStringTask = client.GetStringAsync("start");
            PushNotificationResponse response = new PushNotificationResponse();
            WebClient wc1      = new WebClient();
            var       onlCert1 = wc1.DownloadData(pushObject.FileP12Name);
            // Configuration (NOTE: .pfx can also be used here)
            var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production,
                                               onlCert1, pushObject.FileP12Password);

            // Create a new broker
            var apnsBroker = new ApnsServiceBroker(config);

            // Wire up events
            apnsBroker.OnNotificationFailed += (notification, aggregateEx) =>
            {
                aggregateEx.Handle(ex =>
                {
                    // See what kind of exception it was to further diagnose
                    if (ex is ApnsNotificationException)
                    {
                        var notificationException = (ApnsNotificationException)ex;

                        // Deal with the failed notification
                        var apnsNotification = notificationException.Notification;
                        var statusCode       = notificationException.ErrorStatusCode;
                        resultPush          += ($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}") + Environment.NewLine;

                        //System.Console.WriteLine($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");
                    }
                    else
                    {
                        // Inner exception might hold more useful information dows.Forms.RichTextBox)mFormMain.Controls.Find("txtPushResults", true)[0];

                        resultPush = ($"Apple Notification Failed for some unknown reason : {ex.InnerException}") + Environment.NewLine;
                    }

                    // Mark it as handled
                    return(true);
                });
            };

            apnsBroker.OnNotificationSucceeded += (notification) =>
            {
                resultPush = ("Apple Notification Sent!") + Environment.NewLine;
            };

            // Start the broker
            apnsBroker.Start();
            string data = "{\"aps\":{\"badge\":" + pushObject.Badge + ", \"alert\": \"" + pushObject.Alert + "\", \"sound\": \"" + pushObject.AppleDeviceSoundNotify + "\"}}";

            foreach (var deviceToken in pushObject.ListDevice)
            {
                if (string.IsNullOrEmpty(deviceToken) || deviceToken.Equals("\r") || deviceToken.Equals("\n"))
                {
                    continue;
                }
                // Queue a notification to send
                apnsBroker.QueueNotification(new ApnsNotification
                {
                    DeviceToken = deviceToken,
                    Payload     = JObject.Parse(data)
                });
            }
            // Stop the broker, wait for it to finish
            // This isn't done after every message, but after you're
            // done with the broker
            apnsBroker.Stop();
            response.Message = "Success!";
            return;
        }