private async void Execute(object sender, EventArgs e) { var files = GetFiles(); var folder = Path.GetDirectoryName(files.First()); string spriteFile; if (GetFileName(folder, out spriteFile)) { var doc = new SpriteDocument(spriteFile, files); doc.Stylesheet = Stylesheet.Css; await doc.Save(); ProjectHelpers.DTE.ItemOperations.OpenFile(doc.FileName); await SpriteService.GenerateSprite(doc); } }
public async Task CreateDocument() { var img = Path.Combine(_artifacts, "images/96dpi/a.png"); var original = new SpriteDocument(_fileName, new[] { img }); original.Output = ImageType.Jpg; await original.Save(); var read = await SpriteDocument.FromFile(_fileName); Assert.AreEqual(original.Orientation, read.Orientation); Assert.AreEqual(original.FileName, read.FileName); Assert.AreEqual(original.Output, read.Output); Assert.AreEqual(original.Images.Count(), read.Images.Count()); var input = new FileInfo(Path.Combine(_artifacts, "images/96dpi/a.png")).FullName; Assert.AreEqual(input, read.ToAbsoluteImages().First().Value); }
private void Execute(object sender, EventArgs e) { IEnumerable <string> files = GetFiles(); string folder = Path.GetDirectoryName(files.First()); if (GetFileName(folder, out string spriteFile)) { var doc = new SpriteDocument(spriteFile, files) { Stylesheet = Stylesheet.Css }; ThreadHelper.JoinableTaskFactory.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); await doc.Save(); ProjectHelpers.DTE.ItemOperations.OpenFile(doc.FileName); await SpriteService.GenerateSpriteAsync(doc); }); } }
private void btnGenerate_Click(object sender, EventArgs e) { var _artifacts = new DirectoryInfo(".\\").FullName; var spritesDirName = "Sprites"; if (!Directory.Exists(spritesDirName)) { Directory.CreateDirectory(spritesDirName); } var _fileName = Path.Combine(_artifacts, spritesDirName, $"{txtSpriteName.Text}.sprite"); var images = new List <string>(); foreach (FileInfoDisplayName f in lbTarget.Items) { images.Add(f.File.FullName); } var document = new SpriteDocument(_fileName, images); document.Orientation = ImageSprites.Orientation.Horizontal; document.Padding = 20; document.Output = ImageType.Png; document.Stylesheet = Stylesheet.Css; document.CustomStyles["display"] = "block"; document.CustomStyles.Add("margin", "0"); var task = Task.Run(() => _generator.Generate(document)); task.Wait(); var documentTask = Task.Run(() => document.Save()); documentTask.Wait(); }