Пример #1
0
        private static void NotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args)
        {
            try
            {
                String notificationContent = String.Empty;

                switch (args.NotificationType)
                {
                case PushNotificationType.Badge:
                    notificationContent = args.BadgeNotification.Content.GetXml();
                    break;

                case PushNotificationType.Tile:
                    notificationContent = args.TileNotification.Content.GetXml();
                    break;

                case PushNotificationType.Toast:
                    notificationContent = args.ToastNotification.Content.GetXml();
                    break;

                case PushNotificationType.Raw:
                    notificationContent = args.RawNotification.Content;
                    break;
                }

                ToastMessage message = JsonConvert.DeserializeObject <ToastMessage>(notificationContent);
                if (App.ApplicationApplicationState == Enums.ApplicationStateType.Active)
                {
                    args.Cancel = true;
                    try
                    {
                        if (ChatPageViewModel.SelectedFriend.Id != message.FromId)
                        {
                            ToastHelper.DisplayTextToast(ToastTemplateType.ToastImageAndText01, message.FromId, message.Content, message.FromPicture);
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                    }
                }
                else
                {
                }
                ChatPageViewModel chatPageViewModel = ServiceLocator.Current.GetInstance <ChatPageViewModel>();
                chatPageViewModel.UpdateMessages(message.FromId, message.Content);
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
Пример #2
0
        private static void ToastReceived(object sender, NotificationEventArgs e)
        {
            string      path              = String.Empty;
            ToastPrompt toast             = null;
            string      externalImagePath = null;

            if (e.Collection.Keys.Count >= 3)
            {
                try
                {
                    string content      = e.Collection["wp:Text1"];
                    string extraContent = e.Collection["wp:Param"];
                    String senderId     = RetrieveSenderId(extraContent);

                    if (String.IsNullOrWhiteSpace(senderId) == false)
                    {
                        ToastMessage message = new ToastMessage()
                        {
                            Content     = content,
                            FromPicture = externalImagePath,
                            FromId      = senderId
                        };

                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            if (ChatPageViewModel.SelectedFriend.Id != message.FromId)
                            {
                                ShowToastMessage(e.Collection, extraContent, content, senderId);
                            }
                            else
                            {
                            }
                            ChatPageViewModel.UpdateMessages(message.FromId, message.Content);
                        });
                    }
                    else
                    {
                        int x = 0;
                        x++;
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
            }
        }