first commit -push
This commit is contained in:
20
RobotNet.ScriptManager/Hubs/ConsoleHub.cs
Normal file
20
RobotNet.ScriptManager/Hubs/ConsoleHub.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace RobotNet.ScriptManager.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class ConsoleHub : Hub
|
||||
{
|
||||
public Task RegisterTasksConsole(string name) => Groups.AddToGroupAsync(Context.ConnectionId, $"task-{name}");
|
||||
public Task UnregisterTasksConsole(string name) => Groups.RemoveFromGroupAsync(Context.ConnectionId, $"task-{name}");
|
||||
public Task RegisterTaskConsoles() => Groups.AddToGroupAsync(Context.ConnectionId, "tasks");
|
||||
public Task UnregisterTaskConsoles() => Groups.RemoveFromGroupAsync(Context.ConnectionId, "tasks");
|
||||
public Task RegisterMissionConsole(Guid missionId) => Groups.AddToGroupAsync(Context.ConnectionId, $"mission-{missionId}");
|
||||
public Task UnregisterMissionConsole(Guid missionId) => Groups.RemoveFromGroupAsync(Context.ConnectionId, $"mission-{missionId}");
|
||||
public Task RegisterMissionConsoles() => Groups.AddToGroupAsync(Context.ConnectionId, "missions");
|
||||
public Task UnregisterMissionConsoles() => Groups.RemoveFromGroupAsync(Context.ConnectionId, "missions");
|
||||
public Task RegisterAllConsoles() => Groups.AddToGroupAsync(Context.ConnectionId, "alls");
|
||||
public Task UnregisterAllConsoles() => Groups.RemoveFromGroupAsync(Context.ConnectionId, "alls");
|
||||
|
||||
}
|
||||
24
RobotNet.ScriptManager/Hubs/DashboardHub.cs
Normal file
24
RobotNet.ScriptManager/Hubs/DashboardHub.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using RobotNet.Script.Shares.Dashboard;
|
||||
using RobotNet.ScriptManager.Services;
|
||||
using RobotNet.Shares;
|
||||
|
||||
namespace RobotNet.ScriptManager.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class DashboardHub(DashboardPublisher DashboardPublisher, ILogger<DashboardHub> Logger) : Hub
|
||||
{
|
||||
public MessageResult<DashboardDto> GetDashboardData()
|
||||
{
|
||||
try
|
||||
{
|
||||
return new(true, "") { Data = DashboardPublisher.GetData() };
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogWarning("Lấy dữ liệu Dashboard xảy ra lỗi: {ex}", ex.Message);
|
||||
return new(false, "Lấy dữ liệu Dashboard xảy ra lỗi");
|
||||
}
|
||||
}
|
||||
}
|
||||
45
RobotNet.ScriptManager/Hubs/HMIHub.cs
Normal file
45
RobotNet.ScriptManager/Hubs/HMIHub.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using RobotNet.Script.Shares;
|
||||
using RobotNet.ScriptManager.Services;
|
||||
using RobotNet.Shares;
|
||||
|
||||
namespace RobotNet.ScriptManager.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class HMIHub(ScriptStateManager scriptBuilder, ScriptGlobalsManager globalsManager) : Hub
|
||||
{
|
||||
public ProcessorState GetState() => scriptBuilder.State;
|
||||
|
||||
public ProcessorRequest GetRequest() => scriptBuilder.Request;
|
||||
|
||||
public IDictionary<string, string> GetVariables(IEnumerable<string> keys)
|
||||
{
|
||||
var variables = new Dictionary<string, string>();
|
||||
foreach (var key in keys)
|
||||
{
|
||||
if (globalsManager.Globals.TryGetValue(key, out object? val))
|
||||
{
|
||||
variables.Add(key, val?.ToString() ?? "null");
|
||||
}
|
||||
else
|
||||
{
|
||||
variables.Add(key, "null");
|
||||
}
|
||||
}
|
||||
return variables;
|
||||
}
|
||||
|
||||
public MessageResult SetVariable(string key, string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
globalsManager.SetValue(key, value);
|
||||
return new(true, "");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new(false, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
47
RobotNet.ScriptManager/Hubs/ProcessorHub.cs
Normal file
47
RobotNet.ScriptManager/Hubs/ProcessorHub.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using RobotNet.Script.Shares;
|
||||
using RobotNet.ScriptManager.Services;
|
||||
using RobotNet.Shares;
|
||||
|
||||
namespace RobotNet.ScriptManager.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class ProcessorHub(ScriptStateManager scriptBuilder) : Hub
|
||||
{
|
||||
public ProcessorState GetState() => scriptBuilder.State;
|
||||
|
||||
public ProcessorRequest GetRequest() => scriptBuilder.Request;
|
||||
|
||||
public MessageResult Build()
|
||||
{
|
||||
var message = "";
|
||||
var result = scriptBuilder.Build(ref message);
|
||||
|
||||
return new(result, message);
|
||||
}
|
||||
|
||||
public MessageResult Run()
|
||||
{
|
||||
var message = "";
|
||||
var result = scriptBuilder.Run(ref message);
|
||||
|
||||
return new(result, message);
|
||||
}
|
||||
|
||||
public MessageResult Stop()
|
||||
{
|
||||
var message = "";
|
||||
var result = scriptBuilder.Stop(ref message);
|
||||
|
||||
return new(result, message);
|
||||
}
|
||||
|
||||
public MessageResult Reset()
|
||||
{
|
||||
var message = "";
|
||||
var result = scriptBuilder.Reset(ref message);
|
||||
|
||||
return new(result, message);
|
||||
}
|
||||
}
|
||||
68
RobotNet.ScriptManager/Hubs/ScriptOpenHub.cs
Normal file
68
RobotNet.ScriptManager/Hubs/ScriptOpenHub.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using RobotNet.Script.Shares;
|
||||
using RobotNet.ScriptManager.Services;
|
||||
using RobotNet.Shares;
|
||||
|
||||
namespace RobotNet.ScriptManager.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class ScriptOpenHub(ScriptStateManager scriptBuilder, ScriptGlobalsManager globalManager) : Hub
|
||||
{
|
||||
public ProcessorState GetState() => scriptBuilder.State;
|
||||
|
||||
public MessageResult Run()
|
||||
{
|
||||
var message = "";
|
||||
var result = scriptBuilder.Run(ref message);
|
||||
|
||||
return new(result, message);
|
||||
}
|
||||
|
||||
public MessageResult Stop()
|
||||
{
|
||||
var message = "";
|
||||
var result = scriptBuilder.Stop(ref message);
|
||||
|
||||
return new(result, message);
|
||||
}
|
||||
|
||||
public IDictionary<string, string> GetVariables() => globalManager.GetVariablesData().ToDictionary(v => v.Name, v => v.Value);
|
||||
|
||||
public string GetVariableValue(string name)
|
||||
{
|
||||
if (globalManager.Globals.TryGetValue(name, out var value))
|
||||
{
|
||||
return value?.ToString() ?? "null";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
|
||||
public bool SetVariableValue(string name, string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
globalManager.SetValue(name, value);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool ResetVariableValue(string name)
|
||||
{
|
||||
try
|
||||
{
|
||||
globalManager.ResetValue(name);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
33
RobotNet.ScriptManager/Hubs/ScriptTaskHub.cs
Normal file
33
RobotNet.ScriptManager/Hubs/ScriptTaskHub.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using RobotNet.ScriptManager.Services;
|
||||
using RobotNet.Shares;
|
||||
|
||||
namespace RobotNet.ScriptManager.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class ScriptTaskHub(ScriptTaskManager taskManager) : Hub
|
||||
{
|
||||
public MessageResult Pause(string name)
|
||||
{
|
||||
if (taskManager.Pause(name))
|
||||
{
|
||||
return new MessageResult(true, $"Task '{name}' paused successfully.");
|
||||
}
|
||||
return new MessageResult(false, $"Task '{name}' not found or could not be paused.");
|
||||
}
|
||||
|
||||
public MessageResult Resume(string name)
|
||||
{
|
||||
if (taskManager.Resume(name))
|
||||
{
|
||||
return new MessageResult(true, $"Task '{name}' resumed successfully.");
|
||||
}
|
||||
return new MessageResult(false, $"Task '{name}' not found or could not be resumed.");
|
||||
}
|
||||
|
||||
public IDictionary<string, bool> GetTaskStates()
|
||||
{
|
||||
return taskManager.GetTaskStates();
|
||||
}
|
||||
}
|
||||
78
RobotNet.ScriptManager/Hubs/VariablesHub.cs
Normal file
78
RobotNet.ScriptManager/Hubs/VariablesHub.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using RobotNet.ScriptManager.Services;
|
||||
|
||||
namespace RobotNet.ScriptManager.Hubs;
|
||||
|
||||
[Authorize]
|
||||
public class VariablesHub(ScriptGlobalsManager globalsManager) : Hub
|
||||
{
|
||||
public string GetString(string name)
|
||||
{
|
||||
if (globalsManager.GetVariableType(name) == typeof(string) && globalsManager.Globals.TryGetValue(name, out var value) && value is string strValue)
|
||||
{
|
||||
return strValue;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public int GetInt(string name)
|
||||
{
|
||||
if (globalsManager.GetVariableType(name) == typeof(int) && globalsManager.Globals.TryGetValue(name, out var value) && value is int intValue)
|
||||
{
|
||||
return intValue;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public bool GetBool(string name)
|
||||
{
|
||||
if (globalsManager.GetVariableType(name) == typeof(bool) && globalsManager.Globals.TryGetValue(name, out var value) && value is bool boolValue)
|
||||
{
|
||||
return boolValue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public double GetDouble(string name)
|
||||
{
|
||||
if (globalsManager.GetVariableType(name) == typeof(double) && globalsManager.Globals.TryGetValue(name, out var value) && value is double doubleValue)
|
||||
{
|
||||
return doubleValue;
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
public void SetString(string name, string value)
|
||||
{
|
||||
if (globalsManager.GetVariableType(name) == typeof(double) && globalsManager.Globals.ContainsKey(name))
|
||||
{
|
||||
globalsManager.Globals[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetInt(string name, int value)
|
||||
{
|
||||
if (globalsManager.GetVariableType(name) == typeof(int) && globalsManager.Globals.ContainsKey(name))
|
||||
{
|
||||
globalsManager.Globals[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetBool(string name, bool value)
|
||||
{
|
||||
if (globalsManager.GetVariableType(name) == typeof(bool) && globalsManager.Globals.ContainsKey(name))
|
||||
{
|
||||
globalsManager.Globals[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDouble(string name, double value)
|
||||
{
|
||||
if (globalsManager.GetVariableType(name) == typeof(double) && globalsManager.Globals.ContainsKey(name))
|
||||
{
|
||||
globalsManager.Globals[name] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user