예제 #1
0
        /// <summary>
        /// Method to open a scribble file
        /// </summary>
        private void Open()
        {
            // create a instance of file dialog box to specify the file
            Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
            openFileDialog.Filter = CanvasConstants.FileType;

            // call showDialog to display the file dialog
            if (openFileDialog.ShowDialog() == true)
            {
                // Call service method to deserialize the file contents into Model
                DataService.CanvasService canvasService = new DataService.CanvasService();
                CanvasModel canvasModel = canvasService.Read(openFileDialog.FileName);

                for (int i = 0; i < canvasModel.Points.Length; i++)
                {
                    if (canvasModel.Points[i] != null)
                    {
                        // Call the extension method to convet the points array to storke
                        var strokes = canvasModel.Points[i].GenerateStroke((DrawingMode)canvasModel.Modes[i]);

                        // add the stroke to the collection
                        this.Strokes.Add(strokes);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Method to save the canvas strokes
        /// </summary>
        private void Save()
        {
            CanvasModel canvasModel = new CanvasModel();

            // Call the extension method to convert the strokes in to point array
            canvasModel.Points = this.Strokes.GeneratePointArray();

            // Call the extension method to get the drawing modes of strokes
            canvasModel.Modes = this.Strokes.GetDrawingModes();

            // create a instance of file dialog box to specify the file name and location for save
            Microsoft.Win32.SaveFileDialog saveFileDialog = new Microsoft.Win32.SaveFileDialog();

            // Set the filter that determines the file type
            saveFileDialog.Filter = CanvasConstants.FileType;

            if (saveFileDialog.ShowDialog() == true)
            {
                DataService.CanvasService canvasService = new DataService.CanvasService();

                // call the service method to serialize and save the the contents
                canvasService.Write(saveFileDialog.FileName, canvasModel);
            }
        }