public async Task <GuidesIdsCollection> GetGuidesIdsAsync() { GuidesConfiguration guidesConfiguration = _guidesConfigManager.Get(); var guides = await LoadGuidesIdsAsync(guidesConfiguration); return(guides); }
public GuidesIdsCollection GetGuidesIds() { GuidesConfiguration guidesConfiguration = _guidesConfigManager.Get(); GuidesIdsCollection guides = LoadGuidesIds(guidesConfiguration); return(guides); }
// CONSTRUCTOR SECTION //--------------------------------------------------------------------- public GuideService(IGuideServiceDependencyBlock guideServiceDependency) { _guidesConfigurationManager = guideServiceDependency.GuidesConfigurationManager; _mnnGuideRepository = guideServiceDependency.MnnGuideRepository; _tradeNameGuideRepository = guideServiceDependency.TradeNameGuideRepository; _drugGuideRepository = guideServiceDependency.DrugGuideRepository; _drugformGuideRepository = guideServiceDependency.DrugformGuideRepository; // guide config initialization _guidesConfiguration = _guidesConfigurationManager.Get(); }
private async Task <GuidesIdsCollection> LoadGuidesIdsAsync(GuidesConfiguration guidesConfiguration) { var mnnFile = guidesConfiguration.Guides["mnn"][0]; var mnnGuideIds = await _mnnGuideRepository.GetIdsAsync(mnnFile); var tradeNameFile = guidesConfiguration.Guides["tradeName"][0]; var tradeNameGuideIds = await _tradeNameGuideRepository.GetIdsAsync(tradeNameFile); var guidesIdsCollection = CreateGuidesIdsCollecion(mnnGuideIds, tradeNameGuideIds); return(guidesIdsCollection); }
private GuidesIdsCollection LoadGuidesIds(GuidesConfiguration guidesConfiguration) { var mnnFile = guidesConfiguration.Guides["mnn"][0]; var mnnGuideIds = _mnnGuideRepository.GetIds(mnnFile); var tradeNameFile = guidesConfiguration.Guides["tradeName"][0]; var tradeNameGuideIds = _tradeNameGuideRepository.GetIds(tradeNameFile); var guidesIdsCollection = CreateGuidesIdsCollecion(mnnGuideIds, tradeNameGuideIds); return(guidesIdsCollection); }
// HELPER METHODS SECTION //--------------------------------------------------------------------- #region Helper methods // LOAD CONFIGURATIONS SECTION //------------------------------------------------- private void LoadConnectionsConfiguration() { // RECIPES CONNECTION //--------------------------------------------- try { _recipesConnection = _connectionConfigManager.Get("recipes"); View.RecipesFolderPath = _recipesConnection.ConnectionString; } catch (ArgumentNullException ex) { _log.Error(ex.ToString()); } catch (RepositoryLoadException ex) { _log.Error(ex.ToString()); } // REMAINS CONNECTION //--------------------------------------------- try { _remainsConnection = _connectionConfigManager.Get("remains"); View.RemainsFolderPath = _remainsConnection.ConnectionString; } catch (ArgumentNullException ex) { _log.Error(ex.ToString()); } catch (RepositoryLoadException ex) { _log.Error(ex.ToString()); } // GUIDES CONNECTION //--------------------------------------------- try { _guidesConfiguration = _guidesConfigurationManager.Get(); View.GuidesFolderPath = _guidesConfiguration.Path; } catch (ArgumentNullException ex) { _log.Error(ex.ToString()); } catch (RepositoryLoadException ex) { _log.Error(ex.ToString()); } }
//*** NOT USED private void RenewGuidesUpdateDates(IList <FileMetadata> filesMetaDataList, GuidesConfiguration guidesConfiguration) { foreach (var fileMetadata in filesMetaDataList) { if (fileMetadata.IsForUpdate) { var guideName = guidesConfiguration.Guides.SingleOrDefault(g => string.Equals(g.Value[GuideNameIndex], fileMetadata.Name)).Key; guidesConfiguration.Guides[guideName][GuideDateIndex] = fileMetadata.Date; } } _guidesConfigurationManager.Update(guidesConfiguration); }
private void UpdateDates(IList <FileMeta> filesMetaData, GuidesConfiguration guidesConfiguration) { for (int i = 0; i < filesMetaData.Count; ++i) { var ftpFile = filesMetaData[i]; if (ftpFile.IsForUpdate) { var guideName = guidesConfiguration.Guides. SingleOrDefault(x => x.Value[0] == ftpFile.Name).Key; guidesConfiguration.Guides[guideName][1] = ftpFile.Date; } } _guidesConfigManager.Update(guidesConfiguration); }
// PUBLIC INTERFACE METHODS SECTION //--------------------------------------------------------------------- #region IGuideService members public GuidesCollection GetGuides() { var serviceStateAgrs = new GuideServiceEventArgs(); FtpConfiguration ftpConfiguration = _ftpConfigManager.Get(); GuidesConfiguration guidesConfiguration = _guidesConfigManager.Get(); var ftpClient = new FtpClient(ftpConfiguration.Uri, ftpConfiguration.User, ftpConfiguration.Password); string[] ftpFolderMetadata = ftpClient.GetFtpFolderMetadata(); List <FileMeta> filesMetadata = ParseFtpFolderMetadata(ftpFolderMetadata); serviceStateAgrs.Message = "Checking guides for download."; OnStageChanged(serviceStateAgrs); var isForDownload = CheckGuidesForDownload(filesMetadata, guidesConfiguration.Guides); if (isForDownload) { try { serviceStateAgrs.Message = "Downloading guides."; OnStageChanged(serviceStateAgrs); DownloadGuides(ftpClient, filesMetadata, guidesConfiguration.Path); UpdateDates(filesMetadata, guidesConfiguration); } catch (HttpListenerException ex) { throw new RemoteServerException(ex.Message, ex); } catch (IOException ex) { throw new FileSaveException(ex.Message, ex); } } serviceStateAgrs.Message = "Loading guides."; OnStageChanged(serviceStateAgrs); var guides = LoadGuides(guidesConfiguration); return(guides); }