Beispiel #1
0
        static async void HandleConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
        {
            var isRemoteDatabaseReachable = CrossConnectivity.Current.IsConnected && await CrossConnectivity.Current.IsRemoteReachable(BackendConstants.AzureAPIUrl);

            if (isRemoteDatabaseReachable)
            {
                await DatabaseSyncService.SyncRemoteAndLocalDatabases();
            }
        }
        private static async void HandleConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
        {
            if (e.NetworkAccess is NetworkAccess.Internet)
            {
                var apiResponse = await ApiService.GetHttpResponseMessage().ConfigureAwait(false);

                if (apiResponse.IsSuccessStatusCode)
                {
                    await DatabaseSyncService.SyncRemoteAndLocalDatabases().ConfigureAwait(false);
                }
            }
        }
        public ContactsListViewModel(ApiService apiService,
                                     ContactDatabase contactDatabase,
                                     AppCenterService appCenterService,
                                     DatabaseSyncService databaseSyncService) : base(appCenterService)
        {
            _apiService          = apiService;
            _contactDatabase     = contactDatabase;
            _databaseSyncService = databaseSyncService;

            RefreshCommand = new AsyncCommand(() =>
            {
                AppCenterService.Track(AppCenterConstants.PullToRefreshTriggered);
                return(ExecuteRefreshCommand());
            });

            RestoreDeletedContactsCommand = new AsyncCommand(() =>
            {
                AppCenterService.Track(AppCenterConstants.RestoreDeletedContactsTapped);
                return(ExecuteRestoreDeletedContactsCommand());
            });
        }
Beispiel #4
0
 public ConnectivityService(ApiService apiService, DatabaseSyncService databaseService, IConnectivity connectivity)
 {
     _apiService                       = apiService;
     _databaseSyncService              = databaseService;
     connectivity.ConnectivityChanged += HandleConnectivityChanged;
 }