Exemplo n.º 1
0
 public override Task WriteAsync(object inputObject, Stream targetStream, ILiaraContext context)
 {
     var type = inputObject.GetType();
     if (!ReflectionHelpers.IsTypeAnonymous(type))
     {
         var xmlWriter = new XmlSerializer(type);
         xmlWriter.Serialize(targetStream, inputObject);
     }
     else
     {
         var status = context.Response.Status = LiaraHttpStatus.NotAcceptable;
         var error = new ErrorMessage
         {
             Description = status.Description,
             ErrorCode = status.Code,
             Message = inputObject.ToString()
         };
         var xmlWriter = new XmlSerializer(typeof (ErrorMessage));
         xmlWriter.Serialize(targetStream, error);
     }
     return TaskHelpers.Completed();
 }
Exemplo n.º 2
0
 public override async Task WriteAsync(object inputObject, Stream targetStream, ILiaraContext context)
 {
     var template = ResolveInternalView(context) ?? ResolveView(context);
     if (template.IsInternalTemplate)
     {
         if (inputObject.GetType() != typeof (ErrorMessage))
         {
             inputObject = new ErrorMessage
             {
                 ErrorCode = context.Response.Status.Code,
                 Description = context.Response.Status.Description,
                 Message = inputObject
             };
         }
     }
     var viewOutput = await RenderView(template, inputObject, context);
     var buf = context.Response.Format.CharsetEncoding.GetBytes(viewOutput);
     await targetStream.WriteAsync(buf, 0, buf.Length);
 }