/// <summary> /// Opens saved canvas /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenCanvas(object sender, ExecutedRoutedEventArgs e) { try { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "Text file (*.xml)|*.xml"; dialog.ShowDialog(); if (dialog.FileName != string.Empty) { NewCanvas(sender, e); string[] args = dialog.FileName.Split('\\'); string title = args[args.Length - 1]; Title = title; string fullPath = System.IO.Path.GetFullPath(dialog.FileName); var pol = service.DeserializeAll(fullPath); polygons.Clear(); foreach (var polygon in pol) { polygons.Add(polygon); MainCanvas.Children.Add(polygon); polygonesList.Command = new ShapesCommand(); } } } catch (Exception ex) { throw new ArgumentException(ex.ToString()); } polygonesList.Command = new ShapesCommand(); }
public void PolygonService_SerializeAll_DeseriallizeAll_Test() { Polygon myPolygon = new Polygon(); myPolygon.Stroke = Brushes.Black; myPolygon.Fill = Brushes.LightSeaGreen; myPolygon.StrokeThickness = 5; Point Point1 = new Point(1, 50); Point Point2 = new Point(10, 80); Point Point3 = new Point(50, 50); PointCollection myPointCollection = new PointCollection(); myPointCollection.Add(Point1); myPointCollection.Add(Point2); myPointCollection.Add(Point3); myPolygon.Points = myPointCollection; PolygonsService ps = new PolygonsService(); ps.repo.Add(myPolygon); string path = "C:/Users/Hp/Desktop/Team_NAME/FiguresTask/UnitTests/bin/Debug/rez.txt"; ps.SerealizeAll(path); List <Polygon> polArr = (ps.DeserializeAll(path)).ToList(); Assert.AreEqual(5, polArr[0].StrokeThickness); }