private Device FindDevice(SectionOrSwitch sectionOrSwitch, int DeviceId) { Device device = MainWindow.stationElements_.Elements.Find((GraphicElement elements) => { if (elements is Device) { Device dev = elements as Device; if (sectionOrSwitch == SectionOrSwitch.Section) { if (dev is Section) { if ((dev as Section).ID == DeviceId) { return(true); } } } else { if (dev is RailSwitch) { if ((dev as RailSwitch).ID == DeviceId) { return(true); } } } } return(false); }) as Device; return(device); }
private void GetPosition() { unPack.SkipBytes(7); SectionOrSwitch sectionOrSwitch = (SectionOrSwitch)unPack.GetByte(); int DeviceId = unPack.GetByte(); trainInfo.HeadPosition = FindDevice(sectionOrSwitch, DeviceId); trainInfo.HeadOffset = unPack.GetUint32(); sectionOrSwitch = (SectionOrSwitch)unPack.GetByte(); DeviceId = unPack.GetByte(); trainInfo.TailPosition = FindDevice(sectionOrSwitch, DeviceId); trainInfo.TailOffset = unPack.GetUint32(); }
public void finddevice() { SectionOrSwitch sos = SectionOrSwitch.Switch; int DeviceId = 0; Device device = MainWindow.stationElements_.Elements.Find((GraphicElement elements) => { if (elements is Device) { Device dev = elements as Device; if (sos == SectionOrSwitch.Section) { if (dev is Section) { if ((dev as Section).ID == DeviceId) { return(true); } } } else { if (dev is RailSwitch) { if ((dev as RailSwitch).ID == DeviceId) { return(true); } } } } return(false); }) as Device; List <int> num = new List <int>(); foreach (var item in MainWindow.routeList_.Routes) { if (item.IncomingSections[0] == device) { int a = 9; } foreach (var dev in item.InSections) { if (device == dev) { int a = 0; } } } }