Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dapr Bindings Quickstart - .NET #1140

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion bindings/csharp/sdk/batch/batch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapr.AspNetCore" Version="1.14.*-*" />
<PackageReference Include="Dapr.AspNetCore" Version="1.15.0-rc02" />
</ItemGroup>

</Project>
9 changes: 5 additions & 4 deletions bindings/csharp/sdk/batch/program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ limitations under the License.
options.SupportedCultures = [invariantCulture];
});

builder.Services.AddDaprClient();

var app = builder.Build();

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

app.UseRequestLocalization();

// Triggered by Dapr input binding
app.MapPost("/" + cronBindingName, async () =>
app.MapPost("/" + cronBindingName, async (DaprClient client) =>
{
Console.WriteLine("Processing batch..");

string jsonFile = File.ReadAllText("../../../orders.json");
var ordersArray = JsonSerializer.Deserialize<Orders>(jsonFile);
using var client = new DaprClientBuilder().Build();
foreach (Order ord in ordersArray?.orders ?? new Order[] { })
{
var sqlText = $"insert into orders (orderid, customer, price) values ({ord.OrderId}, '{ord.Customer}', {ord.Price});";
Expand All @@ -65,5 +66,5 @@ limitations under the License.

await app.RunAsync();

public record Order([property: JsonPropertyName("orderid")] int OrderId, [property: JsonPropertyName("customer")] string Customer, [property: JsonPropertyName("price")] float Price);
public record Orders([property: JsonPropertyName("orders")] Order[] orders);
public sealed record Order([property: JsonPropertyName("orderid")] int OrderId, [property: JsonPropertyName("customer")] string Customer, [property: JsonPropertyName("price")] float Price);
WhitWaldo marked this conversation as resolved.
Show resolved Hide resolved
public saeled record Orders([property: JsonPropertyName("orders")] Order[] orders);
Loading