/// <summary> /// Получает ссылку на репозиторий в локальной директории /// </summary> /// <param name="directoryPath">Путь к директории</param> /// <returns>Ссылка на репозиторий</returns> public IRepository GetLocalDirectoryRepository(string directoryPath) { var streamableFileForPsnDataInfoStorage = new StreamedFile(Path.Combine(directoryPath, "PsnDataInformationStorage.xml")); var streamableFileForDeviceInformationStorage = new StreamedFile(Path.Combine(directoryPath, "DeviceInformationStorage.xml")); var streamableFileForPsnDataCustomConfigStorage = new StreamedFile(Path.Combine(directoryPath, "PsnDataCustomConfigrationStorage.xml")); var bw = new BackgroundQueueWorker <Action>(a => a()); return(new RelayRepository(_psnInternalConfigurations.Value, () => { try { return new ReposetoryOpenedResultSimple( new StreamedDataStorageRelayMemoryCache(new StreamReadableDataStorageLocalDir(directoryPath)), new PsnDataInformationStorageRelayMemoryCache(new PsnDataInformationStorageXDocument(streamableFileForPsnDataInfoStorage, streamableFileForPsnDataInfoStorage)), new DeviceInformationStorageRelayMemoryCache(new DeviceInformationStorageXDocument(streamableFileForDeviceInformationStorage, streamableFileForDeviceInformationStorage)), new PsnDataCustomConfigurationsStorageRelayMemoryCache(new PsnDataCustomConfigurationsStorageXDocument(streamableFileForPsnDataCustomConfigStorage, streamableFileForPsnDataCustomConfigStorage)), new PsnInternalConfigurationsStorageRelay(_psnInternalConfigurations.Value)); } catch (Exception ex) { throw new Exception("Не удалось открыть репозиторий по указанному пути: " + directoryPath, ex); } } , new KeyValueStorageHolderXml() , bw , bw , "DIR@" + directoryPath)); }
/// <summary> /// Инициализирует новый экземпляр класса /// </summary> public Loader() { _psnInternalConfigurations = new Lazy <List <IPsnInternalConfiguration> >(() => LoadPsnConfigurations(Path.Combine(typeof(Loader).GetAssemblyDirectoryPath(), "defaults")).ToList()); var bqw = new BackgroundQueueWorker <Action>(a => a()); _backWorker = bqw; _uiNotifier = bqw; }
/// <summary> /// Получает ссылку на удаленный репозиторий, хранящийся на FTP сервере /// </summary> /// <param name="ftpHost">Адрес узла (IP-адрес или доменное имя)</param> /// <param name="ftpPort">TCP порт, на котором расположен FTP сервер</param> /// <param name="ftpUsername">Имя пользователя FTP сервера</param> /// <param name="ftpPassword">Пароль пользователя FTP сервера</param> /// <param name="deviceNumber">Номер устройства</param> /// <param name="locomotiveName">Название локомотива</param> /// <param name="sectionName">Название сервера</param> /// <param name="psnConfiguration">Конфигурация магистрали ПСН</param> /// <returns>Ссылка на репозиторий</returns> /// <exception cref="Exception">Может возникнуть исключение, если не удается открыть репозиторий</exception> public IRepository GetFtpClientRepository(string ftpHost, int ftpPort, string ftpUsername, string ftpPassword, int deviceNumber, string locomotiveName, string sectionName, IPsnProtocolConfig psnConfiguration) { var bw = new BackgroundQueueWorker <Action>(a => a()); var deviceId = new IdentifierGuidBased(Guid.NewGuid()); return(new RelayRepository(_psnInternalConfigurations.Value, () => { try { if (psnConfiguration == null) { throw new Exception("Ошибка, при обращении к устройству необходимо вручную указать конфигурацию ПСН"); } var deviceInformationStorage = new DeviceInformationStorageCustomSingle(locomotiveName, sectionName, deviceId.ToString()); var deviceInformationStorageCache = new DeviceInformationStorageRelayMemoryCache(deviceInformationStorage); var ftpFilesStorage = new FtpFilesStorageLazyCached( new FtpFilesStorageSimple( ftpHost, ftpPort, ftpUsername, ftpPassword, deviceNumber + "/")); var psnDataStorage = new StreamReadableDataStorageFtpUrl(ftpFilesStorage, deviceNumber); var psnDataStorageCache = new StreamedDataStorageRelayMemoryCache(psnDataStorage); var psnDataInfosStorage = new PsnDataInformationStorageFtpUrl(ftpFilesStorage, deviceNumber, deviceId.ToString()); var psnDataInfosStorageCache = new PsnDataInformationStorageRelayMemoryCache(psnDataInfosStorage); var psnDataCustomInfoStorage = new PsnDataCustomConfigurationsStoragePredefined( psnDataInfosStorageCache.PsnDataInformations.Select( pdi => new PsnDataCustomConfigurationSimple(pdi.Id, new IdentifierStringBased(psnConfiguration.Id.ToString()), string.Empty))); var psnDataCustomInfoStorageCache = new PsnDataCustomConfigurationsStorageRelayMemoryCache(psnDataCustomInfoStorage); return new ReposetoryOpenedResultSimple( psnDataStorageCache, psnDataInfosStorageCache, deviceInformationStorageCache, psnDataCustomInfoStorageCache, new PsnInternalConfigurationsStorageRelay(_psnInternalConfigurations.Value)); } catch (Exception ex) { throw new Exception("Не удалось открыть устройство по указанному пути: " + ftpHost + ":" + ftpPort, ex); } } , new KeyValueStorageHolderMemory() , bw , bw , "FtpClient@" + ftpHost + ":" + ftpPort + "[deviceNumber=" + deviceNumber + "]")); }
/// <summary> /// Получает ссылку на репозиторий устройства РПД /// </summary> /// <param name="nandPath">Путь к устройству РПД</param> /// <param name="psnConfiguration">Конфигурация ПСН применяемая ко всем данным NAND</param> /// <returns>Ссылка на репозиторий</returns> public IRepository GetNandFlashRepository(string nandPath, IPsnProtocolConfig psnConfiguration) { var bw = new BackgroundQueueWorker <Action>(a => a()); var deviceId = new IdentifierGuidBased(Guid.NewGuid()); return(new RelayRepository(_psnInternalConfigurations.Value, () => { try { if (psnConfiguration == null) { throw new Exception("Ошибка, при обращении к устройству необходимо вручную указать конфигурацию ПСН"); } var deviceInformationStorage = new DeviceInformationStorageNand(nandPath, deviceId.ToString()); var deviceInformationStorageCache = new DeviceInformationStorageRelayMemoryCache(deviceInformationStorage); var psnDataStorage = new StreamReadableDataStorageNand(nandPath); var psnDataStorageCache = new StreamedDataStorageRelayMemoryCache(psnDataStorage); var psnDataInfosStorage = new PsnDataInformationStorageNand(nandPath, deviceId.ToString()); var psnDataInfosStorageCache = new PsnDataInformationStorageRelayMemoryCache(psnDataInfosStorage); var psnDataCustomInfoStorage = new PsnDataCustomConfigurationsStoragePredefined( psnDataInfosStorageCache.PsnDataInformations.Select( pdi => new PsnDataCustomConfigurationSimple(pdi.Id, new IdentifierStringBased(psnConfiguration.Id.ToString()), string.Empty))); var psnDataCustomInfoStorageCache = new PsnDataCustomConfigurationsStorageRelayMemoryCache(psnDataCustomInfoStorage); return new ReposetoryOpenedResultSimple( psnDataStorageCache, psnDataInfosStorageCache, deviceInformationStorageCache, psnDataCustomInfoStorageCache, new PsnInternalConfigurationsStorageRelay(_psnInternalConfigurations.Value)); } catch (Exception ex) { throw new Exception("Не удалось открыть устройство по указанному пути: " + nandPath, ex); } } , new KeyValueStorageHolderMemory() , bw , bw , "NAND@" + nandPath)); }
/// <summary> /// Получает ссылку на архивированный репозиторий /// </summary> /// <param name="zipFileName">Путь к файлу-архиву репозитория</param> /// <returns>Ссылка на репозиторий</returns> public IRepository GetZippedRepository(string zipFileName) { var bw = new BackgroundQueueWorker <Action>(a => a()); return(new RelayRepository(_psnInternalConfigurations.Value, () => { try { var zipStreamForPscCustomStorage = new StreamedZippedFile(zipFileName, "PsnDataCustomConfigrationStorage.xml"); var zipStreamForPsnDataInformationStorage = new StreamedZippedFile(zipFileName, "PsnDataInformationStorage.xml"); var zipStreamForDeviceInformationStorage = new StreamedZippedFile(zipFileName, "DeviceInformationStorage.xml"); var deviceInformationStorage = new DeviceInformationStorageXDocument(zipStreamForDeviceInformationStorage, zipStreamForDeviceInformationStorage); var deviceInformationStorageCache = new DeviceInformationStorageRelayMemoryCache(deviceInformationStorage); var psnDataStorage = new StreamReadableDataStorageZip(zipFileName); var psnDataStorageCache = new StreamedDataStorageRelayMemoryCache(psnDataStorage); var psnDataInfosStorage = new PsnDataInformationStorageXDocument(zipStreamForPsnDataInformationStorage, zipStreamForPsnDataInformationStorage); var psnDataInfosStorageCache = new PsnDataInformationStorageRelayMemoryCache(psnDataInfosStorage); var psnDataCustomInfoStorage = new PsnDataCustomConfigurationsStorageXDocument(zipStreamForPscCustomStorage, zipStreamForPscCustomStorage); var psnDataCustomInfoStorageCache = new PsnDataCustomConfigurationsStorageRelayMemoryCache(psnDataCustomInfoStorage); return new ReposetoryOpenedResultSimple( psnDataStorageCache, psnDataInfosStorageCache, deviceInformationStorageCache, psnDataCustomInfoStorageCache, new PsnInternalConfigurationsStorageRelay(_psnInternalConfigurations.Value)); } catch (Exception ex) { throw new Exception("Ошибка, проверьте правильность имени файла " + zipFileName + Environment.NewLine + "Если имя файла указано верно, то, возможно файл не доступен для чтения или записи (например, файл поврежден или у Вас нет прав на доступ к файлу)", ex); } } , new KeyValueStorageHolderMemory() , bw , bw , "ZIP@" + zipFileName)); }
/// <summary> /// Создает описание конфигурации /// </summary> /// <returns>Ссылка на новое описание конфигурации</returns> public IDeviceConfiguration CreateDeviceConfiguration() { var bw = new BackgroundQueueWorker <Action>(a => a()); return(new DeviceConfiguration(bw, bw)); }