public void TestSerializeSingleCityWithValues() { var c = new City("Aarau", "Switzerland", 10, 1.1, 2.2); var stream = new StringWriter(); var writer = new SimpleObjectWriter(stream); writer.Next(c); var result = stream.ToString(); Assert.AreEqual(CityWithValues, result); }
static void Main(string[] args) { var c = new City("Aarau", "Switzerland", 10, 1.1, 2.2); //Console.WriteLine(c.Location.GetType()); var stream = new StringWriter(); SimpleObjectWriter w = new SimpleObjectWriter(stream); w.Next(c); var objstr = stream.ToString(); Console.Write(objstr + "\r\n"); var stream2 = new StringReader(objstr); SimpleObjectReader r = new SimpleObjectReader(stream2); var city = r.Next() as City; Console.WriteLine(city.Name); Console.WriteLine(city.Country); Console.WriteLine(city.Population); Console.WriteLine(city.Location); Console.WriteLine(city.Location.Name); Console.WriteLine(city.Location.Latitude); Console.WriteLine(city.Location.Longitude); Console.Write("Welcome to RoutePlanner {0}\n", Assembly.GetExecutingAssembly().GetName().Version); var wayPoint = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312); //Console.WriteLine("{0}: {1}/{2}", wayPoint.Name, wayPoint.Latitude, wayPoint.Longitude); Console.WriteLine(wayPoint); wayPoint.Name = ""; Console.WriteLine(wayPoint); wayPoint.Name = null; Console.WriteLine(wayPoint); var cities = new Cities(); Console.WriteLine(cities.ReadCities(@"data\citiesTestDataLab3.txt")); var routes = new Routes(cities); var count = routes.ReadRoutes(@"data\linksTestDataLab3.txt"); var citiesError = new Cities(); Console.WriteLine(cities.ReadCities(@"data\citiesTestDataLab253.txt")); Console.ReadKey(); }
public void TestSerializeMultCitiesWithValues() { const string expectedString1 = "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\nName=\"Aarau\"\r\nCountry=\"Switzerland\"\r\nPopulation=10\r\nLocation is a nested object...\r\nInstance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\nName=\"Aarau\"\r\nLongitude=2.2\r\nLatitude=1.1\r\nEnd of instance\r\nEnd of instance\r\n"; const string expectedString2 = "Instance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.City\r\nName=\"Bern\"\r\nCountry=\"Switzerland\"\r\nPopulation=10\r\nLocation is a nested object...\r\nInstance of Fhnw.Ecnf.RoutePlanner.RoutePlannerLib.WayPoint\r\nName=\"Bern\"\r\nLongitude=2.2\r\nLatitude=1.1\r\nEnd of instance\r\nEnd of instance\r\n"; const string expectedString = expectedString1 + expectedString2; var c1 = new City("Aarau", "Switzerland", 10, 1.1, 2.2); var c2 = new City("Bern", "Switzerland", 10, 1.1, 2.2); var stream = new StringWriter(); var writer = new SimpleObjectWriter(stream); writer.Next(c1); var result = stream.ToString(); Assert.AreEqual(expectedString1, result); // write second city writer.Next(c2); // result is expected to contain both cities result = stream.ToString(); Assert.AreEqual(expectedString, result); }
static void Main(string[] args) { Version version = Assembly.GetEntryAssembly().GetName().Version; Console.WriteLine("Welcome to RoutePlanner ({0})", version); WayPoint wayPoint = new WayPoint("Windisch", 47.479319847061966, 8.212966918945312); Console.WriteLine(wayPoint.ToString()); WayPoint wpBern = new WayPoint("Bern", 46.9472221, 7.451202500000022); WayPoint wpTripolis = new WayPoint("Tripolis", 59.86062519999999, 17.650885199999948); Console.WriteLine("Distanz Bern-Tripolis: {0}km", wpBern.Distance(wpTripolis)); City cBern = new City("Bern", "Schweiz", 75000, 47.479319847061966, 8.212966918945312); City c0 = new City("Mumbai", "India", 12383146, 18.96, 72.82); string serializedCity = string.Empty; using (StringWriter outstream = new StringWriter()) { SimpleObjectWriter writer = new SimpleObjectWriter(outstream); writer.Next(cBern); serializedCity = outstream.ToString(); } Console.WriteLine(serializedCity); using(StringReader inStream = new StringReader(serializedCity)) { SimpleObjectReader reader = new SimpleObjectReader(inStream); object o = reader.Next(); } WayPoint wp = c0.Location; Cities c = new Cities(); c.ReadCities("citiesTestDataLab2.txt"); c.FindNeighbours(wp,2000); c.ReadCities("citiesTestDataLab2.txt"); var routes = new RoutesDijkstra(c); var reqWatch = new RouteRequestWatcher(); routes.RouteRequestEvent += reqWatch.LogRouteRequests; routes.FindShortestRouteBetween("Mumbai", "India", TransportModes.Rail); routes.FindShortestRouteBetween("Mumbai", "India", TransportModes.Rail); routes.FindShortestRouteBetween("India", "Mumbai", TransportModes.Rail); Console.WriteLine("City found: {0}", c.FindCity("Mumbai").Name); c.ReadCities("citiesTestDataLab4.txt"); Routes r = new RoutesDijkstra(c); r.RouteRequestEvent += reqWatch.LogRouteRequests; r.ReadRoutes("linksTestDataLab4.txt"); List<Link> l = r.FindShortestRouteBetween("Zürich", "Winterthur", TransportModes.Rail); foreach (Link link in l) { Console.WriteLine("from {0} to {1} in {2}", link.FromCity.Name, link.ToCity.Name, link.Distance); } Console.ReadKey(); City zurich = c.FindCity("Zürich"); City winterthur = c.FindCity("Winterthur"); ExcelExchange export = new ExcelExchange(); export.WriteToFile("Test.xls", zurich, winterthur,l); }