using System.Collections.Concurrent;
using WCS.Core;
using WCS.Entity;
using WCS.Entity.Protocol.Station;
namespace WCS.WorkEngineering.Extensions
{
///
/// 设备扩展
///
public static class DeviceExtension
{
///
/// 是否是输送线
///
/// 设备信息
///
public static bool IsConv(this Device source)
{
return source.HasProtocol(typeof(IStation521)) || source.HasProtocol(typeof(IStation520)) || source.HasProtocol(typeof(IStation523));
}
///
/// 是否是巷道
///
/// 设备信息
///
public static bool IsTunnel(this WCS_DeviceInfo source)
{
return source.Code.Contains("TY");
}
///
/// 获取下一个地址
///
/// 设备信息
/// 目标地址
///
public static string GetNextAdd(this WCS_DeviceInfo source, string addto)
{
var path = source.Paths.First(p => p.EndCode == addto).Path;
return path.Split('-')[0];
}
///
/// 获取到达目标地址需要的路径信息
///
/// 设备信息
/// 目标地址
///
public static string GetAddtoPath(this WCS_DeviceInfo source, string addto)
{
return source.Paths.First(p => p.EndCode == addto).Path;
}
#region WCS_DEVICE扩展数据
///
/// 设备标识字典
///
private static ConcurrentDictionary DeviceValues = new ConcurrentDictionary();
///
/// 添加设备标识
///
/// 设备信息
/// 标识
public static void AddFlag(this Device source, DF flag)
{
var df = source.Get("DeviceFlag");
df = df | flag;
source.Set("DeviceFlag", df);
}
///
/// 当前设备是否包含标识
///
/// 设备信息
/// 标识
///
public static bool Is(this Device source, DF flag)
{
var df = source.Get("DeviceFlag");
return (df & flag) == flag;
}
///
/// 为设备写入标识
///
/// 写入值类型
/// 设备信息
/// 标识类型
/// 写入值
public static void Set(this Device source, string key, T value)
{
DeviceValues[source.Code + key] = value;
}
///
/// 获取设备标识
///
/// 写入值类型
/// 设备信息
/// 标识类型
///
public static T Get(this Device source, string key)
{
if (!DeviceValues.ContainsKey(source.Code + key))
return default(T);
return (T)DeviceValues[source.Code + key];
}
///
/// 获取short类型的设备号
///
/// 设备信息
///
public static short Code(this Device source)
{
return short.Parse(source.Code);
}
///
/// 获取巷道
///
/// 设备信息
/// 返回巷道Code
public static string Tunnel(this Device source)
{
return source.Get("Tunnel");
}
///
/// 获取巷道号
///
/// 设备信息
/// 返回巷道号
public static int TunnelNum(this Device source)
{
return int.Parse(source.Tunnel().Last().ToString());
}
///
/// 获取设备楼层信息
///
/// 设备信息
///
public static int Floor(this Device source)
{
return source.Get("Floor");
}
///
/// 获取堆垛机
///
/// 设备信息
///
public static Device SRM(this Device source)
{
return source.Get("SRM");
}
///
/// 获取RGV
///
/// 设备信息
///
public static Device RGV(this Device source)
{
return source.Get("RGV");
}
//public static void AddFlag(DF flag, params string[] devices)
//{
// var arr = LogicHandler.AllObjects.OfType().Where(v => devices.Contains(v.CODE)).ToArray();
// Parallel.ForEach(arr, v =>
// {
// v.AddFlag(flag);
// });
//}
#endregion WCS_DEVICE扩展数据
}
///
/// 设备配置
///
[Flags]
public enum DF
{
无 = 0,
}
}