public static IList <Site> ExtractSites(HostSection config) { List <Site> sites = new List <Site>(); foreach (SiteElement configElement in config.Sites) { Site s = new Site(configElement.RootID ?? config.RootID, configElement.ID, configElement.Name); s.Wildcards = configElement.Wildcards || config.Wildcards; foreach (FolderElement folder in configElement.UploadFolders.AllElements) { if (string.IsNullOrEmpty(folder.Path)) { throw new ConfigurationErrorsException("Upload path configured for site '" + configElement.Name + "' cannot be empty."); } s.UploadFolders.Add(new FileSystemRoot(folder, s)); } foreach (string key in configElement.Settings.AllKeys) { s.Settings[key] = configElement.Settings[key].Value; } sites.Add(s); } return(sites); }
public override void SetUp() { base.SetUp(); root = CreateOneItem <PageItem>(1, "root", null); one = CreateOneItem <CustomExtensionItem>(2, "one", root); two = CreateOneItem <PageItem>(3, "two", one); CreateOneItem <DataItem>(4, "four", root); three = CreateOneItem <PageItem>(5, "three.3", root); webContext = new FakeWebContextWrapper(); var hostSection = new HostSection { Web = new WebElement { Rewrite = rewriteMethod } }; parser = new UrlParser(persister, webContext, new Host(webContext, root.ID, root.ID), hostSection); errorHandler = new FakeErrorHandler(); engine = new FakeEngine(); engine.Container.AddComponentInstance(null, typeof(IWebContext), webContext); adapterProvider = new ContentAdapterProvider(engine, new AppDomainTypeFinder()); adapterProvider.Start(); ReCreateDispatcherWithConfig(hostSection); }
protected virtual void InitializeEnvironment(IServiceContainer container, HostSection hostConfig) { if (hostConfig != null) { Url.DefaultExtension = hostConfig.Web.Extension; PathData.PageQueryKey = hostConfig.Web.PageQueryKey; PathData.ItemQueryKey = hostConfig.Web.ItemQueryKey; PathData.PartQueryKey = hostConfig.Web.PartQueryKey; if (!hostConfig.Web.IsWeb) { container.AddComponentInstance("n2.webContext.notWeb", typeof(IWebContext), new ThreadContext()); } if (hostConfig.Web.Urls.EnableCaching) { container.AddComponent("n2.web.cachingUrlParser", typeof(IUrlParser), typeof(CachingUrlParserDecorator)); } if (hostConfig.MultipleSites) { container.AddComponent("n2.multipleSitesParser", typeof(IUrlParser), typeof(MultipleSitesParser)); } else { container.AddComponent("n2.urlParser", typeof(IUrlParser), typeof(UrlParser)); } } }
public CacheManager(IWebContext context, IPersister persister, HostSection config) : this(context, persister) { enabled = config.OutputCache.Enabled; varyByParam = config.OutputCache.VaryByParam; cacheProfile = config.OutputCache.CacheProfile; duration = config.OutputCache.Duration; }
void ReCreateDispatcherWithConfig(HostSection config) { dispatcher = new RequestPathProvider(webContext, parser, errorHandler, config); handler = new FakeRequestLifeCycleHandler(webContext, dispatcher, adapterProvider, errorHandler, new ConfigurationManagerWrapper { Sections = new ConfigurationManagerWrapper.ContentSectionTable(config, null, null, new EditSection()) }); }
public CacheManager(IWebContext context, IPersister persister, HostSection config) : this(context, persister) { enabled = config.OutputCache.Enabled; varyByParam = config.OutputCache.VaryByParam; varyByHeader = config.OutputCache.VaryByHeader; cacheProfile = config.OutputCache.CacheProfile; duration = config.OutputCache.Duration; invalidationMode = config.OutputCache.InvalidateOnChangesTo; }
public void HostFactoryTypeIsCorrectlyLoadedFromConfig() { // Act RazorWebSectionGroup group = GetRazorGroup(); HostSection host = (HostSection)group.Host; // Assert Assert.NotNull(host); Assert.Equal("System.Web.WebPages.Razor.Test.TestRazorHostFactory, System.Web.WebPages.Razor.Test", host.FactoryType); }
void ReCreateDispatcherWithConfig(HostSection config) { IPersister persister = null; dispatcher = new RequestPathProvider(webContext, parser, errorHandler, config, TestSupport.CreateDraftRepository(ref persister)); handler = new FakeRequestLifeCycleHandler(webContext, dispatcher, adapterProvider, errorHandler, new ConfigurationManagerWrapper { Sections = new ConfigurationManagerWrapper.ContentSectionTable(config, null, null, new EditSection()) }); }
private void SaveConfiguration() { System.Configuration.Configuration cfg = WebConfigurationManager.OpenWebConfiguration("~"); HostSection host = (HostSection)cfg.GetSection("n2/host"); host.RootID = RootId; host.StartPageID = StartId; cfg.Save(); }
public UrlParser(IPersister persister, IWebContext webContext, IHost host, HostSection config) { if (host == null) { throw new ArgumentNullException("host"); } this.persister = persister; this.webContext = webContext; this.host = host; ignoreExistingFiles = config.Web.IgnoreExistingFiles; }
public override void SetUp() { base.SetUp(); config = new HostSection(); config.RootID = 123; config.StartPageID = 234; ctx = new ThreadContext(); host = new Host(ctx, config); root = CreateOneItem <Items.PageItem>(123, "start", null); start = CreateOneItem <Items.PageItem>(234, "start", null); }
public override void SetUp() { base.SetUp(); CreateDefaultStructure(); webContext = new FakeWebContextWrapper("http://www.n2cms.com/"); hostSection = new HostSection { Web = new WebElement { ObserveEmptyExtension = true } }; parser = new UrlParser(persister, webContext, new Host(webContext, startItem.ID, startItem.ID), hostSection); }
public RequestPathProvider(IWebContext webContext, IUrlParser parser, IErrorHandler errorHandler, HostSection config) { this.webContext = webContext; this.parser = parser; this.errorHandler = errorHandler; observeAllExtensions = config.Web.ObserveAllExtensions; rewriteEmptyExtension = config.Web.ObserveEmptyExtension; StringCollection additionalExtensions = config.Web.ObservedExtensions; if (additionalExtensions != null && additionalExtensions.Count > 0) { observedExtensions = new string[additionalExtensions.Count + 1]; additionalExtensions.CopyTo(observedExtensions, 1); } observedExtensions[0] = config.Web.Extension; nonRewritablePaths = config.Web.Urls.NonRewritable.GetPaths(webContext); }
public static IList <Site> ExtractSites(HostSection config) { List <Site> sites = new List <Site>(); foreach (SiteElement configElement in config.Sites) { Site s = new Site(configElement.RootID ?? config.RootID, configElement.ID, configElement.Name); s.Wildcards = configElement.Wildcards || config.Wildcards; foreach (FolderElement folder in configElement.UploadFolders) { s.UploadFolders.Add(folder.Path); } foreach (string key in configElement.Settings.AllKeys) { s.Settings[key] = configElement.Settings[key].Value; } sites.Add(s); } return(sites); }
/// <summary>Creates a new instance of the RequestLifeCycleHandler class.</summary> /// <param name="webContext">The web context wrapper.</param> /// <param name="broker"></param> /// <param name="installer"></param> /// <param name="dispatcher"></param> /// <param name="adapters"></param> /// <param name="errors"></param> /// <param name="editConfig"></param> /// <param name="hostConfig"></param> /// <param name="managementUrls"></param> public RequestLifeCycleHandler(IWebContext webContext, EventBroker broker, InstallationManager installer, RequestPathProvider dispatcher, IContentAdapterProvider adapters, IErrorHandler errors, IEditUrlManager editUrlManager, EditSection editConfig, HostSection hostConfig) { checkInstallation = editConfig.Installer.CheckInstallationStatus; welcomeUrl = editConfig.Installer.WelcomeUrl; managementUrl = editConfig.ManagementInterfaceUrl; rewriteMethod = hostConfig.Web.Rewrite; this.webContext = webContext; this.broker = broker; this.adapters = adapters; this.errors = errors; this.editUrlManager = editUrlManager; this.installer = installer; this.dispatcher = dispatcher; }
void ReCreateDispatcherWithConfig(HostSection config) { dispatcher = new RequestPathProvider(webContext, parser, errorHandler, config); handler = new FakeRequestLifeCycleHandler(webContext, null, dispatcher, adapterProvider, errorHandler, editUrlManager, new EditSection(), config); }
public CachingUrlParserDecorator(IUrlParser inner, IPersister persister, IWebContext webContext, CacheWrapper cache, HostSection config) { this.inner = inner; this.persister = persister; this.webContext = webContext; this.cache = cache; SlidingExpiration = config.OutputCache.SlidingExpiration ?? TimeSpan.FromMinutes(15); }
public MultipleSitesParser(IPersister persister, IWebContext webContext, IHost host, ISitesProvider sitesProvider, HostSection config) : base(persister, webContext, host, config) { if (config == null) { throw new ArgumentNullException("config"); } if (config.DynamicSites) { host.AddSites(sitesProvider.GetSites()); persister.ItemSaved += delegate(object sender, ItemEventArgs e) { if (e.AffectedItem is ISitesSource) { IList <Site> sites = Host.ExtractSites(config); sites = Host.Union(sites, sitesProvider.GetSites()); host.ReplaceSites(host.DefaultSite, sites); } }; } }
public HtmlSanitizer(HostSection config) { encodeHtml = config.HtmlSanitize.EncodeHtml; }
public MultipleSitesParser(IPersister persister, IWebContext webContext, IHost host, N2.Plugin.ConnectionMonitor connections, HostSection config) : base(persister, webContext, host, connections, config) { }
public SafeContentRenderer(HostSection config) { encodeHtml = config.HtmlSanitize.EncodeHtml; }
public MultipleSitesInitializer(IPersister persister, IHost host, ISitesProvider sitesProvider, ConnectionMonitor context, HostSection config, IDefinitionManager ignored) { logger.Debug("MultipleSitesInitializer"); if (config.MultipleSites && config.DynamicSites) { context.Online += delegate { host.AddSites(sitesProvider.GetSites()); persister.ItemSaved += delegate(object sender, ItemEventArgs e) { if (e.AffectedItem is ISitesSource) { IList <Site> sites = Host.ExtractSites(config); sites = Host.Union(sites, sitesProvider.GetSites()); host.ReplaceSites(host.DefaultSite, sites); } }; }; } }
public UrlParser(IPersister persister, IWebContext webContext, IHost host, N2.Plugin.ConnectionMonitor connections, HostSection config) { if (host == null) { throw new ArgumentNullException("host"); } IsOnline = connections.IsConnected ?? true; connections.Online += (s, a) => IsOnline = true; connections.Offline += (s, a) => IsOnline = false; this.persister = persister; this.webContext = webContext; this.host = host; ignoreExistingFiles = config.Web.IgnoreExistingFiles; }
public MultipleSitesParser(IPersister persister, IWebContext webContext, IHost host, HostSection config) : base(persister, webContext, host, config) { Debug.WriteLine("MultipleSitesParser"); }
public Host(IWebContext context, HostSection config) { this.context = context; ReplaceSites(new Site(config.RootID, config.StartPageID), ExtractSites(config)); }
public FakeRequestLifeCycleHandler(IWebContext webContext, InstallationManager installer, RequestPathProvider dispatcher, IContentAdapterProvider adapters, IErrorHandler errors, IEditUrlManager editUrlManager, EditSection editConfig, HostSection hostConfig) : base(webContext, EventBroker.Instance, installer, dispatcher, adapters, errors, editUrlManager, editConfig, hostConfig) { initialized = true; }