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

View File

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

View File

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

View File

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

View File

@ -7,8 +7,6 @@ using System.Collections.Generic;
using System.Runtime.Serialization;
using Newtonsoft.Json;
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 Newtonsoft.Json;
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 Newtonsoft.Json;
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 Newtonsoft.Json;
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 Newtonsoft.Json;
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);
}
[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 ()]
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);
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/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
/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/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