ActionParameterService.cs
2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Rcs.Domain.Entities;
using Rcs.Domain.Models;
using Rcs.Domain.Repositories;
using Rcs.Domain.Services;
namespace Rcs.Application.Services
{
/// <summary>
/// 动作参数解析服务 - 用于构建VDA5050动作参数
/// @author zzy
/// </summary>
public class ActionParameterService
{
private readonly IActionConfigurationRepository _actionConfigRepo;
private readonly IParameterValueResolverFactory _resolverFactory;
public ActionParameterService(
IActionConfigurationRepository actionConfigRepo,
IParameterValueResolverFactory resolverFactory)
{
_actionConfigRepo = actionConfigRepo;
_resolverFactory = resolverFactory;
}
/// <summary>
/// 根据动作配置ID和上下文解析所有参数
/// </summary>
/// <param name="actionConfigId">动作配置ID</param>
/// <param name="task">任务对象</param>
/// <param name="robot">机器人对象</param>
/// <param name="node">节点对象</param>
/// <param name="edge">边对象</param>
/// <returns>解析后的参数列表</returns>
public async Task<List<ResolvedParameter>> ResolveParametersAsync(
Guid actionConfigId,
RobotTask? task = null,
Robot? robot = null,
MapNode? node = null,
MapEdge? edge = null)
{
// 获取动作配置及其参数定义
var actionConfig = await _actionConfigRepo.GetWithParametersAsync(actionConfigId);
if (actionConfig == null)
return new List<ResolvedParameter>();
// 构建解析上下文
var context = new ParameterContext
{
Task = task,
Robot = robot,
Node = node,
Edge = edge
};
// 解析所有参数
return _resolverFactory.ResolveAll(actionConfig.Parameters, context);
}
/// <summary>
/// 根据动作名称解析参数
/// </summary>
/// <param name="actionName">动作名称</param>
/// <param name="context">解析上下文</param>
/// <returns>解析后的参数列表</returns>
public async Task<List<ResolvedParameter>> ResolveParametersByActionNameAsync(
string actionName,
ParameterContext context)
{
var actionConfig = await _actionConfigRepo.GetByActionNameAsync(actionName);
if (actionConfig == null)
return new List<ResolvedParameter>();
return _resolverFactory.ResolveAll(actionConfig.Parameters, context);
}
}
}