Exemplo n.º 1
0
        /// <summary>
        /// Sends the notification asynchronous.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>Task.</returns>
        private async Task SendNotificationAsync(string message)
        {
            try
            {
                Services.Log.Info("Send notification without tag");
                var resultWns = await Services.Push.SendAsync(PushHelper.GetWindowsPushMessageForToastText01(message));

                var json = JsonConvert.SerializeObject(resultWns);
                Debug.WriteLine(json);
                Services.Log.Info(string.Format("Wns-{0}", json));
                var resultGcm = await Services.Push.SendAsync(PushHelper.GetGooglePushMessage(message));

                Services.Log.Info(string.Format("Gcm-{0}", JsonConvert.SerializeObject(resultGcm)));
                var resultMpns = await Services.Push.SendAsync(PushHelper.GetMPNSMessage(message));

                Services.Log.Info(string.Format("Mnps-{0}", JsonConvert.SerializeObject(resultMpns)));
                var resultApns = await Services.Push.SendAsync(PushHelper.GetApplePushMessage(message));

                Services.Log.Info(string.Format("Apns-{0}", JsonConvert.SerializeObject(resultApns)));

                await Services.Push.SendAsync(PushHelper.GetWindowsPushMessageForToastText01(message));

                await Services.Push.SendAsync(PushHelper.GetGooglePushMessage(message));

                await Services.Push.SendAsync(PushHelper.GetMPNSMessage(message));

                await Services.Push.SendAsync(PushHelper.GetApplePushMessage(message));

                Services.Log.Info("Send notification using someTag");
                const string otherMessage = "A second tag was added in AMS.";

                resultWns = await Services.Push.SendAsync(PushHelper.GetWindowsPushMessageForToastText01(otherMessage), NotificationHandler.SomeTag);

                Services.Log.Info(string.Format("Wns-{0}", JsonConvert.SerializeObject(resultWns)));
                resultGcm = await Services.Push.SendAsync(PushHelper.GetGooglePushMessage(otherMessage), NotificationHandler.SomeTag);

                Services.Log.Info(string.Format("Gcm-{0}", JsonConvert.SerializeObject(resultGcm)));
                resultMpns = await Services.Push.SendAsync(PushHelper.GetMPNSMessage(otherMessage), NotificationHandler.SomeTag);

                Services.Log.Info(string.Format("Mnps-{0}", JsonConvert.SerializeObject(resultMpns)));
                resultApns = await Services.Push.SendAsync(PushHelper.GetApplePushMessage(otherMessage), NotificationHandler.SomeTag);

                Services.Log.Info(string.Format("Apns-{0}", JsonConvert.SerializeObject(resultApns)));
            }
            catch (Exception exception)
            {
                Services.Log.Error(exception);
            }
        }