12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using WCS.Core;
- using WCS.Entity.Protocol.DataStructure;
- using WCS.Entity.Protocol.Protocol.DataStructure;
- using WCS.WorkEngineering.Systems;
- namespace WCS.WorkEngineering
- {
- public class ProtocolProxy : ProtocolProxyBase
- {
- public static DataPack DataPack { get; set; } = new DataPack();
- public ProtocolProxy(Device dev, ProtocolInfo info, Type protocolType, World world) : base(dev, info, protocolType, world)
- {
- }
- protected override void DataChanged()
- {
- //var p = DataPack.GetType().GetProperties()
- // .Where(v => v.PropertyType.IsGenericType)
- // .Where(v =>
- // {
- // var t = v.PropertyType.GenericTypeArguments[0].GenericTypeArguments[0];
- // return GetProtocolType(t) == this.ProtocolType;
- // })
- // .FirstOrDefault();
- }
- Type GetProtocolType(Type source)
- {
- var t = source.GetInterfaces()
- .Where(v => v.GetInterfaces().Any(d => d.Name == "IProtocol")).FirstOrDefault();
- return t;
- }
- public object DictionaryToEntity(Type type, Dictionary<string, PlcItem> items)
- {
- var a = Activator.CreateInstance(type);
- foreach (var ty in type.GetProperties())
- {
- foreach (var item in items.Where(item => ty.Name == item.Key))
- {
- ty.SetValue(a, item.Value.Value);
- break;
- }
- }
- return a;
- }
- }
- }
|