52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PlantBox.Broker
|
|
{
|
|
class Broker
|
|
{
|
|
public PlantBoxesManager PlantBoxesManager { get; }
|
|
public ClientManager ClientManager { get; }
|
|
public ServerManager ServerManager { get; }
|
|
|
|
public bool IsRunning { get; set; } = true;
|
|
|
|
public Broker(string[] args)
|
|
{
|
|
Console.WriteLine("Initializing Broker...");
|
|
|
|
PlantBoxesManager = new PlantBoxesManager();
|
|
|
|
PlantBoxesManager.Load();
|
|
PlantBoxesManager.UpdatePlantsState();
|
|
|
|
ClientManager = new ClientManager(this);
|
|
ServerManager = new ServerManager(this);
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
Task.Run(() => ClientManager.Start());
|
|
Task.Run(() => ServerManager.Start());
|
|
|
|
string input;
|
|
do
|
|
{
|
|
input = Console.ReadLine().ToLowerInvariant();
|
|
|
|
if (input == "save")
|
|
{
|
|
PlantBoxesManager.Save();
|
|
}
|
|
} while (input != "exit" && input != "stop" && input != "quit");
|
|
|
|
Console.WriteLine("Stopping Broker...");
|
|
|
|
IsRunning = false;
|
|
PlantBoxesManager.Save();
|
|
}
|
|
}
|
|
}
|