57 lines
2.0 KiB
C#
57 lines
2.0 KiB
C#
using RobotNet.VDA5050.Type;
|
|
using RobotNet10.RobotApp.Interfaces;
|
|
|
|
namespace RobotNet10.RobotApp.Services.Robot.Actions;
|
|
|
|
|
|
[RobotAction(ActionType.CANCEL_ORDER,
|
|
[ActionScope.INSTANT],
|
|
[BlockingType.NONE, BlockingType.SOFT, BlockingType.HARD],
|
|
"Hủy bỏ Order hiện tại của robot.",
|
|
"Robot đã hủy bỏ Order hiện tại.")]
|
|
public class RobotCancelOrderAction(IServiceProvider ServiceProvider) : RobotAction(ServiceProvider)
|
|
{
|
|
private const int MAX_TIMEOUT = 4000;
|
|
private int CountTimeout = 0;
|
|
|
|
private IOrder? RobotOrder;
|
|
private IAction? RobotAction;
|
|
protected override Task StartAction()
|
|
{
|
|
RobotOrder = ServiceProvider.GetRequiredService<IOrder>();
|
|
RobotAction = ServiceProvider.GetRequiredService<IAction>();
|
|
RobotOrder.StopOrder();
|
|
RobotAction.StopOrderAction();
|
|
CountTimeout = 0;
|
|
return base.StartAction();
|
|
}
|
|
|
|
protected override Task StopAction()
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
protected override Task ExecuteAction()
|
|
{
|
|
if (RobotOrder is null || RobotAction is null)
|
|
{
|
|
SetStatus(ActionEvent.FAILED);
|
|
ResultDescription = $"Không thể tìm thấy module quản lý {(RobotOrder is null ? "Order" : RobotAction is null ? "Action" : "")}";
|
|
}
|
|
else
|
|
{
|
|
if (RobotOrder.NodeStates.Length == 0 && RobotOrder.EdgeStates.Length == 0 && !RobotAction.HasActionRunning)
|
|
{
|
|
SetStatus(ActionEvent.FINISHED);
|
|
ResultDescription = string.IsNullOrEmpty(ActionAttribute.ResultDescription) ? ResultDescription : ActionAttribute.ResultDescription;
|
|
}
|
|
else if(CountTimeout++ > MAX_TIMEOUT / ActionInterval)
|
|
{
|
|
SetStatus(ActionEvent.FAILED);
|
|
ResultDescription = "Timeout action";
|
|
}
|
|
}
|
|
return base.ExecuteAction();
|
|
}
|
|
}
|