public async Task UpdateAsync(bool forceUpdate) { await this.LoadAsync(); if (!NetworkStatusManager.Current.IsConnected()) { return; } if (this.LastDateChecked < DateTime.UtcNow - this.TimeBetweenUpdates || forceUpdate) { IEnumerable <AwardContribution> serviceAreas = null; bool isAuthenticated = true; try { serviceAreas = await this.client.GetContributionAreasAsync(); } catch (HttpRequestException hre) when(hre.Message.Contains("401")) { isAuthenticated = false; } catch (Exception ex) { EventLogger.Current.WriteError(ex.ToString()); } if (!isAuthenticated) { await MessageDialogManager.Current.ShowAsync( "Not authorized", "You are no longer authenticated.", new UICommand( "Ok", async command => { await this.client.LogOutAsync(); })); Application.Current.Exit(); } if (serviceAreas != null) { if (this.contributionAreas == null) { this.contributionAreas = new ContributionAreaContainerWrapper(); } this.LastDateChecked = DateTime.UtcNow; this.contributionAreas.LastDateChecked = this.LastDateChecked; this.contributionAreas.ContributionAreas.Clear(); this.contributionAreas.ContributionAreas.AddRange(serviceAreas); await this.SaveAsync(); } } }
public async Task ClearAsync() { await this.LoadAsync(); if (this.contributionAreas == null) { this.contributionAreas = new ContributionAreaContainerWrapper(); } this.contributionAreas.ContributionAreas = new List <AwardContribution>(); this.LastDateChecked = DateTime.MinValue; this.contributionAreas.LastDateChecked = this.LastDateChecked; await this.SaveAsync(); }
public async Task UpdateAsync(bool forceUpdate) { await this.LoadAsync(); if (!NetworkStatusManager.Current.IsConnected()) { return; } if (this.LastDateChecked < DateTime.UtcNow - this.TimeBetweenUpdates || forceUpdate) { IEnumerable <AwardContribution> serviceAreas = null; try { serviceAreas = await this.client.GetContributionAreasAsync(); } catch (HttpRequestException hre) when(hre.Message.Contains("401")) { // Show dialog, unauthorized user detected. Application.Current.Exit(); } catch (Exception ex) { EventLogger.Current.WriteError(ex.ToString()); } if (serviceAreas != null) { if (this.contributionAreas == null) { this.contributionAreas = new ContributionAreaContainerWrapper(); } this.LastDateChecked = DateTime.UtcNow; this.contributionAreas.LastDateChecked = this.LastDateChecked; this.contributionAreas.ContributionAreas.Clear(); this.contributionAreas.ContributionAreas.AddRange(serviceAreas); await this.SaveAsync(); } } }
public async Task LoadAsync() { if (this.contributionAreas != null || this.Loaded) { return; } await this.fileAccessSemaphore.WaitAsync(); this.Loaded = true; try { var file = await ApplicationData.Current.LocalFolder.CreateFileAsync( FileName, CreationCollisionOption.OpenIfExists); this.contributionAreas = await file.GetDataAsync <ContributionAreaContainerWrapper>(); } catch (Exception ex) { #if DEBUG System.Diagnostics.Debug.WriteLine(ex.ToString()); #endif } finally { this.fileAccessSemaphore.Release(); } if (this.contributionAreas == null) { this.contributionAreas = new ContributionAreaContainerWrapper { LastDateChecked = DateTime.MinValue }; await this.SaveAsync(); } this.LastDateChecked = this.contributionAreas.LastDateChecked; }