Skip to content

Commit

Permalink
implement invariantCulture inside WebApplicationBuilder
Browse files Browse the repository at this point in the history
Signed-off-by: Erwin Kramer <[email protected]>
  • Loading branch information
erwinkramer committed Jul 26, 2024
1 parent a314d7a commit af8ee64
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
18 changes: 12 additions & 6 deletions bindings/csharp/http/batch/program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ You may obtain a copy of the License at
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;

using Microsoft.AspNetCore.Localization;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Mvc;

//dapr run --app-id batch-http --app-port 7001 --resources-path ../../../components -- dotnet run

Expand All @@ -28,10 +27,20 @@ limitations under the License.
var daprUrl = $"{baseURL}:{daprPort}/v1.0/bindings/{sqlBindingName}";

var builder = WebApplication.CreateBuilder(args);

builder.Services.Configure<RequestLocalizationOptions>(options =>
{
var invariantCulture = CultureInfo.InvariantCulture;
options.DefaultRequestCulture = new RequestCulture(invariantCulture);
options.SupportedCultures = [invariantCulture];
});

var app = builder.Build();

if (app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); }

app.UseRequestLocalization();

var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

Expand All @@ -40,9 +49,6 @@ limitations under the License.
{
Console.WriteLine("Processing batch..");
// Ensure the culture is set to one that uses dot notation
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
string jsonFile = File.ReadAllText("../../../orders.json");
var ordersArray = JsonSerializer.Deserialize<Orders>(jsonFile);
foreach (Order ord in ordersArray?.orders ?? new Order[] { })
Expand Down
19 changes: 12 additions & 7 deletions bindings/csharp/sdk/batch/program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ You may obtain a copy of the License at
See the License for the specific language governing permissions and
limitations under the License.
*/
using System;

using Microsoft.AspNetCore.Localization;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Mvc;
using Dapr.Client;

// dapr run --app-id batch-sdk --app-port 7002 --resources-path ../../../components -- dotnet run
Expand All @@ -25,18 +23,25 @@ limitations under the License.
var sqlBindingName = "sqldb";

var builder = WebApplication.CreateBuilder(args);

builder.Services.Configure<RequestLocalizationOptions>(options =>
{
var invariantCulture = CultureInfo.InvariantCulture;
options.DefaultRequestCulture = new RequestCulture(invariantCulture);
options.SupportedCultures = [invariantCulture];
});

var app = builder.Build();

if (app.Environment.IsDevelopment()) { app.UseDeveloperExceptionPage(); }

app.UseRequestLocalization();

// Triggered by Dapr input binding
app.MapPost("/" + cronBindingName, async () =>
{
Console.WriteLine("Processing batch..");
// Ensure the culture is set to one that uses dot notation
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
string jsonFile = File.ReadAllText("../../../orders.json");
var ordersArray = JsonSerializer.Deserialize<Orders>(jsonFile);
using var client = new DaprClientBuilder().Build();
Expand Down

0 comments on commit af8ee64

Please sign in to comment.