示例#1
0
        private void InitialTreeBuildUnsafe(Action <double> progressChangeAction)
        {
            // Этот метод, в отличие от UpdateLocomotivesUnsafe() не оперирует хэшами,
            // что позволяет выиграть производительность в медленных хранилищах (например, NAND)

            var devInfos     = _deviceInformationStorage.DeviceInformations.ToList();
            var psnDatas     = _psnDataStorage.PsnDatas.ToList();
            var psnDataInfos = _psnDataInformtationStorage.PsnDataInformations.ToList();

            var signal = new AutoResetEvent(false);
            //Exception exc = null;
            //_uiNotifier.Notify(
            //() => {
            //try {
            int totalDevInfosCount    = devInfos.Count;
            int currentDevInfoZbIndex = 0;

            foreach (var devInfo in devInfos)
            {
                var loc = new Locomotive(devInfo.Name, _backWorker, _deviceInformationStorage);

                _uiNotifier.NotifyAndWait(() => _locomotives.Add(loc));


                var section = new Section(new UidStringToLower(devInfo.Id.IdentyString), devInfo.Description, _backWorker, _deviceInformationStorage);

                _uiNotifier.NotifyAndWait(() => loc.Sections.Add(section));


                IDeviceInformation info = devInfo;

                var psnDatasInfosForDev       = psnDataInfos.Where(pdi => pdi.DeviceInformationId.ToString() == info.Id.ToString()).ToList();
                var totalPsnDatasCount        = psnDatasInfosForDev.Count;
                int currentPsnDataInfoZbIndex = 0;
                foreach (var psnDataInfo in psnDatasInfosForDev)
                {
                    try {
                        var psnData         = psnDatas.First(pl => pl.Id.IdentyString == psnDataInfo.Id.IdentyString);
                        var psnCustomConfig = _psnDataCustomConfigurationsStorage.Configurations.First(pc => pc.Id.IdentyString == psnDataInfo.Id.IdentyString);

                        var psnConfig = _psnConfigurationsStorage.StoredItems.First(pc => pc.Id.IdentyString.ToLower() == psnCustomConfig.PsnConfigurationId.IdentyString.ToLower());

                        var builder           = new PsnProtocolConfigBuilderFromLowLevel(psnConfig);
                        var psnProtocolConfig = builder.Build();

                        IPsnDataInformation dataInfo = psnDataInfo;
                        var psnLog = new PsnLogRelay(
                            psnDataInfo
                            , psnData
                            , psnProtocolConfig
                            , psnConfig
                            , psnCustomConfig
                            , _uiNotifier
                            , _backWorker
                            , _psnConfigurationsStorage
                            , _psnDataCustomConfigurationsStorage
                            , _kvStorageHolder);

                        _uiNotifier.NotifyAndWait(() => section.Psns.Add(psnLog));
                    }
                    catch (Exception ex) {
                        // TODO: catch exception and deliver it to user as warning message
                        Console.WriteLine(ex);
                    }
                    currentPsnDataInfoZbIndex++;
                    progressChangeAction((currentDevInfoZbIndex * 100.0 + currentPsnDataInfoZbIndex * 100.0 / totalPsnDatasCount) / totalDevInfosCount);
                }
                currentDevInfoZbIndex++;
                progressChangeAction(currentDevInfoZbIndex * 100.0 / totalDevInfosCount);
            }
        }
示例#2
0
        private void UpdateLocomotivesIfAddedUnsafe()
        {
            var devInfos           = _deviceInformationStorage.DeviceInformations.ToList();
            var psnDatas           = _psnDataStorage.PsnDatas.ToList();
            var psnDataInfos       = _psnDataInformtationStorage.PsnDataInformations.ToList();
            var psnDataCustomInfos = _psnDataCustomConfigurationsStorage.Configurations.ToList();

            // TODO: нужно работать максимально в фоне: в потоке UI только операции изменения ObservableCollection коллекций

            // 1. Check for newly things:
            foreach (var devInfo in devInfos)
            {
                var loc = _locomotives.FirstOrDefault(l => l.Name == devInfo.Name);
                if (loc == null)
                {
                    loc = new Locomotive(devInfo.Name, _backWorker, _deviceInformationStorage);

                    _uiNotifier.NotifyAndWait(() => _locomotives.Add(loc));
                }
                // at that point loc exist

                var section = loc.Sections.FirstOrDefault(s => s.Name == devInfo.Description);
                if (section == null)
                {
                    section = new Section(new UidStringToLower(devInfo.Id.IdentyString), devInfo.Description, _backWorker, _deviceInformationStorage);
                    _uiNotifier.NotifyAndWait(() => loc.Sections.Add(section));
                }
                // at that point section already exist


                IDeviceInformation currentDeviceInformation = devInfo;

                var possiblePsnDataToAdd = psnDataInfos.Where(pdi => pdi.DeviceInformationId.ToString() == currentDeviceInformation.Id.ToString()).ToList();
                foreach (var psnDataInformation in possiblePsnDataToAdd)
                {
                    // Условие ниже исключает добавление уже присутствующих у секции логов:
                    if (section.Psns.All(pl => pl.Id.UnicString != psnDataInformation.Id.IdentyString))
                    {
                        try {
                            var data              = psnDatas.First(d => d.Id.ToString() == psnDataInformation.Id.ToString());                // TODO: can throw exception if data fail saved
                            var dataCustomInfo    = psnDataCustomInfos.First(pdci => pdci.Id.ToString() == psnDataInformation.Id.ToString());
                            var dataPsnConfig     = _psnConfigurationsStorage.StoredItems.First(pc => pc.Information.Id.IdentyString == dataCustomInfo.PsnConfigurationId.IdentyString);
                            var builder           = new PsnProtocolConfigBuilderFromLowLevel(dataPsnConfig);
                            var psnProtocolConfig = builder.Build();


                            var logToAdd = new PsnLogRelay(
                                psnDataInformation
                                , data
                                , psnProtocolConfig
                                , dataPsnConfig
                                , dataCustomInfo
                                , _uiNotifier
                                , _backWorker
                                , _psnConfigurationsStorage
                                , _psnDataCustomConfigurationsStorage
                                , _kvStorageHolder);

                            _uiNotifier.NotifyAndWait(() => section.Psns.Add(logToAdd));
                        }
                        catch {
                            // Значит ошибка получения данных ПСН, либо ошибка получения кастомной информации
                            continue;
                        }
                    }
                    // else log exist in list
                }
            }
        }