本文整理汇总了C#中IHttpEntity类的典型用法代码示例。如果您正苦于以下问题:C# IHttpEntity类的具体用法?C# IHttpEntity怎么用?C# IHttpEntity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IHttpEntity类属于命名空间,在下文中一共展示了IHttpEntity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteTo
public void WriteTo(object entity, IHttpEntity response, string[] codecParameters)
{
Image image = (Image)entity;
response.ContentType = image.MediaType;
image.Data.Seek(0, SeekOrigin.Begin);
image.Data.WriteTo(response.Stream);
}
示例2: RenderToResponse
private static void RenderToResponse(IHttpEntity response, ISparkView templateBase)
{
Encoding targetEncoding = Encoding.UTF8;
response.ContentType.CharSet = targetEncoding.HeaderName;
TextWriter writer = null;
bool ownsWriter = false;
try
{
if (response is ISupportsTextWriter)
{
writer = ((ISupportsTextWriter) response).TextWriter;
}
else
{
writer = new DeterministicStreamWriter(response.Stream, targetEncoding, StreamActionOnDispose.None);
ownsWriter = true;
}
templateBase.RenderView(writer);
}
finally
{
if (ownsWriter)
writer.Dispose();
}
}
示例3: WriteTo
public void WriteTo(object entity, IHttpEntity response, string[] codecParameters)
{
if (entity == null)
return;
bool isError = (response.Errors.Count > 0);
string status = isError ? "error" : "ok";
var writerSettings = new XmlWriterSettings { OmitXmlDeclaration = true, Encoding = Encoding.UTF8, NamespaceHandling = NamespaceHandling.OmitDuplicates };
using (var xmlTextWriter = XmlWriter.Create(response.Stream, writerSettings)) {
xmlTextWriter.WriteStartDocument();
xmlTextWriter.WriteStartElement("response");
xmlTextWriter.WriteAttributeString("xsi", "noNamespaceSchemaLocation", "", "http://api.7digital.com/1.2/static/7digitalAPI.xsd");
xmlTextWriter.WriteAttributeString("status", status);
xmlTextWriter.WriteAttributeString("version", "1.2");
xmlTextWriter.WriteAttributeString("xmlns", "xsd", "", "http://www.w3.org/2001/XMLSchema");
xmlTextWriter.WriteAttributeString("xmlns", "xsi", "", "http://www.w3.org/2001/XMLSchema-instance");
if (!isError)
OutputEntity(entity, xmlTextWriter);
else
OutputError(response, xmlTextWriter);
xmlTextWriter.WriteEndElement();
}
}
示例4: ReadFrom
public object ReadFrom(IHttpEntity request, IType destinationType, string destinationName)
{
using (var reader = new StreamReader(request.Stream))
{
return JsonPatchDocument.Read(reader);
}
}
示例5: WriteTo
public void WriteTo(object entity, IHttpEntity response, string[] paramneters)
{
if (entity == null)
return;
DataContractJsonSerializer serializer = new DataContractJsonSerializer(entity.GetType());
serializer.WriteObject(response.Stream, entity);
}
示例6: ReadFrom
public object ReadFrom(IHttpEntity request, IType destinationType, string parameterName)
{
if (destinationType.IsAssignableFrom<IEnumerable<IMultipartHttpEntity>>())
{
var multipartReader = new MultipartReader(request.ContentType.Boundary, request.Stream);
return multipartReader.GetParts();
}
if (destinationType.IsAssignableFrom<IDictionary<string, IList<IMultipartHttpEntity>>>())
{
return FormData(request);
}
var binder = BinderLocator.GetBinder(destinationType);
if (binder == null)
{
throw new InvalidOperationException("Cannot find a binder to create the object");
}
binder.Prefixes.Add(parameterName);
bool wasAnyKeyUsed = ReadKeyValues(request).Aggregate(false, (wasUsed, kv) => kv.SetProperty(binder) || wasUsed);
var result = binder.BuildObject();
return wasAnyKeyUsed && result.Successful ? result.Instance : Missing.Value;
}
示例7: ReadFrom
public override object ReadFrom(IHttpEntity request, IType destinationType, string parameterName)
{
if (destinationType.StaticType == null)
throw new InvalidOperationException();
return new XmlSerializer(destinationType.StaticType).Deserialize(request.Stream);
}
示例8: WriteTo
public void WriteTo(object entity, IHttpEntity response, string[] codecParameters)
{
var codecParameterList = new List<string>(codecParameters);
if (!string.IsNullOrEmpty(request.UriName))
codecParameterList.Add(request.UriName);
string templateAddress = GetViewVPath(Configuration, codecParameterList.ToArray());
RenderTemplate(response, templateAddress, entity);
}
示例9: WriteJsonp
private static void WriteJsonp(object entity, IHttpEntity response, string jsonpId)
{
var front = Encoding.UTF8.GetBytes(jsonpId + "(");
response.Stream.Write(front, 0, front.Length);
WriteJson(entity, response);
var back = Encoding.UTF8.GetBytes(")");
response.Stream.Write(back, 0, back.Length);
}
示例10: CheckEntity
void CheckEntity(IHttpEntity entity, MediaType httpContentType, string expectedContent)
{
entity.ContentType
.Matches(httpContentType)
.ShouldBeTrue();
string actualContent = new StreamReader(entity.Stream).ReadToEnd();
actualContent.ShouldBe(expectedContent);
}
示例11: WriteTo
public void WriteTo(object entity, IHttpEntity response, string[] parameters)
{
var entityString = entity.ToString();
var encodedText = Encoding.GetEncoding(EncodingIso88591).GetBytes(entityString);
response.ContentType = new MediaType("text/plain;charset=ISO-8859-1");
response.ContentLength = encodedText.Length;
response.Stream.Write(encodedText, 0, encodedText.Length);
}
示例12: ReadFrom
public object ReadFrom(IHttpEntity request, OpenRasta.TypeSystem.IType destinationType, string destinationName)
{
string text = null;
using (StreamReader r = new StreamReader(request.Stream, Encoding.UTF8))
{
text = r.ReadToEnd();
}
return new Cat { Name = text };
}
示例13: WriteTo
public void WriteTo(object entity, IHttpEntity response, string[] codecParameters)
{
Cat c = (Cat)entity;
using (var writer = new StreamWriter(response.Stream))
{
writer.Write(string.Format("<html><body><p>{0}</p></body></html>", c.Name));
}
}
示例14: WriteTo
public void WriteTo(object entity, IHttpEntity response, string[] codecParameters)
{
Cat c = (Cat)entity;
using (var writer = new StreamWriter(response.Stream))
{
writer.Write(c.Name);
}
}
示例15: ReadFrom
public object ReadFrom(IHttpEntity request, IType destinationType, string paramName)
{
if (destinationType.StaticType == null)
{
throw new InvalidOperationException();
}
return new DataContractJsonSerializer(destinationType.StaticType).ReadObject(request.Stream);
}