Exemplo n.º 1
0
        private async void ShowUpdateMessage(
            UserPlaylistsUpdateStatus userPlaylistsUpdateStatus, SongsUpdateStatus songsUpdateStatus)
        {
            if ((userPlaylistsUpdateStatus != null &&
                 (userPlaylistsUpdateStatus.DeletedPlaylists + userPlaylistsUpdateStatus.UpdatedPlaylists + userPlaylistsUpdateStatus.NewPlaylists) > 0) ||
                (songsUpdateStatus != null &&
                 (songsUpdateStatus.DeletedSongs + songsUpdateStatus.UpdatedSongs + songsUpdateStatus.NewSongs) > 0))
            {
                var dialog = new MessageDialog(this.resources.GetString("Update_MessageBox_Updates_Message"));
                dialog.Commands.Add(
                    new UICommand(
                        this.resources.GetString("Update_MessageBox_Updates_OkButton"),
                        (cmd) =>
                {
                    this.navigationService.ClearHistory();
                    this.navigationService.RefreshCurrentView();
                }));

                dialog.Commands.Add(new UICommand(this.resources.GetString("Update_MessageBox_Updates_CancelButton")));

                try
                {
                    await dialog.ShowAsync().AsTask();
                }
                catch (Exception e)
                {
                    this.Logger.Error(e, "Could not show message dialog: ShowUpdateMessage");
                }
            }
        }
Exemplo n.º 2
0
        private async Task Synchronize(bool forceToDownloadPlaylists = false)
        {
            SongsUpdateStatus         songsUpdateStatus         = null;
            UserPlaylistsUpdateStatus userPlaylistsUpdateStatus = null;

            await this.dispatcher.RunAsync(() => this.synchronizationTimer.Stop());

            if (this.stateService.IsOnline() && !this.isDownloading)
            {
                await this.dispatcher.RunAsync(
                    () =>
                {
                    if (this.stateService.IsOnline())
                    {
                        this.disableClickToCache           = true;
                        this.BindingModel.ShowProgressRing = true;
                        this.BindingModel.MessageText      = this.resources.GetString("LinksRegion_UpdatingSongs");
                        this.UpdateLibraryCommand.RaiseCanExecuteChanged();
                    }
                });

                bool error = false;

                try
                {
                    songsUpdateStatus = await this.googleMusicSynchronizationService.UpdateSongsAsync();

                    if (this.synchronizationTime == 0 || forceToDownloadPlaylists)
                    {
                        await this.dispatcher.RunAsync(() => { this.BindingModel.MessageText = this.resources.GetString("LinksRegion_UpdatingPlaylists"); });

                        userPlaylistsUpdateStatus = await this.googleMusicSynchronizationService.UpdateUserPlaylistsAsync();
                    }
                }
                catch (Exception e)
                {
                    this.Logger.Error(e, "Exception while update user playlist.");
                    error = true;
                }

                await this.dispatcher.RunAsync(
                    () =>
                {
                    this.disableClickToCache = false;

                    if (this.stateService.IsOnline())
                    {
                        this.BindingModel.ShowProgressRing = false;
                        this.BindingModel.MessageText      = error ? this.resources.GetString("LinksRegion_FailedToUpdate") : this.resources.GetString("LinksRegion_Updated");
                    }
                });

                this.ShowUpdateMessage(userPlaylistsUpdateStatus, songsUpdateStatus);

                await Task.Delay(TimeSpan.FromSeconds(2));
            }

            await this.dispatcher.RunAsync(
                () =>
            {
                this.synchronizationTime++;
                if (forceToDownloadPlaylists)
                {
                    this.synchronizationTime = 1;
                }
                else if (this.synchronizationTime >= 6)
                {
                    this.synchronizationTime = 0;
                }

                this.synchronizationTimer.Start();
                this.SetOfflineMessageIfRequired();
                this.UpdateLibraryCommand.RaiseCanExecuteChanged();
            });
        }