async Task SyncAsync(bool pullData = false) { try { await client.SyncContext.PushAsync(); if (pullData) { await todoTable.PullAsync("allTodoItems", todoTable.CreateQuery()); // query ID is used for incremental sync } } catch (MalformedURLException) { CreateAndShowDialog(new Exception("There was an error creating the Mobile Service. Verify the URL"), "Error"); } catch (Exception e) { CreateAndShowDialog(e, "Error"); } }
public async Task SyncAsync() { // 7. add auth await EnsureLogin(); //5. add sync try { await this.MobileService.SyncContext.PushAsync(); var query = jobTable.CreateQuery() .Where(job => job.AgentId == "2"); await jobTable.PullAsync(null, query); } catch (Exception) { } }
//void Initialize () public async Task InitializeAsync() { if (client != null) { return; } //var path = "syncstore.db"; //path = Path.Combine (MobileServiceClient.DefaultDatabasePath, path); // var store = new MobileServiceSQLiteStore ("survey.db"); //var store = new MobileServiceSQLiteStore ("newsurvey.db"); //var store = new MobileServiceSQLiteStore ("newnewsurvey.db"); var store = new MobileServiceSQLiteStore("new7survey.db"); store.DefineTable <SurveyQuestion> (); store.DefineTable <SurveyResponse> (); store.DefineTable <ThinkingOfYou> (); client = new MobileServiceClient(AzureUrl); await client.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler()); questionsTable = client.GetSyncTable <SurveyQuestion> (); responseTable = client.GetSyncTable <SurveyResponse> (); thinkingOfYouTable = client.GetSyncTable <ThinkingOfYou> (); if (CrossConnectivity.Current.IsConnected) { try { await client.SyncContext.PushAsync(); await questionsTable.PullAsync( "allQuestions", questionsTable.CreateQuery()); } catch (Exception ex) { Debug.WriteLine("Got exception: {0}", ex.Message); } } } //end initialize
private async Task SyncAsync() { ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null; try { await _client.SyncContext.PushAsync(); await _locationTable.PullAsync("allLocations", _locationTable.CreateQuery()); } catch (MobileServicePushFailedException exc) { if (exc.PushResult != null) { syncErrors = exc.PushResult.Errors; } } catch (Exception ex) { Debug.WriteLine(ex.Message); throw; } 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(); } Debug.WriteLine(@"Error executing sync opertation. Item: {0} ({1}). Operation discarded.", error.TableName, error.Item["id"]); } } }
private async Task SyncAsync() { string errorString = null; try { await client.SyncContext.PushAsync(); await sightTable.PushFileChangesAsync(); await sightFileTable.PushFileChangesAsync(); await tripTable.PullAsync("tripItems", tripTable.CreateQuery()); foreach (var trip in await tripTable.ToCollectionAsync()) { await sightTable.PullAsync("attractionItems", sightTable.CreateQuery().Where(s => s.TripId == trip.Id)); } foreach (var sight in await sightTable.ToCollectionAsync()) { await sightFileTable.PullAsync("attractionFileItems", sightFileTable.CreateQuery().Where(sf => sf.SightId == sight.Id)); } } catch (MobileServicePushFailedException ex) { errorString = "Push failed because of sync errors. You may be offline.\nMessage: " + ex.Message + "\nPushResult.Status: " + ex.PushResult.Status; } catch (Exception ex) { errorString = "Pull failed: " + ex.Message + "\n\nIf you are still in an offline scenario, " + "you can try your Pull again when connected with your Mobile Service."; } if (errorString != null) { await ShowError(errorString); } }
async Task SyncAsync() { ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null; try { await _client.SyncContext.PushAsync(); await _ticketsTable.PullAsync("all", _ticketsTable.CreateQuery()); } catch (MobileServicePushFailedException ex) { if (ex.PushResult != null) { syncErrors = ex.PushResult.Errors; } } if (syncErrors != null) { foreach (var error in syncErrors) { if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null) { // Update failed, revert to server's copy await error.CancelAndUpdateItemAsync(error.Result); } else { // Discard local change await error.CancelAndDiscardItemAsync(); } Debug.WriteLine(@"Error executing sync operation. Item: {0} ({1}). Operation discarded.", error.TableName, error.Item["id"]); } } else { Debug.WriteLine("Synced successfully."); } }
private async void ButtonPull_Click(object sender, RoutedEventArgs e) { Exception pullException = null; try { await todoTable.PullAsync(todoTable.Where(todoItem => todoItem.Complete == false)); RefreshTodoItems(); } catch (Exception ex) { pullException = ex; } if (pullException != null) { MessageBox.Show("Pull failed: " + pullException.Message + "\n\nIf you are in an offline scenario, " + "try your Pull again when connected with your Mobile Service."); } }
public async Task SyncOfflineCacheAsync() { string queryName = $"incremental_sync_{typeof(T).Name}"; try { await provider.Client.SyncContext.PushAsync(); await syncTable.PullAsync(queryName, syncTable.CreateQuery()); } catch (MobileServicePushFailedException exception) { if (exception.PushResult != null) { foreach (var error in exception.PushResult.Errors) { await ResolveConflictAsync(error); } } } }
private async Task SyncAsync() { try { var ct = cts.Token; ct.ThrowIfCancellationRequested(); await App.MobileService.SyncContext.PushAsync(); await vehicles.PullAsync("vehicles", vehicles.CreateQuery()); } catch (MobileServicePushFailedException) { } finally { foreach (var vehicle in await vehicles.ToEnumerableAsync()) { Debug.WriteLine("Vehicle: " + vehicle.Name); } } }
public async Task <List <InventoryItem> > RefreshDataAsync() { try { // update the local store // all operations on todoTable use the local database, call SyncAsync to send changes await _inventoryTable.PullAsync("InventoryItems", _inventoryTable.CreateQuery()); // query ID is used for incremental sync // This code refreshes the entries in the list view by querying the local TodoItems table. // The query excludes completed TodoItems Items = await _inventoryTable.ToListAsync(); } catch (Exception e) { Console.Error.WriteLine(@"ERROR {0}", e.Message); return(null); } return(Items); }
} //end initialize async Task SynchronizeResponsesAsync(string questionId) { if (!CrossConnectivity.Current.IsConnected) { return; } try { await responseTable.PullAsync("syncResponses" + questionId, responseTable.Where(r => r.SurveyQuestionId == questionId)); } catch (MobileServicePushFailedException ex) { if (ex.PushResult != null) { foreach (var result in ex.PushResult.Errors) { await ResolveError(result); } } } catch (Exception ex) { Debug.WriteLine("Got exception: {0}", ex.Message); } }
/// <summary> /// Syncs Pump Table with mobile API values /// </summary> /// <param name="Id">Pump Id to Sync</param> /// <returns>System.Threading.Tasks.Task</returns> public async Task <SyncState> SyncPump() { SyncState state = SyncState.Offline; if (CrossConnectivity.Current.IsConnected) { try { await pumpTable.PullAsync(Guid.NewGuid().ToString(), pumpTable.Select(p => p)); state = SyncState.Complete; } catch (MobileServicePushFailedException exc) { await SimpleConflictResolution(exc); state = SyncState.CompleteWithConflicts; } } return(state); }
public async Task SyncPoof() { try { if (!CrossConnectivity.Current.IsConnected) { return; } //pull down all latest changes and then push current poofs up await Client.SyncContext.PushAsync(); //await poofTable.PullAsync("allPoofs" + Settings.UserId, poofTable.CreateQuery()); await poofTable.PullAsync("allPoofs" + Settings.UserId, poofTable.Where(p => p.UserId == Settings.UserId && p.DateUtc >= DateTime.UtcNow.Date.AddDays(-7))); } catch (Exception ex) { Insights.Report(ex, Insights.Severity.Error); } }
public async Task SyncLocations() { try { var current = Connectivity.NetworkAccess; if (!(current == NetworkAccess.Internet)) { return; } await locationsTable.PullAsync("allLocations", locationsTable.CreateQuery()); await Client.SyncContext.PushAsync(); } catch (Exception ex) { Crashes.TrackError(ex, new Dictionary <string, string> { { "AzureService", "Unable to sync locations, that is alright as we have offline capabilities" } }); } }
private async Task SyncAsync() { try { await client.SyncContext.PushAsync(); await beaconTable.PullAsync("allBeacons", beaconTable.CreateQuery()); // query ID is used for incremental sync await guisettingsTable.PullAsync("allGuiSettings", guisettingsTable.CreateQuery()); // query ID is used for incremental sync await locationTable.PullAsync("allBeacons", locationTable.CreateQuery()); // query ID is used for incremental sync } catch (Java.Net.MalformedURLException) { CreateAndShowDialog(new Exception("There was an error creating the Mobile Service. Verify the URL"), "Error"); } catch (Exception e) { CreateAndShowDialog(e, "Error"); } }
public Login() { InitializeComponent(); _mobileServiceClient = Services.AzureDataService.Instance._mobileServiceClient; StartLoadingAnimation(); //Get our sync table that will call out to azure UsersTable = ServiceClient.GetSyncTable <Users>(); UsersTable.PullAsync("Users", UsersTable.CreateQuery()); if (defaultInstance == null) { defaultInstance = this; StopLoadingAnimation(); } else { //try to load current user from mobileServiceClient RetrieveUser(); } }
/* * public async Task<Species> AddSpecies() * { * await Initialize(); * Species mySpecies = new Species * { * speciesName = "yexiaozhou", * invasiveOrNot = true, * }; * * await speciesTable.InsertAsync(mySpecies); * await SyncSpecies(); * return mySpecies; * }*/ public async Task SyncSpecies() { await Initialize(); ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null; try { await MobileClient.SyncContext.PushAsync(); await speciesTable.PullAsync($"allMessage", speciesTable.CreateQuery()); } catch (MobileServicePushFailedException exc) { if (exc.PushResult != null) { syncErrors = exc.PushResult.Errors; } } // Simple error/conflict handling. if (syncErrors != null) { foreach (var error in syncErrors) { if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null) { // Update failed, revert to server's copy await error.CancelAndUpdateItemAsync(error.Result); } else { // Discard local change await error.CancelAndDiscardItemAsync(); } Debug.WriteLine(@"Error executing sync operation. Item: {0} ({1}). Operation discarded.", error.TableName, error.Item["id"]); } } }
public async Task SyncAsync() { ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null; try { await client.SyncContext.PushAsync(); // The first paramter is a query name, used to implement incremental sync await todoTable.PullAsync("allTodoItems", todoTable.CreateQuery()); } catch (MobileServicePushFailedException exc) { if (exc.PushResult != null) { syncErrors = exc.PushResult.Errors; } } // Simple conflict handling. A real application would handle the various errors like network // conditions, server conflicts and others via the IMobileServiceSyncHandler. This version will // revert to the server copy or discard the local change (i.e. server wins policy) if (syncErrors != null) { foreach (var error in syncErrors) { if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null) { // Revert to the server copy await error.CancelAndUpdateItemAsync(error.Result); } else { // Discard the local change await error.CancelAndDiscardItemAsync(); } Debug.WriteLine($"Error executing sync operation on table {error.TableName}: {error.Item["id"]} (Operation Discarded)"); } } }
public async Task SyncPeakItemsAsync() { ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null; try { await CurrentClient.SyncContext.PushAsync(); //The first parameter is a query name that is used internally by the client SDK to implement incremental sync. //Use a different query name for each unique query in your program await peakTable.PullAsync("allPeakItems", peakTable.CreateQuery()); } catch (MobileServicePushFailedException exc) { if (exc.PushResult != null) { syncErrors = exc.PushResult.Errors; } } // Simple error/conflict handling. A real application would handle the various errors like network conditions, // server conflicts and others via the IMobileServiceSyncHandler. if (syncErrors != null) { foreach (var error in syncErrors) { if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null) { //Update failed, reverting to server's copy. await error.CancelAndUpdateItemAsync(error.Result); } else { // Discard local change. await error.CancelAndDiscardItemAsync(); } Debug.WriteLine(@"Error executing sync operation. Item: {0} ({1}). Operation discarded.", error.TableName, error.Item["id"]); } } }
public async Task SyncToDos() { //TODO 3: Add connectivity check. //var connected = await Plugin.Connectivity.CrossConnectivity.Current.IsReachable(Helpers.Keys.AzureServiceUrl, 5000); //var connected = await Plugin.Connectivity.CrossConnectivity.Current.IsRemoteReachable("https://altran-socioapp.azurewebsites.net", 5000); var connected = await Plugin.Connectivity.CrossConnectivity.Current.IsRemoteReachable("google.com", 1000); //if (connected == false) // return; try { //TODO 4: Push and Pull our data await MobileService.SyncContext.PushAsync(); await todoTable.PullAsync("allTodoItems", todoTable.CreateQuery()); } catch (Exception ex) { Debug.WriteLine("Unable to sync items, that is alright as we have offline capabilities: " + ex); } }
/// <summary> /// Refresh the async table from the cloud /// </summary> /// <param name="row"></param> /// <returns></returns> public async Task RefreshAsync() { await InitializeAsync(); var store = await DataStore.GetInstance(); if (store.IsAuthenticated) { try { // Do the Pushes await store.CloudService.SyncContext.PushAsync(); } catch (Exception ex) { Debug.WriteLine(string.Format("EXCEPTION:{0}", ex.Message)); } // Do the pulls await _controller.PullAsync("tablequery", _controller.CreateQuery()); } }
public async Task SyncToDos() { //TODO 3: Add connectivity check. var connected = await Plugin.Connectivity.CrossConnectivity.Current.IsReachable(Helpers.Keys.AzureServiceUrl); if (connected == false) { return; } try { //TODO 4: Push and Pull our data await MobileService.SyncContext.PushAsync(); await todoTable.PullAsync("allTodoItems", todoTable.CreateQuery()); } catch (Exception ex) { Debug.WriteLine("Unable to sync items, that is alright as we have offline capabilities: " + ex); } }
public async Task SyncLocationsAsync() { try { if (!CrossConnectivity.Current.IsConnected || !Settings.NeedsSync) { return; } await locationTable.PullAsync("allOffices", locationTable.CreateQuery() /*.Where(o => o.AppId == AppId )*/); Settings.LastSync = DateTime.Now; } catch (Exception ex) { Analytics.TrackEvent("Exception", new Dictionary <string, string> { { "Message", ex.Message }, { "StackTrace", ex.ToString() } }); Debug.WriteLine("Sync Failed:" + ex.Message); } }
public async Task SyncAsync() { ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null; try { await _client.SyncContext.PushAsync(); await _table.PullAsync("allAnimes", _table.CreateQuery()); } catch (MobileServicePushFailedException pushEx) { if (pushEx.PushResult != null) { syncErrors = pushEx.PushResult.Errors; } } // Simple error/conflict handling. if (syncErrors != null) { foreach (var error in syncErrors) { if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null) { //Update failed, reverting to server's copy. await error.CancelAndUpdateItemAsync(error.Result); } else { // Discard local change. await error.CancelAndDiscardItemAsync(); } Debug.WriteLine(@"Error executing sync operation. Item: {0} ({1}). Operation discarded.", error.TableName, error.Item["id"]); } } }
public async Task Sync() { var connected = await CrossConnectivity.Current.IsReachable("google.com"); if (connected == false) { return; } try { await MobileService.SyncContext.PushAsync(); await wordsTable.PullAsync("allWords", wordsTable.CreateQuery()); await topicsTable.PullAsync("allTopics", wordsTable.CreateQuery()); } catch (Exception ex) { Debug.WriteLine("Unable to sync items, that is alright as we have offline capabilities: " + ex); } }
public async Task SyncStudent() { await Initialize(); try { //We are offline, skip if (!CrossConnectivity.Current.IsConnected) { return; } //We are online await client.SyncContext.PushAsync(); await studentTable.PullAsync("allStudents", studentTable.CreateQuery()); } catch (Exception ex) { Debug.WriteLine(ex); } }
public static async Task SyncQueueCustomerAsync() { ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null; try { await client.SyncContext.PushAsync(); // A normal pull will automatically process new/modified/deleted files, engaging the file sync handler await _queueCustomerTable.PullAsync("QueueCustomers", _queueCustomerTable.CreateQuery()); } catch (MobileServicePushFailedException exc) { if (exc.PushResult != null) { syncErrors = exc.PushResult.Errors; } } // Simple error/conflict handling. A real application would handle the various errors like network conditions, // server conflicts and others via the IMobileServiceSyncHandler. if (syncErrors != null) { foreach (var error in syncErrors) { if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null) { //Update failed, reverting to server's copy. await error.CancelAndUpdateItemAsync(error.Result); } else { // Discard local change. await error.CancelAndDiscardItemAsync(); } } } }
public async Task SyncAsync() { ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null; try { await client.SyncContext.PushAsync(); string query = $"incsync_{typeof(T).Name}"; await table.PullAsync(query, table.CreateQuery()); } catch (MobileServicePushFailedException ex) { if (ex.Source != null) { syncErrors = ex.PushResult.Errors; } } catch (Exception e) { Debug.WriteLine(e.Message); } if (syncErrors != null) { foreach (var error in syncErrors) { if (error.OperationKind == MobileServiceTableOperationKind.Update) { await error.CancelAndUpdateItemAsync(error.Result); } else { await error.CancelAndDiscardItemAsync(); } } } }
public async Task SyncOfflineCache(bool throwException = false) { try { Settings.HasSyncStarted = true; // Only here to simulate something bad happening :) if (throwException) { throw new Exception(); } await Initializer(); await client.SyncContext.PushAsync(); //var table = client.GetSyncTable<ToDoItem>(); await table.PullAsync("todo-incremental", table.CreateQuery()); } catch (MobileServicePreconditionFailedException <ToDoItem> precondEx) { // happens for online only } catch (MobileServicePushFailedException ex) { if (ex.PushResult != null) { await ResolveConflicts(ex.PushResult); } } finally { if (!throwException) { Settings.HasSyncStarted = false; } } }
public async Task PullAsync <T>(IMobileServiceSyncTable <T> Table) { ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null; try { // The first parameter is a query name that is used internally by the client SDK to implement incremental sync. // Use a different query name for each unique query in your program. await Table.PullAsync(nameof(Table), Table.CreateQuery()); } catch (MobileServicePushFailedException exc) { if (exc.PushResult != null) { syncErrors = exc.PushResult.Errors; } } // Simple error/conflict handling. if (syncErrors != null) { foreach (var error in syncErrors) { if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null) { // Update failed, revert to server's copy await error.CancelAndUpdateItemAsync(error.Result); } else { // Discard local change await error.CancelAndDiscardItemAsync(); } Debug.WriteLine(@"Error executing sync operation. Item: {0} ({1}). Operation discarded.", error.TableName, error.Item["id"]); } } }