diff --git a/config/csharp.yaml b/config/csharp.yaml index 213292c4..cf3d5561 100644 --- a/config/csharp.yaml +++ b/config/csharp.yaml @@ -1,5 +1,7 @@ changelog: - - 1.3.1 (2024-02-19): + - 1.4.0 (2024-06-11): + - .net 5.0 support + - 1.3.1 (2024-02-19): - Update VideoStatusIngest enum - 1.3.0 (2023-06-28): - Introducing new live streams restream feature diff --git a/templates/csharp/ApiClient.mustache b/templates/csharp/ApiClient.mustache index acae4d48..3143202a 100644 --- a/templates/csharp/ApiClient.mustache +++ b/templates/csharp/ApiClient.mustache @@ -30,6 +30,10 @@ namespace {{packageName}}.Client private const int DEFAULT_CHUNK_SIZE = {{ defaultChunkSize }}; private const int MIN_CHUNK_SIZE = {{ minChunkSize }}; private const int MAX_CHUNK_SIZE = {{ maxChunkSize }}; + private int timeout = 60000; + private String basePath = "ws.api.video"; + private Dictionary originHeaders = new Dictionary(); + private readonly JsonSerializerSettings serializerSettings = new JsonSerializerSettings { @@ -47,7 +51,7 @@ namespace {{packageName}}.Client /// Allows for extending request processing for generated code. /// /// The RestSharp request object - private RestRequest InterceptRequest(IRestRequest request){ + private RestRequest InterceptRequest(RestRequest request){ if(AuthManager != null) return AuthManager.Intercept(request) as RestRequest; return request as RestRequest; @@ -58,7 +62,15 @@ namespace {{packageName}}.Client /// Constructor for ApiClient with custom basePath /// /// the api base path. - public ApiClient(string basePath): this(new RestClient(basePath)) { + public ApiClient(string basePath) { + var options = new RestClientOptions() + { + ThrowOnAnyError = true, + BaseUrl = new Uri(basePath) + }; + RestClient client = new RestClient(options); + + Initialize(client); } /// @@ -75,7 +87,14 @@ namespace {{packageName}}.Client /// Constructor for ApiClient with custom http client. /// /// a RestClient instance used to make API call - public ApiClient(RestClient client) { + public ApiClient(IRestClient client) { + Initialize(client); + + } + + + private void Initialize(IRestClient client) + { this.RestClient = client; setName("AV-Origin-Client", "csharp", "{{ artifactVersion }}"); } @@ -121,7 +140,7 @@ namespace {{packageName}}.Client throw new Exception("Invalid version value. The version should match the xxx[.yyy][.zzz] pattern."); } - this.RestClient.AddDefaultHeader(key, name + ":" + version); + this.originHeaders.Add(key, name + ":" + version); } private bool isValidName(string name) @@ -141,7 +160,7 @@ namespace {{packageName}}.Client /// /// Timeout in milliseconds public int GetTimeout() { - return this.RestClient.Timeout; + return ((int)this.timeout); } /// @@ -153,7 +172,7 @@ namespace {{packageName}}.Client public ApiClient SetTimeout(int connectionTimeout) { // set timeout {{#netStandard}}RestClient.Timeout = TimeSpan.FromMilliseconds(connectionTimeout);{{/netStandard}} - {{^netStandard}}RestClient.Timeout = connectionTimeout;{{/netStandard}} + {{^netStandard}}this.timeout = connectionTimeout;{{/netStandard}} return this; } @@ -161,13 +180,13 @@ namespace {{packageName}}.Client /// Gets or sets the RestClient. /// /// An instance of the RestClient - public RestClient RestClient { get; set; } + public IRestClient RestClient { get; set; } /// /// Sets the api base path. /// public void SetBasePath(string basePath) { - this.RestClient.BaseUrl = new Uri(basePath); + this.basePath = basePath; } @@ -196,6 +215,7 @@ namespace {{packageName}}.Client string contentType) { var request = new RestRequest(path, method); + request.Timeout = new TimeSpan(0, 0, this.timeout); {{#netStandard}} // disable ResetSharp.Portable built-in serialization request.Serializer = null; @@ -209,6 +229,9 @@ namespace {{packageName}}.Client foreach(var param in headerParams) request.AddHeader(param.Key, param.Value); + foreach(var param in this.originHeaders) + request.AddHeader(param.Key, param.Value); + // add query parameter, if any foreach(var param in queryParams) request.AddQueryParameter(param.Key, param.Value); @@ -225,7 +248,7 @@ namespace {{packageName}}.Client {{/netStandard}} {{^netStandard}} {{^supportsUWP}} - request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType); + request.AddFile(param.Value.Name, param.Value.GetFile, param.Value.FileName, param.Value.ContentType); {{/supportsUWP}} {{#supportsUWP}} byte[] paramWriter = null; @@ -281,7 +304,7 @@ namespace {{packageName}}.Client {{/supportsUWP}} {{#supportsUWP}} // Using async method to perform sync call (uwp-only) - var response = RestClient.ExecuteTaskAsync(request).Result; + var response = RestClient.ExecuteAsync(request).Result; {{/supportsUWP}} {{/netStandard}} this.CheckResponse(response); @@ -293,7 +316,7 @@ namespace {{packageName}}.Client /// Check if the api call response was successful /// /// The response to check - private void CheckResponse(IRestResponse response) + private void CheckResponse(RestResponse response) { if (response.ResponseStatus != ResponseStatus.Completed) { @@ -339,7 +362,7 @@ namespace {{packageName}}.Client path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, contentType); request = InterceptRequest(request); - var response = await RestClient.Execute{{^netStandard}}TaskAsync{{/netStandard}}(request, cancellationToken); + var response = await RestClient.Execute{{^netStandard}}Async{{/netStandard}}(request, cancellationToken); return (Object)response; }{{/supportsAsync}} @@ -404,9 +427,9 @@ namespace {{packageName}}.Client /// The HTTP response. /// Object type. /// Object representation of the JSON string. - public object Deserialize(IRestResponse response, Type type) + public object Deserialize(RestResponse response, Type type) { - {{^netStandard}}IList{{/netStandard}}{{#netStandard}}IHttpHeaders{{/netStandard}} headers = response.Headers; + IReadOnlyCollection headers = response.Headers; if (type == typeof(byte[])) // return byte array { return response.RawBytes; diff --git a/templates/csharp/ApiVideoClient.mustache b/templates/csharp/ApiVideoClient.mustache index cd12fcf3..0dd95700 100644 --- a/templates/csharp/ApiVideoClient.mustache +++ b/templates/csharp/ApiVideoClient.mustache @@ -54,7 +54,7 @@ namespace {{packageName}}.Client /// Build an instance that targets the production environment using a custom OkHttp client /// /// the RestClient instance to use - public ApiVideoClient(RestClient client) : this(new ApiClient(client)) + public ApiVideoClient(IRestClient client) : this(new ApiClient(client)) { } @@ -107,7 +107,7 @@ namespace {{packageName}}.Client /// The rest client timeout public int GetTimeout() { - return this.apiClient.RestClient.Timeout; + return this.apiClient.GetTimeout(); } /// @@ -116,7 +116,7 @@ namespace {{packageName}}.Client /// the new timeout public void SetTimeout(int newTimeOut) { - this.apiClient.RestClient.Timeout = newTimeOut; + this.apiClient.SetTimeout(newTimeOut); } /// diff --git a/templates/csharp/AssemblyInfo.mustache b/templates/csharp/AssemblyInfo.mustache index bf80d7d4..9c8f9fdf 100644 --- a/templates/csharp/AssemblyInfo.mustache +++ b/templates/csharp/AssemblyInfo.mustache @@ -1,15 +1,6 @@ using System.Reflection; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("{{packageTitle}}")] -[assembly: AssemblyDescription("{{packageDescription}}")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("{{packageCompany}}")] -[assembly: AssemblyProduct("{{packageProductName}}")] -[assembly: AssemblyCopyright("{{packageCopyright}}")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -17,16 +8,3 @@ using System.Runtime.InteropServices; // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("{{packageVersion}}")] -[assembly: AssemblyFileVersion("{{packageVersion}}")] diff --git a/templates/csharp/AuthenticationManager.mustache b/templates/csharp/AuthenticationManager.mustache index 24476be1..b74139cc 100644 --- a/templates/csharp/AuthenticationManager.mustache +++ b/templates/csharp/AuthenticationManager.mustache @@ -36,7 +36,7 @@ namespace {{packageName}}.Client /// /// The request to update /// The request updated - public IRestRequest Intercept(IRestRequest request){ + public RestRequest Intercept(RestRequest request){ if(request.Resource.Equals("/auth/api-key")) { return request; diff --git a/templates/csharp/Project.mustache b/templates/csharp/Project.mustache index 74474939..114730b8 100644 --- a/templates/csharp/Project.mustache +++ b/templates/csharp/Project.mustache @@ -1,4 +1,3 @@ - - + + net5.0 {{#netStandard}}14.0{{/netStandard}} - Debug - AnyCPU - {{packageGuid}} Library - Properties - {{packageName}} - {{packageName}} - {{#netStandard}} - {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - {{targetFramework}} - {{/netStandard}} - {{^netStandard}} - {{^supportsUWP}} - {{targetFramework}} - {{/supportsUWP}} - {{#supportsUWP}} - UAP - 10.0.10240.0 - 10.0.10240.0 - 14 - {{/supportsUWP}} - {{/netStandard}} - 512 true {{packageName}} {{artifactVersion}} @@ -45,89 +23,35 @@ true MIT {{artifactUrl}} + false + api.video API client + api.video + ApiVideoApiCLient + No Copyright + 1.0.0 + 1.0.0 - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 bin\Debug\{{packageName}}.xml - pdbonly - true - bin\Release\ - TRACE - prompt - 4 bin\Release\{{packageName}}.xml + + true + - {{^netStandard}} - - - - - - - - - - - $(SolutionDir)\packages\Newtonsoft.Json.{{newtonsoft-json.version}}\lib\{{newtonsoft-json.targetFramework}}\Newtonsoft.Json.dll - ..\packages\Newtonsoft.Json.{{newtonsoft-json.version}}\lib\{{newtonsoft-json.targetFramework}}\Newtonsoft.Json.dll - ..\..\packages\Newtonsoft.Json.{{newtonsoft-json.version}}\lib\{{newtonsoft-json.targetFramework}}\Newtonsoft.Json.dll - ..\..\vendor\Newtonsoft.Json.{{newtonsoft-json.version}}\lib\net45\Newtonsoft.Json.dll - - - $(SolutionDir)\packages\JsonSubTypes.{{json-subtypes.version}}\lib\{{json-subtypes.targetFramework}}\JsonSubTypes.dll - ..\packages\JsonSubTypes.{{json-subtypes.version}}\lib\{{json-subtypes.targetFramework}}\JsonSubTypes.dll - ..\..\packages\JsonSubTypes.{{json-subtypes.version}}\lib\{{json-subtypes.targetFramework}}\JsonSubTypes.dll - ..\..\vendor\JsonSubTypes.{{json-subtypes.version}}\lib\{{json-subtypes.targetFramework}}\JsonSubTypes.dll - - - $(SolutionDir)\packages\RestSharp.{{restsharp.version}}\lib\{{restsharp.targetFramework}}\RestSharp.dll - ..\packages\RestSharp.{{restsharp.version}}\lib\{{restsharp.targetFramework}}\RestSharp.dll - ..\..\packages\RestSharp.{{restsharp.version}}\lib\{{restsharp.targetFramework}}\RestSharp.dll - ..\..\vendor\RestSharp.{{restsharp.version}}\lib\{{restsharp.targetFramework}}\RestSharp.dll - - {{#generatePropertyChanged}} - - ..\..\packages\PropertyChanged.Fody.{{propertychanged-fody.version}}\Lib\portable-net4+sl4+wp8+win8+wpa81+MonoAndroid16+MonoTouch40\PropertyChanged.dll - - {{/generatePropertyChanged}} - {{/netStandard}} - {{#netStandard}} - - - {{/netStandard}} - - - - - {{^netStandard}} - - - + + 5.9.1 runtime; build; native; contentfiles; analyzers; buildtransitive all + + + - - {{#generatePropertyChanged}} - - {{/generatePropertyChanged}} - {{/netStandard}} - {{#netStandard}} - - - {{/netStandard}} diff --git a/templates/csharp/README.mustache b/templates/csharp/README.mustache index 76cfbe81..dbc61798 100644 --- a/templates/csharp/README.mustache +++ b/templates/csharp/README.mustache @@ -58,8 +58,7 @@ api.video's C# API client streamlines the coding process. Chunking files is hand {{^netStandard}} {{^supportsUWP}} -- .NET 4.0 or later -- Windows Phone 7.1 (Mango) +- .NET 5.0 or later {{/supportsUWP}} {{#supportsUWP}} @@ -71,9 +70,9 @@ api.video's C# API client streamlines the coding process. Chunking files is hand {{^netStandard}} -- [RestSharp](https://www.nuget.org/packages/RestSharp) - 105.1.0 -- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 7.0.0 or later -- [JsonSubTypes](https://www.nuget.org/packages/JsonSubTypes/) - 1.2.0 or later +- [RestSharp](https://www.nuget.org/packages/RestSharp) - 111.2.0 +- [Json.NET](https://www.nuget.org/packages/Newtonsoft.Json/) - 13.0.3 +- [JsonSubTypes](https://www.nuget.org/packages/JsonSubTypes/) - 1.8.0 We recommend using [NuGet](https://docs.nuget.org/consume/installing-nuget) to obtain the packages: diff --git a/templates/csharp/Solution.mustache b/templates/csharp/Solution.mustache index 3d97bd63..ebbf92fa 100644 --- a/templates/csharp/Solution.mustache +++ b/templates/csharp/Solution.mustache @@ -1,12 +1,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio {{^netStandard}}2012{{/netStandard}}{{#netStandard}}14{{/netStandard}} -VisualStudioVersion = {{^netStandard}}12.0.0.0{{/netStandard}}{{#netStandard}}14.0.25420.1{{/netStandard}} -MinimumVisualStudioVersion = {{^netStandard}}10.0.0.1{{/netStandard}}{{#netStandard}}10.0.40219.1{{/netStandard}} -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "{{packageName}}", "src\{{packageName}}.csproj", "{{packageGuid}}" +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34511.84 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "{{packageName}}", "src\{{packageName}}.csproj", "{{packageGuid}}" EndProject -{{^excludeTests}}Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "{{testPackageName}}", "tests\ApiVideoTests.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiVideoTests", "tests\ApiVideoTests.csproj", "{19F1DEBC-DE5E-4517-8062-F000CD499087}" + ProjectSection(ProjectDependencies) = postProject + {47CD76E4-3F74-3BC2-A1BA-AF194D07E1FA} = {47CD76E4-3F74-3BC2-A1BA-AF194D07E1FA} + EndProjectSection EndProject -{{/excludeTests}}Global +Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU diff --git a/templates/csharp/api.mustache b/templates/csharp/api.mustache index de755e2b..cebec12e 100644 --- a/templates/csharp/api.mustache +++ b/templates/csharp/api.mustache @@ -177,8 +177,8 @@ namespace {{packageName}}.{{apiPackage}} } // make the HTTP request - IRestResponse localVarResponse = (IRestResponse)this.ApiClient.CallApi(localVarPath, - Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + RestResponse localVarResponse = (RestResponse)this.ApiClient.CallApi(localVarPath, + Method.Post, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; @@ -203,8 +203,8 @@ namespace {{packageName}}.{{apiPackage}} // make the HTTP request - IRestResponse localVarResponse = (IRestResponse) this.ApiClient.CallApi(localVarPath, - Method.{{httpMethod}}, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + RestResponse localVarResponse = (RestResponse) this.ApiClient.CallApi(localVarPath, + Method.{{#titlecase}}{{#lower}}{{httpMethod}}{{/lower}}{{/titlecase}}, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarContentType); int localVarStatusCode = (int) localVarResponse.StatusCode; @@ -327,8 +327,8 @@ namespace {{packageName}}.{{apiPackage}} } // make the HTTP request - IRestResponse localVarResponse = (IRestResponse) this.ApiClient.CallApi(localVarPath, - Method.{{httpMethod}}, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, + RestResponse localVarResponse = (RestResponse) this.ApiClient.CallApi(localVarPath, + Method.{{#titlecase}}{{#lower}}{{httpMethod}}{{/lower}}{{/titlecase}}, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarContentType); int localVarStatusCode = (int) localVarResponse.StatusCode; diff --git a/templates/csharp/statics/.github/workflows/release.yml b/templates/csharp/statics/.github/workflows/release.yml index 8ec0e852..37b3cd78 100644 --- a/templates/csharp/statics/.github/workflows/release.yml +++ b/templates/csharp/statics/.github/workflows/release.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dotnet: [ '3.1.x' ] + dotnet: [ '5.x' ] steps: - uses: actions/checkout@v2 - name: Setup Dotnet ${{ matrix.dotnet }} diff --git a/templates/csharp/statics/.github/workflows/test.yml b/templates/csharp/statics/.github/workflows/test.yml index 2121e52c..3131d26c 100644 --- a/templates/csharp/statics/.github/workflows/test.yml +++ b/templates/csharp/statics/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dotnet: [ '3.1.x' ] + dotnet: [ '5.x' ] steps: - uses: actions/checkout@v2 - name: Setup Dotnet ${{ matrix.dotnet }} diff --git a/templates/csharp/statics/tests/ApiVideoTests.csproj b/templates/csharp/statics/tests/ApiVideoTests.csproj index 2f0bb5a3..9f85733d 100644 --- a/templates/csharp/statics/tests/ApiVideoTests.csproj +++ b/templates/csharp/statics/tests/ApiVideoTests.csproj @@ -1,28 +1,20 @@ - netcoreapp3.1 + net5.0 false - ..\src\bin\Debug\ApiVideo.dll - - - ..\src\bin\Debug\JsonSubTypes.dll - - - ..\src\bin\Debug\Newtonsoft.Json.dll - - - ..\src\bin\Debug\RestSharp.dll + ..\src\bin\Debug\net5.0\ApiVideo.dll + diff --git a/templates/csharp/statics/tests/Client/AbstractApiTest.cs b/templates/csharp/statics/tests/Client/AbstractApiTest.cs index a506c488..5f5ffea7 100644 --- a/templates/csharp/statics/tests/Client/AbstractApiTest.cs +++ b/templates/csharp/statics/tests/Client/AbstractApiTest.cs @@ -3,13 +3,16 @@ using System.Net; using System.IO; using ApiVideo.Client; +using ApiVideo.Api; +using System.Collections.Generic; +using System.Threading; namespace VideoApiTests.Client { public abstract class AbstractApiTest { - private static RestClient restClient = Mock.Of(); - protected static ApiVideoClient apiClientMock = new ApiVideoClient(restClient); + protected static Mock restClient = new Mock(); + protected static ApiVideoClient apiClientMock = new ApiVideoClient(restClient.Object); protected string readResourceFile(string path) { @@ -17,14 +20,21 @@ protected string readResourceFile(string path) } protected void answerOnAnyRequest(int statusCode, string body) { - var r = new RestResponse() + var responseHeaders = new List + { + new HeaderParameter("Content-Type", "application/json") + }; + + var response1 = new RestResponse { StatusCode = (HttpStatusCode)statusCode, Content = body, - ResponseStatus = ResponseStatus.Completed + ResponseStatus = ResponseStatus.Completed, + Headers = responseHeaders }; - Mock.Get(restClient).Setup(m => m.Execute(It.IsAny())).Returns(r); + + restClient.Setup(m => m.ExecuteAsync(It.IsAny(), It.IsAny())) + .ReturnsAsync(response1); } } - -} +} \ No newline at end of file diff --git a/templates/csharp/statics/tests/Client/VideosApiTest.cs b/templates/csharp/statics/tests/Client/VideosApiTest.cs index bba178d3..cdcb64e2 100644 --- a/templates/csharp/statics/tests/Client/VideosApiTest.cs +++ b/templates/csharp/statics/tests/Client/VideosApiTest.cs @@ -6,6 +6,9 @@ using System.Collections.Generic; using System.IO; using Moq; +using RestSharp; +using System.Net; +using System.Threading; namespace VideoApiTests.Client {