From a7f2f52d72a8bdb74422e5ff8e2c5c738637fa7d Mon Sep 17 00:00:00 2001 From: onionhammer Date: Fri, 29 Jan 2016 15:05:36 -0600 Subject: [PATCH] - Code cleanup - Properly implement IDisposable interface for ClientBase per CA1063 - Configuration class marked static - Marked tt output as --- WebApiProxy.Tasks/ProxyGenerationTask.cs | 18 +- .../Templates/CSharpProxyTemplate.cs | 331 ++++++++++-------- .../Templates/CSharpProxyTemplate.tt | 42 ++- 3 files changed, 219 insertions(+), 172 deletions(-) diff --git a/WebApiProxy.Tasks/ProxyGenerationTask.cs b/WebApiProxy.Tasks/ProxyGenerationTask.cs index 1469452..33abc77 100644 --- a/WebApiProxy.Tasks/ProxyGenerationTask.cs +++ b/WebApiProxy.Tasks/ProxyGenerationTask.cs @@ -1,13 +1,9 @@ using System; using System.IO; -using System.Net.Http; using Microsoft.Build.Framework; -using WebApiProxy.Core.Models; -using WebApiProxy.Tasks.Templates; -using WebApiProxy.Tasks.Models; -using Microsoft.Build.Evaluation; -using System.Linq; using WebApiProxy.Tasks.Infrastructure; +using WebApiProxy.Tasks.Models; + namespace WebApiProxy.Tasks { public class ProxyGenerationTask : ITask @@ -50,13 +46,10 @@ public bool Execute() { throw ex; } + return true; } - - - - private void tryReadFromCache() { if (!File.Exists(Configuration.CacheFile)) @@ -66,8 +59,5 @@ private void tryReadFromCache() var source = File.ReadAllText(Configuration.CacheFile); File.WriteAllText(Filename, source); } - - } -} - +} \ No newline at end of file diff --git a/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.cs b/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.cs index cad78a4..066e79e 100644 --- a/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.cs +++ b/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.cs @@ -19,7 +19,7 @@ namespace WebApiProxy.Tasks.Templates /// Class to produce the template output /// - #line 1 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 1 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] public partial class CSharpProxyTemplate : CSharpProxyTemplateBase { @@ -29,9 +29,14 @@ public partial class CSharpProxyTemplate : CSharpProxyTemplateBase /// public virtual string TransformText() { - this.Write(@"//This file is auto-generated by WebApiProxy -//Any changes to this file will be overwritten -//Project site: http://github.com/faniereynders/webapiproxy + this.Write(@"//------------------------------------------------------------------------------ +// +// This file is auto-generated by WebApiProxy +// Project site: http://github.com/faniereynders/webapiproxy +// +// Any changes to this file will be overwritten +// +//------------------------------------------------------------------------------ using System; using System.Collections.Generic; @@ -44,37 +49,37 @@ public virtual string TransformText() using System.Web; using "); - #line 20 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 25 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Namespace)); #line default #line hidden this.Write(".Models;\r\n\r\n#region Proxies\r\nnamespace "); - #line 23 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 28 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Namespace)); #line default #line hidden - this.Write("\r\n{\r\n\t/// \r\n\t/// Client configuration.\r\n\t/// \r\n\tpublic partial" + - " class Configuration\r\n\t{\r\n\t\t/// \r\n\t\t/// Web Api Base Address.\r\n\t\t/// \r\n\t\tpublic static string "); + this.Write("\r\n{\r\n\t/// \r\n\t/// Client configuration.\r\n\t/// \r\n\tpublic static " + + "partial class Configuration\r\n\t{\r\n\t\t/// \r\n\t\t/// Web Api Base Address.\r\n\t" + + "\t/// \r\n\t\tpublic static string "); - #line 33 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 38 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Name)); #line default #line hidden this.Write("BaseAddress = \""); - #line 33 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 38 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Metadata.Host)); #line default #line hidden - this.Write("\";\r\n\t\t\r\n\t}\r\n}\r\n#endregion\r\n\r\n#region Models\r\nnamespace "); + this.Write("\";\r\n\t}\r\n}\r\n#endregion\r\n\r\n#region Models\r\nnamespace "); - #line 40 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 44 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Namespace)); #line default @@ -95,175 +100,175 @@ public class WebApiProxyResponseException : Exception "); - #line 54 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 58 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var model in Configuration.Metadata.Models.Where(m => m.Type.Equals("class"))) { #line default #line hidden this.Write("\t\r\n\t/// \r\n\t/// "); - #line 56 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 60 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.Description.ToSummary())); #line default #line hidden this.Write("\r\n\t/// \r\n\tpublic partial class "); - #line 58 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 62 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.Name)); #line default #line hidden this.Write("\r\n\t{\r\n\t\t#region Constants\r\n"); - #line 61 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 65 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var constantItem in model.Constants) { #line default #line hidden this.Write("\t\t/// \r\n\t\t/// "); - #line 63 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 67 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Description.ToSummary())); #line default #line hidden this.Write("\r\n\t\t/// \r\n\t\tpublic const "); - #line 65 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 69 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Type)); #line default #line hidden this.Write(" "); - #line 65 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 69 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Name)); #line default #line hidden this.Write(" = "); - #line 65 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 69 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Value)); #line default #line hidden this.Write(";\r\n"); - #line 66 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 70 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\t#endregion\r\n\r\n\t\t#region Properties\r\n"); - #line 70 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 74 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var propertyItem in model.Properties) { #line default #line hidden this.Write("\t\t/// \r\n\t\t/// "); - #line 72 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 76 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(propertyItem.Description.ToSummary())); #line default #line hidden this.Write("\r\n\t\t/// \r\n\t\tpublic virtual "); - #line 74 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 78 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(propertyItem.Type)); #line default #line hidden this.Write(" "); - #line 74 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 78 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(propertyItem.Name)); #line default #line hidden this.Write(" { get; set; }\r\n"); - #line 75 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 79 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\t#endregion\r\n\t}\t\r\n"); - #line 78 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 82 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\r\n"); - #line 80 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 84 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var model in Configuration.Metadata.Models.Where(m => m.Type.Equals("enum"))) { #line default #line hidden this.Write("\t\r\n\t/// \r\n\t/// "); - #line 82 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 86 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.Description.ToSummary())); #line default #line hidden this.Write("\r\n\t/// \r\n\tpublic enum "); - #line 84 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 88 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(model.Name)); #line default #line hidden this.Write("\r\n\t{\r\n"); - #line 86 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 90 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var constantItem in model.Constants) { #line default #line hidden this.Write("\r\n\t\t/// \r\n\t\t/// "); - #line 89 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 93 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Description.ToSummary())); #line default #line hidden this.Write("\r\n\t\t/// \r\n\t\t"); - #line 91 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 95 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Name)); #line default #line hidden this.Write(" = "); - #line 91 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 95 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Value)); #line default #line hidden this.Write(",\r\n"); - #line 92 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 96 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\t\r\n\t}\r\n"); - #line 94 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 98 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\r\n}\r\n#endregion\r\n\r\n#region Interfaces\r\nnamespace "); - #line 100 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 104 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Namespace)); #line default @@ -271,27 +276,27 @@ public class WebApiProxyResponseException : Exception this.Write(".Interfaces\r\n{\r\n\tpublic interface IClientBase : IDisposable\r\n\t{\r\n\t\tHttpClient Htt" + "pClient { get; }\r\n\t}\r\n\r\n"); - #line 107 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 111 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var definition in Configuration.Metadata.Definitions) { #line default #line hidden this.Write("\t\r\n\tpublic partial interface I"); - #line 108 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 112 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name)); #line default #line hidden - #line 108 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 112 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.ClientSuffix)); #line default #line hidden this.Write(" : IClientBase\r\n\t{\t\r\n"); - #line 110 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 114 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var method in definition.ActionMethods) { var allParameters = method.UrlParameters.AsEnumerable().Where(m => m != null); @@ -318,154 +323,154 @@ public class WebApiProxyResponseException : Exception #line hidden this.Write("\r\n"); - #line 132 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 136 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var p in method.UrlParameters) { #line default #line hidden this.Write("\t\t/// "); - #line 133 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 137 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(p.Description.ToSummary())); #line default #line hidden this.Write("\r\n"); - #line 134 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 138 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\r\n"); - #line 136 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 140 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" if (Configuration.GenerateAsyncReturnTypes == false || String.IsNullOrEmpty(concreteReturnType)) { #line default #line hidden this.Write("\t\t/// \r\n\t\tTask "); - #line 138 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 142 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Name)); #line default #line hidden this.Write("Async("); - #line 138 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 142 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(parameterList)); #line default #line hidden this.Write(");\r\n"); - #line 139 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 143 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } else { #line default #line hidden this.Write("\t\tTask<"); - #line 140 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 144 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(concreteReturnType)); #line default #line hidden this.Write("> "); - #line 140 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 144 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Name)); #line default #line hidden this.Write("Async("); - #line 140 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 144 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(parameterList)); #line default #line hidden this.Write(");\r\n"); - #line 141 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 145 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\r\n"); - #line 143 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 147 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var p in method.UrlParameters) { #line default #line hidden this.Write("\t\t/// "); - #line 144 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 148 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(p.Description.ToSummary())); #line default #line hidden this.Write("\r\n"); - #line 145 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 149 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\t/// \r\n\t\t"); - #line 147 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 151 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(String.IsNullOrEmpty(concreteReturnType) ? "void" : concreteReturnType)); #line default #line hidden this.Write(" "); - #line 147 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 151 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Name)); #line default #line hidden this.Write("("); - #line 147 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 151 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(parameterList)); #line default #line hidden this.Write(");\r\n"); - #line 148 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 152 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\t\t\t\r\n\t}\r\n"); - #line 150 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 154 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\r\n}\r\n#endregion\r\n\r\n#region Clients\r\nnamespace "); - #line 156 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 160 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Namespace)); #line default @@ -491,7 +496,7 @@ protected ClientBase() { BaseAddress = new Uri(Configuration."); - #line 175 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 179 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Name)); #line default @@ -499,7 +504,10 @@ protected ClientBase() this.Write(@"BaseAddress) }; } - + + /// + /// Ensures that response has a valid (200 - OK) status code + /// public virtual void EnsureSuccess(HttpResponseMessage response) { if (response.IsSuccessStatusCode) @@ -520,7 +528,7 @@ protected ClientBase(HttpMessageHandler handler, bool disposeHandler = true) { BaseAddress = new Uri(Configuration."); - #line 197 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 204 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Name)); #line default @@ -553,12 +561,33 @@ protected string EncodeParam(DateTimeOffset value) return System.Net.WebUtility.UrlEncode(value.ToString(""s"")); } + /// + /// Releases the unmanaged resources and disposes of the managed resources. + /// + protected virtual void Dispose(bool disposing) + { + if (disposing && HttpClient != null) + { + HttpClient.Dispose(); + HttpClient = null; + } + } + /// /// Releases the unmanaged resources and disposes of the managed resources. /// public void Dispose() { - HttpClient.Dispose(); + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Destructor + /// + ~ClientBase() + { + Dispose(false); } } @@ -569,34 +598,34 @@ public partial class WebApiClients { "); - #line 239 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 267 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var definition in Configuration.Metadata.Definitions) { #line default #line hidden this.Write("\t\tpublic "); - #line 240 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 268 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name)); #line default #line hidden - #line 240 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 268 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.ClientSuffix)); #line default #line hidden this.Write(" "); - #line 240 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 268 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name)); #line default #line hidden this.Write(" { get; private set; }\r\n"); - #line 241 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 269 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default @@ -604,21 +633,21 @@ public partial class WebApiClients this.Write("\t\t\r\n protected IEnumerable Clients\r\n {\r\n " + " get\r\n {\r\n"); - #line 247 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 275 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var definition in Configuration.Metadata.Definitions) { #line default #line hidden this.Write("\t\t\t\tyield return "); - #line 248 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 276 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name)); #line default #line hidden this.Write(";\r\n"); - #line 249 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 277 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default @@ -626,41 +655,41 @@ public partial class WebApiClients this.Write(" }\r\n }\r\n\r\n\t\tpublic WebApiClients(Uri baseAddress = null)\r\n\t\t{\r\n" + " if (baseAddress != null)\r\n Configuration."); - #line 256 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 284 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Name)); #line default #line hidden this.Write("BaseAddress = baseAddress.AbsoluteUri;\r\n\r\n"); - #line 258 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 286 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var definition in Configuration.Metadata.Definitions) { #line default #line hidden this.Write("\t\t\t"); - #line 259 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 287 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name)); #line default #line hidden this.Write(" = new "); - #line 259 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 287 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name)); #line default #line hidden - #line 259 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 287 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.ClientSuffix)); #line default #line hidden this.Write("();\r\n"); - #line 260 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 288 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default @@ -696,80 +725,80 @@ public void Dispose() "); - #line 290 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 318 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var definition in Configuration.Metadata.Definitions) { #line default #line hidden this.Write("\t/// \r\n\t/// "); - #line 292 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 320 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Description.ToSummary())); #line default #line hidden this.Write("\r\n\t/// \r\n\tpublic partial class "); - #line 294 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 322 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name)); #line default #line hidden - #line 294 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 322 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.ClientSuffix)); #line default #line hidden this.Write(" : ClientBase, Interfaces.I"); - #line 294 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 322 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name)); #line default #line hidden - #line 294 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 322 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.ClientSuffix)); #line default #line hidden this.Write("\r\n\t{\t\t\r\n\r\n\t\t/// \r\n\t\t/// "); - #line 298 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 326 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Description.ToSummary())); #line default #line hidden this.Write("\r\n\t\t/// \r\n\t\tpublic "); - #line 300 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 328 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name)); #line default #line hidden - #line 300 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 328 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.ClientSuffix)); #line default #line hidden this.Write("() : base()\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// \r\n\t\t/// "); - #line 305 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 333 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Description.ToSummary())); #line default #line hidden this.Write("\r\n\t\t/// \r\n\t\tpublic "); - #line 307 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 335 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name)); #line default #line hidden - #line 307 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 335 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.ClientSuffix)); #line default @@ -777,7 +806,7 @@ public void Dispose() this.Write("(HttpMessageHandler handler, bool disposeHandler = true) : base(handler, disposeH" + "andler)\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t#region Methods\r\n\r\n"); - #line 313 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 341 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var method in definition.ActionMethods) { var allParameters = method.UrlParameters.AsEnumerable(); @@ -812,267 +841,267 @@ public void Dispose() #line hidden this.Write("\t\t/// \r\n\t\t/// "); - #line 343 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 371 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Description.ToSummary())); #line default #line hidden this.Write("\r\n\t\t/// \r\n"); - #line 345 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 373 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var p in allParameters.Where(m => m != null)) { #line default #line hidden this.Write("\t\t/// "); - #line 346 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 374 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(p.Description.ToSummary())); #line default #line hidden this.Write("\r\n"); - #line 347 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 375 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\t/// \r\n\t\tprotected virtual async Task "); - #line 349 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 377 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Name)); #line default #line hidden this.Write("AsyncMsg("); - #line 349 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 377 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(parameterList)); #line default #line hidden this.Write(")\r\n\t\t{\r\n\t\t\treturn await HttpClient."); - #line 351 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 379 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Type.ToTitle())); #line default #line hidden - #line 351 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 379 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch ? "AsJson" : "")); #line default #line hidden this.Write("Async"); - #line 351 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 379 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "")); #line default #line hidden this.Write("("); - #line 351 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 379 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(url)); #line default #line hidden - #line 351 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 379 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch ? bodyParameterString:"")); #line default #line hidden this.Write(");\r\n\t\t}\r\n\r\n"); - #line 354 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 382 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" if (Configuration.GenerateAsyncReturnTypes == false || String.IsNullOrEmpty(concreteReturnType)) { #line default #line hidden this.Write("\t\t/// \r\n\t\t/// "); - #line 356 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 384 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Description.ToSummary())); #line default #line hidden this.Write("\r\n\t\t/// \r\n"); - #line 358 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 386 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var p in method.UrlParameters) { #line default #line hidden this.Write("\t\t/// "); - #line 359 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 387 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(p.Description.ToSummary())); #line default #line hidden this.Write("\r\n"); - #line 360 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 388 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\t/// \r\n\t\tpublic virtual async Task "); - #line 362 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 390 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Name)); #line default #line hidden this.Write("Async("); - #line 362 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 390 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(parameterList)); #line default #line hidden this.Write(")\r\n\t\t{\r\n\t\t\treturn await HttpClient."); - #line 364 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 392 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Type.ToTitle())); #line default #line hidden - #line 364 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 392 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch ? "AsJson" : "")); #line default #line hidden this.Write("Async"); - #line 364 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 392 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "")); #line default #line hidden this.Write("("); - #line 364 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 392 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(url)); #line default #line hidden - #line 364 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 392 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch ? bodyParameterString:"")); #line default #line hidden this.Write(");\r\n\t\t}\r\n\r\n"); - #line 367 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 395 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } else { #line default #line hidden this.Write("\t\t/// \r\n\t\t/// "); - #line 369 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 397 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Description.ToSummary())); #line default #line hidden this.Write("\r\n\t\t/// \r\n"); - #line 371 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 399 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var p in method.UrlParameters) { #line default #line hidden this.Write("\t\t/// "); - #line 372 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 400 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(p.Description.ToSummary())); #line default #line hidden this.Write("\r\n"); - #line 373 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 401 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\t/// \r\n\t\tpublic virtual async Task<"); - #line 375 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 403 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(concreteReturnType)); #line default #line hidden this.Write("> "); - #line 375 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 403 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Name)); #line default #line hidden this.Write("Async("); - #line 375 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 403 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(parameterList)); #line default #line hidden this.Write(")\r\n\t\t{\r\n\t\t\tvar result = await HttpClient."); - #line 377 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 405 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Type.ToTitle())); #line default #line hidden - #line 377 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 405 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch ? "AsJson" : "")); #line default #line hidden this.Write("Async"); - #line 377 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 405 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "")); #line default #line hidden this.Write("("); - #line 377 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 405 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(url)); #line default #line hidden - #line 377 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 405 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch ? bodyParameterString:"")); #line default @@ -1080,119 +1109,119 @@ public void Dispose() this.Write(");\r\n\t\t\t \r\n\t\t\tEnsureSuccess(result);\r\n\t\t\t\t \r\n\t\t\treturn await result.Content.ReadAs" + "Async<"); - #line 381 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 409 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(concreteReturnType)); #line default #line hidden this.Write(">();\r\n\t\t}\r\n\r\n"); - #line 384 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 412 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\t/// \r\n\t\t/// "); - #line 386 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 414 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Description.ToSummary())); #line default #line hidden this.Write("\r\n\t\t/// \r\n"); - #line 388 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 416 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" foreach(var p in method.UrlParameters) { #line default #line hidden this.Write("\t\t/// "); - #line 389 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 417 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(p.Description.ToSummary())); #line default #line hidden this.Write("\r\n"); - #line 390 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 418 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\tpublic virtual "); - #line 391 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 419 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(String.IsNullOrEmpty(concreteReturnType) ? "void" : concreteReturnType)); #line default #line hidden this.Write(" "); - #line 391 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 419 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Name)); #line default #line hidden this.Write("("); - #line 391 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 419 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(parameterList)); #line default #line hidden this.Write(")\r\n\t\t{\r\n\t\t\tvar result = Task.Run(() => "); - #line 393 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 421 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(method.Name)); #line default #line hidden this.Write("AsyncMsg("); - #line 393 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 421 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(parameterNameList)); #line default #line hidden this.Write(")).Result;\t\t \r\n\t\t\t \r\n\t\t\tEnsureSuccess(result);\r\n"); - #line 396 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 424 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" if(!String.IsNullOrEmpty(concreteReturnType)) { #line default #line hidden this.Write("\t\t\t \t\t\t \r\n\t\t\treturn result.Content.ReadAsAsync<"); - #line 397 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 425 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" this.Write(this.ToStringHelper.ToStringWithCulture(concreteReturnType)); #line default #line hidden this.Write(">().Result;\r\n\t\t\t "); - #line 398 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 426 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\t}\r\n\r\n"); - #line 401 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 429 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default #line hidden this.Write("\t\t#endregion\r\n\t}\r\n"); - #line 404 "C:\dev\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" + #line 432 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt" } #line default diff --git a/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.tt b/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.tt index d79c71a..91f4b81 100644 --- a/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.tt +++ b/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.tt @@ -4,9 +4,14 @@ <#@ import namespace="System.Text" #> <#@ import namespace="WebApiProxy.Core.Models" #> <#@ import namespace="System.Collections.Generic" #> -//This file is auto-generated by WebApiProxy -//Any changes to this file will be overwritten -//Project site: http://github.com/faniereynders/webapiproxy +//------------------------------------------------------------------------------ +// +// This file is auto-generated by WebApiProxy +// Project site: http://github.com/faniereynders/webapiproxy +// +// Any changes to this file will be overwritten +// +//------------------------------------------------------------------------------ using System; using System.Collections.Generic; @@ -25,13 +30,12 @@ namespace <#= Configuration.Namespace#> /// /// Client configuration. /// - public partial class Configuration + public static partial class Configuration { /// /// Web Api Base Address. /// public static string <#= Configuration.Name #>BaseAddress = "<#= Configuration.Metadata.Host #>"; - } } #endregion @@ -175,7 +179,10 @@ namespace <#= Configuration.Namespace#>.Clients BaseAddress = new Uri(Configuration.<#= Configuration.Name #>BaseAddress) }; } - + + /// + /// Ensures that response has a valid (200 - OK) status code + /// public virtual void EnsureSuccess(HttpResponseMessage response) { if (response.IsSuccessStatusCode) @@ -222,12 +229,33 @@ namespace <#= Configuration.Namespace#>.Clients return System.Net.WebUtility.UrlEncode(value.ToString("s")); } + /// + /// Releases the unmanaged resources and disposes of the managed resources. + /// + protected virtual void Dispose(bool disposing) + { + if (disposing && HttpClient != null) + { + HttpClient.Dispose(); + HttpClient = null; + } + } + /// /// Releases the unmanaged resources and disposes of the managed resources. /// public void Dispose() { - HttpClient.Dispose(); + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Destructor + /// + ~ClientBase() + { + Dispose(false); } }