Shifting parts

This commit is contained in:
Sebastien Ros
2013-10-03 14:57:37 -07:00
parent 6783355f3e
commit 150761875d
7 changed files with 85 additions and 31 deletions

View File

@@ -1,10 +1,14 @@
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
namespace Orchard.Core.Common.Models { namespace Orchard.Core.Common.Models {
public class BodyPart : ContentPart<BodyPartRecord> { public class BodyPart : ContentPart<BodyPartRecord> {
public string Text { public string Text {
get { return Record.Text; } get { return this.As<InfosetPart>().Get<BodyPart>("Text"); }
set { Record.Text = value; } set {
this.As<InfosetPart>().Set<BodyPart>("Text", value);
Record.Text = value;
}
} }
} }
} }

View File

@@ -1,4 +1,6 @@
using System; using System;
using System.Xml;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
using Orchard.Core.Common.Utilities; using Orchard.Core.Common.Utilities;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Aspects;
@@ -22,20 +24,41 @@ namespace Orchard.Core.Common.Models {
get { return _container.Value; } get { return _container.Value; }
set { _container.Value = value; } set { _container.Value = value; }
} }
public DateTime? CreatedUtc { public DateTime? CreatedUtc {
get { return Record.CreatedUtc; } get {
set { Record.CreatedUtc = value; } var dateTime = this.As<InfosetPart>().Get<CommonPart>("CreatedUtc");
return dateTime == "" ? (DateTime?)null : XmlConvert.ToDateTime(dateTime, XmlDateTimeSerializationMode.Utc);
}
set {
string dateTime = value.HasValue ? XmlConvert.ToString(value.Value, XmlDateTimeSerializationMode.Utc) : "";
this.As<InfosetPart>().Set<CommonPart>("CreatedUtc", dateTime);
Record.CreatedUtc = value;
}
} }
public DateTime? PublishedUtc { public DateTime? PublishedUtc {
get { return Record.PublishedUtc; } get {
set { Record.PublishedUtc = value; } var dateTime = this.As<InfosetPart>().Get<CommonPart>("PublishedUtc");
return dateTime == "" ? (DateTime?)null : XmlConvert.ToDateTime(dateTime, XmlDateTimeSerializationMode.Utc);
}
set {
string dateTime = value.HasValue ? XmlConvert.ToString(value.Value, XmlDateTimeSerializationMode.Utc) : "";
this.As<InfosetPart>().Set<CommonPart>("PublishedUtc", dateTime);
Record.PublishedUtc = value;
}
} }
public DateTime? ModifiedUtc { public DateTime? ModifiedUtc {
get { return Record.ModifiedUtc; } get {
set { Record.ModifiedUtc = value; } var dateTime = this.As<InfosetPart>().Get<CommonPart>("ModifiedUtc");
return dateTime == "" ? (DateTime?)null : XmlConvert.ToDateTime(dateTime, XmlDateTimeSerializationMode.Utc);
}
set {
string dateTime = value.HasValue ? XmlConvert.ToString(value.Value, XmlDateTimeSerializationMode.Utc) : "";
this.As<InfosetPart>().Set<CommonPart>("ModifiedUtc", dateTime);
Record.ModifiedUtc = value;
}
} }
CommonPartVersionRecord PartVersionRecord { CommonPartVersionRecord PartVersionRecord {
@@ -47,9 +70,12 @@ namespace Orchard.Core.Common.Models {
public DateTime? VersionCreatedUtc { public DateTime? VersionCreatedUtc {
get { get {
return PartVersionRecord == null ? CreatedUtc : PartVersionRecord.CreatedUtc; var dateTime = this.As<InfosetPart>().Get<ContentPart<CommonPartVersionRecord>>("CreatedUtc");
return dateTime == "" ? (DateTime?)null : XmlConvert.ToDateTime(dateTime, XmlDateTimeSerializationMode.Utc);
} }
set { set {
string dateTime = value.HasValue ? XmlConvert.ToString(value.Value, XmlDateTimeSerializationMode.Utc) : "";
this.As<InfosetPart>().Set<ContentPart<CommonPartVersionRecord>>("CreatedUtc", dateTime);
if (PartVersionRecord != null) if (PartVersionRecord != null)
PartVersionRecord.CreatedUtc = value; PartVersionRecord.CreatedUtc = value;
} }
@@ -57,9 +83,12 @@ namespace Orchard.Core.Common.Models {
public DateTime? VersionPublishedUtc { public DateTime? VersionPublishedUtc {
get { get {
return PartVersionRecord == null ? PublishedUtc : PartVersionRecord.PublishedUtc; var dateTime = this.As<InfosetPart>().Get<ContentPart<CommonPartVersionRecord>>("PublishedUtc");
return dateTime == "" ? (DateTime?)null : XmlConvert.ToDateTime(dateTime, XmlDateTimeSerializationMode.Utc);
} }
set { set {
string dateTime = value.HasValue ? XmlConvert.ToString(value.Value, XmlDateTimeSerializationMode.Utc) : "";
this.As<InfosetPart>().Set<ContentPart<CommonPartVersionRecord>>("PublishedUtc", dateTime);
if (PartVersionRecord != null) if (PartVersionRecord != null)
PartVersionRecord.PublishedUtc = value; PartVersionRecord.PublishedUtc = value;
} }
@@ -67,12 +96,16 @@ namespace Orchard.Core.Common.Models {
public DateTime? VersionModifiedUtc { public DateTime? VersionModifiedUtc {
get { get {
return PartVersionRecord == null ? ModifiedUtc : PartVersionRecord.ModifiedUtc; var dateTime = this.As<InfosetPart>().Get<ContentPart<CommonPartVersionRecord>>("ModifiedUtc");
return dateTime == "" ? (DateTime?)null : XmlConvert.ToDateTime(dateTime, XmlDateTimeSerializationMode.Utc);
} }
set { set {
string dateTime = value.HasValue ? XmlConvert.ToString(value.Value, XmlDateTimeSerializationMode.Utc) : "";
this.As<InfosetPart>().Set<ContentPart<CommonPartVersionRecord>>("ModifiedUtc", dateTime);
if (PartVersionRecord != null) if (PartVersionRecord != null)
PartVersionRecord.ModifiedUtc = value; PartVersionRecord.ModifiedUtc = value;
} }
} }
} }
} }

View File

@@ -1,10 +1,14 @@
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
namespace Orchard.Core.Common.Models { namespace Orchard.Core.Common.Models {
public class IdentityPart : ContentPart<IdentityPartRecord> { public class IdentityPart : ContentPart<IdentityPartRecord> {
public string Identifier { public string Identifier {
get { return Record.Identifier; } get { return this.As<InfosetPart>().Get<IdentityPart>("Identifier"); }
set { Record.Identifier = value; } set {
this.As<InfosetPart>().Set<IdentityPart>("Identifier", value);
Record.Identifier = value;
}
} }
} }
} }

View File

@@ -1,13 +1,17 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
namespace Orchard.Core.Title.Models { namespace Orchard.Core.Title.Models {
public class TitlePart : ContentPart<TitlePartRecord>, ITitleAspect { public class TitlePart : ContentPart<TitlePartRecord>, ITitleAspect {
[Required] [Required]
public string Title { public string Title {
get { return Record.Title; } get { return this.As<InfosetPart>().Get<TitlePart>("Title"); }
set { Record.Title = value; } set {
this.As<InfosetPart>().Set<TitlePart>("Title", value);
Record.Title = value;
}
} }
} }
} }

View File

@@ -1,22 +1,32 @@
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
namespace Orchard.Autoroute.Models { namespace Orchard.Autoroute.Models {
public class AutoroutePart : ContentPart<AutoroutePartRecord>, IAliasAspect { public class AutoroutePart : ContentPart<AutoroutePartRecord>, IAliasAspect {
public string CustomPattern { public string CustomPattern {
get { return Record.CustomPattern; } get { return this.As<InfosetPart>().Get<AutoroutePart>("CustomPattern"); }
set { Record.CustomPattern = value; } set {
this.As<InfosetPart>().Set<AutoroutePart>("CustomPattern", value);
Record.CustomPattern = value;
}
} }
public bool UseCustomPattern { public bool UseCustomPattern {
get { return Record.UseCustomPattern; } get { return bool.Parse(this.As<InfosetPart>().Get<AutoroutePart>("UseCustomPattern")); }
set { Record.UseCustomPattern = value; } set {
this.As<InfosetPart>().Set<AutoroutePart>("UseCustomPattern", value.ToString());
Record.UseCustomPattern = value;
}
} }
public string DisplayAlias { public string DisplayAlias {
get { return Record.DisplayAlias; } get { return this.As<InfosetPart>().Get<AutoroutePart>("DisplayAlias"); }
set { Record.DisplayAlias = value; } set {
this.As<InfosetPart>().Set<AutoroutePart>("DisplayAlias", value);
Record.DisplayAlias = value;
}
} }
public string Path { public string Path {

View File

@@ -76,7 +76,6 @@ namespace Orchard.ContentManagement {
return true; return true;
} }
} }
public class ContentPart<TRecord> : ContentPart { public class ContentPart<TRecord> : ContentPart {

View File

@@ -25,18 +25,18 @@ namespace Orchard.ContentManagement.FieldStorage.InfosetStorage {
} }
public string Get(string partName, string fieldName, string valueName) { public string Get(string partName, string fieldName, string valueName) {
var partElement = Infoset.Element.Element(partName); var partElement = Infoset.Element.Element(XmlConvert.EncodeName(partName));
if (partElement == null) { if (partElement == null) {
return null; return null;
} }
var fieldElement = partElement.Element(fieldName); var fieldElement = partElement.Element(XmlConvert.EncodeName(fieldName));
if (fieldElement == null) { if (fieldElement == null) {
return null; return null;
} }
if (string.IsNullOrEmpty(valueName)) { if (string.IsNullOrEmpty(valueName)) {
return fieldElement.Value; return fieldElement.Value;
} }
var valueAttribute = fieldElement.Attribute(XmlConvert.EncodeLocalName(valueName)); var valueAttribute = fieldElement.Attribute(XmlConvert.EncodeName(valueName));
if (valueAttribute == null) { if (valueAttribute == null) {
return null; return null;
} }
@@ -56,21 +56,21 @@ namespace Orchard.ContentManagement.FieldStorage.InfosetStorage {
} }
public void Set(string partName, string fieldName, string valueName, string value) { public void Set(string partName, string fieldName, string valueName, string value) {
var partElement = Infoset.Element.Element(partName); var partElement = Infoset.Element.Element(XmlConvert.EncodeName(partName));
if (partElement == null) { if (partElement == null) {
partElement = new XElement(partName); partElement = new XElement(XmlConvert.EncodeName(partName));
Infoset.Element.Add(partElement); Infoset.Element.Add(partElement);
} }
var fieldElement = partElement.Element(fieldName); var fieldElement = partElement.Element(XmlConvert.EncodeName(fieldName));
if (fieldElement == null) { if (fieldElement == null) {
fieldElement = new XElement(fieldName); fieldElement = new XElement(XmlConvert.EncodeName(fieldName));
partElement.Add(fieldElement); partElement.Add(fieldElement);
} }
if (string.IsNullOrEmpty(valueName)) { if (string.IsNullOrEmpty(valueName)) {
fieldElement.Value = value ?? ""; fieldElement.Value = value ?? "";
} }
else { else {
fieldElement.SetAttributeValue(XmlConvert.EncodeLocalName(valueName), value ?? ""); fieldElement.SetAttributeValue(XmlConvert.EncodeName(valueName), value);
} }
} }
} }