72 lines
2.3 KiB
C#
72 lines
2.3 KiB
C#
using RobotNet.VDA5050.Factsheet;
|
|
using RobotNet.VDA5050.Type;
|
|
using RobotNet10.RobotApp.Services.Exceptions;
|
|
using System.Collections.ObjectModel;
|
|
|
|
namespace RobotNet10.RobotApp.Services.Robot.Actions;
|
|
|
|
[RobotAction(ActionType.EXAMPLE,
|
|
[ActionScope.INSTANT, ActionScope.NODE, ActionScope.EDGE],
|
|
[BlockingType.NONE, BlockingType.SOFT, BlockingType.HARD],
|
|
"This is an example robot action.",
|
|
"Example robot action completed.")]
|
|
public class RobotActionExample(IServiceProvider serviceProvider) : RobotAction(serviceProvider)
|
|
{
|
|
private static readonly ReadOnlyCollection<ActionParameter> ActionParameters = new List<ActionParameter>
|
|
{
|
|
new() {
|
|
Key = "exampleParam",
|
|
ValueDataType = ValueDataType.STRING,
|
|
Description = "This is an example string parameter.",
|
|
IsOptional = true
|
|
},
|
|
}.AsReadOnly();
|
|
|
|
string paramExample = "";
|
|
|
|
protected override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
if (ActionParameters.Count > 0)
|
|
{
|
|
foreach (var parameterStore in ActionParameters)
|
|
{
|
|
if (!parameterStore.IsOptional)
|
|
{
|
|
if (Action is null || Action.ActionParameters is null || !Action.ActionParameters.Any(a => a.Key == parameterStore.Key)) throw new ActionException($"Thiếu tham số bắt buộc '{parameterStore.Key}' cho action {Type}.");
|
|
}
|
|
}
|
|
Parameters = Action is null || Action.ActionParameters is null ? [] : Action.ActionParameters;
|
|
}
|
|
|
|
var para = Parameters.FirstOrDefault(p => p.Key == "exampleParam") ?? throw new ActionException($"Action {Type} không tìm thấy parameter key 'exampleParam'");
|
|
paramExample = para.Value?.ToString() ?? "";
|
|
}
|
|
|
|
protected override Task StartAction()
|
|
{
|
|
return base.StartAction();
|
|
}
|
|
|
|
protected override Task ExecuteAction()
|
|
{
|
|
return base.ExecuteAction();
|
|
}
|
|
|
|
protected override Task StopAction()
|
|
{
|
|
return base.StopAction();
|
|
}
|
|
|
|
protected override Task PauseAction()
|
|
{
|
|
return base.PauseAction();
|
|
}
|
|
|
|
protected override Task ResumeAction()
|
|
{
|
|
return base.ResumeAction();
|
|
}
|
|
}
|