public static OrbitRelation Parse(string text) { if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException("No relation specified!"); } var parts = text.Split(')'); if (parts.Length != 2) { throw new ArgumentException($"Relation should be specified with two orbits. Error in: '{text}'"); } var orbit1 = parts[0]; var orbit2 = parts[1]; if (string.IsNullOrWhiteSpace(orbit1)) { throw new ArgumentException($"Orbit 1 not specified. Error in: '{text}'"); } if (string.IsNullOrWhiteSpace(orbit2)) { throw new ArgumentException($"Orbit 2 not specified. Error in: '{text}'"); } var result = new OrbitRelation { OrbitName1 = orbit1, OrbitName2 = orbit2 }; return(result); }
public static OrbitMap LoadMap(string map) { var result = new OrbitMap(); using (StringReader reader = new StringReader(map)) { string line; while ((line = reader.ReadLine()) != null) { var relation = OrbitRelation.Parse(line); result.AddRelation(relation); } } return(result); }
private void AddRelation(OrbitRelation relation) { var orbit1 = GetOrbitByName(relation.OrbitName1); var orbit2 = GetOrbitByName(relation.OrbitName2); if (orbit1 == null) { orbit1 = AddOrbit(relation.OrbitName1, null); if (Root == null) { Root = orbit1; } //throw new Exception($"Can't find orbit 1 by name: '{relation.OrbitName1}'"); } if (orbit2 == null) { orbit2 = AddOrbit(relation.OrbitName2, orbit1); } else { orbit2.AddArround(orbit1); } //throw new Exception($"Orbit 2 already added. Orbit name: '{relation.OrbitName2}'"); }