GetAsync() public method

Lookup a fingerprint using the AcoustID webservice.
public GetAsync ( string fingerprint, int duration ) : Task
fingerprint string The audio fingerprint.
duration int The total duration of the audio.
return Task
Beispiel #1
0
        private void Lookup(string fingerprint, int duration)
        {

            btnFingerprint.IsEnabled = false;

            LookupService service = new LookupService();

            service.GetAsync((results, e) =>
            {
                btnOpen.IsEnabled = true;

                if (e != null)
                {
                    System.Windows.MessageBox.Show(e.Message, "Webservice error");
                    return;
                }

                if (results.Count == 0)
                {
                    if (String.IsNullOrEmpty(service.Error))
                    {
                        System.Windows.MessageBox.Show("No results for given fingerprint.");
                    }
                    else System.Windows.MessageBox.Show(service.Error, "Webservice error");

                    return;
                }

                foreach (var result in results)
                {
                    var li = new AcoustIdItem();
                    li.AcoustId = result.Id;
                    li.Score = result.Score.ToString();
                    li.Recordings = result.Recordings;

                    lvResults.Items.Add(li);

                }
            }, fingerprint, duration, new string[] { "recordings", "compress" });
        }
Beispiel #2
0
        private void Lookup(string fingerprint, int duration)
        {
            btnOpen.Enabled = false;
            btnFingerPrint.Enabled = false;
            btnRequest.Enabled = false;

            LookupService service = new LookupService();

            var context = TaskScheduler.FromCurrentSynchronizationContext();

            var task = service.GetAsync(fingerprint, duration, new string[] { "recordings", "compress" });

            // Error handling:
            task.ContinueWith(t =>
            {
                foreach (var e in t.Exception.InnerExceptions)
                {
                    MessageBox.Show(e.Message, "Webservice error");
                }
            },
            CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, context);

            // On success:
            task.ContinueWith(t =>
            {
                btnOpen.Enabled = true;

                var response = t.Result;

                if (!string.IsNullOrEmpty(response.ErrorMessage))
                {
                    MessageBox.Show(response.ErrorMessage, "Webservice error");
                    return;
                }

                if (response.Results.Count == 0)
                {
                    MessageBox.Show("No results for given fingerprint.");
                    return;
                }

                foreach (var result in response.Results)
                {
                    var item = new ListViewItem(new string[]
                    {
                        result.Id,
                        result.Score.ToString(CultureInfo.InvariantCulture),
                        result.Recordings.Count.ToString()
                    });

                    item.Tag = result.Recordings;

                    listView1.Items.Add(item);
                }
            },
            CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, context);
        }
Beispiel #3
0
        private void Lookup(string fingerprint, int duration)
        {
            btnOpen.Enabled = false;
            btnFingerPrint.Enabled = false;
            btnRequest.Enabled = false;

            LookupService service = new LookupService();

            service.GetAsync((results) =>
            {
                btnOpen.Enabled = true;

                if (results.Count == 0)
                {
                    if (String.IsNullOrEmpty(service.Error))
                    {
                        MessageBox.Show("No results for given fingerprint.");
                    }
                    else MessageBox.Show(service.Error, "Webservice error");

                    return;
                }

                foreach (var result in results)
                {
                    var item = new ListViewItem(new string[]
                    {
                        result.Id,
                        result.Score.ToString(CultureInfo.InvariantCulture),
                        result.Recordings.Count.ToString()
                    });

                    item.Tag = result.Recordings;

                    listView1.Items.Add(item);
                }
            }, fingerprint, duration, new string[] { "recordings", "compress" });
        }