Project image cache implementation.
Inheritance: XSelectable, IImageCache
Ejemplo n.º 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="project"></param>
 /// <param name="path"></param>
 /// <param name="fileIO"></param>
 /// <param name="serializer"></param>
 public static void Save(XProject project, string path, IFileSystem fileIO, IJsonSerializer serializer)
 {
     using (var stream = fileIO.Create(path))
     {
         Save(project, stream, fileIO, serializer);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="project"></param>
 /// <param name="stream"></param>
 /// <param name="fileIO"></param>
 /// <param name="serializer"></param>
 public static void Save(XProject project, Stream stream, IFileSystem fileIO, IJsonSerializer serializer)
 {
     using (var archive = new ZipArchive(stream, ZipArchiveMode.Create))
     {
         var projectEntry = archive.CreateEntry(ProjectJsonEntryName);
         WriteProject(project, projectEntry, fileIO, serializer);
         var keys = GetUsedKeys(project);
         WriteImages(project, keys, archive, fileIO);
     }
 }
Ejemplo n.º 3
0
        public void SetCurrentDocument_Sets_CurrentDocument()
        {
            var target = new XProject();

            var document = XDocument.Create();
            target.Documents = target.Documents.Add(document);

            target.SetCurrentDocument(document);

            Assert.Equal(document, target.CurrentDocument);
        }
Ejemplo n.º 4
0
        public void AddImageFromFile_Add_Key_And_Notify()
        {
            var target = new XProject();
            string actual = null;

            target.PropertyChanged += (sender, e) =>
            {
                actual = e.PropertyName;
            };

            var key = target.AddImageFromFile(@"C:/Images/image.jpg", new byte[] { });

            Assert.Equal(XProject.ImageEntryNamePrefix + "image.jpg", key);
            Assert.Equal(1, target.Keys.Count());
            Assert.Equal("Keys", actual);
        }
Ejemplo n.º 5
0
        /// <inheritdoc/>
        void IProjectExporter.Save(string path, XProject project)
        {
            var template = new Template();
            var drawing = new Drawing(template);

            foreach (var document in project.Documents)
            {
                foreach (var container in document.Pages)
                {
                    Add(drawing, container);
                }
            }

            drawing.Save(path);
            ClearCache(isZooming: false);
        }
Ejemplo n.º 6
0
        public void AddImageFromFile_Do_Not_Add_Duplicate()
        {
            var target = new XProject();
            int count = 0;

            target.PropertyChanged += (sender, e) =>
            {
                count++;
            };

            var key1 = target.AddImageFromFile(@"C:/Images/image.jpg", new byte[] { });
            var key2 = target.AddImageFromFile(@"C:/Images/image.jpg", new byte[] { });

            Assert.Equal(XProject.ImageEntryNamePrefix + "image.jpg", key1);
            Assert.Equal(XProject.ImageEntryNamePrefix + "image.jpg", key2);
            Assert.Equal(1, target.Keys.Count());
            Assert.Equal(1, count);
        }
Ejemplo n.º 7
0
        /// <inheritdoc/>
        void IProjectExporter.Save(string path, XProject project)
        {
            using (var stream = new SKFileWStream(path))
            {
                using (var pdf = SKDocument.CreatePdf(stream, _targetDpi))
                {
                    foreach (var document in project.Documents)
                    {
                        foreach (var container in document.Pages)
                        {
                            Add(pdf, container);
                        }
                    }

                    pdf.Close();
                    _renderer.ClearCache(isZooming: false);
                }
            }
        }
Ejemplo n.º 8
0
        public void RemoveImage_Remove_Key_And_Notify()
        {
            var target = new XProject();
            int count = 0;

            target.PropertyChanged += (sender, e) =>
            {
                count++;
            };

            var key = XProject.ImageEntryNamePrefix + "image.jpg";

            target.AddImage(key, new byte[] { });
            target.RemoveImage(key);

            Assert.Equal(0, target.Keys.Count());
            Assert.Equal(2, count);
        }
Ejemplo n.º 9
0
 public void Implements_IImageCache_Interface()
 {
     var target = new XProject();
     Assert.True(target is IImageCache);
 }
Ejemplo n.º 10
0
        public void GetImage_Returns_Null()
        {
            var project = new XProject();

            var key = XProject.ImageEntryNamePrefix + "image.jpg";

            var target = project.GetImage(key);

            Assert.Null(target);
        }
Ejemplo n.º 11
0
        public void GetImage_Returns_Byte_Array()
        {
            var project = new XProject();

            var key = XProject.ImageEntryNamePrefix + "image.jpg";
            var data = new byte[] { 0x12, 0x34, 0x56, 0x78 };

            project.AddImage(key, data);

            var target = project.GetImage(key);

            Assert.Equal(data, target);
        }
Ejemplo n.º 12
0
 public void GroupLibraries_Not_Null()
 {
     var target = new XProject();
     Assert.NotNull(target.GroupLibraries);
 }
Ejemplo n.º 13
0
        public void Setting_Selected_Should_Call_SetSelected()
        {
            var target = new XProject();

            var document = XDocument.Create();
            target.Documents = target.Documents.Add(document);

            target.Selected = document;

            Assert.Equal(document, target.CurrentDocument);
        }
Ejemplo n.º 14
0
 public void Inherits_From_ObservableResource()
 {
     var target = new XProject();
     Assert.True(target is ObservableResource);
 }
Ejemplo n.º 15
0
 private static void WriteProject(XProject project, ZipArchiveEntry projectEntry, IFileSystem fileIO, IJsonSerializer serializer)
 {
     using (var jsonStream = projectEntry.Open())
     {
         fileIO.WriteUtf8Text(jsonStream, serializer.Serialize(project));
     }
 }
Ejemplo n.º 16
0
        public void SetCurrentContainer_Sets_CurrentContainer_And_Selected()
        {
            var target = new XProject();

            var document = XDocument.Create();
            target.Documents = target.Documents.Add(document);

            var page = XContainer.CreatePage();
            document.Pages = document.Pages.Add(page);

            target.SetCurrentContainer(page);

            Assert.Equal(page, target.CurrentContainer);
            Assert.Equal(page, target.Selected);
        }
Ejemplo n.º 17
0
 public void Options_Not_Null()
 {
     var target = new XProject();
     Assert.NotNull(target.Options);
 }
Ejemplo n.º 18
0
 public void Documents_Not_Null()
 {
     var target = new XProject();
     Assert.NotNull(target.Documents);
 }
Ejemplo n.º 19
0
 public void Templates_Not_Null()
 {
     var target = new XProject();
     Assert.NotNull(target.Templates);
 }
Ejemplo n.º 20
0
 public void Databases_Not_Null()
 {
     var target = new XProject();
     Assert.NotNull(target.Databases);
 }
Ejemplo n.º 21
0
        public void PurgeUnusedImages_Remove_All_Keys_And_Notify()
        {
            var target = new XProject();
            int count = 0;

            target.PropertyChanged += (sender, e) =>
            {
                count++;
            };

            var key1 = XProject.ImageEntryNamePrefix + "image1.jpg";
            var key2 = XProject.ImageEntryNamePrefix + "image2.jpg";
            var key3 = XProject.ImageEntryNamePrefix + "image3.jpg";

            target.AddImage(key1, new byte[] { });
            target.AddImage(key2, new byte[] { });
            target.AddImage(key3, new byte[] { });

            var used = Enumerable.Empty<string>().ToImmutableHashSet();

            target.PurgeUnusedImages(used);

            Assert.Equal(0, target.Keys.Count());
            Assert.Equal(4, count);
        }
Ejemplo n.º 22
0
        public void PurgeUnusedImages_Remove_Only_Unused_Keys_And_Notify()
        {
            var target = new XProject();
            int count = 0;

            target.PropertyChanged += (sender, e) =>
            {
                count++;
            };

            var key1 = XProject.ImageEntryNamePrefix + "image1.jpg";
            var key2 = XProject.ImageEntryNamePrefix + "image2.jpg";
            var key3 = XProject.ImageEntryNamePrefix + "image3.jpg";

            target.AddImage(key1, new byte[] { });
            target.AddImage(key2, new byte[] { });
            target.AddImage(key3, new byte[] { });

            var used = ImmutableHashSet.Create(key2);

            target.PurgeUnusedImages(used);

            Assert.Equal(key2, target.Keys.First().Key);
            Assert.Equal(1, target.Keys.Count());
            Assert.Equal(4, count);
        }
Ejemplo n.º 23
0
        public void AddImage_Do_Not_Add_Duplicate()
        {
            var target = new XProject();
            int count = 0;

            target.PropertyChanged += (sender, e) =>
            {
                count++;
            };

            var key = XProject.ImageEntryNamePrefix + "image.jpg";

            target.AddImage(key, new byte[] { });
            target.AddImage(key, new byte[] { });

            Assert.Equal(key, target.Keys.First().Key);
            Assert.Equal(1, target.Keys.Count());
            Assert.Equal(1, count);
        }
Ejemplo n.º 24
0
 public void Keys_Not_Null()
 {
     var target = new XProject();
     Assert.NotNull(target.Keys);
 }
Ejemplo n.º 25
0
        public void SetSelected_Container()
        {
            var target = new XProject();

            var document = XDocument.Create();
            target.Documents = target.Documents.Add(document);

            var page = XContainer.CreatePage();
            document.Pages = document.Pages.Add(page);

            var layer = XLayer.Create("Layer1", page);
            page.Layers = page.Layers.Add(layer);

            bool raised = false;

            layer.InvalidateLayer += (sender, e) =>
            {
                raised = true;
            };

            target.SetSelected(page);

            Assert.Equal(document, target.CurrentDocument);
            Assert.Equal(page, target.CurrentContainer);
            Assert.True(raised);
        }
Ejemplo n.º 26
0
 private static IEnumerable<string> GetUsedKeys(XProject project)
 {
     return XProject.GetAllShapes<XImage>(project).Select(i => i.Key).Distinct();
 }
Ejemplo n.º 27
0
 public void StyleLibraries_Not_Null()
 {
     var target = new XProject();
     Assert.NotNull(target.StyleLibraries);
 }
Ejemplo n.º 28
0
        public void SetCurrentStyleLibrary_Sets_CurrentStyleLibrary()
        {
            var target = new XProject();

            var library = XLibrary<ShapeStyle>.Create("Library1");
            target.StyleLibraries = target.StyleLibraries.Add(library);

            target.SetCurrentStyleLibrary(library);

            Assert.Equal(library, target.CurrentStyleLibrary);
        }
Ejemplo n.º 29
0
        public void SetSelected_Layer()
        {
            var target = new XProject();

            var page = new XContainer();
            var layer = XLayer.Create("Layer1", page);

            target.SetSelected(layer);

            Assert.Equal(layer, page.CurrentLayer);
        }
Ejemplo n.º 30
0
        private void Remove(XProject project)
        {
            if (project == null)
                return;

            project.PropertyChanged -= ObserveProject;

            Remove(project.Options);

            if (project.Databases != null)
            {
                foreach (var database in project.Databases)
                {
                    Remove(database);
                }
            }

            if (project.Documents != null)
            {
                foreach (var document in project.Documents)
                {
                    Remove(document);
                }
            }

            if (project.Templates != null)
            {
                foreach (var template in project.Templates)
                {
                    Remove(template);
                }
            }

            if (project.StyleLibraries != null)
            {
                foreach (var sg in project.StyleLibraries)
                {
                    Remove(sg);
                }
            }
        }
Ejemplo n.º 31
0
 private static IEnumerable <string> GetUsedKeys(XProject project)
 {
     return(XProject.GetAllShapes <XImage>(project).Select(i => i.Key).Distinct());
 }