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:
Louis DeJardin
2010-06-24 14:35:18 -07:00
parent f38620786e
commit 6540479d48
35 changed files with 240 additions and 177 deletions

View File

@@ -3,7 +3,8 @@ using System.Linq;
using Autofac; using Autofac;
using NUnit.Framework; using NUnit.Framework;
using Orchard.ContentManagement; 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.Builders;
using Orchard.ContentManagement.MetaData.Models; using Orchard.ContentManagement.MetaData.Models;
@@ -17,7 +18,7 @@ namespace Orchard.Tests.ContentManagement.Drivers.FieldStorage {
public void Init() { public void Init() {
var builder = new ContainerBuilder(); var builder = new ContainerBuilder();
builder.RegisterType<FieldStorageProviderSelector>().As<IFieldStorageProviderSelector>(); builder.RegisterType<FieldStorageProviderSelector>().As<IFieldStorageProviderSelector>();
builder.RegisterType<InfosetFieldStorageProvider>().As<IFieldStorageProvider>(); builder.RegisterType<InfosetStorageProvider>().As<IFieldStorageProvider>();
builder.RegisterType<TestProvider>().As<IFieldStorageProvider>(); builder.RegisterType<TestProvider>().As<IFieldStorageProvider>();
_container = builder.Build(); _container = builder.Build();

View File

@@ -5,7 +5,8 @@ using System.Text;
using Autofac; using Autofac;
using NUnit.Framework; using NUnit.Framework;
using Orchard.ContentManagement; 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.Builders;
using Orchard.ContentManagement.MetaData.Models; using Orchard.ContentManagement.MetaData.Models;
using Orchard.ContentManagement.Records; using Orchard.ContentManagement.Records;
@@ -18,7 +19,7 @@ namespace Orchard.Tests.ContentManagement.Drivers.FieldStorage {
[SetUp] [SetUp]
public void Init() { public void Init() {
var builder = new ContainerBuilder(); var builder = new ContainerBuilder();
builder.RegisterType<InfosetFieldStorageProvider>().As<IFieldStorageProvider>(); builder.RegisterType<InfosetStorageProvider>().As<IFieldStorageProvider>();
_container = builder.Build(); _container = builder.Build();
_provider = _container.Resolve<IFieldStorageProvider>(); _provider = _container.Resolve<IFieldStorageProvider>();

View File

@@ -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
};
}
}
}

View 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);
}
}
}

View File

@@ -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); }
}
}
}

View 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); }
}
}
}

View File

@@ -2,6 +2,6 @@
namespace Orchard.Core.Common.ViewModels { namespace Orchard.Core.Common.ViewModels {
public class TextContentFieldDisplayViewModel { public class TextContentFieldDisplayViewModel {
public TextContentField Text { get; set; } public TextField Text { get; set; }
} }
} }

View File

@@ -3,12 +3,12 @@ using Orchard.Core.Common.Fields;
namespace Orchard.Core.Common.ViewModels { namespace Orchard.Core.Common.ViewModels {
public class TextContentFieldEditorViewModel { public class TextContentFieldEditorViewModel {
public TextContentField TextContentField { get; set; } public TextField TextField { get; set; }
[Required] [Required]
public string Text { public string Text {
get { return TextContentField.TextField; } get { return TextField.Value; }
set { TextContentField.TextField = value; } set { TextField.Value = value; }
} }
} }
} }

View File

@@ -1,3 +0,0 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<TextContentFieldDisplayViewModel>" %>
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
<%=Model.Text %>

View File

@@ -0,0 +1,2 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Orchard.Core.Common.Fields.TextField>" %>
<%: Model.Value %>

View File

@@ -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>

View File

@@ -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>

View File

@@ -65,8 +65,8 @@
<Compile Include="Common\Drivers\CommonDriver.cs" /> <Compile Include="Common\Drivers\CommonDriver.cs" />
<Compile Include="Common\Drivers\RoutableDriver.cs" /> <Compile Include="Common\Drivers\RoutableDriver.cs" />
<Compile Include="Common\Controllers\RoutableController.cs" /> <Compile Include="Common\Controllers\RoutableController.cs" />
<Compile Include="Common\Drivers\TextContentFieldDriver.cs" /> <Compile Include="Common\Drivers\TextFieldDriver.cs" />
<Compile Include="Common\Fields\TextContentField.cs" /> <Compile Include="Common\Fields\TextField.cs" />
<Compile Include="Common\Handlers\RoutableAspectHandler.cs" /> <Compile Include="Common\Handlers\RoutableAspectHandler.cs" />
<Compile Include="Common\ViewModels\ContainerEditorViewModel.cs" /> <Compile Include="Common\ViewModels\ContainerEditorViewModel.cs" />
<Compile Include="Common\ViewModels\TextContentFieldDisplayViewModel.cs" /> <Compile Include="Common\ViewModels\TextContentFieldDisplayViewModel.cs" />
@@ -202,9 +202,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Common\Module.txt" /> <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.Container.ascx" />
<Content Include="Common\Views\EditorTemplates\Parts\Common.TextContentField.ascx" />
<Content Include="Contents\Module.txt" /> <Content Include="Contents\Module.txt" />
<Content Include="Contents\Styles\admin.css" /> <Content Include="Contents\Styles\admin.css" />
<Content Include="Contents\Views\Admin\EditPart.ascx" /> <Content Include="Contents\Views\Admin\EditPart.ascx" />

View File

@@ -59,7 +59,7 @@ namespace Orchard.Core.Routable.Drivers {
// TEMP: path format patterns replaces this logic // TEMP: path format patterns replaces this logic
var path = part.Record.Path; 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); model.DisplayLeadingPath = path.Substring(0, path.Length - part.Slug.Length);
} }

View File

@@ -57,7 +57,7 @@ namespace Orchard.Core.Settings.Metadata {
private ContentTypeDefinitionRecord Acquire(ContentTypeDefinition contentTypeDefinition) { private ContentTypeDefinitionRecord Acquire(ContentTypeDefinition contentTypeDefinition) {
var result = _typeDefinitionRepository.Fetch(x => x.Name == contentTypeDefinition.Name).SingleOrDefault(); var result = _typeDefinitionRepository.Fetch(x => x.Name == contentTypeDefinition.Name).SingleOrDefault();
if (result == null) { if (result == null) {
result = new ContentTypeDefinitionRecord { Name = contentTypeDefinition.Name, DisplayName = contentTypeDefinition.DisplayName}; result = new ContentTypeDefinitionRecord { Name = contentTypeDefinition.Name, DisplayName = contentTypeDefinition.DisplayName };
_typeDefinitionRepository.Create(result); _typeDefinitionRepository.Create(result);
} }
return result; return result;
@@ -111,7 +111,7 @@ namespace Orchard.Core.Settings.Metadata {
record.Settings = _settingsWriter.Map(model.Settings).ToString(); record.Settings = _settingsWriter.Map(model.Settings).ToString();
var toRemove = record.ContentPartFieldDefinitionRecords 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(); .ToList();
foreach (var remove in toRemove) { foreach (var remove in toRemove) {
@@ -120,9 +120,9 @@ namespace Orchard.Core.Settings.Metadata {
foreach (var field in model.Fields) { foreach (var field in model.Fields) {
var fieldName = field.FieldDefinition.Name; 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) { if (partFieldRecord == null) {
partFieldRecord = new ContentPartFieldDefinitionRecord { partFieldRecord = new ContentPartFieldDefinitionRecord {
ContentFieldDefinitionRecord = Acquire(field.FieldDefinition), ContentFieldDefinitionRecord = Acquire(field.FieldDefinition),
Name = field.Name Name = field.Name
}; };

View File

@@ -79,10 +79,9 @@ namespace Orchard.ContentManagement {
} }
var context3 = new InitializingContentContext { var context3 = new InitializingContentContext {
ContentType = contentType, ContentType = context2.ContentType,
ContentItem = context.Builder.Build() ContentItem = context2.ContentItem,
}; };
context3.ContentItem.ContentManager = this;
foreach (var handler in Handlers) { foreach (var handler in Handlers) {
handler.Initializing(context3); handler.Initializing(context3);
@@ -276,7 +275,8 @@ namespace Orchard.ContentManagement {
var buildingItemVersionRecord = new ContentItemVersionRecord { var buildingItemVersionRecord = new ContentItemVersionRecord {
ContentItemRecord = contentItemRecord, ContentItemRecord = contentItemRecord,
Latest = true, Latest = true,
Published = false Published = false,
Data = existingItemVersionRecord.Data,
}; };
@@ -435,11 +435,11 @@ namespace Orchard.ContentManagement {
var indexContentContext = new IndexContentContext(contentItem, documentIndex); var indexContentContext = new IndexContentContext(contentItem, documentIndex);
// dispatch to handlers to retrieve index information // dispatch to handlers to retrieve index information
foreach ( var handler in Handlers ) { foreach (var handler in Handlers) {
handler.Indexing(indexContentContext); handler.Indexing(indexContentContext);
} }
foreach ( var handler in Handlers ) { foreach (var handler in Handlers) {
handler.Indexed(indexContentContext); handler.Indexed(indexContentContext);
} }
} }

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Orchard.ContentManagement.Drivers.FieldStorage;
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.MetaData; using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Models; using Orchard.ContentManagement.MetaData.Models;
@@ -11,23 +11,21 @@ namespace Orchard.ContentManagement.Drivers {
protected virtual string Zone { get { return "body"; } } protected virtual string Zone { get { return "body"; } }
DriverResult IContentFieldDriver.BuildDisplayModel(BuildDisplayModelContext context) { DriverResult IContentFieldDriver.BuildDisplayModel(BuildDisplayModelContext context) {
var results = context.ContentItem.Parts.SelectMany(part => part.Fields). return Process(context.ContentItem, (part, field) => Display(part, field, context.DisplayType));
OfType<TField>().
Select(field => Display(field, context.DisplayType));
return Combined(results.ToArray());
} }
DriverResult IContentFieldDriver.BuildEditorModel(BuildEditorModelContext context) { DriverResult IContentFieldDriver.BuildEditorModel(BuildEditorModelContext context) {
var results = context.ContentItem.Parts.SelectMany(part => part.Fields). return Process(context.ContentItem, (part, field) => Editor(part, field));
OfType<TField>().
Select(field => Editor(field));
return Combined(results.ToArray());
} }
DriverResult IContentFieldDriver.UpdateEditorModel(UpdateEditorModelContext context) { DriverResult IContentFieldDriver.UpdateEditorModel(UpdateEditorModelContext context) {
var results = context.ContentItem.Parts.SelectMany(part => part.Fields). return Process(context.ContentItem, (part, field) => Editor(part, field, context.Updater));
OfType<TField>(). }
Select(field => Editor(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()); 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 Display(ContentPart part, TField field, string displayType) { return null; }
protected virtual DriverResult Editor(TField field) { return null; } protected virtual DriverResult Editor(ContentPart part, TField field) { return null; }
protected virtual DriverResult Editor(TField field, IUpdateModel updater) { return null; } protected virtual DriverResult Editor(ContentPart part, TField field, IUpdateModel updater) { return null; }
public ContentTemplateResult ContentFieldTemplate(object model) { public ContentTemplateResult ContentFieldTemplate(object model) {

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.ContentManagement.Drivers.FieldStorage; using Orchard.ContentManagement.FieldStorage;
using Orchard.ContentManagement.Handlers; using Orchard.ContentManagement.Handlers;
using Orchard.Logging; using Orchard.Logging;

View File

@@ -18,43 +18,46 @@ namespace Orchard.ContentManagement.Drivers.Coordinators {
} }
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public override void Activating(ActivatingContentContext context) { public override void Activating(ActivatingContentContext context) {
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType); var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentType);
if (contentTypeDefinition == null) if (contentTypeDefinition == null)
return; return;
foreach (var partInfo in _drivers.SelectMany(cpp => cpp.GetPartInfo())) { var partInfos = _drivers.SelectMany(cpp => cpp.GetPartInfo());
var partName = partInfo.PartName;
var typePartDefinition = contentTypeDefinition.Parts.FirstOrDefault(p => p.PartDefinition.Name == partName); foreach (var typePartDefinition in contentTypeDefinition.Parts) {
if (typePartDefinition != null) { var partName = typePartDefinition.PartDefinition.Name;
context.Builder.Weld(partInfo.Factory(typePartDefinition)); 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) { public override void BuildDisplayModel(BuildDisplayModelContext context) {
_drivers.Invoke(driver => { _drivers.Invoke(driver => {
var result = driver.BuildDisplayModel(context); var result = driver.BuildDisplayModel(context);
if (result != null) if (result != null)
result.Apply(context); result.Apply(context);
}, Logger); }, Logger);
} }
public override void BuildEditorModel(BuildEditorModelContext context) { public override void BuildEditorModel(BuildEditorModelContext context) {
_drivers.Invoke(driver => { _drivers.Invoke(driver => {
var result = driver.BuildEditorModel(context); var result = driver.BuildEditorModel(context);
if (result != null) if (result != null)
result.Apply(context); result.Apply(context);
}, Logger); }, Logger);
} }
public override void UpdateEditorModel(UpdateEditorModelContext context) { public override void UpdateEditorModel(UpdateEditorModelContext context) {
_drivers.Invoke(driver => { _drivers.Invoke(driver => {
var result = driver.UpdateEditorModel(context); var result = driver.UpdateEditorModel(context);
if (result != null) if (result != null)
result.Apply(context); result.Apply(context);
}, Logger); }, Logger);
} }
} }
} }

View File

@@ -1,9 +1,8 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Orchard.ContentManagement.MetaData.Models; using Orchard.ContentManagement.MetaData.Models;
namespace Orchard.ContentManagement.Drivers.FieldStorage { namespace Orchard.ContentManagement.FieldStorage {
public class FieldStorageProviderSelector : IFieldStorageProviderSelector { public class FieldStorageProviderSelector : IFieldStorageProviderSelector {
public const string Storage = "Storage"; public const string Storage = "Storage";
public const string DefaultProviderName = "Infoset"; public const string DefaultProviderName = "Infoset";

View File

@@ -1,6 +1,6 @@
using System; using System;
namespace Orchard.ContentManagement.Drivers.FieldStorage { namespace Orchard.ContentManagement.FieldStorage {
public interface IFieldStorage { public interface IFieldStorage {
Func<string, string> Getter { get; } Func<string, string> Getter { get; }
Action<string, string> Setter { get; } Action<string, string> Setter { get; }

View File

@@ -1,6 +1,6 @@
using Orchard.ContentManagement.MetaData.Models; using Orchard.ContentManagement.MetaData.Models;
namespace Orchard.ContentManagement.Drivers.FieldStorage { namespace Orchard.ContentManagement.FieldStorage {
public interface IFieldStorageProvider : IDependency { public interface IFieldStorageProvider : IDependency {
string ProviderName { get; } string ProviderName { get; }

View File

@@ -1,6 +1,6 @@
using Orchard.ContentManagement.MetaData.Models; using Orchard.ContentManagement.MetaData.Models;
namespace Orchard.ContentManagement.Drivers.FieldStorage { namespace Orchard.ContentManagement.FieldStorage {
public interface IFieldStorageProviderSelector : IDependency { public interface IFieldStorageProviderSelector : IDependency {
IFieldStorageProvider GetProvider(ContentPartDefinition.Field partFieldDefinition); IFieldStorageProvider GetProvider(ContentPartDefinition.Field partFieldDefinition);
} }

View File

@@ -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));
}
}
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -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; }
}
}

View File

@@ -3,8 +3,8 @@ using System.Xml;
using System.Xml.Linq; using System.Xml.Linq;
using Orchard.ContentManagement.MetaData.Models; using Orchard.ContentManagement.MetaData.Models;
namespace Orchard.ContentManagement.Drivers.FieldStorage { namespace Orchard.ContentManagement.FieldStorage.InfosetStorage {
public class InfosetFieldStorageProvider : IFieldStorageProvider { public class InfosetStorageProvider : IFieldStorageProvider {
public string ProviderName { public string ProviderName {
get { return FieldStorageProviderSelector.DefaultProviderName; } get { return FieldStorageProviderSelector.DefaultProviderName; }
} }
@@ -12,10 +12,11 @@ namespace Orchard.ContentManagement.Drivers.FieldStorage {
public IFieldStorage BindStorage(ContentPart contentPart, ContentPartDefinition.Field partFieldDefinition) { public IFieldStorage BindStorage(ContentPart contentPart, ContentPartDefinition.Field partFieldDefinition) {
var partName = XmlConvert.EncodeLocalName(contentPart.PartDefinition.Name); var partName = XmlConvert.EncodeLocalName(contentPart.PartDefinition.Name);
var fieldName = XmlConvert.EncodeLocalName(partFieldDefinition.Name); var fieldName = XmlConvert.EncodeLocalName(partFieldDefinition.Name);
var infosetPart = contentPart.As<InfosetPart>();
return new Storage { return new Storage {
Getter = name => Get(contentPart.ContentItem.Record.Infoset.Element, partName, fieldName, name), Getter = name => Get(infosetPart.Infoset.Element, partName, fieldName, name),
Setter = (name, value) => Set(contentPart.ContentItem.Record.Infoset.Element, partName, fieldName, name, value) Setter = (name, value) => Set(infosetPart.Infoset.Element, partName, fieldName, name, value)
}; };
} }

View File

@@ -52,13 +52,16 @@ namespace Orchard.ContentManagement.MetaData.Builders {
} }
public ContentPartDefinitionBuilder WithField(string fieldName, Action<FieldConfigurer> configuration) { 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) { if (existingField != null) {
_fields.Remove(existingField); var toRemove = _fields.Where(x => x.Name == fieldName).ToArray();
foreach (var remove in toRemove) {
_fields.Remove(remove);
}
} }
else { else {
existingField = new ContentPartDefinition.Field(fieldDefinition, fieldName, new SettingsDictionary()); existingField = new ContentPartDefinition.Field(fieldName);
} }
var configurer = new FieldConfigurerImpl(existingField); var configurer = new FieldConfigurerImpl(existingField);
configuration(configurer); configuration(configurer);
@@ -84,7 +87,7 @@ namespace Orchard.ContentManagement.MetaData.Builders {
class FieldConfigurerImpl : FieldConfigurer { class FieldConfigurerImpl : FieldConfigurer {
private ContentFieldDefinition _fieldDefinition; private ContentFieldDefinition _fieldDefinition;
private string _fieldName; private readonly string _fieldName;
public FieldConfigurerImpl(ContentPartDefinition.Field field) public FieldConfigurerImpl(ContentPartDefinition.Field field)
: base(field) { : base(field) {

View File

@@ -1,5 +1,5 @@
using System; using System;
using Orchard.ContentManagement.Drivers.FieldStorage; using Orchard.ContentManagement.FieldStorage;
using Orchard.ContentManagement.MetaData.Models; using Orchard.ContentManagement.MetaData.Models;
namespace Orchard.ContentManagement.MetaData { namespace Orchard.ContentManagement.MetaData {

View File

@@ -10,7 +10,7 @@ namespace Orchard.ContentManagement.MetaData.Models {
Settings = settings; Settings = settings;
} }
public ContentPartDefinition(string name) { public ContentPartDefinition(string name) {
Name = name; Name = name;
Fields = Enumerable.Empty<Field>(); Fields = Enumerable.Empty<Field>();
Settings = new SettingsDictionary(); Settings = new SettingsDictionary();
@@ -21,9 +21,14 @@ namespace Orchard.ContentManagement.MetaData.Models {
public SettingsDictionary Settings { get; private set; } public SettingsDictionary Settings { get; private set; }
public class Field { public class Field {
public Field(ContentFieldDefinition contentFieldDefinition, string name, SettingsDictionary settings) { public Field(string name) {
FieldDefinition = contentFieldDefinition;
Name = name; Name = name;
FieldDefinition = new ContentFieldDefinition(null);
Settings = new SettingsDictionary();
}
public Field( ContentFieldDefinition contentFieldDefinition, string name, SettingsDictionary settings) {
Name = name;
FieldDefinition = contentFieldDefinition;
Settings = settings; Settings = settings;
} }

View File

@@ -36,14 +36,14 @@ namespace Orchard.ContentManagement.MetaData.Services {
foreach (var iter in source.Elements()) { foreach (var iter in source.Elements()) {
var fieldElement = iter; var fieldElement = iter;
string[] fieldParameters = fieldElement.Name.LocalName.Split('.'); var fieldParameters = XmlConvert.DecodeName(fieldElement.Name.LocalName).Split('.');
builder.WithField( builder.WithField(
XmlConvert.DecodeName(fieldParameters[0]), fieldParameters[0],
fieldBuilder => { fieldBuilder => {
fieldBuilder.OfType(fieldParameters[1]);
foreach (var setting in _settingsReader.Map(fieldElement)) { foreach (var setting in _settingsReader.Map(fieldElement)) {
fieldBuilder.WithSetting(setting.Key, setting.Value); fieldBuilder.WithSetting(setting.Key, setting.Value);
} }
fieldBuilder.OfType(fieldParameters[1]);
}); });
} }
} }

View File

@@ -33,6 +33,7 @@ namespace Orchard.ContentManagement.Records {
var alteration = (IAlteration<ContentItemRecord>)Activator.CreateInstance(type); var alteration = (IAlteration<ContentItemRecord>)Activator.CreateInstance(type);
alteration.Override(mapping); alteration.Override(mapping);
} }
mapping.IgnoreProperty(x => x.Infoset);
}); });
model.Override<ContentItemVersionRecord>(mapping => { model.Override<ContentItemVersionRecord>(mapping => {
@@ -41,6 +42,7 @@ namespace Orchard.ContentManagement.Records {
var alteration = (IAlteration<ContentItemVersionRecord>)Activator.CreateInstance(type); var alteration = (IAlteration<ContentItemVersionRecord>)Activator.CreateInstance(type);
alteration.Override(mapping); alteration.Override(mapping);
} }
mapping.IgnoreProperty(x => x.Infoset);
}); });
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Xml.Linq; using Orchard.ContentManagement.FieldStorage;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
namespace Orchard.ContentManagement.Records { namespace Orchard.ContentManagement.Records {
public class ContentItemRecord { public class ContentItemRecord {
@@ -15,30 +16,7 @@ namespace Orchard.ContentManagement.Records {
public virtual ContentTypeRecord ContentType { get; set; } public virtual ContentTypeRecord ContentType { get; set; }
public virtual IList<ContentItemVersionRecord> Versions { get; set; } public virtual IList<ContentItemVersionRecord> Versions { get; set; }
public virtual string Data { public virtual string Data { get { return Infoset.Data; } set { Infoset.Data = value; } }
get { return Infoset.Data; }
set { Infoset.Data = value; }
}
public virtual Infoset Infoset { get; private set; } 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)); }
}
}
} }

View File

@@ -1,10 +1,21 @@
using System;
using Orchard.ContentManagement.FieldStorage;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
namespace Orchard.ContentManagement.Records { namespace Orchard.ContentManagement.Records {
public class ContentItemVersionRecord { public class ContentItemVersionRecord {
public ContentItemVersionRecord() {
Infoset = new Infoset();
}
public virtual int Id { get; set; } public virtual int Id { get; set; }
public virtual ContentItemRecord ContentItemRecord { get; set; } public virtual ContentItemRecord ContentItemRecord { get; set; }
public virtual int Number { get; set; } public virtual int Number { get; set; }
public virtual bool Published { get; set; } public virtual bool Published { get; set; }
public virtual bool Latest { 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; }
} }
} }

View File

@@ -192,19 +192,21 @@
<Compile Include="ContentManagement\Drivers\DriverResult.cs"> <Compile Include="ContentManagement\Drivers\DriverResult.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="ContentManagement\Drivers\FieldStorage\FieldStorageProviderSelector.cs" /> <Compile Include="ContentManagement\FieldStorage\FieldStorageProviderSelector.cs" />
<Compile Include="ContentManagement\Drivers\IContentFieldDriver.cs" /> <Compile Include="ContentManagement\Drivers\IContentFieldDriver.cs" />
<Compile Include="ContentManagement\Drivers\IContentItemDriver.cs"> <Compile Include="ContentManagement\Drivers\IContentItemDriver.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="ContentManagement\Drivers\IContentPartDriver.cs" /> <Compile Include="ContentManagement\Drivers\IContentPartDriver.cs" />
<Compile Include="ContentManagement\Drivers\FieldStorage\IFieldStorage.cs" /> <Compile Include="ContentManagement\FieldStorage\IFieldStorage.cs" />
<Compile Include="ContentManagement\Drivers\FieldStorage\IFieldStorageProvider.cs" /> <Compile Include="ContentManagement\FieldStorage\IFieldStorageProvider.cs" />
<Compile Include="ContentManagement\Drivers\FieldStorage\IFieldStorageProviderSelector.cs" /> <Compile Include="ContentManagement\FieldStorage\IFieldStorageProviderSelector.cs" />
<Compile Include="ContentManagement\Drivers\FieldStorage\InfosetFieldStorageProvider.cs" /> <Compile Include="ContentManagement\FieldStorage\InfosetStorage\InfosetStorageProvider.cs" />
<Compile Include="ContentManagement\Extenstions\UrlHelperExtensions.cs"> <Compile Include="ContentManagement\Extenstions\UrlHelperExtensions.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="ContentManagement\FieldStorage\InfosetStorage\InfosetHandler.cs" />
<Compile Include="ContentManagement\FieldStorage\InfosetStorage\InfosetPart.cs" />
<Compile Include="ContentManagement\Handlers\ActivatedContentContext.cs"> <Compile Include="ContentManagement\Handlers\ActivatedContentContext.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
@@ -343,6 +345,7 @@
<Compile Include="ContentManagement\Records\ContentTypeRecord.cs"> <Compile Include="ContentManagement\Records\ContentTypeRecord.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="ContentManagement\FieldStorage\InfosetStorage\Infoset.cs" />
<Compile Include="ContentManagement\Records\Utility.cs"> <Compile Include="ContentManagement\Records\Utility.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>