Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.49 KB | None | 0 0
  1. //----------------------
  2. // <auto-generated>
  3. // Generated using the NSwag toolchain v13.2.2.0 (NJsonSchema v10.1.4.0 (Newtonsoft.Json v11.0.0.0)) (http://NSwag.org)
  4. // </auto-generated>
  5. //----------------------
  6.  
  7. #pragma warning disable 108 // Disable "CS0108 '{derivedDto}.ToJson()' hides inherited member '{dtoBase}.ToJson()'. Use the new keyword if hiding was intended."
  8. #pragma warning disable 114 // Disable "CS0114 '{derivedDto}.RaisePropertyChanged(String)' hides inherited member 'dtoBase.RaisePropertyChanged(String)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword."
  9. #pragma warning disable 472 // Disable "CS0472 The result of the expression is always 'false' since a value of type 'Int32' is never equal to 'null' of type 'Int32?'
  10. #pragma warning disable 1573 // Disable "CS1573 Parameter '...' has no matching param tag in the XML comment for ...
  11. #pragma warning disable 1591 // Disable "CS1591 Missing XML comment for publicly visible type or member ..."
  12.  
  13. namespace Sec.Services.Shared
  14. {
  15. using System = global::System;
  16.  
  17. [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.2.2.0 (NJsonSchema v10.1.4.0 (Newtonsoft.Json v11.0.0.0))")]
  18. public partial class Client
  19. {
  20. private string _baseUrl = "";
  21. private System.Net.Http.HttpClient _httpClient;
  22. private System.Lazy<Newtonsoft.Json.JsonSerializerSettings> _settings;
  23.  
  24. public Client(string baseUrl, System.Net.Http.HttpClient httpClient)
  25. {
  26. BaseUrl = baseUrl;
  27. _httpClient = httpClient;
  28. _settings = new System.Lazy<Newtonsoft.Json.JsonSerializerSettings>(CreateSerializerSettings);
  29. }
  30.  
  31. private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings()
  32. {
  33. var settings = new Newtonsoft.Json.JsonSerializerSettings();
  34. UpdateJsonSerializerSettings(settings);
  35. return settings;
  36. }
  37.  
  38. public string BaseUrl
  39. {
  40. get { return _baseUrl; }
  41. set { _baseUrl = value; }
  42. }
  43.  
  44. protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _settings.Value; } }
  45.  
  46. partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings);
  47. partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url);
  48. partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder);
  49. partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response);
  50.  
  51. /// <summary>Convert incoming files into pdf</summary>
  52. /// <returns>Converted file content</returns>
  53. /// <exception cref="ApiException">A server side error occurred.</exception>
  54. public System.Threading.Tasks.Task<FileResponse> ConvertAsync(Body body)
  55. {
  56. return ConvertAsync(body, System.Threading.CancellationToken.None);
  57. }
  58.  
  59. /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
  60. /// <summary>Convert incoming files into pdf</summary>
  61. /// <returns>Converted file content</returns>
  62. /// <exception cref="ApiException">A server side error occurred.</exception>
  63. public async System.Threading.Tasks.Task<FileResponse> ConvertAsync(Body body, System.Threading.CancellationToken cancellationToken)
  64. {
  65. var urlBuilder_ = new System.Text.StringBuilder();
  66. urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/convert");
  67.  
  68. var client_ = _httpClient;
  69. try
  70. {
  71. using (var request_ = new System.Net.Http.HttpRequestMessage())
  72. {
  73. var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value));
  74. content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
  75. request_.Content = content_;
  76. request_.Method = new System.Net.Http.HttpMethod("POST");
  77. request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/pdf"));
  78.  
  79. PrepareRequest(client_, request_, urlBuilder_);
  80. var url_ = urlBuilder_.ToString();
  81. request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
  82. PrepareRequest(client_, request_, url_);
  83.  
  84. var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
  85. try
  86. {
  87. var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
  88. if (response_.Content != null && response_.Content.Headers != null)
  89. {
  90. foreach (var item_ in response_.Content.Headers)
  91. headers_[item_.Key] = item_.Value;
  92. }
  93.  
  94. ProcessResponse(client_, response_);
  95.  
  96. var status_ = ((int)response_.StatusCode).ToString();
  97. if (status_ == "200" || status_ == "206")
  98. {
  99. var responseStream_ = response_.Content == null ? System.IO.Stream.Null : await response_.Content.ReadAsStreamAsync().ConfigureAwait(false);
  100. var fileResponse_ = new FileResponse((int)response_.StatusCode, headers_, responseStream_, null, response_);
  101. client_ = null; response_ = null; // response and client are disposed by FileResponse
  102. return fileResponse_;
  103. }
  104. else
  105. if (status_ == "400")
  106. {
  107. var objectResponse_ = await ReadObjectResponseAsync<object>(response_, headers_).ConfigureAwait(false);
  108. throw new ApiException<object>("Error message", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object, null);
  109. }
  110. else
  111. if (status_ == "500")
  112. {
  113. var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
  114. var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string));
  115. }
  116. else
  117. if (status_ != "200" && status_ != "204")
  118. {
  119. var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
  120. throw new ApiException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", (int)response_.StatusCode, responseData_, headers_, null);
  121. }
  122.  
  123. return default(FileResponse);
  124. }
  125. finally
  126. {
  127. if (response_ != null)
  128. response_.Dispose();
  129. }
  130. }
  131. }
  132. finally
  133. {
  134. }
  135. }
  136.  
  137. /// <summary>Fill template template with data and generate report file.</summary>
  138. /// <returns>Report file content</returns>
  139. /// <exception cref="ApiException">A server side error occurred.</exception>
  140. public System.Threading.Tasks.Task<FileResponse> PrintAsync(Body2 body)
  141. {
  142. return PrintAsync(body, System.Threading.CancellationToken.None);
  143. }
  144.  
  145. /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
  146. /// <summary>Fill template template with data and generate report file.</summary>
  147. /// <returns>Report file content</returns>
  148. /// <exception cref="ApiException">A server side error occurred.</exception>
  149. public async System.Threading.Tasks.Task<FileResponse> PrintAsync(Body2 body, System.Threading.CancellationToken cancellationToken)
  150. {
  151. var urlBuilder_ = new System.Text.StringBuilder();
  152. urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/print");
  153.  
  154. var client_ = _httpClient;
  155. try
  156. {
  157. using (var request_ = new System.Net.Http.HttpRequestMessage())
  158. {
  159. var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value));
  160. content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
  161. request_.Content = content_;
  162. request_.Method = new System.Net.Http.HttpMethod("POST");
  163. request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/vnd.oasis.opendocument.text"));
  164.  
  165. PrepareRequest(client_, request_, urlBuilder_);
  166. var url_ = urlBuilder_.ToString();
  167. request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
  168. PrepareRequest(client_, request_, url_);
  169.  
  170. var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
  171. try
  172. {
  173. var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
  174. if (response_.Content != null && response_.Content.Headers != null)
  175. {
  176. foreach (var item_ in response_.Content.Headers)
  177. headers_[item_.Key] = item_.Value;
  178. }
  179.  
  180. ProcessResponse(client_, response_);
  181.  
  182. var status_ = ((int)response_.StatusCode).ToString();
  183. if (status_ == "200" || status_ == "206")
  184. {
  185. var responseStream_ = response_.Content == null ? System.IO.Stream.Null : await response_.Content.ReadAsStreamAsync().ConfigureAwait(false);
  186. var fileResponse_ = new FileResponse((int)response_.StatusCode, headers_, responseStream_, null, response_);
  187. client_ = null; response_ = null; // response and client are disposed by FileResponse
  188. return fileResponse_;
  189. }
  190. else
  191. if (status_ == "400")
  192. {
  193. var objectResponse_ = await ReadObjectResponseAsync<object>(response_, headers_).ConfigureAwait(false);
  194. throw new ApiException<object>("Error message", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object, null);
  195. }
  196. else
  197. if (status_ == "500")
  198. {
  199. var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
  200. var result_ = (string)System.Convert.ChangeType(responseData_, typeof(string));
  201. }
  202. else
  203. if (status_ != "200" && status_ != "204")
  204. {
  205. var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
  206. throw new ApiException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", (int)response_.StatusCode, responseData_, headers_, null);
  207. }
  208.  
  209. return default(FileResponse);
  210. }
  211. finally
  212. {
  213. if (response_ != null)
  214. response_.Dispose();
  215. }
  216. }
  217. }
  218. finally
  219. {
  220. }
  221. }
  222.  
  223. protected struct ObjectResponseResult<T>
  224. {
  225. public ObjectResponseResult(T responseObject, string responseText)
  226. {
  227. this.Object = responseObject;
  228. this.Text = responseText;
  229. }
  230.  
  231. public T Object { get; }
  232.  
  233. public string Text { get; }
  234. }
  235.  
  236. public bool ReadResponseAsString { get; set; }
  237.  
  238. protected virtual async System.Threading.Tasks.Task<ObjectResponseResult<T>> ReadObjectResponseAsync<T>(System.Net.Http.HttpResponseMessage response, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers)
  239. {
  240. if (response == null || response.Content == null)
  241. {
  242. return new ObjectResponseResult<T>(default(T), string.Empty);
  243. }
  244.  
  245. if (ReadResponseAsString)
  246. {
  247. var responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
  248. try
  249. {
  250. var typedBody = Newtonsoft.Json.JsonConvert.DeserializeObject<T>(responseText, JsonSerializerSettings);
  251. return new ObjectResponseResult<T>(typedBody, responseText);
  252. }
  253. catch (Newtonsoft.Json.JsonException exception)
  254. {
  255. var message = "Could not deserialize the response body string as " + typeof(T).FullName + ".";
  256. throw new ApiException(message, (int)response.StatusCode, responseText, headers, exception);
  257. }
  258. }
  259. else
  260. {
  261. try
  262. {
  263. using (var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false))
  264. using (var streamReader = new System.IO.StreamReader(responseStream))
  265. using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(streamReader))
  266. {
  267. var serializer = Newtonsoft.Json.JsonSerializer.Create(JsonSerializerSettings);
  268. var typedBody = serializer.Deserialize<T>(jsonTextReader);
  269. return new ObjectResponseResult<T>(typedBody, string.Empty);
  270. }
  271. }
  272. catch (Newtonsoft.Json.JsonException exception)
  273. {
  274. var message = "Could not deserialize the response body stream as " + typeof(T).FullName + ".";
  275. throw new ApiException(message, (int)response.StatusCode, string.Empty, headers, exception);
  276. }
  277. }
  278. }
  279.  
  280. private string ConvertToString(object value, System.Globalization.CultureInfo cultureInfo)
  281. {
  282. if (value is System.Enum)
  283. {
  284. string name = System.Enum.GetName(value.GetType(), value);
  285. if (name != null)
  286. {
  287. var field = System.Reflection.IntrospectionExtensions.GetTypeInfo(value.GetType()).GetDeclaredField(name);
  288. if (field != null)
  289. {
  290. var attribute = System.Reflection.CustomAttributeExtensions.GetCustomAttribute(field, typeof(System.Runtime.Serialization.EnumMemberAttribute))
  291. as System.Runtime.Serialization.EnumMemberAttribute;
  292. if (attribute != null)
  293. {
  294. return attribute.Value != null ? attribute.Value : name;
  295. }
  296. }
  297. }
  298. }
  299. else if (value is bool) {
  300. return System.Convert.ToString(value, cultureInfo).ToLowerInvariant();
  301. }
  302. else if (value is byte[])
  303. {
  304. return System.Convert.ToBase64String((byte[]) value);
  305. }
  306. else if (value != null && value.GetType().IsArray)
  307. {
  308. var array = System.Linq.Enumerable.OfType<object>((System.Array) value);
  309. return string.Join(",", System.Linq.Enumerable.Select(array, o => ConvertToString(o, cultureInfo)));
  310. }
  311.  
  312. return System.Convert.ToString(value, cultureInfo);
  313. }
  314. }
  315.  
  316. [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.4.0 (Newtonsoft.Json v11.0.0.0)")]
  317. public partial class Body
  318. {
  319. [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Always)]
  320. [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
  321. public string Name { get; set; }
  322.  
  323. [Newtonsoft.Json.JsonProperty("content", Required = Newtonsoft.Json.Required.Always)]
  324. [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
  325. public byte[] Content { get; set; }
  326.  
  327. [Newtonsoft.Json.JsonProperty("orientation", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
  328. [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
  329. public BodyOrientation Orientation { get; set; } = Sec.Services.Shared.BodyOrientation.Portrait;
  330.  
  331. private System.Collections.Generic.IDictionary<string, object> _additionalProperties = new System.Collections.Generic.Dictionary<string, object>();
  332.  
  333. [Newtonsoft.Json.JsonExtensionData]
  334. public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
  335. {
  336. get { return _additionalProperties; }
  337. set { _additionalProperties = value; }
  338. }
  339.  
  340.  
  341. }
  342.  
  343. [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.4.0 (Newtonsoft.Json v11.0.0.0)")]
  344. public partial class Body2
  345. {
  346. [Newtonsoft.Json.JsonProperty("convert", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
  347. public bool Convert { get; set; } = true;
  348.  
  349. [Newtonsoft.Json.JsonProperty("template", Required = Newtonsoft.Json.Required.Always)]
  350. [System.ComponentModel.DataAnnotations.Required]
  351. public Template Template { get; set; } = new Template();
  352.  
  353. [Newtonsoft.Json.JsonProperty("variables", Required = Newtonsoft.Json.Required.Always)]
  354. [System.ComponentModel.DataAnnotations.Required]
  355. public object Variables { get; set; } = new object();
  356.  
  357. [Newtonsoft.Json.JsonProperty("images", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
  358. public System.Collections.Generic.IDictionary<string, byte[]> Images { get; set; }
  359.  
  360. private System.Collections.Generic.IDictionary<string, object> _additionalProperties = new System.Collections.Generic.Dictionary<string, object>();
  361.  
  362. [Newtonsoft.Json.JsonExtensionData]
  363. public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
  364. {
  365. get { return _additionalProperties; }
  366. set { _additionalProperties = value; }
  367. }
  368.  
  369.  
  370. }
  371.  
  372. [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.4.0 (Newtonsoft.Json v11.0.0.0)")]
  373. public enum BodyOrientation
  374. {
  375. [System.Runtime.Serialization.EnumMember(Value = @"Portrait")]
  376. Portrait = 0,
  377.  
  378. [System.Runtime.Serialization.EnumMember(Value = @"Landscape")]
  379. Landscape = 1,
  380.  
  381. }
  382.  
  383. [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "10.1.4.0 (Newtonsoft.Json v11.0.0.0)")]
  384. public partial class Template
  385. {
  386. [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Always)]
  387. [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
  388. public string Name { get; set; }
  389.  
  390. [Newtonsoft.Json.JsonProperty("content", Required = Newtonsoft.Json.Required.Always)]
  391. [System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = true)]
  392. public byte[] Content { get; set; }
  393.  
  394. private System.Collections.Generic.IDictionary<string, object> _additionalProperties = new System.Collections.Generic.Dictionary<string, object>();
  395.  
  396. [Newtonsoft.Json.JsonExtensionData]
  397. public System.Collections.Generic.IDictionary<string, object> AdditionalProperties
  398. {
  399. get { return _additionalProperties; }
  400. set { _additionalProperties = value; }
  401. }
  402.  
  403.  
  404. }
  405.  
  406. public partial class FileResponse : System.IDisposable
  407. {
  408. private System.IDisposable _client;
  409. private System.IDisposable _response;
  410.  
  411. public int StatusCode { get; private set; }
  412.  
  413. public System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> Headers { get; private set; }
  414.  
  415. public System.IO.Stream Stream { get; private set; }
  416.  
  417. public bool IsPartial
  418. {
  419. get { return StatusCode == 206; }
  420. }
  421.  
  422. public FileResponse(int statusCode, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers, System.IO.Stream stream, System.IDisposable client, System.IDisposable response)
  423. {
  424. StatusCode = statusCode;
  425. Headers = headers;
  426. Stream = stream;
  427. _client = client;
  428. _response = response;
  429. }
  430.  
  431. public void Dispose()
  432. {
  433. if (Stream != null)
  434. Stream.Dispose();
  435. if (_response != null)
  436. _response.Dispose();
  437. if (_client != null)
  438. _client.Dispose();
  439. }
  440. }
  441.  
  442. [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.2.2.0 (NJsonSchema v10.1.4.0 (Newtonsoft.Json v11.0.0.0))")]
  443. public partial class ApiException : System.Exception
  444. {
  445. public int StatusCode { get; private set; }
  446.  
  447. public string Response { get; private set; }
  448.  
  449. public System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> Headers { get; private set; }
  450.  
  451. public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers, System.Exception innerException)
  452. : base(message + "\n\nStatus: " + statusCode + "\nResponse: \n" + response.Substring(0, response.Length >= 512 ? 512 : response.Length), innerException)
  453. {
  454. StatusCode = statusCode;
  455. Response = response;
  456. Headers = headers;
  457. }
  458.  
  459. public override string ToString()
  460. {
  461. return string.Format("HTTP Response: \n\n{0}\n\n{1}", Response, base.ToString());
  462. }
  463. }
  464.  
  465. [System.CodeDom.Compiler.GeneratedCode("NSwag", "13.2.2.0 (NJsonSchema v10.1.4.0 (Newtonsoft.Json v11.0.0.0))")]
  466. public partial class ApiException<TResult> : ApiException
  467. {
  468. public TResult Result { get; private set; }
  469.  
  470. public ApiException(string message, int statusCode, string response, System.Collections.Generic.IReadOnlyDictionary<string, System.Collections.Generic.IEnumerable<string>> headers, TResult result, System.Exception innerException)
  471. : base(message, statusCode, response, headers, innerException)
  472. {
  473. Result = result;
  474. }
  475. }
  476.  
  477. }
  478.  
  479. #pragma warning restore 1591
  480. #pragma warning restore 1573
  481. #pragma warning restore 472
  482. #pragma warning restore 114
  483. #pragma warning restore 108
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement