Skip to content

Commit

Permalink
fixed a whole bunch of stuff (probably caused by bad merger) relating…
Browse files Browse the repository at this point in the history
… to the C# generator
  • Loading branch information
faniereynders committed Jan 19, 2016
1 parent 66b62aa commit 267993c
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 185 deletions.
2 changes: 1 addition & 1 deletion WebApiProxy.Tasks/Infrastructure/CSharpGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private Metadata GetProxy()
}
catch (Exception ex)
{
throw new ConnectionException(config.Endpoint);
throw ex;
}
}
}
Expand Down
29 changes: 22 additions & 7 deletions WebApiProxy.Tasks/Models/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Configuration
private string _name = "MyWebApiProxy";
private bool _generateOnBuild = false;
private string _namespace = "WebApi.Proxies";
private bool _generateAsyncReturnTypes = false;

[XmlAttribute("generateOnBuild")]
public bool GenerateOnBuild
Expand Down Expand Up @@ -79,10 +80,20 @@ public string Name
public string Endpoint { get; set; }

[XmlAttribute("generateAsyncReturnTypes")]
public bool GenerateAsyncReturnTypes { get; set; }
public bool GenerateAsyncReturnTypes
{
get
{
return _generateAsyncReturnTypes;
}
set
{
_generateAsyncReturnTypes = value;
}
}

[XmlAttribute("host")]
public string Host { get; set; }
//[XmlAttribute("host")]
//public string Host { get; set; }

[XmlIgnore]
public Metadata Metadata { get; set; }
Expand All @@ -91,17 +102,21 @@ public static Configuration Load(string root)
{
var fileName = root + Configuration.ConfigFileName;

if (!File.Exists(fileName))
throw new ConfigFileNotFoundException(fileName);
if (!File.Exists(fileName))
{
throw new ConfigFileNotFoundException(fileName);
}

var xml = File.ReadAllText(fileName);
var serializer = new XmlSerializer(typeof(Configuration), new XmlRootAttribute("proxy"));
var reader = new StreamReader(fileName);
var config = (Configuration)serializer.Deserialize(reader);
reader.Close();

if (string.IsNullOrEmpty(config.Host))
config.Host = config.Metadata.Host;
//if (string.IsNullOrEmpty(config.Host))
//{
// config.Host = config.Metadata.Host;
//}

return config;

Expand Down
347 changes: 183 additions & 164 deletions WebApiProxy.Tasks/Templates/CSharpProxyTemplate.cs

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions WebApiProxy.Tasks/Templates/CSharpProxyTemplate.tt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace <#= Configuration.Namespace#>
/// <summary>
/// Web Api Base Address.
/// </summary>
public static string <#= Configuration.Name #>BaseAddress = "<#= Configuration.Host #>";
public static string <#= Configuration.Name #>BaseAddress = "<#= Configuration.Metadata.Host #>";

}
}
Expand Down Expand Up @@ -316,6 +316,8 @@ namespace <#= Configuration.Namespace#>.Clients
var bodyParameterString = ", default(HttpResponseMessage)";
var parameterNameList = "";

var concreteReturnType = method.ReturnType.ToConcrete();

if (method.BodyParameter != null) {
allParameters = allParameters.Concat(new [] { method.BodyParameter });
bodyParameterString = ", " + method.BodyParameter.Name;
Expand Down Expand Up @@ -344,9 +346,9 @@ namespace <#= Configuration.Namespace#>.Clients
/// <param name="<#= p.Name #>"><#= p.Description.ToSummary() #></param>
<# } #>
/// <returns></returns>
public virtual async Task<HttpResponseMessage> <#= method.Name #>AsyncMsg(<#= parameterList#>)
protected virtual async Task<HttpResponseMessage> <#= method.Name #>AsyncMsg(<#= parameterList#>)
{
return await HttpClient.<#=method.Type.ToTitle()#><#= postOrPut ? "AsJson" : "" #>Async<#= postOrPut && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "" #>(<#=url#><#= postOrPut ? bodyParameterString:""#>);
return await HttpClient.<#=method.Type.ToTitle()#><#= postOrPutOrPatch ? "AsJson" : "" #>Async<#= postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "" #>(<#=url#><#= postOrPutOrPatch ? bodyParameterString:""#>);
}

<# if (Configuration.GenerateAsyncReturnTypes == false || String.IsNullOrEmpty(concreteReturnType)) { #>
Expand All @@ -357,9 +359,9 @@ namespace <#= Configuration.Namespace#>.Clients
/// <param name="<#= p.Name #>"><#= p.Description.ToSummary() #></param>
<# } #>
/// <returns></returns>
public virtual Task<HttpResponseMessage> <#= method.Name #>Async(<#= parameterList#>)
public virtual async Task<HttpResponseMessage> <#= method.Name #>Async(<#= parameterList#>)
{
return await HttpClient.<#=method.Type.ToTitle()#><#= postOrPut ? "AsJson" : "" #>Async<#= postOrPut && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "" #>(<#=url#><#= postOrPut ? bodyParameterString:""#>);
return await HttpClient.<#=method.Type.ToTitle()#><#= postOrPutOrPatch ? "AsJson" : "" #>Async<#= postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "" #>(<#=url#><#= postOrPutOrPatch ? bodyParameterString:""#>);
}

<# } else { #>
Expand All @@ -372,7 +374,7 @@ namespace <#= Configuration.Namespace#>.Clients
/// <returns></returns>
public virtual async Task<<#= concreteReturnType #>> <#= method.Name #>Async(<#= parameterList#>)
{
var result = await HttpClient.<#=method.Type.ToTitle()#><#= postOrPut ? "AsJson" : "" #>Async<#= postOrPut && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "" #>(<#=url#><#= postOrPut ? bodyParameterString:""#>);
var result = await HttpClient.<#=method.Type.ToTitle()#><#= postOrPutOrPatch ? "AsJson" : "" #>Async<#= postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "" #>(<#=url#><#= postOrPutOrPatch ? bodyParameterString:""#>);

EnsureSuccess(result);

Expand Down
2 changes: 2 additions & 0 deletions WebApiProxy.Tasks/WebApiProxy.CSharp.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
</dependencies>
</metadata>
<files>
<file src="bin\$configuration$\Newtonsoft.Json.dll" target="lib\net45" />
<file src="bin\$configuration$\System.Net.Http.Formatting.dll" target="lib\net45" />
<file src="bin\$configuration$\*.dll" target="build" />
<file src="bin\$configuration$\*.targets" target="build" />

Expand Down
8 changes: 3 additions & 5 deletions WebApiProxy.Tasks/WebApiProxy.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
<Reference Include="Microsoft.Build" />
<Reference Include="Microsoft.Build.Framework" />
<Reference Include="Microsoft.Build.Utilities.v4.0" />
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down Expand Up @@ -78,9 +78,7 @@
<None Include="install.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
<None Include="uninstall.ps1">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 1 addition & 1 deletion WebApiProxy.Tasks/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down
2 changes: 1 addition & 1 deletion WebApiProxy.Tasks/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
</packages>

0 comments on commit 267993c

Please sign in to comment.