public DiscogsTrackDataSearch(DiscogsTrackDataSource dataSource, string query, int tracksPerPage, string format) { HasMoreResults = true; Source = dataSource; SearchQuery = query; _perPage = tracksPerPage; _nextPage = 1; _format = format; _results = new List <TrackData>(); InitRoles(); LoadMoreResults(); }
public DiscogsTrackDataSearch(DiscogsTrackDataSource source, Uri releaseUri) { if (source == null) { throw new ArgumentNullException("source"); } if (releaseUri == null) { throw new ArgumentNullException("releaseUri"); } this.SearchQuery = releaseUri.AbsoluteUri; this.HasMoreResults = false; this.Source = source; //Beatport.com URL regex System.Text.RegularExpressions.Regex releaseURIRegex = new System.Text.RegularExpressions.Regex(@"^http://www.discogs.com/(.*)/release/(\d*)$"); var uriMatch = releaseURIRegex.Match(releaseUri.AbsoluteUri); if (uriMatch.Success) { int releaseId = System.Convert.ToInt32(uriMatch.Groups[2].Value); Dictionary <string, dynamic> releaseData = GetReleaseData(releaseId); IEnumerable <TrackData> releaseTracks = ParseReleaseData(releaseData, this.Source.Host); _results = new List <TrackData>(releaseTracks); } else { throw new ArgumentException("Invalid Discogs release URI format", "searchUri"); } }
public Task <bool> BufferAsync(ITrackDataSource source, CancellationToken cancellationToken) { _cancellationToken = cancellationToken; var bufferingCompleted = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); Task.Run(async() => { var output = ArrayPool <byte> .Shared.Rent(38400); try { int read; while (!Stopped && (read = source.Read(output)) > 0) { while (!Stopped && FreeSpace <= read) { bufferingCompleted.TrySetResult(true); await Task.Delay(100, cancellationToken).ConfigureAwait(false); } if (Stopped) { break; } Write(output, read); } } finally { ArrayPool <byte> .Shared.Return(output); bufferingCompleted.TrySetResult(true); } }, cancellationToken); return(bufferingCompleted.Task); }