mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Point where basic infoset-based storage of fields is working
Moved some namespaces to reorganize some parts of code Created a field storage api and default implementation Added InfosetPart that's always welded as mechanism to reach versioned and non-versioned ad-hoc data --HG-- branch : dev
This commit is contained in:
@@ -3,7 +3,8 @@ using System.Linq;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers.FieldStorage;
|
||||
using Orchard.ContentManagement.FieldStorage;
|
||||
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
|
||||
@@ -17,7 +18,7 @@ namespace Orchard.Tests.ContentManagement.Drivers.FieldStorage {
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<FieldStorageProviderSelector>().As<IFieldStorageProviderSelector>();
|
||||
builder.RegisterType<InfosetFieldStorageProvider>().As<IFieldStorageProvider>();
|
||||
builder.RegisterType<InfosetStorageProvider>().As<IFieldStorageProvider>();
|
||||
builder.RegisterType<TestProvider>().As<IFieldStorageProvider>();
|
||||
|
||||
_container = builder.Build();
|
||||
|
@@ -5,7 +5,8 @@ using System.Text;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers.FieldStorage;
|
||||
using Orchard.ContentManagement.FieldStorage;
|
||||
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
|
||||
using Orchard.ContentManagement.MetaData.Builders;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.Records;
|
||||
@@ -18,7 +19,7 @@ namespace Orchard.Tests.ContentManagement.Drivers.FieldStorage {
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
builder.RegisterType<InfosetFieldStorageProvider>().As<IFieldStorageProvider>();
|
||||
builder.RegisterType<InfosetStorageProvider>().As<IFieldStorageProvider>();
|
||||
|
||||
_container = builder.Build();
|
||||
_provider = _container.Resolve<IFieldStorageProvider>();
|
||||
|
@@ -1,45 +0,0 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Common.Fields;
|
||||
using Orchard.Core.Common.ViewModels;
|
||||
|
||||
namespace Orchard.Core.Common.Drivers {
|
||||
[UsedImplicitly]
|
||||
public class TextContentFieldDriver : ContentFieldDriver<TextContentField> {
|
||||
public IOrchardServices Services { get; set; }
|
||||
private const string TemplateName = "Fields/Common.TextContentField";
|
||||
|
||||
public TextContentFieldDriver(IOrchardServices services) {
|
||||
Services = services;
|
||||
}
|
||||
|
||||
protected override string Prefix {
|
||||
get { return "TextContentField"; }
|
||||
}
|
||||
|
||||
protected override DriverResult Display(TextContentField field, string displayType) {
|
||||
var model = new TextContentFieldDisplayViewModel { Text = field };
|
||||
|
||||
return ContentFieldTemplate(model, TemplateName, Prefix);
|
||||
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(TextContentField field) {
|
||||
var model = BuildEditorViewModel(field);
|
||||
return ContentFieldTemplate(model, TemplateName, Prefix).Location("primary", "5");
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(TextContentField field, IUpdateModel updater) {
|
||||
var model = BuildEditorViewModel(field);
|
||||
updater.TryUpdateModel(model, Prefix, null, null);
|
||||
return ContentFieldTemplate(model, TemplateName, Prefix).Location("primary", "5");
|
||||
}
|
||||
|
||||
private static TextContentFieldEditorViewModel BuildEditorViewModel(TextContentField field) {
|
||||
return new TextContentFieldEditorViewModel {
|
||||
TextContentField = field
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
34
src/Orchard.Web/Core/Common/Drivers/TextFieldDriver.cs
Normal file
34
src/Orchard.Web/Core/Common/Drivers/TextFieldDriver.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Common.Fields;
|
||||
|
||||
namespace Orchard.Core.Common.Drivers {
|
||||
[UsedImplicitly]
|
||||
public class TextFieldDriver : ContentFieldDriver<TextField> {
|
||||
public IOrchardServices Services { get; set; }
|
||||
private const string TemplateName = "Fields/Common.TextField";
|
||||
|
||||
public TextFieldDriver(IOrchardServices services) {
|
||||
Services = services;
|
||||
}
|
||||
|
||||
private static string GetPrefix(TextField field, ContentPart part) {
|
||||
return part.PartDefinition.Name + "." + field.Name;
|
||||
}
|
||||
|
||||
protected override DriverResult Display(ContentPart part, TextField field, string displayType) {
|
||||
return ContentFieldTemplate(field, TemplateName, GetPrefix(field, part));
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(ContentPart part, TextField field) {
|
||||
return ContentFieldTemplate(field, TemplateName, GetPrefix(field, part)).Location("primary", "5");
|
||||
}
|
||||
|
||||
protected override DriverResult Editor(ContentPart part, TextField field, IUpdateModel updater) {
|
||||
updater.TryUpdateModel(field, GetPrefix(field, part), null, null);
|
||||
return Editor(part, field);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -1,10 +0,0 @@
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Core.Common.Fields {
|
||||
public class TextContentField : ContentField {
|
||||
public string TextField {
|
||||
get { return Getter("text"); }
|
||||
set { Setter("text", value); }
|
||||
}
|
||||
}
|
||||
}
|
10
src/Orchard.Web/Core/Common/Fields/TextField.cs
Normal file
10
src/Orchard.Web/Core/Common/Fields/TextField.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Core.Common.Fields {
|
||||
public class TextField : ContentField {
|
||||
public string Value {
|
||||
get { return Getter(null); }
|
||||
set { Setter(null, value); }
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,6 +2,6 @@
|
||||
|
||||
namespace Orchard.Core.Common.ViewModels {
|
||||
public class TextContentFieldDisplayViewModel {
|
||||
public TextContentField Text { get; set; }
|
||||
public TextField Text { get; set; }
|
||||
}
|
||||
}
|
@@ -3,12 +3,12 @@ using Orchard.Core.Common.Fields;
|
||||
|
||||
namespace Orchard.Core.Common.ViewModels {
|
||||
public class TextContentFieldEditorViewModel {
|
||||
public TextContentField TextContentField { get; set; }
|
||||
public TextField TextField { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Text {
|
||||
get { return TextContentField.TextField; }
|
||||
set { TextContentField.TextField = value; }
|
||||
get { return TextField.Value; }
|
||||
set { TextField.Value = value; }
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TextContentFieldDisplayViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
||||
<%=Model.Text %>
|
@@ -0,0 +1,2 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Orchard.Core.Common.Fields.TextField>" %>
|
||||
<%: Model.Value %>
|
@@ -1,7 +0,0 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<TextContentFieldEditorViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
||||
<fieldset>
|
||||
<%: Html.LabelFor(m=>m.Text) %>
|
||||
<%: Html.EditorFor(m=>m.Text) %>
|
||||
<%: Html.ValidationMessageFor(m=>m.Text) %>
|
||||
</fieldset>
|
@@ -0,0 +1,6 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Common.Fields.TextField>" %>
|
||||
<fieldset>
|
||||
<label for="<%:Html.FieldIdFor(m=>m.Value) %>"><%:Model.Name %></label>
|
||||
<%: Html.EditorFor(m=>m.Value) %>
|
||||
<%: Html.ValidationMessageFor(m=>m.Value) %>
|
||||
</fieldset>
|
@@ -65,8 +65,8 @@
|
||||
<Compile Include="Common\Drivers\CommonDriver.cs" />
|
||||
<Compile Include="Common\Drivers\RoutableDriver.cs" />
|
||||
<Compile Include="Common\Controllers\RoutableController.cs" />
|
||||
<Compile Include="Common\Drivers\TextContentFieldDriver.cs" />
|
||||
<Compile Include="Common\Fields\TextContentField.cs" />
|
||||
<Compile Include="Common\Drivers\TextFieldDriver.cs" />
|
||||
<Compile Include="Common\Fields\TextField.cs" />
|
||||
<Compile Include="Common\Handlers\RoutableAspectHandler.cs" />
|
||||
<Compile Include="Common\ViewModels\ContainerEditorViewModel.cs" />
|
||||
<Compile Include="Common\ViewModels\TextContentFieldDisplayViewModel.cs" />
|
||||
@@ -202,9 +202,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Common\Module.txt" />
|
||||
<Content Include="Common\Views\DisplayTemplates\Fields\Common.TextContentField.ascx" />
|
||||
<Content Include="Common\Views\DisplayTemplates\Fields\Common.TextField.ascx" />
|
||||
<Content Include="Common\Views\EditorTemplates\Fields\Common.TextField.ascx" />
|
||||
<Content Include="Common\Views\EditorTemplates\Parts\Common.Container.ascx" />
|
||||
<Content Include="Common\Views\EditorTemplates\Parts\Common.TextContentField.ascx" />
|
||||
<Content Include="Contents\Module.txt" />
|
||||
<Content Include="Contents\Styles\admin.css" />
|
||||
<Content Include="Contents\Views\Admin\EditPart.ascx" />
|
||||
|
@@ -59,7 +59,7 @@ namespace Orchard.Core.Routable.Drivers {
|
||||
|
||||
// TEMP: path format patterns replaces this logic
|
||||
var path = part.Record.Path;
|
||||
if (path.EndsWith(part.Slug)) {
|
||||
if (path != null && path.EndsWith(part.Slug)) {
|
||||
model.DisplayLeadingPath = path.Substring(0, path.Length - part.Slug.Length);
|
||||
}
|
||||
|
||||
|
@@ -57,7 +57,7 @@ namespace Orchard.Core.Settings.Metadata {
|
||||
private ContentTypeDefinitionRecord Acquire(ContentTypeDefinition contentTypeDefinition) {
|
||||
var result = _typeDefinitionRepository.Fetch(x => x.Name == contentTypeDefinition.Name).SingleOrDefault();
|
||||
if (result == null) {
|
||||
result = new ContentTypeDefinitionRecord { Name = contentTypeDefinition.Name, DisplayName = contentTypeDefinition.DisplayName};
|
||||
result = new ContentTypeDefinitionRecord { Name = contentTypeDefinition.Name, DisplayName = contentTypeDefinition.DisplayName };
|
||||
_typeDefinitionRepository.Create(result);
|
||||
}
|
||||
return result;
|
||||
@@ -111,7 +111,7 @@ namespace Orchard.Core.Settings.Metadata {
|
||||
record.Settings = _settingsWriter.Map(model.Settings).ToString();
|
||||
|
||||
var toRemove = record.ContentPartFieldDefinitionRecords
|
||||
.Where(fieldDefinitionRecord => !model.Fields.Any(field => fieldDefinitionRecord.ContentFieldDefinitionRecord.Name == field.FieldDefinition.Name))
|
||||
.Where(partFieldDefinitionRecord => model.Fields.Any(partField => partFieldDefinitionRecord.Name == partField.Name))
|
||||
.ToList();
|
||||
|
||||
foreach (var remove in toRemove) {
|
||||
@@ -120,9 +120,9 @@ namespace Orchard.Core.Settings.Metadata {
|
||||
|
||||
foreach (var field in model.Fields) {
|
||||
var fieldName = field.FieldDefinition.Name;
|
||||
var partFieldRecord = record.ContentPartFieldDefinitionRecords.SingleOrDefault(r => r.ContentFieldDefinitionRecord.Name == fieldName);
|
||||
var partFieldRecord = record.ContentPartFieldDefinitionRecords.SingleOrDefault(r => r.Name == fieldName);
|
||||
if (partFieldRecord == null) {
|
||||
partFieldRecord = new ContentPartFieldDefinitionRecord {
|
||||
partFieldRecord = new ContentPartFieldDefinitionRecord {
|
||||
ContentFieldDefinitionRecord = Acquire(field.FieldDefinition),
|
||||
Name = field.Name
|
||||
};
|
||||
|
@@ -79,10 +79,9 @@ namespace Orchard.ContentManagement {
|
||||
}
|
||||
|
||||
var context3 = new InitializingContentContext {
|
||||
ContentType = contentType,
|
||||
ContentItem = context.Builder.Build()
|
||||
ContentType = context2.ContentType,
|
||||
ContentItem = context2.ContentItem,
|
||||
};
|
||||
context3.ContentItem.ContentManager = this;
|
||||
|
||||
foreach (var handler in Handlers) {
|
||||
handler.Initializing(context3);
|
||||
@@ -276,7 +275,8 @@ namespace Orchard.ContentManagement {
|
||||
var buildingItemVersionRecord = new ContentItemVersionRecord {
|
||||
ContentItemRecord = contentItemRecord,
|
||||
Latest = true,
|
||||
Published = false
|
||||
Published = false,
|
||||
Data = existingItemVersionRecord.Data,
|
||||
};
|
||||
|
||||
|
||||
@@ -435,11 +435,11 @@ namespace Orchard.ContentManagement {
|
||||
var indexContentContext = new IndexContentContext(contentItem, documentIndex);
|
||||
|
||||
// dispatch to handlers to retrieve index information
|
||||
foreach ( var handler in Handlers ) {
|
||||
foreach (var handler in Handlers) {
|
||||
handler.Indexing(indexContentContext);
|
||||
}
|
||||
|
||||
foreach ( var handler in Handlers ) {
|
||||
foreach (var handler in Handlers) {
|
||||
handler.Indexed(indexContentContext);
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.ContentManagement.Drivers.FieldStorage;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
@@ -11,23 +11,21 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
protected virtual string Zone { get { return "body"; } }
|
||||
|
||||
DriverResult IContentFieldDriver.BuildDisplayModel(BuildDisplayModelContext context) {
|
||||
var results = context.ContentItem.Parts.SelectMany(part => part.Fields).
|
||||
OfType<TField>().
|
||||
Select(field => Display(field, context.DisplayType));
|
||||
return Combined(results.ToArray());
|
||||
return Process(context.ContentItem, (part, field) => Display(part, field, context.DisplayType));
|
||||
}
|
||||
|
||||
DriverResult IContentFieldDriver.BuildEditorModel(BuildEditorModelContext context) {
|
||||
var results = context.ContentItem.Parts.SelectMany(part => part.Fields).
|
||||
OfType<TField>().
|
||||
Select(field => Editor(field));
|
||||
return Combined(results.ToArray());
|
||||
return Process(context.ContentItem, (part, field) => Editor(part, field));
|
||||
}
|
||||
|
||||
DriverResult IContentFieldDriver.UpdateEditorModel(UpdateEditorModelContext context) {
|
||||
var results = context.ContentItem.Parts.SelectMany(part => part.Fields).
|
||||
OfType<TField>().
|
||||
Select(field => Editor(field, context.Updater));
|
||||
return Process(context.ContentItem, (part, field) => Editor(part, field, context.Updater));
|
||||
}
|
||||
|
||||
DriverResult Process(ContentItem item, Func<ContentPart, TField, DriverResult> effort) {
|
||||
var results = item.Parts
|
||||
.SelectMany(part => part.Fields.OfType<TField>().Select(field => new { part, field }))
|
||||
.Select(pf => effort(pf.part, pf.field));
|
||||
return Combined(results.ToArray());
|
||||
}
|
||||
|
||||
@@ -47,9 +45,9 @@ namespace Orchard.ContentManagement.Drivers {
|
||||
}
|
||||
|
||||
|
||||
protected virtual DriverResult Display(TField field, string displayType) { return null; }
|
||||
protected virtual DriverResult Editor(TField field) { return null; }
|
||||
protected virtual DriverResult Editor(TField field, IUpdateModel updater) { return null; }
|
||||
protected virtual DriverResult Display(ContentPart part, TField field, string displayType) { return null; }
|
||||
protected virtual DriverResult Editor(ContentPart part, TField field) { return null; }
|
||||
protected virtual DriverResult Editor(ContentPart part, TField field, IUpdateModel updater) { return null; }
|
||||
|
||||
|
||||
public ContentTemplateResult ContentFieldTemplate(object model) {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement.Drivers.FieldStorage;
|
||||
using Orchard.ContentManagement.FieldStorage;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.Logging;
|
||||
|
||||
|
@@ -18,43 +18,46 @@ namespace Orchard.ContentManagement.Drivers.Coordinators {
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
|
||||
public override void Activating(ActivatingContentContext context) {
|
||||
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType);
|
||||
if (contentTypeDefinition == null)
|
||||
return;
|
||||
|
||||
foreach (var partInfo in _drivers.SelectMany(cpp => cpp.GetPartInfo())) {
|
||||
var partName = partInfo.PartName;
|
||||
var typePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(p => p.PartDefinition.Name == partName);
|
||||
if (typePartDefinition != null) {
|
||||
context.Builder.Weld(partInfo.Factory(typePartDefinition));
|
||||
}
|
||||
var partInfos = _drivers.SelectMany(cpp => cpp.GetPartInfo());
|
||||
|
||||
foreach (var typePartDefinition in contentTypeDefinition.Parts) {
|
||||
var partName = typePartDefinition.PartDefinition.Name;
|
||||
var partInfo = partInfos.FirstOrDefault(pi => pi.PartName == partName);
|
||||
var part = partInfo != null
|
||||
? partInfo.Factory(typePartDefinition)
|
||||
: new ContentPart { TypePartDefinition = typePartDefinition };
|
||||
context.Builder.Weld(part);
|
||||
}
|
||||
}
|
||||
|
||||
public override void BuildDisplayModel(BuildDisplayModelContext context) {
|
||||
_drivers.Invoke(driver => {
|
||||
var result = driver.BuildDisplayModel(context);
|
||||
if (result != null)
|
||||
result.Apply(context);
|
||||
}, Logger);
|
||||
var result = driver.BuildDisplayModel(context);
|
||||
if (result != null)
|
||||
result.Apply(context);
|
||||
}, Logger);
|
||||
}
|
||||
|
||||
public override void BuildEditorModel(BuildEditorModelContext context) {
|
||||
_drivers.Invoke(driver => {
|
||||
var result = driver.BuildEditorModel(context);
|
||||
if (result != null)
|
||||
result.Apply(context);
|
||||
}, Logger);
|
||||
var result = driver.BuildEditorModel(context);
|
||||
if (result != null)
|
||||
result.Apply(context);
|
||||
}, Logger);
|
||||
}
|
||||
|
||||
public override void UpdateEditorModel(UpdateEditorModelContext context) {
|
||||
_drivers.Invoke(driver => {
|
||||
var result = driver.UpdateEditorModel(context);
|
||||
if (result != null)
|
||||
result.Apply(context);
|
||||
}, Logger);
|
||||
var result = driver.UpdateEditorModel(context);
|
||||
if (result != null)
|
||||
result.Apply(context);
|
||||
}, Logger);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
|
||||
namespace Orchard.ContentManagement.Drivers.FieldStorage {
|
||||
namespace Orchard.ContentManagement.FieldStorage {
|
||||
public class FieldStorageProviderSelector : IFieldStorageProviderSelector {
|
||||
public const string Storage = "Storage";
|
||||
public const string DefaultProviderName = "Infoset";
|
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace Orchard.ContentManagement.Drivers.FieldStorage {
|
||||
namespace Orchard.ContentManagement.FieldStorage {
|
||||
public interface IFieldStorage {
|
||||
Func<string, string> Getter { get; }
|
||||
Action<string, string> Setter { get; }
|
@@ -1,6 +1,6 @@
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
|
||||
namespace Orchard.ContentManagement.Drivers.FieldStorage {
|
||||
namespace Orchard.ContentManagement.FieldStorage {
|
||||
public interface IFieldStorageProvider : IDependency {
|
||||
string ProviderName { get; }
|
||||
|
@@ -1,6 +1,6 @@
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
|
||||
namespace Orchard.ContentManagement.Drivers.FieldStorage {
|
||||
namespace Orchard.ContentManagement.FieldStorage {
|
||||
public interface IFieldStorageProviderSelector : IDependency {
|
||||
IFieldStorageProvider GetProvider(ContentPartDefinition.Field partFieldDefinition);
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Orchard.ContentManagement.FieldStorage.InfosetStorage {
|
||||
public class Infoset {
|
||||
private XElement _element;
|
||||
|
||||
private void SetElement(XElement value) {
|
||||
_element = value;
|
||||
}
|
||||
|
||||
public XElement Element {
|
||||
get {
|
||||
return _element ?? (_element = new XElement("Data"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Data {
|
||||
get {
|
||||
return _element == null ? null : Element.ToString(SaveOptions.DisableFormatting);
|
||||
}
|
||||
set {
|
||||
SetElement(string.IsNullOrEmpty(value) ? null : XElement.Parse(value, LoadOptions.PreserveWhitespace));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
|
||||
namespace Orchard.ContentManagement.FieldStorage.InfosetStorage {
|
||||
public class InfosetHandler : ContentHandlerBase {
|
||||
public override void Activating(ActivatingContentContext context) {
|
||||
context.Builder.Weld<InfosetPart>();
|
||||
}
|
||||
|
||||
public override void Creating(CreateContentContext context) {
|
||||
var infosetPart = context.ContentItem.As<InfosetPart>();
|
||||
if (infosetPart != null) {
|
||||
context.ContentItemRecord.Data = infosetPart.Infoset.Data;
|
||||
context.ContentItemVersionRecord.Data = infosetPart.VersionInfoset.Data;
|
||||
|
||||
infosetPart.Infoset = context.ContentItemRecord.Infoset;
|
||||
infosetPart.VersionInfoset = context.ContentItemVersionRecord.Infoset;
|
||||
}
|
||||
}
|
||||
public override void Loading(LoadContentContext context) {
|
||||
var infosetPart = context.ContentItem.As<InfosetPart>();
|
||||
if (infosetPart != null) {
|
||||
infosetPart.Infoset = context.ContentItemRecord.Infoset;
|
||||
infosetPart.VersionInfoset = context.ContentItemVersionRecord.Infoset;
|
||||
}
|
||||
}
|
||||
public override void Versioning(VersionContentContext context) {
|
||||
var infosetPart = context.BuildingContentItem.As<InfosetPart>();
|
||||
if (infosetPart != null) {
|
||||
infosetPart.Infoset = context.ContentItemRecord.Infoset;
|
||||
infosetPart.VersionInfoset = context.BuildingItemVersionRecord.Infoset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
namespace Orchard.ContentManagement.FieldStorage.InfosetStorage {
|
||||
public class InfosetPart : ContentPart {
|
||||
public InfosetPart() {
|
||||
Infoset = new Infoset();
|
||||
VersionInfoset = new Infoset();
|
||||
}
|
||||
|
||||
public Infoset Infoset { get; set; }
|
||||
public Infoset VersionInfoset { get; set; }
|
||||
}
|
||||
}
|
@@ -3,8 +3,8 @@ using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
|
||||
namespace Orchard.ContentManagement.Drivers.FieldStorage {
|
||||
public class InfosetFieldStorageProvider : IFieldStorageProvider {
|
||||
namespace Orchard.ContentManagement.FieldStorage.InfosetStorage {
|
||||
public class InfosetStorageProvider : IFieldStorageProvider {
|
||||
public string ProviderName {
|
||||
get { return FieldStorageProviderSelector.DefaultProviderName; }
|
||||
}
|
||||
@@ -12,10 +12,11 @@ namespace Orchard.ContentManagement.Drivers.FieldStorage {
|
||||
public IFieldStorage BindStorage(ContentPart contentPart, ContentPartDefinition.Field partFieldDefinition) {
|
||||
var partName = XmlConvert.EncodeLocalName(contentPart.PartDefinition.Name);
|
||||
var fieldName = XmlConvert.EncodeLocalName(partFieldDefinition.Name);
|
||||
var infosetPart = contentPart.As<InfosetPart>();
|
||||
|
||||
return new Storage {
|
||||
Getter = name => Get(contentPart.ContentItem.Record.Infoset.Element, partName, fieldName, name),
|
||||
Setter = (name, value) => Set(contentPart.ContentItem.Record.Infoset.Element, partName, fieldName, name, value)
|
||||
Getter = name => Get(infosetPart.Infoset.Element, partName, fieldName, name),
|
||||
Setter = (name, value) => Set(infosetPart.Infoset.Element, partName, fieldName, name, value)
|
||||
};
|
||||
}
|
||||
|
@@ -52,13 +52,16 @@ namespace Orchard.ContentManagement.MetaData.Builders {
|
||||
}
|
||||
|
||||
public ContentPartDefinitionBuilder WithField(string fieldName, Action<FieldConfigurer> configuration) {
|
||||
var fieldDefinition = new ContentFieldDefinition(fieldName);
|
||||
var existingField = _fields.SingleOrDefault(x => x.FieldDefinition.Name == fieldDefinition.Name);
|
||||
|
||||
var existingField = _fields.FirstOrDefault(x => x.Name == fieldName);
|
||||
if (existingField != null) {
|
||||
_fields.Remove(existingField);
|
||||
var toRemove = _fields.Where(x => x.Name == fieldName).ToArray();
|
||||
foreach (var remove in toRemove) {
|
||||
_fields.Remove(remove);
|
||||
}
|
||||
}
|
||||
else {
|
||||
existingField = new ContentPartDefinition.Field(fieldDefinition, fieldName, new SettingsDictionary());
|
||||
existingField = new ContentPartDefinition.Field(fieldName);
|
||||
}
|
||||
var configurer = new FieldConfigurerImpl(existingField);
|
||||
configuration(configurer);
|
||||
@@ -84,7 +87,7 @@ namespace Orchard.ContentManagement.MetaData.Builders {
|
||||
|
||||
class FieldConfigurerImpl : FieldConfigurer {
|
||||
private ContentFieldDefinition _fieldDefinition;
|
||||
private string _fieldName;
|
||||
private readonly string _fieldName;
|
||||
|
||||
public FieldConfigurerImpl(ContentPartDefinition.Field field)
|
||||
: base(field) {
|
||||
|
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using Orchard.ContentManagement.Drivers.FieldStorage;
|
||||
using Orchard.ContentManagement.FieldStorage;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
|
||||
namespace Orchard.ContentManagement.MetaData {
|
||||
|
@@ -10,7 +10,7 @@ namespace Orchard.ContentManagement.MetaData.Models {
|
||||
Settings = settings;
|
||||
}
|
||||
|
||||
public ContentPartDefinition(string name) {
|
||||
public ContentPartDefinition(string name) {
|
||||
Name = name;
|
||||
Fields = Enumerable.Empty<Field>();
|
||||
Settings = new SettingsDictionary();
|
||||
@@ -21,9 +21,14 @@ namespace Orchard.ContentManagement.MetaData.Models {
|
||||
public SettingsDictionary Settings { get; private set; }
|
||||
|
||||
public class Field {
|
||||
public Field(ContentFieldDefinition contentFieldDefinition, string name, SettingsDictionary settings) {
|
||||
FieldDefinition = contentFieldDefinition;
|
||||
public Field(string name) {
|
||||
Name = name;
|
||||
FieldDefinition = new ContentFieldDefinition(null);
|
||||
Settings = new SettingsDictionary();
|
||||
}
|
||||
public Field( ContentFieldDefinition contentFieldDefinition, string name, SettingsDictionary settings) {
|
||||
Name = name;
|
||||
FieldDefinition = contentFieldDefinition;
|
||||
Settings = settings;
|
||||
}
|
||||
|
||||
|
@@ -36,14 +36,14 @@ namespace Orchard.ContentManagement.MetaData.Services {
|
||||
|
||||
foreach (var iter in source.Elements()) {
|
||||
var fieldElement = iter;
|
||||
string[] fieldParameters = fieldElement.Name.LocalName.Split('.');
|
||||
var fieldParameters = XmlConvert.DecodeName(fieldElement.Name.LocalName).Split('.');
|
||||
builder.WithField(
|
||||
XmlConvert.DecodeName(fieldParameters[0]),
|
||||
fieldParameters[0],
|
||||
fieldBuilder => {
|
||||
fieldBuilder.OfType(fieldParameters[1]);
|
||||
foreach (var setting in _settingsReader.Map(fieldElement)) {
|
||||
fieldBuilder.WithSetting(setting.Key, setting.Value);
|
||||
}
|
||||
fieldBuilder.OfType(fieldParameters[1]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ namespace Orchard.ContentManagement.Records {
|
||||
var alteration = (IAlteration<ContentItemRecord>)Activator.CreateInstance(type);
|
||||
alteration.Override(mapping);
|
||||
}
|
||||
mapping.IgnoreProperty(x => x.Infoset);
|
||||
});
|
||||
|
||||
model.Override<ContentItemVersionRecord>(mapping => {
|
||||
@@ -41,6 +42,7 @@ namespace Orchard.ContentManagement.Records {
|
||||
var alteration = (IAlteration<ContentItemVersionRecord>)Activator.CreateInstance(type);
|
||||
alteration.Override(mapping);
|
||||
}
|
||||
mapping.IgnoreProperty(x => x.Infoset);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.ContentManagement.FieldStorage;
|
||||
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
|
||||
|
||||
namespace Orchard.ContentManagement.Records {
|
||||
public class ContentItemRecord {
|
||||
@@ -15,30 +16,7 @@ namespace Orchard.ContentManagement.Records {
|
||||
public virtual ContentTypeRecord ContentType { get; set; }
|
||||
public virtual IList<ContentItemVersionRecord> Versions { get; set; }
|
||||
|
||||
public virtual string Data {
|
||||
get { return Infoset.Data; }
|
||||
set { Infoset.Data = value; }
|
||||
}
|
||||
|
||||
public virtual string Data { get { return Infoset.Data; } set { Infoset.Data = value; } }
|
||||
public virtual Infoset Infoset { get; private set; }
|
||||
}
|
||||
|
||||
public class Infoset {
|
||||
private XElement _element;
|
||||
|
||||
private void SetElement(XElement value) {
|
||||
_element = value;
|
||||
}
|
||||
|
||||
public XElement Element {
|
||||
get {
|
||||
return _element ?? (_element = new XElement("Data"));
|
||||
}
|
||||
}
|
||||
|
||||
public string Data {
|
||||
get { return Element.ToString(SaveOptions.DisableFormatting); }
|
||||
set { SetElement(XElement.Parse(value, LoadOptions.PreserveWhitespace)); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,21 @@
|
||||
using System;
|
||||
using Orchard.ContentManagement.FieldStorage;
|
||||
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
|
||||
|
||||
namespace Orchard.ContentManagement.Records {
|
||||
public class ContentItemVersionRecord {
|
||||
public ContentItemVersionRecord() {
|
||||
Infoset = new Infoset();
|
||||
}
|
||||
|
||||
public virtual int Id { get; set; }
|
||||
public virtual ContentItemRecord ContentItemRecord { get; set; }
|
||||
public virtual int Number { get; set; }
|
||||
|
||||
public virtual bool Published { get; set; }
|
||||
public virtual bool Latest { get; set; }
|
||||
|
||||
public virtual string Data { get { return Infoset.Data; } set { Infoset.Data = value; } }
|
||||
public virtual Infoset Infoset { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -192,19 +192,21 @@
|
||||
<Compile Include="ContentManagement\Drivers\DriverResult.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\Drivers\FieldStorage\FieldStorageProviderSelector.cs" />
|
||||
<Compile Include="ContentManagement\FieldStorage\FieldStorageProviderSelector.cs" />
|
||||
<Compile Include="ContentManagement\Drivers\IContentFieldDriver.cs" />
|
||||
<Compile Include="ContentManagement\Drivers\IContentItemDriver.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\Drivers\IContentPartDriver.cs" />
|
||||
<Compile Include="ContentManagement\Drivers\FieldStorage\IFieldStorage.cs" />
|
||||
<Compile Include="ContentManagement\Drivers\FieldStorage\IFieldStorageProvider.cs" />
|
||||
<Compile Include="ContentManagement\Drivers\FieldStorage\IFieldStorageProviderSelector.cs" />
|
||||
<Compile Include="ContentManagement\Drivers\FieldStorage\InfosetFieldStorageProvider.cs" />
|
||||
<Compile Include="ContentManagement\FieldStorage\IFieldStorage.cs" />
|
||||
<Compile Include="ContentManagement\FieldStorage\IFieldStorageProvider.cs" />
|
||||
<Compile Include="ContentManagement\FieldStorage\IFieldStorageProviderSelector.cs" />
|
||||
<Compile Include="ContentManagement\FieldStorage\InfosetStorage\InfosetStorageProvider.cs" />
|
||||
<Compile Include="ContentManagement\Extenstions\UrlHelperExtensions.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\FieldStorage\InfosetStorage\InfosetHandler.cs" />
|
||||
<Compile Include="ContentManagement\FieldStorage\InfosetStorage\InfosetPart.cs" />
|
||||
<Compile Include="ContentManagement\Handlers\ActivatedContentContext.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
@@ -343,6 +345,7 @@
|
||||
<Compile Include="ContentManagement\Records\ContentTypeRecord.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="ContentManagement\FieldStorage\InfosetStorage\Infoset.cs" />
|
||||
<Compile Include="ContentManagement\Records\Utility.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
Reference in New Issue
Block a user