public static void SavePathToATextFile(Path3D path) { using (var writer = new StreamWriter("../../path.txt")) { writer.WriteLine(path.ToString()); } }
public static void Main() { double[] point1 = new double[] { 1.0, 2.0, 3.0 }; double[] point2 = new double[] { 4.0, 5.0, 6.0 }; double[] point3 = new double[] { 7.0, 8.0, 9.0 }; double[] point4 = new double[] { 10.0, 11.0, 12.0 }; List <double[]> points = new List <double[]>(); points.Add(point1); points.Add(point2); points.Add(point3); points.Add(point4); StringBuilder sb = new StringBuilder(); foreach (var point in points) { sb.Append($"{{{string.Join(", ", point)}}} "); } string sequence = sb.ToString(); Path3D path3D = new Path3D(sequence); Storage.SavePath(path3D); Storage.LoadPath(); }
public static Path3D LoadPointCoordinates(string path) { Path3D points = new Path3D(); using (var fileSource = new StreamReader(path, Encoding.UTF8)) { string line = fileSource.ReadLine(); while (line != null) { int[] pointCordinates = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries). Select(int.Parse).ToArray(); if (pointCordinates.Length != 3) { throw new ArgumentException(); } Point3D point = new Point3D(pointCordinates[0], pointCordinates[1], pointCordinates[2]); points.AddPoints(point); line = Console.ReadLine(); } } return points; }
public static void SavePath(Path3D path) { using (StreamWriter writer = new StreamWriter("paths.txt", true)) { writer.WriteLine(path); } }
public static Path3D LoadPath(string fileName) { List <Point3D> points = new List <Point3D>(); Path3D path; try { StreamReader sr = new StreamReader(fileName); using (sr) { String line = sr.ReadLine(); while (line != null) { double[] coordinates = PointExtractor(line); Point3D p = new Point3D(coordinates[0], coordinates[1], coordinates[2]); points.Add(p); line = sr.ReadLine(); } } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } path = new Path3D(points); return(path); }
public static void Main() { Point3D p1 = new Point3D(45, -5, 23); Point3D p2 = new Point3D(-25, 78, 115); Point3D p3 = new Point3D(2, 56, -8); List <Point3D> points1 = new List <Point3D> { p1, p2, p3 }; List <Point3D> points2 = new List <Point3D> { p2, p3 }; List <Point3D> points3 = new List <Point3D> { p1, p3 }; Path3D path1 = new Path3D(points1); Path3D path2 = new Path3D(points2); Path3D path3 = new Path3D(points3); //Console.WriteLine(path1); Storage.SavePath(@"C:\Users\alex\OneDrive\Документи\Visual Studio 2015\Projects\OOP-Static-Members-and-Namespaces\03. Paths\paths.txt", path1, path2, path3); Path3D newPath = Storage.LoadPath(@"C:\Users\alex\OneDrive\Документи\Visual Studio 2015\Projects\OOP-Static-Members-and-Namespaces\03. PathspathToLoad.txt"); Storage.SavePath(@"C: \Users\alex\OneDrive\Документи\Visual Studio 2015\Projects\OOP - Static - Members - and - Namespaces\03.Paths\paths.txt", newPath); Console.WriteLine(newPath); }
public static Path3D LoadPathFromFile(string filepath) { Path3D path = new Path3D(); using (StreamReader reader = new StreamReader(filepath)) { string line = reader.ReadLine(); const string PointPattern = @"[xyz=:\-\s](\d+(?:(?:\.|,)\d+)*)"; while (line != null) { MatchCollection matches = Regex.Matches(line, PointPattern); if (matches.Count == 3) { double x = double.Parse(matches[0].Groups[1].Value); double y = double.Parse(matches[1].Groups[1].Value); double z = double.Parse(matches[2].Groups[1].Value); Point3D point = new Point3D(x, y, z); path.AddPoints(point); } line = reader.ReadLine(); } } return(path); }
static void Main(string[] args) { List<Point3D> points = new List<Point3D>(); points.Add(new Point3D(2.2, 2.3, 1.8)); points.Add(new Point3D(3.2, 9.5, 5.8)); points.Add(new Point3D(2.3, 4.1, 3.2)); points.Add(new Point3D(4.2, 2.5, 6.6)); points.Add(new Point3D(2.4, 4.6, 1.1)); points.Add(new Point3D(5.2, 4.3, 7.8)); points.Add(new Point3D(2.5, 7.5, 3.2)); List<Point3D> morePoints = new List<Point3D>(); morePoints.Add(new Point3D(5.4, 2.5, 1.8)); morePoints.Add(new Point3D(5.2, 4.3, 7.8)); morePoints.Add(new Point3D(2.4, 4.6, 1.1)); morePoints.Add(new Point3D(2.3, 4.1, 3.2)); Path3D myPath = new Path3D("My Path", points); Path3D yourPath = new Path3D("Your Path", morePoints); Storage.SavePath("MyPath", myPath); Storage.SavePath("YourPath", yourPath); Path3D loadedPath = Storage.LoadPath("YourPath"); Console.WriteLine(myPath); Console.WriteLine(loadedPath); }
public static Path3D LoadPath(string fileName) { List<Point3D> points = new List<Point3D>(); Path3D path; try { StreamReader sr = new StreamReader(fileName); using (sr) { String line = sr.ReadLine(); while (line != null) { double[] coordinates = PointExtractor(line); Point3D p = new Point3D(coordinates[0], coordinates[1], coordinates[2]); points.Add(p); line = sr.ReadLine(); } } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } path = new Path3D(points); return path; }
static void Main(string[] args) { List <Point3D> points = new List <Point3D>(); points.Add(new Point3D(2.2, 2.3, 1.8)); points.Add(new Point3D(3.2, 9.5, 5.8)); points.Add(new Point3D(2.3, 4.1, 3.2)); points.Add(new Point3D(4.2, 2.5, 6.6)); points.Add(new Point3D(2.4, 4.6, 1.1)); points.Add(new Point3D(5.2, 4.3, 7.8)); points.Add(new Point3D(2.5, 7.5, 3.2)); List <Point3D> morePoints = new List <Point3D>(); morePoints.Add(new Point3D(5.4, 2.5, 1.8)); morePoints.Add(new Point3D(5.2, 4.3, 7.8)); morePoints.Add(new Point3D(2.4, 4.6, 1.1)); morePoints.Add(new Point3D(2.3, 4.1, 3.2)); Path3D myPath = new Path3D("My Path", points); Path3D yourPath = new Path3D("Your Path", morePoints); Storage.SavePath("MyPath", myPath); Storage.SavePath("YourPath", yourPath); Path3D loadedPath = Storage.LoadPath("YourPath"); Console.WriteLine(myPath); Console.WriteLine(loadedPath); }
public static Path3D LoadPathFromFile(string filepath) { Path3D path = new Path3D(); using (StreamReader reader = new StreamReader(filepath)) { string line = reader.ReadLine(); const string PointPattern = @"[xyz=:\-\s](\d+(?:(?:\.|,)\d+)*)"; while (line != null) { MatchCollection matches = Regex.Matches(line, PointPattern); if (matches.Count == 3) { double x = double.Parse(matches[0].Groups[1].Value); double y = double.Parse(matches[1].Groups[1].Value); double z = double.Parse(matches[2].Groups[1].Value); Point3D point = new Point3D(x, y, z); path.AddPoints(point); } line = reader.ReadLine(); } } return path; }
// Creating new file in "../bin/Debug" and saving the points // in the selected path. public static void SavePath(string fileName, Path3D pathToSave) { FileStream fs = null; try { fs = new FileStream(fileName, FileMode.CreateNew); StreamWriter sw = new StreamWriter(fs); using (sw) { sw.WriteLine(pathToSave.PathName); foreach (var point in pathToSave.Points) { sw.WriteLine(point); } } } catch (IOException e) { Console.WriteLine(e.Message); Console.WriteLine(); } finally { if (fs != null) { fs.Dispose(); } } }
public static void LoadPathFromFile(string inputFileLocation) { StreamReader reader = null; StreamWriter writer = null; // open input (current) file try { reader = new StreamReader(inputFileLocation, Encoding.GetEncoding("windows-1251")); } catch (FileNotFoundException) { Console.WriteLine("File not found."); } // create output file try { writer = new StreamWriter(@"..\..\Paths.txt"); } catch (IOException) { Console.WriteLine("Unable to create output file."); } int counter = 0; string s; using (reader) using (writer) { while (true) { s = reader.ReadLine(); if (s == null) { break; } // check for 3D paths var pointsInPath = (from Match match in Regex.Matches(s, PointMatcher) let xCoordinate = double.Parse(match.Groups[1].Value) let yCoordinate = double.Parse(match.Groups[2].Value) let zCoordinate = double.Parse(match.Groups[3].Value) select new Point3D(xCoordinate, yCoordinate, zCoordinate)).ToList(); if (pointsInPath.Count <= 0) { continue; } // save 3D paths to a new Paths.txt file counter++; var pathFromFile = new Path3D(pointsInPath); writer.WriteLine("Path {0}: {1}", counter, pathFromFile); } } }
public static void SavePath(string destinatio, Path3D path) { using (StreamWriter writer = new StreamWriter(destinatio)) { XmlSerializer serialized = new XmlSerializer(path.GetType()); serialized.Serialize(writer, path); } }
public static void SavePath(Path3D sequence) { StreamWriter savePath = new StreamWriter(filePath); using (savePath) { savePath.WriteLine(sequence); } }
public static void Save(string file, Path3D path) { using (StreamWriter writer = new StreamWriter("../../" + file + ".txt")) { foreach (var currPoint in path.Points) { writer.WriteLine("({0}, {1}, {2})", currPoint.X, currPoint.Y, currPoint.Z); } } }
public static void SavePath(string destination, Path3D path) { using (StreamWriter writer = new StreamWriter(destination)) { foreach (var point in path.Points) { writer.WriteLine(String.Format("[{0}, {1}, {2}]", point.X, point.Y, point.Z)); } } }
static void Main(string[] args) { var path = new Path3D( new Point3D(1, 2, 3), new Point3D(2, 3, 4), new Point3D(3, 4, 5)); Storage.SavePath(path); Console.WriteLine(Storage.LoadPaths()[0].Points[0]); }
public static void LoadPathFromFile(string inputFileLocation) { StreamReader reader = null; StreamWriter writer = null; // open input (current) file try { reader = new StreamReader(inputFileLocation, Encoding.GetEncoding("windows-1251")); } catch (FileNotFoundException) { Console.WriteLine("File not found."); } // create output file try { writer = new StreamWriter(@"..\..\Paths.txt"); } catch (IOException) { Console.WriteLine("Unable to create output file."); } int counter = 0; string s; using (reader) using (writer) { while (true) { s = reader.ReadLine(); if (s == null) { break; } // check for 3D paths var pointsInPath = (from Match match in Regex.Matches(s, PointMatcher) let xCoordinate = double.Parse(match.Groups[1].Value) let yCoordinate = double.Parse(match.Groups[2].Value) let zCoordinate = double.Parse(match.Groups[3].Value) select new Point3D(xCoordinate, yCoordinate, zCoordinate)).ToList(); if (pointsInPath.Count <= 0) continue; // save 3D paths to a new Paths.txt file counter++; var pathFromFile = new Path3D(pointsInPath); writer.WriteLine("Path {0}: {1}", counter, pathFromFile); } } }
static void Main() { var paths = new Path3D( new Point3D(3, 3, 3), new Point3D(5, 6, 8), new Point3D(-3, 4, 21) ); Storage.Save(paths); Storage.Load(); }
public static void SavePath(Path3D path, string fileName) { using (StreamWriter sw = new StreamWriter(fileName)) { foreach (var point in path.Points) { string output = $"{point.X}|{point.Y}|{point.Z}"; sw.WriteLine(output); } } }
static void Main(string[] args) { var path = new Path3D( new Point3D.Point3D(1, 2, 3), new Point3D.Point3D(2, 4, 5), new Point3D.Point3D(3, 6, 7), new Point3D.Point3D(0,0,0)); Storage.SavePath(file, path); Path3D path2 = Storage.LoadPath(file); Console.WriteLine(string.Join(Environment.NewLine,path2.Path)); }
static void Main(string[] args) { const string path = "path.txt"; Path3D pointList = new Path3D(); try { Console.WriteLine("How may points you want to add in your file: "); int number = int.Parse(Console.ReadLine()); if (number < 0) { throw new ArgumentOutOfRangeException(); } for (int i = 1; i <= number; i++) { Console.WriteLine("Enter the cordinates of your [{0}] point separated by a space: ", i); int[] pointCordinates = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); Storage.SavePointCoordinates(path, pointCordinates); } Console.WriteLine(); Console.WriteLine("Now I will read the cordinates of your point from the file"); pointList = Storage.LoadPointCoordinates(path); Console.WriteLine(pointList); } catch (FormatException) { Console.Error.WriteLine("You must add a number"); } catch (OverflowException) { Console.Error.WriteLine("You must add a valid integer number"); } catch (ArgumentOutOfRangeException) { Console.Error.WriteLine("You must add a number"); } catch (ArgumentException) { Console.Error.WriteLine("You must add a number"); } }
public static void Main(string[] args) { var path = new Path3D( new Point3D(1, 2, 3), new Point3D(4, 5, 8), new Point3D(0, 0, 0), new Point3D(3, 12, 13)); Storage.SavePath(File, path); Path3D path2 = Storage.LoadPath(File); Console.WriteLine(string.Join(Environment.NewLine, path2.Path)); }
static void Main(string[] args) { try { Point3D point1 = new Point3D(0, 5, 1); Point3D point2 = new Point3D(-3, 20, 0); Path3D path = new Path3D(point1, point2); Storage.SavePathToFile("../../path.txt", path.ToString()); Console.WriteLine("Load from file:\n" + Storage.LoadPathFromFile("../../path.txt")); } catch (Exception) { throw; } }
static void Main() { Point3D p1 = new Point3D(4.6, 6.4, 36); Point3D p2 = new Point3D(6.2, 5.32, 64.2); Point3D p3 = new Point3D(19.6, 36.4, 23.5); Path3D path = new Path3D(p1, p2, p3); Storage.SavePath("MyPath.path", path); Path3D loaded = Storage.LoadPath("MyPath.path"); foreach (var point in loaded.Points) { Console.WriteLine(point); } }
static void Main() { Path3D path = new Path3D(); Point3D point = new Point3D(2, 5.2, 9.1); path.Add(point); path.Add(Point3D.StartingPointOfCoordSystem); path.Add(new Point3D(2.4, 1.2, 5.3)); Console.WriteLine("Path saved to a file"); Console.WriteLine(path); Storage.SavePathToATextFile(path); var newPath = Storage.LoadPathFromAtextFile("../../fileWithAPath.txt"); Path3D pathLoadedFromFile = newPath; Console.WriteLine("Path loaded from file: "); Console.WriteLine(newPath.ToString()); }
public static void SavePathToFile(Path3D path, string file) { try { using (StreamWriter writer = new StreamWriter(file, true)) { foreach (var point in path.Path) { writer.WriteLine(point.X + "|" + point.Y + "|" + point.Z); } } } catch (Exception e) { Console.WriteLine("The file could not be written to:"); Console.WriteLine(e.Message); } }
public static Path3D LoadPath(string fileName) { Path3D result = new Path3D(); using (StreamReader sr = new StreamReader(fileName)) { string line = string.Empty; while ((line = sr.ReadLine()) != null) { double[] numbers = new double[3]; Point3D point = new Point3D(); numbers = line.Split('|').Select(double.Parse).ToArray(); point.X = numbers[0]; point.Y = numbers[1]; point.Z = numbers[2]; result.Points.Add(point); } } return result; }
public static void Main() { Point3D p1 = new Point3D(45, -5, 23); Point3D p2 = new Point3D(-25, 78, 115); Point3D p3 = new Point3D(2, 56, -8); List<Point3D> points1 = new List<Point3D> { p1, p2, p3 }; List<Point3D> points2 = new List<Point3D> { p2, p3 }; List<Point3D> points3 = new List<Point3D> { p1, p3 }; Path3D path1 = new Path3D(points1); Path3D path2 = new Path3D(points2); Path3D path3 = new Path3D(points3); //Console.WriteLine(path1); Storage.SavePath(@"C:\Users\alex\OneDrive\Документи\Visual Studio 2015\Projects\OOP-Static-Members-and-Namespaces\03. Paths\paths.txt", path1, path2, path3); Path3D newPath = Storage.LoadPath(@"C:\Users\alex\OneDrive\Документи\Visual Studio 2015\Projects\OOP-Static-Members-and-Namespaces\03. PathspathToLoad.txt"); Storage.SavePath(@"C: \Users\alex\OneDrive\Документи\Visual Studio 2015\Projects\OOP - Static - Members - and - Namespaces\03.Paths\paths.txt", newPath); Console.WriteLine(newPath); }
public static Path3D Load(string file) { Path3D loadedPath = new Path3D(); using (StreamReader reader = new StreamReader("../../" + file + ".txt")) { string line = reader.ReadLine(); while (line != null) { string[] currLine = line.Split(' ', '(', ')', ','); int x = int.Parse(currLine[1]); int y = int.Parse(currLine[3]); int z = int.Parse(currLine[5]); loadedPath.Add(new Point3D(x, y, z)); line = reader.ReadLine(); } } return(loadedPath); }
static void Main() { try { Point3D point1 = new Point3D(1, 5, 24); Point3D point2 = new Point3D(0, -12, 3); Point3D point3 = new Point3D(1, 5, 3); Path3D path = new Path3D(point1, point2, point3); Console.WriteLine(path); Storage.SavePathToFile("../../path.txt", path.ToString()); Console.WriteLine("Load from file:\n" + Storage.LoadPathFromFile("../../path.txt")); } catch (FileNotFoundException) { Console.Error.WriteLine("Can not find file!"); } catch (IOException) { Console.Error.WriteLine("Can not open the file!"); } }
public static Path3D LoadPathFromAtextFile(string filePath) { Path3D path = new Path3D(); using (var reader = new StreamReader(filePath)) { string line = reader.ReadLine(); string pattern = @"X: (\-?[0-9]+\.?[0-9]*), Y: (\-?[0-9]+\.?[0-9]*), Z: (\-?[0-9]+\.?[0-9]*)"; Regex regex = new Regex(pattern); while (line != null) { Match match = regex.Match(line); if (match.Success) { Point3D point = new Point3D(double.Parse(match.Groups[1].ToString()), double.Parse(match.Groups[2].ToString()), double.Parse(match.Groups[3].ToString())); path.Add(point); } line = reader.ReadLine(); } } return(path); }
static void Main(string[] args) { Path3D points = new Path3D(); var firsPoint = new Point3D(5, 6, 7); var secondPoint = new Point3D(12, 7, 9); var thirdPoint = new Point3D(3, 32, 15); var fourthPoint = new Point3D(35, 68, 14); var fifthPoint = new Point3D(45, 61, 93); points.Add(firsPoint); points.Add(secondPoint); points.Add(thirdPoint); points.Add(fourthPoint); points.Add(fifthPoint); Storage.Save("exportedPoints", points); Path3D loadedPoints = Storage.Load("exportedPoints"); foreach (var point in loadedPoints.Points) { Console.WriteLine(point); } }
public static void LoadPathFromFile(Path3D path, string file) { string line; string[] input; try { using (StreamReader sr = new StreamReader(file)) { while((line = sr.ReadLine()) != null) { input = line.Split('|'); path.AddPoint(new Point3D(Convert.ToDouble(input[0]), Convert.ToDouble(input[1]), Convert.ToDouble(input[2]))); } } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } }
public static void Save(Path3D path) { File.WriteAllText(FilePath, path.ToString()); Console.WriteLine("File ({0}) saved.", FileName); }