| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 | using System;using System.Collections.Concurrent;using System.Linq;using System.Threading.Tasks;using WCS.Core;using WCS.Entity;public static class Device{    #region WCS_DEVICE扩展数据    private static ConcurrentDictionary<string, object> DeviceValues = new ConcurrentDictionary<string, object>();    public static void AddFlag(this WCS_DEVICE source, DF flag)    {        var df = source.Get<DF>("DeviceFlag");        df = df | flag;        source.Set("DeviceFlag", df);    }    public static bool Is(this WCS_DEVICE source, DF flag)    {        var df = source.Get<DF>("DeviceFlag");        return (df & flag) == flag;    }    public static void Set<T>(this WCS_DEVICE source, string key, T value)    {        DeviceValues[source.CODE + key] = value;    }    public static T Get<T>(this WCS_DEVICE source, string key)    {        if (!DeviceValues.ContainsKey(source.CODE + key))            return default(T);        return (T)DeviceValues[source.CODE + key];    }    public static short Code(this WCS_DEVICE source)    {        return short.Parse(source.CODE);    }    public static string Tunnel(this WCS_DEVICE source)    {        return source.Get<string>("Tunnel");    }    public static int TunnelNum(this WCS_DEVICE source)    {        return int.Parse(source.Tunnel().Last().ToString());    }    public static int Floor(this WCS_DEVICE source)    {        return source.Get<int>("Floor");    }    public static WCS_DEVICE SC(this WCS_DEVICE source)    {        return source.Get<WCS_DEVICE>("SC");    }    public static WCS_DEVICE RGV(this WCS_DEVICE source)    {        return source.Get<WCS_DEVICE>("RGV");    }    public static LocInfo LocInfo(this WCS_DEVICE source)    {        return source.Get<LocInfo>("LocInfo");    }    public static bool WakeupOn(this WCS_DEVICE source, int sec, string key)    {        var str = "WakeupOn" + key;        var last = source.Get<DateTime>(str);        if ((DateTime.Now - last).TotalMilliseconds > sec)        {            source.Set(str, DateTime.Now);            return true;        }        else        {            Ltc.Log("OnSleep");            return false;        }    }    public static bool WakeupOn(this WCS_DEVICE source, int sec)    {        return source.WakeupOn(sec, "");    }    #endregion WCS_DEVICE扩展数据    #region 静态方法    public static WCS_DEVICE[] Where(Func<WCS_DEVICE, bool> func)    {        var arr = LogicHandler.AllObjects.OfType<WCS_DEVICE>().Where(func).ToArray();        return arr;    }    public static WCS_DEVICE Find(string code)    {        return Where(v => v.CODE == code).Single();    }    public static WCS_DEVICE[] Find(params string[] codes)    {        return Where(v => codes.Contains(v.CODE)).ToArray();    }    public static void Set<T>(string key, T value, params string[] devices)    {        var arr = LogicHandler.AllObjects.OfType<WCS_DEVICE>().Where(v => devices.Contains(v.CODE)).ToArray();        Parallel.ForEach(arr, v =>        {            v.Set(key, value);        });    }    public static void Set<T>(string key, T value, Func<WCS_DEVICE, bool> func)    {        var arr = LogicHandler.AllObjects.OfType<WCS_DEVICE>().Where(func).ToArray();        Parallel.ForEach(arr, v =>        {            v.Set(key, value);        });    }    public static void AddFlag(DF flag, params string[] devices)    {        var arr = LogicHandler.AllObjects.OfType<WCS_DEVICE>().Where(v => devices.Contains(v.CODE)).ToArray();        Parallel.ForEach(arr, v =>        {            v.AddFlag(flag);        });    }    public static void AddFlag(DF flag, Action<WCS_DEVICE> callbck, params string[] devices)    {        var arr = LogicHandler.AllObjects.OfType<WCS_DEVICE>().Where(v => devices.Contains(v.CODE)).ToArray();        Parallel.ForEach(arr, v =>        {            v.AddFlag(flag);            callbck?.Invoke(v);        });    }    #endregion 静态方法}/// <summary>/// 设备配置/// </summary>[Flags]public enum DF{    无 = 0,    SRM = 1 << 0,    SRM二级品取货 = 1 << 1,    SRM涂布取货 = 1 << 2,    SRM月台放货 = 1 << 3,    一楼RGV放货 = 1 << 4,    月台 = 1 << 5,    涂布RGV = 1 << 6,    BOPPRGV = 1 << 7,    涂布RGV取货设备组 = 1 << 8,    涂布RGV放货设备组 = 1 << 9,    涂布出库RGV取货站台 = 1 << 10,    涂布入库RGV取货站台 = 1 << 11,    SRM涂布放货 = 1 << 12,    涂布RGV取货站台 = 1 << 13,    BOPPRGV取货设备组 = 1 << 14,    BOPPRGV放货设备组 = 1 << 15,    SRMBOPP取货 = 1 << 16,}
 |