mirror of
https://github.com/Sarsoo/IF.Lastfm.git
synced 2024-10-17 15:23:08 +01:00
b249ea7fa8
Using this mean clients don't have to wrap every call in try/catches http://stackoverflow.com/questions/18562613/async-method-returning-taskt-with-generic-constraint-in-c-sharp?noredirect=1#comment27311729_18562613
44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using IF.Lastfm.Core.Api.Helpers;
|
|
|
|
namespace IF.Lastfm.Core.Api.Commands
|
|
{
|
|
public abstract class LastAsyncCommandBase<T> : IAsyncCommand<T> where T : LastResponse, new()
|
|
{
|
|
public string Method { get; protected set; }
|
|
public Uri Url { get; protected set; }
|
|
public IAuth Auth { get; protected set; }
|
|
public int Page { get; set; }
|
|
public int Count { get; set; }
|
|
|
|
protected Dictionary<string, string> Parameters { get; set; }
|
|
|
|
protected LastAsyncCommandBase()
|
|
{
|
|
Parameters = new Dictionary<string, string>();
|
|
}
|
|
|
|
public abstract void SetParameters();
|
|
protected abstract Uri BuildRequestUrl();
|
|
public abstract Task<T> ExecuteAsync();
|
|
public abstract Task<T> HandleResponse(HttpResponseMessage response);
|
|
|
|
protected void AddPagingParameters()
|
|
{
|
|
Parameters.Add("page", Page.ToString());
|
|
Parameters.Add("limit", Count.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Annoying workaround for Windows Phone's caching...
|
|
/// see http://stackoverflow.com/questions/6334788/windows-phone-7-webrequest-caching
|
|
/// </summary>
|
|
protected void DisableCaching()
|
|
{
|
|
Parameters.Add("disablecachetoken", DateTime.UtcNow.Ticks.ToString());
|
|
}
|
|
}
|
|
} |