Ejemplo n.º 1
0
        /// <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();
                }
            }
        }