public void Harvest(string extensionId) { var extensionDescriptor = _extensionManager.GetExtension(extensionId); if (extensionDescriptor == null) { Context.Output.WriteLine(T("Could not discover recipes because extension '{0}' was not found.", extensionId)); return; } var recipes = _recipeHarvester.HarvestRecipes(extensionId); if (recipes.Count() == 0) { Context.Output.WriteLine(T("No recipes found for extension '{0}'.", extensionId)); return; } Context.Output.WriteLine(T("List of available recipes")); Context.Output.WriteLine(T("--------------------------")); Context.Output.WriteLine(); foreach (var recipe in recipes) { Context.Output.WriteLine(T("Recipe: {0}", recipe.Name)); Context.Output.WriteLine(T(" Version: {0}", recipe.Version)); Context.Output.WriteLine(T(" Tags: {0}", recipe.Tags)); Context.Output.WriteLine(T(" Description: {0}", recipe.Description)); Context.Output.WriteLine(T(" Author: {0}", recipe.Author)); Context.Output.WriteLine(T(" Website: {0}", recipe.WebSite)); } }
public void HarvestRecipes(string extensionId) { ExtensionDescriptor extensionDescriptor = _extensionManager.GetExtension(extensionId); if (extensionDescriptor == null) { throw new OrchardException(T("Could not discover recipes because module '{0}' was not found.", extensionId)); } IEnumerable <Recipe> recipes = _recipeHarvester.HarvestRecipes(extensionId); if (recipes == null) { throw new OrchardException(T("No recipes found for extension {0}.", extensionId)); } Context.Output.WriteLine(T("List of available recipes")); Context.Output.WriteLine(T("--------------------------")); Context.Output.WriteLine(); foreach (Recipe recipe in recipes) { Context.Output.WriteLine(T("Recipe: {0}", recipe.Name)); Context.Output.WriteLine(T(" Version: {0}", recipe.Version)); Context.Output.WriteLine(T(" Tags: {0}", recipe.Tags)); Context.Output.WriteLine(T(" Description: {0}", recipe.Description)); Context.Output.WriteLine(T(" Author: {0}", recipe.Author)); Context.Output.WriteLine(T(" Website: {0}", recipe.WebSite)); } }
public ExtensionDescriptor GetRequestTheme(RequestContext requestContext) { var requestThemes = themeSelectors .Select(x => x.GetTheme(requestContext)) .Where(x => x != null) .OrderByDescending(x => x.Priority); if (!requestThemes.Any()) { return(extensionManager.GetExtension("Default")); } foreach (var theme in requestThemes) { var t = extensionManager.GetExtension(theme.Name); if (t != null && t.Name == "Dashboard" && theme.IsDashboard) { return(t); } if (t != null && shellDescriptor.Features.Any(x => x.Name == t.Id) && !theme.IsDashboard) { return(t); } } return(extensionManager.GetExtension("Default")); }
public void DisableThemeFeatures(string themeName) { var themes = new Queue <string>(); while (themeName != null) { if (themes.Contains(themeName)) { throw new InvalidOperationException(T("The theme \"{0}\" is already in the stack of themes that need features disabled.", themeName).Text); } var theme = _extensionManager.GetExtension(themeName); if (theme == null) { break; } themes.Enqueue(themeName); themeName = !string.IsNullOrWhiteSpace(theme.BaseTheme) ? theme.BaseTheme : null; } var currentTheme = _siteThemeService.GetCurrentThemeName(); while (themes.Count > 0) { var themeId = themes.Dequeue(); // Not disabling base theme if it's the current theme. if (themeId != currentTheme) { _featureManager.DisableFeatures(new[] { themeId }); } } }
public async Task DisableThemeFeaturesAsync(string themeName) { var themes = new Queue <string>(); while (themeName != null) { if (themes.Contains(themeName)) { throw new InvalidOperationException(H["The theme \"{0}\" is already in the stack of themes that need features disabled.", themeName].ToString()); } var theme = _extensionManager.GetExtension(themeName); if (theme == null) { break; } themes.Enqueue(themeName); themeName = !string.IsNullOrWhiteSpace(theme.Manifest.Name) ? theme.Manifest.Name : null; } var currentTheme = await _siteThemeService.GetCurrentThemeNameAsync(); while (themes.Count > 0) { var themeId = themes.Dequeue(); // Not disabling base theme if it's the current theme. if (themeId != currentTheme) { await DisableFeaturesAsync(new[] { themeId }, true); } } }
public IEnumerable <Recipe> HarvestRecipes(string extensionId) { var recipes = new List <Recipe>(); var extension = _extensionManager.GetExtension(extensionId); if (extension != null) { var recipeLocation = Path.Combine(extension.Location, extensionId, "Recipes"); var recipeFiles = _webSiteFolder.ListFiles(recipeLocation, true); recipeFiles.Where(r => r.EndsWith(".recipe.xml", StringComparison.OrdinalIgnoreCase)).ToList().ForEach(r => { try { recipes.Add(_recipeParser.ParseRecipe(_webSiteFolder.ReadFile(r))); } catch (Exception ex) { Logger.Error(ex, "Error while parsing recipe file '{0}'.", r); } }); } else { Logger.Error("Could not discover recipes because module '{0}' was not found.", extensionId); } return(recipes); }
public async Task <ExtensionDescriptor> GetThemeAsync() { // For performance reason, processes the current theme only once per scope (request). // This can't be cached as each request gets a different value. if (_theme == null) { var allThemeResults = await Task.WhenAll(_themeSelectors.Select(async x => await x.GetThemeAsync().ConfigureAwait(false))).ConfigureAwait(false); var requestTheme = allThemeResults .Where(x => x != null) .OrderByDescending(x => x.Priority) .ToList(); if (requestTheme.Count == 0) { return(null); } // Try to load the theme to ensure it's present foreach (var theme in requestTheme) { var t = _extensionManager.GetExtension(theme.ThemeName); if (t != null) { return(_theme = t); } } // No valid theme. Don't save the result right now. return(null); } return(_theme); }
public IEnumerable <string> GetZones() { var theme = _siteThemeService.GetSiteTheme(); IEnumerable <string> zones = new List <string>(); // get the zones for this theme if (theme.Zones != null) { zones = theme.Zones.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()) .Distinct() .ToList(); } // if this theme has no zones defined then walk the BaseTheme chain until we hit a theme which defines zones while (!zones.Any() && theme != null && !string.IsNullOrWhiteSpace(theme.BaseTheme)) { string baseTheme = theme.BaseTheme; theme = _extensionManager.GetExtension(baseTheme); if (theme != null && theme.Zones != null) { zones = theme.Zones.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => x.Trim()) .Distinct() .ToList(); } } return(zones); }
/// <inheritdoc /> public virtual IEnumerable <string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable <string> viewLocations) { if (context.ActionContext.ActionDescriptor is PageActionDescriptor page) { var pageViewLocations = PageViewLocations().ToList(); pageViewLocations.AddRange(viewLocations); return(pageViewLocations); IEnumerable <string> PageViewLocations() { yield return(page.RelativePath.Substring(0, page.RelativePath.IndexOf("/Pages/")) + "/Views/Shared/{0}" + RazorViewEngine.ViewExtension); } } // Get Extension, and then add in the relevant views. var extension = _extensionManager.GetExtension(context.AreaName); if (!extension.Exists) { return(viewLocations); } var result = new List <string>(); var extensionViewsPath = '/' + extension.SubPath.Replace('\\', '/').Trim('/') + "/Views"; result.Add(extensionViewsPath + "/{1}/{0}" + RazorViewEngine.ViewExtension); result.Add(extensionViewsPath + "/Shared/{0}" + RazorViewEngine.ViewExtension); result.AddRange(viewLocations); return(result); }
private IEnumerable <string> ExtractLayoutNames(ExtensionDescriptor theme) { var views = Directory.EnumerateFiles(HttpContext.Current.Server.MapPath( string.Format("{0}/{1}/Views/", theme.Location, theme.Name.Replace(" ", ""))), "*.cshtml").Select(template => { var f = new FileInfo(template); if (f.Name.StartsWith("Layout-")) { string fname = f.Name.Replace("Layout-", "") .Replace("-", " ") .Replace(f.Extension, ""); if (fname.Length > 0) { return(fname); } } return(null); }).Where(n => n != null); // Traverse base themes if (!String.IsNullOrWhiteSpace(theme.BaseTheme)) { var baseTheme = _extensionManager.GetExtension(theme.BaseTheme); // Concat not Union since Distinct is enforce in service anyway views = views.Concat(ExtractLayoutNames(baseTheme)); } return(views); }
public TransformalizeResponse Run(TransformalizeRequest request) { var moduleVersion = _extensionManager.GetExtension("Transformalize.Orchard").Version; var logger = new TransformalizeLogger(request.Part.Title(), request.Part.LogLevel, Logger, OrchardVersion, moduleVersion); var processes = new List <Process>(); //transitioning to using TflRoot instead of string configuration if (request.Root != null) { processes.AddRange(ProcessFactory.Create(request.Root, logger, request.Options)); } else //legacy { processes.AddRange(ProcessFactory.Create(request.Configuration, logger, request.Options, request.Query)); } for (var i = 0; i < processes.Count; i++) { var process = processes[i]; CreateInputOperation(process, request); process.ExecuteScaler(); } return(new TransformalizeResponse() { Processes = processes.ToArray(), Log = logger.Dump().ToList() }); }
public IEnumerable <string> GetZones(ExtensionDescriptor theme) { IEnumerable <string> zones = new List <string>(); // get the zones for this theme if (theme.Zones != null) { zones = theme.Zones.Split(',') .Distinct() .Select(x => x.Trim()) .ToList(); } // if this theme has no zones defined then walk the BaseTheme chain until we hit a theme which defines zones while (zones.Count() == 0 && theme != null && !string.IsNullOrWhiteSpace(theme.BaseTheme)) { string baseTheme = theme.BaseTheme; theme = _extensionManager.GetExtension(baseTheme); if (theme != null && theme.Zones != null) { zones = theme.Zones.Split(',') .Distinct() .Select(x => x.Trim()) .ToList(); } } return(zones); }
public ExtensionDescriptor GetSiteTheme() { var site = _workContextAccessor.GetContext().CurrentSite; string currentThemeName = site.As <ThemeSiteSettingsPart>().CurrentThemeName; return(string.IsNullOrEmpty(currentThemeName) ? null : _extensionManager.GetExtension(currentThemeName)); }
/// <summary> /// 获取当前请求的主题。 /// </summary> /// <param name="requestContext">请求上下文。</param> /// <returns>主题。</returns> public ExtensionDescriptorEntry GetRequestTheme(RequestContext requestContext) { var requestTheme = _themeSelectors .Select(x => x.GetTheme(requestContext)) .Where(x => x != null) .OrderByDescending(x => x.Priority); if (!requestTheme.Any()) { return(null); } var theme = requestTheme.Select(t => _extensionManager.GetExtension(t.ThemeName)).FirstOrDefault(t => t != null); return(theme ?? _extensionManager.GetExtension("SafeMode")); }
public AdminController(IOrchardServices orchardServices, IExtensionManager extensionManager, ILightboxService lightboxService) { _orchardServices = orchardServices; var moduleDescriptor = extensionManager.GetExtension("Duk.Lightbox.Orchard"); _modulePath = VirtualPathUtility.AppendTrailingSlash(VirtualPathUtility.Combine( VirtualPathUtility.AppendTrailingSlash(VirtualPathUtility.ToAbsolute(moduleDescriptor.Location)), moduleDescriptor.Path)); _lightboxService = lightboxService; }
public async Task <ExtensionDescriptor> GetSiteThemeAsync() { string currentThemeName = await GetCurrentThemeNameAsync(); if (String.IsNullOrEmpty(currentThemeName)) { return(null); } return(_extensionManager.GetExtension(currentThemeName)); }
public async Task <IExtensionInfo> GetAdminThemeAsync() { string currentThemeName = await GetAdminThemeNameAsync(); if (String.IsNullOrEmpty(currentThemeName)) { return(null); } return(_extensionManager.GetExtension(currentThemeName)); }
public async Task <IEnumerable <RecipeDescriptor> > HarvestRecipesAsync(string extensionId) { var descriptor = _extensionManager.GetExtension(extensionId); if (descriptor != null) { return(await HarvestRecipesAsync(descriptor)); } Logger.LogError(T["Could not discover recipes because extension '{0}' was not found.", extensionId]); return(Enumerable.Empty <RecipeDescriptor>()); }
public Task <IEnumerable <RecipeDescriptor> > HarvestRecipesAsync(string extensionId) { var descriptor = _extensionManager.GetExtension(extensionId); if (descriptor.Exists) { return(Task.FromResult(HarvestRecipes(descriptor))); } Logger.LogError(T["Could not discover recipes because extension '{0}' was not found.", extensionId]); return(Task.FromResult(Enumerable.Empty <RecipeDescriptor>())); }
public IEnumerable <Recipe> HarvestRecipes(string extensionId) { var extension = _extensionManager.GetExtension(extensionId); if (extension != null) { return(HarvestRecipes(extension)); } Logger.Error("Could not discover recipes because module '{0}' was not found.", extensionId); return(Enumerable.Empty <Recipe>()); }
/// <summary> /// 删除程序集。 /// </summary> /// <param name="moduleName">模块名称。</param> public void DeleteAssembly(string moduleName) { var descriptor = _extensionManager.GetExtension(moduleName); if (descriptor == null) { return; } /* var paths = GetModuleAssemblyPaths(descriptor); * if (paths == null) * return; * * foreach (var assembly in paths.Select(item => item.Key)) * { * Logger.Information("为模块 \"{0}\" 删除来自探测目录的程序集", moduleName); * DeleteAssembly(assembly); * }*/ Logger.Information("为模块 \"{0}\" 删除来自探测目录的程序集", moduleName); DeleteAssembly(new AssemblyDescriptor(moduleName)); }
public void BuildManifests(ResourceManifestBuilder builder) { var manifest = builder.Add(); manifest.DefineStyle("WorkflowsAdmin").SetUrl("orchard-workflows-admin.css").SetDependencies("~/Themes/TheAdmin/Styles/Site.css"); manifest.DefineScript("jsPlumb").SetUrl("jquery.jsPlumb-1.4.1-all-min.js").SetDependencies("jQueryUI"); // Trying to find a matching activity CSS for each activity in the extensions they come from. var resourceNamesAndPaths = _cacheManager.Get("Orchard.Workflows.ActivityResourceNames", context => { var resourceNameAndPathList = new List <Tuple <string, string> >(); foreach (var activity in _activitiesManager.Value.GetActivities()) { var assemblyName = activity.GetType().Assembly.GetName().Name; var extension = _extensionManager.GetExtension(assemblyName); if (extension == null) { continue; } var stylesPath = _virtualPathProvider.Combine(extension.VirtualPath, "Styles"); var resourceName = "WorkflowsActivity-" + activity.Name; var filename = resourceName.HtmlClassify() + ".css"; var filePath = _virtualPathProvider.Combine(_hostEnvironment.MapPath(stylesPath), filename); if (File.Exists(filePath)) { /* Since stylesheets are shapes, we don't need to create the resource with the full path to the CSS file, * because extensions can override those shapes by file name if they reference Orchard.Workflows, * even when they don't exist in Orchard.Workflows. */ resourceNameAndPathList.Add(Tuple.Create(resourceName, filename)); } } return(resourceNameAndPathList); }); foreach (var resourceNameAndPath in resourceNamesAndPaths) { manifest .DefineStyle(resourceNameAndPath.Item1) .SetUrl(resourceNameAndPath.Item2) .SetDependencies("WorkflowsAdmin"); } manifest .DefineStyle("WorkflowsActivities") .SetDependencies(resourceNamesAndPaths.Select(resourceNameAndPath => resourceNameAndPath.Item1).ToArray()); }
public ExtensionDescriptor GetRequestTheme(RequestContext requestContext) { var requestTheme = _themeSelectors .Select(x => x.GetTheme(requestContext)) .Where(x => x != null) .OrderByDescending(x => x.Priority).ToList(); if (!requestTheme.Any()) { return(null); } foreach (var theme in requestTheme) { var t = _extensionManager.GetExtension(theme.ThemeName); if (t != null) { return(t); } } return(_extensionManager.GetExtension("SafeMode")); }
public ApiController( ITransformalizeService transformalize, IApiService apiService, IExtensionManager extensionManager, IJobsQueueService jobQueueService ) { _stopwatch.Start(); _transformalize = transformalize; _apiService = apiService; _jobQueueService = jobQueueService; _moduleVersion = extensionManager.GetExtension("Transformalize.Orchard").Version; T = NullLocalizer.Instance; Logger = NullLogger.Instance; }
public async Task <IExtensionInfo> GetThemeAsync() { // 由于性能原因,每个域(请求)只处理当前主题一次。 //这不能缓存,因为每个请求获得不同的值。 // For performance reason, processes the current theme only once per scope (request). // This can't be cached as each request gets a different value. if (_theme == null) { var themeResults = new List <ThemeSelectorResult>(); foreach (var themeSelector in _themeSelectors) { var themeResult = await themeSelector.GetThemeAsync(); if (themeResult != null) { themeResults.Add(themeResult); } } themeResults.Sort((x, y) => y.Priority.CompareTo(x.Priority)); if (themeResults.Count == 0) { return(null); } // Try to load the theme to ensure it's present尝试加载主题,以确保它的存在。 foreach (var theme in themeResults) { var t = _extensionManager.GetExtension(theme.ThemeName); if (t.Exists) { return(_theme = new ThemeExtensionInfo(t)); } } // No valid theme. Don't save the result right now. return(null); } return(_theme); }
public IEnumerable <Recipe> HarvestRecipes(string extensionId) { var recipes = new List <Recipe>(); var extension = _extensionManager.GetExtension(extensionId); if (extension != null) { var recipeLocation = Path.Combine(extension.Location, extensionId, "Recipes"); var recipeFiles = _webSiteFolder.ListFiles(recipeLocation, true); recipes.AddRange( from recipeFile in recipeFiles where recipeFile.EndsWith(".recipe.xml", StringComparison.OrdinalIgnoreCase) select _recipeParser.ParseRecipe(_webSiteFolder.ReadFile(recipeFile))); } else { Logger.Error("Could not discover recipes because module '{0}' was not found.", extensionId); } return(recipes); }
public async Task <ExtensionDescriptor> GetThemeAsync() { // For performance reason, processes the current theme only once per scope (request). // This can't be cached as each request gets a different value. if (_theme == null) { var themeResults = new List <ThemeSelectorResult>(); foreach (var themeSelector in _themeSelectors) { var themeResult = await themeSelector.GetThemeAsync(); if (themeResult != null) { themeResults.Add(themeResult); } } themeResults.Sort((x, y) => y.Priority.CompareTo(x.Priority)); if (themeResults.Count == 0) { return(null); } // Try to load the theme to ensure it's present foreach (var theme in themeResults) { var t = _extensionManager.GetExtension(theme.ThemeName); if (t != null) { return(_theme = t); } } // No valid theme. Don't save the result right now. return(null); } return(_theme); }
/// <inheritdoc /> public virtual IEnumerable <string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable <string> viewLocations) { // Get Extension, and then add in the relevant views. var extension = _extensionManager.GetExtension(context.AreaName); if (!extension.Exists) { return(viewLocations); } var result = new List <string>(); var extensionViewsPath = Path.Combine(Path.DirectorySeparatorChar + extension.SubPath, "Views"); result.Add(Path.Combine(extensionViewsPath, "{1}", "{0}.cshtml")); result.Add(Path.Combine(extensionViewsPath, "Shared", "{0}.cshtml")); result.AddRange(viewLocations); return(result); }
public void Publish(IEnumerable <RouteDescriptor> routes, Func <IDictionary <string, object>, Task> env) { var routesArray = routes .OrderByDescending(r => r.Priority) .ToArray(); // this is not called often, but is intended to surface problems before // the actual collection is modified var preloading = new RouteCollection(); foreach (var routeDescriptor in routesArray) { // extract the WebApi route implementation var httpRouteDescriptor = routeDescriptor as HttpRouteDescriptor; if (httpRouteDescriptor != null) { var httpRouteCollection = new RouteCollection(); httpRouteCollection.MapHttpRoute(httpRouteDescriptor.Name, httpRouteDescriptor.RouteTemplate, httpRouteDescriptor.Defaults, httpRouteDescriptor.Constraints); routeDescriptor.Route = httpRouteCollection.First(); } preloading.Add(routeDescriptor.Name, routeDescriptor.Route); } using (_routeCollection.GetWriteLock()) { // existing routes are removed while the collection is briefly inaccessable _routeCollection .OfType <HubRoute>() .ToList().ForEach(x => x.ReleaseShell(_shellSettings)); // HACK: For inserting names in internal dictionary when inserting route to RouteCollection. var routeCollectionType = typeof(RouteCollection); var namedMap = (Dictionary <string, RouteBase>)routeCollectionType.GetField("_namedMap", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(_routeCollection); // new routes are added foreach (var routeDescriptor in routesArray) { // Loading session state information. var defaultSessionState = SessionStateBehavior.Default; ExtensionDescriptor extensionDescriptor = null; if (routeDescriptor.Route is Route) { object extensionId; var route = routeDescriptor.Route as Route; if (route.DataTokens != null && route.DataTokens.TryGetValue("area", out extensionId) || route.Defaults != null && route.Defaults.TryGetValue("area", out extensionId)) { extensionDescriptor = _extensionManager.GetExtension(extensionId.ToString()); } } else if (routeDescriptor.Route is IRouteWithArea) { var route = routeDescriptor.Route as IRouteWithArea; extensionDescriptor = _extensionManager.GetExtension(route.Area); } if (extensionDescriptor != null) { // if session state is not define explicitly, use the one define for the extension if (routeDescriptor.SessionState == SessionStateBehavior.Default) { Enum.TryParse(extensionDescriptor.SessionState, true /*ignoreCase*/, out defaultSessionState); } } // Route-level setting overrides module-level setting (from manifest). var sessionStateBehavior = routeDescriptor.SessionState == SessionStateBehavior.Default ? defaultSessionState : routeDescriptor.SessionState; var shellRoute = new ShellRoute(routeDescriptor.Route, _shellSettings, _workContextAccessor, _runningShellTable, env) { IsHttpRoute = routeDescriptor is HttpRouteDescriptor, SessionState = sessionStateBehavior }; var area = extensionDescriptor == null ? "" : extensionDescriptor.Id; var matchedHubRoute = _routeCollection.FirstOrDefault(x => { var hubRoute = x as HubRoute; if (hubRoute == null) { return(false); } return(routeDescriptor.Priority == hubRoute.Priority && hubRoute.Area.Equals(area, StringComparison.OrdinalIgnoreCase) && hubRoute.Name == routeDescriptor.Name); }) as HubRoute; if (matchedHubRoute == null) { matchedHubRoute = new HubRoute(routeDescriptor.Name, area, routeDescriptor.Priority, _runningShellTable); int index; for (index = 0; index < _routeCollection.Count; index++) { var hubRoute = _routeCollection[index] as HubRoute; if (hubRoute == null) { continue; } if (hubRoute.Priority < matchedHubRoute.Priority) { break; } } _routeCollection.Insert(index, matchedHubRoute); // HACK: For inserting names in internal dictionary when inserting route to RouteCollection. if (!string.IsNullOrEmpty(matchedHubRoute.Name) && !namedMap.ContainsKey(matchedHubRoute.Name)) { namedMap[matchedHubRoute.Name] = matchedHubRoute; } } matchedHubRoute.Add(shellRoute, _shellSettings); } } }
public void ShouldReturnNotFoundExtensionInfoWhenNotFound() { var extension = ModuleThemeScopedExtensionManager.GetExtension("NotFound"); Assert.False(extension.Exists); }
public ExtensionDescriptor GetSiteTheme() { string currentThemeName = GetCurrentThemeName(); return(string.IsNullOrEmpty(currentThemeName) ? null : _extensionManager.GetExtension(GetCurrentThemeName())); }