This commit is contained in:
Anders Liu 2015-03-03 22:17:45 -08:00
Родитель b8545644d5
Коммит b6ebef8f46
3 изменённых файлов: 25 добавлений и 1 удалений

Просмотреть файл

@ -86,6 +86,14 @@ namespace ARMClient.Authentication.Utilities
{ {
response = await client.PutAsync(uri, content); response = await client.PutAsync(uri, content);
} }
else if (String.Equals(verb, "patch", StringComparison.OrdinalIgnoreCase))
{
using (var message = new HttpRequestMessage(new HttpMethod("PATCH"), uri))
{
message.Content = content;
response = await client.SendAsync(message).ConfigureAwait(false);
}
}
else else
{ {
throw new InvalidOperationException(String.Format("Invalid http verb {0}!", verb)); throw new InvalidOperationException(String.Format("Invalid http verb {0}!", verb));

Просмотреть файл

@ -116,7 +116,8 @@ namespace ARMClient
else if (String.Equals(verb, "get", StringComparison.OrdinalIgnoreCase) else if (String.Equals(verb, "get", StringComparison.OrdinalIgnoreCase)
|| String.Equals(verb, "delete", StringComparison.OrdinalIgnoreCase) || String.Equals(verb, "delete", StringComparison.OrdinalIgnoreCase)
|| String.Equals(verb, "put", StringComparison.OrdinalIgnoreCase) || String.Equals(verb, "put", StringComparison.OrdinalIgnoreCase)
|| String.Equals(verb, "post", StringComparison.OrdinalIgnoreCase)) || String.Equals(verb, "post", StringComparison.OrdinalIgnoreCase)
|| String.Equals(verb, "patch", StringComparison.OrdinalIgnoreCase))
{ {
var path = _parameters.Get(1, keyName: "url"); var path = _parameters.Get(1, keyName: "url");
var verbose = _parameters.Get("-verbose", requires: false) != null || Utils.GetDefaultVerbose(); var verbose = _parameters.Get("-verbose", requires: false) != null || Utils.GetDefaultVerbose();

Просмотреть файл

@ -101,6 +101,13 @@ namespace ARMClient.Library
return await httpResponse.Content.ReadAsAsync<T>().ConfigureAwait(false); return await httpResponse.Content.ReadAsAsync<T>().ConfigureAwait(false);
} }
public async Task<T> PatchAsync<T>(params object[] args)
{
var httpResponse = await HttpInvoke("Patch", args).ConfigureAwait(false);
httpResponse.EnsureSuccessStatusCode();
return await httpResponse.Content.ReadAsAsync<T>().ConfigureAwait(false);
}
public async Task<T> DeleteAsync<T>() public async Task<T> DeleteAsync<T>()
{ {
var httpResponse = await HttpInvoke("Delete", Enumerable.Empty<object>().ToArray()).ConfigureAwait(false); var httpResponse = await HttpInvoke("Delete", Enumerable.Empty<object>().ToArray()).ConfigureAwait(false);
@ -182,6 +189,14 @@ namespace ARMClient.Library
{ {
response = await client.PutAsync(uri, new StringContent(payload ?? String.Empty, Encoding.UTF8, Constants.JsonContentType)).ConfigureAwait(false); response = await client.PutAsync(uri, new StringContent(payload ?? String.Empty, Encoding.UTF8, Constants.JsonContentType)).ConfigureAwait(false);
} }
else if (String.Equals(verb, "patch", StringComparison.OrdinalIgnoreCase))
{
using (var message = new HttpRequestMessage(new HttpMethod("PATCH"), uri))
{
message.Content = new StringContent(payload ?? String.Empty, Encoding.UTF8, Constants.JsonContentType);
response = await client.SendAsync(message).ConfigureAwait(false);
}
}
else else
{ {
throw new InvalidOperationException(String.Format("Invalid http verb '{0}'!", verb)); throw new InvalidOperationException(String.Format("Invalid http verb '{0}'!", verb));