private void AddDams(List <Reach> reaches, List <DamTableRow> damTable)
        {
            foreach (var reach in reaches)
            {
                foreach (var node in reach.Nodes)
                {
                    DamTableRow located = null;
                    foreach (var dam in damTable)
                    {
                        if (!node.Location.Match(dam.Location, 10))
                        {
                            continue;
                        }
                        node.Dam     = new Dam(dam);
                        reach.HasDam = true;
                        located      = dam;
                        break;
                    }

                    if (located != null)
                    {
                        damTable.Remove(located);
                    }
                }
            }
            if (damTable.Count != 0)
            {
                Trace.WriteLine($"Error: dam table should be empty {String.Join(":", damTable)}");
            }
        }
Esempio n. 2
0
 public Dam(DamTableRow row)
 {
     Id          = row.Id;
     Name        = row.Name;
     Passability = row.Passability;
     OnDeserialized();
     Location.Longitude = row.Location.Longitude;
     Location.Latitude  = row.Location.Latitude;
     Location.Symbol    = Location.MapSymbol.X;
     Location.Color     = Color.DarkRed;
 }
        public static List <DamTableRow> Create(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new ArgumentException($"File {filename} not found.");
            }
            try
            {
                var damTable = new List <DamTableRow>();
                using (var stream = new FileStream(filename, FileMode.Open))
                {
                    using (var reader = new CsvReader(new StreamReader(stream, Encoding.UTF8)))
                    {
                        reader.Read();
                        // Id, X, Y, Name, P
                        while (reader.Read())
                        {
                            var row = new DamTableRow
                            {
                                Id       = reader.GetField <int>(0),
                                Location = new Location
                                {
                                    Longitude = reader.GetField <Double>(1),
                                    Latitude  = reader.GetField <Double>(2)
                                },
                            };
                            row.Name        = reader.TryGetField <string>(3, out var name) ? name : row.Id.ToString();
                            row.Passability = reader.TryGetField <Double>(4, out var pass) ? pass : 0.5;
                            damTable.Add(row);
                        }
                    }
                }

                return(damTable);
            }
            catch (Exception)
            {
                throw new ArgumentException($"Dam file {filename} not in proper format or in use by another application.");
            }
        }