public LocomotiveViewModel(ILocomotive model) { _model = model; _sections = new ObservableCollection <SectionViewModel>(); foreach (var section in model.Sections) { _sections.Add(new SectionViewModel(section)); } _isInEditMode = false; _newName = _model.Name; _cmdStartModifyName = new DependedCommand(() => { IsInEditMode = true; }, () => !IsInEditMode); _cmdStartModifyName.AddDependOnProp(this, "IsInEditMode"); _cmdSetName = new DependedCommand(() => { IsInEditMode = false; Name = _newName; }, () => IsInEditMode); _cmdSetName.AddDependOnProp(this, "IsInEditMode"); }
private void UpdateLocomotivesIfDeletedUnsafe() { var devInfos = _deviceInformationStorage.DeviceInformations.ToList(); var psnDataInfos = _psnDataInformtationStorage.PsnDataInformations.ToList(); // 2. Check for deleted things: var locomotivesToDelete = new List <ILocomotive>(); foreach (var locomotive in _locomotives) { ILocomotive locomotive1 = locomotive; var devInfosForLocomotive = devInfos.Where(di => di.Name == locomotive1.Name).ToList(); if (devInfosForLocomotive.Count == 0) { // Если в привязаном хранилище не найдено не одной информации об устройстве, то нужно удалить такой локомотив locomotivesToDelete.Add(locomotive); } else { // Если найдены информации для локомотива, то проверяем каждую его секцию: var sectionsToDelete = new List <ISection>(); foreach (var section in locomotive.Sections) { ISection section1 = section; // for closure var devInfosForSection = devInfosForLocomotive.Where(di => di.Description == section1.Name).ToList(); if (devInfosForSection.Count == 0) { // Если для секции локомотива не удалось найти информаию об устройстве в хранилище - нужно удалить секцию sectionsToDelete.Add(section); } else { // Если в привязанном хранилище есть информация об устройстве для секции, то нужно проверить логи: var psnDataInformations = psnDataInfos.Where(pdi => devInfosForSection.Any(di => di.Id.ToString() == pdi.DeviceInformationId.ToString())).ToList(); var psnLogsToDelete = section.Psns.Where(psnLog => psnDataInformations.All(pdi => pdi.Id.ToString() != psnLog.Id.ToString())).ToList(); foreach (var psnLog in psnLogsToDelete) { _uiNotifier.NotifyAndWait(() => section.Psns.Remove(psnLog)); } } } foreach (var section in sectionsToDelete) { _uiNotifier.NotifyAndWait(() => locomotive.Sections.Remove(section)); } } } foreach (var locomotive in locomotivesToDelete) { _uiNotifier.NotifyAndWait(() => _locomotives.Remove(locomotive)); } }
private void FillSections(ILocomotive locomotive) { for (int i = 0; i < locomotive.Sections.Count; i++) { Sections.Add(new SectionViewModel(locomotive.Sections[i], i + 1, this)); } // Связываем модель представления секций с секциями из модели данных. _sectionsLinker = new ObservableCollectionsConnector <ISection, ISectionViewModel> (locomotive.Sections, Sections, OnNewSectionAdded, section => Sections.FirstOrDefault(e => e.Section == section)); }
/// <summary> /// Вызывается автоматически при добавлении нового локомотива в список локомотивов в модели данных (IRepository.Locomotives). /// </summary> /// <param name="locomotive">Локомотив.</param> /// <returns>Модель представления локомотива.</returns> private LocomotiveViewModel OnNewLocomotiveAdded(ILocomotive locomotive) { var locomotiveViewModel = new LocomotiveViewModel(locomotive) { CaptureNewFaults = CaptureNewFaults }; if (CaptureNewFaults) { locomotiveViewModel.AllFaultsNew = true; } return(locomotiveViewModel); }
public SpeedAndDirection GetState(ILocomotive locomotive) { SpeedAndDirection speedAndDirection = speedAndDirectionState.FirstOrDefault(o => o.EAddress == locomotive.Functions.EAddress); if (speedAndDirection == null) { speedAndDirection = new SpeedAndDirection() { EAddress = locomotive.Functions.EAddress, speed = 0, Direction = EDirection.Forwards }; speedAndDirectionState.Add(speedAndDirection); } return(speedAndDirection); }
/// <summary> /// Конструктор. /// </summary> /// <param name="locomotive">Локомотив.</param> public LocomotiveViewModel(ILocomotive locomotive) { Locomotive = locomotive; FillSections(locomotive); }
public static bool CanMove(this ILocomotive subject) => subject.Locomotion != null && subject.Locomotion.Active;
public Train(ILocomotive locomotiv, ICollection <IPassengerWagon> wagons) { _Locomotiv = locomotiv; _Wagons = wagons; }
public SectionMock(ILocomotive owner) { OwnerLocomotive = owner; Faults = new ObservableCollection <IFaultLog>(); Psns = new ObservableCollection <IPsnLog>(); }