本文整理汇总了C#中System.Net.Http.HttpResponseMessage.ToTask方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponseMessage.ToTask方法的具体用法?C# HttpResponseMessage.ToTask怎么用?C# HttpResponseMessage.ToTask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpResponseMessage
的用法示例。
在下文中一共展示了HttpResponseMessage.ToTask方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddOrUpdate
public void AddOrUpdate(CacheKey key, HttpResponseMessage response)
{
var memoryStream = new MemoryStream();
Task.Factory.StartNew(() => _serializer.SerializeAsync(response.ToTask(), memoryStream).Wait()).Wait(); // offloading
memoryStream.Position = 0;
var data = memoryStream.ToArray();
_database.StringSet(key.HashBase64, data);
}
示例2: AddOrUpdate
/// <summary>
/// Adds or updates an item in the store
/// ------------------------------------
///
/// Steps:
/// 1) Add the item
/// 2) Update domain-specific sizes
/// 3) Update total size
/// 4) Add to last accessed in domain set
/// 5) Add to general lasst accessed set
/// 6) Add domain (if not exists)
/// </summary>
/// <param name="key"></param>
/// <param name="response"></param>
public void AddOrUpdate(CacheKey key, HttpResponseMessage response)
{
var memoryStream = new MemoryStream();
int length = 0;
// step 1
_serializer.SerializeAsync(response.ToTask(), memoryStream)
.Then(() =>
{
var bytes = memoryStream.ToArray();
length = bytes.Length;
var dictionary = new Dictionary<string, byte[]>();
dictionary.Add(Fields.Response, bytes);
dictionary.Add(Fields.Size, BitConverter.GetBytes(length));
dictionary.Add(Fields.Domain, Encoding.UTF8.GetBytes(key.Domain));
return _connection.Hashes.Set(_databaseId,
key.Hash.ToBase64(), dictionary);
})
.Wait();
// setp 2
_connection.Strings.Increment(_databaseId, KeyNames.DomainPrefix + key.Domain, length)
.Wait();
// step 3
_connection.Strings.Increment(_databaseId, KeyNames.GlobalSize, length)
.Wait();
// setp 4
_connection.SortedSets.Add(_databaseId, KeyNames.DomainEarliestAccessedPrefix + key.Domain,
key.Hash, DateTime.Now.ToBinary()).Wait();
// step 5
_connection.SortedSets.Add(_databaseId, KeyNames.EarliestAccessed,
key.Hash, DateTime.Now.ToBinary()).Wait();
// setp 6
_connection.Sets.Add(_databaseId, KeyNames.DomainList, key.Domain);
}