mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-25 19:17:13 +08:00
committed by
Sébastien Ros
parent
2c26c65f63
commit
5a0fe4e105
@@ -3,5 +3,6 @@
|
||||
namespace Orchard.Layouts.Framework.Harvesters {
|
||||
public class HarvestElementsContext {
|
||||
public IContent Content { get; set; }
|
||||
public bool IsHarvesting { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,6 @@ namespace Orchard.Layouts.Providers {
|
||||
public class BlueprintElementHarvester : Component, IElementHarvester {
|
||||
private readonly Work<IElementBlueprintService> _elementBlueprintService;
|
||||
private readonly Work<IElementManager> _elementManager;
|
||||
private bool _isHarvesting;
|
||||
|
||||
public BlueprintElementHarvester(Work<IElementBlueprintService> elementBlueprintService, Work<IElementManager> elementManager) {
|
||||
_elementBlueprintService = elementBlueprintService;
|
||||
@@ -21,15 +20,14 @@ namespace Orchard.Layouts.Providers {
|
||||
}
|
||||
|
||||
public IEnumerable<ElementDescriptor> HarvestElements(HarvestElementsContext context) {
|
||||
if (_isHarvesting)
|
||||
if (context.IsHarvesting)
|
||||
return Enumerable.Empty<ElementDescriptor>();
|
||||
|
||||
_isHarvesting = true;
|
||||
var blueprints = _elementBlueprintService.Value.GetBlueprints().ToArray();
|
||||
|
||||
var query =
|
||||
from blueprint in blueprints
|
||||
let describeContext = new DescribeElementsContext {Content = context.Content, CacheVaryParam = "Blueprints"}
|
||||
let describeContext = new DescribeElementsContext {Content = context.Content, CacheVaryParam = "Blueprints", IsHarvesting = true }
|
||||
let baseElementDescriptor = _elementManager.Value.GetElementDescriptorByTypeName(describeContext, blueprint.BaseElementTypeName)
|
||||
let baseElement = _elementManager.Value.ActivateElement(baseElementDescriptor)
|
||||
select new ElementDescriptor(
|
||||
@@ -48,9 +46,7 @@ namespace Orchard.Layouts.Providers {
|
||||
}
|
||||
};
|
||||
|
||||
var descriptors = query.ToArray();
|
||||
_isHarvesting = false;
|
||||
return descriptors;
|
||||
return query.ToArray();
|
||||
}
|
||||
|
||||
private static string GetCategory(ElementBlueprint blueprint) {
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Orchard.Layouts.Services {
|
||||
public class DescribeElementsContext {
|
||||
public IContent Content { get; set; }
|
||||
public string CacheVaryParam { get; set; }
|
||||
public bool IsHarvesting { get; set; }
|
||||
|
||||
public static readonly DescribeElementsContext Empty = new DescribeElementsContext();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ namespace Orchard.Layouts.Services {
|
||||
var cacheKey = String.Format("LayoutElementTypes-{0}-{1}", contentType ?? "AnyType", context.CacheVaryParam);
|
||||
return _cacheManager.Get(cacheKey, true, acquireContext => {
|
||||
var harvesterContext = new HarvestElementsContext {
|
||||
Content = context.Content
|
||||
Content = context.Content,
|
||||
IsHarvesting = context.IsHarvesting
|
||||
};
|
||||
var query =
|
||||
from harvester in _elementHarvesters.Value
|
||||
|
||||
Reference in New Issue
Block a user