You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.0 KiB
31 lines
1.0 KiB
using Kean.Domain.Task.Commands;
|
|
using Kean.Domain.Task.Models;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Kean.Domain.Task.Strategies
|
|
{
|
|
/// <summary>
|
|
/// 避让策略上下文
|
|
/// </summary>
|
|
public sealed class AvertContext<T> where T : AvertStrategy
|
|
{
|
|
private readonly T _strategy; // 策略实例
|
|
|
|
/// <summary>
|
|
/// 初始化 Kean.Domain.Task.Strategies.AvertContext 类的新实例
|
|
/// </summary>
|
|
public AvertContext(IServiceProvider serviceProvider) =>
|
|
_strategy = Activator.CreateInstance(typeof(T),
|
|
typeof(T).GetConstructors().First().GetParameters().Select(p => serviceProvider.GetService(p.ParameterType)).ToArray()) as T;
|
|
|
|
/// <summary>
|
|
/// 生成用于避让的移库命令
|
|
/// </summary>
|
|
/// <param name="cell">避让货位</param>
|
|
/// <returns>移库命令</returns>
|
|
public Task<TransferCommand> AutoCommand(Cell cell) =>
|
|
_strategy.AutoCommand(cell);
|
|
}
|
|
}
|