예제 #1
0
        private IEnumerable <RoadTypeModel> GetRoadTypes()
        {
            const string regionNamesFileName = "RoadTypes.csv";
            var          regionDirectory     = new DirectoryInfo(RoadTypeCsv);
            var          roadTypeFile        = regionDirectory.EnumerateFiles("*.csv", SearchOption.TopDirectoryOnly)
                                               .Single(f => f.Name == regionNamesFileName);
            var types =
                RegionsBuilder.GetCsvModel <RoadTypeModel>(roadTypeFile.FullName).ToList();

            return(types);
        }
예제 #2
0
        private void ImportRegions()
        {
            const string regionNamesFileName = "RegionNames.csv";
            var          regionDirectory     = new DirectoryInfo(RegionCsv);
            var          csvs = regionDirectory.EnumerateFiles("*.csv", SearchOption.TopDirectoryOnly);

            var regionNamesFile = csvs.Single(f => f.Name == regionNamesFileName);
            var names           =
                RegionsBuilder.GetCsvModel <RegionNameModel>(regionNamesFile.FullName).ToDictionary(i => i.FileName);

            var regions = csvs.Where(f => f.Name != regionNamesFileName)
                          .Select(RegionsBuilder.GetRegionModel).ToList();

            Console.WriteLine("Saving regions");
            using (var troutDashContext = new TroutDashPrototypeContext())
            {
                Console.WriteLine("Deleting all regions");
                troutDashContext.regions.RemoveRange(troutDashContext.regions);
                troutDashContext.SaveChanges();
                _sequenceRestarter.RestartSequence("region_id_seq");

                Console.WriteLine("Saving region:");
                foreach (var region in regions)
                {
                    Console.WriteLine("   " + region.regionName);
                    var r = new region();
                    r.name = region.regionName;
                    var fipsCodes = region.Counties.Select(i => i.FIPS).ToList();
                    r.counties =
                        troutDashContext.counties.Where(i => fipsCodes.Any(f => f == i.statefp + i.countyfp))
                        .ToList();
                    r.Geom      = DisolveCountyGeometriesByRegion(region);
                    r.long_name = names[region.regionName].FullName;
                    troutDashContext.regions.Add(r);
                    troutDashContext.SaveChanges();
                }
            }
        }