public bool LoadFile(int fileId, int datasetId) { var file = _fileRepository.Get(fileId); string filePath; DataTable dataTable; bool success; filePath = Path.Combine(file.Path, file.FileName); dataTable = ReadOriginalFile(filePath); switch (file.Format) { case "SDTM": var sdtmLoader = new SDTMloader(_dataServiceUnit); success = sdtmLoader.LoadSDTM(datasetId, fileId, dataTable); return(success); case "ADTM": var hdDataloader = new HDloader(_dataServiceUnit); success = hdDataloader.LoadHDdata(datasetId, fileId, dataTable); return(success); } return(false); }
public async Task <bool> LoadDataset(int datasetId, int fileId) { Dataset dataset = GetActivityDataset(datasetId); var reload = false; var loaded = false; var dataFile = _dataFileRepository.Get(fileId); if (dataFile.IsLoadedToDB) { reload = true; } try { switch (dataset.Template.Code) { case "DM": var subjectLoader = new SubjectLoader(_dataServiceUnit); loaded = await subjectLoader.LoadSubjects(dataset, fileId, reload); break; case "BS": var sampleLoader = new BioSampleLoader(_dataServiceUnit); loaded = await sampleLoader.LoadBioSamples(dataset, fileId, reload); break; case "CY": case "HD": var hdDataLoader = new HDloader(_dataServiceUnit); //loaded = await hdDataLoader.LoadHDdata(dataset,fileId, datasetId); break; case "MX": break; default: var observationLoader = new ObservationLoader(this._dataServiceUnit); loaded = await observationLoader.LoadObservations(dataset, fileId, reload); if (loaded) { await _cacheService.GenerateAndCacheClinicalDTO(dataFile.ProjectId); } break; } if (loaded) { dataFile.State = "LOADED"; dataFile.IsLoadedToDB = true; _dataFileRepository.Update(dataFile); if (!dataset.DataFiles.Select(d => d.DatafileId).Contains(fileId)) { //Adding a new datafile to this dataset dataset.DataFiles.Add(new DatasetDatafile() { DatasetId = datasetId, DatafileId = dataFile.Id }); _datasetRepository.Update(dataset); } _dataServiceUnit.Save(); } if (!loaded && dataFile.State == "SAVED") { _sdtmRepository.DeleteMany(s => s.DatafileId == fileId && s.DatasetId == datasetId); } } catch (Exception e) { Debug.WriteLine("Failed to load descriptors to SQL database", e.Message); await UnloadDataset(datasetId, fileId, "LOADING FAILED"); } return(loaded); }