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; }
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(); } 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(); } } }