Exemplo n.º 1
0
        public void ImportOverview(string[] headerNames, string filePath)
        {
            CsvToDictionaryLoader loader = new CsvToDictionaryLoader(headerNames);
            string csvFile = File.ReadAllText(@filePath);
            List <Dictionary <string, string> > overviews = loader.LoadToDictionary(csvFile);

            using (var context = new SossusvleiSedimentologyContext())
            {
                string idHeader = overviews.First().Keys.First();

                foreach (var sample in overviews)
                {
                    SampleOverview databaseEntry = new SampleOverview();
                    databaseEntry.SampleName = sample["SampleName"];
                    databaseEntry.Latitude   = sample["Latitude"].Substring(0, sample["Latitude"].Length - 1);
                    databaseEntry.Longitude  = sample["Longitude"].Substring(0, sample["Longitude"].Length - 1);
                    databaseEntry.Section    = sample["Section"];
                    databaseEntry.Facies     = sample["Facies"];

                    context.SampleOverview.Add(databaseEntry);

                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        e.HandleSaveChangesSqlException(idHeader);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public XrfMainElement Convert(KeyValuePair <string, string> map, SampleOverview sampleOverview)
        {
            XrfMainElement xrfMainElement = new XrfMainElement();

            xrfMainElement.Sample       = sampleOverview;
            xrfMainElement.MajorElement = map.Key;
            string amount = string.IsNullOrEmpty(map.Value) ? "0.0" : map.Value;

            xrfMainElement.Amount = decimal.Parse(amount, CultureInfo.InvariantCulture);

            return(xrfMainElement);
        }
        public GrainSize Convert(KeyValuePair <string, string> map, SampleOverview sampleOverview)
        {
            GrainSize grainSize = new GrainSize();

            grainSize.Sample = sampleOverview;
            grainSize.Size   = decimal.Parse(map.Key);
            string amount = string.IsNullOrEmpty(map.Value) ? "0.0" : map.Value;

            grainSize.WeightPercent = decimal.Parse(amount, CultureInfo.InvariantCulture);

            return(grainSize);
        }
Exemplo n.º 4
0
        public Petrography Convert(KeyValuePair <string, string> map, SampleOverview sampleOverview)
        {
            Petrography petrography = new Petrography();

            petrography.Sample  = sampleOverview;
            petrography.Mineral = map.Key;
            string amount = string.IsNullOrEmpty(map.Value) ? "0.0" : map.Value;

            petrography.Amount = decimal.Parse(amount, CultureInfo.InvariantCulture);

            return(petrography);
        }
Exemplo n.º 5
0
        public XrdMineralogy Convert(KeyValuePair <string, string> map, SampleOverview sampleOverview)
        {
            XrdMineralogy xrdMineralogy = new XrdMineralogy();

            xrdMineralogy.Sample  = sampleOverview;
            xrdMineralogy.Mineral = map.Key;
            string amount = string.IsNullOrEmpty(map.Value) ? "0.0" : map.Value;

            xrdMineralogy.Amount = decimal.Parse(amount, CultureInfo.InvariantCulture);

            return(xrdMineralogy);
        }
Exemplo n.º 6
0
        public void Import()
        {
            CsvToDictionaryLoader loader = new CsvToDictionaryLoader(_headerNames);
            string csvFile = File.ReadAllText(_filePath);
            List <Dictionary <string, string> > maps = loader.LoadToDictionary(csvFile);

            using (var context = new SossusvleiSedimentologyContext())
            {
                string idHeader = maps.First().Keys.First();

                foreach (var map in maps)
                {
                    string         sampleName = map[idHeader];
                    SampleOverview overview   = context.SampleOverview.First(s => s.SampleName == sampleName);

                    if (overview is null)
                    {
                        Console.WriteLine($"Missing overview for sample '{sampleName}'. Skipping data import.");

                        continue;
                    }

                    var filteredMap = map.Where(m => m.Key != idHeader);

                    foreach (var item in filteredMap)
                    {
                        TSedimentologicalData data = _mapConverter.Convert(item, overview);
                        context.Set <TSedimentologicalData>().Add(data);

                        try
                        {
                            context.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            e.HandleSaveChangesSqlException(map[idHeader]);
                        }
                    }
                }
            }
        }