/// <summary> /// Constructor /// </summary> /// <param name="settings"></param> /// <param name="renderModelFactory"></param> public RenderViewEngine(UmbracoSettings settings, IRenderModelFactory renderModelFactory) { // TODO: Resolve TwoLevelViewCache problems in release builds, as it seems to cache views without taking parent folder into account ViewLocationCache = DefaultViewLocationCache.Null; //if (HttpContext.Current == null || HttpContext.Current.IsDebuggingEnabled) //{ // ViewLocationCache = DefaultViewLocationCache.Null; //} //else //{ // //override the view location cache with our 2 level view location cache // ViewLocationCache = new TwoLevelViewCache(ViewLocationCache); //} _settings = settings; var replaceWithUmbracoFolder = _supplementedViewLocations.ForEach(location => _settings.UmbracoFolders.TemplateFolder + location); var replacePartialWithUmbracoFolder = _supplementedPartialViewLocations.ForEach(location => _settings.UmbracoFolders.TemplateFolder + location); //The Render view engine doesn't support Area's so make those blank ViewLocationFormats = replaceWithUmbracoFolder.ToArray(); PartialViewLocationFormats = replacePartialWithUmbracoFolder.ToArray(); AreaPartialViewLocationFormats = new string[] {}; AreaViewLocationFormats = new string[] {}; }
/// <summary> /// Constructor /// </summary> /// <param name="settings"></param> /// <param name="mapPath">A delegate method used to perform a Server.MapPath operation</param> public DefaultPackageContext(UmbracoSettings settings, Func <string, string> mapPath) { _settings = settings; _pluginInstallFolderPath = mapPath(_settings.PluginConfig.PluginsPath + "/Packages"); _localPackageRepoFolderPath = mapPath(_settings.UmbracoFolders.LocalPackageRepositoryFolder); //create lazy instances of each _localPackageRepository = new Lazy <IPackageRepository>( () => { //create a new path resolver with false as 'useSideBySidePaths' so that it doesn't install with version numbers. var packageFileSys = new PhysicalFileSystem(_localPackageRepoFolderPath); var packagePathResolver = new DefaultPackagePathResolver(packageFileSys, false); return(new LocalPackageRepository(packagePathResolver, packageFileSys, true)); }); _localPackageManager = new Lazy <IPackageManager>( () => { //create a new path resolver with false as 'useSideBySidePaths' so that it doesn't install with version numbers. var packageFileSys = new PhysicalFileSystem(_pluginInstallFolderPath); var packagePathResolver = new DefaultPackagePathResolver(packageFileSys, false); return(new PackageManager(_localPackageRepository.Value, packagePathResolver, packageFileSys)); }); _publicPackageRepository = new Lazy <IPackageRepository>( () => PackageRepositoryFactory.Default.CreateRepository(_settings.PublicPackageRepository.RepositoryAddress)); _publicPackageManager = new Lazy <IPackageManager>( () => new PackageManager(_publicPackageRepository.Value, mapPath(_settings.PluginConfig.PluginsPath + "/Packages"))); }
public override void TearDown() { base.TearDown(); PluginManager.Current.AssembliesToScan = null; UmbracoSettings.ResetSetters(); }
/// <summary> /// /// </summary> /// <param name="hive"></param> /// <param name="settings"></param> /// <param name="frameworkContext"></param> public FakeUmbracoApplicationContext(IHiveManager hive, UmbracoSettings settings, IFrameworkContext frameworkContext) : this(hive) { Hive = hive; Settings = settings; FrameworkContext = frameworkContext; }
public CmsBootstrapper(UmbracoSettings settings, UmbracoAreaRegistration areaRegistration, InstallAreaRegistration installRegistration, IEnumerable <PackageAreaRegistration> componentAreas) { _areaRegistration = areaRegistration; _installRegistration = installRegistration; _componentAreas = componentAreas; _settings = settings; _attributeTypeRegistry = new DependencyResolverAttributeTypeRegistry(); }
public CmsBootstrapper(UmbracoSettings settings, UmbracoAreaRegistration areaRegistration, InstallAreaRegistration installRegistration, IEnumerable <PackageAreaRegistration> componentAreas, IAttributeTypeRegistry attributeTypeRegistry) { _areaRegistration = areaRegistration; _installRegistration = installRegistration; _componentAreas = componentAreas; _attributeTypeRegistry = attributeTypeRegistry; _settings = settings; }
public static void Reset() { UmbracoSettings.ResetSetters(); GlobalSettings.ResetCache(); foreach (var kvp in SavedAppSettings) { ConfigurationManager.AppSettings.Set(kvp.Key, kvp.Value); } // set some defaults that are wrong in the config file?! // this is annoying, really HideTopLevelNodeFromPath = false; }
/// <summary> /// Authenticates the request by reading the FormsAuthentication cookie and setting the /// context and thread principle object /// </summary> /// <param name="sender"></param> /// <param name="e"></param> static void AuthenticateRequest(object sender, EventArgs e) { var app = (HttpApplication)sender; var http = new HttpContextWrapper(app.Context); //we need to determine if the path being requested is an umbraco path, if not don't do anything var settings = UmbracoSettings.GetSettings(); var backOfficeRoutePath = string.Concat(settings.UmbracoPaths.BackOfficePath, "/"); var installerRoutePath = string.Concat("Install", "/"); var routeUrl = ""; var routeData = RouteTable.Routes.GetRouteData(http); if (routeData != null) { var route = routeData.Route as Route; if (route != null) { routeUrl = route.Url; } } if (routeUrl.StartsWith(installerRoutePath, StringComparison.InvariantCultureIgnoreCase) || routeUrl.StartsWith(backOfficeRoutePath, StringComparison.InvariantCultureIgnoreCase)) { if (app.Context.User == null) { if (app.User != null) { //set the principal object app.Context.User = app.User; Thread.CurrentPrincipal = app.User; } else { var ticket = http.GetUmbracoAuthTicket(); if (ticket != null && !ticket.Expired && http.RenewUmbracoAuthTicket()) { //create the Umbraco user identity var identity = new UmbracoBackOfficeIdentity(ticket); //set the principal object var principal = new GenericPrincipal(identity, identity.Roles); app.Context.User = principal; Thread.CurrentPrincipal = principal; } } } } }
public virtual void TearDown() { if (ApplicationContext != null) { if (DatabaseContext != null && DatabaseContext.Database != null) { DatabaseContext.Database.Dispose(); } //reset the app context ApplicationContext.ApplicationCache.ClearAllCache(); } SqlSyntaxContext.SqlSyntaxProvider = null; //legacy API database connection close - because a unit test using PetaPoco db-layer can trigger the usage of SqlHelper we need to ensure that a possible connection is closed. SqlCeContextGuardian.CloseBackgroundConnection(); ApplicationContext.Current = null; Resolution.IsFrozen = false; RepositoryResolver.Reset(); SqlSyntaxProvidersResolver.Reset(); TestHelper.CleanContentDirectories(); string path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", null); SettingsForTests.Reset(); UmbracoSettings.ResetSetters(); try { string filePath = string.Concat(path, "\\UmbracoPetaPocoTests.sdf"); if (File.Exists(filePath)) { File.Delete(filePath); } } catch (Exception ex) { LogHelper.Error <BaseDatabaseFactoryTest>("Could not remove the old database file", ex); //We will swallow this exception! That's because a sub class might require further teardown logic. } }
public static string ResolveLayoutPath(string path, File file) { if (path.StartsWith("~") || path.StartsWith("/")) { path = HttpContext.Current.Server.MapPath(path); } else if (file != null) { path = file.RootedPath.Substring(0, file.RootedPath.LastIndexOf("\\")) + "\\" + path; } else { path = HttpContext.Current.Server.MapPath(UmbracoSettings.GetSettings().UmbracoFolders.TemplateFolder) + "\\" + path; } return(path); }
public override void TearDown() { base.TearDown(); //reset the app context DataTypesResolver.Reset(); ApplicationContext.Current = null; Resolution.IsFrozen = false; PluginManager.Current = null; string path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", null); SerializationService = null; UmbracoSettings.ResetSetters(); }
internal static string GetCurrentNotFoundPageId() { library.GetCurrentDomains(1); var error404 = ""; var error404Node = UmbracoSettings.GetKeyAsNode("/settings/content/errors/error404"); if (error404Node.ChildNodes.Count > 0 && error404Node.ChildNodes[0].HasChildNodes) { // try to get the 404 based on current culture (via domain) XmlNode cultureErrorNode; if (umbraco.cms.businesslogic.web.Domain.Exists(HttpContext.Current.Request.ServerVariables["SERVER_NAME"])) { var d = umbraco.cms.businesslogic.web.Domain.GetDomain(HttpContext.Current.Request.ServerVariables["SERVER_NAME"]); // test if a 404 page exists with current culture cultureErrorNode = error404Node.SelectSingleNode(string.Format("errorPage [@culture = '{0}']", d.Language.CultureAlias)); if (cultureErrorNode != null && cultureErrorNode.FirstChild != null) { error404 = cultureErrorNode.FirstChild.Value; } } else if (error404Node.SelectSingleNode(string.Format("errorPage [@culture = '{0}']", System.Threading.Thread.CurrentThread.CurrentUICulture.Name)) != null) { cultureErrorNode = error404Node.SelectSingleNode(string.Format("errorPage [@culture = '{0}']", System.Threading.Thread.CurrentThread.CurrentUICulture.Name)); if (cultureErrorNode.FirstChild != null) { error404 = cultureErrorNode.FirstChild.Value; } } else { cultureErrorNode = error404Node.SelectSingleNode("errorPage [@culture = 'default']"); if (cultureErrorNode != null && cultureErrorNode.FirstChild != null) { error404 = cultureErrorNode.FirstChild.Value; } } } else { error404 = UmbracoSettings.GetKey("/settings/content/errors/error404"); } return(error404); }
public override void TearDown() { base.TearDown(); //TestHelper.ClearDatabase(); //reset the app context DataTypesResolver.Reset(); ApplicationContext.Current = null; Resolution.IsFrozen = false; RepositoryResolver.Reset(); string path = TestHelper.CurrentAssemblyDirectory; AppDomain.CurrentDomain.SetData("DataDirectory", null); UmbracoSettings.ResetSetters(); }
/// <summary> /// Constructor /// </summary> /// <param name="settings"></param> /// <param name="packageContext"></param> public PluginViewEngine(UmbracoSettings settings, IPackageContext packageContext) { _settings = settings; _packageContext = packageContext; // TODO: Resolve TwoLevelViewCache problems in release builds, as it seems to cache views without taking parent folder into account ViewLocationCache = DefaultViewLocationCache.Null; //if (HttpContext.Current == null || HttpContext.Current.IsDebuggingEnabled) //{ // ViewLocationCache = DefaultViewLocationCache.Null; //} //else //{ // //override the view location cache with our 2 level view location cache // ViewLocationCache = new TwoLevelViewCache(ViewLocationCache); //} SetViewLocations(); }
public UmbracoApplicationContext( //ICmsHiveManager hive, //HiveManager hive, UmbracoSettings settings, IFrameworkContext frameworkContext, ISecurityService securityService) { //Hive = hive; Settings = settings; FrameworkContext = frameworkContext; Security = securityService; //Hive2 = hive2; //Hive2 = DependencyResolver.Current.GetService<HiveManager>(); //TODO: Use this cache mechanism! But in order to do so , we need triggers working from Hive providers, currently they are not setup //clear our status cache when any hive install status changes frameworkContext.TaskManager.AddDelegateTask( TaskTriggers.Hive.InstallStatusChanged, x => _installStatuses = null); }
public FakeUmbracoApplicationContext(IHiveManager hive, bool addSystemRooNode = true) { ApplicationId = Guid.NewGuid(); //_repo = new NHibernateInMemoryRepository(cmsManager.CoreManager.FrameworkContext); Hive = hive; FrameworkContext = Hive.FrameworkContext; //Security = MockRepository.GenerateMock<ISecurityService>(); Security = Substitute.For <ISecurityService>(); Security.GetEffectivePermission(Arg.Any <Guid>(), Arg.Any <HiveId>(), Arg.Any <HiveId>()) .Returns(new PermissionResult(new BackOfficeAccessPermission(), HiveId.Empty, PermissionStatus.Allow)); Security.GetEffectivePermissions(Arg.Any <HiveId>(), Arg.Any <HiveId>(), Arg.Any <Guid[]>()) .Returns(new PermissionResults(new PermissionResult(new BackOfficeAccessPermission(), HiveId.Empty, PermissionStatus.Allow))); if (addSystemRooNode) { //we need to add the root node // Create root node var root = new SystemRoot(); AddPersistenceData(root); } //get the bin folder var binFolder = Common.CurrentAssemblyDirectory; //get settings var settingsFile = new FileInfo(Path.Combine(binFolder, "web.config")); Settings = new UmbracoSettings(settingsFile); //FrameworkContext.Stub(x => x.CurrentLanguage).Return((LanguageInfo) Thread.CurrentThread.CurrentCulture); //FrameworkContext.Stub(x => x.TextManager).Return(MockRepository.GenerateMock<TextManager>()); }
/// <summary>Builds the dependency demands required by this implementation. </summary> /// <param name="builder">The <see cref="IContainerBuilder"/> .</param> /// <param name="builderContext"></param> public void Build(IContainerBuilder builder, IBuilderContext builderContext) { //raise the building event OnContainerBuilding(new ContainerBuilderEventArgs(builder)); //register all of the abstract web types builder.AddDependencyDemandBuilder(new WebTypesDemandBuilder(_httpApp)); var typeFinder = new TypeFinder(); builder.ForInstanceOfType(typeFinder) .ScopedAs.Singleton(); //register the umbraco settings builder.ForFactory(x => UmbracoSettings.GetSettings()) .KnownAsSelf() .ScopedAs.Singleton(); //only have one instance ever //register our MVC types builder.AddDependencyDemandBuilder(new MvcTypesDemandBuilder(typeFinder)); // Register the IRoutableRequestContext builder.For <HttpRequestScopedCache>().KnownAs <AbstractScopedCache>().ScopedAs.Singleton(); builder.For <HttpRuntimeApplicationCache>().KnownAs <AbstractApplicationCache>().ScopedAs.Singleton(); builder.For <HttpRequestScopedFinalizer>().KnownAs <AbstractFinalizer>().ScopedAs.Singleton(); builder.For <DefaultFrameworkContext>().KnownAs <IFrameworkContext>().ScopedAs.Singleton(); builder.For <UmbracoApplicationContext>().KnownAs <IUmbracoApplicationContext>().ScopedAs.Singleton(); builder.For <RoutableRequestContext>().KnownAs <IRoutableRequestContext>().ScopedAs.HttpRequest(); builder.For <DefaultBackOfficeRequestContext>().KnownAs <IBackOfficeRequestContext>().ScopedAs.HttpRequest(); // TODO: Ensure this isn't created manually anywhere but tests, only via a factory: builder.ForType<IUmbracoRenderModel, UmbracoRenderContext>().Register().ScopedPerHttpRequest(); builder.For <DefaultRenderModelFactory>().KnownAs <IRenderModelFactory>(). ScopedAs.Singleton(); // Register Hive provider //builder.AddDependencyDemandBuilder(new HiveDemandBuilder()); builder.AddDependencyDemandBuilder(new Hive.DemandBuilders.HiveDemandBuilder()); // Register Persistence provider loader //builder.AddDependencyDemandBuilder(new Framework.Persistence.DependencyManagement.DemandBuilders.LoadFromPersistenceConfig()); builder.AddDependencyDemandBuilder(new Hive.DemandBuilders.LoadFromPersistenceConfig()); // Register Cms bootstrapper // TODO: Split UmbracoContainerBuilder between Cms and Frontend variants / needs builder.For <CmsBootstrapper>().KnownAsSelf(); // Register Frontend bootstrapper builder.ForFactory( x => new RenderBootstrapper( x.Resolve <IUmbracoApplicationContext>(), x.Resolve <IRouteHandler>(RenderRouteHandler.SingletonServiceName), x.Resolve <IRenderModelFactory>()) ) .KnownAsSelf(); //register all component areas, loop through all found package folders //TODO: All other places querying for packages use the NuGet IO FileManager stuff, not the standard .Net IO classes var pluginFolder = new DirectoryInfo(_httpApp.Server.MapPath(_settings.PluginConfig.PluginsPath)); foreach (var package in pluginFolder.GetDirectories(PluginManager.PackagesFolderName) .SelectMany(x => x.GetDirectories() .Where(PluginManager.IsPackagePluginFolder))) { //register an area for this package builder.For <PackageAreaRegistration>() .KnownAsSelf() .WithNamedParam("packageFolder", package); } //register the RoutingEngine builder .For <DefaultRoutingEngine>() .KnownAs <IRoutingEngine>() .ScopedAs.HttpRequest(); //register the package context builder .ForFactory(x => new DefaultPackageContext(x.Resolve <UmbracoSettings>(), HostingEnvironment.MapPath)) //.For<DefaultPackageContext>() .KnownAs <IPackageContext>() .ScopedAs.Singleton(); //register the PropertyEditorFactory builder.For <PropertyEditorFactory>() .KnownAs <IPropertyEditorFactory>() .ScopedAs.Singleton(); //register the ParameterEditorFactory builder.For <ParameterEditorFactory>() .KnownAs <IParameterEditorFactory>() .ScopedAs.Singleton(); //register the SecurityService builder.For <SecurityService>() .KnownAs <ISecurityService>(); //register the CmsAttributeTypeRegistry builder.For <CmsAttributeTypeRegistry>() .KnownAs <IAttributeTypeRegistry>() .ScopedAs.Singleton(); //component registration _componentRegistrar.RegisterTasks(builder, typeFinder); _componentRegistrar.RegisterTreeControllers(builder, typeFinder); _componentRegistrar.RegisterPropertyEditors(builder, typeFinder); _componentRegistrar.RegisterParameterEditors(builder, typeFinder); _componentRegistrar.RegisterEditorControllers(builder, typeFinder); _componentRegistrar.RegisterMenuItems(builder, typeFinder); _componentRegistrar.RegisterSurfaceControllers(builder, typeFinder); _componentRegistrar.RegisterDashboardFilters(builder, typeFinder); _componentRegistrar.RegisterDashboardMatchRules(builder, typeFinder); _componentRegistrar.RegisterPermissions(builder, typeFinder); _componentRegistrar.RegisterMacroEngines(builder, typeFinder); //register the registrations builder.For <ComponentRegistrations>().KnownAsSelf(); //register task manager builder.For <ApplicationTaskManager>().KnownAsSelf().ScopedAs.Singleton(); //register our model mappings and resolvers builder.AddDependencyDemandBuilder(new ModelMappingsDemandBuilder()); //TODO: More stuff should happen with the TextManager here (e.g. db access and whatnot) //The user may later override settings, most importantly the LocalizationConfig.CurrentTextManager delegate to implement different environments //The text manager is assumed to be set up by the framework var textManager = LocalizationConfig.TextManager; LocalizationWebConfig.ApplyDefaults <TWebApp>(textManager, overridesPath: "~/App_Data/Umbraco/LocalizationEntries.xml"); LocalizationWebConfig.SetupMvcDefaults(setupMetadata: false); //The name of the assembly that contains common texts textManager.FallbackNamespaces.Add("Umbraco.Cms.Web"); OnContainerBuildingComplete(new ContainerBuilderEventArgs(builder)); }
/// <summary> /// Returns the editor url using the default action /// </summary> /// <param name="url">The URL.</param> /// <param name="id">The id.</param> /// <param name="editorId">The editor id.</param> /// <param name="preResolvedComponentRegistrations">The pre resolved component registrations.</param> /// <param name="preResovledSettings"></param> /// <returns></returns> public static string GetEditorUrl(this UrlHelper url, HiveId id, Guid editorId, ComponentRegistrations preResolvedComponentRegistrations, UmbracoSettings preResovledSettings) { return(url.GetEditorUrl("Edit", id, editorId, preResolvedComponentRegistrations, preResovledSettings)); }
public void TearDown() { UmbracoSettings.ResetSetters(); }
public static string GetEditorUrl(this UrlHelper url, string action, Guid editorId, object actionParams, ComponentRegistrations preResolvedComponentRegistrations, UmbracoSettings preResovledSettings) { var editorMetaData = preResolvedComponentRegistrations .EditorControllers .Where(x => x.Metadata.Id == editorId) .SingleOrDefault(); if (editorMetaData == null) { throw new InvalidOperationException("Could not find the editor controller with id " + editorId); } var routeValDictionary = new RouteValueDictionary(actionParams); routeValDictionary["editorId"] = editorId.ToString("N"); var area = preResovledSettings.UmbracoPaths.BackOfficePath; //now, need to figure out what area this editor belongs too... var pluginDefinition = editorMetaData.Metadata.PluginDefinition; if (pluginDefinition.HasRoutablePackageArea()) { area = pluginDefinition.PackageName; } //add the plugin area to our collection routeValDictionary["area"] = area; var resolvedUrl = url.Action(action, editorMetaData.Metadata.ControllerName, routeValDictionary); return(resolvedUrl); }
/// <summary> /// Returns the full unique url for an Editor /// </summary> /// <param name="url">The URL.</param> /// <param name="action">The action.</param> /// <param name="id">A HiveId object or null if no id is required</param> /// <param name="editorId">The editor id.</param> /// <param name="preResolvedComponentRegistrations">The pre resolved component registrations.</param> /// <param name="preResovledSettings"></param> /// <returns></returns> public static string GetEditorUrl(this UrlHelper url, string action, HiveId?id, Guid editorId, ComponentRegistrations preResolvedComponentRegistrations, UmbracoSettings preResovledSettings) { var idVal = GetIdVal(id); return(url.GetEditorUrl(action, editorId, new { id = idVal }, preResolvedComponentRegistrations, preResovledSettings)); }
public InstallAreaRegistration(UmbracoSettings umbracoSettings) { _umbracoSettings = umbracoSettings; }
public static void Initialize() { using (new WriteLockDisposable(Locker)) { using (DisposableTimer.TraceDuration <PluginManager>("Start Initialise", "End Initialise")) { var settings = UmbracoSettings.GetSettings(); // TODO: Add verbose exception handling / raising here since this is happening on app startup and could // prevent app from starting altogether var pluginFolder = new DirectoryInfo(HostingEnvironment.MapPath(settings.PluginConfig.PluginsPath)); _shadowCopyFolder = new DirectoryInfo(HostingEnvironment.MapPath(settings.PluginConfig.ShadowCopyPath)); var referencedPlugins = new List <PluginDefinition>(); var pluginFiles = Enumerable.Empty <FileInfo>(); try { LogHelper.TraceIfEnabled <PluginManager>("Creating shadow copy folder and querying for dlls"); //ensure folders are created Directory.CreateDirectory(pluginFolder.FullName); Directory.CreateDirectory(_shadowCopyFolder.FullName); Directory.CreateDirectory(Path.Combine(pluginFolder.FullName, PackagesFolderName)); //get list of all DLLs in bin var binFiles = _shadowCopyFolder.GetFiles("*.dll", SearchOption.AllDirectories); //get list of all DLLs in plugins (not in bin!) //this will match the plugin folder pattern pluginFiles = pluginFolder.GetFiles("*.dll", SearchOption.AllDirectories) //just make sure we're not registering shadow copied plugins .Where(x => !binFiles.Select(q => q.FullName).Contains(x.FullName)) .Where(x => x.Directory.Parent != null && (IsPackagePluginBinFolder(x.Directory))) .ToList(); //clear out shadow copied plugins foreach (var f in binFiles) { LogHelper.TraceIfEnabled <PluginManager>("Deleting {0}", () => f.Name); File.Delete(f.FullName); } } catch (Exception ex) { var fail = new ApplicationException("Could not initialise plugin folder", ex); LogHelper.Error <PluginManager>(fail.Message, fail); //throw fail; } try { LogHelper.TraceIfEnabled <PluginManager>("Shadow copying assemblies"); //shadow copy files referencedPlugins .AddRange(pluginFiles.Select(plug => new PluginDefinition(plug, GetPackageFolderFromPluginDll(plug), PerformFileDeploy(plug), plug.Directory.Parent.Name == "Core"))); } catch (Exception ex) { var fail = new ApplicationException("Could not initialise plugin folder", ex); LogHelper.Error <PluginManager>(fail.Message, fail); //throw fail; } ReferencedPlugins = referencedPlugins; } } }
/// <summary> /// Default constructor that uses the standard UmbracoComponentRegistrar as the IComponentRegistrar /// </summary> /// <param name="httpApp"></param> public UmbracoContainerBuilder(TWebApp httpApp) { _httpApp = httpApp; _settings = UmbracoSettings.GetSettings(); _componentRegistrar = new UmbracoComponentRegistrar(); }
/// <summary> /// Custom constructor that can be used to assign a custom IComponentRegistrar /// </summary> /// <param name="httpApp"></param> /// <param name="componentRegistrar"></param> /// <param name="settings"></param> public UmbracoContainerBuilder(TWebApp httpApp, IComponentRegistrar componentRegistrar, UmbracoSettings settings) { _httpApp = httpApp; _componentRegistrar = componentRegistrar; _settings = settings; }
public IDictionary <string, string> GetData() { return(UmbracoSettings.GetSettings().Applications.ToDictionary(x => x.Alias, y => y.Name)); }
//[Obsolete] //public (string, string) GetApiSettings() //{ // AddApiSettings(); // return (configuration.AppSettings.Settings["TotalCode.Admin.AppId"].Value, configuration.AppSettings.Settings["TotalCode.Admin.ApiKey"].Value); //} public ApiSettings GetApiSettings() { var settings = new ApiSettings(); // web.config settings var keys = Configuration.AppSettings.Settings.AllKeys.Where(x => x.Contains("TotalCode.Admin.")); foreach (var key in keys) { settings.Add(new ApiSetting { Key = key, Value = Configuration.AppSettings.Settings[key].Value, SettingType = ApiSettingType.AppSettings }); } var customErrorsSection = (CustomErrorsSection)Configuration.GetSection( "system.web/customErrors"); var customErrorsMode = new ApiSetting { Key = "Mode", Value = customErrorsSection.Mode.ToString(), SettingType = ApiSettingType.CustomErrors }; var customErrorsDefaultRedirect = new ApiSetting { Key = "DefaultRedirect", Value = customErrorsSection.DefaultRedirect, SettingType = ApiSettingType.CustomErrors }; var customErrors500Error = new ApiSetting { Key = "500Error", Value = customErrorsSection.Errors["500"] != null ? customErrorsSection.Errors["500"].Redirect : "", SettingType = ApiSettingType.CustomErrors }; settings.Add(customErrorsMode); settings.Add(customErrorsDefaultRedirect); settings.Add(customErrors500Error); // Get Umbraco settings var error404 = new ApiSetting { Key = "error404", Value = UmbracoSettings.Descendants("error404").First().Value, SettingType = ApiSettingType.UmbracoConfig }; var notificationEmail = new ApiSetting { Key = "email", Value = UmbracoSettings.Descendants("email").First().Value, SettingType = ApiSettingType.UmbracoConfig }; var loginBackgroundImage = new ApiSetting { Key = "loginBackgroundImage", Value = UmbracoSettings.Descendants("loginBackgroundImage").First().Value, SettingType = ApiSettingType.UmbracoConfig }; // Client dependency Settings var clientDepenency = new ApiSetting { Key = "clientDependency", Value = ClientDependency.Descendants("clientDependency").Attributes().Single(x => x.Name == "version").Value, SettingType = ApiSettingType.ClientDependency }; settings.Add(error404); settings.Add(notificationEmail); settings.Add(loginBackgroundImage); settings.Add(clientDepenency); return(settings); }
public void EditApiSettings(ApiSettings settings) { foreach (var setting in settings) { switch (setting.SettingType) { case ApiSettingType.AppSettings: Configuration.AppSettings.Settings[setting.Key].Value = setting.Value; Configuration.Save(ConfigurationSaveMode.Modified); break; case ApiSettingType.CustomErrors: var customErrorsSection = (CustomErrorsSection)Configuration.GetSection("system.web/customErrors"); if (setting.Key == "Mode") { customErrorsSection.Mode = (CustomErrorsMode)Enum.Parse(typeof(CustomErrorsMode), setting.Value); } else if (setting.Key == "DefaultRedirect") { customErrorsSection.DefaultRedirect = setting.Value; } else if (setting.Key == "500Error") { if (string.IsNullOrEmpty(setting.Value)) { customErrorsSection.Errors.Remove("500"); } else { if (customErrorsSection.Errors["500"] == null) { customErrorsSection.Errors.Add(new CustomError(500, setting.Value)); } else { customErrorsSection.Errors["500"].Redirect = setting.Value; } } } Configuration.Save(ConfigurationSaveMode.Modified); break; case ApiSettingType.ClientDependency: ClientDependency.Descendants("clientDependency").Attributes().Single(x => x.Name == "version").Value = setting.Value; ClientDependency.Save(HttpContext.Current.Server.MapPath(CLIENT_DEPENDENCY_PATH)); break; case ApiSettingType.UmbracoConfig: if (setting.Key == "error404") { UmbracoSettings.Descendants("error404").First().Value = setting.Value; } else if (setting.Key == "loginBackgroundImage") { UmbracoSettings.Descendants("loginBackgroundImage").First().Value = setting.Value; } else if (setting.Key == "email") { UmbracoSettings.Descendants("email").First().Value = setting.Value; } UmbracoSettings.Save(HttpContext.Current.Server.MapPath(UMBRACO_SETTINGS_PATH)); break; default: break; } } settings.LoadConfigurationsIntoMemory(); }
public DocumentTypeIconFileResolver(HttpServerUtilityBase server, UmbracoSettings settings, UrlHelper url) : base(new DirectoryInfo(server.MapPath(settings.UmbracoFolders.DocTypeIconFolder)), url) { }
/// <summary> /// Initializes a new instance of the <see cref="UrlProvider"/> class with an Umbraco context and a list of url providers. /// </summary> /// <param name="umbracoContext">The Umbraco context.</param> /// <param name="urlProviders">The list of url providers.</param> internal UrlProvider(UmbracoContext umbracoContext, IEnumerable <IUrlProvider> urlProviders) { _umbracoContext = umbracoContext; _urlProviders = urlProviders; Mode = UmbracoSettings.For <Configuration.WebRouting>().UrlProviderMode; }