public void ExportLakeSections() { Console.WriteLine("Exporting Lake Sections..."); var state = _troutDashContext.states.First(s => s.short_name == "MN"); var pre_existing_sections = state.streams.SelectMany(s => s.lake_sections); _troutDashContext.lake_sections.RemoveRange(pre_existing_sections); _troutDashContext.SaveChanges(); var lakes = state.lakes.ToDictionary(i => i.source_id); state.streams .ToList() .AsParallel() .ForAll(stream => { try { using (var troutDashContext = new TroutDashPrototypeContext()) { Console.WriteLine(stream.name + "..."); var sections = ExportLakeSections(stream, lakes).ToList(); troutDashContext.lake_sections.AddRange(sections); troutDashContext.SaveChanges(); } } catch (Exception) { throw; } }); }
private void ExportMnRoadTypes() { using (var context = new MinnesotaShapeDataContext()) using (var troutDashContext = new TroutDashPrototypeContext()) { // Remove old MN road types. Console.WriteLine("Deleting Minnesota road types..."); var minnesota = troutDashContext.states.Single(s => s.short_name == "MN"); troutDashContext.road_types.RemoveRange(minnesota.road_types.ToList()); troutDashContext.SaveChanges(); Console.WriteLine("Done deleting Minnesota road types."); Console.WriteLine("Getting Minnesota road types..."); var roadTypes = GetMnRoadTypes().ToList().Select(i => new road_type() { description = i.name, state_gid = minnesota.gid, source = i.road_type_id.ToString(), type = i.abc, }); Console.WriteLine("Saving Minnesota road types..."); troutDashContext.road_types.AddRange(roadTypes); troutDashContext.SaveChanges(); Console.WriteLine("Done saving Minnesota road types."); } }
public void ExportRestrictions() { var restrictions = GetRestrictions(); using (var context = new MinnesotaShapeDataContext()) using (var troutDashContext = new TroutDashPrototypeContext()) { var states = troutDashContext.counties.ToList(); var minnesota = troutDashContext.states.Single(s => s.short_name == "MN"); // clear out the old. Console.WriteLine("Removing all restrictions in minnesota"); var oldRestrictions = minnesota.restrictions.ToList(); troutDashContext.restrictions.RemoveRange(oldRestrictions); troutDashContext.SaveChanges(); _sequenceRestarter.RestartSequence("restriction_id_seq"); // in with the new. var newRestrictions = restrictions.Select(r => new restriction { state = minnesota, isAnglingRestriction = r.isAnglingRestriction, isHarvestRestriciton = r.isHarvestRestriction, isSeasonal = false, short_text = r.shortText, legal_text = r.text, source_id = r.id.ToString(), }).ToList(); Console.WriteLine("Saving new restrictions"); troutDashContext.restrictions.AddRange(newRestrictions); troutDashContext.SaveChanges(); } }
private void SaveStream(IGrouping <string, trout_streams_minnesota> section, string stateName, int stateId, List <trout_streams_minnesota> badList) { using (var context = new MinnesotaShapeDataContext()) using (var troutDashContext = new TroutDashPrototypeContext()) { try { var id = section.Key; Console.WriteLine("Loading Trout Stream Id: " + id); var route = context.StreamRoute.Single(sr => sr.kittle_nbr == id); stream stream = CreateStream(route, stateName, stateId); Console.WriteLine("Saving trout stream: " + stream.name); troutDashContext.streams.Add(stream); troutDashContext.SaveChanges(); CreateStreamSections(route, section, stream); troutDashContext.SaveChanges(); } catch (Exception) { Console.WriteLine("FAILED LOAIND STREAM: " + section.Key); badList.Add(section.First()); } } }
public ExportRegulationSections(TroutDashPrototypeContext troutDashContext, MinnesotaShapeDataContext minnesotaContext, IDatabaseConnection dbConnection) { _troutDashContext = troutDashContext; _minnesotaContext = minnesotaContext; _sequenceRestarter = new SequenceRestarter(dbConnection); }
public void ExportCountyToStreamRelations() { using (var troutDashContext = new TroutDashPrototypeContext()) { Console.WriteLine("Caching minnesota counties and streams..."); var minnesota = troutDashContext.states.Single(s => s.short_name == "MN"); var mnCounties = minnesota.counties.ToList(); var mnStreams = minnesota.streams.ToList(); Console.WriteLine("Finding all streams in each county"); foreach (var mnCounty in mnCounties) { Console.WriteLine(mnCounty.name + " county..."); foreach (var mnStream in mnStreams) { var isMatch = mnCounty.OriginalGeometry.Intersects(mnStream.OriginalGeometry); if (isMatch) { Console.WriteLine(" has " + mnStream.name); mnCounty.stream.Add(mnStream); mnCounty.stream_count++; } } troutDashContext.SaveChanges(); } } }
public RegionToShapefileExporter(TroutDashPrototypeContext context, DirectoryInfo rootDirectory, IEnumerable <string> shapes, IDatabaseConnection dataseConnection, IJsonExporter jsonExporter) { _context = context; _rootDirectory = rootDirectory; _shapes = shapes; _dataseConnection = dataseConnection; _jsonExporter = jsonExporter; }
public void ExportSections() { using (var context = new MinnesotaShapeDataContext()) using (var troutDashContext = new TroutDashPrototypeContext()) { var routesWithTroutStreamSections = GetMinnesotaStreamRoutesThatHaveTroutStreamSections(context); } }
public RegulationsExporter(TroutDashPrototypeContext troutDashContext, MinnesotaShapeDataContext minnesotaContext, SequenceRestarter sequenceRestarter, GetLinearOffsets getLinearOffsets) { _troutDashContext2 = troutDashContext; _minnesotaContext2 = minnesotaContext; _sequenceRestarter = sequenceRestarter; _getLinearOffsets = getLinearOffsets; }
public LakeExporter(TroutDashPrototypeContext troutDashContext, MinnesotaShapeDataContext minnesotaContext, SequenceRestarter sequenceRestarter, GetLinearOffsets getLinearOffsets) { _sequenceRestarter = sequenceRestarter; _troutDashContext = troutDashContext; _minnesotaContext = minnesotaContext; _getLinearOffsets = getLinearOffsets; _getState = new Lazy <state>(GetState); }
private void ExportMnRoads() { using (var context = new MinnesotaShapeDataContext()) using (var troutDashContext = new TroutDashPrototypeContext()) { const int UncategorizedRoad = 100; // Remove old MN road types. Console.WriteLine("Deleting Minnesota roads..."); var minnesota = troutDashContext.states.Single(s => s.short_name == "MN"); troutDashContext.roads.RemoveRange(minnesota.roads); troutDashContext.SaveChanges(); Console.WriteLine("Done deleting Minnesota roads."); Console.WriteLine("Getting Minnesota roads..."); var roadTypes = minnesota.road_types.ToDictionary(i => i.source); var roads = context.streets_load.ToList().Select(i => { var key = Convert.ToInt32(i.route_syst).ToString(); var roadTypeId = -1; if (i.route_syst == "1") { roadTypeId = 1; } else if (i.route_syst == "2") { roadTypeId = 2; } else { roadTypeId = roadTypes.ContainsKey(key) == false ? roadTypes.Single(j => j.Value.source == UncategorizedRoad.ToString()).Value.id : roadTypes[key].id; } var t = new road() { name = i.street_nam, local_name = "", state_gid = minnesota.gid, road_type_id = roadTypeId, Geom = i.Geom_4326 }; return(t); }).ToList(); Console.WriteLine("Saving Minnesota roads..."); troutDashContext.roads.AddRange(roads); troutDashContext.SaveChanges(); Console.WriteLine("Done saving Minnesota roads."); } }
private void ImportStatesAndCounties() { using (var context = new UsShapeDataContext()) using (var troutDashContext = new TroutDashPrototypeContext()) { var states = troutDashContext.states.ToList(); troutDashContext.states.RemoveRange(states); troutDashContext.SaveChanges(); _sequenceRestarter.RestartSequence("states_gid_seq"); _sequenceRestarter.RestartSequence("counties_gid_seq"); var counties = context.counties.ToLookup(c => c.statefp); foreach (var state in context.states) { var actualState = _fips.Value[Convert.ToInt32(state.statefp)].FirstOrDefault(); if (actualState == null) { continue; } Console.WriteLine("Adding state " + actualState.StateName); var stateCounties = counties[state.statefp]; var countyModels = stateCounties.Select(c => new TroutDash.EntityFramework.Models.county { Geom = c.Geom_4326, countyfp = c.countyfp, statefp = c.statefp, name = c.name, lsad = c.lsad, stream_count = 0 }).ToList(); var stateAbbreviation = actualState.StateAbbreviation; var stateName = actualState.StateName; var newState = new TroutDash.EntityFramework.Models.state { counties = countyModels, Name = stateName, short_name = stateAbbreviation, statefp = state.statefp, Geom = state.Geom_4326, }; troutDashContext.states.Add(newState); troutDashContext.SaveChanges(); } } }
private void Stuff(stream s, Dictionary <string, restriction> restrictions) { try { using (var troutDashContext = new TroutDashPrototypeContext()) { Console.WriteLine(s.name + "..."); var sections = GetSections(s, restrictions).ToList(); troutDashContext.restriction_section.AddRange(sections); troutDashContext.SaveChanges(); } } catch (Exception) { } }
private void ExportStreamAccessPoints() { using (var context = new MinnesotaShapeDataContext()) using (var troutDashContext = new TroutDashPrototypeContext()) { Console.WriteLine("Deleting minnesota stream access points..."); var state = troutDashContext.states.First(s => s.short_name == "MN"); var pre_existing_sections = state.streams.SelectMany(s => s.stream_access_points).ToList(); troutDashContext.stream_access_points.RemoveRange(pre_existing_sections); troutDashContext.SaveChanges(); var roadIntersections = GetRoadStreamIntersections().ToList(); troutDashContext.stream_access_points.AddRange(roadIntersections); troutDashContext.SaveChanges(); } }
public void TestMethod1() { var context = new TroutDashPrototypeContext(); var shapes = new[] { "lake", "county", "stream", "trout_stream_section", "publicly_accessible_land", "restriction_route" }; var targetDirectory = new DirectoryInfo(Directory.GetCurrentDirectory()).Parent; var dbConnection = new DatabaseConnection("troutdash2", "localhost", "postgres"); var t = new RegionToShapefileExporter(context, targetDirectory, shapes, dbConnection, new JsonExporter(context)); t.Export(); }
private void ExportStreamToPubliclyAccessibleLandRelations() { List <publicly_accessible_land> mnPals = new List <publicly_accessible_land>(); List <stream> mnStreams = new List <stream>(); using (var troutDashContext = new TroutDashPrototypeContext()) { Console.WriteLine("Caching minnesota counties and streams..."); var minnesota = troutDashContext.states.Single(s => s.short_name == "MN"); mnPals = minnesota.Pal.ToList(); mnStreams = minnesota.streams.ToList(); } Console.WriteLine("Finding all streams in each county"); mnStreams.AsParallel() .ForAll(stream => { using (var troutDashContext2 = new TroutDashPrototypeContext()) { try { Console.WriteLine(stream.name + " stream..."); foreach (var mnPal in mnPals) { var isMatch = mnPal.OriginalGeometry.Intersects(stream.OriginalGeometry); if (isMatch) { Console.WriteLine(" has " + mnPal.area_name); mnPal.streams.Add(stream); } } troutDashContext2.SaveChanges(); } catch (Exception) { throw; } } } ); }
public void TestMethod1() { var context = new TroutDashPrototypeContext(); var jsonExporter = new JsonExporter(context); var streamDetails = jsonExporter.GetStreamDetails(); var detailsJson = JsonConvert.SerializeObject(streamDetails, Formatting.None); File.WriteAllText("streamDetails.json", detailsJson); var t = streamDetails.ToDictionary(i => i.Id, i => i); var json = File.ReadAllText("stream.geojson"); var featureCollection = JsonConvert.DeserializeObject <FeatureCollection>(json).Features; var oldCount = featureCollection.Count; // var orphans = // featureCollection.Where(f => t.Any(stream => stream.Key == Convert.ToInt32(f.Properties["gid"]))) // .ToList(); featureCollection.RemoveAll(f => t.Any(stream => stream.Key == Convert.ToInt32(f.Properties["gid"])) == false); var newCount = featureCollection.Count; foreach (var f in featureCollection) { var gid = f.Properties["gid"]; var featureId = Convert.ToInt32(gid); var jsonObject = t[featureId]; var obj = JsonConvert.SerializeObject(jsonObject, Formatting.None); Dictionary <string, object> FD = (from x in jsonObject.GetType().GetProperties() select x).ToDictionary(x => x.Name, x => (x.GetGetMethod().Invoke(jsonObject, null) ?? "")); // f.Properties.Clear(); // foreach (var entry in FD) // { // f.Properties.Add(entry.Key, entry.Value); // } } var result = JsonConvert.SerializeObject(featureCollection, Formatting.None); File.WriteAllText("streamResult.json", json); }
public void CreateEmptySpeciesCsv() { var context = new TroutDashPrototypeContext(); var mnStreams = context.streams.Where(i => i.state == "Minnesota").ToList(); var rows = mnStreams.Select(s => { var f = new Func <bool, bool?>((b) => { if (!b) { return(null); } return(true); }); return(new StreamSpeciesCsv() { Name = s.name, Id = s.source, Counties = string.Join(",", s.counties.Select(c => c.name)), IsBrook = f(s.has_brook_trout), IsBrown = f(s.has_brown_trout), IsRainbow = f(s.has_rainbow_trout), IsBrookStocked = f(s.is_brook_trout_stocked), IsBrownStocked = f(s.is_brown_trout_stocked), IsRainbowStocked = f(s.is_rainbow_trout_stocked), Status = s.status_mes }); }).ToList(); using (var writer = File.CreateText("StreamSpeciesBlank.csv")) { var csv = new CsvWriter(writer); csv.WriteRecords(rows); } }
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(); } } }
public void GetAlphabetDistribution2() { var context = new TroutDashPrototypeContext(); var jsonExporter = new JsonExporter(context); var streamDetails = jsonExporter.GetStreamDetails(); var inputNames = streamDetails.Select(s => s.Name) .Concat(streamDetails.SelectMany(x => x.LocalNames).Distinct()) .ToList(); var alphabet = CreateAlphabet().ToArray(); var sb = new StringBuilder(); var alphabetString = new string(alphabet); var firstRow = "firstLetter\tsecondLetter\tfirstLetterOnlyHits\ttwoLetterHits"; sb.Append(firstRow); // alphabet.ToList().ForEach(x => sb.Append("" + x + '\t')); sb.AppendLine(); foreach (var firstLetter in alphabet) { var singleCharacter = "" + firstLetter; var totalHitsSingleCharacter = inputNames.Count(n => n.IndexOf(singleCharacter, StringComparison.OrdinalIgnoreCase) >= 0); foreach (var secondLetter in alphabet) { sb.Append(String.Empty + firstLetter + '\t'); sb.Append(String.Empty + secondLetter + '\t'); sb.Append(String.Empty + totalHitsSingleCharacter + '\t'); // sb.Append("" + totalHitsSingleCharacter + '\t'); var soughtToken = "" + firstLetter + secondLetter; var totalHits = inputNames.Count(n => n.IndexOf(soughtToken, StringComparison.OrdinalIgnoreCase) >= 0); sb.Append("" + totalHits + '\t'); sb.AppendLine(); } } var results = sb.ToString(); }
private void ImportFederalRoadTypes() { var roadTypes = GetRoadTypes(); using (var troutDashContext = new TroutDashPrototypeContext()) { Console.WriteLine("Deleting all regions"); troutDashContext.road_types.RemoveRange(troutDashContext.road_types); troutDashContext.SaveChanges(); foreach (var roadType in roadTypes) { var dbRoadType = new road_type(); dbRoadType.description = roadType.name; dbRoadType.source = "0"; dbRoadType.type = roadType.type; troutDashContext.road_types.Add(dbRoadType); } troutDashContext.SaveChanges(); } }
private void ExportRestrictionRoutes() { using (var context = new MinnesotaShapeDataContext()) using (var troutDashContext = new TroutDashPrototypeContext()) { // clear out the old. Console.WriteLine("Caching minnesota restriction routes..."); var minnesota = troutDashContext.states.Single(s => s.short_name == "MN"); var routes = minnesota.restrictions.SelectMany(i => i.restrictionRoutes); troutDashContext.restriction_routes.RemoveRange(routes); Console.WriteLine("Deleting minnesota restriction routes..."); troutDashContext.SaveChanges(); _sequenceRestarter.RestartSequence("restriction_route_id_seq"); var restrictions = troutDashContext.restrictions.ToDictionary(i => i.source_id); var restrictionRoutes = context.strm_regsln3.ToList(); Console.WriteLine("Building minnesota restriction routes..."); foreach (var restrictionRoute in restrictionRoutes) { var route = new restriction_route(); route.Restriction = restrictions[restrictionRoute.new_reg.ToString()]; route.Geom = restrictionRoute.Geom_4326; route.source_id = restrictionRoute.gid.ToString(); troutDashContext.restriction_routes.Add(route); } Console.WriteLine("Saving minnesota restriction routes..."); troutDashContext.SaveChanges(); // TODO: MOVE THIS. Console.WriteLine("Saved minnesota restriction routes..."); } using (var context = new MinnesotaShapeDataContext()) using (var troutDashContext = new TroutDashPrototypeContext()) { var stuff = troutDashContext.restrictions.SelectMany(r => r.restrictionRoutes).Select(i => i.gid).ToList(); } }
public void ExportPubliclyAccessibleLandSections() { List <stream> streams = new List <stream>(); using (var troutDashContext = new TroutDashPrototypeContext()) { var minnesota = troutDashContext.states.Single(s => s.short_name == "MN"); streams = minnesota.streams.ToList(); Console.WriteLine("Clearing old entries"); troutDashContext.PalSection.RemoveRange( troutDashContext.PalSection.Where(i => i.Stream.state1.short_name == "MN")); troutDashContext.SaveChanges(); _sequenceRestarter.RestartSequence("publicly_accessible_land_section_id_seq"); } streams.AsParallel() .ForAll(route => { try { var kittleNumber = route.source_id; Console.WriteLine("Getting PAL for " + route.name); Parallel.Invoke( () => { using (var troutDashContext2 = new TroutDashPrototypeContext()) { var type = "Easement"; var easement = troutDashContext2.PalTypes.First(i => i.type == type); var easements = SaveEasements(easement, route, type, "mndnr_fisheries_acquisition").ToList(); troutDashContext2.PalSection.AddRange(easements); troutDashContext2.SaveChanges(); } }, () => { using (var troutDashContext2 = new TroutDashPrototypeContext()) { var type = "State Park"; var easement = troutDashContext2.PalTypes.First(i => i.type == type); var stateParks = SaveEasements(easement, route, "State Park", "dnr_stat_plan_areas_prk").ToList(); troutDashContext2.PalSection.AddRange(stateParks); troutDashContext2.SaveChanges(); } }, () => { using (var troutDashContext2 = new TroutDashPrototypeContext()) { var type = "WMA"; var easement = troutDashContext2.PalTypes.First(i => i.type == type); var wmas = SaveEasements(easement, route, "WMA", "dnr_wma_boundaries_pa") .ToList(); troutDashContext2.PalSection.AddRange(wmas); troutDashContext2.SaveChanges(); } }, () => { using (var troutDashContext2 = new TroutDashPrototypeContext()) { var type = "State Forest"; var easement = troutDashContext2.PalTypes.First(i => i.type == type); var stateForests = SaveEasements(easement, route, "State Forest", "state_forest_management_units") .ToList(); troutDashContext2.PalSection.AddRange(stateForests); troutDashContext2.SaveChanges(); } } ); } catch (Exception) { throw; } }); }
public void ExportPubliclyAccessibleLand() { using (var context = new MinnesotaShapeDataContext()) using (var troutDashContext = new TroutDashPrototypeContext()) { Console.WriteLine("Removing all publicly accessible land in minnesota"); var minnesota = troutDashContext.states.Single(s => s.short_name == "MN"); var oldPal = minnesota.PalTypes.ToList(); troutDashContext.PalTypes.RemoveRange(oldPal); troutDashContext.SaveChanges(); _sequenceRestarter.RestartSequence("publicly_accessible_land_type_id_seq"); // _sequenceRestarter.RestartSequence("publicly_accessible_land_section_id_seq"); _sequenceRestarter.RestartSequence("publicly_accessibly_land_gid_seq"); Console.WriteLine("Adding all ublicly accessible land in minnesota"); minnesota.PalTypes = new List <publicly_accessible_land_type> { new publicly_accessible_land_type { state = minnesota, description = "Wildlife Management Area", is_federal = false, type = "WMA" }, new publicly_accessible_land_type { state = minnesota, description = "State Parks", is_federal = false, type = "State Park", }, new publicly_accessible_land_type { state = minnesota, description = "Land Easement", is_federal = false, type = "Easement" }, new publicly_accessible_land_type { state = minnesota, description = "State Forest", is_federal = false, type = "State Forest" } }; troutDashContext.SaveChanges(); var easementType = troutDashContext.PalTypes.Single( i => i.state.gid == minnesota.gid && i.type == "Easement"); var accessableEasements = context.mndnr_fisheries_acquisition .Where(i => i.use_reg != mndnr_fisheries_acquisition.NoAccess) .ToList() //i.use_reg_type != use_reg_types.NoAccess) .Select(i => new publicly_accessible_land { state_gid = minnesota.gid, area_name = i.unit_name, pal_Id = easementType.id, shape_area = Convert.ToDecimal(i.OriginalGeometry.Area), Geom = i.Geom_4326 }).ToList(); Console.WriteLine("Loading easements"); troutDashContext.publicly_accessible_lands.AddRange(accessableEasements); var stateparkType = troutDashContext.PalTypes.Single( i => i.state.gid == minnesota.gid && i.type == "State Park"); var parks = context.dnr_stat_plan_areas_prk .ToList() .Select(p => new publicly_accessible_land { state_gid = minnesota.gid, area_name = p.area_name, pal_Id = stateparkType.id, shape_area = Convert.ToDecimal(p.OriginalGeometry.Area), Geom = p.Geom_4326 }); Console.WriteLine("Loading state parks"); troutDashContext.publicly_accessible_lands.AddRange(parks); var wmaType = troutDashContext.PalTypes.Single( i => i.state.gid == minnesota.gid && i.type == "WMA"); var wmas = context.dnr_wildlife_management_area_boundaries_publicly_accessible .ToList() .Select(i => new publicly_accessible_land { state_gid = minnesota.gid, Geom = i.Geom_4326, pal_Id = wmaType.id, area_name = i.unitname, shape_area = Convert.ToDecimal(i.OriginalGeometry.Area) }); Console.WriteLine("Loading wildlife management areas"); troutDashContext.publicly_accessible_lands.AddRange(wmas); var stateParks = context.state_forest_management_units .ToList() .Select(i => new publicly_accessible_land { state_gid = minnesota.gid, Geom = i.Geom_4326, pal_Id = wmaType.id, area_name = i.unit_name, shape_area = Convert.ToDecimal(i.OriginalGeometry.Area) }); troutDashContext.publicly_accessible_lands.AddRange(stateParks); Console.WriteLine("Saving publicly accessible land changes"); troutDashContext.SaveChanges(); } }
public void ExportStreams() { using (var context = new MinnesotaShapeDataContext()) using (var troutDashContext = new TroutDashPrototypeContext()) { Console.WriteLine("Deleting all streams in Minnesota"); var minnesota = troutDashContext.states.Single(s => s.short_name == "MN"); minnesota.streams.ToList().ForEach(s => troutDashContext.streams.Remove(s)); troutDashContext.SaveChanges(); _sequenceRestarter.RestartSequence("stream_gid_seq"); _sequenceRestarter.RestartSequence("trout_stream_section_gid_seq"); Console.WriteLine("Deleted all streams in Minnesota"); // gather ye trout streams. ILookup <string, trout_streams_minnesota> troutStreamSectionIds = context.trout_streams_minnesota.Where(ts => ts.trout_flag == 1).ToLookup(tss => tss.kittle_nbr); var badList = new List <trout_streams_minnesota>(); troutStreamSectionIds.AsParallel().ForAll(section => SaveStream(section, minnesota.Name, minnesota.gid, badList)); Console.WriteLine("Failures: "); badList.ForEach(b => Console.WriteLine(b.kittle_nam + " " + b.kittle_nbr)); troutDashContext.SaveChanges(); } using (var troutDashContext = new TroutDashPrototypeContext()) { var minnesota = troutDashContext.states.Single(s => s.short_name == "MN"); Console.WriteLine("Saving Metadata for stream... "); using (var writer = File.OpenText(StreamMetadataFileLocation)) { var csv = new CsvReader(writer); while (csv.Read()) { var record = csv.GetRecord <StreamSpeciesCsv>(); var id = record.Id; try { var stream = minnesota.streams.FirstOrDefault(s => s.source == id); if (stream == null) { continue; } Console.WriteLine(" " + stream.name + " | " + stream.source); stream.has_brook_trout = record.IsBrook ?? false; stream.has_brown_trout = record.IsBrown ?? false; stream.has_rainbow_trout = record.IsRainbow ?? false; stream.is_brook_trout_stocked = record.IsBrookStocked ?? false; stream.is_brown_trout_stocked = record.IsBrownStocked ?? false; stream.is_rainbow_trout_stocked = record.IsRainbowStocked ?? false; stream.status_mes = record.Status ?? String.Empty; stream.local_name = record.AltName ?? String.Empty; troutDashContext.SaveChanges(); } catch { throw; } } } Console.WriteLine("updating stream centroids..."); _centroidResetter.RestartSequence(); } }
public JsonExporter(TroutDashPrototypeContext context) { _context = context; }