示例#1
0
        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);
        }
示例#2
0
 /// <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();
     }
 }
示例#3
0
 /// <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));
 }
示例#4
0
 public PluginAssetTreeNode(PluginAsset resource)
     : base(resource.DisplayName)
 {
     ToolTipText = resource.Description;
     Checked     = resource.IsEnabled;
 }