示例#1
0
        public void MobileServiceCollectionCanCopyToAndNotNotifies()
        {
            // Get the Books table
            MobileServiceTableQueryMock <Book> query = new MobileServiceTableQueryMock <Book>();

            query.EnumerableAsyncThrowsException = true;

            MobileServiceCollection <Book> collection = new MobileServiceCollection <Book>(query);

            List <string> properties         = new List <string>();
            List <string> expectedProperties = new List <string>()
            {
            };
            List <NotifyCollectionChangedAction> actions         = new List <NotifyCollectionChangedAction>();
            List <NotifyCollectionChangedAction> expectedActions = new List <NotifyCollectionChangedAction>()
            {
            };

            Book book = new Book();

            collection.Add(book);
            Book[] books = new Book[1];

            ((INotifyPropertyChanged)collection).PropertyChanged += (s, e) => properties.Add(e.PropertyName);
            collection.CollectionChanged += (s, e) => actions.Add(e.Action);
            collection.CopyTo(books, 0);

            Assert.AreEqual(1, collection.Count);
            Assert.AreEqual(1, books.Count());
            Assert.AreEqual(collection[0], books[0]);
            Assert.IsTrue(properties.SequenceEqual(expectedProperties));
            Assert.IsTrue(actions.SequenceEqual(expectedActions));
        }
示例#2
0
        public async Task AddVehicleAsync(Vehicle vehicle)
        {
            try
            {
                Debug.WriteLine("Inserting vehicle...");
                await vehicles.InsertAsync(vehicle);

                Debug.WriteLine("Adding vehicle to offline database...");
                Items.Add(vehicle);
                Debug.WriteLine("Syncing offline database...");
                await SyncAsync();
            }
            catch
            {
            }
        }
        public void MobileServiceCollectionCanContainsAndNotNotifies()
        {
            // Get the Books table
            MobileServiceTableQueryMock <Book> query = new MobileServiceTableQueryMock <Book>();

            query.EnumerableAsyncThrowsException = true;

            MobileServiceCollection <Book, Book> collection = new MobileServiceCollection <Book, Book>(query);

            List <string> properties         = new List <string>();
            List <string> expectedProperties = new List <string>()
            {
            };
            List <NotifyCollectionChangedAction> actions         = new List <NotifyCollectionChangedAction>();
            List <NotifyCollectionChangedAction> expectedActions = new List <NotifyCollectionChangedAction>()
            {
            };

            Book book = new Book();

            collection.Add(book);

            ((INotifyPropertyChanged)collection).PropertyChanged += (s, e) => properties.Add(e.PropertyName);
            collection.CollectionChanged += (s, e) => actions.Add(e.Action);

            Assert.Contains(book, collection);
            Assert.Equal(expectedProperties, properties);
            Assert.Equal(expectedActions, actions);
        }
        private async Task InsertTodoItem(TodoItem todoItem)
        {
            // This code inserts a new TodoItem into the database. After the operation completes
            // and the mobile app backend has assigned an id, the item is added to the CollectionView.
            try
            {
                await todoTable.InsertAsync(todoItem);

                items.Add(todoItem);
            }
            catch (System.Net.Http.HttpRequestException ex)
            {
                ContentDialog deleteFileDialog = new ContentDialog
                {
                    FontSize          = 10,
                    Title             = "Network Error",
                    PrimaryButtonText = "Home"
                };

                ContentDialogResult result = await deleteFileDialog.ShowAsync();

                this.Frame.Navigate(typeof(ServerMenuPage));
            }


#if OFFLINE_SYNC_ENABLED
            await App.MobileService.SyncContext.PushAsync(); // offline sync
#endif
        }
示例#5
0
        public void MobileServiceCollectionCanClearAndNotifies()
        {
            // Get the Books table
            MobileServiceTableQueryMock <Book> query = new MobileServiceTableQueryMock <Book>();

            query.EnumerableAsyncThrowsException = true;

            MobileServiceCollection <Book> collection = new MobileServiceCollection <Book>(query);

            List <string> properties         = new List <string>();
            List <string> expectedProperties = new List <string>()
            {
                "Count", "Item[]"
            };
            List <NotifyCollectionChangedAction> actions         = new List <NotifyCollectionChangedAction>();
            List <NotifyCollectionChangedAction> expectedActions = new List <NotifyCollectionChangedAction>()
            {
                NotifyCollectionChangedAction.Reset
            };

            Book book = new Book();

            collection.Add(book);

            ((INotifyPropertyChanged)collection).PropertyChanged += (s, e) => properties.Add(e.PropertyName);
            collection.CollectionChanged += (s, e) => actions.Add(e.Action);
            collection.Clear();

            Assert.AreEqual(0, collection.Count);
            Assert.IsTrue(properties.SequenceEqual(expectedProperties));
            Assert.IsTrue(actions.SequenceEqual(expectedActions));
        }
示例#6
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;
        }
示例#7
0
        private async void InsertTodoItem(TodoItem todoItem)
        {
            // This code inserts a new TodoItem into the database. When the operation completes
            // and Mobile Services has assigned an Id, the item is added to the CollectionView
            await todoTable.InsertAsync(todoItem);

            items.Add(todoItem);
        }
示例#8
0
        private async Task InsertTodoItem(Message todoItem)
        {
            // This code inserts a new TodoItem into the database. When the operation completes
            // and Mobile Services has assigned an Id, the item is added to the CollectionView
            await messageTable.InsertAsync(todoItem);

            messages.Add(todoItem);

            //await SyncAsync(); // offline sync
        }
示例#9
0
        private async Task InsertTodoItem(TodoItem todoItem)
        {
            // This code inserts a new TodoItem into the database. When the operation completes
            // and Mobile Apps has assigned an Id, the item is added to the CollectionView
            await todoTable.InsertAsync(todoItem);

            items.Add(todoItem);

            //await App.MobileService.SyncContext.PushAsync(); // offline sync
        }
示例#10
0
        private async Task InsertTodoItem(TodoItem todoItem)
        {
            // This code inserts a new TodoItem into the database. When the operation completes
            // and Mobile App backend has assigned an Id, the item is added to the CollectionView.
            await todoTable.InsertAsync(todoItem);

            items.Add(todoItem);

            await SyncAsync(); // offline sync
        }
示例#11
0
        private async Task InsertWeatherDataItem(WeatherDataItem weatherDataItem)
        {
            // This code inserts a new WeatherDataItem into the database. When the operation completes
            // and Mobile App backend has assigned an Id, the item is added to the CollectionView.
            await weatherTable.InsertAsync(weatherDataItem);

            data.Add(weatherDataItem);

            await SyncAsync(); // offline sync
        }
示例#12
0
        private async Task InsertUser(User user)
        {
            // This code inserts a new User into the database. When the operation completes
            // and Mobile Services has assigned an Id, the item is added to the CollectionView
            await usersTable.InsertAsync(user);

            users.Add(user);

            //await SyncAsync(); // offline sync
        }
示例#13
0
        private async Task InsertTodoItem(TodoItem todoItem)
        {
            await todoTable.InsertAsync(todoItem);

            items.Add(todoItem);

#if OFFLINE_SYNC_ENABLED
            await App.MobileService.SyncContext.PushAsync(); // offline sync
#endif
        }
示例#14
0
文件: MainPage.cs 项目: jackhwl/azure
        private async Task InsertDemoColor(DemoColor demoColor)
        {
            if (!string.IsNullOrWhiteSpace(demoColor.Name))
            {
                // This code inserts a new DemoColor into the database. When the operation completes
                // and Mobile App backend has assigned an Id, the item is added to the CollectionView.
                await demoTable.InsertAsync(demoColor);

                items.Add(demoColor);
            }
        }
示例#15
0
        // Add drill to database
        public async Task AddDrill(DrillItem drillItem, String n, int s, int t, string sty, string use)
        {
            drillItem.Name    = n;
            drillItem.Sets    = s;
            drillItem.SetTime = t;
            drillItem.Style   = sty;
            drillItem.Use     = use;
            await App.MobileService.GetTable <DrillItem>().InsertAsync(drillItem);

            drills.Add(drillItem);
        }
        private async Task InsertTodoItem(TodoItem todoItem)
        {
            // This code inserts a new TodoItem into the database. After the operation completes
            // and the mobile app backend has assigned an id, the item is added to the CollectionView.
            await todoTable.InsertAsync(todoItem);
            items.Add(todoItem);

#if OFFLINE_SYNC_ENABLED
            await App.MobileService.SyncContext.PushAsync(); // offline sync
#endif
        }
示例#17
0
        public Content AddContent()
        {
            Content instance = new Content
            {
                Id = Guid.NewGuid().ToString()
            };

            _contentTable.InsertAsync(instance);
            _items.Add(instance);
            return(instance);
        }
示例#18
0
        private async void SendInfo(problem prob)
        {
            try
            {
                await prob_tb.InsertAsync(prob);

                probl.Add(prob);
            }
            catch (Exception ex)
            {
            }
        }
示例#19
0
        private async void SendInfo(newQ que)
        {
            try
            {
                await quest_tb.InsertAsync(que);

                quest.Add(que);
            }
            catch (Exception ex)
            {
            }
        }
        private async Task InsertTournamentTeam(string teamId)
        {
            string         tournamentId   = TournamentIdTextBlock.Text;
            TournamentTeam tournamentTeam = new TournamentTeam {
                TournamentId = tournamentId, TeamId = teamId, TeamWins = 0
            };
            await tournamentTeamsTable.InsertAsync(tournamentTeam);

            tournamentTeams.Add(tournamentTeam);

            //await App.MobileService.SyncContext.PushAsync(); // offline sync
        }
示例#21
0
        private async void InsertTodoItem(StudentTable todoItem)
        {
            await todoTable.InsertAsync(todoItem);

            items.Add(todoItem);

            // TODO: Delete or comment the following statement; Mobile Services auto-generates the ID.
            // todoItem.Id = Guid.NewGuid().ToString();

            //// This code inserts a new TodoItem into the database. When the operation completes
            //// and Mobile Services has assigned an Id, the item is added to the CollectionView
            //// TODO: Mark this method as "async" and uncomment the following statement.
        }
示例#22
0
        public async Task InsertSessionItem(session sessionItem)
        {
            try
            {
                await sessionTable.InsertAsync(sessionItem);

                items.Add(sessionItem);

                //await SyncAsync(); // offline sync
            }
            catch
            {
            }
        }
        public async Task <bool> InsertProduct(Product newProduct)
        {
            try
            {
                await productTable.InsertAsync(newProduct);

                _products.Add(newProduct);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#24
0
        public async Task InsertEventItem(dxevent eventItem)
        {
            try
            {
                await eventTable.InsertAsync(eventItem);

                items.Add(eventItem);

                //await SyncAsync(); // offline sync
            }
            catch
            {
            }
        }
        private async Task InsertTodoItem(ToDoItemDocDb todoItem)
        {
            // This code inserts a new TodoItem into the database. After the operation completes
            // and the mobile app backend has assigned an id, the item is added to the CollectionView.
            await todoTable.InsertAsync(todoItem);

            todoItems.Add(todoItem);

            try
            {
                await App.MobileService.SyncContext.PushAsync();
            }
            catch { }
        }
        private async void InsertTodoItem(TodoItem todoItem)
        {
            // This code inserts a new TodoItem into the database. When the operation completes
            // and Mobile Services has assigned an Id, the item is added to the CollectionView
            try
            {
                await todoTable.InsertAsync(todoItem);

                items.Add(todoItem);
            }
            catch (HttpRequestException)
            {
                ShowError();
            }
        }
示例#27
0
        private async Task InsertIntentItem(IntentItem IntentItem)
        {
            try
            {
                // This code inserts a new IntentItem into the database. After the operation completes
                // and the mobile app backend has assigned an id, the item is added to the CollectionView.
                await intentTable.InsertAsync(IntentItem);

                items.Add(IntentItem);

                await MobileService.SyncContext.PushAsync(); // offline sync
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
示例#28
0
        private async void OnPushNotification(PushNotificationChannel sender, PushNotificationReceivedEventArgs e)
        {
            String notificationContent = String.Empty;

            e.Cancel = true;

            switch (e.NotificationType)
            {
            // Los Badges aún no funcionan, pueden hacer eso en proximas versiones
            case PushNotificationType.Badge:
                notificationContent = e.BadgeNotification.Content.GetXml();
                break;

            // Los Tiles aún no funcionan, pueden hacer eso en proximas versiones
            case PushNotificationType.Tile:
                notificationContent = e.TileNotification.Content.GetXml();
                break;

            // La versión actual de esta aplicación sólo soporta notificaciones Toast
            case PushNotificationType.Toast:
                notificationContent = e.ToastNotification.Content.GetXml();
                XmlDocument toastXml = e.ToastNotification.Content;

                //Extrae los datos relevantes del chat para la carga de la notificación Toast
                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 Chat {
                        Mensaje = chatline, NombreUsuario = username
                    };
                    items.Add(chatItem);
                });

                break;

            // Las notificaciones Raw tampoco se utilizan en esta versión
            case PushNotificationType.Raw:
                notificationContent = e.RawNotification.Content;
                break;
            }
        }
        private async void InsertTodoItem(TodoItem todoItem)
        {
            string errorString = string.Empty;

            if (imageStream != null)
            {
                // Set blob properties of TodoItem.
                todoItem.ContainerName = "todoitemimages";
                todoItem.ResourceName  = Guid.NewGuid().ToString() + ".jpg";
            }

            // Send the item to be inserted. When blob properties are set this
            // generates an SAS in the response.
            await todoTable.InsertAsync(todoItem);

            // If we have a returned SAS, then upload the blob.
            if (!string.IsNullOrEmpty(todoItem.SasQueryString))
            {
                // Get the URI generated that contains the SAS
                // and extract the storage credentials.
                StorageCredentials cred = new StorageCredentials(todoItem.SasQueryString);
                var imageUri            = new Uri(todoItem.ImageUri);

                // Instantiate a Blob store container based on the info in the returned item.
                CloudBlobContainer container = new CloudBlobContainer(
                    new Uri(string.Format("https://{0}/{1}",
                                          imageUri.Host, todoItem.ContainerName)), cred);

                // Upload the new image as a BLOB from the stream.
                CloudBlockBlob blobFromSASCredential =
                    container.GetBlockBlobReference(todoItem.ResourceName);
                await blobFromSASCredential.UploadFromStreamAsync(imageStream);

                // When you request an SAS at the container-level instead of the blob-level,
                // you are able to upload multiple streams using the same container credentials.

                imageStream = null;
            }

            // Add the new item to the collection.
            items.Add(todoItem);
            TodoInput.Text = "";
        }
        private async Task InsertTodoItem(TodoItem todoItem)
        {
            // This code inserts a new TodoItem into the database. After the operation completes
            // and the mobile app backend has assigned an id, the item is added to the CollectionView.
            try
            {
                await todoTable.InsertAsync(todoItem);

                items.Add(todoItem);

#if OFFLINE_SYNC_ENABLED
                await App.MobileService.SyncContext.PushAsync(); // offline sync
#endif
            }
            catch (Exception e)
            {
                await new MessageDialog(e.Message, "Error syncing items").ShowAsync();
            }
        }
        public void MobileServiceCollectionCanClearAndNotifies()
        {
            // Get the Books table
            MobileServiceTableQueryMock<Book> query = new MobileServiceTableQueryMock<Book>();
            query.EnumerableAsyncThrowsException = true;

            MobileServiceCollection<Book, Book> collection = new MobileServiceCollection<Book, Book>(query);

            List<string> properties = new List<string>();
            List<string> expectedProperties = new List<string>() { "Count", "Item[]" };
            List<NotifyCollectionChangedAction> actions = new List<NotifyCollectionChangedAction>();
            List<NotifyCollectionChangedAction> expectedActions = new List<NotifyCollectionChangedAction>() { NotifyCollectionChangedAction.Reset };

            Book book = new Book();
            collection.Add(book);

            ((INotifyPropertyChanged)collection).PropertyChanged += (s, e) => properties.Add(e.PropertyName);
            collection.CollectionChanged += (s, e) => actions.Add(e.Action);
            collection.Clear();

            Assert.AreEqual(0, collection.Count);
            Assert.IsTrue(properties.SequenceEqual(expectedProperties));
            Assert.IsTrue(actions.SequenceEqual(expectedActions));
        }
        public void MobileServiceCollectionCanCopyToAndNotNotifies()
        {
            // Get the Books table
            MobileServiceTableQueryMock<Book> query = new MobileServiceTableQueryMock<Book>();
            query.EnumerableAsyncThrowsException = true;

            MobileServiceCollection<Book, Book> collection = new MobileServiceCollection<Book, Book>(query);

            List<string> properties = new List<string>();
            List<string> expectedProperties = new List<string>() {  };
            List<NotifyCollectionChangedAction> actions = new List<NotifyCollectionChangedAction>();
            List<NotifyCollectionChangedAction> expectedActions = new List<NotifyCollectionChangedAction>() {  };

            Book book = new Book();
            collection.Add(book);
            Book[] books = new Book[1];

            ((INotifyPropertyChanged)collection).PropertyChanged += (s, e) => properties.Add(e.PropertyName);
            collection.CollectionChanged += (s, e) => actions.Add(e.Action);
            collection.CopyTo(books, 0);

            Assert.AreEqual(1, collection.Count);
            Assert.AreEqual(1, books.Count());
            Assert.AreEqual(collection[0], books[0]);
            Assert.IsTrue(properties.SequenceEqual(expectedProperties));
            Assert.IsTrue(actions.SequenceEqual(expectedActions));
        }