Skip to content

Commit

Permalink
Merge pull request #1741 from wing328/csharp_set_timeout
Browse files Browse the repository at this point in the history
[C#] add timeout and update default constructor with optional value
  • Loading branch information
wing328 committed Dec 20, 2015
2 parents 968c943 + 2cc5924 commit 391d0b9
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using IO.Swagger.Client;
using IO.Swagger.Model;


namespace IO.Swagger.Api
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using IO.Swagger.Client;
using IO.Swagger.Model;


namespace IO.Swagger.Api
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using IO.Swagger.Client;
using IO.Swagger.Model;


namespace IO.Swagger.Api
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ public class Configuration
/// <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)
Expand All @@ -43,19 +44,24 @@ string dateTimeFormat
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;
Expand All @@ -75,20 +81,39 @@ public Configuration(ApiClient apiClient=null)
/// <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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;



namespace IO.Swagger.Model
{

Expand Down Expand Up @@ -124,6 +122,4 @@ public override int GetHashCode()
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;



namespace IO.Swagger.Model
{

Expand Down Expand Up @@ -189,6 +187,4 @@ public override int GetHashCode()
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;



namespace IO.Swagger.Model
{

Expand Down Expand Up @@ -189,6 +187,4 @@ public override int GetHashCode()
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;



namespace IO.Swagger.Model
{

Expand Down Expand Up @@ -124,6 +122,4 @@ public override int GetHashCode()
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using System.Runtime.Serialization;
using Newtonsoft.Json;



namespace IO.Swagger.Model
{

Expand Down Expand Up @@ -221,6 +219,4 @@ public override int GetHashCode()
}

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,17 @@ public void TestUsage ()
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);
}
}
}
5 changes: 4 additions & 1 deletion samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ public void TestGetPetByIdAsyncWithHttpInfo ()
[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");

Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.
Binary file not shown.

0 comments on commit 391d0b9

Please sign in to comment.