コード例 #1
0
        public 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 (MobileServiceInvalidOperationException e)
            {
                Console.Error.WriteLine(@"Sync Failed: {0}", e.Message);
            }
        }
コード例 #2
0
        public async Task SyncAsync()
        {
            await Initialize();

            ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null;

            try
            {
                await client.SyncContext.PushAsync();

                await todoTable.PullAsync(
                    //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
                    "allTodoItems",
                    todoTable.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 if (error.OperationKind != MobileServiceTableOperationKind.Update)
                    {
                        // Discard local change.
                        await error.CancelAndDiscardItemAsync();
                    }

                    Debug.WriteLine(@"Error executing sync operation. Item: {0} ({1}). Operation discarded.", error.TableName, error.Item["id"]);
                }
            }
        }
コード例 #3
0
        public async Task SyncMovies()
        {
            ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null;

            try
            {
                await _mobileServiceClient.SyncContext.PushAsync();
            }
            catch (MobileServicePushFailedException e)
            {
                if (e.PushResult != null)
                {
                    syncErrors = e.PushResult.Errors;
                }
            }

            // Error/conflict handling.
            if (syncErrors != null)
            {
                foreach (var error in syncErrors)
                {
                    if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null)
                    {
                        // Revert to server's copy
                        await error.CancelAndUpdateItemAsync(error.Result);
                    }
                    else
                    {
                        // Discard local change
                        await error.CancelAndDiscardItemAsync();
                    }

                    Debug.WriteLine($"Error executing sync operation. Item: {error.TableName} ({error.Item["id"]}). Operation discarded.");
                }
            }

            try
            {
                await _moviesTable.PullAsync("allMovies", _moviesTable.CreateQuery());
            }
            catch (Exception)
            {
                // It is ok if we are not connected
            }
        }
コード例 #4
0
        private async Task SyncAsync(bool pullData = false)
        {
            try
            {
                await azureDatabase.SyncContext.PushAsync();

                if (pullData)
                {
                    await azureSyncTable.PullAsync("allTodoItems", azureSyncTable.CreateQuery());

                    // query ID is used for incremental sync
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
コード例 #5
0
        public async Task SyncPomodoro()
        {
            try
            {
                if (!CrossConnectivity.Current.IsConnected)
                {
                    return;
                }

                await pomodoroTable.PullAsync("allPomodoro", pomodoroTable.CreateQuery());

                await ServiceManager.DefaultManager.CurrentClient.SyncContext.PushAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to sync coffees, that is alright as we have offline capabilities: " + ex);
            }
        }
コード例 #6
0
ファイル: AzureDataStore.cs プロジェクト: quikkz/OnBudget
 public async Task <bool> PullLatestAsync()
 {
     if (!CrossConnectivity.Current.IsConnected)
     {
         Debug.WriteLine("Unable to pull items, we are offline");
         return(false);
     }
     try
     {
         await itemsTable.PullAsync($"all{typeof(Item).Name}", itemsTable.CreateQuery());
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Unable to pull items, that is alright as we have offline capabilities: " + ex);
         return(false);
     }
     return(true);
 }
コード例 #7
0
        /*
         * //Select an option from the menu
         * public override bool OnOptionsItemSelected(IMenuItem item)
         * {
         *  if (item.ItemId == Resource.Id.menu_refresh) {
         *      item.SetEnabled(false);
         *
         *      OnRefreshItemsSelected();
         *
         *      item.SetEnabled(true);
         *  }
         *  return true;
         * }
         */
        private 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
                    await User.PullAsync("CreateUser", User.CreateQuery());
                }
            }
            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");
            }
        }
コード例 #8
0
        public async Task SyncCoffee()
        {
            try
            {
                if (!CrossConnectivity.Current.IsConnected)
                {
                    return;
                }

                await _coffeeTable.PullAsync("allCoffee", _coffeeTable.CreateQuery());

                await Client.SyncContext.PushAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to sync coffees, that is alright as we have offline capabilities: " + ex);
            }
        }
コード例 #9
0
        public async Task SyncStoresAsync()
        {
            try
            {
                if (!IsInternetAvailable || !Settings.NeedsSync)
                {
                    return;
                }

                await storeTable.PullAsync("allStores", storeTable.CreateQuery());

                Settings.LastSync = DateTime.Now;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Sync Failed:" + ex.Message);
            }
        }
コード例 #10
0
        public async Task SyncService()
        {
            try
            {
                if (!CrossConnectivity.Current.IsConnected)
                {
                    return;
                }

                await serviceTable.PullAsync("servicosFeitos", serviceTable.CreateQuery());

                await Client.SyncContext.PushAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to sync schedules, that is alright as we have offline capabilities: " + ex);
            }
        }
コード例 #11
0
        private async Task SyncAsync(bool pullData = false)
        {
            try
            {
                await client.SyncContext.PushAsync();

                if (pullData)
                {
                    await torneoItemTable.PullAsync("allTorneoItems", torneoItemTable.CreateQuery().Where(
                                                        item => item.Email == emailParticipante));
                }
            }
            catch (Exception e)
            {
                string error = e.Message;
                Toast.MakeText(this, "Error: " + error, ToastLength.Long);
            }
        }
コード例 #12
0
        public async Task SyncStoresAsync()
        {
            try
            {
                if (!CrossConnectivity.Current.IsConnected || !Settings.NeedsSync)
                {
                    return;
                }

                await storeTable.PullAsync("allStores", storeTable.CreateQuery());

                Settings.LastSync = DateTime.Now;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Sync Failed:" + ex.Message);
            }
        }
コード例 #13
0
        public async Task SyncAsync()
        {
            ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null;

            // assicurarsi che il gestore sia stato inizializzato
            await Initialize();

            try
            {
                await client.SyncContext.PushAsync();

                /* i primo parametro è un nome di query utilizzato internamente dall'SDK
                 * client per implementare la sincronizzazione incrementale, uusare
                 * un nome di query diverso per ogni query univoca nell'app  */
                await todoTable.PullAsync("allTodoItems", todoTable.CreateQuery());
            }
            catch (MobileServicePushFailedException exc)
            {
                if (exc.PushResult != null)
                {
                    syncErrors = exc.PushResult.Errors;
                }
            }

            /* gestione di errori/conflitti, un'app reale gestirebbe i vari errori come le
             * condizioni di rete, conflitti tra server e altri tramite IMobileServiceSyncHandler  */
            if (syncErrors != null)
            {
                foreach (var error in syncErrors)
                {
                    if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null)
                    {
                        // aggiornamento non riuscito, ripristino della copia del server
                        await error.CancelAndUpdateItemAsync(error.Result);
                    }
                    else if (error.OperationKind != MobileServiceTableOperationKind.Update)
                    {
                        // eliminare le modifiche locali
                        await error.CancelAndDiscardItemAsync();
                    }
                    Debug.WriteLine(@"Errore durante l'esecuzione dell'operazione di sincronizzazione. Item: {0} ({1}). Operazione scartata.", error.TableName, error.Item["id"]);
                }
            }
        }
コード例 #14
0
        public DataManager()
        {
            ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null;

            try
            {
                _client = new MobileServiceClient(Constants.ApplicationUrl);

                var store = new MobileServiceSQLiteStore("localstore.db");
                store.DefineTable <Location>();

                _client.SyncContext.InitializeAsync(store);

                _locationTable = _client.GetSyncTable <Location>();

                _locationTable.PullAsync(null, _locationTable.CreateQuery());
            }

            catch (MobileServiceInvalidOperationException ioe)
            {
                Debug.WriteLine(ioe.Message);
            }

            catch (MobileServicePushFailedException exc)
            {
                if (exc.PushResult != null)
                {
                    syncErrors = exc.PushResult.Errors;
                }
            }

            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            if (syncErrors != null)
            {
                foreach (var error in syncErrors)
                {
                    Debug.WriteLine(@"Error executing sync opertation. Item: {0} ({1}). Operation discarded.", error.TableName, error.Item["id"]);
                }
            }
        }
コード例 #15
0
        public async Task SyncFeedback()
        {
            try
            {
                if (!CrossConnectivity.Current.IsConnected)
                {
                    return;
                }

                await feedbackTable.PullAsync("allFeedback", feedbackTable.CreateQuery());

                await Client.SyncContext.PushAsync();
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                Debug.WriteLine("Unable to sync feedback, that is alright as we have offline capabilities: " + ex);
            }
        }
コード例 #16
0
        public async Task <Customer> GetCustomerAsync(string id)
        {
            try
            {
                var customer = await customerTable.LookupAsync(id);

                if (customer == null)
                {
                    return(null);
                }

                // Expand orders
                customer.Orders = await orderTable.CreateQuery().Where(c => c.CustomerId == customer.Id).ToCollectionAsync();

                if (customer.Orders != null)
                {
                    // Expand Product
                    foreach (var item in customer.Orders.SelectMany(c => c.OrderDetails))
                    {
                        item.Product = await productTable.LookupAsync(item.ProductId);
                    }
                }
                if (customer.Addresses != null)
                {
                    int index = 1;
                    foreach (var addr in customer.Addresses)
                    {
                        addr.Index = index;
                        index++;
                    }
                }
                return(customer);
            }
            catch (MobileServiceInvalidOperationException msioe)
            {
                Debug.WriteLine("Invalid sync operation: {0}", new[] { msioe.Message });
            }
            catch (Exception e)
            {
                Debug.WriteLine("Sync error: {0}", new[] { e.Message });
            }
            return(null);
        }
        private async Task SynchronizeAsync()
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                return;
            }

            try
            {
                await client.SyncContext.PushAsync();

                await favouriteSpotsTable.PullAsync(null, favouriteSpotsTable.CreateQuery());
            }
            catch (Exception ex)
            {
                // TODO: handle error in your app specific way
                Console.WriteLine("Could not sync: " + ex.Message);
            }
        }
コード例 #18
0
        public async Task SyncCoffee()
        {
            var time = Xamarin.Insights.TrackTime("SyncCoffeeTime");

            time.Start();
            try
            {
                //pull down all latest changes and then push current coffees up
                await coffeeTable.PullAsync("allCoffees", coffeeTable.CreateQuery());

                await MobileService.SyncContext.PushAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to sync coffees, that is alright as we have offline capabilities: " + ex);
            }

            time.Stop();
        }
コード例 #19
0
ファイル: Client.cs プロジェクト: anasonov/BeerDrinkin
        public async Task SyncAsync <T>(IMobileServiceSyncTable <T> table, string queryId)
        {
            try
            {
                await Client.SyncContext.PushAsync();

                await table.PullAsync(queryId, table.CreateQuery());
            }
            catch (MobileServiceInvalidOperationException e)
            {
                //TODO Implement some logger
                Debug.WriteLine(@"Sync Failed on {0} table with message of: {1}", table, e.Message);
            }
            catch (Exception ex)
            {
                //TODO Implement some logger
                Debug.WriteLine(@"Sync Failed on {0} table with message of: {1}", table, ex.Message);
            }
        }
コード例 #20
0
        private async Task SyncAsync()
        {
            try
            {
                await PushReadsToCloud();

                SyncStatus = "Pulling...";
                await RouteSyncTable.PullAsync("PullQuery", RouteSyncTable.CreateQuery());

                SyncStatus = "Syncronized";

                ReadEndpoints   = 0;
                TotalEndpoints  = 0;
                BadLocEndpoints = 0;
            }
            catch (Exception e)
            {
                SyncStatus = "Error Syncronizing: " + e.Message;
            }
            finally
            {
                IEnumerable <JsonMeterModel> SyncMeters = await RouteSyncTable.ReadAsync();

                foreach (JsonMeterModel model in SyncMeters)
                {
                    Meters.Add(new MeterModel()
                    {
                        MeterInfo = model,
                        Location  = new Geopoint(new BasicGeoposition()
                        {
                            Latitude = model.Latitude, Longitude = model.Longitude
                        }),
                        ReadUpdated = false
                    });
                    if (Meters.Count == 20)
                    {
                        break;
                    }
                    //await Task.Delay(1);
                }
            }
        }
コード例 #21
0
        public async Task <ObservableCollection <Customer> > GetCustomersAsync(string term)
        {
            try
            {
                IEnumerable <Customer> items = await customerTable.CreateQuery()
                                               .Where(c => c.Name.Contains(term) || c.CustomerNumber.Contains(term) || c.Email.Contains(term) || c.Phone.Contains(term))
                                               .ToEnumerableAsync();

                return(new ObservableCollection <Customer>(items));
            }
            catch (MobileServiceInvalidOperationException msioe)
            {
                Debug.WriteLine("Invalid sync operation: {0}", new[] { msioe.Message });
            }
            catch (Exception e)
            {
                Debug.WriteLine("Sync error: {0}", new[] { e.Message });
            }
            return(null);
        }
コード例 #22
0
        public async Task SyncAsync(bool pullData = false)
        {
            try
            {
                await client.SyncContext.PushAsync();

                if (pullData)
                {
                    await usuarioTable.PullAsync("allUsuarios", usuarioTable.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");
            }
        }
コード例 #23
0
        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");
            }
        }
コード例 #24
0
        public async Task SyncWords()
        {
            var connected = await CrossConnectivity.Current.IsReachable("google.com");

            if (connected == false)
            {
                return;
            }

            try
            {
                await MobileService.SyncContext.PushAsync();

                await wordTable.PullAsync("allWords", wordTable.CreateQuery());
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Unable to sync items, that is alright as we have offline capabilities: " + ex);
            }
        }
コード例 #25
0
        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.");
            }
        }
コード例 #26
0
        //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
コード例 #27
0
        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);
            }
        }
コード例 #28
0
        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"]);
                }
            }
        }
コード例 #29
0
        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);
                }
            }
        }
コード例 #30
0
        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" }
                });
            }
        }