Exemple #1
0
        private void MainWindowMenuDeleteButton_Click(object sender, RoutedEventArgs e)
        {
            // EXIT IF
            if (trackRenderer == null)
            {
                return;
            }

            var dialog = InfoDialog.ShowYesNoDialog(
                "Are you sure you want to remove this track from your computer?",
                "Yes (Remove)", "No (Cancel)");

            if (dialog.InfoDialogState == InfoDialogState.YesNoDialogYes)
            {
                // FUNC
                var trackPath = trackRenderer.GetTrack().GetTrackPath();
                if (File.Exists(trackPath))
                {
                    File.Delete(trackPath);
                    CloseTrack();
                    InfoDialog.ShowMessageDialog("Track has been removed successfully.");
                }
            }
        }
        /// <summary>
        /// Collects info from Dialog, creates new track and adds it to library.
        /// </summary>
        public bool CreateTrack()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(NTDAuthor.Text) ||
                    string.IsNullOrWhiteSpace(NTDTitle.Text))
                {
                    throw new NewTrackDialogException("Name and Author cannot be empty.");
                }

                if (!NTDAuthor.Text.IsAlphanumeric() ||
                    !NTDTitle.Text.IsAlphanumeric())
                {
                    throw new NewTrackDialogException(
                              "Name and Author must consist of alphanumeric characters only.");
                }

                var author = NTDAuthor.Text;
                var name   = NTDTitle.Text;

                Track track = new Track(author, name, imgBytes);


                if (NTDAdvancedSlidingSpeedCheckBox.IsChecked == true)
                {
                    NTDAdvancedSlidingSpeedInput.Text =
                        NTDAdvancedSlidingSpeedInput.Text.Replace('.', ',');

                    if (double.TryParse(NTDAdvancedSlidingSpeedInput.Text, out double speed))
                    {
                        if (speed < 0 || speed >= 10)
                        {
                            throw new NewTrackDialogException("Slider speed has to be decimal number between 0 and 10.");
                        }

                        speed = speed.RoundToDecPlaces(2);
                        track.TrackInfo.SliderValue = speed;
                    }
                    else
                    {
                        throw new NewTrackDialogException("Slider speed has to be decimal number between 0 and 10.");
                    }
                }

                // REGISTER
                RegisterAssets(track);


                // PASSWORD ?
                string password = null;
                if (NTDAdvancedPasswordCheckBox.IsChecked == true)
                {
                    password = NTDAdvancedPassword.Text;
                }


                // SAVE TO FILE
                if (NTDAdvancedWriteToCheckBox.IsChecked == true)
                {
                    string dirPath = NTDAdvancedWriteTo.Text;
                    if (Directory.Exists(dirPath))
                    {
                        track.WriteTrack($"{dirPath}/{name}.ns", password);
                    }
                    else
                    {
                        var dialog = InfoDialog.ShowYesNoDialog(string.Format(
                                                                    "Directory {0} does not exists. Do you want to create one?", dirPath),
                                                                "Yes", "No"
                                                                );

                        if (dialog.InfoDialogState == InfoDialogState.YesNoDialogYes)
                        {
                            Directory.CreateDirectory(dirPath);
                            track.WriteTrack($"{dirPath}/{name}.ns", password);
                        }
                        else
                        {
                            throw new NewTrackDialogException("Set path you really want...");
                        }
                    }
                }
                else
                {
                    track.WriteTrack(password);
                }

                // DONE !!!
                if (_modifyMode)
                {
                    InfoDialog.ShowMessageDialog("Track updated successfully.");
                }
                else
                {
                    InfoDialog.ShowMessageDialog("Track created successfully.");
                }

                // TODO EventAgregator.Instance.Publish<> publish new track event
                return(true);
            } catch (ForUserException e)
            {
                e.ShowGUIMessage();
                return(false);
            }
        }