Ejemplo n.º 1
0
        private void LOAD_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            // получаем выбранный файл
            string filename = openFileDialog1.FileName;

            // читаем файл в строку
            MessageBox.Show("Файл открыт");

            /* LoadCommand load_com = (LoadCommand)commands["Load"].clon();
             * load_com.execute(filename, storage);
             * history.Push(load_com);
             * undo_unexecute.Enabled = true;*/


            MyFigureFactory factory = new MyFigureFactory();

            XmlReader rdr = XmlReader.Create(new System.IO.StringReader(File.ReadAllText(openFileDialog1.FileName)));

            storage.LOAD(factory, filename, rdr);

            Refresh();
        }
Ejemplo n.º 2
0
        public void LOAD(MyFigureFactory factory, string filename, XmlReader rdr)
        {
            StreamReader reader = new StreamReader(filename);

            /*int count = System.IO.File.ReadAllLines(filename).Length;
             * for (int i = 0; i < count; i++)
             * {
             *  string read;
             *  read = reader.ReadLine();
             *  bool flag1 = false;
             *  Figure figure = factory.createFigure(read, 0, 0);
             *  if (figure != null)
             *  {
             *
             *      figure.load(reader, factory);
             *      setFigure(figure);
             *  }
             *
             * }*/

            //int count = System.IO.File.ReadAllLines(filename)- 5;
            //for (int i = 0; i < count; i++)
            //{

            //Строка для чтения
            string read = "";


            read = reader.ReadLine();

            //Пока файл читается
            while (rdr.Read())
            {
                //Если встретился тег, тогда создаем соответвующую фигуру и загружаем ее в хранилище
                if (rdr.NodeType == XmlNodeType.Element && rdr.LocalName != "svg")
                {
                    Figure figure = factory.createFigure(rdr.LocalName, 0, 0);
                    figure.load(reader, factory, rdr);
                    //Помещаем фигуру в хранилище
                    setFigure(figure);
                }
            }

            notifyEveryine();
        }
Ejemplo n.º 3
0
 public LoadCommand()
 {
     storage  = new Storage();
     factory  = new MyFigureFactory();
     filename = null;
 }
Ejemplo n.º 4
0
 public CreateFigureCommand()
 {
     factory = new MyFigureFactory();
     f       = null;
 }