コード例 #1
0
        // Fetches the last chat conversation items from the cloud to be displayed on screen
        private async void RefreshChatItems()
        {
            prgBusy.IsActive = true;

            if (isLoggedin)
            {
                MobileServiceInvalidOperationException exception = null;
                try
                {
                    // The max number of items to retrieve from Azure Mobile Services
                    // Note that N CANNOT be greater than 50, we'd have to use paging for more
                    int n = 20;

                    // This code refreshes the entries in the list view by querying the ChatItems table.
                    // We only want the last N members, so we have to sort by descending order and request the first N
                    items = await chatTable.OrderByDescending(chatitem => chatitem.TimeStamp).Take(n).ToCollectionAsync();

                    // But now we need to reverse the order again so the last item is always at the bottom of the list, not the top
                    // Unfortunately, both of these methods are unsupported on a Mobile Service Collection
                    // items.Reverse<ChatItem>();
                    // items.OrderBy(chatitem => chatitem.TimeStamp);

                    // Let's get creative and manually invert the order of the items by moving them one by one
                    // Since there cannot be more than 50 items, this is not an unreasonable technique to use
                    if (items.Count > 0)
                    {
                        if (items.Count < n)
                        {
                            n = items.Count;
                        }

                        for (int i = 0; i < (n - 1); i++)
                        {
                            items.Move(0, n - i - 1);
                        }
                    }

                    items.CollectionChanged += (s, args) => ScrollDown();

                    ScrollDown();
                }
                catch (MobileServiceInvalidOperationException e)
                {
                    exception = e;
                }

                if (exception != null)
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        new MessageDialog(exception.Message, "Error loading items").ShowAsync();
                    });
                }
                else
                {
                    ListItems.ItemsSource = items;
                }
            }
            prgBusy.IsActive = false;
        }
コード例 #2
0
        // Fetches the last chat conversation items from the cloud to be displayed on screen
        private async void RefreshChatItems()
        {
            prgBusy.IsActive = true;

            if (isLoggedin)
            {
                MobileServiceInvalidOperationException exception = null;
                try
                {
                    // The max number of items to retrieve from Azure Mobile Services
                    int n = 30;
                    // refreshes the entries in the list view by querying the ChatItems table.
                    items = await chatTable.OrderByDescending(chatitem => chatitem.TimeStamp).Take(n).ToCollectionAsync();

                    // reverse the order again so the last item is always at the bottom of the list, not the top
                    if (items.Count > 0)
                    {
                        if (items.Count < n)
                        {
                            n = items.Count;
                        }

                        for (int i = 0; i < (n - 1); i++)
                        {
                            items.Move(0, n - i - 1);
                        }
                    }

                    ScrollDown();
                }
                catch (MobileServiceInvalidOperationException e)
                {
                    exception = e;
                }

                if (exception != null)
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        new MessageDialog(exception.Message, "Error loading items").ShowAsync();
                    });
                }
                else
                {
                    ListItems.ItemsSource = items;
                    //lastCount = items.Count;
                    ScrollDown();
                }
            }
            prgBusy.IsActive = false;
        }
コード例 #3
0
        // Obtiene los últimos mensajes de la conversación desde la nube para mostrarlos en la pantalla
        private async void RefreshChatItems()
        {
            prgBusy.IsActive = true;

            if (isLoggedin)
            {
                MobileServiceInvalidOperationException exception = null;
                try
                {
                    int n = 20;
                    items = await chatTable.OrderByDescending(chatitem => chatitem.TimeStamp).Take(n).ToCollectionAsync();

                    if (items.Count > 0)
                    {
                        if (items.Count < n)
                        {
                            n = items.Count;
                        }

                        for (int i = 0; i < (n - 1); i++)
                        {
                            items.Move(0, n - i - 1);
                        }
                    }
                }
                catch (MobileServiceInvalidOperationException e)
                {
                    exception = e;
                }

                if (exception != null)
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        new MessageDialog(exception.Message, "Error cargando los mensajes").ShowAsync();
                    });
                }
                else
                {
                    ListItems.ItemsSource = items;
                }
            }
            prgBusy.IsActive = false;
        }
コード例 #4
0
        // Fetches the last chat conversation items from the cloud to be displayed on screen
        private async void RefreshChatItems()
        {
            prgBusy.IsActive = true;

            if (isLoggedin)
            {
                MobileServiceInvalidOperationException exception = null;
                try
                {
                    // The max number of items to retrieve from Azure Mobile Services
                    // Note that N CANNOT be greater than 50, we'd have to use paging for more
                    int n = 20;

                    // This code refreshes the entries in the list view by querying the ChatItems table.
                    // We only want the last N members, so we have to sort by descending order and request the first N
                    items = await chatTable.OrderByDescending(chatitem => chatitem.TimeStamp).Take(n).ToCollectionAsync();
                    // But now we need to reverse the order again so the last item is always at the bottom of the list, not the top
                    // Unfortunately, both of these methods are unsupported on a Mobile Service Collection
                    // items.Reverse<ChatItem>();
                    // items.OrderBy(chatitem => chatitem.TimeStamp);

                    // Let's get creative and manually invert the order of the items by moving them one by one
                    // Since there cannot be more than 50 items, this is not an unreasonable technique to use
                    if (items.Count > 0)
                    {
                        if (items.Count < n) { n = items.Count; }

                        for (int i = 0; i < (n - 1); i++)
                        {
                            items.Move(0, n - i - 1);
                        }
                    }

                    items.CollectionChanged += (s, args) => ScrollDown();

                    ScrollDown();
                }
                catch (MobileServiceInvalidOperationException e)
                {
                    exception = e;
                }

                if (exception != null)
                {
                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        new MessageDialog(exception.Message, "Error loading items").ShowAsync();
                    });
                }
                else
                {
                    ListItems.ItemsSource = items;
                } 
            }
            prgBusy.IsActive = false;
        }