Files
Orchard/src/Orchard.Web/Modules/Orchard.Widgets/Migrations.cs
Suha Can ce208c44f2 - RuleEngine implementation for widget layer rules.
- The ResultFilter uses the rule manager to filter out layers and widgets.
- Added rules to default layers.
- RuleManager with callback injection into the dlr scripting sandbox.
- RuleProvider implementations for Url and Authenticated. Anonymous is just "not Authenticated".
- RuleContext.
- Renaming Layer.Rule to Layer.LayerRule. NHibernate bug for SqlCe most likely, couldn't escape "Rule" as expected.
- Unit tests.

--HG--
branch : dev
2010-10-04 12:27:59 -07:00

83 lines
3.2 KiB
C#

using System.Collections.Generic;
using Orchard.ContentManagement;
using Orchard.ContentManagement.MetaData;
using Orchard.Data.Migration;
using Orchard.Environment.Configuration;
using Orchard.Environment.Descriptor.Models;
using Orchard.Environment.State;
using Orchard.Events;
using Orchard.Widgets.Models;
namespace Orchard.Widgets {
public interface IDefaultLayersInitializer : IEventHandler {
void CreateDefaultLayers();
}
public class DefaultLayersInitializer : IDefaultLayersInitializer {
private readonly IContentManager _contentManager;
public DefaultLayersInitializer(IContentManager contentManager) {
_contentManager = contentManager;
}
public void CreateDefaultLayers() {
IContent defaultLayer = _contentManager.Create<LayerPart>("Layer", t => { t.Record.Name = "Default"; t.Record.LayerRule = "true"; });
_contentManager.Publish(defaultLayer.ContentItem);
IContent authenticatedLayer = _contentManager.Create<LayerPart>("Layer", t => { t.Record.Name = "Authenticated"; t.Record.LayerRule = "Authenticated"; });
_contentManager.Publish(authenticatedLayer.ContentItem);
IContent anonymousLayer = _contentManager.Create<LayerPart>("Layer", t => { t.Record.Name = "Anonymous"; t.Record.LayerRule = "not Authenticated"; });
_contentManager.Publish(anonymousLayer.ContentItem);
}
}
public class WidgetsDataMigration : DataMigrationImpl {
private readonly IProcessingEngine _processingEngine;
private readonly ShellSettings _shellSettings;
private readonly ShellDescriptor _shellDescriptor;
public WidgetsDataMigration(IProcessingEngine processingEngine, ShellSettings shellSettings, ShellDescriptor shellDescriptor) {
_processingEngine = processingEngine;
_shellSettings = shellSettings;
_shellDescriptor = shellDescriptor;
}
public int Create() {
SchemaBuilder.CreateTable("LayerPartRecord", table => table
.ContentPartRecord()
.Column<string>("Name")
.Column<string>("Description")
.Column<string>("LayerRule")
);
SchemaBuilder.CreateTable("WidgetPartRecord", table => table
.ContentPartRecord()
.Column<string>("Title")
.Column<string>("Position")
.Column<string>("Zone")
);
ContentDefinitionManager.AlterTypeDefinition("Layer",
cfg => cfg
.WithPart("LayerPart")
);
ContentDefinitionManager.AlterTypeDefinition("HtmlWidget",
cfg => cfg
.WithPart("WidgetPart")
.WithPart("BodyPart")
);
CreateDefaultLayers();
return 1;
}
private void CreateDefaultLayers() {
_processingEngine.AddTask(
_shellSettings,
_shellDescriptor,
"IDefaultLayersInitializer.CreateDefaultLayers",
new Dictionary<string, object>());
}
}
}