예제 #1
0
 /// <summary>
 /// Adds or removes content to the web site.
 /// </summary>
 private void EnableDisableContent()
 {
     if (_WebSite != null)
     {
         if (!Enabled)
         {
             if (_SiteRoot != null)
             {
                 _WebSite.RemoveSiteRoot(_SiteRoot);
             }
             foreach (var contentInjector in _ContentInjectors)
             {
                 _WebSite.RemoveHtmlContentInjector(contentInjector);
             }
         }
         else
         {
             if (_SiteRoot != null)
             {
                 _WebSite.AddSiteRoot(_SiteRoot);
             }
             foreach (var contentInjector in _ContentInjectors)
             {
                 _WebSite.AddHtmlContentInjector(contentInjector);
             }
         }
     }
 }
예제 #2
0
파일: Plugin.cs 프로젝트: nevrrmind/vrs
        /// <summary>
        /// Applies the options.
        /// </summary>
        private void ApplyOptions(Options options)
        {
            if (_WebSite != null)
            {
                if (!options.Enabled)
                {
                    DisableSiteRoot();
                }
                else
                {
                    EnableSiteRoot(options.SiteRootFolder);
                }

                if (!options.Enabled || String.IsNullOrEmpty(options.ResourceImagesFolder))
                {
                    _CustomResourceImageManager.Enabled = false;
                    _CustomResourceImageManager.ResourceImagesFolder = null;
                    _CustomResourceImageManager.UnloadCustomImages();
                }
                else
                {
                    _CustomResourceImageManager.ResourceImagesFolder = options.ResourceImagesFolder;
                    _CustomResourceImageManager.Enabled = true;
                    _CustomResourceImageManager.LoadCustomImages(blockThread: true);
                }

                foreach (var existingInjector in _ContentInjectors)
                {
                    _WebSite.RemoveHtmlContentInjector(existingInjector);
                }
                _ContentInjectors.Clear();
                if (options.Enabled)
                {
                    int priority = 1;
                    foreach (var injectSettings in options.InjectSettings.Where(r => r.Enabled))
                    {
                        var injector = new CustomHtmlContentInjector()
                        {
                            AtStart     = injectSettings.Start,
                            Element     = injectSettings.InjectionLocation.ToString().ToLower(),
                            FileName    = injectSettings.File,
                            PathAndFile = injectSettings.PathAndFile == "*" ? null : injectSettings.PathAndFile,
                            Priority    = priority++,
                        };
                        _WebSite.AddHtmlContentInjector(injector);
                        _ContentInjectors.Add(injector);
                    }
                }

                if (!options.Enabled)
                {
                    Status = CustomContentStrings.Disabled;
                }
                else
                {
                    if (String.IsNullOrEmpty(options.SiteRootFolder))
                    {
                        Status = CustomContentStrings.EnabledNoSiteRoot;
                    }
                    else
                    {
                        Status = String.Format(CustomContentStrings.EnabledWithSiteRoot, options.SiteRootFolder);
                    }
                }
            }

            OnStatusChanged(EventArgs.Empty);
        }