mirror of https://github.com/dapr/quickstarts.git
staging a reminders feature
Signed-off-by: Paul Yuknewicz <paulyuk@Pauls-MBP-2.lan>
This commit is contained in:
parent
41c92012df
commit
a3b93d848e
|
|
@ -19,17 +19,17 @@ class Program
|
|||
// An ActorId uniquely identifies an actor instance
|
||||
var deviceActorId1 = new ActorId(deviceId1);
|
||||
|
||||
// Create the local proxy by using the same interface that the service implements.
|
||||
// You need to provide the type and id so the actor can be located.
|
||||
// If the actor matching this id does not exist, it will be created
|
||||
var proxySmartDevice1 = ActorProxy.Create<ISmartDevice>(deviceActorId1, smokeDetectorActorType);
|
||||
|
||||
// Create a new instance of the data class that will be stored in the actor
|
||||
var deviceData1 = new SmartDeviceData(){
|
||||
Location = "First Floor",
|
||||
Status = "Ready",
|
||||
};
|
||||
|
||||
// Create the local proxy by using the same interface that the service implements.
|
||||
// You need to provide the type and id so the actor can be located.
|
||||
// If the actor matching this id does not exist, it will be created
|
||||
var proxySmartDevice1 = ActorProxy.Create<ISmartDevice>(deviceActorId1, smokeDetectorActorType);
|
||||
|
||||
// Now you can use the actor interface to call the actor's methods.
|
||||
Console.WriteLine($"Calling SetDataAsync on {smokeDetectorActorType}:{deviceActorId1}...");
|
||||
var setDataResponse1 = await proxySmartDevice1.SetDataAsync(deviceData1);
|
||||
|
|
@ -57,6 +57,9 @@ class Program
|
|||
var controllerActorId = new ActorId("controller");
|
||||
var proxyController = ActorProxy.Create<IController>(controllerActorId, controllerActorType);
|
||||
|
||||
//Register reminders every 30 to clear out invalid state or alarms
|
||||
await proxyController.RegisterReminder();
|
||||
|
||||
Console.WriteLine($"Registering the IDs of both Devices...");
|
||||
await proxyController.RegisterDeviceIdsAsync(new string[]{deviceId1, deviceId2});
|
||||
var deviceIds = await proxyController.ListRegisteredDeviceIdsAsync();
|
||||
|
|
@ -72,5 +75,14 @@ class Program
|
|||
Console.WriteLine($"Device 1 state: {storedDeviceData1}");
|
||||
storedDeviceData2 = await proxySmartDevice2.GetDataAsync();
|
||||
Console.WriteLine($"Device 2 state: {storedDeviceData2}");
|
||||
|
||||
// Sleep for 35 seconds and observe reminders have cleared alarm state
|
||||
Console.WriteLine("Sleeping for 35 seconds before observing alarm state after reminders fire");
|
||||
await Task.Delay(35000);
|
||||
|
||||
storedDeviceData1 = await proxySmartDevice1.GetDataAsync();
|
||||
Console.WriteLine($"Device 1 state: {storedDeviceData1}");
|
||||
storedDeviceData2 = await proxySmartDevice2.GetDataAsync();
|
||||
Console.WriteLine($"Device 2 state: {storedDeviceData2}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,12 @@ public interface IController : IActor
|
|||
Task RegisterDeviceIdsAsync(string[] deviceIds);
|
||||
Task<string[]> ListRegisteredDeviceIdsAsync();
|
||||
Task TriggerAlarmForAllDetectors();
|
||||
|
||||
/// <summary>
|
||||
/// Registers a timer.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous save operation.</returns>
|
||||
Task RegisterReminder();
|
||||
}
|
||||
|
||||
public class ControllerData
|
||||
|
|
|
|||
|
|
@ -61,4 +61,11 @@ internal class ControllerActor : Actor, IController
|
|||
await proxySmartDevice.SoundAlarm();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task RegisterReminder()
|
||||
{
|
||||
// Register a reminder to refresh alarm state every 30 seconds
|
||||
await this.RegisterReminderAsync("AlarmRefreshReminder", null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(30));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue