Example #1
0
        public IExtractedDataset <T> Extract <T>(IDataToImport dataToImport) where T : new()
        {
            var extractedDataset            = new ExtractedDataset <T>(_thresholdLevel);
            var validatedDataToImportResult = ValidateDataToImport(dataToImport);

            extractedDataset.AddParsingResults(validatedDataToImportResult.Item2);

            if (!validatedDataToImportResult.Item1)
            {
                //format not valid, return
                return(extractedDataset);
            }
            var results = new List <IResult>();
            var model   = new T();
            IDataSourceLocation currentLocation = null;

            foreach (var configuration in _extractConfigurations)
            {
                if (configuration is SimpleXMLExtractConfiguration)
                {
                    currentLocation = new XMLDataSourceLocation(((SimpleXMLExtractConfiguration)configuration).ElementName, ((SimpleXMLExtractConfiguration)configuration).AttributeName);
                }

                results.AddRange(((SimpleXMLExtractConfiguration)configuration).ExtractData(model, dataToImport, currentLocation));
            }

            var parsingResult = new ParsingResult(ResultLevel.DEBUG, "Extract data from single row success", model, null);

            results.Add(parsingResult);

            extractedDataset.AddParsingResults(results);

            return(extractedDataset);
        }
Example #2
0
        public IExtractedDataset <T> Extract <T>(IDataToImport dataToImport) where T : new()
        {
            var extractedDataset            = new ExtractedDataset <T>(_thresholdLevel);
            var validatedDataToImportResult = ValidateDataToImport(dataToImport);

            extractedDataset.AddParsingResults(validatedDataToImportResult.Item2);

            if (!validatedDataToImportResult.Item1)
            {
                //format not valid, return
                return(extractedDataset);
            }

            var        csvDataSource = dataToImport as XMLDataToImport;
            var        rawData       = csvDataSource.Data as XDocument;
            XNamespace rdf           = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
            var        parentNodes   = rawData.Descendants().Where(x => x.Name.LocalName == _rootNode);

            foreach (XElement element in parentNodes)
            {
                var extractResultsForNode = ExtractDataForSingleNode <T>(_extractConfigurations, new XMLDataToImport("", new XDocument(element)));
                extractedDataset.AddParsingResults(extractResultsForNode);
            }
            return(extractedDataset);
        }
Example #3
0
        public override IExtractedDataset <T> Extract <T>(IDataToImport dataToImport)
        {
            var extractedDataset = new ExtractedDataset <T>(_thresholdLevel);

            var validatedDataToImportResult = ValidateDataToImport(dataToImport);

            extractedDataset.AddParsingResults(validatedDataToImportResult.Item2);
            if (!validatedDataToImportResult.Item1)
            {
                //format not valid, return
                return(extractedDataset);
            }

            var csvDataSource = dataToImport as CSVDataToImport;
            var rawData       = csvDataSource.Data as string[][];

            for (var i = _startRow; i < rawData.Length; i++)
            {
                var extractResultsForRow = ExtractDataForSingleRow <T>(_extractConfigurations, dataToImport, i);
                extractedDataset.AddParsingResults(extractResultsForRow);
            }

            return(extractedDataset);
        }
        public override IExtractedDataset <T> Extract <T>(IDataToImport dataToImport)
        {
            var extractedDataset = new ExtractedDataset <T>(_thresholdLevel);

            ChemistryFileChildObjectExtractConfiguration chemistryDataExtractConfiguration = null;
            SampleFileChildObjectExtractConfiguration    sampleDataExtractConfiguration    = null;



            var castedDataToImport = dataToImport as ESDATDataToImport;

            if (castedDataToImport == null)
            {
                extractedDataset.AddParsingResult(new BaseResult(ResultLevel.FATAL, "Data to Import needs to be ESDATDataToImport"));
            }

            try
            {
                chemistryDataExtractConfiguration = _extractConfigurations.Where(x => x is ChemistryFileChildObjectExtractConfiguration)
                                                    .Cast <ChemistryFileChildObjectExtractConfiguration>()
                                                    .SingleOrDefault();
            }
            catch (Exception ex)
            {
                chemistryDataExtractConfiguration = null;
                extractedDataset.AddParsingResult(new BaseResult(ResultLevel.FATAL, "ESDAT data importer needs to have one and only one Chemistry file extract configuration"));
            }

            try
            {
                sampleDataExtractConfiguration = _extractConfigurations.Where(x => x is SampleFileChildObjectExtractConfiguration)
                                                 .Cast <SampleFileChildObjectExtractConfiguration>()
                                                 .SingleOrDefault();
            }
            catch (Exception ex)
            {
                sampleDataExtractConfiguration = null;
                extractedDataset.AddParsingResult(new BaseResult(ResultLevel.FATAL, "ESDAT data importer needs to have one and only one Sample file extract configuration"));
            }

            var model = new T();

            if (castedDataToImport.HeaderFileToImport == null)
            {
                var castedModel = model as ESDATModel;
                castedModel.LabName = _wqDefaultValueProvider.OrganizationNameSampleCollection;
                extractedDataset.AddParsingResults(new List <IResult> {
                    new BaseResult(ResultLevel.WARN, "Header file is null, use the default organization name in the default value provider")
                });
            }
            else
            {
                var headerFileExtractResults = ExtractHeaderFile(model, _extractConfigurations, castedDataToImport.HeaderFileToImport);
                extractedDataset.AddParsingResults(headerFileExtractResults);
            }


            if (chemistryDataExtractConfiguration != null && sampleDataExtractConfiguration != null)
            {
                var chemistryFileExtractResults = ExtractChemistryFileData(model, chemistryDataExtractConfiguration, castedDataToImport.ChemistryFileToImport);
                extractedDataset.AddParsingResults(chemistryFileExtractResults);

                var sampleFileExtractResults = ExtractSampleFileData(model, sampleDataExtractConfiguration, castedDataToImport.SampleFileToImport);
                extractedDataset.AddParsingResults(sampleFileExtractResults);
            }

            extractedDataset.AddParsingResults(new List <IResult> {
                new ParsingResult(ResultLevel.DEBUG, "Extract data into ESDAT model", model, null)
            });

            return(extractedDataset);
        }