Fixed rest of awaits.

This commit is contained in:
Petr Houška 2016-09-08 12:06:24 +02:00
parent a67305cb14
commit 80f58df929
3 changed files with 16 additions and 14 deletions

View File

@ -103,7 +103,9 @@ namespace SpotifyAPI.Local.Models
string url = GetAlbumArtUrl(size);
if (url == "")
return null;
var data = await wc.DownloadDataTaskAsync(url);
var data =
wc.DownloadDataTaskAsync(url);
using (MemoryStream ms = new MemoryStream(data))
{
return (Bitmap)Image.FromStream(ms);
@ -116,7 +118,7 @@ namespace SpotifyAPI.Local.Models
/// </summary>
/// <param name="size">AlbumArtSize (160,320,640)</param>
/// <returns>A byte[], which is the albumart in binary data</returns>
public async Task<byte[]> GetAlbumArtAsByteArrayAsync(AlbumArtSize size)
public Task<byte[]> GetAlbumArtAsByteArrayAsync(AlbumArtSize size)
{
using (WebClient wc = new WebClient())
{
@ -124,7 +126,7 @@ namespace SpotifyAPI.Local.Models
string url = GetAlbumArtUrl(size);
if (url == "")
return null;
return await wc.DownloadDataTaskAsync(url);
return wc.DownloadDataTaskAsync(url);
}
}

View File

@ -24,23 +24,23 @@ namespace SpotifyAPI.Local
internal async void SendPauseRequest()
{
await QueryAsync("remote/pause.json?pause=true", true, true, -1);
await QueryAsync("remote/pause.json?pause=true", true, true, -1).ConfigureAwait(false);
}
internal async void SendPlayRequest()
{
await QueryAsync("remote/pause.json?pause=false", true, true, -1);
await QueryAsync("remote/pause.json?pause=false", true, true, -1).ConfigureAwait(false);
}
internal async void SendPlayRequest(string url, string context = "")
{
// TODO: instead of having an empty context, one way to fix the bug with the playback time beyond the length of a song would be to provide a 1-song context, and it would be fixed.
await QueryAsync($"remote/play.json?uri={url}&context={context}", true, true, -1);
await QueryAsync($"remote/play.json?uri={url}&context={context}", true, true, -1).ConfigureAwait(false);
}
internal async void SendQueueRequest(string url)
{
await QueryAsync("remote/play.json?uri=" + url + "?action=queue", true, true, -1);
await QueryAsync("remote/play.json?uri=" + url + "?action=queue", true, true, -1).ConfigureAwait(false);
}
internal StatusResponse GetNewStatus()
@ -151,7 +151,7 @@ namespace SpotifyAPI.Local
using (var wc = new ExtendedWebClient())
{
if (SpotifyLocalAPI.IsSpotifyRunning())
response = "[ " + await wc.DownloadStringTaskAsync(new Uri(address)) + " ]";
response = "[ " + await wc.DownloadStringTaskAsync(new Uri(address)).ConfigureAwait(false) + " ]";
}
}
catch

View File

@ -57,7 +57,7 @@ namespace SpotifyAPI.Web
Tuple<ResponseInfo, string> response;
try
{
Tuple<ResponseInfo, byte[]> raw = await DownloadRawAsync(url);
Tuple<ResponseInfo, byte[]> raw = await DownloadRawAsync(url).ConfigureAwait(false);
response = new Tuple<ResponseInfo, string>(raw.Item1, raw.Item2.Length > 0 ? _encoding.GetString(raw.Item2) : "{}");
}
catch (WebException e)
@ -91,7 +91,7 @@ namespace SpotifyAPI.Web
webClient.Encoding = _encoding;
webClient.Headers = _webClient.Headers;
byte[] data = await _webClient.DownloadDataTaskAsync(url);
byte[] data = await _webClient.DownloadDataTaskAsync(url).ConfigureAwait(false);
ResponseInfo info = new ResponseInfo()
{
Headers = webClient.ResponseHeaders
@ -108,7 +108,7 @@ namespace SpotifyAPI.Web
public async Task<Tuple<ResponseInfo, T>> DownloadJsonAsync<T>(string url)
{
Tuple<ResponseInfo, string> response = await DownloadAsync(url);
Tuple<ResponseInfo, string> response = await DownloadAsync(url).ConfigureAwait(false);
return new Tuple<ResponseInfo, T>(response.Item1, JsonConvert.DeserializeObject<T>(response.Item2, JsonSettings));
}
@ -138,7 +138,7 @@ namespace SpotifyAPI.Web
Tuple<ResponseInfo, string> response;
try
{
Tuple<ResponseInfo, byte[]> data = await UploadRawAsync(url, body, method);
Tuple<ResponseInfo, byte[]> data = await UploadRawAsync(url, body, method).ConfigureAwait(false);
response = new Tuple<ResponseInfo, string>(data.Item1, data.Item2.Length > 0 ? _encoding.GetString(data.Item2) : "{}");
}
catch (WebException e)
@ -171,7 +171,7 @@ namespace SpotifyAPI.Web
webClient.Proxy = null;
webClient.Encoding = _encoding;
webClient.Headers = _webClient.Headers;
byte[] data = await _webClient.UploadDataTaskAsync(url, method, _encoding.GetBytes(body));
byte[] data = await _webClient.UploadDataTaskAsync(url, method, _encoding.GetBytes(body)).ConfigureAwait(false);
ResponseInfo info = new ResponseInfo
{
Headers = _webClient.ResponseHeaders
@ -188,7 +188,7 @@ namespace SpotifyAPI.Web
public async Task<Tuple<ResponseInfo, T>> UploadJsonAsync<T>(string url, string body, string method)
{
Tuple<ResponseInfo, string> response = await UploadAsync(url, body, method);
Tuple<ResponseInfo, string> response = await UploadAsync(url, body, method).ConfigureAwait(false);
return new Tuple<ResponseInfo, T>(response.Item1, JsonConvert.DeserializeObject<T>(response.Item2, JsonSettings));
}