Changing AddOnXxx to OnXxx in the content provider. Starting to hook up BodyAspect.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042764
This commit is contained in:
loudej
2009-11-30 20:15:52 +00:00
parent 9852c56cb2
commit d39042fda2
10 changed files with 77 additions and 18 deletions

View File

@@ -1,8 +1,7 @@
using Orchard.Core.Common.Records;
using Orchard.Models;
namespace Orchard.Core.Common.Models {
public class BodyAspect : ContentPart {
public string Body { get; set; }
public string Format { get; set; }
public class BodyAspect : ContentPart<BodyRecord> {
}
}

View File

@@ -1,7 +1,18 @@
using System;
using Orchard.Core.Common.Models;
using Orchard.Core.Common.Records;
using Orchard.Data;
using Orchard.Models.Driver;
namespace Orchard.Core.Common.Providers {
public class BodyAspectProvider : ContentProvider {
public BodyAspectProvider(IRepository<BodyRecord> bodyRepository) {
Filters.Add(new StorageFilter<BodyRecord>(bodyRepository));
OnGetEditors<BodyAspect>();
}
private void OnGetEditors<TPart>() {
}
}
}

View File

@@ -23,9 +23,9 @@ namespace Orchard.Core.Common.Providers {
_authenticationService = authenticationService;
_contentManager = contentManager;
AddOnActivated<CommonAspect>(PropertySetHandlers);
AddOnCreating<CommonAspect>(DefaultTimestampsAndOwner);
AddOnLoaded<CommonAspect>(LazyLoadHandlers);
OnActivated<CommonAspect>(PropertySetHandlers);
OnCreating<CommonAspect>(DefaultTimestampsAndOwner);
OnLoaded<CommonAspect>(LazyLoadHandlers);
Filters.Add(new StorageFilter<CommonRecord>(repository));
}

View File

@@ -9,7 +9,7 @@ namespace Orchard.Blogs.Models {
public Blog Blog { get; set; }
public string Title { get { return this.As<RoutableAspect>().Title; } }
public string Body { get { return this.As<BodyAspect>().Body; } }
public string Body { get { return this.As<BodyAspect>().Record.Body; } }
public string Slug { get { return this.As<RoutableAspect>().Slug; } }
public IUser Creator { get { return this.As<CommonAspect>().OwnerField.Value; } }
public DateTime? Published { get { return Record.Published; } }

View File

@@ -16,7 +16,7 @@ namespace Orchard.Blogs.Models {
Filters.Add(new ActivatingFilter<RoutableAspect>("blogpost"));
Filters.Add(new ActivatingFilter<BodyAspect>("blogpost"));
Filters.Add(new StorageFilter<BlogPostRecord>(repository));
AddOnLoaded<BlogPost>((context, bp) => bp.Blog = contentManager.Get<Blog>(bp.Record.Blog.Id));
OnLoaded<BlogPost>((context, bp) => bp.Blog = contentManager.Get<Blog>(bp.Record.Blog.Id));
}
}
}

View File

@@ -23,7 +23,7 @@ namespace Orchard.Comments.Models {
Filters.Add(new ActivatingFilter<CommentSettings>("site"));
Filters.Add(new StorageFilter<CommentSettingsRecord>(_commentSettingsRepository) { AutomaticallyCreateMissingRecord = true });
Filters.Add(new TemplateFilterForRecord<CommentSettingsRecord>("CommentSettings"));
AddOnActivated<CommentSettings>(DefaultSettings);
OnActivated<CommentSettings>(DefaultSettings);
}
private static void DefaultSettings(ActivatedContentContext context, CommentSettings settings) {

View File

@@ -16,7 +16,7 @@ namespace Orchard.Media.Models {
public MediaSettingsProvider(IRepository<MediaSettingsRecord> repository) {
Filters.Add(new ActivatingFilter<MediaSettings>("site"));
Filters.Add(new StorageFilter<MediaSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
AddOnActivated<MediaSettings>(DefaultSettings);
OnActivated<MediaSettings>(DefaultSettings);
}
private static void DefaultSettings(ActivatedContentContext context, MediaSettings settings) {

View File

@@ -22,7 +22,7 @@ namespace Orchard.Roles.Models {
_notifier = notifier;
Filters.Add(new ActivatingFilter<UserRoles>("user"));
AddOnLoaded<UserRoles>((context, userRoles) => {
OnLoaded<UserRoles>((context, userRoles) => {
userRoles.Roles = _userRolesRepository
.Fetch(x => x.UserId == context.ContentItem.Id)
.Select(x => x.Role.Name).ToList();

View File

@@ -16,7 +16,7 @@ namespace Orchard.Tags.Models {
Filters.Add(new ActivatingFilter<TagSettings>("site"));
Filters.Add(new StorageFilter<TagSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
Filters.Add(new TemplateFilterForRecord<TagSettingsRecord>("TagSettings"));
AddOnActivated<TagSettings>(DefaultSettings);
OnActivated<TagSettings>(DefaultSettings);
}
private static void DefaultSettings(ActivatedContentContext context, TagSettings settings) {

View File

@@ -13,25 +13,74 @@ namespace Orchard.Models.Driver {
public List<IContentFilter> Filters { get; set; }
public ILogger Logger { get; set; }
public void AddOnActivated<TPart>(Action<ActivatedContentContext, TPart> handler) where TPart : class, IContent {
protected void OnActivated<TPart>(Action<ActivatedContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnActivated = handler });
}
public void AddOnCreating<TPart>(Action<CreateContentContext, TPart> handler) where TPart : class, IContent {
protected void OnCreating<TPart>(Action<CreateContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnCreating = handler });
}
public void AddOnLoaded<TPart>(Action<LoadContentContext, TPart> handler) where TPart : class, IContent {
protected void OnCreated<TPart>(Action<CreateContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnCreated = handler });
}
protected void OnLoading<TPart>(Action<LoadContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnLoading = handler });
}
protected void OnLoaded<TPart>(Action<LoadContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineStorageFilter<TPart> { OnLoaded = handler });
}
protected void OnGetDisplays<TPart>(Action<GetDisplaysContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineTemplateFilter<TPart> { OnGetDisplays = handler });
}
protected void OnGetEditors<TPart>(Action<GetEditorsContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineTemplateFilter<TPart> { OnGetEditors = handler });
}
protected void OnUpdateEditors<TPart>(Action<UpdateContentContext, TPart> handler) where TPart : class, IContent {
Filters.Add(new InlineTemplateFilter<TPart> { OnUpdateEditors = handler });
}
class InlineStorageFilter<TPart> : StorageFilterBase<TPart> where TPart : class, IContent {
public Action<ActivatedContentContext, TPart> OnActivated { get; set; }
public Action<CreateContentContext, TPart> OnCreating { get; set; }
public Action<CreateContentContext, TPart> OnCreated { get; set; }
public Action<LoadContentContext, TPart> OnLoading { get; set; }
public Action<LoadContentContext, TPart> OnLoaded { get; set; }
protected override void Activated(ActivatedContentContext context, TPart instance) { if (OnActivated != null) OnActivated(context, instance); }
protected override void Creating(CreateContentContext context, TPart instance) { if (OnCreating != null) OnCreating(context, instance); }
protected override void Loaded(LoadContentContext context, TPart instance) { if (OnLoaded != null) OnLoaded(context, instance); }
protected override void Activated(ActivatedContentContext context, TPart instance) {
if (OnActivated != null) OnActivated(context, instance);
}
protected override void Creating(CreateContentContext context, TPart instance) {
if (OnCreating != null) OnCreating(context, instance);
}
protected override void Created(CreateContentContext context, TPart instance) {
if (OnCreating != null) OnCreated(context, instance);
}
protected override void Loading(LoadContentContext context, TPart instance) {
if (OnLoaded != null) OnLoading(context, instance);
}
protected override void Loaded(LoadContentContext context, TPart instance) {
if (OnLoaded != null) OnLoaded(context, instance);
}
}
class InlineTemplateFilter<TPart> : TemplateFilterBase<TPart> where TPart : class, IContent {
public Action<GetDisplaysContext, TPart> OnGetDisplays { get; set; }
public Action<GetEditorsContext, TPart> OnGetEditors { get; set; }
public Action<UpdateContentContext, TPart> OnUpdateEditors { get; set; }
protected override void GetDisplays(GetDisplaysContext context, TPart instance) {
if (OnGetDisplays != null) OnGetDisplays(context, instance);
}
protected override void GetEditors(GetEditorsContext context, TPart instance) {
if (OnGetEditors != null) OnGetEditors(context, instance);
}
protected override void UpdateEditors(UpdateContentContext context, TPart instance) {
if (OnUpdateEditors != null) OnUpdateEditors(context, instance);
}
}
public virtual IEnumerable<ContentType> GetContentTypes() {