Example #1
0
        private async void OnPushNotification(PushNotificationChannel sender, PushNotificationReceivedEventArgs e)
        {
            String notificationContent = String.Empty;

            e.Cancel = true;

            switch (e.NotificationType)
            {
            // Badges are not yet supported and will be added in a future version
            case PushNotificationType.Badge:
                notificationContent = e.BadgeNotification.Content.GetXml();
                break;

            // Tiles are not yet supported and will be added in a future version
            case PushNotificationType.Tile:
                notificationContent = e.TileNotification.Content.GetXml();
                break;

            // The current version of AzureChatr only works via toast notifications
            case PushNotificationType.Toast:
                notificationContent = e.ToastNotification.Content.GetXml();
                XmlDocument toastXml = e.ToastNotification.Content;

                // Extract the relevant chat item data from the toast notification payload
                XmlNodeList toastTextAttributes = toastXml.GetElementsByTagName("text");
                string      username            = toastTextAttributes[0].InnerText;
                string      chatline            = toastTextAttributes[1].InnerText;
                string      chatdatetime        = toastTextAttributes[2].InnerText;

                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    var chatItem = new ChatItem {
                        Text = chatline, UserName = username
                    };
                    // Post the new chat item received in the chat window.
                    // IMPORTANT: If you updated the code above to post new chat lines from
                    //            the current user immediately in the chat window, you will
                    //            end up with duplicates here. You need to filter-out the
                    //            current user's chat entries to avoid these duplicates.
                    items.Add(chatItem);
                    ScrollDown();
                });

                // This is a quick and dirty way to make sure that we don't use speech synthesis
                // to read the current user's chat lines out loud
                if (chatline != lastChatline)
                {
                    ReadText(username + " says: " + chatline);
                }

                break;

            // Raw notifications are not used in this version
            case PushNotificationType.Raw:
                notificationContent = e.RawNotification.Content;
                break;
            }
            //e.Cancel = true;
        }
Example #2
0
        // Inserts a new chat item to the conversation by posting it in the Azure Mobile
        // Services table, and posting it in the application's chat window
        private async void InsertChatItem(ChatItem chatItem)
        {
            // This code inserts a new ChatItem into the database. When the operation completes
            // and Mobile Services has assigned an Id, the item is added to the CollectionView
            await chatTable.InsertAsync(chatItem);

            // When the following line is commented, the new chat item from the current user is
            // NOT posted to the current chat window. It instead waits until the chat item is
            // received in a push notification and intercepted by the app, and then displayed.
            //items.Add(chatItem);
        }
Example #3
0
        // Prepares the chat item to be sent to the cloud
        private void SendChatLine()
        {
            string msg = TextInput.Text.Trim();

            if (isLoggedin && msg.Length > 0)
            {
                var chatItem = new ChatItem {
                    Text = msg, UserName = String.Format("{0} {1}", userfirstname, userlastname), TimeStamp = DateTime.UtcNow
                };
                lastChatline = chatItem.Text;
                InsertChatItem(chatItem);
                TextInput.Text = "";
            }
        }
        private async void OnPushNotification(PushNotificationChannel sender, PushNotificationReceivedEventArgs e)
        {
            String notificationContent = String.Empty;

            e.Cancel = true;

            switch (e.NotificationType)
            {
                // Badges are not yet supported and will be added in a future version
                case PushNotificationType.Badge:
                    notificationContent = e.BadgeNotification.Content.GetXml();
                    break;

                // Tiles are not yet supported and will be added in a future version
                case PushNotificationType.Tile:
                    notificationContent = e.TileNotification.Content.GetXml();
                    break;

                // The current version of AzureChatr only works via toast notifications
                case PushNotificationType.Toast:
                    notificationContent = e.ToastNotification.Content.GetXml();
                    XmlDocument toastXml = e.ToastNotification.Content;

                    // Extract the relevant chat item data from the toast notification payload
                    XmlNodeList toastTextAttributes = toastXml.GetElementsByTagName("text");
                    string username = toastTextAttributes[0].InnerText;
                    string chatline = toastTextAttributes[1].InnerText;
                    string chatdatetime = toastTextAttributes[2].InnerText;

                    await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        var chatItem = new ChatItem { Text = chatline, UserName = username };
                        // Post the new chat item received in the chat window.
                        // IMPORTANT: If you updated the code above to post new chat lines from
                        //            the current user immediately in the chat window, you will
                        //            end up with duplicates here. You need to filter-out the
                        //            current user's chat entries to avoid these duplicates.
                        items.Add(chatItem);
                        ScrollDown();
                    });

                    // This is a quick and dirty way to make sure that we don't use speech synthesis
                    // to read the current user's chat lines out loud
                    if (chatline != lastChatline){
                        ReadText(username + " says: " + chatline);
                    }

                    break;

                // Raw notifications are not used in this version
                case PushNotificationType.Raw:
                    notificationContent = e.RawNotification.Content;
                    break;
            }
            //e.Cancel = true;
        }
 // Prepares the chat item to be sent to the cloud
 private void SendChatLine()
 {
     string msg = TextInput.Text.Trim();
     if (isLoggedin && msg.Length > 0)
     {
         var chatItem = new ChatItem { Text = msg, UserName = String.Format("{0} {1}", userfirstname, userlastname), TimeStamp = DateTime.UtcNow };
         lastChatline = chatItem.Text;
         InsertChatItem(chatItem);
         TextInput.Text = "";
     }
 }
        // Inserts a new chat item to the conversation by posting it in the Azure Mobile 
        // Services table, and posting it in the application's chat window
        private async void InsertChatItem(ChatItem chatItem)
        {
            // This code inserts a new ChatItem into the database. When the operation completes
            // and Mobile Services has assigned an Id, the item is added to the CollectionView
            await chatTable.InsertAsync(chatItem);

            // When the following line is commented, the new chat item from the current user is
            // NOT posted to the current chat window. It instead waits until the chat item is
            // received in a push notification and intercepted by the app, and then displayed.
            //items.Add(chatItem);
        }