Esempio n. 1
0
        public override async void OnNavigatedTo(NavigationParameters parameters)
        {
            IsBusy = true;
            try
            {
                base.OnNavigatedTo(parameters);

                var authUri = new Uri($"{ Login.Config.Constants.AzureServerUrl}/.auth/logout");
                using (var httpClient = new HttpClient())
                {
                    httpClient.DefaultRequestHeaders.Add("X-ZUMO-AUTH", Settings.LastValidToken);
                    httpClient.DefaultRequestHeaders.Add("ZUMO-API-VERSION", "2.0.0");
                    await httpClient.GetAsync(authUri);
                }
                await _login.LogoutAsync();
                await Navigate(@"http://myapp.com/NNavigationPage/OnStartRoutingPage");
            }
            catch (Exception ex)
            {
                InsightsLog.LogError(ex, "Logout_OnNavigatedTo");
            }
            finally
            {
                IsBusy = false;
            }
        }
Esempio n. 2
0
        public async Task SyncAllAsync()
        {
            //todo filter on valid sync by user, as user can disable sync for sensitive data


            ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null;

            try
            {
                //await ItemManager<T>.DefaultManager.CurrentClient.SyncContext.PushAsync();
                var pushAsync
                    = SharedClient.CurrentClient?.SyncContext.PushAsync();
                if (pushAsync != null)
                {
                    await pushAsync;
                }


                var listOfTables = ListOfTables();

                foreach (var tableName in listOfTables)
                {
                    var type   = Type.GetType($"{typeof(BaseModel).Namespace}.{tableName}");
                    var method =
                        //disables as that is method description, not invocation, else infinite waiting
                        GetSyncAllTablesMethod();


                    var genericMethod = method.MakeGenericMethod(type);

                    await genericMethod.InvokeVoidAsync(this, null);
                }
            }
            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)
            {
                try
                {
                    foreach (var error in syncErrors)
                    {
                        try
                        {
                            if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null)
                            {
                                await error.CancelAndUpdateItemAsync(error.Result);
                            }
                            else
                            {
                                await error.CancelAndDiscardItemAsync();
                            }

                            Debug.WriteLine(
                                $@"Error executing sync operation. Item: {error.TableName} ({
                                        error.Item["id"]
                                    }). Operation discarded.");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            InsightsLog.LogError(e, "SyncAllAsync_inside_syncErrors");
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    InsightsLog.LogError(e, "SyncAllAsync_outside_syncErrors");
                }
            }
        }