Exemplo n.º 1
0
        public async Task <CreateNewPlaylistResult> CreateNewPlaylistAsync(string playlistName, PlaylistType type)
        {
            if (string.IsNullOrWhiteSpace(playlistName))
            {
                return(CreateNewPlaylistResult.Blank);
            }

            string sanitizedPlaylistName = FileUtils.SanitizeFilename(playlistName);
            string filePath = this.CreatePlaylistFilePath(sanitizedPlaylistName, type);

            if (System.IO.File.Exists(filePath))
            {
                return(CreateNewPlaylistResult.Duplicate);
            }

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

            PlaylistViewModel playlistViewModel = null;

            if (type.Equals(PlaylistType.Static))
            {
                playlistViewModel = await this.CreateNewStaticPlaylistAsync(playlistName, filePath);
            }
            else if (type.Equals(PlaylistType.Smart))
            {
                playlistViewModel = await this.CreateNewSmartPlaylistAsync(playlistName, filePath);
            }

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

            if (playlistViewModel == null)
            {
                return(CreateNewPlaylistResult.Error);
            }

            this.PlaylistFolderChanged(this, new EventArgs());

            return(CreateNewPlaylistResult.Success);
        }
Exemplo n.º 2
0
 private string CreatePlaylistFilePath(string sanitizedPlaylistName, PlaylistType type)
 {
     string extension = type.Equals(PlaylistType.Smart) ? FileFormats.DSPL : FileFormats.M3U;
     return Path.Combine(this.PlaylistFolder, sanitizedPlaylistName + extension);
 }