IdentityPart as a last resort GUID for references.

Adding it to htmlwidget and comment.

--HG--
branch : dev
This commit is contained in:
Suha Can
2011-03-17 14:25:23 -07:00
parent db91c88615
commit 8e6001b8fc
13 changed files with 121 additions and 23 deletions

View File

@@ -0,0 +1,30 @@
using JetBrains.Annotations;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Models;
using Orchard.Localization;
namespace Orchard.Core.Common.Drivers {
[UsedImplicitly]
public class IdentityPartDriver : ContentPartDriver<IdentityPart> {
public IdentityPartDriver() {
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
protected override string Prefix {
get { return "Identity"; }
}
protected override void Importing(IdentityPart part, ContentManagement.Handlers.ImportContentContext context) {
var identity = context.Attribute(part.PartDefinition.Name, "Identifier");
if (identity != null) {
part.Identifier = identity;
}
}
protected override void Exporting(IdentityPart part, ContentManagement.Handlers.ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Identifier", part.Identifier);
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.Core.Common.Models;
using Orchard.Data;
using Orchard.ContentManagement.Handlers;
namespace Orchard.Core.Common.Handlers {
[UsedImplicitly]
public class IdentityPartHandler : ContentHandler {
public IdentityPartHandler(IRepository<IdentityPartRecord> identityRepository) {
Filters.Add(StorageFilter.For(identityRepository));
OnInitializing<IdentityPart>(AssignIdentity);
}
protected void AssignIdentity(InitializingContentContext context, IdentityPart part) {
part.Identifier = Guid.NewGuid().ToString("n");
}
protected override void GetItemMetadata(GetContentItemMetadataContext context) {
var part = context.ContentItem.As<IdentityPart>();
if (part != null) {
context.Metadata.Identity.Add("Identifier", part.Identifier);
}
}
}
}

View File

@@ -36,5 +36,16 @@ namespace Orchard.Core.Common {
return 1;
}
public int UpdateFrom1() {
SchemaBuilder.CreateTable("IdentityPartRecord",
table => table
.ContentPartRecord()
.Column<string>("Identifier", column => column.Unlimited())
);
ContentDefinitionManager.AlterPartDefinition("IdentityPart", builder => builder.Attachable());
return 2;
}
}
}

View File

@@ -0,0 +1,10 @@
using Orchard.ContentManagement;
namespace Orchard.Core.Common.Models {
public class IdentityPart : ContentPart<IdentityPartRecord> {
public string Identifier {
get { return Record.Identifier; }
set { Record.Identifier = value; }
}
}
}

View File

@@ -0,0 +1,7 @@
using Orchard.ContentManagement.Records;
namespace Orchard.Core.Common.Models {
public class IdentityPartRecord : ContentPartRecord {
public virtual string Identifier { get; set; }
}
}

View File

@@ -61,7 +61,11 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="Common\Drivers\IdentityPartDriver.cs" />
<Compile Include="Common\Handlers\IdentityPartHandler.cs" />
<Compile Include="Common\Models\CommonPartVersionRecord.cs" />
<Compile Include="Common\Models\IdentityPartRecord.cs" />
<Compile Include="Common\Models\IdentityPart.cs" />
<Compile Include="Common\Services\XmlRpcHandler.cs" />
<Compile Include="Containers\Controllers\ItemController.cs" />
<Compile Include="Containers\Drivers\ContainablePartDriver.cs" />