Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Knoema.Client/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private async Task<T> ApiGet<T>(string path, Dictionary<string, string> paramete
var request = new HttpRequestMessage(HttpMethod.Get, uri);
var response = await ProcessRequest(request);
EnsureSuccessApiCall(response);
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<T>(responseContent);
}

Expand All @@ -139,7 +139,7 @@ private async Task<T> ApiPost<T>(string path, HttpContent content)
};
var response = await ProcessRequest(request);
EnsureSuccessApiCall(response);
var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<T>(responseContent);
}

Expand Down Expand Up @@ -321,7 +321,7 @@ public async Task<UploadResult> UploadDataset(string filename, string datasetNam

var result = UploadSubmit(upload).Result;
while (UploadStatus(result.Id).Result.Status == "in progress")
await Task.Delay(5000);
await Task.Delay(5000).ConfigureAwait(false);

return await UploadStatus(result.Id);
}
Expand Down Expand Up @@ -376,7 +376,7 @@ public async Task<Response> SearchTimeseries(Request request, string lang = null

var sendAsyncResp = await ProcessRequest(message);
sendAsyncResp.EnsureSuccessStatusCode();
var strRead = await sendAsyncResp.Content.ReadAsStringAsync();
var strRead = await sendAsyncResp.Content.ReadAsStringAsync().ConfigureAwait(false);
var result = JsonConvert.DeserializeObject<Response>(strRead);
foreach (var datasetItem in result.Items)
foreach (var series in datasetItem.Items)
Expand Down Expand Up @@ -411,7 +411,7 @@ public async Task<SearchTimeSeriesResponse> Search(string searchText, SearchScop

var sendAsyncResp = await ProcessRequest(message);
sendAsyncResp.EnsureSuccessStatusCode();
var strRead = await sendAsyncResp.Content.ReadAsStringAsync();
var strRead = await sendAsyncResp.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<SearchTimeSeriesResponse>(strRead);
}

Expand Down Expand Up @@ -458,7 +458,7 @@ public async Task<T> WaitTaskResult<T>(TaskResponse taskResponse, int spinDelayI
i++;
if (i >= maxWaitCount)
throw new Exception("Maximum wait count reached");
await Task.Delay(TimeSpan.FromSeconds(spinDelayInSeconds));
await Task.Delay(TimeSpan.FromSeconds(spinDelayInSeconds)).ConfigureAwait(false);
}

if (taskResult.Status == Meta.TaskStatus.Cancelled)
Expand Down Expand Up @@ -513,9 +513,9 @@ private Task<Task>[] GetFilesAfterUnload(string[] files, Stream[] resultStreams)
Stream dataStream = null;
try
{
response = t.GetAwaiter().GetResult();
response = t.ConfigureAwait(false).GetAwaiter().GetResult();
content = response.Content;
dataStream = content.ReadAsStreamAsync().GetAwaiter().GetResult();
dataStream = content.ReadAsStreamAsync().ConfigureAwait(false).GetAwaiter().GetResult();
return dataStream.CopyToAsync(output, 4096 * 16, cts.Token).ContinueWith(_ =>
{
dataStream.Dispose();
Expand Down Expand Up @@ -659,7 +659,7 @@ public async Task CreateReplacement(string originalDatasetId, string replacement
var response = await ProcessRequest(message);
response.EnsureSuccessStatusCode();

var responseContent = await response.Content.ReadAsStringAsync();
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
if (!string.IsNullOrEmpty(responseContent))
{
var resultStatus = new ResultStatusViewModel();
Expand Down
37 changes: 37 additions & 0 deletions Knoema.Client/ClientExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Knoema.Data;

using System.Collections.Generic;

namespace Knoema
{
#if NETCOREAPP3_1_OR_GREATER
public static class ClientExtension
{
public static async IAsyncEnumerable<RegularTimeSeriesRawData> GetDataAsync(this Client client, PivotRequest pivot)
{
var response = await client.GetDataBegin(pivot);
foreach (var item in response.Data)
yield return item;
while (!string.IsNullOrEmpty(response.ContinuationToken))
{
response = await client.GetDataStreaming(response.ContinuationToken);
foreach (var item in response.Data)
yield return item;
}
}

public static async IAsyncEnumerable<FlatTimeSeriesRawData> GetFlatDataAsync(this Client client, PivotRequest pivot)
{
var response = await client.GetFlatDataBegin(pivot);
foreach (var item in response.Data)
yield return item;
while (!string.IsNullOrEmpty(response.ContinuationToken))
{
response = await client.GetFlatDataStreaming(response.ContinuationToken);
foreach (var item in response.Data)
yield return item;
}
}
}
#endif
}
14 changes: 1 addition & 13 deletions Knoema.Client/Knoema.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net45;netcoreapp2.0;netcoreapp3.1</TargetFrameworks>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.0.0</PackageVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<DefineConstants>NETSTANDARD2_0</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<DefineConstants>NETCORE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net45'">
<DefineConstants>NET45</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<PackageReference Include="Microsoft.Net.Http" Version="2.2.29" />
</ItemGroup>
Expand Down
10 changes: 8 additions & 2 deletions Knoema.Client/Knoema.Client.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2046
# Visual Studio Version 16
VisualStudioVersion = 16.0.31112.23
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably stops the project opening on old VS versions

MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Knoema.Client", "Knoema.Client.csproj", "{2267DC41-0A9D-48BC-AC78-79BB4472544B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Knoema.UnitTests", "..\Knoem.Client.UnitTests\Knoema.UnitTests.csproj", "{41EF4128-CFDD-4924-AA83-39C098BAF952}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Knoema.UnitTestsNetCore31", "..\Knoema.UnitTestsNetCore31\Knoema.UnitTestsNetCore31.csproj", "{61FD8A1F-004A-4B4C-9BD1-29E8AC6EA16E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{41EF4128-CFDD-4924-AA83-39C098BAF952}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41EF4128-CFDD-4924-AA83-39C098BAF952}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41EF4128-CFDD-4924-AA83-39C098BAF952}.Release|Any CPU.Build.0 = Release|Any CPU
{61FD8A1F-004A-4B4C-9BD1-29E8AC6EA16E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61FD8A1F-004A-4B4C-9BD1-29E8AC6EA16E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61FD8A1F-004A-4B4C-9BD1-29E8AC6EA16E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61FD8A1F-004A-4B4C-9BD1-29E8AC6EA16E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
28 changes: 28 additions & 0 deletions Knoema.UnitTestsNetCore31/Knoema.UnitTestsNetCore31.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>

<AssemblyName>Knoema.UnitTestsNetCore31</AssemblyName>

<RootNamespace>Knoema.UnitTestsNetCore31</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Linq.Async" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Knoema.Client\Knoema.Client.csproj" />
</ItemGroup>

</Project>
52 changes: 52 additions & 0 deletions Knoema.UnitTestsNetCore31/KnoemaClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Knoema.Data;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Knoema.UnitTestsNetCore31
{
[TestClass]
public class KnoemaClientTests
{
[TestMethod]
public async Task GetDataStreamingAsync()
{
var instance = new Client("knoema.com");
var request = new PivotRequest
{
Dataset = "WBWDI2019Jan",
Header = new List<PivotRequestItem>
{
new PivotRequestItem
{
DimensionId = "Time",
UiMode = "AllData"
}
},
Stub = new List<PivotRequestItem>
{
new PivotRequestItem
{
DimensionId = "country",
Members = Enumerable.Range(0, 100).Select(i => 1000000 + i * 10).Cast<object>().ToArray()
},
new PivotRequestItem
{
DimensionId = "series",
Members = Enumerable.Range(0, 100).Select(i => 1000000 + i * 10).Cast<object>().ToArray()
}
},
Frequencies = new List<string> { "A" },
DetailColumns = new[] { "*" }
};

var result = await instance.GetDataAsync(request).ToListAsync();

Console.WriteLine(result.Count);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no assert. Maybe it's worth adding specific elements and check the expected ts count. No exceptions are good, but it might be not enough.

}
}
}