本文整理汇总了C#中System.Net.Http.HttpContent.ReadAsAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContent.ReadAsAsync方法的具体用法?C# HttpContent.ReadAsAsync怎么用?C# HttpContent.ReadAsAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpContent
的用法示例。
在下文中一共展示了HttpContent.ReadAsAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Extract
public static Object Extract( HttpContent content, Type commandType )
{
var read = content.ReadAsAsync( commandType );
read.Wait();
//reset the internal stream position to allow the WebAPI pipeline to read it again.
content.ReadAsStreamAsync()
.ContinueWith( t =>
{
if( t.Result.CanSeek )
{
t.Result.Seek( 0, SeekOrigin.Begin );
}
} )
.Wait();
return read.Result;
}
示例2: GetJobDetailsFromServerResponse
//This code is tightly coupled to Templeton. If parsing fails, we capture the full json payload, the error
//then log it upstream. I've left the constants here, since this is A) The only place they are used and B) there are a lot of them.
//In the future, if we see this being something that is reused, they could be moved.
//For a sample response see the large comment at the end of this file.
internal async Task<JobDetails> GetJobDetailsFromServerResponse(HttpContent content)
{
const string userArgsSection = "userargs";
const string defineSection = "define";
const string statusSection = "status";
const string jobNameKey = "hdInsightJobName=";
const string statusDirectory = "statusdir";
const string exitCodeValue = "exitValue";
const string startTimeValue = "startTime";
const string jobStatusValue = "runState";
const string hiveQueryValue = "execute";
const string outputFile = "/stdout";
const string errorFile = "/stderr";
Contract.AssertArgNotNull(content, "content");
JObject result = null;
try
{
result = await content.ReadAsAsync<JObject>();
Contract.Assert(result != null);
var outputAsvPath = (string)result[userArgsSection][statusDirectory];
var outputFolderUri = GetOutputFolderUri(outputAsvPath);
var defines = result[userArgsSection][defineSection].ToArray();
var jobNameItem = (string)defines.First(s => ((string)s).Contains(jobNameKey));
var jobName = jobNameItem.Split('=')[1];
var details = new JobDetails
{
ExitCode = (int)result[exitCodeValue],
SubmissionTime = result[statusSection][startTimeValue].ToString(),
Name = jobName,
StatusCode = (JobStatusCode)Enum.Parse(typeof(JobStatusCode), result[statusSection][jobStatusValue].ToString()),
PhysicalOutputPath = new Uri(outputFolderUri + outputFile),
LogicalOutputPath = outputAsvPath + outputFile,
ErrorOutputPath = outputFolderUri + errorFile,
Query = (string)result[userArgsSection][hiveQueryValue],
};
return details;
}
catch (Exception ex)
{
var rawJson = string.Empty;
if(result != null)
{
rawJson = result.ToString();
if (rawJson.Length > 4000)
{
//truncating the response if its large then 4000 char, in order to prevent large data in the logs
rawJson = rawJson.Substring(0, 4000);
}
}
throw new HttpParseException(string.Format(JobSubmissionConstants.UnableToParseJobDetailsLogMessage, ex.Message, rawJson));
}
}
示例3: GetJobIdFromServerResponse
//This code is tightly coupled to Templeton. If parsing fails, we capture the full json payload, the error
//then log it upstream.
internal async Task<string> GetJobIdFromServerResponse(HttpContent content)
{
Contract.AssertArgNotNull(content,"content");
try
{
var result = await content.ReadAsAsync<JObject>();
Contract.Assert(result != null);
JToken jobId;
Contract.Assert(result.TryGetValue(JobSubmissionConstants.JobIdPropertyName,out jobId));
Contract.Assert(jobId != null);
return jobId.ToString();
}
catch (Exception ex)
{
throw new HttpParseException(ex.Message);
}
}
示例4: GetJobIdListFromServerResponse
//This code is tightly coupled to Templeton. If parsing fails, we capture the full json payload, the error
//then log it upstream.
internal async Task<List<string>> GetJobIdListFromServerResponse(HttpContent content)
{
Contract.AssertArgNotNull(content, "content");
try
{
var result = await content.ReadAsAsync<JArray>();
if (result == null || !result.HasValues)
{
return new List<string>();
}
var ret = result.Values<string>();
return ret.ToList();
}
catch (Exception ex)
{
throw new HttpParseException(ex.Message);
}
}
示例5: ReadAsAsyncCore
private static async Task<NameValueCollection> ReadAsAsyncCore(HttpContent content, MediaTypeFormatter[] formatters,
CancellationToken cancellationToken)
{
FormDataCollection formData = await content.ReadAsAsync<FormDataCollection>(formatters, cancellationToken);
return formData == null ? null : formData.ReadAsNameValueCollection();
}