Exemplo n.º 1
0
        /// <summary>
        /// Method Write
        /// </summary>
        /// <param name="intoBox">Input List</param>
        public void Write(string output, List <IFigure> intoBox)
        {
            XmlWriter xmlWriter = XmlWriter.Create(output);

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteStartElement("Boxs");
            foreach (var i in intoBox)
            {
                switch (i.GetType().Name)
                {
                case "CircleMadeByFilm":
                {
                    CircleMadeByFilm c1 = (CircleMadeByFilm)i;
                    xmlWriter.WriteStartElement("figure");
                    xmlWriter.WriteAttributeString("type", "Circle");
                    xmlWriter.WriteStartElement("material");
                    xmlWriter.WriteString("Film");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("color");
                    xmlWriter.WriteString("None");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("diameter");
                    xmlWriter.WriteString("" + c1.Diameter);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    break;
                }

                case "RectangleMadeByFilm":
                {
                    RectangleMadeByFilm r1 = (RectangleMadeByFilm)i;
                    xmlWriter.WriteStartElement("figure");
                    xmlWriter.WriteAttributeString("type", "Rectangle");
                    xmlWriter.WriteStartElement("material");
                    xmlWriter.WriteString("Film");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("color");
                    xmlWriter.WriteString("None");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("height");
                    xmlWriter.WriteString("" + r1.Height);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("width");
                    xmlWriter.WriteString("" + r1.Width);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    break;
                }

                case "SquareMadeByFilm":
                {
                    SquareMadeByFilm s1 = (SquareMadeByFilm)i;
                    xmlWriter.WriteStartElement("figure");
                    xmlWriter.WriteAttributeString("type", "Square");
                    xmlWriter.WriteStartElement("material");
                    xmlWriter.WriteString("Film");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("color");
                    xmlWriter.WriteString("None");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("height");
                    xmlWriter.WriteString("" + s1.A);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    break;
                }

                case "TriangleMadeByFilm":
                {
                    TriangleMadeByFilm t1 = (TriangleMadeByFilm)i;
                    xmlWriter.WriteStartElement("figure");
                    xmlWriter.WriteAttributeString("type", "Triangle");
                    xmlWriter.WriteStartElement("material");
                    xmlWriter.WriteString("Film");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("color");
                    xmlWriter.WriteString("None");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("side_a");
                    xmlWriter.WriteString("" + t1.A);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("side_b");
                    xmlWriter.WriteString("" + t1.B);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("side_c");
                    xmlWriter.WriteString("" + t1.C);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    break;
                }

                case "CircleMadeByPaper":
                {
                    CircleMadeByPaper c1 = (CircleMadeByPaper)i;
                    xmlWriter.WriteStartElement("figure");
                    xmlWriter.WriteAttributeString("type", "Circle");
                    xmlWriter.WriteStartElement("material");
                    xmlWriter.WriteString("Paper");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("color");
                    xmlWriter.WriteString("" + c1.Color);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("diameter");
                    xmlWriter.WriteString("" + c1.Diameter);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    break;
                }

                case "RectangleMadeByPaper":
                {
                    RectangleMadeByPaper r1 = (RectangleMadeByPaper)i;
                    xmlWriter.WriteStartElement("figure");
                    xmlWriter.WriteAttributeString("type", "Rectangle");
                    xmlWriter.WriteStartElement("material");
                    xmlWriter.WriteString("Paper");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("color");
                    xmlWriter.WriteString("" + r1.Color);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("height");
                    xmlWriter.WriteString("" + r1.Height);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("width");
                    xmlWriter.WriteString("" + r1.Width);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    break;
                }

                case "SquareMadeByPaper":
                {
                    SquareMadeByPaper s1 = (SquareMadeByPaper)i;
                    xmlWriter.WriteStartElement("figure");
                    xmlWriter.WriteAttributeString("type", "Square");
                    xmlWriter.WriteStartElement("material");
                    xmlWriter.WriteString("Paper");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("color");
                    xmlWriter.WriteString("" + s1.Color);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("height");
                    xmlWriter.WriteString("" + s1.A);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    break;
                }

                case "TriangleMadeByPaper":
                {
                    TriangleMadeByPaper t1 = (TriangleMadeByPaper)i;
                    xmlWriter.WriteStartElement("figure");
                    xmlWriter.WriteAttributeString("type", "Triangle");
                    xmlWriter.WriteStartElement("material");
                    xmlWriter.WriteString("Paper");
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("color");
                    xmlWriter.WriteString("" + t1.Color);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("side_a");
                    xmlWriter.WriteString("" + t1.A);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("side_b");
                    xmlWriter.WriteString("" + t1.B);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteStartElement("side_c");
                    xmlWriter.WriteString("" + t1.C);
                    xmlWriter.WriteEndElement();
                    xmlWriter.WriteEndElement();
                    break;
                }
                }
            }
            xmlWriter.WriteEndDocument();
            xmlWriter.Close();
        }
        /// <summary>
        /// Create new figure
        /// </summary>
        /// <param name="material">Material of new figure</param>
        /// <param name="form">Form of new figure</param>
        /// <param name="ps">Array of other params</param>
        /// <returns>Figure</returns>
        public IFigure CreateFigure(Material material, Form form, params float[] ps)
        {
            IFigure figure;

            switch (material)
            {
            case Material.Film:
            {
                switch (form)
                {
                case Form.Circle:
                {
                    if (ps.Length == 1)
                    {
                        figure = new CircleMadeByFilm(ps[0]);
                        break;
                    }
                    else
                    {
                        throw new Exception("Wrong input parameters");
                    }
                }

                case Form.Rectangle:
                {
                    if (ps.Length == 2)
                    {
                        figure = new RectangleMadeByFilm(ps[0], ps[1]);
                        break;
                    }
                    else
                    {
                        throw new Exception("Wrong input parameters");
                    }
                }

                case Form.Square:
                {
                    if (ps.Length == 1)
                    {
                        figure = new SquareMadeByFilm(ps[0]);
                        break;
                    }
                    else
                    {
                        throw new Exception("Wrong input parameters");
                    }
                }

                case Form.Triangle:
                {
                    if (ps.Length == 3)
                    {
                        figure = new TriangleMadeByFilm(ps[0], ps[1], ps[2]);
                        break;
                    }
                    else
                    {
                        throw new Exception("Wrong input parameters");
                    }
                }

                default: throw new Exception("Wrong input Form");
                }
                break;
            }

            case Material.Paper:
            {
                switch (form)
                {
                case Form.Circle:
                {
                    if (ps.Length == 1)
                    {
                        figure = new CircleMadeByPaper(ps[0]);
                        break;
                    }
                    else
                    {
                        throw new Exception("Wrong input parameters");
                    }
                }

                case Form.Rectangle:
                {
                    if (ps.Length == 2)
                    {
                        figure = new RectangleMadeByPaper(ps[0], ps[1]);
                        break;
                    }
                    else
                    {
                        throw new Exception("Wrong input parameters");
                    }
                }

                case Form.Square:
                {
                    if (ps.Length == 1)
                    {
                        figure = new SquareMadeByPaper(ps[0]);
                        break;
                    }
                    else
                    {
                        throw new Exception("Wrong input parameters");
                    }
                }

                case Form.Triangle:
                {
                    if (ps.Length == 3)
                    {
                        figure = new TriangleMadeByPaper(ps[0], ps[1], ps[2]);
                        break;
                    }
                    else
                    {
                        throw new Exception("Wrong input parameters");
                    }
                }

                default: throw new Exception("Wrong input Form");
                }
                break;
            }

            default: throw new Exception("Wrong input Material");
            }
            return(figure);
        }