/// <inheritdoc /> public async Task LoadAsync() { if (this.contributionTypes != null || this.Loaded) { return; } await this.fileAccessSemaphore.WaitAsync(); this.Loaded = true; try { var file = await ApplicationData.Current.LocalFolder.CreateFileAsync( FileName, CreationCollisionOption.OpenIfExists); this.contributionTypes = await file.GetDataAsync <ContributionTypeContainerWrapper>(); } catch (Exception ex) { #if DEBUG System.Diagnostics.Debug.WriteLine(ex.ToString()); #endif } finally { this.fileAccessSemaphore.Release(); } if (this.contributionTypes == null) { this.contributionTypes = new ContributionTypeContainerWrapper { LastDateChecked = DateTime.MinValue }; await this.SaveAsync(); } this.LastDateChecked = this.contributionTypes.LastDateChecked; }
/// <inheritdoc /> public async Task UpdateAsync(bool forceUpdate) { await this.LoadAsync(); if (!NetworkStatusManager.Current.IsConnected()) { return; } if (this.LastDateChecked < DateTime.UtcNow - this.TimeBetweenUpdates || forceUpdate) { IEnumerable <ContributionType> serviceTypes = null; try { serviceTypes = await this.client.GetContributionTypesAsync(); } catch (HttpRequestException hre) when(hre.Message.Contains("401")) { // Show dialog, unauthorized user detected. Application.Current.Exit(); } if (serviceTypes != null) { if (this.contributionTypes == null) { this.contributionTypes = new ContributionTypeContainerWrapper(); } this.LastDateChecked = DateTime.UtcNow; this.contributionTypes.LastDateChecked = this.LastDateChecked; this.contributionTypes.ContributionTypes.Clear(); this.contributionTypes.ContributionTypes.AddRange(serviceTypes); await this.SaveAsync(); } } }