private async Task AddPlaylistAsync(string playlistName)
        {
            this.IsLoadingPlaylists = true;

            AddPlaylistResult result = await this.collectionService.AddPlaylistAsync(playlistName);

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

                break;

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

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

            case AddPlaylistResult.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;
            }
        }
Exemplo n.º 2
0
        public async Task <AddPlaylistResult> AddPlaylistAsync(string playlistName)
        {
            AddPlaylistResult result = await this.playlistRepository.AddPlaylistAsync(playlistName);

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

            return(result);
        }
Exemplo n.º 3
0
        public async Task <OpenPlaylistResult> OpenPlaylistAsync(string fileName)
        {
            string playlistName = String.Empty;
            var    paths        = new List <String>();

            // Decode the playlist file
            // ------------------------
            var decoder = new PlaylistDecoder();
            DecodePlaylistResult decodeResult = null;

            await Task.Run(() => decodeResult = decoder.DecodePlaylist(fileName));

            if (!decodeResult.DecodeResult.Result)
            {
                LogClient.Instance.Logger.Error("Error while decoding playlist file. Exception: {0}", decodeResult.DecodeResult.GetMessages());
                return(OpenPlaylistResult.Error);
            }

            // Set the paths
            // -------------
            paths = decodeResult.Paths;


            // Get a unique name for the playlist
            // ----------------------------------
            playlistName = await this.playlistRepository.GetUniquePlaylistNameAsync(decodeResult.PlaylistName);

            // Add the Playlist to the database
            // --------------------------------
            AddPlaylistResult addPlaylistResult = await this.playlistRepository.AddPlaylistAsync(playlistName);

            if (addPlaylistResult != AddPlaylistResult.Success)
            {
                return(OpenPlaylistResult.Error);
            }

            // Add TrackInfo's to the Playlist
            // -------------------------------
            List <TrackInfo> tracks = await this.trackRepository.GetTracksAsync(paths);

            AddToPlaylistResult result = await this.playlistRepository.AddTracksToPlaylistAsync(tracks, playlistName);

            if (!result.IsSuccess)
            {
                return(OpenPlaylistResult.Error);
            }

            // If we arrive at this point, OpenPlaylistResult = OpenPlaylistResult.Success,
            // so we can always raise the PlaylistsChanged Event.
            this.PlaylistsChanged(this, new EventArgs());

            return(OpenPlaylistResult.Success);
        }
Exemplo n.º 4
0
        public async Task <AddPlaylistResult> AddPlaylistAsync(string playlistName)
        {
            AddPlaylistResult result = AddPlaylistResult.Success;

            string trimmedPlaylistName = playlistName.Trim();

            if (string.IsNullOrEmpty(trimmedPlaylistName))
            {
                LogClient.Instance.Logger.Info("Could not add the Playlist because no playlist name was provided");
                return(AddPlaylistResult.Blank);
            }

            await Task.Run(() =>
            {
                try
                {
                    using (var conn = this.factory.GetConnection())
                    {
                        try
                        {
                            Playlist newPlaylist = new Playlist {
                                PlaylistName = trimmedPlaylistName
                            };
                            var existingPlaylistCount = conn.Query <Playlist>("SELECT * FROM Playlist WHERE TRIM(PlaylistName)=?", newPlaylist.PlaylistName).Count();

                            if (existingPlaylistCount == 0)
                            {
                                conn.Insert(newPlaylist);
                                LogClient.Instance.Logger.Info("Added the Playlist {0}", trimmedPlaylistName);
                            }
                            else
                            {
                                LogClient.Instance.Logger.Info("Didn't add the Playlist {0} because it is already in the database", trimmedPlaylistName);
                                result = AddPlaylistResult.Duplicate;
                            }
                        }
                        catch (Exception ex)
                        {
                            LogClient.Instance.Logger.Error("Could not add the Playlist {0}. Exception: {1}", trimmedPlaylistName, ex.Message);
                            result = AddPlaylistResult.Error;
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogClient.Instance.Logger.Error("Could not connect to the database. Exception: {0}", ex.Message);
                }
            });

            return(result);
        }
        private async Task AddPlaylistAsync(string playlistName)
        {
            AddPlaylistResult result = await this.playlistService.AddPlaylistAsync(playlistName);

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

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

            case AddPlaylistResult.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;
            }
        }
Exemplo n.º 6
0
        public async Task <AddPlaylistResult> AddPlaylistAsync(string playlistName)
        {
            if (string.IsNullOrWhiteSpace(playlistName))
            {
                return(AddPlaylistResult.Blank);
            }

            string sanitizedPlaylistName = FileUtils.SanitizeFilename(playlistName);
            string filename = this.CreatePlaylistFilename(sanitizedPlaylistName);

            if (System.IO.File.Exists(filename))
            {
                return(AddPlaylistResult.Duplicate);
            }

            AddPlaylistResult result = AddPlaylistResult.Success;

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

            await Task.Run(() =>
            {
                try
                {
                    System.IO.File.Create(filename).Close(); // Close() prevents file in use issues
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not create playlist '{0}' with filename '{1}'. Exception: {2}", playlistName, filename, ex.Message);
                    result = AddPlaylistResult.Error;
                }
            });

            if (result == AddPlaylistResult.Success)
            {
                this.PlaylistAdded(sanitizedPlaylistName);
            }

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

            return(result);
        }
Exemplo n.º 7
0
        private async Task AddGenresToPlaylistAsync(IList <string> genres, string playlistName)
        {
            AddPlaylistResult addPlaylistResult = AddPlaylistResult.Success; // Default Success

            // If no playlist is provided, first create one.
            if (playlistName == null)
            {
                var responseText = ResourceUtils.GetString("Language_New_Playlist");

                if (this.dialogService.ShowInputDialog(
                        0xea37,
                        16,
                        ResourceUtils.GetString("Language_New_Playlist"),
                        ResourceUtils.GetString("Language_Enter_Name_For_New_Playlist"),
                        ResourceUtils.GetString("Language_Ok"),
                        ResourceUtils.GetString("Language_Cancel"),
                        ref responseText))
                {
                    playlistName      = responseText;
                    addPlaylistResult = await this.playlistService.AddPlaylistAsync(playlistName);
                }
            }

            // If playlist name is still null, the user clicked cancel on the previous dialog. Stop here.
            if (playlistName == null)
            {
                return;
            }

            // Verify if the playlist was added
            switch (addPlaylistResult)
            {
            case AddPlaylistResult.Success:
            case AddPlaylistResult.Duplicate:
                // Add items to playlist
                AddTracksToPlaylistResult result = await this.playlistService.AddGenresToPlaylistAsync(genres, playlistName);

                if (result == AddTracksToPlaylistResult.Error)
                {
                    this.dialogService.ShowNotification(0xe711, 16, ResourceUtils.GetString("Language_Error"), ResourceUtils.GetString("Language_Error_Adding_Songs_To_Playlist").Replace("{playlistname}", "\"" + playlistName + "\""), ResourceUtils.GetString("Language_Ok"), true, ResourceUtils.GetString("Language_Log_File"));
                }
                break;

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

            case AddPlaylistResult.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;
            }
        }