/// <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;

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

                    profileImage = await this.client.GetMyProfileImageAsync();
                }
                catch (HttpRequestException hre) when(hre.Message.Contains("401"))
                {
                    // Show dialog, unauthorized user detected.
#if WINDOWS_UWP
                    Application.Current.Exit();
#endif
                }
                catch (Exception ex)
                {
#if WINDOWS_UWP
                    EventLogger.Current.WriteError(ex.ToString());
#endif
                }

                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();
            }
        }
        public async Task SetProfileImageAsync(string image)
        {
            await this.LoadAsync();

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

            this.profileData.ProfileImage = image;

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

            await this.SaveAsync();
        }
        public async Task SetAccountAsync(MSACredentials account)
        {
            await this.LoadAsync();

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

            this.profileData.Account = account;

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

            await this.SaveAsync();
        }
        /// <inheritdoc />
        public async Task LoadAsync()
        {
            if (this.profileData != null || this.Loaded)
            {
                return;
            }

            await this.fileAccessSemaphore.WaitAsync();

            this.Loaded = true;

            try
            {
#if WINDOWS_UWP
                var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                    FileName,
                    CreationCollisionOption.OpenIfExists);
#elif ANDROID || iOS
                var file = await AppData.Current.LocalFolder.CreateFileAsync(
                    FileName,
                    FileStoreCreationOption.OpenIfExists);
#endif

                this.profileData = await file.GetDataAsync <ProfileDataContainerWrapper>();
            }
            catch (Exception ex)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(ex.ToString());
#endif
            }
            finally
            {
                this.fileAccessSemaphore.Release();
            }

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

                await this.SaveAsync();
            }

            this.LastDateChecked = this.profileData.LastDateChecked;
        }
        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();
        }
        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();
        }
        /// <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();
            }
        }