private void ConfigManager_Executed(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs args) { if (args.CommandName == "SaveSection") { var section = args.CommandArguments as VirtualPathSettingsConfig; if (section != null) { // Reset the VirtualPathManager whenever we save the VirtualPathConfig section. // This is needed so that our prefixes for the widget templates in the module assembly are taken into account. VirtualPathManager.Reset(); } } }
public void PopulateScriptReferences_ViewsCollection_ConstructScriptReferencesCollection() { // TODO: Reduce class coupling // Arrange string widgetName = "Dummy"; var views = new List <string>(); views.Add("DesignerView.someViewName"); var designerViewConfigs = this.CreateDummyDesignerViewConfigModel(); using (var objFactory = new ObjectFactoryContainerRegion()) { ObjectFactory.Container.RegisterType <ConfigManager, ConfigManager>(typeof(XmlConfigProvider).Name.ToUpperInvariant(), new InjectionConstructor(typeof(XmlConfigProvider).Name)); ObjectFactory.Container.RegisterType <XmlConfigProvider, DummyConfigProvider>(); Config.RegisterSection <VirtualPathSettingsConfig>(); Config.RegisterSection <ControlsConfig>(); Config.RegisterSection <ResourcesConfig>(); using (var factoryReg = new ControllerFactoryRegion <DummyControllerFactory>()) { factoryReg.Factory.ControllerRegistry["Dummy"] = typeof(DummyController); factoryReg.Factory.ControllerRegistry["Designer"] = typeof(DesignerController); var fileResolverPrefix = "~/Frontend-Assembly"; VirtualPathManager.AddVirtualFileResolver <DummyVirtualFileResolver>(fileResolverPrefix + "*", "DummyVirtualFileResolver"); var dummyModel = new DummyDesignerModel(views, new List <string>(), widgetName, Guid.Empty, "someViewName"); try { // Act dummyModel.PopulateScriptReferencesPublic(widgetName, designerViewConfigs); } finally { VirtualPathManager.RemoveVirtualFileResolver(fileResolverPrefix); VirtualPathManager.Reset(); } // Assert Assert.AreEqual(4, dummyModel.ScriptReferences.Count(), "The script count is not as expected."); Assert.IsTrue(dummyModel.ScriptReferences.Contains("Mvc/Scripts/Dummy/designerview-someviewname.js"), "ScriptReferences doesn't contain scripts for the view."); Assert.IsTrue(dummyModel.ScriptReferences.Contains(Script1), "ScriptReferences doesn't contain expected scripts."); Assert.IsTrue(dummyModel.ScriptReferences.Contains(Script2), "ScriptReferences doesn't contain expected scripts."); Assert.IsTrue(dummyModel.ScriptReferences.Contains(Script3), "ScriptReferences doesn't contain expected scripts."); } } }
private static string GenerateVirtualPath(string path) { var virtualPathConfig = Telerik.Sitefinity.Configuration.Config.Get <VirtualPathSettingsConfig>(); VirtualPathElement element = null; virtualPathConfig.VirtualPaths.TryGetValue("~/SFAkismet/*", out element); if (element == null) { var jobsModuleVirtualPathConfig = new VirtualPathElement(virtualPathConfig.VirtualPaths) { VirtualPath = "~/SFAkismet/*", ResolverName = "EmbeddedResourceResolver", ResourceLocation = "AkismetModule" }; virtualPathConfig.VirtualPaths.Add(jobsModuleVirtualPathConfig); ConfigManager.GetManager().SaveSection(virtualPathConfig); VirtualPathManager.Reset(); } return("~/SFAkismet/" + path); }