mirror of https://github.com/dapr/quickstarts.git
Change naming to SmokeDetectorActor
This commit is contained in:
parent
dadb2a821b
commit
849ea9ce8c
|
|
@ -59,10 +59,9 @@ class Program
|
|||
var proxyController = ActorProxy.Create<IController>(actorId, actorType);
|
||||
|
||||
Console.WriteLine($"Registering the IDs of both SmartDetectors...");
|
||||
var controllerData = new ControllerData(){
|
||||
DeviceIds = new string[]{"1", "2"}
|
||||
};
|
||||
await proxyController.RegisterSmokeDetectorsAsync(controllerData);
|
||||
await proxyController.RegisterDeviceIdsAsync(new string[]{"1", "2"});
|
||||
var deviceIds = await proxyController.ListRegisteredDeviceIdsAsync();
|
||||
Console.WriteLine($"Registered devices: {string.Join(", " , deviceIds)}");
|
||||
|
||||
// Smoke detected on device 1
|
||||
actorType = "SmokeDetectorActor";
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ public interface IController : IActor
|
|||
{
|
||||
Task<decimal> GetNetBatteryPercentage();
|
||||
Task<decimal> GetAverageTemperature();
|
||||
Task RegisterSmokeDetectorsAsync(ControllerData data);
|
||||
Task RegisterDeviceIdsAsync(string[] deviceIds);
|
||||
Task<string[]> ListRegisteredDeviceIdsAsync();
|
||||
Task TriggerAlarmForAllDetectors();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,9 +67,14 @@ internal class ControllerActor : Actor, IController
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task RegisterSmokeDetectorsAsync(ControllerData data)
|
||||
public async Task RegisterDeviceIdsAsync(string[] deviceIds)
|
||||
{
|
||||
await this.StateManager.SetStateAsync<ControllerData>("controllerData", data);
|
||||
await this.StateManager.SetStateAsync<string[]>("deviceIds", deviceIds);
|
||||
}
|
||||
|
||||
public async Task<string[]> ListRegisteredDeviceIdsAsync()
|
||||
{
|
||||
return await this.StateManager.GetStateAsync<string[]>("deviceIds");
|
||||
}
|
||||
|
||||
public async Task TriggerAlarmForAllDetectors()
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ internal class SmokeDetectorActor : Actor, ISmartDevice
|
|||
/// </summary>
|
||||
protected override Task OnDeactivateAsync()
|
||||
{
|
||||
// Provides Opporunity to perform optional cleanup.
|
||||
// Provides Opportunity to perform optional cleanup.
|
||||
Console.WriteLine($"Deactivating actor id: {this.Id}");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ internal class SmokeDetectorActor : Actor, ISmartDevice
|
|||
|
||||
public async Task DetectSmokeAsync()
|
||||
{
|
||||
Console.WriteLine($"Smoke detected in ActorId: {this.Id}.");
|
||||
//Console.WriteLine($"Smoke detected in ActorId: {this.Id}.");
|
||||
|
||||
var controllerActorId = new ActorId("controller");
|
||||
var controllerActorType = "ControllerActor";
|
||||
|
|
@ -81,6 +81,6 @@ internal class SmokeDetectorActor : Actor, ISmartDevice
|
|||
smartDeviceData.Status = "Alarm";
|
||||
await SetDataAsync(smartDeviceData);
|
||||
|
||||
Console.WriteLine($"ActorId: {this.Id}, Status: {smartDeviceData.Status}.");
|
||||
//Console.WriteLine($"ActorId: {this.Id}, Status: {smartDeviceData.Status}.");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue