public async Task SetProfileAsync(MVPProfile profile)
        {
            await this.LoadAsync();

            if (this.profileData == null)
            {
                this.profileData = new ProfileDataContainerWrapper();
            }

            this.profileData.Profile = profile;
            this.messenger.Send(new ProfileUpdatedMessage(this.Profile));

            this.LastDateChecked             = DateTime.UtcNow;
            this.profileData.LastDateChecked = this.LastDateChecked;

            await this.SaveAsync();
        }
        private async Task <MVPProfile> TestApiEndpointAsync()
        {
            MVPProfile profile = null;

            try
            {
                profile = await this.apiClient.GetMyProfileAsync();
            }
            catch (Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(ex.ToString());
#endif
            }

            return(profile);
        }
        public async Task ClearAsync()
        {
            await this.LoadAsync();

            if (this.profileData == null)
            {
                this.profileData = new ProfileDataContainerWrapper();
            }

            this.profileData.Account      = null;
            this.profileData.Profile      = null;
            this.profileData.ProfileImage = string.Empty;

            this.LastDateChecked             = DateTime.MinValue;
            this.profileData.LastDateChecked = this.LastDateChecked;

            await this.SaveAsync();
        }
        private static async Task TestProfileAsync()
        {
            try
            {
                MVPProfile profile = await App.API.GetMyProfileAsync();
            }
            catch (Exception ex)
            {
                await App.MessageDialogManager.ShowAsync("Error", $"Error in GetMyProfileAsync method. Error: {ex}");

                return;
            }

            try
            {
                MVPProfile profile = await App.API.GetProfileAsync("5001534");
            }
            catch (Exception ex)
            {
                await App.MessageDialogManager.ShowAsync("Error", $"Error in GetProfileAsync method. Error: {ex}");

                return;
            }

            try
            {
                string profileImage = await App.API.GetMyProfileImageAsync();
            }
            catch (Exception ex)
            {
                await App.MessageDialogManager.ShowAsync(
                    "Error",
                    $"Error in GetMyProfileImageAsync method. Error: {ex}");

                return;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProfileUpdatedMessage"/> class.
 /// </summary>
 /// <param name="profile">
 /// The user's updated MVP profile.
 /// </param>
 public ProfileUpdatedMessage(MVPProfile profile)
 {
     this.Profile = profile;
 }
        /// <inheritdoc />
        public async Task UpdateAsync(bool forceUpdate)
        {
            await this.LoadAsync();

#if WINDOWS_UWP
            if (!NetworkStatusManager.Current.IsConnected())
            {
                return;
            }
#elif ANDROID
            // Check network connectivity
#endif

            if (this.LastDateChecked < DateTime.UtcNow - this.TimeBetweenUpdates || forceUpdate)
            {
                MVPProfile profile      = null;
                string     profileImage = string.Empty;

                bool isAuthenticated = true;

                try
                {
                    profile = await this.client.GetMyProfileAsync();

                    profileImage = await this.client.GetMyProfileImageAsync();
                }
                catch (HttpRequestException hre) when(hre.Message.Contains("401"))
                {
                    isAuthenticated = false;
                }
                catch (Exception ex)
                {
#if WINDOWS_UWP
                    EventLogger.Current.WriteError(ex.ToString());
#endif
                }

                if (!isAuthenticated)
                {
#if WINDOWS_UWP
                    await MessageDialogManager.Current.ShowAsync(
                        "Not authorized",
                        "You are no longer authenticated.",
                        new UICommand(
                            "Ok",
                            async command =>
                    {
                        await this.client.LogOutAsync();
                    }));

                    Application.Current.Exit();
#endif
                    return;
                }

                if (profile != null || !string.IsNullOrWhiteSpace(profileImage))
                {
                    if (this.profileData == null)
                    {
                        this.profileData = new ProfileDataContainerWrapper();
                    }

                    this.LastDateChecked = DateTime.UtcNow;

                    this.profileData.Profile      = profile;
                    this.profileData.ProfileImage = profileImage;

                    await this.SaveAsync();
                }

                this.messenger?.Send(new ProfileUpdatedMessage(this.Profile));

                await this.SaveAsync();
            }
        }