48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using RobotNet10.FleetManager.Services.TrafficControl.Models;
|
|
|
|
namespace RobotNet10.FleetManager.Services.TrafficControl.Services;
|
|
|
|
/// <summary>
|
|
/// Service for managing active robot routes storage
|
|
/// </summary>
|
|
public class RouteStorageService : IRouteStorageService
|
|
{
|
|
// In-memory storage for active routes
|
|
private readonly Dictionary<string, RobotRoute> _activeRoutes = [];
|
|
private readonly Lock _routesLock = new();
|
|
|
|
public Task<Dictionary<string, RobotRoute>> GetAllActiveRoutesAsync()
|
|
{
|
|
lock (_routesLock)
|
|
{
|
|
return Task.FromResult(new Dictionary<string, RobotRoute>(_activeRoutes));
|
|
}
|
|
}
|
|
|
|
public Task<RobotRoute?> GetRobotRouteAsync(string robotId)
|
|
{
|
|
lock (_routesLock)
|
|
{
|
|
_activeRoutes.TryGetValue(robotId, out var route);
|
|
return Task.FromResult(route);
|
|
}
|
|
}
|
|
|
|
public Task<bool> UpdateRobotRouteAsync(string robotId, RobotRoute route)
|
|
{
|
|
try
|
|
{
|
|
lock (_routesLock)
|
|
{
|
|
_activeRoutes[robotId] = route;
|
|
}
|
|
return Task.FromResult(true);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return Task.FromResult(false);
|
|
}
|
|
}
|
|
}
|
|
|