public async Task DownloadTrack(string name) { var responseStream = await MakeRequest(NotesliderServer + name); MemoryStream memoryStream = new MemoryStream(); await responseStream.CopyToAsync(memoryStream); string path = $"{Paths.Library}/{name}.ns"; FileStream file = File.Create(path); byte[] bytes = memoryStream.ToArray(); file.Write(bytes, 0, bytes.Length); file.Close(); InfoDialog.ShowMessageDialog("Downloading complete."); }
private void LoadTrack(int i) { try { var track = Track.ReadTrack(tracks[i].Path); TrackRenderer tr = new TrackRenderer(track); Program.MainWindow.SetTrackRenderer(tr); tr.Render(); Program.MainWindow.MWInfoTitle.Content = track.TrackInfo.Name; Program.MainWindow.MWInfoAuthor.Content = track.TrackInfo.Author; Program.MainWindow.MWInfoImage.Source = (track.TrackInfo.Image != null && track.TrackInfo.ImageLen > 0) ? (BitmapSource) new ImageSourceConverter().ConvertFrom(track.TrackInfo.Image) : ResourceHelper.LoadBitmapFromResource("Resources/Default.png"); // set slider value EventAgregator.Instance.Publish(new MWSliderValChangedEvt(track.TrackInfo.SliderValue)); } catch (ForUserException e) { InfoDialog.ShowMessageDialog(e.Message); } }
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); } }
public void ShowGUIMessage() { InfoDialog.ShowMessageDialog(Message); }