Exemple #1
0
        private async Task <RenamePlaylistResult> RenameStaticPlaylistAsync(PlaylistViewModel playlistToRename, string newPlaylistName)
        {
            string oldFilename = playlistToRename.Path;

            if (!System.IO.File.Exists(oldFilename))
            {
                LogClient.Error("Error while renaming playlist. The playlist '{0}' could not be found", playlistToRename.Path);
                return(RenamePlaylistResult.Error);
            }

            string sanitizedNewPlaylistName = FileUtils.SanitizeFilename(newPlaylistName);
            string newFilename = this.CreatePlaylistFilePath(sanitizedNewPlaylistName, PlaylistType.Static);

            if (System.IO.File.Exists(newFilename))
            {
                return(RenamePlaylistResult.Duplicate);
            }

            RenamePlaylistResult result = RenamePlaylistResult.Success;

            await Task.Run(() =>
            {
                try
                {
                    System.IO.File.Move(oldFilename, newFilename);
                }
                catch (Exception ex)
                {
                    LogClient.Error("Error while renaming playlist '{0}' to '{1}'. Exception: {2}", playlistToRename.Name, newPlaylistName, ex.Message);
                    result = RenamePlaylistResult.Error;
                }
            });

            return(result);
        }
Exemple #2
0
        private async Task <RenamePlaylistResult> RenameSmartPlaylistAsync(PlaylistViewModel playlistToRename, string newPlaylistName)
        {
            IList <PlaylistViewModel> existingSmartPlaylists = await this.GetSmartPlaylistsAsync();

            if (existingSmartPlaylists.Any(x => x.Name.ToLower().Equals(newPlaylistName.ToLower())))
            {
                return(RenamePlaylistResult.Duplicate);
            }

            RenamePlaylistResult result = RenamePlaylistResult.Success;

            await Task.Run(() =>
            {
                try
                {
                    this.SetSmartPlaylistNameIfDifferent(playlistToRename.Path, newPlaylistName);
                }
                catch (Exception ex)
                {
                    LogClient.Error("Error while renaming playlist '{0}' to '{1}'. Exception: {2}", playlistToRename.Name, newPlaylistName, ex.Message);
                    result = RenamePlaylistResult.Error;
                }
            });

            return(result);
        }
        public override async Task <RenamePlaylistResult> RenamePlaylistAsync(PlaylistViewModel playlistToRename, string newPlaylistName)
        {
            if (playlistToRename == null)
            {
                LogClient.Error($"{nameof(playlistToRename)} is null");
                return(RenamePlaylistResult.Error);
            }
            if (string.IsNullOrWhiteSpace(newPlaylistName))
            {
                LogClient.Error($"{nameof(newPlaylistName)} is empty");
                return(RenamePlaylistResult.Blank);
            }

            string oldFilename = playlistToRename.Path;

            if (!System.IO.File.Exists(oldFilename))
            {
                LogClient.Error("Error while renaming playlist. The playlist '{0}' could not be found", playlistToRename.Path);
                return(RenamePlaylistResult.Error);
            }

            string sanitizedNewPlaylistName = FileUtils.SanitizeFilename(newPlaylistName);
            string newFilename = this.CreatePlaylistFilename(sanitizedNewPlaylistName);

            if (System.IO.File.Exists(newFilename))
            {
                return(RenamePlaylistResult.Duplicate);
            }

            RenamePlaylistResult result = RenamePlaylistResult.Success;

            this.Watcher.Suspend(); // Stop watching the playlist folder

            await Task.Run(() =>
            {
                try
                {
                    System.IO.File.Move(oldFilename, newFilename);
                }
                catch (Exception ex)
                {
                    LogClient.Error("Error while renaming playlist '{0}' to '{1}'. Exception: {2}", playlistToRename.Name, newPlaylistName, ex.Message);
                    result = RenamePlaylistResult.Error;
                }
            });

            if (result == RenamePlaylistResult.Success)
            {
                this.OnPlaylistRenamed(
                    playlistToRename,
                    new PlaylistViewModel(sanitizedNewPlaylistName, newFilename));
            }

            this.Watcher.Resume(); // Start watching the playlist folder

            return(result);
        }
Exemple #4
0
        public async Task <RenamePlaylistResult> RenamePlaylistAsync(string oldPlaylistName, string newPlaylistName)
        {
            if (string.IsNullOrWhiteSpace(oldPlaylistName))
            {
                LogClient.Error("OldPlaylistName is empty");
                return(RenamePlaylistResult.Error);
            }
            if (string.IsNullOrWhiteSpace(newPlaylistName))
            {
                LogClient.Error("NewPlaylistName is empty");
                return(RenamePlaylistResult.Blank);
            }

            string oldFilename = this.CreatePlaylistFilename(oldPlaylistName);

            if (!System.IO.File.Exists(oldFilename))
            {
                LogClient.Error("Error while renaming playlist. The playlist '{0}' could not be found", oldPlaylistName);
                return(RenamePlaylistResult.Error);
            }

            string sanitizedNewPlaylist = FileUtils.SanitizeFilename(newPlaylistName);
            string newFilename          = this.CreatePlaylistFilename(sanitizedNewPlaylist);

            if (System.IO.File.Exists(newFilename))
            {
                return(RenamePlaylistResult.Duplicate);
            }

            RenamePlaylistResult result = RenamePlaylistResult.Success;

            watcher.EnableRaisingEvents = false; // Stop watching the playlist folder

            await Task.Run(() =>
            {
                try
                {
                    System.IO.File.Move(oldFilename, newFilename);
                }
                catch (Exception ex)
                {
                    LogClient.Error("Error while renaming playlist '{0}' to '{1}'. Exception: {2}", oldPlaylistName, newPlaylistName, ex.Message);
                    result = RenamePlaylistResult.Error;
                }
            });

            if (result == RenamePlaylistResult.Success)
            {
                this.PlaylistRenamed(oldPlaylistName, sanitizedNewPlaylist);
            }

            watcher.EnableRaisingEvents = true; // Start watching the playlist folder

            return(result);
        }
        public async Task <RenamePlaylistResult> RenamePlaylistAsync(string oldPlaylistName, string newPlaylistName)
        {
            RenamePlaylistResult result = await this.playlistRepository.RenamePlaylistAsync(oldPlaylistName, newPlaylistName);

            if (result == RenamePlaylistResult.Success)
            {
                this.PlaylistsChanged(this, new EventArgs());
            }

            return(result);
        }
        private async Task RenamePlaylistAsync(string oldPlaylistName, string newPlaylistName)
        {
            this.IsLoadingPlaylists = true;
            RenamePlaylistResult result = await this.collectionService.RenamePlaylistAsync(oldPlaylistName, newPlaylistName);

            switch (result)
            {
            case RenamePlaylistResult.Success:
                await this.FillListsAsync();

                break;

            case RenamePlaylistResult.Duplicate:
                this.IsLoadingPlaylists = false;
                this.dialogService.ShowNotification(
                    0xe711,
                    16,
                    ResourceUtils.GetStringResource("Language_Already_Exists"),
                    ResourceUtils.GetStringResource("Language_Already_Playlist_With_That_Name").Replace("%playlistname%", "\"" + newPlaylistName + "\""),
                    ResourceUtils.GetStringResource("Language_Ok"),
                    false,
                    string.Empty);
                break;

            case RenamePlaylistResult.Error:
                this.IsLoadingPlaylists = false;
                this.dialogService.ShowNotification(
                    0xe711,
                    16,
                    ResourceUtils.GetStringResource("Language_Error"),
                    ResourceUtils.GetStringResource("Language_Error_Renaming_Playlist"),
                    ResourceUtils.GetStringResource("Language_Ok"),
                    true,
                    ResourceUtils.GetStringResource("Language_Log_File"));
                break;

            case RenamePlaylistResult.Blank:
                this.IsLoadingPlaylists = false;
                this.dialogService.ShowNotification(
                    0xe711,
                    16,
                    ResourceUtils.GetStringResource("Language_Error"),
                    ResourceUtils.GetStringResource("Language_Provide_Playlist_Name"),
                    ResourceUtils.GetStringResource("Language_Ok"),
                    false,
                    string.Empty);
                break;

            default:
                // Never happens
                this.IsLoadingPlaylists = false;
                break;
            }
        }
Exemple #7
0
        public async Task <RenamePlaylistResult> RenamePlaylistAsync(string oldPlaylistName, string newPlaylistName)
        {
            RenamePlaylistResult result = RenamePlaylistResult.Success;

            string trimmedOldPlaylistName = oldPlaylistName.Trim();
            string trimmedNewPlaylistName = newPlaylistName.Trim();

            if (string.IsNullOrEmpty(trimmedNewPlaylistName))
            {
                LogClient.Instance.Logger.Info("Could not rename the Playlist {0} because no new playlist name was provided", trimmedOldPlaylistName);
                return(RenamePlaylistResult.Blank);
            }

            await Task.Run(() =>
            {
                try
                {
                    using (var conn = this.factory.GetConnection())
                    {
                        // Check if there is already a playlist with that name
                        var existingPlaylistCount = conn.Query <Playlist>("SELECT * FROM Playlist WHERE TRIM(PlaylistName)=?", trimmedNewPlaylistName).Count();

                        if (existingPlaylistCount == 0)
                        {
                            Playlist playlistToRename = conn.Query <Playlist>("SELECT * FROM Playlist WHERE TRIM(PlaylistName)=?", trimmedOldPlaylistName).ToList().FirstOrDefault();

                            if (playlistToRename != null)
                            {
                                playlistToRename.PlaylistName = trimmedNewPlaylistName;
                                conn.Update(playlistToRename);

                                result = RenamePlaylistResult.Success;
                            }
                            else
                            {
                                LogClient.Instance.Logger.Error("The playlist {0} could not be renamed because it was not found in the database.", trimmedOldPlaylistName);
                                result = RenamePlaylistResult.Error;
                            }
                        }
                        else
                        {
                            result = RenamePlaylistResult.Duplicate;
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogClient.Instance.Logger.Error("Could not connect to the database. Exception: {0}", ex.Message);
                }
            });

            return(result);
        }
        public override async Task <RenamePlaylistResult> RenamePlaylistAsync(PlaylistViewModel playlistToRename, string newPlaylistName)
        {
            if (playlistToRename == null)
            {
                LogClient.Error($"{nameof(playlistToRename)} is null");
                return(RenamePlaylistResult.Error);
            }
            if (string.IsNullOrWhiteSpace(newPlaylistName))
            {
                LogClient.Error($"{nameof(newPlaylistName)} is empty");
                return(RenamePlaylistResult.Blank);
            }

            IList <PlaylistViewModel> existingPlaylists = await this.GetPlaylistsAsync();

            if (existingPlaylists.Any(x => x.Name.ToLower().Equals(newPlaylistName.ToLower())))
            {
                return(RenamePlaylistResult.Duplicate);
            }

            RenamePlaylistResult result = RenamePlaylistResult.Success;

            this.Watcher.Suspend(); // Stop watching the playlist folder

            await Task.Run(() =>
            {
                try
                {
                    this.SetPlaylistNameIfDifferent(playlistToRename.Path, newPlaylistName);
                }
                catch (Exception ex)
                {
                    LogClient.Error("Error while renaming playlist '{0}' to '{1}'. Exception: {2}", playlistToRename.Name, newPlaylistName, ex.Message);
                    result = RenamePlaylistResult.Error;
                }
            });

            if (result == RenamePlaylistResult.Success)
            {
                this.OnPlaylistRenamed(
                    playlistToRename,
                    new PlaylistViewModel(newPlaylistName, playlistToRename.Path));
            }

            this.Watcher.Resume(); // Start watching the playlist folder

            return(result);
        }
        private async Task RenamePlaylistAsync(string oldPlaylist, string newPlaylist)
        {
            RenamePlaylistResult result = await this.playlistService.RenamePlaylistAsync(oldPlaylist, newPlaylist);

            switch (result)
            {
            case RenamePlaylistResult.Duplicate:
                this.dialogService.ShowNotification(
                    0xe711,
                    16,
                    ResourceUtils.GetStringResource("Language_Already_Exists"),
                    ResourceUtils.GetStringResource("Language_Already_Playlist_With_That_Name").Replace("%playlistname%", newPlaylist),
                    ResourceUtils.GetStringResource("Language_Ok"),
                    false,
                    string.Empty);
                break;

            case RenamePlaylistResult.Error:
                this.dialogService.ShowNotification(
                    0xe711,
                    16,
                    ResourceUtils.GetStringResource("Language_Error"),
                    ResourceUtils.GetStringResource("Language_Error_Renaming_Playlist"),
                    ResourceUtils.GetStringResource("Language_Ok"),
                    true,
                    ResourceUtils.GetStringResource("Language_Log_File"));
                break;

            case RenamePlaylistResult.Blank:
                this.dialogService.ShowNotification(
                    0xe711,
                    16,
                    ResourceUtils.GetStringResource("Language_Error"),
                    ResourceUtils.GetStringResource("Language_Provide_Playlist_Name"),
                    ResourceUtils.GetStringResource("Language_Ok"),
                    false,
                    string.Empty);
                break;

            default:
                // Never happens
                break;
            }
        }
Exemple #10
0
        public async Task <RenamePlaylistResult> RenamePlaylistAsync(string oldPlaylist, string newPlaylist)
        {
            string oldFilename = this.CreatePlaylistFilename(oldPlaylist);

            if (!System.IO.File.Exists(oldFilename))
            {
                LogClient.Error("Error while renaming playlist. The playlist '{0}' could not be found", oldPlaylist);
                return(RenamePlaylistResult.Error);
            }

            string sanitizedNewPlaylist = FileUtils.SanitizeFilename(newPlaylist);
            string newFilename          = this.CreatePlaylistFilename(sanitizedNewPlaylist);

            if (System.IO.File.Exists(newFilename))
            {
                return(RenamePlaylistResult.Duplicate);
            }

            RenamePlaylistResult result = RenamePlaylistResult.Success;

            await Task.Run(() =>
            {
                try
                {
                    System.IO.File.Move(oldFilename, newFilename);
                }
                catch (Exception ex)
                {
                    LogClient.Error("Error while renaming playlist '{0}' to '{1}'. Exception: {2}", oldPlaylist, newPlaylist, ex.Message);
                    result = RenamePlaylistResult.Error;
                }
            });

            if (result == RenamePlaylistResult.Success)
            {
                this.PlaylistRenamed(oldPlaylist, sanitizedNewPlaylist);
            }

            return(result);
        }
Exemple #11
0
        public async Task <RenamePlaylistResult> RenamePlaylistAsync(PlaylistViewModel playlistToRename, string newPlaylistName)
        {
            if (playlistToRename == null)
            {
                LogClient.Error($"{nameof(playlistToRename)} is null");
                return(RenamePlaylistResult.Error);
            }
            if (string.IsNullOrWhiteSpace(newPlaylistName))
            {
                LogClient.Error($"{nameof(newPlaylistName)} is empty");
                return(RenamePlaylistResult.Blank);
            }


            this.watcher.Suspend(); // Stop watching the playlist folder

            RenamePlaylistResult result = RenamePlaylistResult.Error;

            if (playlistToRename.Type.Equals(PlaylistType.Static))
            {
                result = await this.RenameStaticPlaylistAsync(playlistToRename, newPlaylistName);
            }
            else if (playlistToRename.Type.Equals(PlaylistType.Smart))
            {
                result = await this.RenameSmartPlaylistAsync(playlistToRename, newPlaylistName);
            }

            this.watcher.Resume(); // Start watching the playlist folder

            if (result == RenamePlaylistResult.Success)
            {
                this.PlaylistFolderChanged(this, new EventArgs());
            }

            return(result);
        }
        private async Task RenameSelectedPlaylistAsync()
        {
            if (!this.IsPlaylistSelected)
            {
                return;
            }

            string oldPlaylistName = this.SelectedPlaylistName;
            string newPlaylistName = oldPlaylistName;

            if (this.dialogService.ShowInputDialog(
                    0xea37,
                    16,
                    ResourceUtils.GetString("Language_Rename_Playlist"),
                    ResourceUtils.GetString("Language_Enter_New_Name_For_Playlist").Replace("{playlistname}", oldPlaylistName),
                    ResourceUtils.GetString("Language_Ok"),
                    ResourceUtils.GetString("Language_Cancel"),
                    ref newPlaylistName))
            {
                RenamePlaylistResult result = await this.playlistService.RenamePlaylistAsync(oldPlaylistName, newPlaylistName);

                switch (result)
                {
                case RenamePlaylistResult.Duplicate:
                    this.dialogService.ShowNotification(
                        0xe711,
                        16,
                        ResourceUtils.GetString("Language_Already_Exists"),
                        ResourceUtils.GetString("Language_Already_Playlist_With_That_Name").Replace("{playlistname}", newPlaylistName),
                        ResourceUtils.GetString("Language_Ok"),
                        false,
                        string.Empty);
                    break;

                case RenamePlaylistResult.Error:
                    this.dialogService.ShowNotification(
                        0xe711,
                        16,
                        ResourceUtils.GetString("Language_Error"),
                        ResourceUtils.GetString("Language_Error_Renaming_Playlist"),
                        ResourceUtils.GetString("Language_Ok"),
                        true,
                        ResourceUtils.GetString("Language_Log_File"));
                    break;

                case RenamePlaylistResult.Blank:
                    this.dialogService.ShowNotification(
                        0xe711,
                        16,
                        ResourceUtils.GetString("Language_Error"),
                        ResourceUtils.GetString("Language_Provide_Playlist_Name"),
                        ResourceUtils.GetString("Language_Ok"),
                        false,
                        string.Empty);
                    break;

                default:
                    // Never happens
                    break;
                }
            }
        }