Modified ClientGenerator to support responses as a parameter input. Improved streams support. Bumped package version to 1.4.8
This commit is contained in:
parent
b9e1f2ca7d
commit
6a7f6ce096
@ -215,7 +215,7 @@ namespace MontoyaTech.Rest.Net.Example
|
||||
}
|
||||
|
||||
[RouteGroup("Stream")]
|
||||
[RouteResponse(typeof(MemoryStream))]
|
||||
[RouteResponse(typeof(FileStream), Parameter = true)]
|
||||
public static HttpListenerResponse Download(HttpListenerContext context)
|
||||
{
|
||||
return context.Response.WithStatus(HttpStatusCode.OK).WithText("Hello world");
|
||||
|
@ -17,7 +17,7 @@
|
||||
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
|
||||
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<Version>1.4.7</Version>
|
||||
<Version>1.4.8</Version>
|
||||
<PackageReleaseNotes></PackageReleaseNotes>
|
||||
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
|
||||
</PropertyGroup>
|
||||
|
@ -342,6 +342,12 @@ namespace MontoyaTech.Rest.Net
|
||||
writer.Write(this.GetTypeFullyResolvedName(routeRequest.RequestType)).Write(" request");
|
||||
}
|
||||
|
||||
if (routeResponse != null && routeResponse.Parameter)
|
||||
{
|
||||
writer.WriteSeparator();
|
||||
writer.Write(this.GetTypeFullyResolvedName(routeResponse.ResponseType)).Write(" input");
|
||||
}
|
||||
|
||||
writer.WriteLine(")").WriteLine("{").Indent();
|
||||
|
||||
//Generate the message code
|
||||
@ -433,24 +439,31 @@ namespace MontoyaTech.Rest.Net
|
||||
|
||||
//Generate the response code
|
||||
if (this.StaticCode)
|
||||
writer.WriteBreak().WriteLine($"var response = {this.ClientName}.HttpClient.Send(message);");
|
||||
writer.WriteBreak().WriteLine($"var response = {this.ClientName}.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);");
|
||||
else
|
||||
writer.WriteBreak().WriteLine("var response = this.Client.HttpClient.Send(message);");
|
||||
writer.WriteBreak().WriteLine("var response = this.Client.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);");
|
||||
|
||||
//Handle the response
|
||||
if (routeResponse != null)
|
||||
{
|
||||
writer.WriteBreak().WriteLine("if (response.IsSuccessStatusCode)").WriteLine("{").Indent();
|
||||
|
||||
if (routeResponse.ResponseType.IsEquivalentTo(typeof(MemoryStream)))
|
||||
if (routeResponse.ResponseType.IsAssignableTo(typeof(Stream)))
|
||||
{
|
||||
writer.WriteBreak().WriteLine($"var stream = new {this.GetTypeFullyResolvedName(routeResponse.ResponseType)}();");
|
||||
if (routeResponse.Parameter)
|
||||
{
|
||||
writer.WriteBreak().WriteLine("response.Content.CopyToAsync(input).GetAwaiter().GetResult();");
|
||||
|
||||
writer.WriteBreak().WriteLine("response.Content.ReadAsStream().CopyTo(stream);");
|
||||
writer.WriteBreak().WriteLine("return input;");
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteBreak().WriteLine($"var stream = new {this.GetTypeFullyResolvedName(routeResponse.ResponseType)}();");
|
||||
|
||||
writer.WriteBreak().WriteLine("stream.Seek(0, System.IO.SeekOrigin.Begin);");
|
||||
writer.WriteBreak().WriteLine("response.Content.CopyToAsync(stream).GetAwaiter().GetResult();");
|
||||
|
||||
writer.WriteBreak().WriteLine("return stream;");
|
||||
writer.WriteBreak().WriteLine("return stream;");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -22,6 +22,11 @@ namespace MontoyaTech.Rest.Net
|
||||
/// </summary>
|
||||
public bool Json = true;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the response is passed as a parameter to the route function.
|
||||
/// </summary>
|
||||
public bool Parameter = false;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a default route response.
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user