Beispiel #1
0
        private void View_WriteToFileButton_Click(object sender, EventArgs e)
        {
            if (_figuresBuffer.Count == 0)
            {
                _view.ShowError(new Exception("Список фигур пуст."));
                return;
            }
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Filter = "Text files(*.txt)|*.txt";

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var serializer = AppDependencies.CreateSerializer();

                    var list = new List <FigureDrawer>();

                    foreach (var figure in _figuresBuffer)
                    {
                        list.Add(figure as FigureDrawer);
                    }

                    serializer.Serialize(list, dialog.FileName);
                }
            }
        }
Beispiel #2
0
        private void View_OnReadFromFileButton_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Filter = "Text files(*.txt)|*.txt";

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var serializer = AppDependencies.CreateSerializer();

                    try
                    {
                        var figures = serializer.Deserialize(dialog.FileName);

                        _figuresBuffer.AddRange(figures.ToArray());
                        _outFigures.AddRange(figures.ToArray());
                    }
                    catch (Exception err)
                    {
                        _view.ShowError(err);
                    }
                }
            }
        }