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); }
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; }
public static Path3D LoadPathsFromFile(string inputPath) { Path3D path; List <Point3D> points = new List <Point3D>(); try { StreamReader sr = new StreamReader(inputPath); using (sr) { string line = sr.ReadLine(); while (line != null) { string sub = line.Substring(0, 1); if (sub == "x") { double[] pathPoints = getPathPoints(line); Point3D point = new Point3D(pathPoints[0], pathPoints[1], pathPoints[2]); points.Add(point); line = sr.ReadLine(); } else { line = sr.ReadLine(); } } } } catch { Console.WriteLine("No read file!"); } path = new Path3D(points); return(path); }
static void Main(string[] args) { Point3D p1 = new Point3D(2.2, 4.3, -1); Point3D p2 = new Point3D(-2.2, 1.3, -4); Point3D p3 = new Point3D(3.2, -1.3, 2.2); Point3D p4 = new Point3D(1, -1, 0.2); List<Point3D> points1 = new List<Point3D> { p1, p2, p3, p4 }; List<Point3D> points2 = new List<Point3D> { p1, p2, p3 }; List<Point3D> points3 = new List<Point3D> { p2, p3, p4 }; List<Point3D> points4 = new List<Point3D> { p1, p4 }; Path3D path1 = new Path3D(points1); Path3D path2 = new Path3D(points2); Path3D path3 = new Path3D(points3); Path3D path4 = new Path3D(points4); Storage.SavePath("../../paths1.txt", path1); Storage.SavePath("../../paths2.txt", path2); Storage.SavePath("../../paths3.txt", path3); Storage.SavePath("../../paths4.txt", path4); Path3D Storagepath1 = Storage.LoadPathsFromFile("../../paths1.txt"); Console.WriteLine(Storagepath1.ToString()); Path3D Storagepath2 = Storage.LoadPathsFromFile("../../paths2.txt"); Console.WriteLine(Storagepath2.ToString()); Path3D Storagepath3 = Storage.LoadPathsFromFile("../../paths3.txt"); Console.WriteLine(Storagepath3.ToString()); Path3D Storagepath4 = Storage.LoadPathsFromFile("../../paths4.txt"); Console.WriteLine(Storagepath4.ToString()); }
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 path, string filename) { using (var writer = new StreamWriter(filename)) { foreach (var point in path.Path) { writer.WriteLine("{0} {1} {2}", point.X, point.Y, point.Z); } } }
static void Main() { var path = new Path3D( new Point3D(1, 2, 3), new Point3D(4, 5, 6), new Point3D(7, 8, 9)); Storage.SavePath(path, File); Path3D pathLoaded = Storage.LoadPath(File); Console.WriteLine(string.Join(Environment.NewLine, pathLoaded.Path)); }
static void Main() { var path = new Path3D( new Point3D(1, 2, 3), new Point3D(4, 5, 6), new Point3D(7, 8, 9), new Point3D(0.3, 0.77, 12.44)); Storage.SavePath(File, path); Path3D secondPath = Storage.LoadPath(File); Console.WriteLine(string.Join(Environment.NewLine,secondPath.Path)); }
static void Main() { var path = new Path3D( new Point3D(1, 2, 3), new Point3D(4, 5, 6), new Point3D(7, 8, 9), new Point3D(0.3, 0.77, 12.44)); Storage.SavePath(File, path); Path3D secondPath = Storage.LoadPath(File); Console.WriteLine(string.Join(Environment.NewLine, secondPath.Path)); }
static void Main(string[] args) { Path3D path = new Path3D(new Point3D(4.6, 7.3, 5), new Point3D(1.4, 2.65, 4.5), new Point3D(10.45, 3.3, 5.9), new Point3D(2.6, 16.4, 20.5)); Storage.SavePath(path, filename); Path3D pathFromFile = Storage.LoadPath(filename); foreach (var point in pathFromFile.Path) { Console.WriteLine(point); } }
static void Main(string[] args) { try { Point3D point1 = new Point3D(10, 3, 1); Point3D point2 = new Point3D(5, 15, 3); Path3D path = new Path3D(point1, point2); Storage.SavePathToFile("D:\\SoftUni\\Fundamental level\\OOP\\2.Статични членове и пространства от имена\\Домашни\\Static Members and Namespaces\\path.txt", path.ToString()); Console.WriteLine("Load from file:\n" + Storage.LoadPathFromFile("D:\\SoftUni\\Fundamental level\\OOP\\2.Статични членове и пространства от имена\\Домашни\\Static Members and Namespaces\\path.txt")); } catch (Exception) { throw; } }
static void Main(string[] args) { try { Point3D point1 = new Point3D(1, 2, 3); Point3D point2 = new Point3D(-3, 4, 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; } }
public static Path3D LoadPath(string filename) { Path3D loadedPath = new Path3D(); using (var reader = new StreamReader(filename)) { string line = reader.ReadLine(); while (line != null) { double[] coordinates = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(double.Parse).ToArray(); loadedPath.Path.Add(new Point3D(coordinates[0], coordinates[1], coordinates[2])); line = reader.ReadLine(); } } return loadedPath; }