Ejemplo n.º 1
0
        public async Task <bool> ChangeNameAsync(UserPlaylist playlist, string name)
        {
            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Changing name for playlist with Id '{0}' to '{1}'.", playlist.ProviderPlaylistId, name);
            }

            bool result = await this.webService.ChangeNameAsync(playlist.ProviderPlaylistId, name);

            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("The result of name changing for playlist with id '{0}' is '{1}'.", playlist.ProviderPlaylistId, result);
            }

            if (result)
            {
                playlist.Title     = name;
                playlist.TitleNorm = name.Normalize();
                await this.repository.UpdateAsync(playlist);

                this.eventAggregator.Publish(PlaylistsChangeEvent.New(PlaylistType.UserPlaylist).AddUpdatedPlaylists(playlist));
            }

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <bool> DeleteAsync(IList <Radio> radios)
        {
            var response = await this.radioWebService.DeleteStationsAsync(radios.Select(x => x.Id));

            if (response.MutateResponse != null)
            {
                IList <Radio> deletedRadios = new List <Radio>();
                foreach (var mutateResponse in response.MutateResponse)
                {
                    if (string.Equals(mutateResponse.ResponseCode, "OK", StringComparison.OrdinalIgnoreCase))
                    {
                        Radio radio =
                            radios.FirstOrDefault(r => string.Equals(r.Id, mutateResponse.Id, StringComparison.OrdinalIgnoreCase));
                        if (radio != null)
                        {
                            deletedRadios.Add(radio);
                        }
                    }
                }
                await this.radioStationsRepository.DeleteAsync(deletedRadios);

                this.eventAggregator.Publish(PlaylistsChangeEvent.New(PlaylistType.Radio).AddRemovedPlaylists(deletedRadios.Cast <IPlaylist>().ToArray()));
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        private async void DeleteRadio()
        {
            if (this.DeleteRadioCommand.CanExecute())
            {
                try
                {
                    var yesUiCommand = new UICommand(this.resources.GetString("MessageBox_DeletePlaylistYes"));
                    var noUiCommand  = new UICommand(this.resources.GetString("MessageBox_DeletePlaylistNo"));

                    var playlists = this.BindingModel.SelectedItems.Select(bm => bm.Playlist).ToList();

                    MessageDialog dialog = new MessageDialog(this.resources.GetString("MessageBox_DeleteRadioMessage"));
                    dialog.Commands.Add(yesUiCommand);
                    dialog.Commands.Add(noUiCommand);
                    dialog.DefaultCommandIndex = 0;
                    dialog.CancelCommandIndex  = 1;
                    var command = await dialog.ShowAsync();

                    if (command == yesUiCommand)
                    {
                        this.IsDataLoading = true;

                        await this.radioStationsService.DeleteAsync(playlists.Cast <Radio>().ToList());

                        this.IsDataLoading = false;

                        this.EventAggregator.Publish(PlaylistsChangeEvent.New(PlaylistType.Radio));
                    }
                }
                catch (Exception e)
                {
                    this.Logger.Error(e, "DeleteRadio failed");
                }
            }
        }
Ejemplo n.º 4
0
        public async Task <bool> DeleteAsync(IList <UserPlaylist> playlists)
        {
            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Deleting playlists.");
            }

            List <UserPlaylist> toDelete = new List <UserPlaylist>();

            var resp = await this.webService.DeleteAsync(playlists);

            foreach (var mutation in resp.MutateResponse)
            {
                if (string.Equals(mutation.ResponseCode, "OK", StringComparison.OrdinalIgnoreCase))
                {
                    var playlist =
                        playlists.FirstOrDefault(
                            x => string.Equals(x.Id, mutation.Id, StringComparison.OrdinalIgnoreCase));
                    if (playlist != null)
                    {
                        toDelete.Add(playlist);
                    }
                }
                else
                {
                    this.logger.Debug(
                        "Playlist '{0}' was not deleted from server with response '{1}'.",
                        mutation.Id,
                        mutation.ResponseCode);
                }
            }

            if (toDelete.Count > 0)
            {
                await this.repository.DeleteAsync(toDelete);

                this.eventAggregator.Publish(
                    PlaylistsChangeEvent.New(PlaylistType.UserPlaylist).AddRemovedPlaylists(toDelete.Cast <IPlaylist>().ToArray()));
            }

            return(toDelete.Count > 0);
        }
Ejemplo n.º 5
0
        public async Task <bool> RenameStationAsync(Radio radio, string title)
        {
            var resp = await this.radioWebService.ChangeStationNameAsync(radio, title);

            if (resp != null && resp.MutateResponse != null && resp.MutateResponse.Length == 1)
            {
                if (string.Equals(resp.MutateResponse[0].ResponseCode, "OK", StringComparison.OrdinalIgnoreCase))
                {
                    radio.Title     = title;
                    radio.TitleNorm = title.Normalize();

                    await this.radioStationsRepository.UpdateAsync(new[] { radio });

                    this.eventAggregator.Publish(PlaylistsChangeEvent.New(PlaylistType.Radio).AddUpdatedPlaylists(radio));
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        public async Task <UserPlaylist> CreateAsync(string name)
        {
            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Creating playlist '{0}'.", name);
            }

            var resp = await this.webService.CreateAsync(name);

            if (resp.Success.HasValue && !resp.Success.Value)
            {
                if (this.logger.IsDebugEnabled)
                {
                    this.logger.Debug(
                        "Could not create playlist for name '{0}'.", name);
                }

                return(null);
            }
            else
            {
                if (this.logger.IsDebugEnabled)
                {
                    this.logger.Debug(
                        "Playlist was created on the server with id '{0}' for name '{1}'.", resp.Id, name);
                }

                var userPlaylist = new UserPlaylist
                {
                    ProviderPlaylistId = resp.Id,
                    Title     = name,
                    TitleNorm = name.Normalize()
                };

                await this.repository.InsertAsync(userPlaylist);

                this.eventAggregator.Publish(PlaylistsChangeEvent.New(PlaylistType.UserPlaylist).AddAddedPlaylists(userPlaylist));

                return(userPlaylist);
            }
        }
        private async void Save()
        {
            this.isRenaming = true;
            this.SaveCommand.RaiseCanExecuteChanged();

            try
            {
                await this.radioWebService.RenameStationAsync(this.radioPlaylist, this.Title);

                this.EventAggregator.Publish(PlaylistsChangeEvent.New(PlaylistType.Radio));

                this.View.Close();
            }
            catch (Exception e)
            {
                this.Logger.Error(e, "Cannot rename radio station");
            }

            this.isRenaming = false;
            this.SaveCommand.RaiseCanExecuteChanged();
        }
Ejemplo n.º 8
0
        public async Task <UserPlaylist> CreateAsync(string name)
        {
            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Creating playlist '{0}'.", name);
            }

            var resp = await this.webService.CreateAsync(name);

            if (resp != null && resp.MutateResponse != null && resp.MutateResponse.Length == 1 && string.Equals(resp.MutateResponse[0].ResponseCode, "OK", StringComparison.OrdinalIgnoreCase))
            {
                var mutation = resp.MutateResponse[0];

                if (this.logger.IsDebugEnabled)
                {
                    this.logger.Debug("Playlist was created on the server with id '{0}' for name '{1}'.", mutation.Id, name);
                }

                var userPlaylist = new UserPlaylist {
                    PlaylistId = mutation.Id, Title = name, TitleNorm = name.Normalize()
                };

                await this.repository.InsertAsync(new[] { userPlaylist });

                this.eventAggregator.Publish(
                    PlaylistsChangeEvent.New(PlaylistType.UserPlaylist).AddAddedPlaylists(userPlaylist));

                return(userPlaylist);
            }
            else
            {
                if (this.logger.IsDebugEnabled)
                {
                    this.logger.Debug("Could not create playlist for name '{0}'.", name);
                }

                return(null);
            }
        }
Ejemplo n.º 9
0
        public async Task <bool> DeleteAsync(UserPlaylist playlist)
        {
            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Deleting playlist '{0}'.", playlist.ProviderPlaylistId);
            }

            var resp = await this.webService.DeleteAsync(playlist.ProviderPlaylistId);

            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Playlist '{0}' was deleted from server with response '{1}'.", playlist.ProviderPlaylistId, resp);
            }

            if (resp)
            {
                await this.repository.DeleteAsync(playlist);

                this.eventAggregator.Publish(PlaylistsChangeEvent.New(PlaylistType.UserPlaylist).AddRemovedPlaylists(playlist));
            }

            return(resp);
        }
Ejemplo n.º 10
0
        public async Task <bool> ChangeNameAsync(UserPlaylist playlist, string name)
        {
            if (this.logger.IsDebugEnabled)
            {
                this.logger.Debug("Changing name for playlist with Id '{0}' to '{1}'.", playlist.PlaylistId, name);
            }

            var resp = await this.webService.ChangeNameAsync(playlist.PlaylistId, name);

            if (resp != null && resp.MutateResponse != null && resp.MutateResponse.Length == 1 && string.Equals(resp.MutateResponse[0].ResponseCode, "OK", StringComparison.OrdinalIgnoreCase))
            {
                var mutation = resp.MutateResponse[0];

                if (this.logger.IsDebugEnabled)
                {
                    this.logger.Debug("The result of name changing for playlist with id '{0}' is '{1}'", mutation.Id, name);
                }

                playlist.Title     = name;
                playlist.TitleNorm = name.Normalize();

                await this.repository.UpdateAsync(new[] { playlist });

                this.eventAggregator.Publish(PlaylistsChangeEvent.New(PlaylistType.UserPlaylist).AddUpdatedPlaylists(playlist));

                return(true);
            }
            else
            {
                if (this.logger.IsDebugEnabled)
                {
                    this.logger.Debug("Could not change name for playlist '{0}'.", playlist.Id);
                }

                return(false);
            }
        }
Ejemplo n.º 11
0
        private async Task <Tuple <Radio, IList <Song> > > HandleCreationResponse(GoogleMusicMutateResponse response)
        {
            if (response.MutateResponse != null && response.MutateResponse.Length == 1)
            {
                var mutateResponse = response.MutateResponse[0];
                if (string.Equals(mutateResponse.ResponseCode, "OK", StringComparison.OrdinalIgnoreCase) &&
                    mutateResponse.Station != null)
                {
                    var radio = mutateResponse.Station.ToRadio();
                    await this.radioStationsRepository.InsertAsync(new[] { radio });

                    this.eventAggregator.Publish(PlaylistsChangeEvent.New(PlaylistType.Radio).AddAddedPlaylists(radio));
                    IList <Song> tracks = await this.GetSongsAsync(mutateResponse.Station.Tracks);

                    return(Tuple.Create(radio, tracks));
                }
                else
                {
                    this.logger.Error("Could not create radio, because of {0}", mutateResponse.ResponseCode);
                }
            }

            return(null);
        }