public IEnumerable<ResultMessageViewModel> ImportLocalFiles()
        {
            var results = new List<ResultMessageViewModel>();

            var request = HttpContext.Current.Request;

            XMLDataToImport headerFileXMLFileToImport = null;

            if (request.Files.AllKeys.Contains(HeaderFileInputElementName))
            {
                var headerFile = request.Files[HeaderFileInputElementName];
                var headerFileData = new DataFromFileSystem(headerFile.FileName, headerFile.InputStream);
                headerFileXMLFileToImport = new XMLDataToImport(headerFileData);
            }
            else
            {
                results.Add(new ResultMessageViewModel(ResultMessageViewModel.RESULT_LEVEL_WARN, "Header file is not uploaded, use default value."));
            }
            
            var sampleFile = request.Files[SampleFileInputElementName];
            var chemistryFile = request.Files[ChemistryFileInputElementName];

            var sampleFileData = new DataFromFileSystem(sampleFile.FileName, sampleFile.InputStream);
            var sampleFileCSVFileToImport = new CSVDataToImport(sampleFileData);

            var chemistryFileData = new DataFromFileSystem(chemistryFile.FileName, chemistryFile.InputStream);
            var chemistryCSVFileToImport = new CSVDataToImport(chemistryFileData);

            var esdatDataToImport = new ESDATDataToImport(headerFileXMLFileToImport, sampleFileCSVFileToImport, chemistryCSVFileToImport);
            var importer = ESDATDataImportHelper.BuildESDATDataImporter(_wqDefaultValueProvider);

            results.AddRange(PersistESDATData(esdatDataToImport, importer));

            return results;
        }
        public void CSVDataToImportReadCSVFileTest()
        {
            var dataSource = new WindowsFileSystem(_csvDataFilePath);
            var dataFromFileSystem = dataSource.FetchData();

            var dataToImport = new CSVDataToImport(dataFromFileSystem);
            AssertData(Path.GetFileName(_csvDataFilePath), dataToImport);
        }
        private void AssertData(string fileName, CSVDataToImport csvDataToImport)
        {           

            Assert.AreEqual(fileName, csvDataToImport.FileName);
            Assert.NotNull(csvDataToImport);
            var castedData = csvDataToImport.Data as string[][];
            Assert.NotNull(castedData);
            Assert.AreEqual(12, castedData.Count());
            Assert.AreEqual("TOA5", castedData[0][0]);
        }
        public void GetDataTest()
        {
            var xmlDataToImport = new XMLDataToImport("test.xml", new System.Xml.Linq.XDocument());
            var csvDataToImport1 = new CSVDataToImport("test1.csv", new string[][]{});
            var csvDataToImport2 = new CSVDataToImport("test2.csv", new string[][] { });

            var dataToImport = new ESDATDataToImport(xmlDataToImport, csvDataToImport1, csvDataToImport2);

            Assert.AreEqual(dataToImport, dataToImport.Data);
        }
        public void ExtractChemistryFileDataTest()
        {
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "ChemistryFileExample.csv");
            var dataSource = new WindowsFileSystem(path);
            var dataFromFileSystem = dataSource.FetchData();

            var dataToImport = new CSVDataToImport(dataFromFileSystem);

            var chemistryFileImporter = BuildChemistryFileImporter();

            var extractResult = chemistryFileImporter.Extract<ChemistryFileData>(dataToImport);

            var allFailResults = extractResult.AllParsingResults.Where(x => x.Level == ResultLevel.ERROR).ToList();

            Assert.NotNull(extractResult);
            Assert.AreEqual(ResultLevel.ERROR, extractResult.ThresholdLevel);
            Assert.False(allFailResults.Any());
            Assert.AreEqual(true, extractResult.IsExtractedSuccess);
            Assert.AreEqual(9, extractResult.ExtractedEntities.Count());

            var firstEntity = extractResult.ExtractedEntities.FirstOrDefault();

            Assert.NotNull(firstEntity);
            Assert.AreEqual("5828314", firstEntity.SampleCode);
            Assert.AreEqual("100-41-4", firstEntity.ChemCode);
            Assert.AreEqual("Ethylbenzene", firstEntity.OriginalChemName);
            Assert.AreEqual("<", firstEntity.Prefix);
            Assert.AreEqual(0.0005, firstEntity.Result);
            Assert.AreEqual("mg/L", firstEntity.ResultUnit);
            Assert.AreEqual("T", firstEntity.TotalOrFiltered);
            Assert.AreEqual("REG", firstEntity.ResultType);
            Assert.AreEqual("Inorganic", firstEntity.MethodType);
            Assert.AreEqual("TO 0332", firstEntity.MethodName);
            Assert.AreEqual(new DateTime(2014, 9, 23), firstEntity.ExtractionDate);
            Assert.AreEqual(new DateTime(2014, 9, 24), firstEntity.AnalysedDate);
            Assert.AreEqual(0.0005, firstEntity.EQL);
            Assert.AreEqual("mg/L", firstEntity.EQLUnits);
            Assert.AreEqual(string.Empty, firstEntity.Comments);
            Assert.AreEqual(50.0d, firstEntity.UCL);
            Assert.AreEqual(null, firstEntity.LCL);
        }
        public void ChemistryFilePropertyTest()
        {
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "ChemistryFileExample.csv");
            var dataSource = new WindowsFileSystem(path);
            var dataFromFileSystem = dataSource.FetchData();
            var dataToImport = new CSVDataToImport(dataFromFileSystem);

            var simpleValueAssginer = new SimpleValueAssigner();

            var chemistryImporter = ESDATTestHelper.BuildChemistryFileImporter();

            var childObjectExtractConfiguration = new ChemistryFileChildObjectExtractConfiguration(chemistryImporter, "ChemistryData", simpleValueAssginer);

            Assert.AreEqual(typeof(ChemistryFileData), childObjectExtractConfiguration.ChildObjectType);

            var testESDATModel = new ESDATModel();

            var extractResult = childObjectExtractConfiguration.ExtractData(testESDATModel, dataToImport);

            Assert.NotNull(extractResult);
            Assert.AreEqual(9, testESDATModel.ChemistryData.Count());
        }
        public void ChemistryFilePropertyTest()
        {
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "SampleFileExample.csv");
            var dataSource = new WindowsFileSystem(path);
            var dataFromFileSystem = dataSource.FetchData();
            var dataToImport = new CSVDataToImport(dataFromFileSystem);

            var simpleValueAssginer = new SimpleValueAssigner();

            var sampleDataImporter = ESDATTestHelper.BuildSampleDataFileImporter();

            var childObjectExtractConfiguration = new SampleFileChildObjectExtractConfiguration(sampleDataImporter, "SampleFileData", simpleValueAssginer);

            Assert.AreEqual(typeof(SampleFileData), childObjectExtractConfiguration.ChildObjectType);

            var testESDATModel = new ESDATModel();

            var extractResult = childObjectExtractConfiguration.ExtractData(testESDATModel, dataToImport);

            Assert.NotNull(extractResult);
            Assert.AreEqual(3, testESDATModel.SampleFileData.Count());

            var firstSampleData = testESDATModel.SampleFileData.FirstOrDefault();

            Assert.NotNull(firstSampleData);
            Assert.AreEqual("5828314", firstSampleData.SampleCode);
            Assert.AreEqual(new DateTime(2014, 9, 16), firstSampleData.SampledDateTime);
            Assert.AreEqual("FRL-1 @ 16:00", firstSampleData.FieldID);
            Assert.Null(firstSampleData.SampleDepth);
            Assert.AreEqual("Water", firstSampleData.MatrixType);
            Assert.AreEqual("Normal", firstSampleData.SampleType);
            Assert.AreEqual(string.Empty, firstSampleData.ParentSample);
            Assert.AreEqual("14J891101", firstSampleData.SDG);
            Assert.AreEqual("AGAT", firstSampleData.LabName);
            Assert.AreEqual("5828314", firstSampleData.LabSampleID);
            Assert.AreEqual(string.Empty, firstSampleData.Comments);
            Assert.AreEqual("14J891101", firstSampleData.LabReportNumber);
        }
        public void ExtractSampleDataFileTest()
        {
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "SampleFileExample.csv");
            var dataSource = new WindowsFileSystem(path);
            var dataFromFileSystem = dataSource.FetchData();

            var dataToImport = new CSVDataToImport(dataFromFileSystem);

            var sampleDataFileImporter = ESDATTestHelper.BuildSampleDataFileImporter();

            var extractResult = sampleDataFileImporter.Extract<SampleFileData>(dataToImport);

            var allFailResults = extractResult.AllParsingResults.Where(x => x.Level == ResultLevel.ERROR).ToList();

            Assert.NotNull(extractResult);
            Assert.AreEqual(ResultLevel.ERROR, extractResult.ThresholdLevel);
            Assert.False(allFailResults.Any());
            Assert.AreEqual(true, extractResult.IsExtractedSuccess);
            Assert.AreEqual(3, extractResult.ExtractedEntities.Count());

            var firstEntity = extractResult.ExtractedEntities.FirstOrDefault();
            
            Assert.NotNull(firstEntity);
            Assert.AreEqual("5828314", firstEntity.SampleCode);
            Assert.AreEqual(new DateTime(2014, 9, 16), firstEntity.SampledDateTime);
            Assert.AreEqual("FRL-1 @ 16:00", firstEntity.FieldID);
            Assert.Null(firstEntity.SampleDepth);
            Assert.AreEqual("Water", firstEntity.MatrixType);
            Assert.AreEqual("Normal", firstEntity.SampleType);
            Assert.AreEqual(string.Empty, firstEntity.ParentSample);
            Assert.AreEqual("14J891101", firstEntity.SDG);
            Assert.AreEqual("AGAT", firstEntity.LabName);
            Assert.AreEqual("5828314", firstEntity.LabSampleID);
            Assert.AreEqual(string.Empty, firstEntity.Comments);
            Assert.AreEqual("14J891101", firstEntity.LabReportNumber);
        }
        public static IExtractConfiguration CreateSampleFileDataExtractConfiguration()
        {
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataFiles", "SampleFileExample.csv");
            var dataSource = new WindowsFileSystem(path);
            var dataFromFileSystem = dataSource.FetchData();
            var dataToImport = new CSVDataToImport(dataFromFileSystem);

            var simpleValueAssginer = new SimpleValueAssigner();

            var sampleDataImporter = ESDATTestHelper.BuildSampleDataFileImporter();

            var childObjectExtractConfiguration = new SampleFileChildObjectExtractConfiguration(sampleDataImporter, "SampleFileData", simpleValueAssginer);

            return childObjectExtractConfiguration;
        }
        public static CSVDataToImport CreateCSVDataToImport(string filePath)
        {
            var dataSource = new WindowsFileSystem(filePath);
            var dataFromFileSystem = dataSource.FetchData();
            var dataToImport = new CSVDataToImport(dataFromFileSystem);

            return dataToImport;
        }
        public IEnumerable<ResultMessageViewModel> ImportHttpFiles(HttpFileImportDataViewModel data)
        {
            XMLDataToImport headerFileXMLFileToImport = null;

            if (!string.IsNullOrEmpty(data.HeaderFileURL))
            {
                var headerFileHttpFileSystem = new HttpFileSystem(data.HeaderFileURL);
                headerFileXMLFileToImport = new XMLDataToImport(headerFileHttpFileSystem.FetchData());
            }
            

            var sampleFileHttpFileSystem = new HttpFileSystem(data.SampleFileURL);
            var sampleFileCSVFileToImport = new CSVDataToImport(sampleFileHttpFileSystem.FetchData());

            var chemistryFileHttpFileSystem = new HttpFileSystem(data.ChemistryFileURL);
            var chemistryCSVFileToImport = new CSVDataToImport(chemistryFileHttpFileSystem.FetchData());

            var esdatDataToImport = new ESDATDataToImport(headerFileXMLFileToImport, sampleFileCSVFileToImport, chemistryCSVFileToImport);
            var importer = ESDATDataImportHelper.BuildESDATDataImporter(_wqDefaultValueProvider);

            var results = PersistESDATData(esdatDataToImport, importer);

            return results;
        }
 public ESDATDataToImport(XMLDataToImport headerFileToImport, CSVDataToImport sampleFileToImport, CSVDataToImport chemistryFileToImport)
 {
     _headerFileToImport = headerFileToImport;
     _sampleFileToImport = sampleFileToImport;
     _chemistryFileToImport = chemistryFileToImport;
 }