Skip to content

Commit

Permalink
set culture for parsing numbers to de-DE. This fixes the problem wher…
Browse files Browse the repository at this point in the history
…e used data was read incorrectly if the system locale is not de-DE.
  • Loading branch information
winterleitner committed Apr 4, 2024
1 parent 304ead6 commit c06d373
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
7 changes: 4 additions & 3 deletions KontomanagerClient/A1BusinessClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -271,7 +272,7 @@ public async Task<AccountUsage> GetAccountUsage(PhoneNumber number)
if (before != null && after != null)
{
usage.Cost = int.Parse(before.InnerText.Trim().Trim(',')) +
decimal.Parse(after.InnerText.Trim().Trim(',')) / 100;
decimal.Parse(after.InnerText.Trim().Trim(','), new CultureInfo("de-DE")) / 100;
}
}

Expand Down Expand Up @@ -312,9 +313,9 @@ public async Task<AccountUsage> GetAccountUsage(PhoneNumber number)
var circle = package.SelectSingleNode(".//div[contains(@class, 'circle100')]");
var usageSpan = circle.SelectSingleNode(".//span");
if (uq.Name.Contains("Daten"))
uq.Used = (int)Math.Round(decimal.Parse(usageSpan.FirstChild.InnerText.Trim()) * 1024); //convert to MB
uq.Used = (int)Math.Round(decimal.Parse(usageSpan.FirstChild.InnerText.Trim(), new CultureInfo("de-DE")) * 1024); //convert to MB
else
uq.Used = (int)Math.Round(decimal.Parse(usageSpan.FirstChild.InnerText.Trim()));
uq.Used = (int)Math.Round(decimal.Parse(usageSpan.FirstChild.InnerText.Trim(), new CultureInfo("de-DE")));
var regex = new Regex(@"\/(\d+)(\\n)?\s+([a-zA-Z]+)");
if (regex.IsMatch(usageSpan.InnerHtml))
{
Expand Down
2 changes: 1 addition & 1 deletion KontomanagerClient/KontomanagerClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<TargetFrameworks>net5.0;net6.0;net7.0;netcoreapp3.1;netstandard2.0;net8.0</TargetFrameworks>
<PackageVersion>2.1.3</PackageVersion>
<PackageVersion>2.1.4</PackageVersion>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

Expand Down
5 changes: 3 additions & 2 deletions KontomanagerClientNet.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=482bb9db_002D4cac_002D48e4_002D8c59_002D04793434aa13/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="Test1" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=482bb9db_002D4cac_002D48e4_002D8c59_002D04793434aa13/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Test1" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;TestAncestor&gt;
&lt;TestId&gt;xUnit::AD1BEAB0-0431-4154-B58C-5CCBF427ABEF::net7.0::BlitzkabineTests.TestAccounts.Test1&lt;/TestId&gt;
&lt;TestId&gt;xUnit::AD1BEAB0-0431-4154-B58C-5CCBF427ABEF::net7.0::BlitzkabineTests.TestAccounts.TestSubscriberIdsWithPreload&lt;/TestId&gt;
Expand All @@ -11,9 +11,10 @@
&lt;TestId&gt;xUnit::AD1BEAB0-0431-4154-B58C-5CCBF427ABEF::net7.0::BlitzkabineTests.TestMeinA1Account.Test1&lt;/TestId&gt;
&lt;TestId&gt;xUnit::AD1BEAB0-0431-4154-B58C-5CCBF427ABEF::net7.0::BlitzkabineTests.TestMeinA1Account.TestAccountUsage&lt;/TestId&gt;
&lt;TestId&gt;xUnit::AD1BEAB0-0431-4154-B58C-5CCBF427ABEF::net7.0::BlitzkabineTests.TestMeinA1Account.TestMultiLogin&lt;/TestId&gt;
&lt;TestId&gt;xUnit::AD1BEAB0-0431-4154-B58C-5CCBF427ABEF::net7.0::BlitzkabineTests.TestMeinA1Account.TestDataUsage&lt;/TestId&gt;
&lt;/TestAncestor&gt;
&lt;/SessionState&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=f2d08fbe_002Df22b_002D45ea_002Da1a6_002D3e6b9947aafa/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="TestAccountUsage" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=f2d08fbe_002Df22b_002D45ea_002Da1a6_002D3e6b9947aafa/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" Name="TestAccountUsage" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;TestAncestor&gt;
&lt;TestId&gt;xUnit::AD1BEAB0-0431-4154-B58C-5CCBF427ABEF::net7.0::BlitzkabineTests.TestMeinA1Account&lt;/TestId&gt;
&lt;/TestAncestor&gt;
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ The following projects seem to do the same thing as this client in other languag

# Changelog

### 04.04.2024 2.1.4
- set culture for parsing numbers to de-DE. This fixes the problem where used data was read incorrectly if the system locale is not de-DE.

### 04.04.2024 2.1.3
- add more information to `A1BusinessClient`, such as contract validity periods, loyalty points and customer number.
- fix bugs found in versions 2.1.0 - 2.1.2
Expand Down

0 comments on commit c06d373

Please sign in to comment.