예제 #1
0
        void db_CloseEvent(object sender, EventArgs e)
        {
            try
            {
                this.gdDrawing.Visibility = System.Windows.Visibility.Collapsed;

                Image     img = this.currentDb.GetSnapshot();
                Rectangle rec = this.gdBack.Children[0] as Rectangle;
                img.Width  = rec.ActualWidth;
                img.Height = rec.ActualHeight;

                DrawingboardData data = this.currentDb.GetModel();
                this.AddToCache(this.currentDb.ID, data);

                this.Add(img, this.currentDb.ID);
                RenderTargetBitmap bitmapSource = img.Source as RenderTargetBitmap;
                this.Save(data, bitmapSource);

                if (this.CloseEvent != null)
                {
                    this.CloseEvent(this, e);
                }
            }
            catch (Exception ex)
            {
            }
        }
예제 #2
0
        public static DrawingboardData Load(string drawingboardId)
        {
            try
            {
                string text          = "";
                string fileDirectory = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileDirectory);

                string fileName = System.IO.Path.Combine(fileDirectory, drawingboardId + ".txt");
                if (System.IO.File.Exists(fileName))
                {
                    using (var fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.ReadWrite))
                    {
                        var reader = new System.IO.StreamReader(fs);
                        text = reader.ReadToEnd();
                    }
                }

                if (string.IsNullOrEmpty(text) == false)
                {
                    DrawingboardData board = JsonHelper.Deserialize <DrawingboardData>(text);
                    return(board);
                }
            }
            catch
            {
                return(null);
            }

            return(null);
        }
예제 #3
0
        internal DrawingboardData GetModel()
        {
            DrawingboardData data = new DrawingboardData();
            var strokesData       = StrokeBuilder.StrokesToData(inkCanvas.Strokes, new Size(inkCanvas.ActualWidth, inkCanvas.ActualHeight));

            data.ID      = this.ID;
            data.Strokes = strokesData;

            return(data);
        }
예제 #4
0
 private void AddToCache(string id, DrawingboardData data)
 {
     if (this.boards.ContainsKey(id))
     {
         this.boards[id] = data;
     }
     else
     {
         this.boards.Add(id, data);
     }
 }
예제 #5
0
        void SaveContentInBackground(object o)
        {
            DrawingboardData data = o as DrawingboardData;

            if (data != null)
            {
                bool result = StrokeBuilder.Save(data);
                if (result)
                {
                }
            }
        }
예제 #6
0
        void Save(DrawingboardData content, RenderTargetBitmap snapShotSource)
        {
            string fileName        = content.ID;
            string snapShotAddress = StrokeBuilder.GetSnapShotAddresss(fileName);

            try
            {
                snapShotSource.Save(snapShotAddress);
                Thread saveThread = new Thread(this.SaveContentInBackground);
                saveThread.Start(content);
            }
            catch (Exception ex)
            {
                return;
            }
        }
예제 #7
0
        public static bool Save(DrawingboardData drawingboard)
        {
            try
            {
                string text = JsonHelper.Serialize <DrawingboardData>(drawingboard);

                string fileDirectory = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FileDirectory);

                System.IO.File.WriteAllText(System.IO.Path.Combine(fileDirectory, drawingboard.ID + ".txt"), text);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #8
0
        private void Load()
        {
            if (this.isLoadFiles == false)
            {
                this.isLoadFiles = true;
                string fileDirectory = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, StrokeBuilder.FileDirectory);
                if (Directory.Exists(fileDirectory) == false)
                {
                    Directory.CreateDirectory(fileDirectory);
                }

                string snapShotDirectory = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, StrokeBuilder.SnapshotDirectory);
                if (Directory.Exists(snapShotDirectory) == false)
                {
                    Directory.CreateDirectory(snapShotDirectory);
                }
                else
                {
                    string[]             files      = Directory.GetFiles(snapShotDirectory);
                    IEnumerable <string> orderFiles = files.OrderBy(item => item);
                    char[] split = { '\\' };
                    foreach (string file in orderFiles)
                    {
                        string[] filepath = file.Split(split);
                        string   fileName = filepath[filepath.Length - 1];
                        int      index    = fileName.IndexOf('.');
                        string   fileId   = fileName.Substring(0, index);
                        Image    img      = new Image();
                        img.SetImage(file, true);

                        DrawingboardData data = StrokeBuilder.Load(fileId);
                        if (data != null)
                        {
                            this.boards.Add(fileId, data);

                            this.Add(img, fileId);
                        }
                    }
                }
            }
        }
예제 #9
0
 internal void Load(DrawingboardData data)
 {
     this.ID   = data.ID;
     this.data = data;
 }