Esempio n. 1
0
        public FigureStorage Deserialize(FigureStorage currentFigureStorage)
        {
            try
            {
                FigureStorage figureStorage = new FigureStorage();

                openDialog.ShowDialog();
                string fileName = openDialog.FileName;

                if (fileName != "")
                {
                    using FileStream fStream = File.OpenRead(fileName);
                    string streamReader = new StreamReader(fStream).ReadToEnd();
                    figureStorage = JsonConvert.DeserializeObject <FigureStorage>(streamReader, settings);

                    return(figureStorage);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(currentFigureStorage);
        }
Esempio n. 2
0
        private void DeserializerButton_Click(object sender, EventArgs e)
        {
            figureStorage = serializer.Deserialize(figureStorage);
            PictureBox.Refresh();

            if (!figureStorage.undoList.IsEmpty())
            {
                UndoButton.Enabled = true;
            }
            if (!figureStorage.redoStack.IsEmpty())
            {
                RedoButton.Enabled = true;
            }
        }
Esempio n. 3
0
        public MainForm()
        {
            InitializeComponent();

            figureStorage = new FigureStorage();

            serializer = new Serializer();

            plugin = new Plugin();

            color     = Color.Black;
            fillColor = Color.White;

            penWidth   = 3;
            cornersNum = 3;

            isDrawing = false;
            isFeel    = false;

            points = new List <Point>();

            bitmap           = new Bitmap(PictureBox.Width, PictureBox.Height);
            PictureBox.Image = bitmap;
        }
Esempio n. 4
0
        public void Serialize(FigureStorage figureStorage)
        {
            JsonSerializer serializer = JsonSerializer.Create(settings);

            try
            {
                saveDialog.DefaultExt = ".json";
                saveDialog.Filter     = "JSON files (*.json)|*json|Text files (*.txt)|*txt";

                saveDialog.ShowDialog();
                string fileName = saveDialog.FileName;

                if (fileName != "")
                {
                    using StreamWriter streamWriter = new StreamWriter(fileName);
                    using JsonWriter jsonWriter     = new JsonTextWriter(streamWriter);
                    serializer.Serialize(jsonWriter, figureStorage);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }