Merge pull request #1741 from wing328/csharp_set_timeout

[C#] add timeout and update default constructor with optional value
This commit is contained in:
wing328 2015-12-20 23:35:20 +08:00
commit 391d0b9f9d
17 changed files with 99 additions and 57 deletions

View File

@ -24,15 +24,16 @@ namespace {{packageName}}.Client
/// <param name="apiKeyPrefix">Dictionary of API key prefix</param> /// <param name="apiKeyPrefix">Dictionary of API key prefix</param>
/// <param name="tempFolderPath">Temp folder path</param> /// <param name="tempFolderPath">Temp folder path</param>
/// <param name="dateTimeFormat">DateTime format string</param> /// <param name="dateTimeFormat">DateTime format string</param>
public Configuration(ApiClient apiClient, public Configuration(ApiClient apiClient = null,
Dictionary<String, String> defaultHeader, Dictionary<String, String> defaultHeader = null,
string username, string username = null,
string password, string password = null,
string accessToken, string accessToken = null,
Dictionary<String, String> apiKey, Dictionary<String, String> apiKey = null,
Dictionary<String, String> apiKeyPrefix, Dictionary<String, String> apiKeyPrefix = null,
string tempFolderPath, string tempFolderPath = null,
string dateTimeFormat string dateTimeFormat = null,
int timeout = 100000
) )
{ {
if (apiClient == null) if (apiClient == null)
@ -43,19 +44,24 @@ namespace {{packageName}}.Client
Username = username; Username = username;
Password = password; Password = password;
AccessToken = accessToken; AccessToken = accessToken;
ApiKey = apiKey;
ApiKeyPrefix = apiKeyPrefix; if (defaultHeader != null)
DefaultHeader = defaultHeader;
if (apiKey != null)
ApiKey = apiKey;
if (apiKeyPrefix != null)
ApiKeyPrefix = apiKeyPrefix;
TempFolderPath = tempFolderPath; TempFolderPath = tempFolderPath;
DateTimeFormat = dateTimeFormat; DateTimeFormat = dateTimeFormat;
Timeout = timeout;
} }
/// <summary> /// <summary>
/// Initializes a new instance of the Configuration class. /// Initializes a new instance of the Configuration class.
/// </summary> /// </summary>
/// <param name="apiClient">Api client.</param> /// <param name="apiClient">Api client.</param>
public Configuration(ApiClient apiClient=null) public Configuration(ApiClient apiClient)
{ {
if (apiClient == null) if (apiClient == null)
ApiClient = ApiClient.Default; ApiClient = ApiClient.Default;
@ -75,20 +81,39 @@ namespace {{packageName}}.Client
/// <value>Configuration.</value> /// <value>Configuration.</value>
public static Configuration Default = new Configuration(); public static Configuration Default = new Configuration();
/// <summary>
/// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds.
/// </summary>
/// <value>Timeout.</value>
public int Timeout
{
get { return ApiClient.RestClient.Timeout; }
set
{
ApiClient.RestClient.Timeout = value;
}
}
/// <summary> /// <summary>
/// Gets or sets the default API client for making HTTP calls. /// Gets or sets the default API client for making HTTP calls.
/// </summary> /// </summary>
/// <value>The API client.</value> /// <value>The API client.</value>
public ApiClient ApiClient; public ApiClient ApiClient;
private readonly Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>(); private Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
/// <summary> /// <summary>
/// Gets the default header. /// Gets or sets the default header.
/// </summary> /// </summary>
public Dictionary<String, String> DefaultHeader public Dictionary<String, String> DefaultHeader
{ {
get { return _defaultHeaderMap; } get { return _defaultHeaderMap; }
set
{
_defaultHeaderMap = value;
}
} }
/// <summary> /// <summary>

View File

@ -6,7 +6,6 @@ using RestSharp;
using IO.Swagger.Client; using IO.Swagger.Client;
using IO.Swagger.Model; using IO.Swagger.Model;
namespace IO.Swagger.Api namespace IO.Swagger.Api
{ {

View File

@ -6,7 +6,6 @@ using RestSharp;
using IO.Swagger.Client; using IO.Swagger.Client;
using IO.Swagger.Model; using IO.Swagger.Model;
namespace IO.Swagger.Api namespace IO.Swagger.Api
{ {

View File

@ -6,7 +6,6 @@ using RestSharp;
using IO.Swagger.Client; using IO.Swagger.Client;
using IO.Swagger.Model; using IO.Swagger.Model;
namespace IO.Swagger.Api namespace IO.Swagger.Api
{ {

View File

@ -24,15 +24,16 @@ namespace IO.Swagger.Client
/// <param name="apiKeyPrefix">Dictionary of API key prefix</param> /// <param name="apiKeyPrefix">Dictionary of API key prefix</param>
/// <param name="tempFolderPath">Temp folder path</param> /// <param name="tempFolderPath">Temp folder path</param>
/// <param name="dateTimeFormat">DateTime format string</param> /// <param name="dateTimeFormat">DateTime format string</param>
public Configuration(ApiClient apiClient, public Configuration(ApiClient apiClient = null,
Dictionary<String, String> defaultHeader, Dictionary<String, String> defaultHeader = null,
string username, string username = null,
string password, string password = null,
string accessToken, string accessToken = null,
Dictionary<String, String> apiKey, Dictionary<String, String> apiKey = null,
Dictionary<String, String> apiKeyPrefix, Dictionary<String, String> apiKeyPrefix = null,
string tempFolderPath, string tempFolderPath = null,
string dateTimeFormat string dateTimeFormat = null,
int timeout = 100000
) )
{ {
if (apiClient == null) if (apiClient == null)
@ -43,19 +44,24 @@ namespace IO.Swagger.Client
Username = username; Username = username;
Password = password; Password = password;
AccessToken = accessToken; AccessToken = accessToken;
ApiKey = apiKey;
ApiKeyPrefix = apiKeyPrefix; if (defaultHeader != null)
DefaultHeader = defaultHeader;
if (apiKey != null)
ApiKey = apiKey;
if (apiKeyPrefix != null)
ApiKeyPrefix = apiKeyPrefix;
TempFolderPath = tempFolderPath; TempFolderPath = tempFolderPath;
DateTimeFormat = dateTimeFormat; DateTimeFormat = dateTimeFormat;
Timeout = timeout;
} }
/// <summary> /// <summary>
/// Initializes a new instance of the Configuration class. /// Initializes a new instance of the Configuration class.
/// </summary> /// </summary>
/// <param name="apiClient">Api client.</param> /// <param name="apiClient">Api client.</param>
public Configuration(ApiClient apiClient=null) public Configuration(ApiClient apiClient)
{ {
if (apiClient == null) if (apiClient == null)
ApiClient = ApiClient.Default; ApiClient = ApiClient.Default;
@ -75,20 +81,39 @@ namespace IO.Swagger.Client
/// <value>Configuration.</value> /// <value>Configuration.</value>
public static Configuration Default = new Configuration(); public static Configuration Default = new Configuration();
/// <summary>
/// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds.
/// </summary>
/// <value>Timeout.</value>
public int Timeout
{
get { return ApiClient.RestClient.Timeout; }
set
{
ApiClient.RestClient.Timeout = value;
}
}
/// <summary> /// <summary>
/// Gets or sets the default API client for making HTTP calls. /// Gets or sets the default API client for making HTTP calls.
/// </summary> /// </summary>
/// <value>The API client.</value> /// <value>The API client.</value>
public ApiClient ApiClient; public ApiClient ApiClient;
private readonly Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>(); private Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
/// <summary> /// <summary>
/// Gets the default header. /// Gets or sets the default header.
/// </summary> /// </summary>
public Dictionary<String, String> DefaultHeader public Dictionary<String, String> DefaultHeader
{ {
get { return _defaultHeaderMap; } get { return _defaultHeaderMap; }
set
{
_defaultHeaderMap = value;
}
} }
/// <summary> /// <summary>

View File

@ -7,8 +7,6 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model namespace IO.Swagger.Model
{ {
@ -124,6 +122,4 @@ namespace IO.Swagger.Model
} }
} }
} }

View File

@ -7,8 +7,6 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model namespace IO.Swagger.Model
{ {
@ -189,6 +187,4 @@ namespace IO.Swagger.Model
} }
} }
} }

View File

@ -7,8 +7,6 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model namespace IO.Swagger.Model
{ {
@ -189,6 +187,4 @@ namespace IO.Swagger.Model
} }
} }
} }

View File

@ -7,8 +7,6 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model namespace IO.Swagger.Model
{ {
@ -124,6 +122,4 @@ namespace IO.Swagger.Model
} }
} }
} }

View File

@ -7,8 +7,6 @@ using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace IO.Swagger.Model namespace IO.Swagger.Model
{ {
@ -221,6 +219,4 @@ namespace IO.Swagger.Model
} }
} }
} }

View File

@ -107,5 +107,17 @@ namespace SwaggerClientTest.TestConfiguration
Assert.AreSame (p4.Configuration.ApiClient, a1); Assert.AreSame (p4.Configuration.ApiClient, a1);
} }
[Test ()]
public void TestTimeout ()
{
Configuration c1 = new Configuration();
Assert.AreEqual(100000, c1.Timeout); // default vaue
c1.Timeout = 50000;
Assert.AreEqual(50000, c1.Timeout);
Configuration c2 = new Configuration(timeout: 20000);
Assert.AreEqual(20000, c2.Timeout);
}
} }
} }

View File

@ -114,7 +114,10 @@ namespace SwaggerClientTest.TestPet
[Test ()] [Test ()]
public void TestGetPetById () public void TestGetPetById ()
{ {
PetApi petApi = new PetApi (); // set timeout to 10 seconds
Configuration c1 = new Configuration (timeout: 10000);
PetApi petApi = new PetApi (c1);
Pet response = petApi.GetPetById (petId); Pet response = petApi.GetPetById (petId);
Assert.IsInstanceOf<Pet> (response, "Response is a Pet"); Assert.IsInstanceOf<Pet> (response, "Response is a Pet");

View File

@ -1,9 +1,9 @@
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll