From 65a42c3893ef52759b725ddcf986614f2ef5fa76 Mon Sep 17 00:00:00 2001 From: Phillip Hoff Date: Thu, 26 Oct 2023 11:15:04 -0700 Subject: [PATCH] Update actor reminder example. Signed-off-by: Phillip Hoff --- examples/Actor/ActorClient/Program.cs | 5 ++--- examples/Actor/DemoActor/DemoActor.cs | 15 ++++++++++++--- examples/Actor/IDemoActor/IDemoActor.cs | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/examples/Actor/ActorClient/Program.cs b/examples/Actor/ActorClient/Program.cs index aeee28386..5d7f06fb2 100644 --- a/examples/Actor/ActorClient/Program.cs +++ b/examples/Actor/ActorClient/Program.cs @@ -18,7 +18,6 @@ namespace ActorClient using System.Threading.Tasks; using Dapr.Actors; using Dapr.Actors.Client; - using Dapr.Actors.Communication; using IDemoActorInterface; /// @@ -69,7 +68,7 @@ public static async Task Main(string[] args) } catch (ActorMethodInvocationException ex) { - if (ex.InnerException is NotImplementedException) + if (ex.InnerException is ActorInvokeException invokeEx && invokeEx.ActualExceptionType is "System.NotImplementedException") { Console.WriteLine($"Got Correct Exception from actor method invocation."); } @@ -111,7 +110,7 @@ public static async Task Main(string[] args) await Task.Delay(5000); Console.WriteLine("Getting details of the registered reminder"); reminder = await proxy.GetReminder(); - Console.WriteLine($"Received reminder is {reminder}."); + Console.WriteLine($"Received reminder is {reminder?.ToString() ?? "None"} (expecting None)."); Console.WriteLine("Registering reminder with ttl and repetitions, i.e. reminder stops when either condition is met - The reminder will repeat 2 times."); await proxy.RegisterReminderWithTtlAndRepetitions(TimeSpan.FromSeconds(5), 2); Console.WriteLine("Getting details of the registered reminder"); diff --git a/examples/Actor/DemoActor/DemoActor.cs b/examples/Actor/DemoActor/DemoActor.cs index 0ab633fcd..62c100f79 100644 --- a/examples/Actor/DemoActor/DemoActor.cs +++ b/examples/Actor/DemoActor/DemoActor.cs @@ -85,9 +85,18 @@ public async Task RegisterReminderWithTtlAndRepetitions(TimeSpan ttl, int repeti await this.RegisterReminderAsync("TestReminder", null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1), repetitions, ttl); } - public async Task GetReminder() - { - return await this.GetReminderAsync("TestReminder"); + public async Task GetReminder() + { + var reminder = await this.GetReminderAsync("TestReminder"); + + return reminder is not null + ? new ActorReminderData + { + Name = reminder.Name, + Period = reminder.Period, + DueTime = reminder.DueTime + } + : null; } public Task UnregisterReminder() diff --git a/examples/Actor/IDemoActor/IDemoActor.cs b/examples/Actor/IDemoActor/IDemoActor.cs index adec6df68..c2926a048 100644 --- a/examples/Actor/IDemoActor/IDemoActor.cs +++ b/examples/Actor/IDemoActor/IDemoActor.cs @@ -100,7 +100,7 @@ public interface IDemoActor : IActor /// /// The name of the reminder. /// A task that returns the reminder after completion. - Task GetReminder(); + Task GetReminder(); /// /// Unregisters the registered timer. @@ -132,4 +132,18 @@ public override string ToString() return $"PropertyA: {propAValue}, PropertyB: {propBValue}"; } } + + public class ActorReminderData + { + public string Name { get; set; } + + public TimeSpan DueTime { get; set; } + + public TimeSpan Period { get; set; } + + public override string ToString() + { + return $"Name: {this.Name}, DueTime: {this.DueTime}, Period: {this.Period}"; + } + } }