diff --git a/Samples/Tutorials/Aggregates/Kitchen.cs b/Samples/Tutorials/Aggregates/Kitchen.cs index 96b6f196..a8b96575 100644 --- a/Samples/Tutorials/Aggregates/Kitchen.cs +++ b/Samples/Tutorials/Aggregates/Kitchen.cs @@ -11,7 +11,7 @@ namespace Kitchen [AggregateRoot("01ad9a9f-711f-47a8-8549-43320f782a1e")] public class Kitchen : AggregateRoot { - int _counter; + int _ingredients = 2; public Kitchen(EventSourceId eventSource) : base(eventSource) @@ -20,11 +20,12 @@ public Kitchen(EventSourceId eventSource) public void PrepareDish(string dish, string chef) { + if (_ingredients <= 0) throw new Exception("We have run out of ingredients, sorry!"); Apply(new DishPrepared(dish, chef)); - Console.WriteLine($"Kitchen Aggregate {EventSourceId} has applied {_counter} {typeof(DishPrepared)} events"); + Console.WriteLine($"Kitchen {EventSourceId} prepared a {dish}, there are {_ingredients} ingredients left."); } void On(DishPrepared @event) - => _counter++; + => _ingredients--; } } diff --git a/Samples/Tutorials/Aggregates/Program.cs b/Samples/Tutorials/Aggregates/Program.cs index 5a22a3a1..03ab9207 100644 --- a/Samples/Tutorials/Aggregates/Program.cs +++ b/Samples/Tutorials/Aggregates/Program.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // Sample code for the tutorial at https://dolittle.io/tutorials/getting-started/csharp/ +using System.Threading.Tasks; using Dolittle.SDK; using Dolittle.SDK.Tenancy; @@ -9,7 +10,7 @@ namespace Kitchen { class Program { - public static void Main() + public static async Task Main() { var client = Client .ForMicroservice("f39b1f61-d360-4675-b859-53c05c87c0e6") @@ -21,7 +22,7 @@ public static void Main() builder.Register()) .Build(); - client + await client .AggregateOf("bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9", _ => _.ForTenant(TenantId.Development)) .Perform(kitchen => kitchen.PrepareDish("Bean Blaster Taco", "Mr. Taco")); diff --git a/Samples/Tutorials/Embeddings/Program.cs b/Samples/Tutorials/Embeddings/Program.cs index 56369d9d..ee000f1c 100644 --- a/Samples/Tutorials/Embeddings/Program.cs +++ b/Samples/Tutorials/Embeddings/Program.cs @@ -3,6 +3,7 @@ // Sample code for the tutorial at https://dolittle.io/tutorials/embeddings/ using System; +using System.Linq; using System.Threading.Tasks; using Dolittle.SDK; using Dolittle.SDK.Tenancy; @@ -41,15 +42,17 @@ await client.Embeddings .Update(updatedEmployee.Name, updatedEmployee); Console.WriteLine($"Updated {updatedEmployee.Name}."); - var mrTaco = client.Embeddings + var mrTaco = await client.Embeddings .ForTenant(TenantId.Development) - .Get("Mr. Taco"); - var allEmployees = client.Embeddings - .ForTenant(TenantId.Development) - .GetAll(); - var employeeKeys = client.Embeddings + .Get("Mr. Taco") + .ConfigureAwait(false); + Console.WriteLine($"Mr. Taco is now working at {mrTaco.State.Workplace}"); + + var allEmployeeNames = await client.Embeddings .ForTenant(TenantId.Development) - .GetKeys(); + .GetKeys() + .ConfigureAwait(false); + Console.WriteLine($"All current employees are {string.Join(",", allEmployeeNames)}"); await client.Embeddings .ForTenant(TenantId.Development) @@ -60,4 +63,4 @@ await client.Embeddings await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false); } } -} +} \ No newline at end of file diff --git a/Samples/Tutorials/GettingStarted/Program.cs b/Samples/Tutorials/GettingStarted/Program.cs index ea361709..52f39609 100644 --- a/Samples/Tutorials/GettingStarted/Program.cs +++ b/Samples/Tutorials/GettingStarted/Program.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. // Sample code for the tutorial at https://dolittle.io/tutorials/getting-started/csharp/ +using System.Threading.Tasks; using Dolittle.SDK; using Dolittle.SDK.Tenancy; @@ -9,7 +10,7 @@ namespace Kitchen { class Program { - public static void Main() + public static async Task Main() { var client = Client .ForMicroservice("f39b1f61-d360-4675-b859-53c05c87c0e6") @@ -21,15 +22,15 @@ public static void Main() var preparedTaco = new DishPrepared("Bean Blaster Taco", "Mr. Taco"); - client.EventStore + await client.EventStore .ForTenant(TenantId.Development) .Commit(eventsBuilder => eventsBuilder .CreateEvent(preparedTaco) - .FromEventSource("bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9")); + .FromEventSource("Dolittle Tacos")); // Blocks until the EventHandlers are finished, i.e. forever client.Start().Wait(); } } -} +} \ No newline at end of file diff --git a/Samples/Tutorials/Projections/DishHandler.cs b/Samples/Tutorials/Projections/DishHandler.cs deleted file mode 100644 index 370d7cbe..00000000 --- a/Samples/Tutorials/Projections/DishHandler.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Dolittle. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. -// Sample code for the tutorial at https://dolittle.io/tutorials/getting-started/projections/ - -using System; -using Dolittle.SDK.Events; -using Dolittle.SDK.Events.Handling; - -namespace Kitchen -{ - [EventHandler("f2d366cf-c00a-4479-acc4-851e04b6fbba")] - public class DishHandler - { - public void Handle(DishPrepared @event, EventContext eventContext) - { - Console.WriteLine($"{@event.Chef} has prepared {@event.Dish}. Yummm!"); - } - } -} diff --git a/Samples/Tutorials/Projections/Program.cs b/Samples/Tutorials/Projections/Program.cs index 2379b69d..cf8f5bcc 100644 --- a/Samples/Tutorials/Projections/Program.cs +++ b/Samples/Tutorials/Projections/Program.cs @@ -17,8 +17,6 @@ public async static Task Main() .ForMicroservice("f39b1f61-d360-4675-b859-53c05c87c0e6") .WithEventTypes(eventTypes => eventTypes.Register()) - .WithEventHandlers(builder => - builder.RegisterEventHandler()) .WithProjections(builder => { builder.RegisterProjection(); @@ -38,19 +36,19 @@ public async static Task Main() await eventStore.Commit(_ => _.CreateEvent(new DishPrepared("Bean Blaster Taco", "Mr. Taco")) - .FromEventSource("bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9")) + .FromEventSource("Dolittle Tacos")) .ConfigureAwait(false); await eventStore.Commit(_ => _.CreateEvent(new DishPrepared("Bean Blaster Taco", "Mrs. Tex Mex")) - .FromEventSource("bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9")) + .FromEventSource("Dolittle Tacos")) .ConfigureAwait(false); await eventStore.Commit(_ => _.CreateEvent(new DishPrepared("Avocado Artillery Tortilla", "Mr. Taco")) - .FromEventSource("bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9")) + .FromEventSource("Dolittle Tacos")) .ConfigureAwait(false); await eventStore.Commit(_ => _.CreateEvent(new DishPrepared("Chili Canon Wrap", "Mrs. Tex Mex")) - .FromEventSource("bfe6f6e4-ada2-4344-8a3b-65a3e1fe16e9")) + .FromEventSource("Dolittle Tacos")) .ConfigureAwait(false); await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);