PageRenderTime 129ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs

https://gitlab.com/akkhil2012/swagger-codegen
C# | 283 lines | 149 code | 35 blank | 99 comment | 26 complexity | 0a67ac2411cf0ab952f3495d335b5851 MD5 | raw file
  1. using System;
  2. using System.Reflection;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. namespace IO.Swagger.Client
  8. {
  9. /// <summary>
  10. /// Represents a set of configuration settings
  11. /// </summary>
  12. public class Configuration
  13. {
  14. /// <summary>
  15. /// Initializes a new instance of the Configuration class with different settings
  16. /// </summary>
  17. /// <param name="apiClient">Api client</param>
  18. /// <param name="defaultHeader">Dictionary of default HTTP header</param>
  19. /// <param name="username">Username</param>
  20. /// <param name="password">Password</param>
  21. /// <param name="accessToken">accessToken</param>
  22. /// <param name="apiKey">Dictionary of API key</param>
  23. /// <param name="apiKeyPrefix">Dictionary of API key prefix</param>
  24. /// <param name="tempFolderPath">Temp folder path</param>
  25. /// <param name="dateTimeFormat">DateTime format string</param>
  26. /// <param name="timeout">HTTP connection timeout (in milliseconds)</param>
  27. public Configuration(ApiClient apiClient = null,
  28. Dictionary<String, String> defaultHeader = null,
  29. string username = null,
  30. string password = null,
  31. string accessToken = null,
  32. Dictionary<String, String> apiKey = null,
  33. Dictionary<String, String> apiKeyPrefix = null,
  34. string tempFolderPath = null,
  35. string dateTimeFormat = null,
  36. int timeout = 100000,
  37. string userAgent = "Swagger-Codegen/1.0.0/csharp"
  38. )
  39. {
  40. setApiClientUsingDefault(apiClient);
  41. Username = username;
  42. Password = password;
  43. AccessToken = accessToken;
  44. UserAgent = userAgent;
  45. if (defaultHeader != null)
  46. DefaultHeader = defaultHeader;
  47. if (apiKey != null)
  48. ApiKey = apiKey;
  49. if (apiKeyPrefix != null)
  50. ApiKeyPrefix = apiKeyPrefix;
  51. TempFolderPath = tempFolderPath;
  52. DateTimeFormat = dateTimeFormat;
  53. Timeout = timeout;
  54. }
  55. /// <summary>
  56. /// Initializes a new instance of the Configuration class.
  57. /// </summary>
  58. /// <param name="apiClient">Api client.</param>
  59. public Configuration(ApiClient apiClient)
  60. {
  61. setApiClientUsingDefault(apiClient);
  62. }
  63. /// <summary>
  64. /// Version of the package.
  65. /// </summary>
  66. /// <value>Version of the package.</value>
  67. public const string Version = "1.0.0";
  68. /// <summary>
  69. /// Gets or sets the default Configuration.
  70. /// </summary>
  71. /// <value>Configuration.</value>
  72. public static Configuration Default = new Configuration();
  73. /// <summary>
  74. /// Gets or sets the HTTP timeout (milliseconds) of ApiClient. Default to 100000 milliseconds.
  75. /// </summary>
  76. /// <value>Timeout.</value>
  77. public int Timeout
  78. {
  79. get { return ApiClient.RestClient.Timeout; }
  80. set
  81. {
  82. if (ApiClient != null)
  83. ApiClient.RestClient.Timeout = value;
  84. }
  85. }
  86. /// <summary>
  87. /// Gets or sets the default API client for making HTTP calls.
  88. /// </summary>
  89. /// <value>The API client.</value>
  90. public ApiClient ApiClient;
  91. /// <summary>
  92. /// Set the ApiClient using Default or ApiClient instance.
  93. /// </summary>
  94. /// <param name="apiClient">An instance of ApiClient.</param>
  95. /// <returns></returns>
  96. public void setApiClientUsingDefault (ApiClient apiClient = null)
  97. {
  98. if (apiClient == null)
  99. {
  100. if (Default != null && Default.ApiClient == null)
  101. Default.ApiClient = new ApiClient();
  102. ApiClient = Default != null ? Default.ApiClient : new ApiClient();
  103. }
  104. else
  105. {
  106. if (Default != null && Default.ApiClient == null)
  107. Default.ApiClient = apiClient;
  108. ApiClient = apiClient;
  109. }
  110. }
  111. private Dictionary<String, String> _defaultHeaderMap = new Dictionary<String, String>();
  112. /// <summary>
  113. /// Gets or sets the default header.
  114. /// </summary>
  115. public Dictionary<String, String> DefaultHeader
  116. {
  117. get { return _defaultHeaderMap; }
  118. set
  119. {
  120. _defaultHeaderMap = value;
  121. }
  122. }
  123. /// <summary>
  124. /// Add default header.
  125. /// </summary>
  126. /// <param name="key">Header field name.</param>
  127. /// <param name="value">Header field value.</param>
  128. /// <returns></returns>
  129. public void AddDefaultHeader(string key, string value)
  130. {
  131. _defaultHeaderMap.Add(key, value);
  132. }
  133. /// <summary>
  134. /// Gets or sets the HTTP user agent.
  135. /// </summary>
  136. /// <value>Http user agent.</value>
  137. public String UserAgent { get; set; }
  138. /// <summary>
  139. /// Gets or sets the username (HTTP basic authentication).
  140. /// </summary>
  141. /// <value>The username.</value>
  142. public String Username { get; set; }
  143. /// <summary>
  144. /// Gets or sets the password (HTTP basic authentication).
  145. /// </summary>
  146. /// <value>The password.</value>
  147. public String Password { get; set; }
  148. /// <summary>
  149. /// Gets or sets the access token for OAuth2 authentication.
  150. /// </summary>
  151. /// <value>The access token.</value>
  152. public String AccessToken { get; set; }
  153. /// <summary>
  154. /// Gets or sets the API key based on the authentication name.
  155. /// </summary>
  156. /// <value>The API key.</value>
  157. public Dictionary<String, String> ApiKey = new Dictionary<String, String>();
  158. /// <summary>
  159. /// Gets or sets the prefix (e.g. Token) of the API key based on the authentication name.
  160. /// </summary>
  161. /// <value>The prefix of the API key.</value>
  162. public Dictionary<String, String> ApiKeyPrefix = new Dictionary<String, String>();
  163. /// <summary>
  164. /// Get the API key with prefix.
  165. /// </summary>
  166. /// <param name="apiKeyIdentifier">API key identifier (authentication scheme).</param>
  167. /// <returns>API key with prefix.</returns>
  168. public string GetApiKeyWithPrefix (string apiKeyIdentifier)
  169. {
  170. var apiKeyValue = "";
  171. ApiKey.TryGetValue (apiKeyIdentifier, out apiKeyValue);
  172. var apiKeyPrefix = "";
  173. if (ApiKeyPrefix.TryGetValue (apiKeyIdentifier, out apiKeyPrefix))
  174. return apiKeyPrefix + " " + apiKeyValue;
  175. else
  176. return apiKeyValue;
  177. }
  178. private string _tempFolderPath = Path.GetTempPath();
  179. /// <summary>
  180. /// Gets or sets the temporary folder path to store the files downloaded from the server.
  181. /// </summary>
  182. /// <value>Folder path.</value>
  183. public String TempFolderPath
  184. {
  185. get { return _tempFolderPath; }
  186. set
  187. {
  188. if (String.IsNullOrEmpty(value))
  189. {
  190. _tempFolderPath = value;
  191. return;
  192. }
  193. // create the directory if it does not exist
  194. if (!Directory.Exists(value))
  195. Directory.CreateDirectory(value);
  196. // check if the path contains directory separator at the end
  197. if (value[value.Length - 1] == Path.DirectorySeparatorChar)
  198. _tempFolderPath = value;
  199. else
  200. _tempFolderPath = value + Path.DirectorySeparatorChar;
  201. }
  202. }
  203. private const string ISO8601_DATETIME_FORMAT = "o";
  204. private string _dateTimeFormat = ISO8601_DATETIME_FORMAT;
  205. /// <summary>
  206. /// Gets or sets the the date time format used when serializing in the ApiClient
  207. /// By default, it's set to ISO 8601 - "o", for others see:
  208. /// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx
  209. /// and https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
  210. /// No validation is done to ensure that the string you're providing is valid
  211. /// </summary>
  212. /// <value>The DateTimeFormat string</value>
  213. public String DateTimeFormat
  214. {
  215. get
  216. {
  217. return _dateTimeFormat;
  218. }
  219. set
  220. {
  221. if (string.IsNullOrEmpty(value))
  222. {
  223. // Never allow a blank or null string, go back to the default
  224. _dateTimeFormat = ISO8601_DATETIME_FORMAT;
  225. return;
  226. }
  227. // Caution, no validation when you choose date time format other than ISO 8601
  228. // Take a look at the above links
  229. _dateTimeFormat = value;
  230. }
  231. }
  232. /// <summary>
  233. /// Returns a string with essential information for debugging.
  234. /// </summary>
  235. public static String ToDebugReport()
  236. {
  237. String report = "C# SDK (IO.Swagger) Debug Report:\n";
  238. report += " OS: " + Environment.OSVersion + "\n";
  239. report += " .NET Framework Version: " + Assembly
  240. .GetExecutingAssembly()
  241. .GetReferencedAssemblies()
  242. .Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
  243. report += " Version of the API: 1.0.0\n";
  244. report += " SDK Package Version: 1.0.0\n";
  245. return report;
  246. }
  247. }
  248. }