private async Task CacheImages(T2d.Project project) { var images = T2d.Editor.GetAllShapes <T2d.XImage>(project); if (images != null) { foreach (var image in images) { await CacheImage(image.Path); } } }
/// <summary> /// /// </summary> /// <param name="project"></param> public void Remove(Project project) { if (project == null) return; project.PropertyChanged -= ProjectObserver; Verbose("Remove Project: " + project.Name); 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); } } }
/// <summary> /// Creates a new instance of the <see cref="Container"/> class. /// </summary> /// <param name="project">The new container owner project.</param> /// <param name="name">The new container name.</param> /// <returns>The new instance of the <see cref="Container"/>.</returns> private Container CreateGridTemplate(Project project, string name) { var template = GetTemplate(project, name); var style = project .StyleLibraries.FirstOrDefault(g => g.Name == "Template") .Styles.FirstOrDefault(s => s.Name == "Grid"); var layer = template.Layers.FirstOrDefault(); var builder = layer.Shapes.ToBuilder(); var grid = XRectangle.Create( 0, 0, template.Width, template.Height, style, project.Options.PointShape); grid.IsStroked = false; grid.IsFilled = false; grid.IsGrid = true; grid.OffsetX = 30.0; grid.OffsetY = 30.0; grid.CellWidth = 30.0; grid.CellHeight = 30.0; grid.State.Flags &= ~ShapeStateFlags.Printable; builder.Add(grid); layer.Shapes = builder.ToImmutable(); return template; }
/// <summary> /// Creates a new instance of the <see cref="Container"/> class. /// </summary> /// <param name="project">The new container owner project.</param> /// <param name="name">The new container name.</param> /// <returns>The new instance of the <see cref="Container"/>.</returns> public Container GetTemplate(Project project, string name) { var container = Container.Create(name, true); container.Background = ArgbColor.Create(0xFF, 0xFF, 0xFF, 0xFF); foreach (var layer in container.Layers) { layer.Name = string.Concat("Template", layer.Name); } return container; }
/// <summary> /// Creates a new instance of the <see cref="Document"/> class. /// </summary> /// <param name="project">The new document owner project.</param> /// <param name="name">The new document name.</param> /// <returns>The new instance of the <see cref="Document"/>.</returns> public Document GetDocument(Project project, string name) { var document = Document.Create(name); return document; }
/// <summary> /// Creates a new instance of the <see cref="Container"/> class. /// </summary> /// <param name="project">The new container owner project.</param> /// <param name="name">The new container name.</param> /// <returns>The new instance of the <see cref="Container"/>.</returns> public Container GetContainer(Project project, string name) { var container = Container.Create(name); if (project.CurrentTemplate == null) { var template = GetTemplate(project, "Empty"); var templateBuilder = project.Templates.ToBuilder(); templateBuilder.Add(template); project.Templates = templateBuilder.ToImmutable(); project.CurrentTemplate = template; } container.Template = project.CurrentTemplate; return container; }
/// <summary> /// /// </summary> /// <param name="stream"></param> /// <param name="project"></param> /// <param name="serializer"></param> public static void Save(Stream stream, Project project, ISerializer serializer) { using (var archive = new ZipArchive(stream, ZipArchiveMode.Create)) { // First step is to write project entry. var jsonEntry = archive.CreateEntry(ProjectEntryName); using (var jsonStream = jsonEntry.Open()) { var json = serializer.Serialize(project); WriteUtf8Text(jsonStream, json); } // Second step is to write (if any) project images. var keys = Editor.GetAllShapes<XImage>(project).Select(i => i.Path).Distinct(); foreach (var key in keys) { var bytes = project.GetImage(key); if (bytes != null) { var imageEntry = archive.CreateEntry(key); using (var imageStream = imageEntry.Open()) { WriteBinary(imageStream, bytes); } } } // NOTE: Purge deleted images from memory is not called here to enable Undo/Redo. //project.PurgeUnusedImages(new HashSet<string>(keys)); } }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="project"></param> /// <param name="serializer"></param> /// <returns></returns> public static void Save(string path, Project project, ISerializer serializer) { using (var stream = new FileStream(path, FileMode.Create)) { Save(stream, project, serializer); } }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <returns></returns> public static Project Create(string name = "Project") { var p = new Project() { Name = name, Options = Options.Create(), Databases = ImmutableArray.Create<Database>(), StyleLibraries = ImmutableArray.Create<StyleLibrary>(), GroupLibraries = ImmutableArray.Create<GroupLibrary>(), Templates = ImmutableArray.Create<Container>(), Documents = ImmutableArray.Create<Document>(), }; return p; }
/// <summary> /// /// </summary> /// <param name="project"></param> /// <param name="name"></param> /// <returns></returns> private Container CreateGridTemplate(Project project, string name) { var container = GetTemplate(project, name); CreateGrid(project, container); return container; }