mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
This commit is contained in:
parent
5800e18324
commit
9839ceca69
@ -170,6 +170,8 @@
|
||||
<Compile Include="Models\NavigationQueryPart.cs" />
|
||||
<Compile Include="Models\NavigationQueryPartRecord.cs" />
|
||||
<Compile Include="Models\QueryPart.cs" />
|
||||
<Compile Include="Providers\Builders\MemberBindingsStep.cs" />
|
||||
<Compile Include="Providers\Executors\MemberBindingsStep.cs" />
|
||||
<Compile Include="Providers\Filters\ContentPartRecordsForm.cs" />
|
||||
<Compile Include="Providers\Filters\EagerFetchFilter.cs" />
|
||||
<Compile Include="Providers\Layouts\RawLayout.cs" />
|
||||
|
@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Projections.Services;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.Projections.Providers.Builders {
|
||||
public class MemberBindingsStep : RecipeBuilderStep {
|
||||
private readonly IMemberBindingProvider _memberBindingProvider;
|
||||
public MemberBindingsStep(IMemberBindingProvider memberBindingProvider) {
|
||||
_memberBindingProvider = memberBindingProvider;
|
||||
}
|
||||
|
||||
public override string Name {
|
||||
get { return "MemberBindings"; }
|
||||
}
|
||||
|
||||
public override LocalizedString DisplayName {
|
||||
get { return T("Member Bindings"); }
|
||||
}
|
||||
|
||||
public override LocalizedString Description {
|
||||
get { return T("Exports query member bindings."); }
|
||||
}
|
||||
|
||||
public override int Priority {
|
||||
get { return 25; }
|
||||
}
|
||||
|
||||
public override int Position {
|
||||
get { return 25; }
|
||||
}
|
||||
|
||||
public override void Build(BuildContext context) {
|
||||
var memberBindings = new XElement("MemberBindings");
|
||||
context.RecipeDocument.Element("Orchard").Add(memberBindings);
|
||||
|
||||
var bindingBuilder = new BindingBuilder();
|
||||
_memberBindingProvider.GetMemberBindings(bindingBuilder);
|
||||
|
||||
foreach (var bindingItem in bindingBuilder.Build()) {
|
||||
var declaringType = bindingItem.Property.DeclaringType;
|
||||
|
||||
var memberBinding = new XElement("MemberBinding",
|
||||
new XAttribute("Type", declaringType.FullName),
|
||||
new XAttribute("Member", bindingItem.Property.Name),
|
||||
new XAttribute("Description", bindingItem.Description),
|
||||
new XAttribute("DisplayName", bindingItem.DisplayName));
|
||||
|
||||
memberBindings.Add(memberBinding);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Data;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Projections.Models;
|
||||
using Orchard.Recipes.Models;
|
||||
using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.Projections.Providers.Executors {
|
||||
public class MemberBindingsStep : RecipeExecutionStep {
|
||||
private readonly IRepository<MemberBindingRecord> _repository;
|
||||
|
||||
public MemberBindingsStep(IRepository<MemberBindingRecord> repository, RecipeExecutionLogger logger) : base(logger) {
|
||||
_repository = repository;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public override string Name {
|
||||
get { return "MemberBindings"; }
|
||||
}
|
||||
|
||||
public override void Execute(RecipeExecutionContext context) {
|
||||
foreach (var memberBindingElement in context.RecipeStep.Step.Elements()) {
|
||||
Logger.Information("Importing member bindings.");
|
||||
try {
|
||||
var member = memberBindingElement.Attribute("Member").Value;
|
||||
var type = memberBindingElement.Attribute("Type").Value;
|
||||
if (_repository.Get(b => b.Member == member && b.Type == type) != null)
|
||||
continue;
|
||||
_repository.Create(new MemberBindingRecord {
|
||||
Member = member,
|
||||
Type = type,
|
||||
DisplayName = memberBindingElement.Attribute("DisplayName").Value,
|
||||
Description = memberBindingElement.Attribute("Description").Value,
|
||||
});
|
||||
}
|
||||
catch (Exception ex) {
|
||||
Logger.Error(ex, "Error while importing member bindings.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user