Exemple #1
0
        /// <summary>
        /// Serializes into XML
        /// </summary>
        /// <param name="path"></param>
        public void SerealizeAll(string path)
        {
            if (path != "" && path != null)
            {
                IEnumerable <Polygon> allPolygons = repo.GetAll();
                var           points    = allPolygons.Select(polygon => new PolygonModel(polygon.Points.ToList(), ((SolidColorBrush)polygon.Fill).Color, polygon.StrokeThickness)).ToArray();
                XmlSerializer formatter = new XmlSerializer(typeof(PolygonModel[]));

                using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
                {
                    formatter.Serialize(fs, points);
                }
            }
            else
            {
                if (path == "")
                {
                    throw new ArgumentException("Path to serealization file was set incorrectly");
                }
                else
                {
                    throw new ArgumentException("There was no path to serealization file");
                }
            }
        }
Exemple #2
0
        public void SerealizeAll(string path)
        {
            IEnumerable <Polygon> allPolygons = repo.GetAll();
            var           points    = allPolygons.Select(polygon => new PolygonModel(polygon.Points.ToList(), ((SolidColorBrush)polygon.Fill).Color, polygon.StrokeThickness)).ToArray();
            XmlSerializer formatter = new XmlSerializer(typeof(PolygonModel[]));

            using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
            {
                formatter.Serialize(fs, points);
            }
        }
Exemple #3
0
        public void ShapesRepository_GetAll_Test()
        {
            Polygon polygon1 = new Polygon();
            Polygon polygon2 = new Polygon();

            polygon2.StrokeThickness     = 2;
            polygon1.HorizontalAlignment = HorizontalAlignment.Left;
            ShapesRepository arr = new ShapesRepository();

            arr.Add(polygon1);
            arr.Add(polygon2);
            List <Polygon> pol = arr.GetAll().ToList();

            Assert.AreEqual(2, pol[1].StrokeThickness);
            Assert.AreEqual(HorizontalAlignment.Left, pol[0].HorizontalAlignment);
        }