CodeLiturgy.Dashboard/BlueWest/Artefacts/AccountArtefact.cs

73 lines
1.9 KiB
C#

using System;
using BlueWest.Core.ComponentSystem;
using BlueWest.Tools;
using PerformanceSolution.Data;
namespace PerformanceSolution.Artefacts
{
public enum CommandRequestEventType
{
GetUsers, GetUserById
}
public readonly struct CommandRequestEvent
{
public readonly CommandRequestEventType CommandRequestEventType;
public readonly int Id;
public CommandRequestEvent(CommandRequestEventType commandRequestEventType, int id = 0)
{
CommandRequestEventType = commandRequestEventType;
Id = id;
}
}
public class AccountArtefact : Artefact, EventListener<CommandRequestEvent>
{
public AccountArtefact()
{
Frequency = ArtefactFrequency.T10Hz;
LoopEnabled = false;
}
protected override void Start()
{
_eventManager.EventStartListening(this);
}
private void GetAllUsersInConsole()
{
var data = MemoryData.UserList;
if (data != null)
{
Console.WriteLine(MemoryData.UserList.ToString());
}
}
private void GetUserByIdInConsole(int id)
{
var user = MemoryData.GetUserById(id);
if (user != null)
{
Console.WriteLine(user.ToString());
}
}
public void OnEvent(CommandRequestEvent commandRequestEvent)
{
switch (commandRequestEvent.CommandRequestEventType)
{
case CommandRequestEventType.GetUserById:
GetUserByIdInConsole(commandRequestEvent.Id);
break;
case CommandRequestEventType.GetUsers:
GetAllUsersInConsole();
break;
}
}
}
}