Exemplo n.º 1
0
 private void button4_Click(object sender, EventArgs e)
 {
     LoadTags.ShowDialog();
     AlbumArt.Image = null;
     textBox3.Text  = "";
     textBox4.Text  = "";
     textBox5.Text  = "";
     try
     {
         if (File.Exists(LoadTags.FileName))
         {
             TagLib.File file = TagLib.File.Create(LoadTags.FileName);
             try { textBox3.Text = file.Tag.Title; } catch { }
             try { textBox4.Text = file.Tag.Performers[0]; } catch { }
             try { textBox5.Text = file.Tag.Album; } catch { }
             try { MemoryStream ms = new MemoryStream(file.Tag.Pictures[0].Data.Data); AlbumArt.Image = System.Drawing.Image.FromStream(ms); } catch { }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Something went wrong." + Environment.NewLine + "--------------------------------------" + Environment.NewLine + ex, "kPanel - MP3 Dumper", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 2
0
        public TagsViewModel(QDMSClient.QDMSClient client, IDialogCoordinator dialogCoordinator)
        {
            _client            = client;
            _dialogCoordinator = dialogCoordinator;
            Tags = new ObservableCollection <TagViewModel>();

            //Load all tags from db
            LoadTags = ReactiveCommand.CreateFromTask(async _ => await _client.GetTags().ConfigureAwait(true));
            LoadTags.Subscribe(async result =>
            {
                if (!result.WasSuccessful)
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Error", string.Join("\n", result.Errors)).ConfigureAwait(true);
                    return;
                }

                foreach (var tag in result.Result)
                {
                    Tags.Add(new TagViewModel(tag));
                }
            });

            //Add new tag
            Add = ReactiveCommand.CreateFromTask(async _ =>
            {
                var tag     = await client.AddTag(NewTag.Model).ConfigureAwait(true);
                NewTag.Name = "";
                return(tag);
            });

            Add.Subscribe(async result =>
            {
                if (!result.WasSuccessful)
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Error", string.Join("\n", result.Errors)).ConfigureAwait(true);
                    return;
                }
                Tags.Add(new TagViewModel(result.Result));
            });

            //When changing the selected tag, reset the delete confirmation
            this.WhenAnyValue(x => x.SelectedTag)
            .Buffer(1, 1)
            .Subscribe(x => { var tagVm = x.FirstOrDefault(); if (tagVm != null)
                              {
                                  tagVm.ConfirmDelete = false;
                              }
                       });

            //Delete Tag
            Delete = ReactiveCommand.CreateFromTask(async _ =>
            {
                if (SelectedTag == null)
                {
                    return(null);
                }

                if (SelectedTag.ConfirmDelete != true)
                {
                    SelectedTag.ConfirmDelete = true;
                    return(null);
                }

                return(await client.DeleteTag(SelectedTag?.Model).ConfigureAwait(true));
            });
            Delete.Subscribe(async result =>
            {
                if (result == null)
                {
                    return;
                }
                if (!result.WasSuccessful)
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Error", string.Join("\n", result.Errors)).ConfigureAwait(true);
                    return;
                }

                Tags.Remove(Tags.FirstOrDefault(x => x.Model.ID == result.Result.ID));
            });

            //Update Tag
            Save = ReactiveCommand.CreateFromTask(async _ => await client.UpdateTag(SelectedTag?.Model).ConfigureAwait(true));
            Save.Subscribe(async result =>
            {
                if (!result.WasSuccessful)
                {
                    await _dialogCoordinator.ShowMessageAsync(this, "Error", string.Join("\n", result.Errors)).ConfigureAwait(true);
                }
            });
        }