private Task OnPreCompile(ISite site) { foreach (var page in site.MainPage.GetAllPages()) { string image; if (MetadataExtension.TryGetParameter <string>(page.Data, IMAGE_TAG_NAME, out image)) { if (!string.IsNullOrEmpty(image)) { if (string.Equals(Path.GetExtension(image), SVG_EXT, StringComparison.CurrentCultureIgnoreCase)) { IAsset imgAsset; try { imgAsset = AssetsHelper.FindAsset(site, page, image); } catch (Exception ex) { throw new NullReferenceException($"Failed to find image asset: '{image}'", ex); } var imgName = Path.GetFileNameWithoutExtension(image) + PNG_EXT; byte[] pngBuffer = null; using (var svgStream = new MemoryStream(imgAsset.Content)) { var svgDocument = SvgDocument.Open <SvgDocument>(svgStream); var bitmap = svgDocument.Draw(m_Settings.SvgPngWidth, m_Settings.SvgPngHeight); using (var pngStream = new MemoryStream()) { bitmap.Save(pngStream, ImageFormat.Png); pngBuffer = pngStream.ToArray(); } } page.Data.Add(REPLACE_IMAGE_TAG_NAME, imgName); var imgPngAsset = new PluginAsset(pngBuffer, imgName); page.Assets.Add(imgPngAsset); } } } } if (m_Settings.GenerateFavIcon) { GenerateFavIcon(site); } return(Task.CompletedTask); }
/// <summary>Store whether the plugin asset is enabled using the application settings.</summary> /// <param name="resource"></param> /// <param name="value"></param> protected override void SetIsPluginAssetEnabled(PluginAsset resource, bool value) { if (value != GetIsPluginAssetEnabled(resource)) { if (value) { DisabledPluginResources.Remove(GetType().FullName); } else { DisabledPluginResources.Add(GetType().FullName); } Properties.Settings.Default.Save(); } }
/// <summary>Get whether the plugin asset is enabled, using the application settings.</summary> /// <param name="resource"></param> /// <returns></returns> protected override bool GetIsPluginAssetEnabled(PluginAsset resource) { return(!DisabledPluginResources.Contains(resource.GetType().FullName)); }
public PluginAssetTreeNode(PluginAsset resource) : base(resource.DisplayName) { ToolTipText = resource.Description; Checked = resource.IsEnabled; }