diff --git a/.gitignore b/.gitignore
index 20938ef..4a36a6e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -181,4 +181,8 @@ UpgradeLog*.htm
*.bim_*.settings
# Microsoft Fakes
-FakesAssemblies/
\ No newline at end of file
+FakesAssemblies/
+
+
+# vs files
+.vs/
\ No newline at end of file
diff --git a/Nuget/build-nuget-csharp.bat b/Nuget/build-nuget-csharp.bat
index 99b02ff..4f36936 100644
--- a/Nuget/build-nuget-csharp.bat
+++ b/Nuget/build-nuget-csharp.bat
@@ -1,12 +1,12 @@
-@echo off
-set path=.
-if not [%1]==[] set path=%1
-
-IF NOT EXIST Packages MKDIR Packages
-
-echo Creating WebProxyApi CSharp Package
- %path%\..\.nuget\nuget pack %path%\..\WebApiProxy.Tasks\WebApiProxy.Tasks.csproj -IncludeReferencedProjects -OutputDirectory %path%\Packages -Properties Configuration=Release -Verbose
-
-if errorlevel 1 echo Error creating WebApiProxy CSharp Package
-
+@echo off
+set path=.
+if not [%1]==[] set path=%1
+
+IF NOT EXIST Packages MKDIR Packages
+
+echo Creating WebProxyApi CSharp Package
+ %path%\..\.nuget\nuget pack %path%\..\WebApiProxy.Tasks\WebApiProxy.Tasks.csproj -Build -IncludeReferencedProjects -OutputDirectory %path%\Packages -Properties Configuration=Release -Verbose
+
+if errorlevel 1 echo Error creating WebApiProxy CSharp Package
+
pause;
\ No newline at end of file
diff --git a/Nuget/build-nuget-server.bat b/Nuget/build-nuget-server.bat
index f74ea5f..9becd4c 100644
--- a/Nuget/build-nuget-server.bat
+++ b/Nuget/build-nuget-server.bat
@@ -1,12 +1,12 @@
-@echo off
-set path=.
-if not [%1]==[] set path=%1
-
-IF NOT EXIST Packages MKDIR Packages
-
-echo Creating WebProxyApi Package
- %path%\..\.nuget\nuget pack %path%\..\WebApiProxy.Server\WebApiProxy.Server.csproj -IncludeReferencedProjects -OutputDirectory %path%\..\Nuget\Packages -Properties Configuration=Release -Verbose
-
-if errorlevel 1 echo Error creating WebApiProxy Package
-
+@echo off
+set path=.
+if not [%1]==[] set path=%1
+
+IF NOT EXIST Packages MKDIR Packages
+
+echo Creating WebProxyApi Package
+ %path%\..\.nuget\nuget pack %path%\..\WebApiProxy.Server\WebApiProxy.Server.csproj -Build -IncludeReferencedProjects -OutputDirectory %path%\..\Nuget\Packages -Properties Configuration=Release -Verbose
+
+if errorlevel 1 echo Error creating WebApiProxy Package
+
pause;
\ No newline at end of file
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..0b5f09b
--- /dev/null
+++ b/README.org
@@ -0,0 +1,183 @@
+#+TITLE: web-api-uoko
+#+DATE: <2015-08-07 Fri>
+#+AUTHOR: $+j
+#+EMAIL: lust4life.jun@gmail.com
+#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
+#+OPTIONS: author:t c:nil creator:comment d:(not "LOGBOOK") date:t
+#+OPTIONS: e:t email:nil f:t inline:t num:nil p:nil pri:nil stat:t
+#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:t todo:t |:t
+#+CREATOR: Emacs 24.5.1 (Org mode 8.2.10)
+#+DESCRIPTION:
+#+EXCLUDE_TAGS: noexport
+#+KEYWORDS:
+#+LANGUAGE: zh
+#+SELECT_TAGS: export
+
+* 使用 api proxy
+
+** 服务端配置
+
+*** 从 nuget 安装包
+
+ 在api的站点层,引用包 : WebApiProxy(WebApi Proxy Provider) ,创建者为 Fanie Reynders 的这个.
+
+*** 注册 Endpoint
+
+ 在 web api 配置类中注册
+
+ #+BEGIN_SRC csharp
+ config.RegisterProxyRoutes();
+ #+END_SRC
+
+** 客户端配置
+
+*** 安装包
+
+ 在需要用到 client 的地方,建立一个类库项目,作为这个 client 的寄宿.对这个类库项目引用 uoko nuget 上的 UOKO.ApiProxy.CSharp (WebApiProxy c# Proxy Client Generator).
+
+ #+BEGIN_QUOTE
+ 为什么要单独建立一个类库项目?
+
+ 因为目前这个 proxy client 的代码生成不支持多个 endpoint ,所以在需要调用 api 的项目中直接使用的话,没法做到多个 api 一起用.后期可以改改源码,支持多个 endpoint 的代码生成.
+ #+END_QUOTE
+
+*** config 和 使用
+
+ 安装成功以后,在项目中会出现一个 WebApiProxy 的文件夹.分别有一个代码生成类文件 以及 一个配置文件.
+
+ #+BEGIN_SRC xml
+
+ #+END_SRC
+
+ 我们主要配置三个东西:
+
+ - endpoint : 这个是你需要使用的 api 服务端地址
+ - namespace : proxy 代码生成类的命名空间
+ - generateOnBuild : 是否在 build 的时候,生成代码. 建议是按需调整.需要生成的时候置为 1 , 生成完成后修改为 0
+
+ 然后 build 这个解决方案, 相应的 proxy 代码即可生成了.
+
+** 细节处理
+
+
+*** 服务端相关
+
+ 大家都知道 web api Action 的返回类型支持就 4 种.
+
+
+ 1. void
+ 2. HttpResponseMessage
+ 3. IHttpActionResult
+ 4. Some other type
+
+ 见: http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/action-results
+
+ 如果你的返回类型是 1, 4 那么不用修改什么. 如果你的返回类型是 2,3 两种的话,那么你需要告诉 Proxy 你请求成功时候真正的返回类型是什么类型.这样代码生成的时候才能生成相应的类.这时候在 Action 使用 [ResponseType(xxxType)] 即可.如下:
+
+ [[./img/web-api-uoko/api-response-type-assign.jpg]]
+
+*** 客户端相关
+
+ 客户端生成的代码中有一类情况需要完善修改的.就是大家需要搜索生成代码中 =throw new NotImplementedException();= 的地方.需要对这些类进行继承以后重写实现这个方法.
+
+ #+BEGIN_QUOTE
+ 什么时候回出现这类情况?
+
+ 如果大家在服务端 Action 的参数中使用了复杂类型参数,并且请求是 Get 请求, 并且这个参数的绑定方式是 FromUri 的时候,那么生成的 Proxy 代码就会出现这类情况.
+ #+END_QUOTE
+
+ 见如下代码:
+
+ #+BEGIN_SRC csharp
+ ///
+ /// 获取部门分页列表
+ ///
+ /// 查询实体类
+ public virtual async Task GetAsync(DepartmentQuery query)
+ {
+ var requestUrl = "api/Department";
+
+ var queryHasParamUrl = "";
+
+
+ var queryNoParamUrlTpl = "CompanyId={CompanyId}&DepLevel={DepLevel}&offset={offset}&pageSize={pageSize}&sortBy={sortBy}&sortType={sortType}";
+ var queryNoParamUrl = GenerateGetQueryString(queryNoParamUrlTpl, query);
+
+ if (string.IsNullOrEmpty(queryHasParamUrl))
+ {
+ requestUrl = requestUrl + "?" + queryNoParamUrl;
+ }
+ else
+ {
+ requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl;
+ }
+
+
+ return await HttpClient.GetAsync(requestUrl ).ConfigureAwait(false);
+ }
+
+
+ public virtual string GenerateGetQueryString(string urlQueryString, DepartmentQuery query)
+ {
+ var kvList = GenerateGetKeyValueList( query );
+ var urlTpl = GenerateQueryStrFromKvList(kvList);
+
+ return urlTpl;
+ }
+
+ public virtual List> GenerateGetKeyValueList(DepartmentQuery query)
+ {
+ throw new NotImplementedException();
+ }
+ #+END_SRC
+
+ 这类情况我们需要做的就是:
+
+ #+BEGIN_SRC csharp
+ public class DepartmentClientIndeed : DepartmentClient
+ {
+ public override List> GenerateGetKeyValueList(DepartmentQuery query)
+ {
+ var kvList = new List>()
+ {
+ new KeyValuePair("CompanyId", query.CompanyId),
+ new KeyValuePair("DepLevel", query.DepLevel),
+
+ new KeyValuePair("offset", query.offset),
+ new KeyValuePair("pageSize", query.pageSize),
+ new KeyValuePair("sortBy", query.sortBy),
+ new KeyValuePair("sortType", query.sortType),
+ };
+ return kvList;
+ }
+ }
+ #+END_SRC
+
+ 这里做的就是, 指定上面 url 中查询串的参数,都如何从 复杂对象 中获取.
+
+ 因为 Proxy 代码是生成的, 所以这个新建的子类,应该是独立的类文件, 不会被生成覆盖的.
+
+
+*** 使用
+
+ 到此,基本上就可以正常使用了. 因为会有子类的存在,所以我们最好不要直接在需要用 api 的地方, 创建具体的实体类. 这样不利于后期维护和修改调整.因为生成代码中已经生成了接口代码.所以最好是对接口进行依赖.然后通过大家喜欢的 DI 框架,注入到接口中进行使用.比如:
+
+ [[./img/web-api-uoko/api-client-usage.jpg]]
+
+ 如下是 DI 框架注入的, 箭头都是被重写过的类.
+
+ [[./img/web-api-uoko/api-client-usage-di.jpg]]
+
+
+* 关于 proxy
+
+ 使用的是 https://github.com/faniereynders/WebApiProxy
+
+ 该项目分两大部分,服务端 api 描述信息生成. 客户端代码根据描述信息,生成本地代理.我们只是把生成代理的代码做了一些定制化修改,方便我们自己使用.更多有意思的东西,可以直接看官方使用 wiki: https://github.com/faniereynders/WebApiProxy/wiki 或者源码进行了解.
+
+ 有兴趣还可了解下来由: [[file:user-permission-refactor.org::*web%20api%20proxy/help%20page(api%20lifecycle)][web api proxy/help page(api lifecycle)]]
diff --git a/WebApiProxy.Core/ConnectionException.cs b/WebApiProxy.Core/ConfigFileNotFoundException.cs
similarity index 58%
rename from WebApiProxy.Core/ConnectionException.cs
rename to WebApiProxy.Core/ConfigFileNotFoundException.cs
index 11a8cfe..97cfbf4 100644
--- a/WebApiProxy.Core/ConnectionException.cs
+++ b/WebApiProxy.Core/ConfigFileNotFoundException.cs
@@ -1,48 +1,30 @@
-using System;
-
-namespace WebApiProxy
-{
- public class ConnectionException : Exception
- {
-
- private string uri;
- public ConnectionException(string uri)
- {
- this.uri = uri;
- }
-
- public override string Message
- {
- get
- {
- return "WebApiProxy: Could not connect to remote server - " + uri;
- }
- }
- }
-
- public class ConfigFileNotFoundException : Exception
- {
- private readonly string path;
- public ConfigFileNotFoundException(string path)
- {
- this.path = path;
- }
- public override string StackTrace
- {
- get
- {
- return String.Empty;
- }
- }
-
-
-
- public override string Message
- {
- get
- {
- return "WebApiProxy: Configuration file not found: " + path;
- }
- }
- }
-}
+using System;
+
+namespace WebApiProxy
+{
+ public class ConfigFileNotFoundException : Exception
+ {
+ private readonly string path;
+ public ConfigFileNotFoundException(string path)
+ {
+ this.path = path;
+ }
+ public override string StackTrace
+ {
+ get
+ {
+ return String.Empty;
+ }
+ }
+
+
+
+ public override string Message
+ {
+ get
+ {
+ return "WebApiProxy: Configuration file not found: " + path;
+ }
+ }
+ }
+}
diff --git a/WebApiProxy.Core/ExcludeProxy.cs b/WebApiProxy.Core/ExcludeProxy.cs
index 929a52d..eea7b0b 100644
--- a/WebApiProxy.Core/ExcludeProxy.cs
+++ b/WebApiProxy.Core/ExcludeProxy.cs
@@ -1,8 +1,8 @@
-using System;
-
-namespace WebApiProxy
-{
- public class ExcludeProxy : Attribute
- {
- }
-}
+using System;
+
+namespace WebApiProxy
+{
+ public class ExcludeProxy : Attribute
+ {
+ }
+}
diff --git a/WebApiProxy.Core/Models/ActionMethodDefinition.cs b/WebApiProxy.Core/Models/ActionMethodDefinition.cs
index 52a598c..abf05c8 100644
--- a/WebApiProxy.Core/Models/ActionMethodDefinition.cs
+++ b/WebApiProxy.Core/Models/ActionMethodDefinition.cs
@@ -1,22 +1,22 @@
-using System.Collections.Generic;
-
-namespace WebApiProxy.Core.Models
-{
- public class ActionMethodDefinition
- {
- public string Type { get; set; }
-
- public string Name { get; set; }
-
- public string Url { get; set; }
-
- public IEnumerable UrlParameters { get; set; }
-
- public ParameterDefinition BodyParameter { get; set; }
-
- public string Description { get; set; }
-
- public string ReturnType { get; set; }
-
- }
-}
+using System.Collections.Generic;
+
+namespace WebApiProxy.Core.Models
+{
+ public class ActionMethodDefinition
+ {
+ public string Type { get; set; }
+
+ public string Name { get; set; }
+
+ public string Url { get; set; }
+
+ public IEnumerable UrlParameters { get; set; }
+
+ public ParameterDefinition BodyParameter { get; set; }
+
+ public string Description { get; set; }
+
+ public string ReturnType { get; set; }
+
+ }
+}
diff --git a/WebApiProxy.Core/Models/ControllerDefinition.cs b/WebApiProxy.Core/Models/ControllerDefinition.cs
index e4741ca..0420f71 100644
--- a/WebApiProxy.Core/Models/ControllerDefinition.cs
+++ b/WebApiProxy.Core/Models/ControllerDefinition.cs
@@ -1,14 +1,14 @@
-using System.Collections.Generic;
-
-namespace WebApiProxy.Core.Models
-{
- public class ControllerDefinition
- {
- public string Name { get; set; }
-
- public string Description { get; set; }
-
- public IEnumerable ActionMethods { get; set; }
-
- }
-}
+using System.Collections.Generic;
+
+namespace WebApiProxy.Core.Models
+{
+ public class ControllerDefinition
+ {
+ public string Name { get; set; }
+
+ public string Description { get; set; }
+
+ public IEnumerable ActionMethods { get; set; }
+
+ }
+}
diff --git a/WebApiProxy.Core/Models/Metadata.cs b/WebApiProxy.Core/Models/Metadata.cs
index 68e6b99..aa7e9bd 100644
--- a/WebApiProxy.Core/Models/Metadata.cs
+++ b/WebApiProxy.Core/Models/Metadata.cs
@@ -1,14 +1,14 @@
-using System.Collections.Generic;
-
-namespace WebApiProxy.Core.Models
-{
- public class Metadata
- {
- public string Host { get; set; }
-
- public IEnumerable Definitions { get; set; }
-
- public IEnumerable Models { get; set; }
-
- }
-}
+using System.Collections.Generic;
+
+namespace WebApiProxy.Core.Models
+{
+ public class Metadata
+ {
+ public string Host { get; set; }
+
+ public IEnumerable Definitions { get; set; }
+
+ public IEnumerable Models { get; set; }
+
+ }
+}
diff --git a/WebApiProxy.Core/Models/ModelDefinition.cs b/WebApiProxy.Core/Models/ModelDefinition.cs
index 329e877..905a092 100644
--- a/WebApiProxy.Core/Models/ModelDefinition.cs
+++ b/WebApiProxy.Core/Models/ModelDefinition.cs
@@ -1,47 +1,47 @@
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace WebApiProxy.Core.Models
-{
- [DebuggerDisplay("{Name}")]
- public class ModelDefinition
- {
- #region Constructors
- public ModelDefinition()
- {
- GenericArgumentsMap = new Dictionary();
- Constants = new List();
- Properties = new List();
- }
- #endregion
-
- #region Properties
- public string Name { get; set; }
- public string Description { get; set; }
- public string Type { get; set; }
- public IDictionary GenericArgumentsMap { get; set; }
-
- public IEnumerable Constants { get; set; }
- public IEnumerable Properties { get; set; }
- #endregion
-
- #region Methods
- public string AddGenericArgument(string argument)
- {
- var result = System.String.Format(System.Globalization.CultureInfo.InvariantCulture, "T{0}", GenericArgumentsMap.Count + 1);
- GenericArgumentsMap.Add(argument, result);
- return result;
- }
-
- public string GetGenericArgument(string argument)
- {
- return GenericArgumentsMap[argument];
- }
-
- public bool IsGenericArgument(string argument)
- {
- return GenericArgumentsMap.ContainsKey(argument);
- }
- #endregion
- }
-}
+using System.Collections.Generic;
+using System.Diagnostics;
+
+namespace WebApiProxy.Core.Models
+{
+ [DebuggerDisplay("{Name}")]
+ public class ModelDefinition
+ {
+ #region Constructors
+ public ModelDefinition()
+ {
+ GenericArgumentsMap = new Dictionary();
+ Constants = new List();
+ Properties = new List();
+ }
+ #endregion
+
+ #region Properties
+ public string Name { get; set; }
+ public string Description { get; set; }
+ public string Type { get; set; }
+ public IDictionary GenericArgumentsMap { get; set; }
+
+ public IEnumerable Constants { get; set; }
+ public IEnumerable Properties { get; set; }
+ #endregion
+
+ #region Methods
+ public string AddGenericArgument(string argument)
+ {
+ var result = System.String.Format(System.Globalization.CultureInfo.InvariantCulture, "T{0}", GenericArgumentsMap.Count + 1);
+ GenericArgumentsMap.Add(argument, result);
+ return result;
+ }
+
+ public string GetGenericArgument(string argument)
+ {
+ return GenericArgumentsMap[argument];
+ }
+
+ public bool IsGenericArgument(string argument)
+ {
+ return GenericArgumentsMap.ContainsKey(argument);
+ }
+ #endregion
+ }
+}
diff --git a/WebApiProxy.Core/Models/ParameterDefinition.cs b/WebApiProxy.Core/Models/ParameterDefinition.cs
index fd7d5c4..e6ff8a7 100644
--- a/WebApiProxy.Core/Models/ParameterDefinition.cs
+++ b/WebApiProxy.Core/Models/ParameterDefinition.cs
@@ -1,16 +1,16 @@
-
-namespace WebApiProxy.Core.Models
-{
- public class ParameterDefinition
- {
- public string Name { get; set; }
-
- public string Type { get; set; }
-
- public string Description { get; set; }
-
- public bool IsOptional { get; set; }
-
- public object DefaultValue { get; set; }
- }
-}
+
+namespace WebApiProxy.Core.Models
+{
+ public class ParameterDefinition
+ {
+ public string Name { get; set; }
+
+ public string Type { get; set; }
+
+ public string Description { get; set; }
+
+ public bool IsOptional { get; set; }
+
+ public object DefaultValue { get; set; }
+ }
+}
diff --git a/WebApiProxy.Core/StringExtensions.cs b/WebApiProxy.Core/StringExtensions.cs
index f7680df..6b7b417 100644
--- a/WebApiProxy.Core/StringExtensions.cs
+++ b/WebApiProxy.Core/StringExtensions.cs
@@ -1,100 +1,100 @@
-using System;
-using System.Collections.Generic;
-using System.Text.RegularExpressions;
-
-namespace WebApiProxy
-{
- public static class StringExtensions
- {
- public static string DefaultIfEmpty(this string helper, string value)
- {
- if (String.IsNullOrEmpty(helper))
- return value;
-
- return helper;
- }
-
- public static string ToTitle(this string helper)
- {
- return helper.Substring(0, 1).ToUpper() + helper.Substring(1, helper.Length - 1).ToLower();
-
- }
-
- public static string ToCamelCasing(this string helper)
- {
- return helper.Replace(helper[0].ToString(), helper[0].ToString().ToLower());
- }
-
- ///
- /// Transform the string to the XML documentation expected format respecting the new lines.
- ///
- /// The description.
- /// The xml documentation format.
- public static string ToSummary(this string description)
- {
- return Regex.Replace(description, "\n\\s*", "\n\t\t/// ");
- }
-
- ///
- /// Ensures common return types are made conrete
- ///
- public static string ToConcrete(this string returnType)
- {
- if (string.IsNullOrWhiteSpace(returnType))
- return returnType;
-
- string[] commonTypes = {
- "IQueryable",
- "IList",
- "IEnumerable"
- };
-
- foreach (var type in commonTypes)
- {
- var replaced = Regex.Replace(returnType, type + @"\<(.+)\>", "List<$1>");
-
- if (replaced.Length != returnType.Length)
- return replaced;
- }
-
- return returnType;
- }
-
- public static string Format(this string pattern, object template)
- {
- var rePattern = new Regex(@"(\{+)([^\}]+)(\}+)", RegexOptions.Compiled);
-
- if (template == null) throw new ArgumentNullException();
- Type type = template.GetType();
- var cache = new Dictionary();
- return rePattern.Replace(pattern, match =>
- {
- int lCount = match.Groups[1].Value.Length,
- rCount = match.Groups[3].Value.Length;
- if ((lCount % 2) != (rCount % 2)) throw new InvalidOperationException("Unbalanced braces");
- string lBrace = lCount == 1 ? "" : new string('{', lCount / 2),
- rBrace = rCount == 1 ? "" : new string('}', rCount / 2);
-
- string key = match.Groups[2].Value, value;
- if (lCount % 2 == 0)
- {
- value = key;
- }
- else
- {
- if (!cache.TryGetValue(key, out value))
- {
- var prop = type.GetProperty(key);
- if (prop == null)
- {
- throw new ArgumentException("Not found: " + key, "pattern");
- }
- value = Convert.ToString(prop.GetValue(template, null));
- cache.Add(key, value);
- }
- }
- return lBrace + value + rBrace;
- });
- }
- }
-}
+using System;
+using System.Collections.Generic;
+using System.Text.RegularExpressions;
+
+namespace WebApiProxy
+{
+ public static class StringExtensions
+ {
+ public static string DefaultIfEmpty(this string helper, string value)
+ {
+ if (String.IsNullOrEmpty(helper))
+ return value;
+
+ return helper;
+ }
+
+ public static string ToTitle(this string helper)
+ {
+ return helper.Substring(0, 1).ToUpper() + helper.Substring(1, helper.Length - 1).ToLower();
+
+ }
+
+ public static string ToCamelCasing(this string helper)
+ {
+ return helper.Replace(helper[0].ToString(), helper[0].ToString().ToLower());
+ }
+
+ ///
+ /// Transform the string to the XML documentation expected format respecting the new lines.
+ ///
+ /// The description.
+ /// The xml documentation format.
+ public static string ToSummary(this string description)
+ {
+ return Regex.Replace(description, "\n\\s*", "\n\t\t/// ");
+ }
+
+ ///
+ /// Ensures common return types are made conrete
+ ///
+ public static string ToConcrete(this string returnType)
+ {
+ if (string.IsNullOrWhiteSpace(returnType))
+ return returnType;
+
+ string[] commonTypes = {
+ "IQueryable",
+ "IList",
+ "IEnumerable"
+ };
+
+ foreach (var type in commonTypes)
+ {
+ var replaced = Regex.Replace(returnType, type + @"\<(.+)\>", "List<$1>");
+
+ if (replaced.Length != returnType.Length)
+ return replaced;
+ }
+
+ return returnType;
+ }
+
+ public static string Format(this string pattern, object template)
+ {
+ var rePattern = new Regex(@"(\{+)([^\}]+)(\}+)", RegexOptions.Compiled);
+
+ if (template == null) throw new ArgumentNullException();
+ Type type = template.GetType();
+ var cache = new Dictionary();
+ return rePattern.Replace(pattern, match =>
+ {
+ int lCount = match.Groups[1].Value.Length,
+ rCount = match.Groups[3].Value.Length;
+ if ((lCount % 2) != (rCount % 2)) throw new InvalidOperationException("Unbalanced braces");
+ string lBrace = lCount == 1 ? "" : new string('{', lCount / 2),
+ rBrace = rCount == 1 ? "" : new string('}', rCount / 2);
+
+ string key = match.Groups[2].Value, value;
+ if (lCount % 2 == 0)
+ {
+ value = key;
+ }
+ else
+ {
+ if (!cache.TryGetValue(key, out value))
+ {
+ var prop = type.GetProperty(key);
+ if (prop == null)
+ {
+ throw new ArgumentException("Not found: " + key, "pattern");
+ }
+ value = Convert.ToString(prop.GetValue(template, null));
+ cache.Add(key, value);
+ }
+ }
+ return lBrace + value + rBrace;
+ });
+ }
+ }
+}
diff --git a/WebApiProxy.Core/WebApiProxy.Core.csproj b/WebApiProxy.Core/WebApiProxy.Core.csproj
index 59f5f0c..3a4d943 100644
--- a/WebApiProxy.Core/WebApiProxy.Core.csproj
+++ b/WebApiProxy.Core/WebApiProxy.Core.csproj
@@ -1,62 +1,62 @@
-
-
-
-
- Debug
- AnyCPU
- {94508206-8537-4088-923B-E7FCB0539903}
- Library
- Properties
- WebApiProxy.Core
- WebApiProxy.Core
- v4.5
- 512
- ..\
- true
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ Debug
+ AnyCPU
+ {94508206-8537-4088-923B-E7FCB0539903}
+ Library
+ Properties
+ WebApiProxy.Core
+ WebApiProxy.Core
+ v4.5
+ 512
+ ..\
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/WebApiProxy.Server/ProxyHandler.cs b/WebApiProxy.Server/ProxyHandler.cs
index 4a29c34..2aba291 100644
--- a/WebApiProxy.Server/ProxyHandler.cs
+++ b/WebApiProxy.Server/ProxyHandler.cs
@@ -1,45 +1,45 @@
-using System;
-using System.Linq;
-using System.Net.Http;
-using System.Net.Http.Headers;
-using System.Threading.Tasks;
-using System.Web.Http;
-using WebApiProxy.Server.Templates;
-//testing ci 1
-namespace WebApiProxy.Server
-{
- public class ProxyHandler : DelegatingHandler
- {
- private MetadataProvider _metadataProvider;
- HttpConfiguration _config;
- public ProxyHandler(HttpConfiguration config)
- {
- _metadataProvider = new MetadataProvider(config);
- _config = config;
- }
-
- protected async override Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
- {
- return await Task.Run(() =>
- {
- var metadata = _metadataProvider.GetMetadata(request);
-
- if (request.Headers.Any(h => h.Key == "X-Proxy-Type" && h.Value.Contains("metadata")))
- {
- return request.CreateResponse(System.Net.HttpStatusCode.OK, metadata);
- }
-
- var template = new JsProxyTemplate(metadata);
- var js = new StringContent(template.TransformText());
-
- js.Headers.ContentType = new MediaTypeHeaderValue("application/javascript");
- js.Headers.Expires = DateTime.Now.AddDays(30).ToUniversalTime();
-
- var result = new HttpResponseMessage { Content = js }; ;
- result.Headers.CacheControl = CacheControlHeaderValue.Parse("public");
-
- return result;
- });
- }
- }
-}
+using System;
+using System.Linq;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Threading.Tasks;
+using System.Web.Http;
+using WebApiProxy.Server.Templates;
+//testing ci 1
+namespace WebApiProxy.Server
+{
+ public class ProxyHandler : DelegatingHandler
+ {
+ private MetadataProvider _metadataProvider;
+ HttpConfiguration _config;
+ public ProxyHandler(HttpConfiguration config)
+ {
+ _metadataProvider = new MetadataProvider(config);
+ _config = config;
+ }
+
+ protected async override Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
+ {
+ return await Task.Run(() =>
+ {
+ var metadata = _metadataProvider.GetMetadata(request);
+
+ if (request.Headers.Any(h => h.Key == "X-Proxy-Type" && h.Value.Contains("metadata")))
+ {
+ return request.CreateResponse(System.Net.HttpStatusCode.OK, metadata);
+ }
+
+ var template = new JsProxyTemplate(metadata);
+ var js = new StringContent(template.TransformText());
+
+ js.Headers.ContentType = new MediaTypeHeaderValue("application/javascript");
+ js.Headers.Expires = DateTime.Now.AddDays(30).ToUniversalTime();
+
+ var result = new HttpResponseMessage { Content = js }; ;
+ result.Headers.CacheControl = CacheControlHeaderValue.Parse("public");
+
+ return result;
+ });
+ }
+ }
+}
diff --git a/WebApiProxy.Server/Templates/JsProxyTemplate.Parameters.cs b/WebApiProxy.Server/Templates/JsProxyTemplate.Parameters.cs
index 8520e86..b8108c4 100644
--- a/WebApiProxy.Server/Templates/JsProxyTemplate.Parameters.cs
+++ b/WebApiProxy.Server/Templates/JsProxyTemplate.Parameters.cs
@@ -1,21 +1,21 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using WebApiProxy.Core.Models;
-
-namespace WebApiProxy.Server.Templates
-{
- ///
- /// A partial class implementation used to pass parameters to the proxy template.
- ///
- public partial class JsProxyTemplate
- {
- public JsProxyTemplate(Metadata metadata)
- {
- this.Metadata = metadata;
- }
- public Metadata Metadata { get; set; }
- }
-}
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using WebApiProxy.Core.Models;
+
+namespace WebApiProxy.Server.Templates
+{
+ ///
+ /// A partial class implementation used to pass parameters to the proxy template.
+ ///
+ public partial class JsProxyTemplate
+ {
+ public JsProxyTemplate(Metadata metadata)
+ {
+ this.Metadata = metadata;
+ }
+ public Metadata Metadata { get; set; }
+ }
+}
diff --git a/WebApiProxy.Server/Templates/JsProxyTemplate.cs b/WebApiProxy.Server/Templates/JsProxyTemplate.cs
index 1f3d3b0..ee2ff83 100644
--- a/WebApiProxy.Server/Templates/JsProxyTemplate.cs
+++ b/WebApiProxy.Server/Templates/JsProxyTemplate.cs
@@ -1,505 +1,505 @@
-// ------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
-// Runtime Version: 14.0.0.0
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
-// ------------------------------------------------------------------------------
-namespace WebApiProxy.Server.Templates
-{
- using System.Linq;
- using System.Text;
- using System.Collections.Generic;
- using System;
-
- ///
- /// Class to produce the template output
- ///
-
- #line 1 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")]
- public partial class JsProxyTemplate : JsProxyTemplateBase
- {
-#line hidden
- ///
- /// Create the template output
- ///
- public virtual string TransformText()
- {
- this.Write("\r\n(function($) {\r\n\t\"use strict\";\r\n\r\n\tif (!$) {\r\n\t\tthrow \"jQuery is required\";\r\n\t}" +
- "\r\n\r\n\t$.proxies = $.proxies || { \r\n\t\tbaseUrl: \"");
-
- #line 15 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(this.Metadata.Host));
-
- #line default
- #line hidden
- this.Write("\"\r\n\t};\r\n\r\n\tfunction getQueryString(params, queryString) {\r\n\t\tqueryString = queryS" +
- "tring || \"\";\r\n\t\tfor(var prop in params) {\r\n\t\t\tif (params.hasOwnProperty(prop)) {" +
- "\r\n\t\t\t\tvar val = getArgValue(params[prop]);\r\n\t\t\t\tif (val === null) continue;\r\n\r\n\t" +
- "\t\t\tif (\"\" + val === \"[object Object]\") {\r\n\t\t\t\t\tqueryString = getQueryString(para" +
- "ms[prop], queryString);\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (queryString.length) {\r" +
- "\n\t\t\t\t\tqueryString += \"&\";\r\n\t\t\t\t} else {\r\n\t\t\t\t\tqueryString += \"?\";\r\n\t\t\t\t}\r\n\t\t\t\tqu" +
- "eryString = queryString + prop + \"=\" +val;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn queryString;\r\n\t}" +
- "\r\n\r\n\tfunction getArgValue(val) {\r\n\t\tif (val === undefined || val === null) retur" +
- "n null;\r\n\t\treturn val;\r\n\t}\r\n\r\n\tfunction invoke(url, type, urlParams, body) {\r\n\t\t" +
- "//url += getQueryString(urlParams);\r\n\r\n\t\tvar ajaxOptions = $.extend({}, this.def" +
- "aultOptions, {\r\n\t\t\turl: $.proxies.baseUrl + url,\r\n\t\t\ttype: type,\r\n\t\t\tbeforeSend " +
- ": function(xhr) {\r\n\t\t\t\tif (typeof(webApiAuthToken) != \"undefined\" && webApiAuthT" +
- "oken.length > 0)\r\n\t\t\t\t\txhr.setRequestHeader(\"Authorization\", \"Bearer \" + webApiA" +
- "uthToken);\r\n\t\t\t},\r\n\t\t});\r\n\r\n\t\tif (body) {\r\n\t\t\tajaxOptions.data = body;\r\n\t\t}\r\n\r\n\t" +
- "\tif (this.antiForgeryToken) {\r\n\t\t\tvar token = $.isFunction(this.antiForgeryToken" +
- ") ? this.antiForgeryToken() : this.antiForgeryToken;\r\n\t\t\tif (token) {\r\n\t\t\t\tajaxO" +
- "ptions.headers = ajaxOptions.headers || {};\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\treturn $.ajax(ajaxO" +
- "ptions);\r\n\t}\r\n\r\n\tfunction defaultAntiForgeryTokenAccessor() {\r\n\t\treturn $(\"input" +
- "[name=__RequestVerificationToken]\").val();\r\n\t}\r\n\r\n\tfunction endsWith(str, suffix" +
- ") {\r\n\t\treturn str.indexOf(suffix, str.length - suffix.length) !== -1;\r\n\t}\r\n\r\n\tfu" +
- "nction appendPathDelimiter(url){\r\n\t\tif(!endsWith(url, \'/\')){\r\n\t\t\treturn url + \'/" +
- "\';\r\n\t\t}\r\n\t\t\r\n\t\treturn url;\r\n\t}\r\n\r\n\t/* Proxies */\r\n\r\n\t");
-
- #line 90 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- foreach(var definition in this.Metadata.Definitions) {
-
- #line default
- #line hidden
- this.Write("\t$.proxies.");
-
- #line 91 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name.ToLower()));
-
- #line default
- #line hidden
- this.Write(" = {\r\n\t\tdefaultOptions: {},\r\n\t\tantiForgeryToken: defaultAntiForgeryTokenAccessor," +
- "\r\n");
-
- #line 94 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- foreach(var method in definition.ActionMethods) {
-
- #line default
- #line hidden
- this.Write("\r\n");
-
- #line 96 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
-
- var allParameters = method.UrlParameters.AsEnumerable();
-
- if (method.BodyParameter != null) {
- allParameters = allParameters.Concat(new [] { method.BodyParameter });
- }
- var selectedParameters = allParameters.Where(m => m != null).Select(m => m.Name).ToList();
- selectedParameters.Add("options");
-
- var parameterList = string.Join(",", selectedParameters);
-
-
-
- var url = ("\"" + method.Url.Replace("{", "\" + ").Replace("}", " + \"") + "\"").Replace(" + \"\"","");
-
-
-
- #line default
- #line hidden
- this.Write("\r\n\r\n\t");
-
- #line 114 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(method.Name.ToCamelCasing()));
-
- #line default
- #line hidden
- this.Write(": function(");
-
- #line 114 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(parameterList));
-
- #line default
- #line hidden
- this.Write(") {\r\n\t\t var defaults = { fields: [] };\r\n var settings = $.extend({}, defa" +
- "ults, options || {});\r\n\t\t var url = ");
-
- #line 117 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(url));
-
- #line default
- #line hidden
- this.Write(";\r\n\r\n\t\t if(settings.fields.length > 0) {\r\n\t\t url += url.indexOf(\"?\") == -1 ? " +
- "\"?\" : \"&\";\r\n\t\t\turl += \"fields=\" + settings.fields.join();\r\n\t\t }\r\n\r\n\t\treturn invo" +
- "ke.call(this, url, \"");
-
- #line 124 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(method.Type.ToString().ToLower()));
-
- #line default
- #line hidden
- this.Write("\", \r\n\t\t");
-
- #line 125 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- if (method.UrlParameters.Any()) {
-
- #line default
- #line hidden
- this.Write("\t\t\t{\r\n\t\t\t");
-
- #line 127 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- foreach (var parameter in method.UrlParameters) {
-
- #line default
- #line hidden
- this.Write("\t\t\t\t");
-
- #line 128 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name));
-
- #line default
- #line hidden
- this.Write(": ");
-
- #line 128 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name));
-
- #line default
- #line hidden
- this.Write(",\r\n\t\t\t");
-
- #line 129 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write("\t\t\t}\r\n\t\t");
-
- #line 131 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- } else {
-
- #line default
- #line hidden
- this.Write("\t\t\t{}\r\n\t\t");
-
- #line 133 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write("\t\t");
-
- #line 134 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- if (method.BodyParameter != null) {
-
- #line default
- #line hidden
- this.Write("\t\t\t, ");
-
- #line 135 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(method.BodyParameter.Name));
-
- #line default
- #line hidden
- this.Write(");\r\n\t\t");
-
- #line 136 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- } else {
-
- #line default
- #line hidden
- this.Write("\t\t\t);\r\n\t\t");
-
- #line 138 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write("\t},\r\n");
-
- #line 140 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write(" \r\n};\r\n\t");
-
- #line 142 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write("}(jQuery));\r\n");
- return this.GenerationEnvironment.ToString();
- }
- }
-
- #line default
- #line hidden
- #region Base class
- ///
- /// Base class for this transformation
- ///
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")]
- public class JsProxyTemplateBase
- {
- #region Fields
- private global::System.Text.StringBuilder generationEnvironmentField;
- private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField;
- private global::System.Collections.Generic.List indentLengthsField;
- private string currentIndentField = "";
- private bool endsWithNewline;
- private global::System.Collections.Generic.IDictionary sessionField;
- #endregion
- #region Properties
- ///
- /// The string builder that generation-time code is using to assemble generated output
- ///
- protected System.Text.StringBuilder GenerationEnvironment
- {
- get
- {
- if ((this.generationEnvironmentField == null))
- {
- this.generationEnvironmentField = new global::System.Text.StringBuilder();
- }
- return this.generationEnvironmentField;
- }
- set
- {
- this.generationEnvironmentField = value;
- }
- }
- ///
- /// The error collection for the generation process
- ///
- public System.CodeDom.Compiler.CompilerErrorCollection Errors
- {
- get
- {
- if ((this.errorsField == null))
- {
- this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection();
- }
- return this.errorsField;
- }
- }
- ///
- /// A list of the lengths of each indent that was added with PushIndent
- ///
- private System.Collections.Generic.List indentLengths
- {
- get
- {
- if ((this.indentLengthsField == null))
- {
- this.indentLengthsField = new global::System.Collections.Generic.List();
- }
- return this.indentLengthsField;
- }
- }
- ///
- /// Gets the current indent we use when adding lines to the output
- ///
- public string CurrentIndent
- {
- get
- {
- return this.currentIndentField;
- }
- }
- ///
- /// Current transformation session
- ///
- public virtual global::System.Collections.Generic.IDictionary Session
- {
- get
- {
- return this.sessionField;
- }
- set
- {
- this.sessionField = value;
- }
- }
- #endregion
- #region Transform-time helpers
- ///
- /// Write text directly into the generated output
- ///
- public void Write(string textToAppend)
- {
- if (string.IsNullOrEmpty(textToAppend))
- {
- return;
- }
- // If we're starting off, or if the previous text ended with a newline,
- // we have to append the current indent first.
- if (((this.GenerationEnvironment.Length == 0)
- || this.endsWithNewline))
- {
- this.GenerationEnvironment.Append(this.currentIndentField);
- this.endsWithNewline = false;
- }
- // Check if the current text ends with a newline
- if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture))
- {
- this.endsWithNewline = true;
- }
- // This is an optimization. If the current indent is "", then we don't have to do any
- // of the more complex stuff further down.
- if ((this.currentIndentField.Length == 0))
- {
- this.GenerationEnvironment.Append(textToAppend);
- return;
- }
- // Everywhere there is a newline in the text, add an indent after it
- textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField));
- // If the text ends with a newline, then we should strip off the indent added at the very end
- // because the appropriate indent will be added when the next time Write() is called
- if (this.endsWithNewline)
- {
- this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length));
- }
- else
- {
- this.GenerationEnvironment.Append(textToAppend);
- }
- }
- ///
- /// Write text directly into the generated output
- ///
- public void WriteLine(string textToAppend)
- {
- this.Write(textToAppend);
- this.GenerationEnvironment.AppendLine();
- this.endsWithNewline = true;
- }
- ///
- /// Write formatted text directly into the generated output
- ///
- public void Write(string format, params object[] args)
- {
- this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
- }
- ///
- /// Write formatted text directly into the generated output
- ///
- public void WriteLine(string format, params object[] args)
- {
- this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
- }
- ///
- /// Raise an error
- ///
- public void Error(string message)
- {
- System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
- error.ErrorText = message;
- this.Errors.Add(error);
- }
- ///
- /// Raise a warning
- ///
- public void Warning(string message)
- {
- System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
- error.ErrorText = message;
- error.IsWarning = true;
- this.Errors.Add(error);
- }
- ///
- /// Increase the indent
- ///
- public void PushIndent(string indent)
- {
- if ((indent == null))
- {
- throw new global::System.ArgumentNullException("indent");
- }
- this.currentIndentField = (this.currentIndentField + indent);
- this.indentLengths.Add(indent.Length);
- }
- ///
- /// Remove the last indent that was added with PushIndent
- ///
- public string PopIndent()
- {
- string returnValue = "";
- if ((this.indentLengths.Count > 0))
- {
- int indentLength = this.indentLengths[(this.indentLengths.Count - 1)];
- this.indentLengths.RemoveAt((this.indentLengths.Count - 1));
- if ((indentLength > 0))
- {
- returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength));
- this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength));
- }
- }
- return returnValue;
- }
- ///
- /// Remove any indentation
- ///
- public void ClearIndent()
- {
- this.indentLengths.Clear();
- this.currentIndentField = "";
- }
- #endregion
- #region ToString Helpers
- ///
- /// Utility class to produce culture-oriented representation of an object as a string.
- ///
- public class ToStringInstanceHelper
- {
- private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture;
- ///
- /// Gets or sets format provider to be used by ToStringWithCulture method.
- ///
- public System.IFormatProvider FormatProvider
- {
- get
- {
- return this.formatProviderField ;
- }
- set
- {
- if ((value != null))
- {
- this.formatProviderField = value;
- }
- }
- }
- ///
- /// This is called from the compile/run appdomain to convert objects within an expression block to a string
- ///
- public string ToStringWithCulture(object objectToConvert)
- {
- if ((objectToConvert == null))
- {
- throw new global::System.ArgumentNullException("objectToConvert");
- }
- System.Type t = objectToConvert.GetType();
- System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] {
- typeof(System.IFormatProvider)});
- if ((method == null))
- {
- return objectToConvert.ToString();
- }
- else
- {
- return ((string)(method.Invoke(objectToConvert, new object[] {
- this.formatProviderField })));
- }
- }
- }
- private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper();
- ///
- /// Helper to produce culture-oriented representation of an object as a string
- ///
- public ToStringInstanceHelper ToStringHelper
- {
- get
- {
- return this.toStringHelperField;
- }
- }
- #endregion
- }
- #endregion
-}
+// ------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+// Runtime Version: 14.0.0.0
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+// ------------------------------------------------------------------------------
+namespace WebApiProxy.Server.Templates
+{
+ using System.Linq;
+ using System.Text;
+ using System.Collections.Generic;
+ using System;
+
+ ///
+ /// Class to produce the template output
+ ///
+
+ #line 1 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")]
+ public partial class JsProxyTemplate : JsProxyTemplateBase
+ {
+#line hidden
+ ///
+ /// Create the template output
+ ///
+ public virtual string TransformText()
+ {
+ this.Write("\r\n(function($) {\r\n\t\"use strict\";\r\n\r\n\tif (!$) {\r\n\t\tthrow \"jQuery is required\";\r\n\t}" +
+ "\r\n\r\n\t$.proxies = $.proxies || { \r\n\t\tbaseUrl: \"");
+
+ #line 15 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(this.Metadata.Host));
+
+ #line default
+ #line hidden
+ this.Write("\"\r\n\t};\r\n\r\n\tfunction getQueryString(params, queryString) {\r\n\t\tqueryString = queryS" +
+ "tring || \"\";\r\n\t\tfor(var prop in params) {\r\n\t\t\tif (params.hasOwnProperty(prop)) {" +
+ "\r\n\t\t\t\tvar val = getArgValue(params[prop]);\r\n\t\t\t\tif (val === null) continue;\r\n\r\n\t" +
+ "\t\t\tif (\"\" + val === \"[object Object]\") {\r\n\t\t\t\t\tqueryString = getQueryString(para" +
+ "ms[prop], queryString);\r\n\t\t\t\t\tcontinue;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (queryString.length) {\r" +
+ "\n\t\t\t\t\tqueryString += \"&\";\r\n\t\t\t\t} else {\r\n\t\t\t\t\tqueryString += \"?\";\r\n\t\t\t\t}\r\n\t\t\t\tqu" +
+ "eryString = queryString + prop + \"=\" +val;\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn queryString;\r\n\t}" +
+ "\r\n\r\n\tfunction getArgValue(val) {\r\n\t\tif (val === undefined || val === null) retur" +
+ "n null;\r\n\t\treturn val;\r\n\t}\r\n\r\n\tfunction invoke(url, type, urlParams, body) {\r\n\t\t" +
+ "//url += getQueryString(urlParams);\r\n\r\n\t\tvar ajaxOptions = $.extend({}, this.def" +
+ "aultOptions, {\r\n\t\t\turl: $.proxies.baseUrl + url,\r\n\t\t\ttype: type,\r\n\t\t\tbeforeSend " +
+ ": function(xhr) {\r\n\t\t\t\tif (typeof(webApiAuthToken) != \"undefined\" && webApiAuthT" +
+ "oken.length > 0)\r\n\t\t\t\t\txhr.setRequestHeader(\"Authorization\", \"Bearer \" + webApiA" +
+ "uthToken);\r\n\t\t\t},\r\n\t\t});\r\n\r\n\t\tif (body) {\r\n\t\t\tajaxOptions.data = body;\r\n\t\t}\r\n\r\n\t" +
+ "\tif (this.antiForgeryToken) {\r\n\t\t\tvar token = $.isFunction(this.antiForgeryToken" +
+ ") ? this.antiForgeryToken() : this.antiForgeryToken;\r\n\t\t\tif (token) {\r\n\t\t\t\tajaxO" +
+ "ptions.headers = ajaxOptions.headers || {};\r\n\t\t\t}\r\n\t\t}\r\n\t\r\n\t\treturn $.ajax(ajaxO" +
+ "ptions);\r\n\t}\r\n\r\n\tfunction defaultAntiForgeryTokenAccessor() {\r\n\t\treturn $(\"input" +
+ "[name=__RequestVerificationToken]\").val();\r\n\t}\r\n\r\n\tfunction endsWith(str, suffix" +
+ ") {\r\n\t\treturn str.indexOf(suffix, str.length - suffix.length) !== -1;\r\n\t}\r\n\r\n\tfu" +
+ "nction appendPathDelimiter(url){\r\n\t\tif(!endsWith(url, \'/\')){\r\n\t\t\treturn url + \'/" +
+ "\';\r\n\t\t}\r\n\t\t\r\n\t\treturn url;\r\n\t}\r\n\r\n\t/* Proxies */\r\n\r\n\t");
+
+ #line 90 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ foreach(var definition in this.Metadata.Definitions) {
+
+ #line default
+ #line hidden
+ this.Write("\t$.proxies.");
+
+ #line 91 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name.ToLower()));
+
+ #line default
+ #line hidden
+ this.Write(" = {\r\n\t\tdefaultOptions: {},\r\n\t\tantiForgeryToken: defaultAntiForgeryTokenAccessor," +
+ "\r\n");
+
+ #line 94 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ foreach(var method in definition.ActionMethods) {
+
+ #line default
+ #line hidden
+ this.Write("\r\n");
+
+ #line 96 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+
+ var allParameters = method.UrlParameters.AsEnumerable();
+
+ if (method.BodyParameter != null) {
+ allParameters = allParameters.Concat(new [] { method.BodyParameter });
+ }
+ var selectedParameters = allParameters.Where(m => m != null).Select(m => m.Name).ToList();
+ selectedParameters.Add("options");
+
+ var parameterList = string.Join(",", selectedParameters);
+
+
+
+ var url = ("\"" + method.Url.Replace("{", "\" + ").Replace("}", " + \"") + "\"").Replace(" + \"\"","");
+
+
+
+ #line default
+ #line hidden
+ this.Write("\r\n\r\n\t");
+
+ #line 114 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name.ToCamelCasing()));
+
+ #line default
+ #line hidden
+ this.Write(": function(");
+
+ #line 114 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(parameterList));
+
+ #line default
+ #line hidden
+ this.Write(") {\r\n\t\t var defaults = { fields: [] };\r\n var settings = $.extend({}, defa" +
+ "ults, options || {});\r\n\t\t var url = ");
+
+ #line 117 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(url));
+
+ #line default
+ #line hidden
+ this.Write(";\r\n\r\n\t\t if(settings.fields.length > 0) {\r\n\t\t url += url.indexOf(\"?\") == -1 ? " +
+ "\"?\" : \"&\";\r\n\t\t\turl += \"fields=\" + settings.fields.join();\r\n\t\t }\r\n\r\n\t\treturn invo" +
+ "ke.call(this, url, \"");
+
+ #line 124 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Type.ToString().ToLower()));
+
+ #line default
+ #line hidden
+ this.Write("\", \r\n\t\t");
+
+ #line 125 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ if (method.UrlParameters.Any()) {
+
+ #line default
+ #line hidden
+ this.Write("\t\t\t{\r\n\t\t\t");
+
+ #line 127 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ foreach (var parameter in method.UrlParameters) {
+
+ #line default
+ #line hidden
+ this.Write("\t\t\t\t");
+
+ #line 128 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name));
+
+ #line default
+ #line hidden
+ this.Write(": ");
+
+ #line 128 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(parameter.Name));
+
+ #line default
+ #line hidden
+ this.Write(",\r\n\t\t\t");
+
+ #line 129 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\t\t\t}\r\n\t\t");
+
+ #line 131 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ } else {
+
+ #line default
+ #line hidden
+ this.Write("\t\t\t{}\r\n\t\t");
+
+ #line 133 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\t\t");
+
+ #line 134 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ if (method.BodyParameter != null) {
+
+ #line default
+ #line hidden
+ this.Write("\t\t\t, ");
+
+ #line 135 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.BodyParameter.Name));
+
+ #line default
+ #line hidden
+ this.Write(");\r\n\t\t");
+
+ #line 136 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ } else {
+
+ #line default
+ #line hidden
+ this.Write("\t\t\t);\r\n\t\t");
+
+ #line 138 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\t},\r\n");
+
+ #line 140 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write(" \r\n};\r\n\t");
+
+ #line 142 "C:\dev\WebApiProxy\WebApiProxy.Server\Templates\JsProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("}(jQuery));\r\n");
+ return this.GenerationEnvironment.ToString();
+ }
+ }
+
+ #line default
+ #line hidden
+ #region Base class
+ ///
+ /// Base class for this transformation
+ ///
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")]
+ public class JsProxyTemplateBase
+ {
+ #region Fields
+ private global::System.Text.StringBuilder generationEnvironmentField;
+ private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField;
+ private global::System.Collections.Generic.List indentLengthsField;
+ private string currentIndentField = "";
+ private bool endsWithNewline;
+ private global::System.Collections.Generic.IDictionary sessionField;
+ #endregion
+ #region Properties
+ ///
+ /// The string builder that generation-time code is using to assemble generated output
+ ///
+ protected System.Text.StringBuilder GenerationEnvironment
+ {
+ get
+ {
+ if ((this.generationEnvironmentField == null))
+ {
+ this.generationEnvironmentField = new global::System.Text.StringBuilder();
+ }
+ return this.generationEnvironmentField;
+ }
+ set
+ {
+ this.generationEnvironmentField = value;
+ }
+ }
+ ///
+ /// The error collection for the generation process
+ ///
+ public System.CodeDom.Compiler.CompilerErrorCollection Errors
+ {
+ get
+ {
+ if ((this.errorsField == null))
+ {
+ this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection();
+ }
+ return this.errorsField;
+ }
+ }
+ ///
+ /// A list of the lengths of each indent that was added with PushIndent
+ ///
+ private System.Collections.Generic.List indentLengths
+ {
+ get
+ {
+ if ((this.indentLengthsField == null))
+ {
+ this.indentLengthsField = new global::System.Collections.Generic.List();
+ }
+ return this.indentLengthsField;
+ }
+ }
+ ///
+ /// Gets the current indent we use when adding lines to the output
+ ///
+ public string CurrentIndent
+ {
+ get
+ {
+ return this.currentIndentField;
+ }
+ }
+ ///
+ /// Current transformation session
+ ///
+ public virtual global::System.Collections.Generic.IDictionary Session
+ {
+ get
+ {
+ return this.sessionField;
+ }
+ set
+ {
+ this.sessionField = value;
+ }
+ }
+ #endregion
+ #region Transform-time helpers
+ ///
+ /// Write text directly into the generated output
+ ///
+ public void Write(string textToAppend)
+ {
+ if (string.IsNullOrEmpty(textToAppend))
+ {
+ return;
+ }
+ // If we're starting off, or if the previous text ended with a newline,
+ // we have to append the current indent first.
+ if (((this.GenerationEnvironment.Length == 0)
+ || this.endsWithNewline))
+ {
+ this.GenerationEnvironment.Append(this.currentIndentField);
+ this.endsWithNewline = false;
+ }
+ // Check if the current text ends with a newline
+ if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture))
+ {
+ this.endsWithNewline = true;
+ }
+ // This is an optimization. If the current indent is "", then we don't have to do any
+ // of the more complex stuff further down.
+ if ((this.currentIndentField.Length == 0))
+ {
+ this.GenerationEnvironment.Append(textToAppend);
+ return;
+ }
+ // Everywhere there is a newline in the text, add an indent after it
+ textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField));
+ // If the text ends with a newline, then we should strip off the indent added at the very end
+ // because the appropriate indent will be added when the next time Write() is called
+ if (this.endsWithNewline)
+ {
+ this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length));
+ }
+ else
+ {
+ this.GenerationEnvironment.Append(textToAppend);
+ }
+ }
+ ///
+ /// Write text directly into the generated output
+ ///
+ public void WriteLine(string textToAppend)
+ {
+ this.Write(textToAppend);
+ this.GenerationEnvironment.AppendLine();
+ this.endsWithNewline = true;
+ }
+ ///
+ /// Write formatted text directly into the generated output
+ ///
+ public void Write(string format, params object[] args)
+ {
+ this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
+ }
+ ///
+ /// Write formatted text directly into the generated output
+ ///
+ public void WriteLine(string format, params object[] args)
+ {
+ this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
+ }
+ ///
+ /// Raise an error
+ ///
+ public void Error(string message)
+ {
+ System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
+ error.ErrorText = message;
+ this.Errors.Add(error);
+ }
+ ///
+ /// Raise a warning
+ ///
+ public void Warning(string message)
+ {
+ System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
+ error.ErrorText = message;
+ error.IsWarning = true;
+ this.Errors.Add(error);
+ }
+ ///
+ /// Increase the indent
+ ///
+ public void PushIndent(string indent)
+ {
+ if ((indent == null))
+ {
+ throw new global::System.ArgumentNullException("indent");
+ }
+ this.currentIndentField = (this.currentIndentField + indent);
+ this.indentLengths.Add(indent.Length);
+ }
+ ///
+ /// Remove the last indent that was added with PushIndent
+ ///
+ public string PopIndent()
+ {
+ string returnValue = "";
+ if ((this.indentLengths.Count > 0))
+ {
+ int indentLength = this.indentLengths[(this.indentLengths.Count - 1)];
+ this.indentLengths.RemoveAt((this.indentLengths.Count - 1));
+ if ((indentLength > 0))
+ {
+ returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength));
+ this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength));
+ }
+ }
+ return returnValue;
+ }
+ ///
+ /// Remove any indentation
+ ///
+ public void ClearIndent()
+ {
+ this.indentLengths.Clear();
+ this.currentIndentField = "";
+ }
+ #endregion
+ #region ToString Helpers
+ ///
+ /// Utility class to produce culture-oriented representation of an object as a string.
+ ///
+ public class ToStringInstanceHelper
+ {
+ private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture;
+ ///
+ /// Gets or sets format provider to be used by ToStringWithCulture method.
+ ///
+ public System.IFormatProvider FormatProvider
+ {
+ get
+ {
+ return this.formatProviderField ;
+ }
+ set
+ {
+ if ((value != null))
+ {
+ this.formatProviderField = value;
+ }
+ }
+ }
+ ///
+ /// This is called from the compile/run appdomain to convert objects within an expression block to a string
+ ///
+ public string ToStringWithCulture(object objectToConvert)
+ {
+ if ((objectToConvert == null))
+ {
+ throw new global::System.ArgumentNullException("objectToConvert");
+ }
+ System.Type t = objectToConvert.GetType();
+ System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] {
+ typeof(System.IFormatProvider)});
+ if ((method == null))
+ {
+ return objectToConvert.ToString();
+ }
+ else
+ {
+ return ((string)(method.Invoke(objectToConvert, new object[] {
+ this.formatProviderField })));
+ }
+ }
+ }
+ private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper();
+ ///
+ /// Helper to produce culture-oriented representation of an object as a string
+ ///
+ public ToStringInstanceHelper ToStringHelper
+ {
+ get
+ {
+ return this.toStringHelperField;
+ }
+ }
+ #endregion
+ }
+ #endregion
+}
diff --git a/WebApiProxy.Server/Templates/JsProxyTemplate.tt b/WebApiProxy.Server/Templates/JsProxyTemplate.tt
index 8c44cbe..1571ab3 100644
--- a/WebApiProxy.Server/Templates/JsProxyTemplate.tt
+++ b/WebApiProxy.Server/Templates/JsProxyTemplate.tt
@@ -1,143 +1,143 @@
-<#@ template language="C#" #>
-<#@ assembly name="System.Core" #>
-<#@ import namespace="System.Linq" #>
-<#@ import namespace="System.Text" #>
-<#@ import namespace="System.Collections.Generic" #>
-
-(function($) {
- "use strict";
-
- if (!$) {
- throw "jQuery is required";
- }
-
- $.proxies = $.proxies || {
- baseUrl: "<#= this.Metadata.Host #>"
- };
-
- function getQueryString(params, queryString) {
- queryString = queryString || "";
- for(var prop in params) {
- if (params.hasOwnProperty(prop)) {
- var val = getArgValue(params[prop]);
- if (val === null) continue;
-
- if ("" + val === "[object Object]") {
- queryString = getQueryString(params[prop], queryString);
- continue;
- }
-
- if (queryString.length) {
- queryString += "&";
- } else {
- queryString += "?";
- }
- queryString = queryString + prop + "=" +val;
- }
- }
- return queryString;
- }
-
- function getArgValue(val) {
- if (val === undefined || val === null) return null;
- return val;
- }
-
- function invoke(url, type, urlParams, body) {
- //url += getQueryString(urlParams);
-
- var ajaxOptions = $.extend({}, this.defaultOptions, {
- url: $.proxies.baseUrl + url,
- type: type,
- beforeSend : function(xhr) {
- if (typeof(webApiAuthToken) != "undefined" && webApiAuthToken.length > 0)
- xhr.setRequestHeader("Authorization", "Bearer " + webApiAuthToken);
- },
- });
-
- if (body) {
- ajaxOptions.data = body;
- }
-
- if (this.antiForgeryToken) {
- var token = $.isFunction(this.antiForgeryToken) ? this.antiForgeryToken() : this.antiForgeryToken;
- if (token) {
- ajaxOptions.headers = ajaxOptions.headers || {};
- }
- }
-
- return $.ajax(ajaxOptions);
- }
-
- function defaultAntiForgeryTokenAccessor() {
- return $("input[name=__RequestVerificationToken]").val();
- }
-
- function endsWith(str, suffix) {
- return str.indexOf(suffix, str.length - suffix.length) !== -1;
- }
-
- function appendPathDelimiter(url){
- if(!endsWith(url, '/')){
- return url + '/';
- }
-
- return url;
- }
-
- /* Proxies */
-
- <# foreach(var definition in this.Metadata.Definitions) { #>
- $.proxies.<#= definition.Name.ToLower() #> = {
- defaultOptions: {},
- antiForgeryToken: defaultAntiForgeryTokenAccessor,
-<# foreach(var method in definition.ActionMethods) { #>
-
-<#
- var allParameters = method.UrlParameters.AsEnumerable();
-
- if (method.BodyParameter != null) {
- allParameters = allParameters.Concat(new [] { method.BodyParameter });
- }
- var selectedParameters = allParameters.Where(m => m != null).Select(m => m.Name).ToList();
- selectedParameters.Add("options");
-
- var parameterList = string.Join(",", selectedParameters);
-
-
-
- var url = ("\"" + method.Url.Replace("{", "\" + ").Replace("}", " + \"") + "\"").Replace(" + \"\"","");
-
-#>
-
-
- <#= method.Name.ToCamelCasing() #>: function(<#=parameterList#>) {
- var defaults = { fields: [] };
- var settings = $.extend({}, defaults, options || {});
- var url = <#= url #>;
-
- if(settings.fields.length > 0) {
- url += url.indexOf("?") == -1 ? "?" : "&";
- url += "fields=" + settings.fields.join();
- }
-
- return invoke.call(this, url, "<#= method.Type.ToString().ToLower() #>",
- <# if (method.UrlParameters.Any()) { #>
- {
- <# foreach (var parameter in method.UrlParameters) { #>
- <#= parameter.Name #>: <#= parameter.Name #>,
- <# } #>
- }
- <# } else { #>
- {}
- <# } #>
- <# if (method.BodyParameter != null) { #>
- , <#= method.BodyParameter.Name #>);
- <# } else { #>
- );
- <# } #>
- },
-<# } #>
-};
- <# } #>
-}(jQuery));
+<#@ template language="C#" #>
+<#@ assembly name="System.Core" #>
+<#@ import namespace="System.Linq" #>
+<#@ import namespace="System.Text" #>
+<#@ import namespace="System.Collections.Generic" #>
+
+(function($) {
+ "use strict";
+
+ if (!$) {
+ throw "jQuery is required";
+ }
+
+ $.proxies = $.proxies || {
+ baseUrl: "<#= this.Metadata.Host #>"
+ };
+
+ function getQueryString(params, queryString) {
+ queryString = queryString || "";
+ for(var prop in params) {
+ if (params.hasOwnProperty(prop)) {
+ var val = getArgValue(params[prop]);
+ if (val === null) continue;
+
+ if ("" + val === "[object Object]") {
+ queryString = getQueryString(params[prop], queryString);
+ continue;
+ }
+
+ if (queryString.length) {
+ queryString += "&";
+ } else {
+ queryString += "?";
+ }
+ queryString = queryString + prop + "=" +val;
+ }
+ }
+ return queryString;
+ }
+
+ function getArgValue(val) {
+ if (val === undefined || val === null) return null;
+ return val;
+ }
+
+ function invoke(url, type, urlParams, body) {
+ //url += getQueryString(urlParams);
+
+ var ajaxOptions = $.extend({}, this.defaultOptions, {
+ url: $.proxies.baseUrl + url,
+ type: type,
+ beforeSend : function(xhr) {
+ if (typeof(webApiAuthToken) != "undefined" && webApiAuthToken.length > 0)
+ xhr.setRequestHeader("Authorization", "Bearer " + webApiAuthToken);
+ },
+ });
+
+ if (body) {
+ ajaxOptions.data = body;
+ }
+
+ if (this.antiForgeryToken) {
+ var token = $.isFunction(this.antiForgeryToken) ? this.antiForgeryToken() : this.antiForgeryToken;
+ if (token) {
+ ajaxOptions.headers = ajaxOptions.headers || {};
+ }
+ }
+
+ return $.ajax(ajaxOptions);
+ }
+
+ function defaultAntiForgeryTokenAccessor() {
+ return $("input[name=__RequestVerificationToken]").val();
+ }
+
+ function endsWith(str, suffix) {
+ return str.indexOf(suffix, str.length - suffix.length) !== -1;
+ }
+
+ function appendPathDelimiter(url){
+ if(!endsWith(url, '/')){
+ return url + '/';
+ }
+
+ return url;
+ }
+
+ /* Proxies */
+
+ <# foreach(var definition in this.Metadata.Definitions) { #>
+ $.proxies.<#= definition.Name.ToLower() #> = {
+ defaultOptions: {},
+ antiForgeryToken: defaultAntiForgeryTokenAccessor,
+<# foreach(var method in definition.ActionMethods) { #>
+
+<#
+ var allParameters = method.UrlParameters.AsEnumerable();
+
+ if (method.BodyParameter != null) {
+ allParameters = allParameters.Concat(new [] { method.BodyParameter });
+ }
+ var selectedParameters = allParameters.Where(m => m != null).Select(m => m.Name).ToList();
+ selectedParameters.Add("options");
+
+ var parameterList = string.Join(",", selectedParameters);
+
+
+
+ var url = ("\"" + method.Url.Replace("{", "\" + ").Replace("}", " + \"") + "\"").Replace(" + \"\"","");
+
+#>
+
+
+ <#= method.Name.ToCamelCasing() #>: function(<#=parameterList#>) {
+ var defaults = { fields: [] };
+ var settings = $.extend({}, defaults, options || {});
+ var url = <#= url #>;
+
+ if(settings.fields.length > 0) {
+ url += url.indexOf("?") == -1 ? "?" : "&";
+ url += "fields=" + settings.fields.join();
+ }
+
+ return invoke.call(this, url, "<#= method.Type.ToString().ToLower() #>",
+ <# if (method.UrlParameters.Any()) { #>
+ {
+ <# foreach (var parameter in method.UrlParameters) { #>
+ <#= parameter.Name #>: <#= parameter.Name #>,
+ <# } #>
+ }
+ <# } else { #>
+ {}
+ <# } #>
+ <# if (method.BodyParameter != null) { #>
+ , <#= method.BodyParameter.Name #>);
+ <# } else { #>
+ );
+ <# } #>
+ },
+<# } #>
+};
+ <# } #>
+}(jQuery));
diff --git a/WebApiProxy.Server/TypeExtensions.cs b/WebApiProxy.Server/TypeExtensions.cs
index eb50e6e..eec8e93 100644
--- a/WebApiProxy.Server/TypeExtensions.cs
+++ b/WebApiProxy.Server/TypeExtensions.cs
@@ -1,13 +1,13 @@
-using System;
-using System.Linq;
-
-namespace WebApiProxy
-{
- public static class TypeExtensions
- {
- public static bool IsExcluded(this Type type)
- {
- return type.GetCustomAttributes(true).OfType().Any();
- }
- }
-}
+using System;
+using System.Linq;
+
+namespace WebApiProxy
+{
+ public static class TypeExtensions
+ {
+ public static bool IsExcluded(this Type type)
+ {
+ return type.GetCustomAttributes(true).OfType().Any();
+ }
+ }
+}
diff --git a/WebApiProxy.Server/WebApiProxy.Server.csproj b/WebApiProxy.Server/WebApiProxy.Server.csproj
index ade53e9..9230903 100644
--- a/WebApiProxy.Server/WebApiProxy.Server.csproj
+++ b/WebApiProxy.Server/WebApiProxy.Server.csproj
@@ -1,111 +1,111 @@
-
-
-
-
- Debug
- AnyCPU
- {4E5B8C2F-9008-4A17-ABD1-A92E046C6A1E}
- Library
- Properties
- WebApiProxy.Server
- WebApiProxy.Server
- v4.5
- 512
- ..\
- true
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\packages\DocsByReflection.1.0.11\lib\net40\DocsByReflection.dll
- True
-
-
- ..\packages\HelperSharp.0.0.4.2\lib\net35\HelperSharp.dll
- True
-
-
- ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll
- True
-
-
-
-
- ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll
- True
-
-
-
- ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll
- True
-
-
-
-
-
-
-
-
-
- True
- True
- JsProxyTemplate.tt
-
-
-
-
-
-
-
-
-
- TextTemplatingFilePreprocessor
- JsProxyTemplate.cs
-
-
- Designer
-
-
-
-
-
-
-
- {94508206-8537-4088-923b-e7fcb0539903}
- WebApiProxy.Core
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ Debug
+ AnyCPU
+ {4E5B8C2F-9008-4A17-ABD1-A92E046C6A1E}
+ Library
+ Properties
+ WebApiProxy.Server
+ WebApiProxy.Server
+ v4.5
+ 512
+ ..\
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ ..\packages\DocsByReflection.1.0.11\lib\net40\DocsByReflection.dll
+ True
+
+
+ ..\packages\HelperSharp.0.0.4.2\lib\net35\HelperSharp.dll
+ True
+
+
+ ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll
+ True
+
+
+
+
+ ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll
+ True
+
+
+
+ ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll
+ True
+
+
+
+
+
+
+
+
+
+ True
+ True
+ JsProxyTemplate.tt
+
+
+
+
+
+
+
+
+
+ TextTemplatingFilePreprocessor
+ JsProxyTemplate.cs
+
+
+ Designer
+
+
+
+
+
+
+
+ {94508206-8537-4088-923b-e7fcb0539903}
+ WebApiProxy.Core
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/WebApiProxy.Server/WebApiProxy.nuspec b/WebApiProxy.Server/WebApiProxy.nuspec
index 46f0165..d8755d1 100644
--- a/WebApiProxy.Server/WebApiProxy.nuspec
+++ b/WebApiProxy.Server/WebApiProxy.nuspec
@@ -1,23 +1,23 @@
-
-
-
- WebApiProxy
- $version$
- TGP WebApi Proxy Provider
- https://github.com/travisrussi/WebApiProxy
- Fanie Reynders, Travis Russi, TPG
- Fanie Reynders, Travis Russi
- false
- This package exposes an endpoint for ASP.NET Web Api services to serve a JavaScript proxy and metadata
-
- Copyright 2014
- AspNet WebAPI Proxy JavaScript CSharp
-
-
-
-
-
-
-
-
+
+
+
+ WebApiProxy
+ $version$
+ TGP WebApi Proxy Provider
+ https://github.com/travisrussi/WebApiProxy
+ Fanie Reynders, Travis Russi, TPG
+ Fanie Reynders, Travis Russi
+ false
+ This package exposes an endpoint for ASP.NET Web Api services to serve a JavaScript proxy and metadata
+
+ Copyright 2014
+ AspNet WebAPI Proxy JavaScript CSharp
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/WebApiProxy.Server/packages.config b/WebApiProxy.Server/packages.config
index 2c8a52d..f3e0edc 100644
--- a/WebApiProxy.Server/packages.config
+++ b/WebApiProxy.Server/packages.config
@@ -1,8 +1,8 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/WebApiProxy.Tasks/Infrastructure/CSharpGenerator.cs b/WebApiProxy.Tasks/Infrastructure/CSharpGenerator.cs
index 9fe6a2f..7cdde22 100644
--- a/WebApiProxy.Tasks/Infrastructure/CSharpGenerator.cs
+++ b/WebApiProxy.Tasks/Infrastructure/CSharpGenerator.cs
@@ -16,8 +16,8 @@ public CSharpGenerator(Configuration config)
public string Generate()
{
- config.Metadata = GetProxy();
- var template = new CSharpProxyTemplate(config);
+ var metaData = GetProxy();
+ var template = new CSharpProxyTemplate(config,metaData);
var source = template.TransformText();
return source;
}
@@ -25,22 +25,13 @@ public string Generate()
private Metadata GetProxy()
{
- var url = string.Empty;
-
- try
- {
- using (var client = new HttpClient())
- {
- client.DefaultRequestHeaders.Add("X-Proxy-Type", "metadata");
- var response = client.GetAsync(config.Endpoint).Result;
- response.EnsureSuccessStatusCode();
- var metadata = response.Content.ReadAsAsync().Result;
- return metadata;
- }
- }
- catch (Exception ex)
+ using (var client = new HttpClient())
{
- throw ex;
+ client.DefaultRequestHeaders.Add("X-Proxy-Type", "metadata");
+ var response = client.GetAsync(config.Endpoint).Result;
+ response.EnsureSuccessStatusCode();
+ var metadata = response.Content.ReadAsAsync().Result;
+ return metadata;
}
}
}
diff --git a/WebApiProxy.Tasks/Models/Configuration.cs b/WebApiProxy.Tasks/Models/Configuration.cs
index 08ffd90..8219dc5 100644
--- a/WebApiProxy.Tasks/Models/Configuration.cs
+++ b/WebApiProxy.Tasks/Models/Configuration.cs
@@ -1,12 +1,5 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Xml;
+using System.IO;
using System.Xml.Serialization;
-using WebApiProxy.Core.Models;
namespace WebApiProxy.Tasks.Models
{
@@ -14,7 +7,7 @@ namespace WebApiProxy.Tasks.Models
public class Configuration
{
public const string ConfigFileName = "WebApiProxy.config";
- public const string CacheFile = "WebApiProxy.generated.cache";
+ public const string JsonConfigFileName = "WebApiProxy.json";
private string _clientSuffix = "Client";
private string _name = "MyWebApiProxy";
@@ -48,8 +41,6 @@ public string ClientSuffix
}
}
-
-
[XmlAttribute("namespace")]
public string Namespace
{
@@ -80,44 +71,33 @@ public string Name
public string Endpoint { get; set; }
[XmlAttribute("generateAsyncReturnTypes")]
- public bool GenerateAsyncReturnTypes
+ public bool GenerateAsyncReturnTypes
{
- get
- {
- return _generateAsyncReturnTypes;
- }
- set
- {
- _generateAsyncReturnTypes = value;
- }
+ get
+ {
+ return _generateAsyncReturnTypes;
+ }
+ set
+ {
+ _generateAsyncReturnTypes = value;
+ }
}
- //[XmlAttribute("host")]
- //public string Host { get; set; }
-
- [XmlIgnore]
- public Metadata Metadata { get; set; }
public static Configuration Load(string root)
{
var fileName = root + Configuration.ConfigFileName;
- if (!File.Exists(fileName))
+ if (!File.Exists(fileName))
{
- throw new ConfigFileNotFoundException(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;
- //}
-
return config;
}
diff --git a/WebApiProxy.Tasks/Models/GenerateConfig.cs b/WebApiProxy.Tasks/Models/GenerateConfig.cs
new file mode 100644
index 0000000..fa81307
--- /dev/null
+++ b/WebApiProxy.Tasks/Models/GenerateConfig.cs
@@ -0,0 +1,46 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace WebApiProxy.Tasks.Models
+{
+ public class GenerateConfig
+ {
+ public bool GenerateOnBuild { get; set; }
+ public bool GenerateAsyncReturnTypes { get; set; }
+
+ public IEnumerable Services { get; set; }
+
+
+ public class ServiceConfig
+ {
+ public ServiceConfig()
+ {
+ ClientSuffix = "Client";
+ }
+
+ public string ProxyEndpoint { get; set; }
+ public string Namespace { get; set; }
+ public string Name { get; set; }
+
+ public string ClientSuffix { get; set; }
+
+ public bool IncludeValidation { get; set; }
+ public bool EnsureSuccess { get; set; }
+ }
+
+
+ public IEnumerable TransformToOldConfig()
+ {
+ return Services.Select(service => new Configuration
+ {
+ GenerateOnBuild = GenerateOnBuild,
+ GenerateAsyncReturnTypes = GenerateAsyncReturnTypes,
+ Endpoint = service.ProxyEndpoint,
+ ClientSuffix = service.ClientSuffix,
+ Namespace = service.Namespace,
+ Name = service.Name
+ });
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/WebApiProxy.Tasks/Models/WebApiProxyResponseException.cs b/WebApiProxy.Tasks/Models/WebApiProxyResponseException.cs
new file mode 100644
index 0000000..9cc02f5
--- /dev/null
+++ b/WebApiProxy.Tasks/Models/WebApiProxyResponseException.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Net.Http;
+
+namespace WebApiProxy.Tasks.Models
+{
+ public class WebApiProxyResponseException : Exception
+ {
+
+ public HttpResponseMessage Response { get; private set; }
+
+
+ public WebApiProxyResponseException(HttpResponseMessage response) : base("A " + response.StatusCode + " (" + (int)response.StatusCode + ") http exception occured. See response.")
+ {
+ Response = response;
+ }
+ }
+}
\ No newline at end of file
diff --git a/WebApiProxy.Tasks/ProxyGenerationTask.cs b/WebApiProxy.Tasks/ProxyGenerationTask.cs
index 33abc77..8d23957 100644
--- a/WebApiProxy.Tasks/ProxyGenerationTask.cs
+++ b/WebApiProxy.Tasks/ProxyGenerationTask.cs
@@ -1,63 +1,61 @@
-using System;
-using System.IO;
-using Microsoft.Build.Framework;
-using WebApiProxy.Tasks.Infrastructure;
-using WebApiProxy.Tasks.Models;
-
-namespace WebApiProxy.Tasks
-{
- public class ProxyGenerationTask : ITask
- {
- private Configuration config;
-
- [Output]
- public string Filename { get; set; }
-
- [Output]
- public string Root { get; set; }
-
- [Output]
- public string ProjectPath { get; set; }
-
- public IBuildEngine BuildEngine { get; set; }
-
- public ITaskHost HostObject { get; set; }
-
- public bool Execute()
- {
- try
- {
- config = Configuration.Load(Root);
-
- if (config.GenerateOnBuild)
- {
- var generator = new CSharpGenerator(config);
- var source = generator.Generate();
- File.WriteAllText(Filename, source);
- File.WriteAllText(Configuration.CacheFile, source);
-
- }
- }
- catch (ConnectionException)
- {
- tryReadFromCache();
- }
- catch (Exception ex)
- {
- throw ex;
- }
-
- return true;
- }
-
- private void tryReadFromCache()
- {
- if (!File.Exists(Configuration.CacheFile))
- {
- throw new ConnectionException(config.Endpoint);
- }
- var source = File.ReadAllText(Configuration.CacheFile);
- File.WriteAllText(Filename, source);
- }
- }
+using System.IO;
+using Microsoft.Build.Framework;
+using Newtonsoft.Json;
+using WebApiProxy.Tasks.Infrastructure;
+using WebApiProxy.Tasks.Models;
+
+namespace WebApiProxy.Tasks
+{
+ public class ProxyGenerationTask : ITask
+ {
+ [Output]
+ public string Root { get; set; }
+
+ public IBuildEngine BuildEngine { get; set; }
+
+ public ITaskHost HostObject { get; set; }
+
+ public bool Execute()
+ {
+ var oldConfigFile = Path.Combine(Root, Configuration.ConfigFileName);
+ if (File.Exists(oldConfigFile))
+ {
+ var config = Configuration.Load(Root);
+
+ GenerateProxyFile(config);
+ }
+ else
+ {
+ var jsonConfigFile = Path.Combine(Root, Configuration.JsonConfigFileName);
+ GenerateConfig jsonConfig;
+
+ using (var sr = new StreamReader(jsonConfigFile))
+ {
+ jsonConfig = JsonConvert.DeserializeObject(sr.ReadToEnd());
+ }
+
+ var oldConfigs = jsonConfig.TransformToOldConfig();
+ foreach (var config in oldConfigs)
+ {
+ GenerateProxyFile(config);
+ }
+ }
+
+ return true;
+ }
+
+ private void GenerateProxyFile(Configuration config)
+ {
+ if (!config.GenerateOnBuild)
+ {
+ return;
+ }
+
+ var csFilePath = Path.Combine(Root, config.Name) + ".cs";
+ var generator = new CSharpGenerator(config);
+ var source = generator.Generate();
+ File.WriteAllText(csFilePath, source);
+ }
+
+ }
}
\ No newline at end of file
diff --git a/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.Parameters.cs b/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.Parameters.cs
index 0fdc86a..1ce3e15 100644
--- a/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.Parameters.cs
+++ b/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.Parameters.cs
@@ -1,22 +1,18 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using WebApiProxy.Core.Models;
-using WebApiProxy.Tasks.Models;
-
-
-namespace WebApiProxy.Tasks.Templates
-{
- public partial class CSharpProxyTemplate
- {
- public CSharpProxyTemplate(Configuration config)
- {
-
- this.Configuration = config;
- }
- public Configuration Configuration { get; set; }
-
- }
-}
+using WebApiProxy.Core.Models;
+using WebApiProxy.Tasks.Models;
+
+
+namespace WebApiProxy.Tasks.Templates
+{
+ public partial class CSharpProxyTemplate
+ {
+ public Metadata MetaData { get; set; }
+ public Configuration Configuration { get; set; }
+
+ public CSharpProxyTemplate(Configuration config, Metadata metaData)
+ {
+ this.Configuration = config;
+ this.MetaData = metaData;
+ }
+ }
+}
diff --git a/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.cs b/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.cs
index 3ec53bc..7d52fe7 100644
--- a/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.cs
+++ b/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.cs
@@ -1,1511 +1,1694 @@
-// ------------------------------------------------------------------------------
-//
-// This code was generated by a tool.
-// Runtime Version: 14.0.0.0
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-//
-// ------------------------------------------------------------------------------
-namespace WebApiProxy.Tasks.Templates
-{
- using System.Linq;
- using System.Text;
- using WebApiProxy.Core.Models;
- using System.Collections.Generic;
- using System;
-
- ///
- /// Class to produce the template output
- ///
-
- #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
- {
-#line hidden
- ///
- /// Create the template output
- ///
- public virtual string TransformText()
- {
- 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;
-using System.Net.Http;
-using System.Net.Http.Headers;
-using System.Threading.Tasks;
-using System.Net.Http.Formatting;
-using System.Linq;
-using System.Net;
-using System.Web;
-using ");
-
- #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 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 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 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 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}\r\n}\r\n#endregion\r\n\r\n#region Models\r\nnamespace ");
-
- #line 44 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Namespace));
-
- #line default
- #line hidden
- this.Write(@".Models
-{
- public class WebApiProxyResponseException : Exception
- {
- public HttpStatusCode StatusCode { get; private set; }
- public string Content { get; private set; }
-
- public WebApiProxyResponseException(HttpStatusCode statusCode, string content) : base(""A "" + statusCode + "" ("" + (int)statusCode + "") http exception occured. See Content for response body."")
- {
- StatusCode = statusCode;
- Content = content;
- }
- }
-
-");
-
- #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 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 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 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 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 69 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Type));
-
- #line default
- #line hidden
- this.Write(" ");
-
- #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 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 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 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 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 78 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(propertyItem.Type));
-
- #line default
- #line hidden
- this.Write(" ");
-
- #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 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 82 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
-}
-
- #line default
- #line hidden
- this.Write("\r\n");
-
- #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 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 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 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 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 95 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Name));
-
- #line default
- #line hidden
- this.Write(" = ");
-
- #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 96 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
-}
-
- #line default
- #line hidden
- this.Write("\t\t\r\n\t}\r\n");
-
- #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 104 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Namespace));
-
- #line default
- #line hidden
- 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 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 112 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
-
- #line default
- #line hidden
-
- #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 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);
-
- var bodyParameterString = "";
-
- if (method.BodyParameter != null) {
- allParameters = allParameters.Concat(new [] { method.BodyParameter });
- bodyParameterString = ", " + method.BodyParameter.Name;
- }
-
- var parameterList = "";
-
- if (allParameters.Any())
- {
- var q = allParameters.Select(m => m.Type + " " + m.Name);
- if (q != null)
- parameterList = string.Join(",", q.ToArray());
- }
-
- var concreteReturnType = method.ReturnType.ToConcrete();
-
-
- #line default
- #line hidden
- this.Write("\r\n");
-
- #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 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 138 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write("\r\n");
-
- #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 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 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 143 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- } else {
-
- #line default
- #line hidden
- this.Write("\t\tTask<");
-
- #line 144 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(concreteReturnType));
-
- #line default
- #line hidden
- this.Write("> ");
-
- #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 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 145 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write("\r\n");
-
- #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 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 149 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write("\t\t/// \r\n\t\t");
-
- #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 151 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
-
- #line default
- #line hidden
- this.Write("(");
-
- #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 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 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 160 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Namespace));
-
- #line default
- #line hidden
- this.Write(@".Clients
-{
- ///
- /// Client base class.
- ///
- public abstract partial class ClientBase : IDisposable
- {
- ///
- /// Gests the HttpClient.
- ///
- public HttpClient HttpClient { get; protected set; }
-
- ///
- /// Initializes a new instance of the class.
- ///
- protected ClientBase()
- {
- HttpClient = new HttpClient()
- {
- BaseAddress = new Uri(Configuration.");
-
- #line 179 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Name));
-
- #line default
- #line hidden
- this.Write(@"BaseAddress)
- };
- }
-
- ///
- /// Ensures that response has a valid (200 - OK) status code
- ///
- public virtual void EnsureSuccess(HttpResponseMessage response)
- {
- if (response.IsSuccessStatusCode)
- return;
-
- var content = response.Content.ReadAsStringAsync().Result;
- throw new WebApiProxyResponseException(response.StatusCode, content);
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The handler.
- /// if set to true [dispose handler].
- protected ClientBase(HttpMessageHandler handler, bool disposeHandler = true)
- {
- HttpClient = new HttpClient(handler, disposeHandler)
- {
- BaseAddress = new Uri(Configuration.");
-
- #line 204 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Name));
-
- #line default
- #line hidden
- this.Write(@"BaseAddress)
- };
- }
-
- ///
- /// Encode the input parameter as a string
- ///
- protected string EncodeParam(T value)
- {
- return System.Net.WebUtility.UrlEncode(value.ToString());
- }
-
- ///
- /// Encode the input parameter as a string
- ///
- protected string EncodeParam(DateTime value)
- {
- return System.Net.WebUtility.UrlEncode(value.ToString(""s""));
- }
-
- ///
- /// Encode the input parameter as a string
- ///
- 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()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- ///
- /// Destructor
- ///
- ~ClientBase()
- {
- Dispose(false);
- }
- }
-
- ///
- /// Helper class to access all clients at once
- ///
- public partial class WebApiClients
- {
-");
-
- #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 268 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
-
- #line default
- #line hidden
-
- #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 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 269 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write("\t\t\r\n protected IEnumerable Clients\r\n {\r\n " +
- " get\r\n {\r\n");
-
- #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 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 277 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- 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 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 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 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 287 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
-
- #line default
- #line hidden
-
- #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 288 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write(@" }
-
- public void SetAuthentication(AuthenticationHeaderValue auth)
- {
- foreach (var client in Clients)
- client.HttpClient.DefaultRequestHeaders.Authorization = auth;
- }
-
- protected virtual void Dispose(bool disposing)
- {
- if (disposing)
- {
- foreach (var client in Clients)
- client.Dispose();
- }
- }
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- ~WebApiClients()
- {
- Dispose(false);
- }
- }
-
-");
-
- #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 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 322 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
-
- #line default
- #line hidden
-
- #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 322 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
-
- #line default
- #line hidden
-
- #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 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 328 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
-
- #line default
- #line hidden
-
- #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 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 335 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
-
- #line default
- #line hidden
-
- #line 335 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.ClientSuffix));
-
- #line default
- #line hidden
- 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 341 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- foreach(var method in definition.ActionMethods) {
- var allParameters = method.UrlParameters.AsEnumerable();
-
- 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;
- }
-
- if (allParameters.Any())
- parameterNameList = string.Join(", ", allParameters.Select(m => m.Name));
-
- var parameterList = "";
-
- if (allParameters.Any())
- {
- var q = allParameters.Where(m => m != null).Select(m => m.Type + " " + m.Name);
-
- if (q != null)
- parameterList = string.Join(",", q.ToArray());
- }
-
- var postOrPutOrPatch = method.Type.ToTitle() == "Post" || method.Type.ToTitle() == "Put" || method.Type.ToTitle() == "Patch";
- var url = ("\"" + method.Url.Replace("{", "\" + ").Replace("}", " + \"") + "\"").Replace(" + \"\"","");
-
- allParameters.Where(m => m != null && (m.Type == "DateTime" || m.Type == "Nullable"))
- .ToList()
- .ForEach(p => url = url.Replace(" " + p.Name, " " + p.Name + ".ToString(\"o\")"));
-
- #line default
- #line hidden
- this.Write("\t\t/// \r\n\t\t/// ");
-
- #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 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 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 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 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 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 379 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(method.Type.ToTitle()));
-
- #line default
- #line hidden
-
- #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 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 379 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(url));
-
- #line default
- #line hidden
-
- #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 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 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 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 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 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 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 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 392 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(method.Type.ToTitle()));
-
- #line default
- #line hidden
-
- #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 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 392 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(url));
-
- #line default
- #line hidden
-
- #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 395 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- } else {
-
- #line default
- #line hidden
- this.Write("\t\t/// \r\n\t\t/// ");
-
- #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 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 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 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 403 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(concreteReturnType));
-
- #line default
- #line hidden
- this.Write("> ");
-
- #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 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 405 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(method.Type.ToTitle()));
-
- #line default
- #line hidden
-
- #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 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 405 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(url));
-
- #line default
- #line hidden
-
- #line 405 "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\t \r\n\t\t\tEnsureSuccess(result);\r\n\t\t\t\t \r\n\t\t\treturn await result.Content.ReadAs" +
- "Async<");
-
- #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 412 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write("\t\t/// \r\n\t\t/// ");
-
- #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 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 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 418 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write("\t\tpublic virtual ");
-
- #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 419 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
-
- #line default
- #line hidden
- this.Write("(");
-
- #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 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 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 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 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 426 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write("\t\t}\r\n\r\n");
-
- #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 432 "C:\Development\Personal\WebApiProxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
- }
-
- #line default
- #line hidden
- this.Write("}\r\n#endregion\r\n\r\n");
- return this.GenerationEnvironment.ToString();
- }
- }
-
- #line default
- #line hidden
- #region Base class
- ///
- /// Base class for this transformation
- ///
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")]
- public class CSharpProxyTemplateBase
- {
- #region Fields
- private global::System.Text.StringBuilder generationEnvironmentField;
- private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField;
- private global::System.Collections.Generic.List indentLengthsField;
- private string currentIndentField = "";
- private bool endsWithNewline;
- private global::System.Collections.Generic.IDictionary sessionField;
- #endregion
- #region Properties
- ///
- /// The string builder that generation-time code is using to assemble generated output
- ///
- protected System.Text.StringBuilder GenerationEnvironment
- {
- get
- {
- if ((this.generationEnvironmentField == null))
- {
- this.generationEnvironmentField = new global::System.Text.StringBuilder();
- }
- return this.generationEnvironmentField;
- }
- set
- {
- this.generationEnvironmentField = value;
- }
- }
- ///
- /// The error collection for the generation process
- ///
- public System.CodeDom.Compiler.CompilerErrorCollection Errors
- {
- get
- {
- if ((this.errorsField == null))
- {
- this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection();
- }
- return this.errorsField;
- }
- }
- ///
- /// A list of the lengths of each indent that was added with PushIndent
- ///
- private System.Collections.Generic.List indentLengths
- {
- get
- {
- if ((this.indentLengthsField == null))
- {
- this.indentLengthsField = new global::System.Collections.Generic.List();
- }
- return this.indentLengthsField;
- }
- }
- ///
- /// Gets the current indent we use when adding lines to the output
- ///
- public string CurrentIndent
- {
- get
- {
- return this.currentIndentField;
- }
- }
- ///
- /// Current transformation session
- ///
- public virtual global::System.Collections.Generic.IDictionary Session
- {
- get
- {
- return this.sessionField;
- }
- set
- {
- this.sessionField = value;
- }
- }
- #endregion
- #region Transform-time helpers
- ///
- /// Write text directly into the generated output
- ///
- public void Write(string textToAppend)
- {
- if (string.IsNullOrEmpty(textToAppend))
- {
- return;
- }
- // If we're starting off, or if the previous text ended with a newline,
- // we have to append the current indent first.
- if (((this.GenerationEnvironment.Length == 0)
- || this.endsWithNewline))
- {
- this.GenerationEnvironment.Append(this.currentIndentField);
- this.endsWithNewline = false;
- }
- // Check if the current text ends with a newline
- if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture))
- {
- this.endsWithNewline = true;
- }
- // This is an optimization. If the current indent is "", then we don't have to do any
- // of the more complex stuff further down.
- if ((this.currentIndentField.Length == 0))
- {
- this.GenerationEnvironment.Append(textToAppend);
- return;
- }
- // Everywhere there is a newline in the text, add an indent after it
- textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField));
- // If the text ends with a newline, then we should strip off the indent added at the very end
- // because the appropriate indent will be added when the next time Write() is called
- if (this.endsWithNewline)
- {
- this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length));
- }
- else
- {
- this.GenerationEnvironment.Append(textToAppend);
- }
- }
- ///
- /// Write text directly into the generated output
- ///
- public void WriteLine(string textToAppend)
- {
- this.Write(textToAppend);
- this.GenerationEnvironment.AppendLine();
- this.endsWithNewline = true;
- }
- ///
- /// Write formatted text directly into the generated output
- ///
- public void Write(string format, params object[] args)
- {
- this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
- }
- ///
- /// Write formatted text directly into the generated output
- ///
- public void WriteLine(string format, params object[] args)
- {
- this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
- }
- ///
- /// Raise an error
- ///
- public void Error(string message)
- {
- System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
- error.ErrorText = message;
- this.Errors.Add(error);
- }
- ///
- /// Raise a warning
- ///
- public void Warning(string message)
- {
- System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
- error.ErrorText = message;
- error.IsWarning = true;
- this.Errors.Add(error);
- }
- ///
- /// Increase the indent
- ///
- public void PushIndent(string indent)
- {
- if ((indent == null))
- {
- throw new global::System.ArgumentNullException("indent");
- }
- this.currentIndentField = (this.currentIndentField + indent);
- this.indentLengths.Add(indent.Length);
- }
- ///
- /// Remove the last indent that was added with PushIndent
- ///
- public string PopIndent()
- {
- string returnValue = "";
- if ((this.indentLengths.Count > 0))
- {
- int indentLength = this.indentLengths[(this.indentLengths.Count - 1)];
- this.indentLengths.RemoveAt((this.indentLengths.Count - 1));
- if ((indentLength > 0))
- {
- returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength));
- this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength));
- }
- }
- return returnValue;
- }
- ///
- /// Remove any indentation
- ///
- public void ClearIndent()
- {
- this.indentLengths.Clear();
- this.currentIndentField = "";
- }
- #endregion
- #region ToString Helpers
- ///
- /// Utility class to produce culture-oriented representation of an object as a string.
- ///
- public class ToStringInstanceHelper
- {
- private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture;
- ///
- /// Gets or sets format provider to be used by ToStringWithCulture method.
- ///
- public System.IFormatProvider FormatProvider
- {
- get
- {
- return this.formatProviderField ;
- }
- set
- {
- if ((value != null))
- {
- this.formatProviderField = value;
- }
- }
- }
- ///
- /// This is called from the compile/run appdomain to convert objects within an expression block to a string
- ///
- public string ToStringWithCulture(object objectToConvert)
- {
- if ((objectToConvert == null))
- {
- throw new global::System.ArgumentNullException("objectToConvert");
- }
- System.Type t = objectToConvert.GetType();
- System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] {
- typeof(System.IFormatProvider)});
- if ((method == null))
- {
- return objectToConvert.ToString();
- }
- else
- {
- return ((string)(method.Invoke(objectToConvert, new object[] {
- this.formatProviderField })));
- }
- }
- }
- private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper();
- ///
- /// Helper to produce culture-oriented representation of an object as a string
- ///
- public ToStringInstanceHelper ToStringHelper
- {
- get
- {
- return this.toStringHelperField;
- }
- }
- #endregion
- }
- #endregion
-}
+// ------------------------------------------------------------------------------
+//
+// 此代码由工具生成。
+// 运行时版本: 14.0.0.0
+//
+// 对此文件的更改可能导致不正确的行为,如果
+// 重新生成代码,则所做更改将丢失。
+//
+// ------------------------------------------------------------------------------
+namespace WebApiProxy.Tasks.Templates
+{
+ using System.Linq;
+ using System.Text;
+ using WebApiProxy.Core.Models;
+ using System.Collections.Generic;
+ using System;
+
+ ///
+ /// Class to produce the template output
+ ///
+
+ #line 1 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")]
+ public partial class CSharpProxyTemplate : CSharpProxyTemplateBase
+ {
+#line hidden
+ ///
+ /// Create the template output
+ ///
+ public virtual string TransformText()
+ {
+ 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;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Threading.Tasks;
+using System.Net.Http.Formatting;
+using System.Linq;
+using System.Net;
+using System.Web;
+using Newtonsoft.Json;
+using WebApiProxy.Tasks.Models;
+using ");
+
+ #line 27 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Namespace));
+
+ #line default
+ #line hidden
+ this.Write(".Models;\r\n\r\n\r\n#region Proxies\r\nnamespace ");
+
+ #line 31 "E:\git\uoko\web.api.proxy\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 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 41 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Name));
+
+ #line default
+ #line hidden
+ this.Write("BaseAddress = \"");
+
+ #line 41 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(MetaData.Host));
+
+ #line default
+ #line hidden
+ this.Write("\";\r\n\t}\r\n}\r\n#endregion\r\n\r\n#region Models\r\nnamespace ");
+
+ #line 47 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Namespace));
+
+ #line default
+ #line hidden
+ this.Write(".Models\r\n{\r\n\r\n");
+
+ #line 50 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var model in MetaData.Models.Where(m => m.Type.Equals("class"))) {
+
+ #line default
+ #line hidden
+ this.Write("\t\r\n\t/// \r\n\t/// ");
+
+ #line 52 "E:\git\uoko\web.api.proxy\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 54 "E:\git\uoko\web.api.proxy\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 57 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var constantItem in model.Constants) {
+
+ #line default
+ #line hidden
+ this.Write("\t\t/// \r\n\t\t/// ");
+
+ #line 59 "E:\git\uoko\web.api.proxy\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 61 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Type));
+
+ #line default
+ #line hidden
+ this.Write(" ");
+
+ #line 61 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Name));
+
+ #line default
+ #line hidden
+ this.Write(" = ");
+
+ #line 61 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Value));
+
+ #line default
+ #line hidden
+ this.Write(";\r\n");
+
+ #line 62 "E:\git\uoko\web.api.proxy\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 66 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var propertyItem in model.Properties) {
+
+ #line default
+ #line hidden
+ this.Write("\t\t/// \r\n\t\t/// ");
+
+ #line 68 "E:\git\uoko\web.api.proxy\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 70 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(propertyItem.Type));
+
+ #line default
+ #line hidden
+ this.Write(" ");
+
+ #line 70 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(propertyItem.Name));
+
+ #line default
+ #line hidden
+ this.Write(" { get; set; }\r\n");
+
+ #line 71 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+}
+
+ #line default
+ #line hidden
+ this.Write("\t\t#endregion\r\n\t}\t\r\n");
+
+ #line 74 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+}
+
+ #line default
+ #line hidden
+ this.Write("\r\n");
+
+ #line 76 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var model in MetaData.Models.Where(m => m.Type.Equals("enum"))) {
+
+ #line default
+ #line hidden
+ this.Write("\t\r\n\t/// \r\n\t/// ");
+
+ #line 78 "E:\git\uoko\web.api.proxy\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 80 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(model.Name));
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t{\r\n");
+
+ #line 82 "E:\git\uoko\web.api.proxy\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 85 "E:\git\uoko\web.api.proxy\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 87 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Name));
+
+ #line default
+ #line hidden
+ this.Write(" = ");
+
+ #line 87 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(constantItem.Value));
+
+ #line default
+ #line hidden
+ this.Write(",\r\n");
+
+ #line 88 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+}
+
+ #line default
+ #line hidden
+ this.Write("\t\t\r\n\t}\r\n");
+
+ #line 90 "E:\git\uoko\web.api.proxy\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 96 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Namespace));
+
+ #line default
+ #line hidden
+ 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 103 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var definition in MetaData.Definitions) {
+
+ #line default
+ #line hidden
+ this.Write("\t\r\n\tpublic partial interface I");
+
+ #line 104 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
+
+ #line default
+ #line hidden
+
+ #line 104 "E:\git\uoko\web.api.proxy\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 106 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var method in definition.ActionMethods) {
+ var allParameters = method.UrlParameters.AsEnumerable().Where(m => m != null);
+
+ var bodyParameterString = "";
+
+ if (method.BodyParameter != null) {
+ allParameters = allParameters.Concat(new [] { method.BodyParameter });
+ bodyParameterString = ", " + method.BodyParameter.Name;
+ }
+
+ var parameterList = "";
+
+ if (allParameters.Any())
+ {
+ var q = allParameters.Select(m => m.Type + " " + m.Name);
+ if (q != null)
+ parameterList = string.Join(",", q.ToArray());
+ }
+
+ var concreteReturnType = method.ReturnType.ToConcrete();
+
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t/// \r\n\t\t/// ");
+
+ #line 129 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Description));
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t/// \r\n");
+
+ #line 131 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var p in allParameters.Where(m => m != null)) {
+
+ #line default
+ #line hidden
+ this.Write("\t\t/// ");
+
+ #line 132 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(p.Description.ToSummary()));
+
+ #line default
+ #line hidden
+ this.Write("\r\n");
+
+ #line 133 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\r\n");
+
+ #line 135 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ if (Configuration.GenerateAsyncReturnTypes == false || String.IsNullOrEmpty(concreteReturnType) || concreteReturnType == "void") {
+
+ #line default
+ #line hidden
+ this.Write("\t\t/// \r\n\t\tTask ");
+
+ #line 137 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("Async(");
+
+ #line 137 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(parameterList));
+
+ #line default
+ #line hidden
+ this.Write(");\r\n");
+
+ #line 138 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ } else {
+
+ #line default
+ #line hidden
+ this.Write("\t\tTask<");
+
+ #line 139 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(concreteReturnType));
+
+ #line default
+ #line hidden
+ this.Write("> ");
+
+ #line 139 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("Async(");
+
+ #line 139 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(parameterList));
+
+ #line default
+ #line hidden
+ this.Write(");\r\n");
+
+ #line 140 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t/// \r\n\t\t/// ");
+
+ #line 143 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Description));
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t/// \r\n");
+
+ #line 145 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var p in allParameters.Where(m => m != null)) {
+
+ #line default
+ #line hidden
+ this.Write("\t\t/// ");
+
+ #line 146 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(p.Description.ToSummary()));
+
+ #line default
+ #line hidden
+ this.Write("\r\n");
+
+ #line 147 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\t\t/// \r\n\t\t");
+
+ #line 149 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(String.IsNullOrEmpty(concreteReturnType) ? "void" : concreteReturnType));
+
+ #line default
+ #line hidden
+ this.Write(" ");
+
+ #line 149 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("(");
+
+ #line 149 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(parameterList));
+
+ #line default
+ #line hidden
+ this.Write(");\r\n");
+
+ #line 150 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+}
+
+ #line default
+ #line hidden
+ this.Write("\t\t\t\t\r\n\t}\r\n");
+
+ #line 152 "E:\git\uoko\web.api.proxy\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 158 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Namespace));
+
+ #line default
+ #line hidden
+ this.Write(@".Clients
+{
+ ///
+ /// Client base class.
+ ///
+ public abstract partial class ClientBase : IDisposable
+ {
+ ///
+ /// Gests the HttpClient.
+ ///
+ public HttpClient HttpClient { get; protected set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ protected ClientBase()
+ {
+ HttpClient = new HttpClient()
+ {
+ BaseAddress = new Uri(Configuration.");
+
+ #line 177 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Name));
+
+ #line default
+ #line hidden
+ this.Write("BaseAddress)\r\n\t\t\t};\r\n\r\n\t\t\tSerializationSettings = new JsonSerializerSettings\r\n " +
+ " {\r\n NullValueHandling = NullValueHandling.Ignore,\r\n " +
+ " ReferenceLoopHandling = ReferenceLoopHandling.Serialize,\r\n " +
+ " };\r\n\t\t}\r\n\r\n public JsonSerializerSettings SerializationSettings;\r\n\r\n\t\t\r\n" +
+ "\t\t/// \r\n\t\t/// Ensures that response has a valid (200 - OK) status code\r" +
+ "\n\t\t/// \r\n\t\tpublic virtual void EnsureSuccess(HttpResponseMessage respo" +
+ "nse)\r\n\t\t{\t\t\t\r\n\t\t\tif (response.IsSuccessStatusCode)\t\t\t\t\r\n\t\t\t\treturn;\r\n\t\t\t\t\t\t\t\t\t\t\t" +
+ "\t\t\r\n throw new WebApiProxyResponseException(response);\r\n\t\t}\r\n\r\n\t\tprot" +
+ "ected virtual string GenerateQueryStrFromKvList(List> kvList)\r\n\t {\r\n var urlTpl = string.Join(\"&\",\r\n " +
+ " kvList.Select(item =>\r\n {\r\n " +
+ " var queryKey = Uri.EscapeDataString(item.Key);\r\n " +
+ " var queryValue = string.Empty;\r\n\r\n\t\t\t\t\t\t\t\t if (item.Value !" +
+ "= null)\r\n {\r\n\t\t\t\t\t\t\t\t\t\tif (item.Value is string" +
+ ")\r\n\t\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\t\tqueryValue = Uri.EscapeDataString((string)item.Value)" +
+ ";\r\n\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t\t\telse\r\n\t\t\t\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\t\t\t\tvar queryValueJson = Jso" +
+ "nConvert.SerializeObject(item.Value,SerializationSettings).Trim(\'\"\');\r\n\t\t\t\t\t\t\t\t\t" +
+ "\t\tqueryValue = Uri.EscapeDataString(queryValueJson);\r\n\t\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t " +
+ "}\r\n return queryKey + \"=\" + queryValue;\r\n " +
+ " }));\r\n\t return urlTpl;\r\n\t }\r\n\r\n\t\t\r\n\t\t/// \r\n\t\t/// Initializes a new instance of the class.\r\n\t\t/" +
+ "// \r\n\t\t/// The handler.\r\n\t\t/// if set to true [dispose handler].\r\n\t\tprotecte" +
+ "d ClientBase(HttpMessageHandler handler, bool disposeHandler = true)\r\n\t\t{\r\n\t\t\tHt" +
+ "tpClient = new HttpClient(handler, disposeHandler)\r\n\t\t\t{\r\n\t\t\t\tBaseAddress = new " +
+ "Uri(Configuration.");
+
+ #line 236 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.Name));
+
+ #line default
+ #line hidden
+ this.Write(@"BaseAddress)
+ };
+ }
+
+
+ ///
+ /// Encode the input parameter as a string
+ ///
+ protected string EncodeParam(T value)
+ {
+ return System.Net.WebUtility.UrlEncode(value.ToString());
+ }
+
+ ///
+ /// Encode the input parameter as a string
+ ///
+ protected string EncodeParam(DateTime value)
+ {
+ return System.Net.WebUtility.UrlEncode(value.ToString(""s""));
+ }
+
+ ///
+ /// Encode the input parameter as a string
+ ///
+ 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()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ /// Destructor
+ ///
+ ~ClientBase()
+ {
+ Dispose(false);
+ }
+ }
+
+ ///
+ /// Helper class to access all clients at once
+ ///
+ public partial class WebApiClients
+ {
+");
+
+ #line 300 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var definition in MetaData.Definitions) {
+
+ #line default
+ #line hidden
+ this.Write("\t\tpublic ");
+
+ #line 301 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
+
+ #line default
+ #line hidden
+
+ #line 301 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.ClientSuffix));
+
+ #line default
+ #line hidden
+ this.Write(" ");
+
+ #line 301 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
+
+ #line default
+ #line hidden
+ this.Write(" { get; private set; }\r\n");
+
+ #line 302 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\t\t\r\n protected IEnumerable Clients\r\n {\r\n " +
+ " get\r\n {\r\n");
+
+ #line 308 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var definition in MetaData.Definitions) {
+
+ #line default
+ #line hidden
+ this.Write("\t\t\t\tyield return ");
+
+ #line 309 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
+
+ #line default
+ #line hidden
+ this.Write(";\r\n");
+
+ #line 310 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ 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 317 "E:\git\uoko\web.api.proxy\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 319 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var definition in MetaData.Definitions) {
+
+ #line default
+ #line hidden
+ this.Write("\t\t\t");
+
+ #line 320 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
+
+ #line default
+ #line hidden
+ this.Write(" = new ");
+
+ #line 320 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
+
+ #line default
+ #line hidden
+
+ #line 320 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.ClientSuffix));
+
+ #line default
+ #line hidden
+ this.Write("();\r\n");
+
+ #line 321 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write(@" }
+
+ public void SetAuthentication(AuthenticationHeaderValue auth)
+ {
+ foreach (var client in Clients)
+ client.HttpClient.DefaultRequestHeaders.Authorization = auth;
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ foreach (var client in Clients)
+ client.Dispose();
+ }
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ ~WebApiClients()
+ {
+ Dispose(false);
+ }
+ }
+
+");
+
+ #line 351 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var definition in MetaData.Definitions) {
+
+ #line default
+ #line hidden
+ this.Write("\t/// \r\n\t/// ");
+
+ #line 353 "E:\git\uoko\web.api.proxy\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 355 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
+
+ #line default
+ #line hidden
+
+ #line 355 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.ClientSuffix));
+
+ #line default
+ #line hidden
+ this.Write(" : ClientBase, Interfaces.I");
+
+ #line 355 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
+
+ #line default
+ #line hidden
+
+ #line 355 "E:\git\uoko\web.api.proxy\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 359 "E:\git\uoko\web.api.proxy\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 361 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
+
+ #line default
+ #line hidden
+
+ #line 361 "E:\git\uoko\web.api.proxy\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 366 "E:\git\uoko\web.api.proxy\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 368 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(definition.Name));
+
+ #line default
+ #line hidden
+
+ #line 368 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(Configuration.ClientSuffix));
+
+ #line default
+ #line hidden
+ 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\t");
+
+ #line 374 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var method in definition.ActionMethods) {
+ var allParameters = method.UrlParameters.AsEnumerable();
+
+ 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;
+ }
+
+ if (allParameters.Any())
+ {
+ parameterNameList = string.Join(", ", allParameters.Select(m => m.Name));
+ }
+
+ var parameterList = "";
+
+ if (allParameters.Any())
+ {
+ var q = allParameters.Where(m => m != null).Select(m => m.Type + " " + m.Name);
+
+ if (q != null)
+ parameterList = string.Join(",", q.ToArray());
+ }
+
+ var postOrPutOrPatch = method.Type.ToTitle() == "Post" || method.Type.ToTitle() == "Put" || method.Type.ToTitle() == "Patch";
+
+
+ var urlParts = method.Url.Split(new[] {"?"}, StringSplitOptions.RemoveEmptyEntries);
+ var requestUrl = urlParts[0];
+ var urlQueryString = string.Empty;
+ var hasQueryString = false;
+
+ if (urlParts.Length > 1)
+ {
+ urlQueryString = urlParts[1];
+ hasQueryString = true;
+ }
+
+ requestUrl = System.Text.RegularExpressions.Regex.Replace(requestUrl, @"\{(.*?)\}", "\"+Uri.EscapeUriString(Convert.ToString($1))+\"");
+
+
+ var urlQueryParts = urlQueryString.Split(new[] {"&"}, StringSplitOptions.RemoveEmptyEntries)
+ .Select(item =>
+ {
+ var kvParts = item.Split(new[] {"="},
+ StringSplitOptions.RemoveEmptyEntries);
+ return new KeyValuePair(kvParts[0], kvParts[1]);
+ })
+ .ToList();
+
+ var queryHasParams =
+ urlQueryParts.Where(
+ item =>
+ allParameters.Any(param =>
+ string.Equals(item.Value, "{" + param.Name + "}",
+ StringComparison.OrdinalIgnoreCase)))
+ .ToList();
+
+ var queryHasParamUrlTpl = string.Join("&",
+ queryHasParams.Select(
+ item =>
+ string.Format("{0}={1}", item.Key, item.Value)));
+
+ var queryHasParamUrl = System.Text.RegularExpressions.Regex.Replace(queryHasParamUrlTpl, @"\{(.*?)\}", "\"+Uri.EscapeDataString(Convert.ToString($1))+\"");
+
+
+ var queryHasNoParams = urlQueryParts.Except(queryHasParams).ToList();
+ var queryNoParamUrlTpl = string.Join("&",
+ queryHasNoParams.Select(
+ item =>
+ string.Format("{0}={1}", item.Key, item.Value)));
+
+
+ #line default
+ #line hidden
+ this.Write("\r\n\r\n");
+
+ #line 452 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ if (Configuration.GenerateAsyncReturnTypes && !String.IsNullOrEmpty(concreteReturnType) && concreteReturnType != "void") {
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t/// \r\n\t\t/// ");
+
+ #line 455 "E:\git\uoko\web.api.proxy\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 457 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var p in allParameters.Where(m => m != null)) {
+
+ #line default
+ #line hidden
+ this.Write("\t\t/// ");
+
+ #line 458 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(p.Description.ToSummary()));
+
+ #line default
+ #line hidden
+ this.Write("\r\n");
+
+ #line 459 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\t\t/// \r\n\t\tpublic virtual async Task<");
+
+ #line 461 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(concreteReturnType));
+
+ #line default
+ #line hidden
+ this.Write("> ");
+
+ #line 461 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("Async(");
+
+ #line 461 "E:\git\uoko\web.api.proxy\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 var requestUrl = \"");
+
+ #line 463 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(requestUrl));
+
+ #line default
+ #line hidden
+ this.Write("\";\r\n\t\t\r\n\t");
+
+ #line 465 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ if(hasQueryString){
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t\tvar queryHasParamUrl = \"");
+
+ #line 467 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(queryHasParamUrl));
+
+ #line default
+ #line hidden
+ this.Write("\";\r\n\r\n\r\n\t\t");
+
+ #line 470 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ if(!string.IsNullOrEmpty(queryNoParamUrlTpl)){
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t\tvar queryNoParamUrl = Generate");
+
+ #line 472 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("QueryString(");
+
+ #line 472 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(parameterNameList));
+
+ #line default
+ #line hidden
+ this.Write(");\r\n\t\t\r\n\t\t");
+
+ #line 474 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }else{
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t\tvar queryNoParamUrl = string.Empty;\r\n\t\t\r\n\t\t");
+
+ #line 478 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write(" \r\n\t\t\tif (string.IsNullOrEmpty(queryHasParamUrl))\r\n\t\t\t{\r\n\t\t\t\trequestUrl = " +
+ "requestUrl + \"?\" + queryNoParamUrl;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trequestUrl = reque" +
+ "stUrl + \"?\" + queryHasParamUrl + \"&\" + queryNoParamUrl;\r\n\t\t\t}\r\n \r\n\t");
+
+ #line 489 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t\tvar result = await HttpClient.");
+
+ #line 491 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Type.ToTitle()));
+
+ #line default
+ #line hidden
+
+ #line 491 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch ? "AsJson" : ""));
+
+ #line default
+ #line hidden
+ this.Write("Async");
+
+ #line 491 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : ""));
+
+ #line default
+ #line hidden
+ this.Write("(requestUrl ");
+
+ #line 491 "E:\git\uoko\web.api.proxy\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\t\t\tEnsureSuccess(result);\r\n\t\t\t\t \r\n\t\t\treturn await result.Content.ReadAs" +
+ "Async<");
+
+ #line 496 "E:\git\uoko\web.api.proxy\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 499 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ } else {
+
+ #line default
+ #line hidden
+ this.Write("\r\n\r\n\t\t/// \r\n\t\t/// ");
+
+ #line 503 "E:\git\uoko\web.api.proxy\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 505 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var p in allParameters.Where(m => m != null)) {
+
+ #line default
+ #line hidden
+ this.Write("\t\t/// ");
+
+ #line 506 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(p.Description.ToSummary()));
+
+ #line default
+ #line hidden
+ this.Write("\r\n");
+
+ #line 507 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\t\t/// \r\n\t\tpublic virtual async Task ");
+
+ #line 509 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("Async(");
+
+ #line 509 "E:\git\uoko\web.api.proxy\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 var requestUrl = \"");
+
+ #line 511 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(requestUrl));
+
+ #line default
+ #line hidden
+ this.Write("\";\r\n\r\n\t");
+
+ #line 513 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ if(hasQueryString){
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t\tvar queryHasParamUrl = \"");
+
+ #line 515 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(queryHasParamUrl));
+
+ #line default
+ #line hidden
+ this.Write("\";\r\n\r\n\r\n\t\t");
+
+ #line 518 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ if(!string.IsNullOrEmpty(queryNoParamUrlTpl)){
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t\tvar queryNoParamUrl = Generate");
+
+ #line 520 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("QueryString(");
+
+ #line 520 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(parameterNameList));
+
+ #line default
+ #line hidden
+ this.Write(");\r\n\t\t\r\n\t\t");
+
+ #line 522 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }else{
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t\tvar queryNoParamUrl = string.Empty;\r\n\t\t\r\n\t\t");
+
+ #line 526 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write(" \r\n\t\t\tif (string.IsNullOrEmpty(queryHasParamUrl))\r\n\t\t\t{\r\n\t\t\t\trequestUrl = " +
+ "requestUrl + \"?\" + queryNoParamUrl;\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\trequestUrl = reque" +
+ "stUrl + \"?\" + queryHasParamUrl + \"&\" + queryNoParamUrl;\r\n\t\t\t}\r\n \r\n\t");
+
+ #line 537 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t\treturn await HttpClient.");
+
+ #line 539 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Type.ToTitle()));
+
+ #line default
+ #line hidden
+
+ #line 539 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch ? "AsJson" : ""));
+
+ #line default
+ #line hidden
+ this.Write("Async");
+
+ #line 539 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : ""));
+
+ #line default
+ #line hidden
+ this.Write("(requestUrl ");
+
+ #line 539 "E:\git\uoko\web.api.proxy\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 542 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t");
+
+ #line 544 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ if(hasQueryString && !string.IsNullOrEmpty(queryNoParamUrlTpl)){
+
+ #line default
+ #line hidden
+ this.Write("\t\t\t\t\r\n\t\tprotected virtual string Generate");
+
+ #line 546 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("QueryString(");
+
+ #line 546 "E:\git\uoko\web.api.proxy\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 kvList = Generate");
+
+ #line 548 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("KeyValueList( ");
+
+ #line 548 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(parameterNameList));
+
+ #line default
+ #line hidden
+ this.Write(" );\r\n var urlTpl = GenerateQueryStrFromKvList(kvList);\r\n\r\n \tret" +
+ "urn urlTpl;\r\n\t\t}\r\n\r\n\t\tprotected virtual List> Gener" +
+ "ate");
+
+ #line 554 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("KeyValueList(");
+
+ #line 554 "E:\git\uoko\web.api.proxy\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\t// ");
+
+ #line 556 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(queryNoParamUrlTpl));
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t\tthrow new NotImplementedException();\r\n\t\t}\r\n\r\n\t");
+
+ #line 560 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+}
+
+ #line default
+ #line hidden
+ this.Write("\r\n\r\n\t\t/// \r\n\t\t/// ");
+
+ #line 564 "E:\git\uoko\web.api.proxy\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 566 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ foreach(var p in allParameters.Where(m => m != null)) {
+
+ #line default
+ #line hidden
+ this.Write("\t\t/// ");
+
+ #line 567 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(p.Description.ToSummary()));
+
+ #line default
+ #line hidden
+ this.Write("\r\n");
+
+ #line 568 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\t\tpublic virtual ");
+
+ #line 569 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(String.IsNullOrEmpty(concreteReturnType) ? "void" : concreteReturnType));
+
+ #line default
+ #line hidden
+ this.Write(" ");
+
+ #line 569 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("(");
+
+ #line 569 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(parameterList));
+
+ #line default
+ #line hidden
+ this.Write(")\r\n\t\t{\r\n\r\n");
+
+ #line 572 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ if (Configuration.GenerateAsyncReturnTypes && !String.IsNullOrEmpty(concreteReturnType) && concreteReturnType != "void") {
+
+ #line default
+ #line hidden
+ this.Write("\t\t\treturn ");
+
+ #line 573 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("Async(");
+
+ #line 573 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(parameterNameList));
+
+ #line default
+ #line hidden
+ this.Write(").Result;\r\n");
+
+ #line 574 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ } else {
+
+ #line default
+ #line hidden
+ this.Write("\t\t\tvar result = ");
+
+ #line 575 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(method.Name));
+
+ #line default
+ #line hidden
+ this.Write("Async(");
+
+ #line 575 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(parameterNameList));
+
+ #line default
+ #line hidden
+ this.Write(").Result; \r\n\t\t\tEnsureSuccess(result);\r\n");
+
+ #line 577 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ if (!String.IsNullOrEmpty(concreteReturnType) && concreteReturnType != "void") {
+
+ #line default
+ #line hidden
+ this.Write("\t\t\treturn result.Content.ReadAsAsync<");
+
+ #line 578 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ this.Write(this.ToStringHelper.ToStringWithCulture(concreteReturnType));
+
+ #line default
+ #line hidden
+ this.Write(">().Result;\r\n");
+
+ #line 579 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\r\n");
+
+ #line 581 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\r\n\t\t}\r\n\r\n");
+
+ #line 585 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+}
+
+ #line default
+ #line hidden
+ this.Write("\t\t#endregion\r\n\t}\r\n");
+
+ #line 588 "E:\git\uoko\web.api.proxy\WebApiProxy.Tasks\Templates\CSharpProxyTemplate.tt"
+ }
+
+ #line default
+ #line hidden
+ this.Write("\r\n}\r\n\r\n#endregion\r\n\r\n");
+ return this.GenerationEnvironment.ToString();
+ }
+ }
+
+ #line default
+ #line hidden
+ #region Base class
+ ///
+ /// Base class for this transformation
+ ///
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")]
+ public class CSharpProxyTemplateBase
+ {
+ #region Fields
+ private global::System.Text.StringBuilder generationEnvironmentField;
+ private global::System.CodeDom.Compiler.CompilerErrorCollection errorsField;
+ private global::System.Collections.Generic.List indentLengthsField;
+ private string currentIndentField = "";
+ private bool endsWithNewline;
+ private global::System.Collections.Generic.IDictionary sessionField;
+ #endregion
+ #region Properties
+ ///
+ /// The string builder that generation-time code is using to assemble generated output
+ ///
+ protected System.Text.StringBuilder GenerationEnvironment
+ {
+ get
+ {
+ if ((this.generationEnvironmentField == null))
+ {
+ this.generationEnvironmentField = new global::System.Text.StringBuilder();
+ }
+ return this.generationEnvironmentField;
+ }
+ set
+ {
+ this.generationEnvironmentField = value;
+ }
+ }
+ ///
+ /// The error collection for the generation process
+ ///
+ public System.CodeDom.Compiler.CompilerErrorCollection Errors
+ {
+ get
+ {
+ if ((this.errorsField == null))
+ {
+ this.errorsField = new global::System.CodeDom.Compiler.CompilerErrorCollection();
+ }
+ return this.errorsField;
+ }
+ }
+ ///
+ /// A list of the lengths of each indent that was added with PushIndent
+ ///
+ private System.Collections.Generic.List indentLengths
+ {
+ get
+ {
+ if ((this.indentLengthsField == null))
+ {
+ this.indentLengthsField = new global::System.Collections.Generic.List();
+ }
+ return this.indentLengthsField;
+ }
+ }
+ ///
+ /// Gets the current indent we use when adding lines to the output
+ ///
+ public string CurrentIndent
+ {
+ get
+ {
+ return this.currentIndentField;
+ }
+ }
+ ///
+ /// Current transformation session
+ ///
+ public virtual global::System.Collections.Generic.IDictionary Session
+ {
+ get
+ {
+ return this.sessionField;
+ }
+ set
+ {
+ this.sessionField = value;
+ }
+ }
+ #endregion
+ #region Transform-time helpers
+ ///
+ /// Write text directly into the generated output
+ ///
+ public void Write(string textToAppend)
+ {
+ if (string.IsNullOrEmpty(textToAppend))
+ {
+ return;
+ }
+ // If we're starting off, or if the previous text ended with a newline,
+ // we have to append the current indent first.
+ if (((this.GenerationEnvironment.Length == 0)
+ || this.endsWithNewline))
+ {
+ this.GenerationEnvironment.Append(this.currentIndentField);
+ this.endsWithNewline = false;
+ }
+ // Check if the current text ends with a newline
+ if (textToAppend.EndsWith(global::System.Environment.NewLine, global::System.StringComparison.CurrentCulture))
+ {
+ this.endsWithNewline = true;
+ }
+ // This is an optimization. If the current indent is "", then we don't have to do any
+ // of the more complex stuff further down.
+ if ((this.currentIndentField.Length == 0))
+ {
+ this.GenerationEnvironment.Append(textToAppend);
+ return;
+ }
+ // Everywhere there is a newline in the text, add an indent after it
+ textToAppend = textToAppend.Replace(global::System.Environment.NewLine, (global::System.Environment.NewLine + this.currentIndentField));
+ // If the text ends with a newline, then we should strip off the indent added at the very end
+ // because the appropriate indent will be added when the next time Write() is called
+ if (this.endsWithNewline)
+ {
+ this.GenerationEnvironment.Append(textToAppend, 0, (textToAppend.Length - this.currentIndentField.Length));
+ }
+ else
+ {
+ this.GenerationEnvironment.Append(textToAppend);
+ }
+ }
+ ///
+ /// Write text directly into the generated output
+ ///
+ public void WriteLine(string textToAppend)
+ {
+ this.Write(textToAppend);
+ this.GenerationEnvironment.AppendLine();
+ this.endsWithNewline = true;
+ }
+ ///
+ /// Write formatted text directly into the generated output
+ ///
+ public void Write(string format, params object[] args)
+ {
+ this.Write(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
+ }
+ ///
+ /// Write formatted text directly into the generated output
+ ///
+ public void WriteLine(string format, params object[] args)
+ {
+ this.WriteLine(string.Format(global::System.Globalization.CultureInfo.CurrentCulture, format, args));
+ }
+ ///
+ /// Raise an error
+ ///
+ public void Error(string message)
+ {
+ System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
+ error.ErrorText = message;
+ this.Errors.Add(error);
+ }
+ ///
+ /// Raise a warning
+ ///
+ public void Warning(string message)
+ {
+ System.CodeDom.Compiler.CompilerError error = new global::System.CodeDom.Compiler.CompilerError();
+ error.ErrorText = message;
+ error.IsWarning = true;
+ this.Errors.Add(error);
+ }
+ ///
+ /// Increase the indent
+ ///
+ public void PushIndent(string indent)
+ {
+ if ((indent == null))
+ {
+ throw new global::System.ArgumentNullException("indent");
+ }
+ this.currentIndentField = (this.currentIndentField + indent);
+ this.indentLengths.Add(indent.Length);
+ }
+ ///
+ /// Remove the last indent that was added with PushIndent
+ ///
+ public string PopIndent()
+ {
+ string returnValue = "";
+ if ((this.indentLengths.Count > 0))
+ {
+ int indentLength = this.indentLengths[(this.indentLengths.Count - 1)];
+ this.indentLengths.RemoveAt((this.indentLengths.Count - 1));
+ if ((indentLength > 0))
+ {
+ returnValue = this.currentIndentField.Substring((this.currentIndentField.Length - indentLength));
+ this.currentIndentField = this.currentIndentField.Remove((this.currentIndentField.Length - indentLength));
+ }
+ }
+ return returnValue;
+ }
+ ///
+ /// Remove any indentation
+ ///
+ public void ClearIndent()
+ {
+ this.indentLengths.Clear();
+ this.currentIndentField = "";
+ }
+ #endregion
+ #region ToString Helpers
+ ///
+ /// Utility class to produce culture-oriented representation of an object as a string.
+ ///
+ public class ToStringInstanceHelper
+ {
+ private System.IFormatProvider formatProviderField = global::System.Globalization.CultureInfo.InvariantCulture;
+ ///
+ /// Gets or sets format provider to be used by ToStringWithCulture method.
+ ///
+ public System.IFormatProvider FormatProvider
+ {
+ get
+ {
+ return this.formatProviderField ;
+ }
+ set
+ {
+ if ((value != null))
+ {
+ this.formatProviderField = value;
+ }
+ }
+ }
+ ///
+ /// This is called from the compile/run appdomain to convert objects within an expression block to a string
+ ///
+ public string ToStringWithCulture(object objectToConvert)
+ {
+ if ((objectToConvert == null))
+ {
+ throw new global::System.ArgumentNullException("objectToConvert");
+ }
+ System.Type t = objectToConvert.GetType();
+ System.Reflection.MethodInfo method = t.GetMethod("ToString", new System.Type[] {
+ typeof(System.IFormatProvider)});
+ if ((method == null))
+ {
+ return objectToConvert.ToString();
+ }
+ else
+ {
+ return ((string)(method.Invoke(objectToConvert, new object[] {
+ this.formatProviderField })));
+ }
+ }
+ }
+ private ToStringInstanceHelper toStringHelperField = new ToStringInstanceHelper();
+ ///
+ /// Helper to produce culture-oriented representation of an object as a string
+ ///
+ public ToStringInstanceHelper ToStringHelper
+ {
+ get
+ {
+ return this.toStringHelperField;
+ }
+ }
+ #endregion
+ }
+ #endregion
+}
diff --git a/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.tt b/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.tt
index cb9627c..c22d907 100644
--- a/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.tt
+++ b/WebApiProxy.Tasks/Templates/CSharpProxyTemplate.tt
@@ -22,8 +22,11 @@ using System.Net.Http.Formatting;
using System.Linq;
using System.Net;
using System.Web;
+using Newtonsoft.Json;
+using WebApiProxy.Tasks.Models;
using <#= Configuration.Namespace#>.Models;
+
#region Proxies
namespace <#= Configuration.Namespace#>
{
@@ -35,7 +38,7 @@ namespace <#= Configuration.Namespace#>
///
/// Web Api Base Address.
///
- public static string <#= Configuration.Name #>BaseAddress = "<#= Configuration.Metadata.Host #>";
+ public static string <#= Configuration.Name #>BaseAddress = "<#= MetaData.Host #>";
}
}
#endregion
@@ -43,19 +46,8 @@ namespace <#= Configuration.Namespace#>
#region Models
namespace <#= Configuration.Namespace#>.Models
{
- public class WebApiProxyResponseException : Exception
- {
- public HttpStatusCode StatusCode { get; private set; }
- public string Content { get; private set; }
- public WebApiProxyResponseException(HttpStatusCode statusCode, string content) : base("A " + statusCode + " (" + (int)statusCode + ") http exception occured. See Content for response body.")
- {
- StatusCode = statusCode;
- Content = content;
- }
- }
-
-<# foreach(var model in Configuration.Metadata.Models.Where(m => m.Type.Equals("class"))) { #>
+<# foreach(var model in MetaData.Models.Where(m => m.Type.Equals("class"))) { #>
///
/// <#= model.Description.ToSummary() #>
///
@@ -81,7 +73,7 @@ namespace <#= Configuration.Namespace#>.Models
}
<#}#>
-<# foreach(var model in Configuration.Metadata.Models.Where(m => m.Type.Equals("enum"))) { #>
+<# foreach(var model in MetaData.Models.Where(m => m.Type.Equals("enum"))) { #>
///
/// <#= model.Description.ToSummary() #>
///
@@ -108,7 +100,7 @@ namespace <#= Configuration.Namespace#>.Interfaces
HttpClient HttpClient { get; }
}
-<# foreach(var definition in Configuration.Metadata.Definitions) { #>
+<# foreach(var definition in MetaData.Definitions) { #>
public partial interface I<#=definition.Name#><#=Configuration.ClientSuffix#> : IClientBase
{
<# foreach(var method in definition.ActionMethods) {
@@ -133,18 +125,24 @@ namespace <#= Configuration.Namespace#>.Interfaces
var concreteReturnType = method.ReturnType.ToConcrete();
#>
-<# foreach(var p in method.UrlParameters) { #>
+ ///
+ /// <#= method.Description #>
+ ///
+<# foreach(var p in allParameters.Where(m => m != null)) { #>
/// <#= p.Description.ToSummary() #>
<# } #>
-<# if (Configuration.GenerateAsyncReturnTypes == false || String.IsNullOrEmpty(concreteReturnType)) { #>
+<# if (Configuration.GenerateAsyncReturnTypes == false || String.IsNullOrEmpty(concreteReturnType) || concreteReturnType == "void") { #>
///
Task <#= method.Name #>Async(<#= parameterList#>);
<# } else { #>
Task<<#= concreteReturnType #>> <#= method.Name #>Async(<#= parameterList#>);
<# } #>
-<# foreach(var p in method.UrlParameters) {#>
+ ///
+ /// <#= method.Description #>
+ ///
+<# foreach(var p in allParameters.Where(m => m != null)) {#>
/// <#= p.Description.ToSummary() #>
<# } #>
///
@@ -178,7 +176,16 @@ namespace <#= Configuration.Namespace#>.Clients
{
BaseAddress = new Uri(Configuration.<#= Configuration.Name #>BaseAddress)
};
+
+ SerializationSettings = new JsonSerializerSettings
+ {
+ NullValueHandling = NullValueHandling.Ignore,
+ ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
+ };
}
+
+ public JsonSerializerSettings SerializationSettings;
+
///
/// Ensures that response has a valid (200 - OK) status code
@@ -188,10 +195,35 @@ namespace <#= Configuration.Namespace#>.Clients
if (response.IsSuccessStatusCode)
return;
- var content = response.Content.ReadAsStringAsync().Result;
- throw new WebApiProxyResponseException(response.StatusCode, content);
+ throw new WebApiProxyResponseException(response);
}
+ protected virtual string GenerateQueryStrFromKvList(List> kvList)
+ {
+ var urlTpl = string.Join("&",
+ kvList.Select(item =>
+ {
+ var queryKey = Uri.EscapeDataString(item.Key);
+ var queryValue = string.Empty;
+
+ if (item.Value != null)
+ {
+ if (item.Value is string)
+ {
+ queryValue = Uri.EscapeDataString((string)item.Value);
+ }
+ else
+ {
+ var queryValueJson = JsonConvert.SerializeObject(item.Value,SerializationSettings).Trim('"');
+ queryValue = Uri.EscapeDataString(queryValueJson);
+ }
+ }
+ return queryKey + "=" + queryValue;
+ }));
+ return urlTpl;
+ }
+
+
///
/// Initializes a new instance of the class.
///
@@ -205,6 +237,7 @@ namespace <#= Configuration.Namespace#>.Clients
};
}
+
///
/// Encode the input parameter as a string
///
@@ -264,7 +297,7 @@ namespace <#= Configuration.Namespace#>.Clients
///
public partial class WebApiClients
{
-<# foreach(var definition in Configuration.Metadata.Definitions) { #>
+<# foreach(var definition in MetaData.Definitions) { #>
public <#=definition.Name#><#= Configuration.ClientSuffix#> <#= definition.Name #> { get; private set; }
<# } #>
@@ -272,7 +305,7 @@ namespace <#= Configuration.Namespace#>.Clients
{
get
{
-<# foreach(var definition in Configuration.Metadata.Definitions) { #>
+<# foreach(var definition in MetaData.Definitions) { #>
yield return <#= definition.Name #>;
<# } #>
}
@@ -283,7 +316,7 @@ namespace <#= Configuration.Namespace#>.Clients
if (baseAddress != null)
Configuration.<#= Configuration.Name #>BaseAddress = baseAddress.AbsoluteUri;
-<# foreach(var definition in Configuration.Metadata.Definitions) { #>
+<# foreach(var definition in MetaData.Definitions) { #>
<#= definition.Name #> = new <#=definition.Name#><#= Configuration.ClientSuffix#>();
<# } #>
}
@@ -315,7 +348,7 @@ namespace <#= Configuration.Namespace#>.Clients
}
}
-<# foreach(var definition in Configuration.Metadata.Definitions) { #>
+<# foreach(var definition in MetaData.Definitions) { #>
///
/// <#= definition.Description.ToSummary() #>
///
@@ -338,7 +371,7 @@ namespace <#= Configuration.Namespace#>.Clients
#region Methods
-<# foreach(var method in definition.ActionMethods) {
+ <# foreach(var method in definition.ActionMethods) {
var allParameters = method.UrlParameters.AsEnumerable();
var bodyParameterString = ", default(HttpResponseMessage)";
@@ -352,7 +385,9 @@ namespace <#= Configuration.Namespace#>.Clients
}
if (allParameters.Any())
+ {
parameterNameList = string.Join(", ", allParameters.Select(m => m.Name));
+ }
var parameterList = "";
@@ -365,13 +400,57 @@ namespace <#= Configuration.Namespace#>.Clients
}
var postOrPutOrPatch = method.Type.ToTitle() == "Post" || method.Type.ToTitle() == "Put" || method.Type.ToTitle() == "Patch";
- var url = ("\"" + method.Url.Replace("{", "\" + ").Replace("}", " + \"") + "\"").Replace(" + \"\"","");
-
- allParameters.Where(m => m != null && (m.Type == "DateTime" || m.Type == "Nullable"))
- .ToList()
- .ForEach(p => url = url.Replace(" " + p.Name, " " + p.Name + ".ToString(\"o\")"));
-
-#>
+
+
+ var urlParts = method.Url.Split(new[] {"?"}, StringSplitOptions.RemoveEmptyEntries);
+ var requestUrl = urlParts[0];
+ var urlQueryString = string.Empty;
+ var hasQueryString = false;
+
+ if (urlParts.Length > 1)
+ {
+ urlQueryString = urlParts[1];
+ hasQueryString = true;
+ }
+
+ requestUrl = System.Text.RegularExpressions.Regex.Replace(requestUrl, @"\{(.*?)\}", "\"+Uri.EscapeUriString(Convert.ToString($1))+\"");
+
+
+ var urlQueryParts = urlQueryString.Split(new[] {"&"}, StringSplitOptions.RemoveEmptyEntries)
+ .Select(item =>
+ {
+ var kvParts = item.Split(new[] {"="},
+ StringSplitOptions.RemoveEmptyEntries);
+ return new KeyValuePair(kvParts[0], kvParts[1]);
+ })
+ .ToList();
+
+ var queryHasParams =
+ urlQueryParts.Where(
+ item =>
+ allParameters.Any(param =>
+ string.Equals(item.Value, "{" + param.Name + "}",
+ StringComparison.OrdinalIgnoreCase)))
+ .ToList();
+
+ var queryHasParamUrlTpl = string.Join("&",
+ queryHasParams.Select(
+ item =>
+ string.Format("{0}={1}", item.Key, item.Value)));
+
+ var queryHasParamUrl = System.Text.RegularExpressions.Regex.Replace(queryHasParamUrlTpl, @"\{(.*?)\}", "\"+Uri.EscapeDataString(Convert.ToString($1))+\"");
+
+
+ var queryHasNoParams = urlQueryParts.Except(queryHasParams).ToList();
+ var queryNoParamUrlTpl = string.Join("&",
+ queryHasNoParams.Select(
+ item =>
+ string.Format("{0}={1}", item.Key, item.Value)));
+ #>
+
+
+<# if (Configuration.GenerateAsyncReturnTypes && !String.IsNullOrEmpty(concreteReturnType) && concreteReturnType != "void") { #>
+
///
/// <#= method.Description.ToSummary() #>
///
@@ -379,62 +458,136 @@ namespace <#= Configuration.Namespace#>.Clients
/// <#= p.Description.ToSummary() #>
<# } #>
///
- protected virtual async Task <#= method.Name #>AsyncMsg(<#= parameterList#>)
+ public virtual async Task<<#= concreteReturnType #>> <#= method.Name #>Async(<#= parameterList#>)
{
- return await HttpClient.<#=method.Type.ToTitle()#><#= postOrPutOrPatch ? "AsJson" : "" #>Async<#= postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "" #>(<#=url#><#= postOrPutOrPatch ? bodyParameterString:""#>);
+ var requestUrl = "<#= requestUrl #>";
+
+ <# if(hasQueryString){ #>
+
+ var queryHasParamUrl = "<#= queryHasParamUrl #>";
+
+
+ <# if(!string.IsNullOrEmpty(queryNoParamUrlTpl)){ #>
+
+ var queryNoParamUrl = Generate<#= method.Name #>QueryString(<#=parameterNameList#>);
+
+ <# }else{ #>
+
+ var queryNoParamUrl = string.Empty;
+
+ <# } #>
+
+ if (string.IsNullOrEmpty(queryHasParamUrl))
+ {
+ requestUrl = requestUrl + "?" + queryNoParamUrl;
+ }
+ else
+ {
+ requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl;
+ }
+
+ <# } #>
+
+ var result = await HttpClient.<#=method.Type.ToTitle()#><#= postOrPutOrPatch ? "AsJson" : "" #>Async<#= postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "" #>(requestUrl <#= postOrPutOrPatch ? bodyParameterString:""#>);
+
+
+ EnsureSuccess(result);
+
+ return await result.Content.ReadAsAsync<<#= concreteReturnType #>>();
}
-<# if (Configuration.GenerateAsyncReturnTypes == false || String.IsNullOrEmpty(concreteReturnType)) { #>
+<# } else { #>
+
+
///
/// <#= method.Description.ToSummary() #>
///
-<# foreach(var p in method.UrlParameters) { #>
+<# foreach(var p in allParameters.Where(m => m != null)) { #>
/// <#= p.Description.ToSummary() #>
<# } #>
///
public virtual async Task <#= method.Name #>Async(<#= parameterList#>)
{
- return await HttpClient.<#=method.Type.ToTitle()#><#= postOrPutOrPatch ? "AsJson" : "" #>Async<#= postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "" #>(<#=url#><#= postOrPutOrPatch ? bodyParameterString:""#>);
+ var requestUrl = "<#= requestUrl #>";
+
+ <# if(hasQueryString){ #>
+
+ var queryHasParamUrl = "<#= queryHasParamUrl #>";
+
+
+ <# if(!string.IsNullOrEmpty(queryNoParamUrlTpl)){ #>
+
+ var queryNoParamUrl = Generate<#= method.Name #>QueryString(<#=parameterNameList#>);
+
+ <# }else{ #>
+
+ var queryNoParamUrl = string.Empty;
+
+ <# } #>
+
+ if (string.IsNullOrEmpty(queryHasParamUrl))
+ {
+ requestUrl = requestUrl + "?" + queryNoParamUrl;
+ }
+ else
+ {
+ requestUrl = requestUrl + "?" + queryHasParamUrl + "&" + queryNoParamUrl;
+ }
+
+ <# } #>
+
+ return await HttpClient.<#=method.Type.ToTitle()#><#= postOrPutOrPatch ? "AsJson" : "" #>Async<#= postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "" #>(requestUrl <#= postOrPutOrPatch ? bodyParameterString:""#>);
}
-<# } else { #>
- ///
- /// <#= method.Description.ToSummary() #>
- ///
-<# foreach(var p in method.UrlParameters) { #>
- /// <#= p.Description.ToSummary() #>
<# } #>
- ///
- public virtual async Task<<#= concreteReturnType #>> <#= method.Name #>Async(<#= parameterList#>)
+
+ <# if(hasQueryString && !string.IsNullOrEmpty(queryNoParamUrlTpl)){ #>
+
+ protected virtual string Generate<#= method.Name #>QueryString(<#= parameterList#>)
{
- var result = await HttpClient.<#=method.Type.ToTitle()#><#= postOrPutOrPatch ? "AsJson" : "" #>Async<#= postOrPutOrPatch && method.BodyParameter != null ? "<" + method.BodyParameter.Type + ">" : "" #>(<#=url#><#= postOrPutOrPatch ? bodyParameterString:""#>);
-
- EnsureSuccess(result);
-
- return await result.Content.ReadAsAsync<<#= concreteReturnType #>>();
+ var kvList = Generate<#= method.Name #>KeyValueList( <#=parameterNameList#> );
+ var urlTpl = GenerateQueryStrFromKvList(kvList);
+
+ return urlTpl;
}
-<# }#>
+ protected virtual List> Generate<#= method.Name #>KeyValueList(<#= parameterList#>)
+ {
+ // <#=queryNoParamUrlTpl#>
+ throw new NotImplementedException();
+ }
+
+ <#}#>
+
+
///
/// <#= method.Description.ToSummary() #>
///
-<# foreach(var p in method.UrlParameters) { #>
+<# foreach(var p in allParameters.Where(m => m != null)) { #>
/// <#= p.Description.ToSummary() #>
<# } #>
public virtual <#= String.IsNullOrEmpty(concreteReturnType) ? "void" : concreteReturnType #> <#= method.Name #>(<#= parameterList#>)
{
- var result = Task.Run(() => <#= method.Name #>AsyncMsg(<#=parameterNameList#>)).Result;
-
+
+<# if (Configuration.GenerateAsyncReturnTypes && !String.IsNullOrEmpty(concreteReturnType) && concreteReturnType != "void") { #>
+ return <#= method.Name #>Async(<#=parameterNameList#>).Result;
+<# } else { #>
+ var result = <#= method.Name #>Async(<#=parameterNameList#>).Result;
EnsureSuccess(result);
-<# if(!String.IsNullOrEmpty(concreteReturnType)) { #>
+<# if (!String.IsNullOrEmpty(concreteReturnType) && concreteReturnType != "void") { #>
return result.Content.ReadAsAsync<<#= concreteReturnType #>>().Result;
- <# } #>
+<# } #>
+
+<# } #>
+
}
<#}#>
#endregion
}
<# } #>
+
}
+
#endregion
diff --git a/WebApiProxy.Tasks/WebApiProxy.CSharp.nuspec b/WebApiProxy.Tasks/WebApiProxy.CSharp.nuspec
index 27d9e5a..d0e8e5e 100644
--- a/WebApiProxy.Tasks/WebApiProxy.CSharp.nuspec
+++ b/WebApiProxy.Tasks/WebApiProxy.CSharp.nuspec
@@ -24,9 +24,8 @@
-
-
-
+
+
diff --git a/WebApiProxy.Tasks/WebApiProxy.CSharp.targets b/WebApiProxy.Tasks/WebApiProxy.CSharp.targets
index 154d0e5..7926cf5 100644
--- a/WebApiProxy.Tasks/WebApiProxy.CSharp.targets
+++ b/WebApiProxy.Tasks/WebApiProxy.CSharp.targets
@@ -1,19 +1,19 @@
-
-
-
-
- .
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ .
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WebApiProxy.Tasks/WebApiProxy.Tasks.csproj b/WebApiProxy.Tasks/WebApiProxy.Tasks.csproj
index c60e042..d7ca3dd 100644
--- a/WebApiProxy.Tasks/WebApiProxy.Tasks.csproj
+++ b/WebApiProxy.Tasks/WebApiProxy.Tasks.csproj
@@ -1,129 +1,141 @@
-
-
-
-
- Debug
- AnyCPU
- {A635DE23-DDC1-43ED-BC5D-D49B7E8A4355}
- Library
- Properties
- WebApiProxy.Tasks
- WebApiProxy.Tasks
- v4.5
- 512
- ..\
- true
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
- ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll
- True
-
-
-
-
- True
-
-
- ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll
- True
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- True
- True
- CSharpProxyTemplate.tt
-
-
- Always
-
-
-
-
-
- Always
-
-
- Always
-
-
-
- Always
-
-
- Always
- Designer
-
-
- Designer
-
-
- Designer
- Always
-
-
- TextTemplatingFilePreprocessor
- <%3fxml version="1.0" encoding="utf-16"%3f>
-<ArrayOfParameterStorage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
- CSharpProxyTemplate.cs
-
-
- Always
-
-
-
-
-
-
-
- {94508206-8537-4088-923b-e7fcb0539903}
- WebApiProxy.Core
-
-
-
-
- Always
-
-
-
-
-
+
+
+
+
+ Debug
+ AnyCPU
+ {A635DE23-DDC1-43ED-BC5D-D49B7E8A4355}
+ Library
+ Properties
+ WebApiProxy.Tasks
+ WebApiProxy.Tasks
+ v4.5
+ 512
+ ..\
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+ ..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll
+ True
+
+
+
+
+ True
+
+
+ ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll
+ True
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ True
+ True
+ CSharpProxyTemplate.tt
+
+
+
+ Always
+
+
+
+
+
+ Always
+
+
+ Always
+
+
+
+ Always
+
+
+ Always
+ Designer
+
+
+ Designer
+
+
+ Designer
+ Always
+
+
+ TextTemplatingFilePreprocessor
+ <%3fxml version="1.0" encoding="utf-16"%3f>
+<ArrayOfParameterStorage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
+ CSharpProxyTemplate.cs
+
+
+ Always
+
+
+
+
+
+
+
+ {94508206-8537-4088-923b-e7fcb0539903}
+ WebApiProxy.Core
+
+
+
+
+ Always
+
+
+
+
+ Always
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/WebApiProxy.Tasks/WebApiProxy.config b/WebApiProxy.Tasks/WebApiProxy.config
index 8de7a0d..25ae118 100644
--- a/WebApiProxy.Tasks/WebApiProxy.config
+++ b/WebApiProxy.Tasks/WebApiProxy.config
@@ -1,9 +1,9 @@
-
-
-
-
+
+
+
+
diff --git a/WebApiProxy.Tasks/WebApiProxy.json b/WebApiProxy.Tasks/WebApiProxy.json
new file mode 100644
index 0000000..7a1743b
--- /dev/null
+++ b/WebApiProxy.Tasks/WebApiProxy.json
@@ -0,0 +1,18 @@
+{
+ "GenerateOnBuild": true,
+ "GenerateAsyncReturnTypes": true,
+ "Services": [
+ {
+ "ProxyEndpoint": "http://localhost:12016/api/proxies",
+ "Namespace": "WebApi.Proxies",
+ "Name": "TestProxy",
+ "ClientSuffix": "Client"
+ },
+ {
+ "ProxyEndpoint": "http://localhost:12016/api/proxies",
+ "Namespace": "WebApi.Proxies",
+ "Name": "AnotherTestProxy",
+ "ClientSuffix": "Client"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/WebApiProxy.Tasks/WebApiProxyCSharp.psm1 b/WebApiProxy.Tasks/WebApiProxyCSharp.psm1
index c9982e0..428c4a7 100644
--- a/WebApiProxy.Tasks/WebApiProxyCSharp.psm1
+++ b/WebApiProxy.Tasks/WebApiProxyCSharp.psm1
@@ -1,37 +1,24 @@
-function WebApiProxy-Generate-CSharp() {
+function WebApiProxy-Generate-CSharp {
$project = Get-Project
- $projectPath = [System.IO.Path]::GetDirectoryName($project.FullName)
- $root = (Join-Path $projectPath "WebApiProxy\")
- $rootSpaces = "$root"
+ $projectPath = [System.IO.Path]::GetDirectoryName($project.FullName)
+ $root = (Join-Path $projectPath "WebApiProxy\").ToString()
$taskPath = ($project.Object.References | where {$_.Identity -eq 'WebApiProxy.Tasks'} | Select-Object -first 1).Path
-
$generateJob = Start-Job -ScriptBlock {
- param($project,$projectPath,$rootSpaces,$taskPath)
+ param($root,$taskPath)
Add-Type -Path $taskPath
+ $task = New-Object WebApiProxy.Tasks.ProxyGenerationTask
+ $task.Root = $root
+ $task.Execute()
- $config = [WebApiProxy.Tasks.Models.Configuration]::Load($rootSpaces);
-
- $generator = New-Object WebApiProxy.Tasks.Infrastructure.CSharpGenerator -ArgumentList @($config)
- $fileName = (Join-Path $projectPath "WebApiProxy\WebApiProxy.generated.cs")
-
- Write-Host "Generating proxy code..."
-
- $source = $generator.Generate()
-
- $result = New-Item $fileName `
- -ItemType "file" -Force `
- -Value $source
-
- # $item = $project.ProjectItems.AddFromFile($fileName)
- } -ArgumentList @($project,$projectPath,$rootSpaces,$taskPath)
+ } -ArgumentList @($root,$taskPath)
$result = Receive-Job -Job $generateJob -Wait
Write-Host $result
Write-Host "Done."
-}
+}
Export-ModuleMember "WebApiProxy-Generate-CSharp"
diff --git a/WebApiProxy.Tasks/packages.config b/WebApiProxy.Tasks/packages.config
index e3e5ec9..9ce6161 100644
--- a/WebApiProxy.Tasks/packages.config
+++ b/WebApiProxy.Tasks/packages.config
@@ -1,5 +1,5 @@
-
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/WebApiProxy.Tasks/webapiproxy.snippet b/WebApiProxy.Tasks/webapiproxy.snippet
index bef34b9..827e14f 100644
--- a/WebApiProxy.Tasks/webapiproxy.snippet
+++ b/WebApiProxy.Tasks/webapiproxy.snippet
@@ -1,58 +1,58 @@
-
-
-
-
- WebAPIProxy Client
- webapiproxy
- Creates a new client for WebAPIProxy
- Fanie Reynders
-
- Expansion
-
-
-
-
-
- clientName
- The API resouce (controller) name
- Api
-
-
- clientSuffix
- Suffix as per config
- Client
-
-
- method
- Http method
- Get
-
-
- returnType
- Return type
- object
-
-
- useContent
- Read the content
- //
-
-
- parameters
- Parameters
-
-
-
-
- ();
- }
- ]]>
-
-
-
-
+
+
+
+
+ WebAPIProxy Client
+ webapiproxy
+ Creates a new client for WebAPIProxy
+ Fanie Reynders
+
+ Expansion
+
+
+
+
+
+ clientName
+ The API resouce (controller) name
+ Api
+
+
+ clientSuffix
+ Suffix as per config
+ Client
+
+
+ method
+ Http method
+ Get
+
+
+ returnType
+ Return type
+ object
+
+
+ useContent
+ Read the content
+ //
+
+
+ parameters
+ Parameters
+
+
+
+
+ ();
+ }
+ ]]>
+
+
+
+
diff --git a/WebApiProxy.sln b/WebApiProxy.sln
index d4ace1c..3c45f0f 100644
--- a/WebApiProxy.sln
+++ b/WebApiProxy.sln
@@ -1,47 +1,47 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.31101.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiProxy.Core", "WebApiProxy.Core\WebApiProxy.Core.csproj", "{94508206-8537-4088-923B-E7FCB0539903}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiProxy.Tasks", "WebApiProxy.Tasks\WebApiProxy.Tasks.csproj", "{A635DE23-DDC1-43ED-BC5D-D49B7E8A4355}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiProxy.Server", "WebApiProxy.Server\WebApiProxy.Server.csproj", "{4E5B8C2F-9008-4A17-ABD1-A92E046C6A1E}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{C3B525D0-5AC0-4267-AD47-09D8A05CE549}"
- ProjectSection(SolutionItems) = preProject
- .nuget\NuGet.Config = .nuget\NuGet.Config
- .nuget\NuGet.exe = .nuget\NuGet.exe
- .nuget\NuGet.targets = .nuget\NuGet.targets
- EndProjectSection
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Nuget", "Nuget", "{CC09190C-3038-49F9-ABD1-3C2F4FA81698}"
- ProjectSection(SolutionItems) = preProject
- Nuget\build-nuget-csharp.bat = Nuget\build-nuget-csharp.bat
- Nuget\build-nuget-server.bat = Nuget\build-nuget-server.bat
- EndProjectSection
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {94508206-8537-4088-923B-E7FCB0539903}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {94508206-8537-4088-923B-E7FCB0539903}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {94508206-8537-4088-923B-E7FCB0539903}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {94508206-8537-4088-923B-E7FCB0539903}.Release|Any CPU.Build.0 = Release|Any CPU
- {A635DE23-DDC1-43ED-BC5D-D49B7E8A4355}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {A635DE23-DDC1-43ED-BC5D-D49B7E8A4355}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {A635DE23-DDC1-43ED-BC5D-D49B7E8A4355}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {A635DE23-DDC1-43ED-BC5D-D49B7E8A4355}.Release|Any CPU.Build.0 = Release|Any CPU
- {4E5B8C2F-9008-4A17-ABD1-A92E046C6A1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {4E5B8C2F-9008-4A17-ABD1-A92E046C6A1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {4E5B8C2F-9008-4A17-ABD1-A92E046C6A1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {4E5B8C2F-9008-4A17-ABD1-A92E046C6A1E}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.25123.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiProxy.Core", "WebApiProxy.Core\WebApiProxy.Core.csproj", "{94508206-8537-4088-923B-E7FCB0539903}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiProxy.Tasks", "WebApiProxy.Tasks\WebApiProxy.Tasks.csproj", "{A635DE23-DDC1-43ED-BC5D-D49B7E8A4355}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiProxy.Server", "WebApiProxy.Server\WebApiProxy.Server.csproj", "{4E5B8C2F-9008-4A17-ABD1-A92E046C6A1E}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{C3B525D0-5AC0-4267-AD47-09D8A05CE549}"
+ ProjectSection(SolutionItems) = preProject
+ .nuget\NuGet.Config = .nuget\NuGet.Config
+ .nuget\NuGet.exe = .nuget\NuGet.exe
+ .nuget\NuGet.targets = .nuget\NuGet.targets
+ EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Nuget", "Nuget", "{CC09190C-3038-49F9-ABD1-3C2F4FA81698}"
+ ProjectSection(SolutionItems) = preProject
+ Nuget\build-nuget-csharp.bat = Nuget\build-nuget-csharp.bat
+ Nuget\build-nuget-server.bat = Nuget\build-nuget-server.bat
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {94508206-8537-4088-923B-E7FCB0539903}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {94508206-8537-4088-923B-E7FCB0539903}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {94508206-8537-4088-923B-E7FCB0539903}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {94508206-8537-4088-923B-E7FCB0539903}.Release|Any CPU.Build.0 = Release|Any CPU
+ {A635DE23-DDC1-43ED-BC5D-D49B7E8A4355}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {A635DE23-DDC1-43ED-BC5D-D49B7E8A4355}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {A635DE23-DDC1-43ED-BC5D-D49B7E8A4355}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {A635DE23-DDC1-43ED-BC5D-D49B7E8A4355}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4E5B8C2F-9008-4A17-ABD1-A92E046C6A1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4E5B8C2F-9008-4A17-ABD1-A92E046C6A1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4E5B8C2F-9008-4A17-ABD1-A92E046C6A1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4E5B8C2F-9008-4A17-ABD1-A92E046C6A1E}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/img/web-api-uoko/api-client-usage-di.jpg b/img/web-api-uoko/api-client-usage-di.jpg
new file mode 100644
index 0000000..1de3a62
Binary files /dev/null and b/img/web-api-uoko/api-client-usage-di.jpg differ
diff --git a/img/web-api-uoko/api-client-usage.jpg b/img/web-api-uoko/api-client-usage.jpg
new file mode 100644
index 0000000..61ffd48
Binary files /dev/null and b/img/web-api-uoko/api-client-usage.jpg differ
diff --git a/img/web-api-uoko/api-response-type-assign.jpg b/img/web-api-uoko/api-response-type-assign.jpg
new file mode 100644
index 0000000..9ab99d7
Binary files /dev/null and b/img/web-api-uoko/api-response-type-assign.jpg differ