using Quasar.Common.Messages;
using Quasar.Common.Models;
using Quasar.Common.Networking;
using Quasar.Server.Networking;
using System.Collections.Generic;
namespace Quasar.Server.Messages
{
///
/// Handles messages for the interaction with remote startup tasks.
///
public class StartupManagerHandler : MessageProcessorBase>
{
///
/// The client which is associated with this startup manager handler.
///
private readonly Client _client;
///
/// Initializes a new instance of the class using the given client.
///
/// The associated client.
public StartupManagerHandler(Client client) : base(true)
{
_client = client;
}
///
public override bool CanExecute(IMessage message) => message is GetStartupItemsResponse;
///
public override bool CanExecuteFrom(ISender sender) => _client.Equals(sender);
///
public override void Execute(ISender sender, IMessage message)
{
switch (message)
{
case GetStartupItemsResponse items:
Execute(sender, items);
break;
}
}
///
/// Refreshes the current startup items.
///
public void RefreshStartupItems()
{
_client.Send(new GetStartupItems());
}
///
/// Removes an item from startup.
///
/// Startup item to remove.
public void RemoveStartupItem(StartupItem item)
{
_client.Send(new DoStartupItemRemove {StartupItem = item});
}
///
/// Adds an item to startup.
///
/// Startup item to add.
public void AddStartupItem(StartupItem item)
{
_client.Send(new DoStartupItemAdd {StartupItem = item});
}
private void Execute(ISender client, GetStartupItemsResponse message)
{
OnReport(message.StartupItems);
}
}
}