public static void Main() { // Adding some paths to save in file Point3D path = new Point3D(1, 4, 7); Path current = new Path(); current.AddPath(path); path = new Point3D(1, 74, 78); current.AddPath(path); path = new Point3D(18, 14, 8); current.AddPath(path); path = new Point3D(100, 84, 47); current.AddPath(path); path = new Point3D(47, 94, 0); current.AddPath(path); PathStorage.SavePath(current); Console.WriteLine("The paths are saved in PathSave.txt"); // Uncomment the foreach cycle in PathStorage.cs to print the path readed from PathLoad.txt PathStorage.LoadPath(); }
public static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Console.WriteLine("Start point coordinates: ({0})\n", Point3D.StartPoint); Point3D secondPoint = new Point3D(50.05, 50, 5.555); Console.WriteLine("Second point coordinates: ({0})\n", secondPoint); Console.WriteLine("The distance between start and second point: {0:F2}\n", DistanceCalculator.CalculateDistance(secondPoint, Point3D.StartPoint)); Path path = new Path(); path.AddPath(Point3D.StartPoint); // Adding paths path.AddPath(secondPoint); path.AddPath(new Point3D(-2, 22, 0.22)); Console.WriteLine(path); Console.WriteLine("Writing the upper coordinates to 'test.txt' file\n"); PathStorage.SavePath(path, @"..\..\test.txt"); Console.WriteLine("Read 'test.txt' file:"); Path testRead = PathStorage.LoadPath(@"..\..\test.txt"); Console.WriteLine(testRead); }
public static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Point3D firstPoint = new Point3D(1, 20, 30); Console.WriteLine(firstPoint); Point3D secondPoint = new Point3D(5, 10, 35); Console.WriteLine(secondPoint); Point3D thirdPoint = Point3D.Start0; Console.WriteLine(thirdPoint); double distance = Distance.CalculateDistance(firstPoint, secondPoint); Console.WriteLine(distance); Path pathList = new Path(); pathList.AddPath(firstPoint); pathList.AddPath(secondPoint); //Console.WriteLine(pathList); PathStorage.WritePath(pathList, "..\\..\\test.txt"); PathStorage.ReadPath("..\\..\\test.txt"); Console.WriteLine(PathStorage.ReadPath("..\\..\\test.txt")); }
public static void LoadPath() { StreamReader loadPath = new StreamReader(@"..\..\PathLoad.txt"); Path currentPath = new Path(); using (loadPath) { string line = loadPath.ReadLine(); while (line != null) { string[] coordinates = line.Split(' '); Point3D newPoint = new Point3D(int.Parse(coordinates[0]), int.Parse(coordinates[1]), int.Parse(coordinates[2])); currentPath.AddPath(newPoint); line = loadPath.ReadLine(); } } //foreach (var item in currentPath.sequenceOfPoints) //{ // Console.WriteLine(item); //} }
public static Path ReadPath(string filePath) { Path pathList = new Path(); StreamReader reader = new StreamReader(filePath); using (reader) { while (reader.EndOfStream == false) { string line = reader.ReadLine(); string[] coord = line.Split(new char[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToArray(); Point3D point = new Point3D(int.Parse(coord[2]), int.Parse(coord[5]), int.Parse(coord[8])); pathList.AddPath(point); } } return(pathList); }
public static Path LoadPath(string filePathName) { Path loadedPaths = new Path(); try { using (StreamReader reader = new StreamReader(filePathName)) { string line = reader.ReadLine(); while (reader.EndOfStream != true) { line = line.Substring(15); double[] points = line.Split(new char[] { ' ', ',', '(', ')' }, StringSplitOptions.RemoveEmptyEntries) .Select(double.Parse) .ToArray(); loadedPaths.AddPath(new Point3D(points[0], points[1], points[2])); line = reader.ReadLine(); } } } catch (FileNotFoundException fnfe) { Console.WriteLine(fnfe.Message); } catch (DirectoryNotFoundException dnf) { Console.WriteLine(dnf.Message); } catch (UnauthorizedAccessException uae) { Console.WriteLine(uae.Message); } catch (IOException ioe) { Console.WriteLine(ioe.Message); } return(loadedPaths); }