public async Task <ObservableCollection <T> > RefreshAsync(bool syncItems = true)
        {
            Debug.WriteLine($"[AzureDataTable$RefreshAsync] Entry");
            try
            {
                if (syncItems && isSyncTable)
                {
                    Debug.WriteLine($"[AzureDataTable$RefreshAsync] Updating Offline Sync Cache");
                    await this.SyncOfflineCacheAsync();
                }
                Debug.WriteLine($"[AzureDataTable$RefreshAsync] Requesting Items");
                if (isSyncTable)
                {
                    List <T> items = await syncTable.OrderBy(item => item.UpdatedAt).ToListAsync();

                    dataView = new ObservableCollection <T>(items);
                }
                else
                {
                    List <T> items = await dataTable.OrderBy(item => item.UpdatedAt).ToListAsync();

                    dataView = new ObservableCollection <T>(items);
                }
                Debug.WriteLine($"[AzureDataTable$RefreshAsync] {dataView.Count} items available");
                return(dataView);
            }
            catch (MobileServiceInvalidOperationException exception)
            {
                throw new CloudTableOperationFailed(exception.Message, exception);
            }
        }
        public async Task AsyncFilterSelectOrdering_OrderByVersion_NotImpactedBySystemProperties()
        {
            // Set up the table.
            await EnsureEmptyTableAsync <RoundTripTableItemWithSystemPropertiesType>();

            IMobileServiceTable <RoundTripTableItemWithSystemPropertiesType> table = GetClient().GetTable <RoundTripTableItemWithSystemPropertiesType>();
            List <RoundTripTableItemWithSystemPropertiesType> items = new List <RoundTripTableItemWithSystemPropertiesType>();

            for (int id = 0; id < 5; id++)
            {
                RoundTripTableItemWithSystemPropertiesType item = new RoundTripTableItemWithSystemPropertiesType()
                {
                    Id = id.ToString(), Name = "a value"
                };
                await table.InsertAsync(item);

                Assert.NotNull(item.CreatedAt);
                Assert.NotNull(item.UpdatedAt);
                Assert.NotNull(item.Version);
                items.Add(item);
            }

            // Run test
            var results = await table.OrderBy(t => t.Version).ToListAsync(); // Fails here with .NET runtime. Why??

            RoundTripTableItemWithSystemPropertiesType[] orderItems = results.ToArray();
            for (int i = 0; i < orderItems.Length - 1; i++)
            {
                Assert.True(int.Parse(orderItems[i].Id) < int.Parse(orderItems[i + 1].Id));
            }

            // Cleanup
            items.ForEach(async t => await table.DeleteAsync(t));
        }
Example #3
0
        public async Task<List<Corso>> GetCorsi()
        {
            await Initialize();

            checkAuthentication();

            var corsi = await corsoTable.OrderBy(c => c.Insegnamento).ToEnumerableAsync();
            //return new ObservableCollection<TazzaDiCaffe>(coffes);
            return corsi.ToList();
        }
Example #4
0
        public async Task<List<User>> GetUsers()
        {
            await Initialize();

            checkAuthentication();

            var users = await userTable.OrderBy(c => c.Email).ToEnumerableAsync();
            //return new ObservableCollection<TazzaDiCaffe>(coffes);
            return users.ToList();
        }
        public async Task OrderingReadAsyncWithValidStringIdAgainstStringIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithStringId>();

            string[] testIdData = new string[] { "a", "b", "C", "_A", "_B", "_C", "1", "2", "3" };
            IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>();

            foreach (string testId in testIdData)
            {
                ToDoWithStringId item = new ToDoWithStringId()
                {
                    Id = testId, String = "Hey"
                };
                await table.InsertAsync(item);
            }

            IEnumerable <ToDoWithStringId> results = await table.OrderBy(p => p.Id).ToEnumerableAsync();

            ToDoWithStringId[] items = results.ToArray();

            Assert.AreEqual(9, items.Count());
            Assert.AreEqual("_A", items[0].Id);
            Assert.AreEqual("_B", items[1].Id);
            Assert.AreEqual("_C", items[2].Id);
            Assert.AreEqual("1", items[3].Id);
            Assert.AreEqual("2", items[4].Id);
            Assert.AreEqual("3", items[5].Id);
            Assert.AreEqual("a", items[6].Id);
            Assert.AreEqual("b", items[7].Id);
            Assert.AreEqual("C", items[8].Id);

            results = await table.OrderByDescending(p => p.Id).ToEnumerableAsync();

            items = results.ToArray();

            Assert.AreEqual(9, items.Count());
            Assert.AreEqual("_A", items[8].Id);
            Assert.AreEqual("_B", items[7].Id);
            Assert.AreEqual("_C", items[6].Id);
            Assert.AreEqual("1", items[5].Id);
            Assert.AreEqual("2", items[4].Id);
            Assert.AreEqual("3", items[3].Id);
            Assert.AreEqual("a", items[2].Id);
            Assert.AreEqual("b", items[1].Id);
            Assert.AreEqual("C", items[0].Id);

            foreach (string testId in testIdData)
            {
                ToDoWithStringId item = new ToDoWithStringId()
                {
                    Id = testId
                };
                await table.DeleteAsync(item);
            }
        }
Example #6
0
        public async Task<List<Preferiti>> GetAllPreferiti()
        {
            await Initialize();

            checkAuthentication();

            var preferiti = await preferitiTable.OrderBy(c => c.Id).ToEnumerableAsync();
            //return new ObservableCollection<TazzaDiCaffe>(coffes);
            var list = preferiti.ToList();
            return list;
        }
Example #7
0
 private async Task <List <Character> > ReadCharactersFromAzure()
 {
     try
     {
         var query = CharacterTable.OrderBy(x => x.Name);
         return(await query.ToListAsync());
     }
     catch (Exception ex)
     {
         return(default(List <Character>));
     }
 }
        public async Task OrderByAscDescAsyncGeneric()
        {
            TestHttpHandler hijack = new TestHttpHandler();

            hijack.SetResponseContent("[]");
            IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);

            IMobileServiceTable <StringType> table = service.GetTable <StringType>();
            List <StringType> people = await table.OrderBy(p => p.Id).ThenByDescending(p => p.String).ToListAsync();

            Assert.Contains(hijack.Request.RequestUri.ToString(), "StringType");
            Assert.Contains(hijack.Request.RequestUri.ToString(), "orderby=id,String desc");
        }
Example #9
0
 protected override async void OnAppearing()
 {
     if (_isDataLoaded)
     {
         // refresh ingredient collection
         try
         {
             ingredientsListView.ItemsSource = await _ingredientTable.OrderBy(x => x.Type).ToCollectionAsync();
         }
         catch (MobileServiceInvalidOperationException msioe)
         {
             Debug.WriteLine("Invalid sync operation: {0}", new[] { msioe.Message });
         }
     }
Example #10
0
        /// <summary>
        /// Get the list of characters
        /// </summary>
        /// <returns>ObservableCollection of Character objects</returns>
        public async Task <ObservableCollection <Character> > GetCharactersAsync()
        {
            try
            {
                var query      = CharacterTable.OrderBy(c => c.Name);
                var characters = await query.ToListAsync();

                return(new ObservableCollection <Character>(characters));
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Get the list of movies
        /// </summary>
        /// <returns>ObservableCollection of Character objects</returns>
        public async Task <ObservableCollection <Movie> > GetMoviesAsync()
        {
            try
            {
                var query  = MovieTable.OrderBy(c => c.Title);
                var movies = await query.ToListAsync();

                return(new ObservableCollection <Movie>(movies));
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #12
0
        private async Task RefreshTodoItems()
        {
            MobileServiceInvalidOperationException exception = null;

            try
            {
                items = await parameters.ToCollectionAsync();

                stats = await statistics.OrderBy <DateTime>(item => item.ValueDateTime).ToCollectionAsync();
            }
            catch (MobileServiceInvalidOperationException e)
            {
                exception = e;
            }
            catch (HttpRequestException e)
            {
                await new MessageDialog(String.Format("{0}\nService is not available", e.Message), "Error loading items").ShowAsync();
                return;
            }

            if (exception != null)
            {
                await new MessageDialog(exception.Message, "Error loading items").ShowAsync();
            }
            else
            {
                currentHouseEntity.HouseEntity.Temperature = items.FirstOrDefault(i => i.Name == "Temperature")?.Value;
                currentHouseEntity.HouseEntity.Humidity    = items.FirstOrDefault(i => i.Name == "Humidity")?.Value;
                currentHouseEntity.HouseEntity.FanMode     = items.FirstOrDefault(i => i.Name == "FanMode").Value;
                currentHouseEntity.HouseEntity.FanPower    = items.FirstOrDefault(i => i.Name == "FanPower").Value;
                currentHouseEntity.HouseEntity.Door        = items.FirstOrDefault(i => i.Name == "Door").Value;

                //List<StatisticsHTs> list = new List<StatisticsHTs>()
                //{
                //    new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,0,0), Humidity = 80, Temperature = 24},
                //    new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,2,0), Humidity = 82, Temperature = 24},
                //    new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,4,0), Humidity = 90, Temperature = 25},
                //    new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,6,0), Humidity = 99, Temperature = 25},
                //    new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,8,0), Humidity = 99, Temperature = 25},
                //    new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,10,0), Humidity = 91, Temperature = 26},
                //    new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,12,0), Humidity = 77, Temperature = 26},
                //    new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,14,0), Humidity = 64, Temperature = 24}
                //};
                currentHouseEntity.Statistics = stats.ToList();
            }
        }
        /*
         * /// <summary>
         * /// Get the list of characters from an embedded JSON file, including their child entities.
         * /// </summary>
         * /// <returns>Array of Character objects</returns>
         * private async Task<Character[]> ReadCharactersFromFile()
         * {
         *  var assembly = typeof(CharacterService).GetTypeInfo().Assembly;
         *  Stream stream = assembly.GetManifestResourceStream(Constants.CharactersFilename);
         *  string text;
         *
         *  using (var reader = new System.IO.StreamReader(stream))
         *  {
         *      text = await reader.ReadToEndAsync();
         *  }
         *
         *  var characters = JsonConvert.DeserializeObject<Character[]>(text);
         *  return characters;
         * }
         */

        public async Task <ObservableCollection <Character> > GetCharactersAsync()
        {
            //var characters = await ReadCharactersFromFile();
            //return new ObservableCollection<Character>(characters);
            try
            {
                CharacterTable = Client.GetTable <Character>();
                var query      = CharacterTable.OrderBy(c => c.Name);
                var characters = await query.ToListAsync();

                return(new ObservableCollection <Character>(characters));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public async Task OrderingReadAsyncWithStringIdAgainstIntegerIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithIntId>();

            IMobileServiceTable <ToDoWithIntId> table = GetClient().GetTable <ToDoWithIntId>();
            List <ToDoWithIntId> integerIdItems       = new List <ToDoWithIntId>();

            for (var i = 0; i < 10; i++)
            {
                ToDoWithIntId item = new ToDoWithIntId()
                {
                    String = i.ToString()
                };
                await table.InsertAsync(item);

                integerIdItems.Add(item);
            }

            IMobileServiceTable <ToDoWithStringIdAgainstIntIdTable> stringIdTable = GetClient().GetTable <ToDoWithStringIdAgainstIntIdTable>();

            IEnumerable <ToDoWithStringIdAgainstIntIdTable> results = await stringIdTable.OrderBy(p => p.Id).ToEnumerableAsync();

            ToDoWithStringIdAgainstIntIdTable[] items = results.ToArray();

            Assert.AreEqual(10, items.Count());
            for (var i = 0; i < 8; i++)
            {
                Assert.AreEqual((int.Parse(items[i].Id) + 1).ToString(), items[i + 1].Id);
            }

            results = await stringIdTable.OrderByDescending(p => p.Id).ToEnumerableAsync();

            items = results.ToArray();

            Assert.AreEqual(10, items.Count());
            for (var i = 8; i >= 0; i--)
            {
                Assert.AreEqual((int.Parse(items[i].Id) - 1).ToString(), items[i + 1].Id);
            }

            foreach (ToDoWithIntId integerIdItem in integerIdItems)
            {
                await table.DeleteAsync(integerIdItem);
            }
        }
Example #15
0
 /// <summary>
 /// Reads the xamagram items async.
 /// </summary>
 /// <returns>The xamagram items async.</returns>
 public async Task <IEnumerable <Anuncios> > GetAllItemsAsync()
 {
     return(await _itemTable.OrderBy(_itemTable => _itemTable.fecha).ToListAsync());
 }
        public async Task AsyncFilterSelectOrderingOperationsNotImpactedBySystemProperties()
        {
            await EnsureEmptyTableAsync <ToDoWithSystemPropertiesType>();

            IMobileServiceTable <ToDoWithSystemPropertiesType> table = GetClient().GetTable <ToDoWithSystemPropertiesType>();
            List <ToDoWithSystemPropertiesType> items = new List <ToDoWithSystemPropertiesType>();

            // Insert some items
            for (int id = 0; id < 5; id++)
            {
                ToDoWithSystemPropertiesType item = new ToDoWithSystemPropertiesType()
                {
                    Id = id.ToString(), String = "a value"
                };

                await table.InsertAsync(item);

                Assert.IsNotNull(item.CreatedAt);
                Assert.IsNotNull(item.UpdatedAt);
                Assert.IsNotNull(item.Version);
                items.Add(item);

                await Task.Delay(10); // to separate the items in time
            }

            // Ordering
            var results = await table.OrderBy(t => t.CreatedAt).ToEnumerableAsync();

            ToDoWithSystemPropertiesType[] orderItems = results.ToArray();

            for (int i = 0; i < orderItems.Length - 1; i++)
            {
                Assert.IsTrue(int.Parse(orderItems[i].Id) < int.Parse(orderItems[i + 1].Id));
            }

            results = await table.OrderBy(t => t.UpdatedAt).ToEnumerableAsync();

            orderItems = results.ToArray();

            for (int i = 0; i < orderItems.Length - 1; i++)
            {
                Assert.IsTrue(int.Parse(orderItems[i].Id) < int.Parse(orderItems[i + 1].Id));
            }

            results = await table.OrderBy(t => t.Version).ToEnumerableAsync();

            orderItems = results.ToArray();

            for (int i = 0; i < orderItems.Length - 1; i++)
            {
                Assert.IsTrue(int.Parse(orderItems[i].Id) < int.Parse(orderItems[i + 1].Id));
            }

            // Filtering
            results = await table.Where(t => t.CreatedAt >= items[4].CreatedAt).ToEnumerableAsync();

            ToDoWithSystemPropertiesType[] filteredItems = results.ToArray();

            for (int i = 0; i < filteredItems.Length - 1; i++)
            {
                Assert.IsTrue(filteredItems[i].CreatedAt >= items[4].CreatedAt);
            }

            results = await table.Where(t => t.UpdatedAt >= items[4].UpdatedAt).ToEnumerableAsync();

            filteredItems = results.ToArray();

            for (int i = 0; i < filteredItems.Length - 1; i++)
            {
                Assert.IsTrue(filteredItems[i].UpdatedAt >= items[4].UpdatedAt);
            }

            results = await table.Where(t => t.Version == items[4].Version).ToEnumerableAsync();

            filteredItems = results.ToArray();

            for (int i = 0; i < filteredItems.Length - 1; i++)
            {
                Assert.IsTrue(filteredItems[i].Version == items[4].Version);
            }

            // Selection
            var selectionResults = await table.Select(t => new { Id = t.Id, CreatedAt = t.CreatedAt }).ToEnumerableAsync();

            var selectedItems = selectionResults.ToArray();

            for (int i = 0; i < selectedItems.Length; i++)
            {
                var item = items.Where(t => t.Id == selectedItems[i].Id).FirstOrDefault();
                Assert.IsTrue(item.CreatedAt == selectedItems[i].CreatedAt);
            }

            var selectionResults2 = await table.Select(t => new { Id = t.Id, UpdatedAt = t.UpdatedAt }).ToEnumerableAsync();

            var selectedItems2 = selectionResults2.ToArray();

            for (int i = 0; i < selectedItems2.Length; i++)
            {
                var item = items.Where(t => t.Id == selectedItems2[i].Id).FirstOrDefault();
                Assert.IsTrue(item.UpdatedAt == selectedItems2[i].UpdatedAt);
            }

            var selectionResults3 = await table.Select(t => new { Id = t.Id, Version = t.Version }).ToEnumerableAsync();

            var selectedItems3 = selectionResults3.ToArray();

            for (int i = 0; i < selectedItems3.Length; i++)
            {
                var item = items.Where(t => t.Id == selectedItems3[i].Id).FirstOrDefault();
                Assert.IsTrue(item.Version == selectedItems3[i].Version);
            }

            // Delete
            foreach (var item in items)
            {
                await table.DeleteAsync(item);
            }
        }
 public IMobileServiceTableQuery <T> OrderBy <TKey>(Expression <Func <T, TKey> > keySelector)
 {
     return(_table.OrderBy(keySelector));
 }
Example #18
0
        public async Task AsyncFilterSelectOrderingOperationsNotImpactedBySystemProperties()
        {
            await EnsureEmptyTableAsync <RoundTripTableItemWithSystemPropertiesType>();

            IMobileServiceTable <RoundTripTableItemWithSystemPropertiesType> table = GetClient().GetTable <RoundTripTableItemWithSystemPropertiesType>();
            List <RoundTripTableItemWithSystemPropertiesType> items = new List <RoundTripTableItemWithSystemPropertiesType>();

            // Insert some items
            for (int id = 0; id < 5; id++)
            {
                RoundTripTableItemWithSystemPropertiesType item = new RoundTripTableItemWithSystemPropertiesType()
                {
                    Id = id.ToString(), Name = "a value"
                };

                await table.InsertAsync(item);

                Assert.IsNotNull(item.CreatedAt);
                Assert.IsNotNull(item.UpdatedAt);
                Assert.IsNotNull(item.Version);
                items.Add(item);
            }

            // Ordering
            var results = await table.OrderBy(t => t.CreatedAt).ToEnumerableAsync(); // Fails here with .NET runtime. Why??

            RoundTripTableItemWithSystemPropertiesType[] orderItems = results.ToArray();

            for (int i = 0; i < orderItems.Length - 1; i++)
            {
                Assert.IsTrue(int.Parse(orderItems[i].Id) < int.Parse(orderItems[i + 1].Id));
            }

            results = await table.OrderBy(t => t.UpdatedAt).ToEnumerableAsync();

            orderItems = results.ToArray();

            for (int i = 0; i < orderItems.Length - 1; i++)
            {
                Assert.IsTrue(int.Parse(orderItems[i].Id) < int.Parse(orderItems[i + 1].Id));
            }

            results = await table.OrderBy(t => t.Version).ToEnumerableAsync();

            orderItems = results.ToArray();

            for (int i = 0; i < orderItems.Length - 1; i++)
            {
                Assert.IsTrue(int.Parse(orderItems[i].Id) < int.Parse(orderItems[i + 1].Id));
            }

            // Filtering
            results = await table.Where(t => t.CreatedAt >= items[4].CreatedAt).ToEnumerableAsync();

            RoundTripTableItemWithSystemPropertiesType[] filteredItems = results.ToArray();

            for (int i = 0; i < filteredItems.Length - 1; i++)
            {
                Assert.IsTrue(filteredItems[i].CreatedAt >= items[4].CreatedAt);
            }

            results = await table.Where(t => t.UpdatedAt >= items[4].UpdatedAt).ToEnumerableAsync();

            filteredItems = results.ToArray();

            for (int i = 0; i < filteredItems.Length - 1; i++)
            {
                Assert.IsTrue(filteredItems[i].UpdatedAt >= items[4].UpdatedAt);
            }

            // TODO: Seperate to own test, to not run for .NET / Fix.Net

            /*
             * results = await table.Where(t => t.Version == items[4].Version).ToEnumerableAsync();
             * filteredItems = results.ToArray();
             *
             * for (int i = 0; i < filteredItems.Length - 1; i++)
             * {
             *  Assert.IsTrue(filteredItems[i].Version == items[4].Version);
             * }
             */

            // Selection
            var selectionResults = await table.Select(t => new { Id = t.Id, CreatedAt = t.CreatedAt }).ToEnumerableAsync();

            var selectedItems = selectionResults.ToArray();

            for (int i = 0; i < selectedItems.Length; i++)
            {
                var item = items.Where(t => t.Id == selectedItems[i].Id).FirstOrDefault();
                Assert.IsTrue(item.CreatedAt == selectedItems[i].CreatedAt);
            }

            var selectionResults2 = await table.Select(t => new { Id = t.Id, UpdatedAt = t.UpdatedAt }).ToEnumerableAsync();

            var selectedItems2 = selectionResults2.ToArray();

            for (int i = 0; i < selectedItems2.Length; i++)
            {
                var item = items.Where(t => t.Id == selectedItems2[i].Id).FirstOrDefault();
                Assert.IsTrue(item.UpdatedAt == selectedItems2[i].UpdatedAt);
            }

            var selectionResults3 = await table.Select(t => new { Id = t.Id, Version = t.Version }).ToEnumerableAsync();

            var selectedItems3 = selectionResults3.ToArray();

            for (int i = 0; i < selectedItems3.Length; i++)
            {
                var item = items.Where(t => t.Id == selectedItems3[i].Id).FirstOrDefault();
                Assert.IsTrue(item.Version == selectedItems3[i].Version);
            }

            // Delete
            foreach (var item in items)
            {
                await table.DeleteAsync(item);
            }
        }
Example #19
0
 /// <summary>
 /// Reads the xamagram items async.
 /// </summary>
 /// <returns>The xamagram items async.</returns>
 public async Task <IEnumerable <Categorias> > GetAllCategoriesAsync()
 {
     return(await _categoryTable.OrderBy(_categoryTable => _categoryTable.nombre).ToListAsync());
 }
Example #20
0
 public async Task <List <Equipo> > ObtenerEquipos()
 {
     return(await TablaEquipo.OrderBy(x => x.Nombre).ToListAsync());
 }
 public async Task <List <Tarefa> > ListarAsync()
 {
     return(await _tarefaTable.OrderBy(c => c.Descricao).ToListAsync());
 }
Example #22
0
 //Filter Ascending Method
 public async void FilterByAscendingOrder(TodoItem todo)
 {
     //IMobileServiceTableQuery<TodoItem> query = todoTable.OrderBy(todoItem => todoItem.Text).Skip().Take(10);
     IMobileServiceTableQuery <TodoItem> query = todoTable.OrderBy(todoItem => todoItem.Text);
     List <TodoItem> items = await query.ToListAsync();
 }