Пример #1
0
        public async Task <bool> DeleteDataFromDatabase()
        {
            var success = true;

            try
            {
                await _recipiesTable.PurgeAsync(true);

                await _categoriesTable.PurgeAsync(true);

                await _favoritesTable.PurgeAsync(true);

                await _ingredientsTable.PurgeAsync(true);

                await _quantityTypeTable.PurgeAsync(true);

                await _categoriesTable.PurgeAsync(true);
            }
            catch (Exception e)
            {
                success = false;
            }

            return(success);
        }
Пример #2
0
        public async Task PurgeAsync <U>(string queryId, IMobileServiceTableQuery <U> query, CancellationToken cancellationToken)
        {
            if (!await InitializeAsync())
            {
                throw new MobileServiceInvalidOperationException("Unable to purge data. Initialization failed.", null, null);
            }

            await _syncTable.PurgeAsync(queryId, query, cancellationToken);
        }
Пример #3
0
        public async Task PurgeAsync(Expression <Func <TEntity, bool> > Filter)
        {
            try
            {
                var tableQuery = tEntity.CreateQuery().Where(Filter);

                await tEntity.PurgeAsync($"purge_{tEntity.TableName}", tableQuery, true, CancellationToken.None);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Пример #4
0
        public async Task LogOffAsync()
        {
            // Delete the local cache
            CrossSecureStorage.Current.DeleteKey(App.UserIdKey);
            CrossSecureStorage.Current.DeleteKey(App.TokenKey);

            if (azureClient.CurrentUser == null)
            {
                return;
            }

            // Throw away token cache on server
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("X-ZUMO-AUTH", azureClient.CurrentUser.MobileServiceAuthenticationToken);
                await client.GetAsync(azureClient.MobileAppUri + "/.auth/logout");
            }

            // Throw away token in client library

            await azureClient.LogoutAsync();

            Debug.Assert(azureClient.CurrentUser == null);

            // Finally, purge the local data.
            await entriesTable.PurgeAsync(true);

            if (azureClient.CurrentUser != null)
            {
                azureClient.CurrentUser = null;
            }
        }
Пример #5
0
        public async Task SyncAsync()
        {
            ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null;

            try
            {
                await client.SyncContext.PushAsync();

                await vehicleTable.PullAsync("allVehicleRecords", vehicleTable.CreateQuery().Where(v => v.ParkingLotId == Settings.ParkingLotId));

                // the parkingLotId comparison is in case the user change it in Settings.
                await vehicleTable.PurgeAsync(vehicleTable.CreateQuery().Where(v => v.Done || v.ParkingLotId != Settings.ParkingLotId));
            }
            catch (MobileServicePushFailedException exc)
            {
                syncErrors = exc.PushResult?.Errors;
            }

            if (syncErrors != null)
            {
                foreach (var error in syncErrors)
                {
                    if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null)
                    {
                        await error.CancelAndUpdateItemAsync(error.Result);
                    }
                    else
                    {
                        await error.CancelAndDiscardItemAsync();
                    }

                    Console.WriteLine(@"Error executing sync operation. Item: {0} ({1}). Operation discarded.", error.TableName, error.Item["id"]);
                }
            }
        }
Пример #6
0
        public async Task <List <User> > GetUser()
        {
            await UserTable.PurgeAsync();

            await SyncUserAsync();

            return(await UserTable.ToListAsync());
        }
Пример #7
0
        public async Task PurgeAll()
        {
            await this.Initializer();

            var query = table.CreateQuery();

            await table.PurgeAsync("todo-incremental", query, new System.Threading.CancellationToken());
        }
Пример #8
0
        public async Task PurgeData()
        {
            if (_client.SyncContext.PendingOperations > 0)
            {
                await _client.SyncContext.PushAsync();
            }

            await _table.PurgeAsync();
        }
Пример #9
0
        public async Task <List <FormItem> > RefreshForms(string userId)
        {
            await Initialize();

            await formTable.PurgeAsync();

            await formTable.PullAsync(null, formTable.CreateQuery().Where(c => c.UserID == userId));

            return(await formTable.OrderByDescending(c => c.EnteredDateUTC).ToListAsync());
        }
        public async Task UpdateMoviesAsync(List <Movie> movies)
        {
            await InitAndSync();

            await _moviesTable.PurgeAsync();

            foreach (var movie in movies)
            {
                await _moviesTable.InsertAsync(movie);
            }
        }
Пример #11
0
 public async Task PurgeAsync()
 {
     try
     {
         var query = sensorDataTable.Where(s => s.speed > 0);
         await sensorDataTable.PurgeAsync(query);
     }
     catch (MobileServiceInvalidOperationException e)
     {
         Console.Error.WriteLine(@"Purge Failed: {0}", e.Message);
     }
 }
Пример #12
0
        internal async Task PurgeDataAsync()
        {
            IPlatform platform = DependencyService.Get <IPlatform>();
            await vehicleTableSync.PurgeFilesAsync();

            await vehicleTableSync.PurgeAsync(QueryVehicleString, null, true, CancellationToken.None);

            await claimTableSync.PurgeFilesAsync();

            await claimTableSync.PurgeAsync(QueryClaimString, null, true, CancellationToken.None);

            //delete downloaded files
            await FileHelper.DeleteLocalPathAsync(await platform.GetDataFilesPath());
        }
Пример #13
0
        /*********************************************************************/
        /*                    Get the Azure login credentials                */
        /*********************************************************************/
        public async Task <AzureToken> GetAzureTokenAsync(LocalToken currentUser)
        {
            //APPARENTLY THIS DOES NOT WORK PROPERLY
            await _azureTokenTable.PullAsync("loginUser",
                                             _azureTokenTable.Where(user => user.Id == currentUser.Id));

            List <AzureToken> _tokenList = await _azureTokenTable.Where(user =>
                                                                        user.Id == currentUser.Id).ToListAsync();

            //DELETE THE LOGIN INFORMATION
            await _azureTokenTable.PurgeAsync();

            return(_tokenList[0]);
        }
Пример #14
0
        public static async Task <bool> PurgeTableAsync()
        {
            try
            {
                await HomeSyncTable.PurgeAsync(true);

                Debug.WriteLine("HomeTableController.PurgeTableAsync - Table Purged");
                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine("AccountTableController.PurgeTableAsync - Error message recieved: " + e.Message);
                return(false);
            }
        }
Пример #15
0
        private async Task PurgeDataAsync()
        {
            var platform = DependencyService.Get <IPlatform>();
            await platform.LogoutAsync();

            await imageTableSync.PurgeAsync(AllImagesQueryString, null, true, CancellationToken.None);

            await albumTableSync.PurgeAsync(AllAlbumsQueryString, null, true, CancellationToken.None);

            // delete downloaded files
            await FileHelper.DeleteLocalFileAsync(await platform.GetDataFilesPath());

            Settings.Current.AuthenticationType = Settings.AuthOption.GuestAccess;
            Settings.Current.CurrentUserId      = Settings.Current.DefaultUserId;
        }
Пример #16
0
        public static async Task <bool> PurgeTableAsync()
        {
            try
            {
                await deviceTable.PurgeAsync(true);

                Debug.WriteLine("DeviceTable.PurgeTableAsync - Table Purged");
                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine("DeviceTable.PurgeTableAsync - Error message recieved: " + e.Message);
                return(false);
            }
        }
Пример #17
0
        private async Task InitializeAsync()
        {
            if (_avisoTable != null)
            {
                return;
            }

            // Inicialización de SQLite local
            var store = new MobileServiceSQLiteStore(GlobalSettings.Database);

            store.DefineTable <Aviso>();

            await _client.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());

            _avisoTable = _client.GetSyncTable <Aviso>();
            // Limpiar registros offline.
            await _avisoTable.PurgeAsync(true);
        }
Пример #18
0
        public async Task InitializeAsync()
        {
            if (azureClient?.SyncContext?.IsInitialized ?? false)
            {
                return;
            }

            //if (entriesTable != null)
            //    return;

            //InitialzeDatabase for path
            var path = localDatabaseFile;

            path = Path.Combine(MobileServiceClient.DefaultDatabasePath, path);

            //setup our local sqlite store and intialize our table
            store = new MobileServiceSQLiteStore(path);

            //Define Table
            store.DefineTable <DiaryEntry>();
            store.DefineTable <User>();

            try
            {
                //Initialize SyncContext
                await azureClient.SyncContext.InitializeAsync(store, new AzureSyncHandler(azureClient));

                //Get our sync table that will call out to azure
                entriesTable = azureClient.GetSyncTable <DiaryEntry>();
                userTable    = azureClient.GetSyncTable <User>();

                //Clean out local table
                await userTable.PurgeAsync(true);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Got exception: {0}", ex.Message);
            }
        }
Пример #19
0
        public async Task SynchronizeTopPostsAsync()
        {
            if (!LocalDBExists)
            {
                await Init();
            }
            try
            {
                await _topPostTable.PullAsync("MainPage", _topPostTable.CreateQuery());

                IList <TopPost> posts = await _topPostTable.Where(p => p.UserId == "u1").ToListAsync();

                foreach (var post in posts)
                {
                    Debug.WriteLine(post.ToString());
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                await _topPostTable.PurgeAsync();
            }
        }
Пример #20
0
        public async Task SynchronizePostsAsync()
        {
            if (!LocalDBExists)
            {
                await Init();
            }
            try
            {
                await _postTable.PullAsync("syncPosts", _postTable.CreateQuery());

                IEnumerable <Post> posts = await _postTable.Where(p => p.UserId == "u1").ToEnumerableAsync();

                foreach (var post in posts)
                {
                    Debug.WriteLine(post.Id);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                await _postTable.PurgeAsync();
            }
        }
Пример #21
0
        /// <summary>
        /// Ensures the data is seeded.
        /// </summary>
        async Task EnsureDataIsSeededAsync()
        {
            if (Settings.DataIsSeeded)
            {
                return;
            }

            await _RecipeTable.PullAsync($"getAll{typeof(Recipe).Name}", _RecipeTable.Where(x => x.DataPartitionId == _DataPartitionId)).ConfigureAwait(false);

            var any = (await _RecipeTable.Where(x => x.DataPartitionId == _DataPartitionId).OrderBy(x => x.Name).ToEnumerableAsync().ConfigureAwait(false)).Any();

            if (any)
            {
                Settings.DataIsSeeded = true;
            }

            await _RecipeTable.PurgeAsync();

            if (!Settings.DataIsSeeded)
            {
                var newItems = SeedData.Get("");

                foreach (var i in newItems)
                {
                    try
                    {
                        await _RecipeTable.InsertAsync(i);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }

                Settings.DataIsSeeded = true;
            }
        }
 public async Task ClearTable()
 {
     await mainTable.PurgeAsync(true);
 }
 public Task PurgeAsync()
 {
     return(_mobileServiceSyncTable.PurgeAsync(true));
 }
Пример #24
0
        public async Task Insert_ThenPush_ThenPull_ThenRead_ThenUpdate_ThenRefresh_ThenDelete_ThenLookup_ThenPush_ThenPurge_ThenRead()
        {
            ResetDatabase(TestTable);

            var hijack = new TestHttpHandler();

            hijack.AddResponseContent("{\"id\":\"b\",\"String\":\"Hey\"}");                                       // insert response
            hijack.AddResponseContent("[{\"id\":\"b\",\"String\":\"Hey\"},{\"id\":\"a\",\"String\":\"World\"}]"); // pull response
            hijack.AddResponseContent("[]");                                                                      // pull last page

            IMobileServiceClient service = await CreateTodoClient(hijack);

            IMobileServiceSyncTable <ToDoWithStringId> table = service.GetSyncTable <ToDoWithStringId>();

            // first insert an item
            await table.InsertAsync(new ToDoWithStringId()
            {
                Id = "b", String = "Hey"
            });

            // then push it to server
            await service.SyncContext.PushAsync();

            // then pull changes from server
            await table.PullAsync(null, null);

            // order the records by id so we can assert them predictably
            IList <ToDoWithStringId> items = await table.OrderBy(i => i.Id).ToListAsync();

            // we should have 2 records
            Assert.Equal(2, items.Count);

            // according to ordering a id comes first
            Assert.Equal("a", items[0].Id);
            Assert.Equal("World", items[0].String);

            // then comes b record
            Assert.Equal("b", items[1].Id);
            Assert.Equal("Hey", items[1].String);

            // we made 2 requests, one for push and two for pull
            Assert.Equal(3, hijack.Requests.Count);

            // recreating the client from state in the store
            service = await CreateTodoClient(hijack);

            table = service.GetSyncTable <ToDoWithStringId>();

            // update the second record
            items[1].String = "Hello";
            await table.UpdateAsync(items[1]);

            // create an empty record with same id as modified record
            var second = new ToDoWithStringId()
            {
                Id = items[1].Id
            };
            // refresh the empty record
            await table.RefreshAsync(second);

            // make sure it is same as modified record now
            Assert.Equal(second.String, items[1].String);

            // now delete the record
            await table.DeleteAsync(second);

            // now try to get the deleted record
            ToDoWithStringId deleted = await table.LookupAsync(second.Id);

            // this should be null
            Assert.Null(deleted);

            // try to get the non-deleted record
            ToDoWithStringId first = await table.LookupAsync(items[0].Id);

            // this should still be there;
            Assert.NotNull(first);

            // make sure it is same as
            Assert.Equal(first.String, items[0].String);

            // recreating the client from state in the store
            service = await CreateTodoClient(hijack);

            table = service.GetSyncTable <ToDoWithStringId>();

            await service.SyncContext.PushAsync();

            // now purge the remaining records
            await table.PurgeAsync();

            // now read one last time
            IEnumerable <ToDoWithStringId> remaining = await table.ReadAsync();

            // There shouldn't be anything remaining
            Assert.Empty(remaining);
        }
Пример #25
0
 public async Task CleanData()
 {
     await _table.PurgeAsync("allContacts", _table.CreateQuery(), new System.Threading.CancellationToken());
 }
Пример #26
0
 public async Task CleanData()
 {
     await Table.PurgeAsync("GetAllCategories", Table.CreateQuery(), new System.Threading.CancellationToken());
 }
Пример #27
0
 public async Task PurgeData()
 {
     await offlineTimesheet.PurgeAsync("allOfflineTimesheet", null, true, CancellationToken.None);
 }
Пример #28
0
 public async Task CleanLoginData()
 {
     await _loginTable.PurgeAsync("allLogins", _loginTable.CreateQuery(), new System.Threading.CancellationToken());
 }
Пример #29
0
 public async Task CleanPoItemData()
 {
     await _purchaseOrderItemTable.PurgeAsync("allPoItems", _purchaseOrderItemTable.CreateQuery(), new System.Threading.CancellationToken());
 }
Пример #30
0
 public async Task CleanAsync()
 {
     await _table.PurgeAsync("allContacts", string.Empty, true, new
                             System.Threading.CancellationToken())
     .ContinueWith((b) => { SetNotification(GetPendingOperations()); });
 }