Merge 1.x

--HG--
branch : autoroute
This commit is contained in:
randompete
2011-12-31 04:26:55 +00:00
57 changed files with 1858 additions and 490 deletions

View File

@@ -1,5 +1,5 @@
Autofac IoC Container
Copyright (c) 2007-2008 Autofac Contributors
Copyright (c) 2007-2010 Autofac Contributors
http://code.google.com/p/autofac/wiki/Contributing
Other software included in this distribution is owned and

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -28,7 +28,7 @@ namespace Orchard.Core.Tests.Scheduling {
public override void Init() {
base.Init();
_repository = _container.Resolve<IRepository<ScheduledTaskRecord>>();
_executor = _container.Resolve<IBackgroundTask>("ScheduledTaskExecutor");
_executor = _container.ResolveNamed<IBackgroundTask>("ScheduledTaskExecutor");
}
public override void Register(ContainerBuilder builder) {
_handler = new StubTaskHandler();

View File

@@ -78,7 +78,7 @@ namespace Orchard.Tests.ContentManagement.Handlers.Coordinators {
}
protected override DriverResult Display(StubPart part, string displayType, dynamic shapeHelper) {
var stub = shapeHelper.Stub(ContentPart: part, Foo: string.Join(",", part.Foo));
var stub = shapeHelper.Stub(Foo: string.Join(",", part.Foo));
if (!string.IsNullOrWhiteSpace(displayType))
stub.Metadata.Type = string.Format("{0}.{1}", stub.Metadata.Type, displayType);
return ContentShape(stub).Location("TopMeta");

View File

@@ -89,6 +89,10 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
throw new NotImplementedException();
}
public void DeleteFile(string virtualPath) {
throw new NotImplementedException();
}
public bool DirectoryExists(string virtualPath) {
throw new NotImplementedException();
}
@@ -97,6 +101,10 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
throw new NotImplementedException();
}
public virtual void DeleteDirectory(string virtualPath) {
throw new NotImplementedException();
}
public string GetDirectoryName(string virtualPath) {
throw new NotImplementedException();
}

View File

@@ -86,6 +86,10 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
throw new NotImplementedException();
}
public void DeleteFile(string virtualPath) {
throw new NotImplementedException();
}
public bool DirectoryExists(string virtualPath) {
throw new NotImplementedException();
}
@@ -98,6 +102,10 @@ namespace Orchard.Tests.DisplayManagement.Descriptors {
throw new NotImplementedException();
}
public void DeleteDirectory(string virtualPath) {
throw new NotImplementedException();
}
public IEnumerable<string> ListFiles(string path) {
return TestViewEngine.Keys.Select(o => o.ToString());
}

View File

@@ -135,7 +135,7 @@ namespace Orchard.Tests.Environment {
[Test]
[Test, Ignore("containers are disposed when calling BeginRequest, maybe by the StubVirtualPathMonitor")]
public void NormalDependenciesShouldBeUniquePerRequestContainer() {
var host = _lifetime.Resolve<IOrchardHost>();
var container1 = host.CreateShellContainer_Obsolete();

View File

@@ -78,6 +78,10 @@ namespace Orchard.Tests.Stubs {
throw new NotImplementedException();
}
public void DeleteFile(string virtualPath) {
_fileSystem.DeleteFile(ToFileSystemPath(virtualPath));
}
public bool DirectoryExists(string virtualPath) {
return _fileSystem.GetDirectoryEntry(ToFileSystemPath(virtualPath)) != null;
}
@@ -86,6 +90,10 @@ namespace Orchard.Tests.Stubs {
_fileSystem.CreateDirectoryEntry(ToFileSystemPath(virtualPath));
}
public void DeleteDirectory(string virtualPath) {
throw new NotImplementedException();
}
public string GetDirectoryName(string virtualPath) {
return Path.GetDirectoryName(virtualPath);
}

View File

@@ -29,6 +29,7 @@ namespace Orchard.Tests.Utility {
public AutoMockSource(MockBehavior behavior) {
_behavior = behavior;
Ignore<IStartable>();
}
public bool IsAdapterForIndividualComponents {

View File

@@ -38,12 +38,12 @@ namespace Orchard.Core.Common.Drivers {
ContentShape("Parts_Common_Body",
() => {
var bodyText = _htmlFilters.Aggregate(part.Text, (text, filter) => filter.ProcessContent(text, GetFlavor(part)));
return shapeHelper.Parts_Common_Body(ContentPart: part, Html: new HtmlString(bodyText));
return shapeHelper.Parts_Common_Body(Html: new HtmlString(bodyText));
}),
ContentShape("Parts_Common_Body_Summary",
() => {
var bodyText = _htmlFilters.Aggregate(part.Text, (text, filter) => filter.ProcessContent(text, GetFlavor(part)));
return shapeHelper.Parts_Common_Body_Summary(ContentPart: part, Html: new HtmlString(bodyText));
return shapeHelper.Parts_Common_Body_Summary(Html: new HtmlString(bodyText));
})
);
}

View File

@@ -38,11 +38,11 @@ namespace Orchard.Core.Common.Drivers {
protected override DriverResult Display(CommonPart part, string displayType, dynamic shapeHelper) {
return Combined(
ContentShape("Parts_Common_Metadata",
() => shapeHelper.Parts_Common_Metadata(ContentPart: part)),
() => shapeHelper.Parts_Common_Metadata()),
ContentShape("Parts_Common_Metadata_Summary",
() => shapeHelper.Parts_Common_Metadata_Summary(ContentPart: part)),
() => shapeHelper.Parts_Common_Metadata_Summary()),
ContentShape("Parts_Common_Metadata_SummaryAdmin",
() => shapeHelper.Parts_Common_Metadata_SummaryAdmin(ContentPart: part))
() => shapeHelper.Parts_Common_Metadata_SummaryAdmin())
);
}

View File

@@ -26,7 +26,7 @@ namespace Orchard.Core.Common.Drivers {
protected override DriverResult Display(ContentPart part, TextField field, string displayType, dynamic shapeHelper) {
return ContentShape("Fields_Common_Text", GetDifferentiator(field, part),
() => shapeHelper.Fields_Common_Text(ContentPart: part, ContentField: field, Name: field.Name, Value: field.Value));
() => shapeHelper.Fields_Common_Text(Name: field.Name, Value: field.Value));
}
protected override DriverResult Editor(ContentPart part, TextField field, dynamic shapeHelper) {

View File

@@ -8,11 +8,11 @@ namespace Orchard.Core.Contents.Drivers {
protected override DriverResult Display(ContentPart part, string displayType, dynamic shapeHelper) {
return Combined(
ContentShape("Parts_Contents_Publish",
() => shapeHelper.Parts_Contents_Publish(ContentPart: part)),
() => shapeHelper.Parts_Contents_Publish()),
ContentShape("Parts_Contents_Publish_Summary",
() => shapeHelper.Parts_Contents_Publish_Summary(ContentPart: part)),
() => shapeHelper.Parts_Contents_Publish_Summary()),
ContentShape("Parts_Contents_Publish_SummaryAdmin",
() => shapeHelper.Parts_Contents_Publish_SummaryAdmin(ContentPart: part))
() => shapeHelper.Parts_Contents_Publish_SummaryAdmin())
);
}

View File

@@ -6,7 +6,7 @@
@T("Welcome, <strong>{0}</strong>!", new HtmlString(Html.ActionLink( WorkContext.CurrentUser.UserName, "ChangePassword", new { Controller = "Account", Area = "Orchard.Users" }).ToString()))
</span>
<span class="user-actions">
@Html.ActionLink(T("Sign Out").ToString(), "LogOff", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = Context.Request.RawUrl })
@Html.ActionLink(T("Sign Out").ToString(), "LogOff", new { Controller = "Account", Area = "Orchard.Users", ReturnUrl = Context.Request.RawUrl }, new { rel = "nofollow" })
@Html.ActionLink(T("Dashboard").ToString(), "Index", new { Area = "Dashboard", Controller = "Admin" })
</span>
} else {

View File

@@ -18,11 +18,11 @@ namespace Orchard.Core.Title.Drivers {
protected override DriverResult Display(TitlePart part, string displayType, dynamic shapeHelper) {
return Combined(
ContentShape("Parts_Title",
() => shapeHelper.Parts_Title(ContentPart: part, Title: part.Title)),
() => shapeHelper.Parts_Title(Title: part.Title)),
ContentShape("Parts_Title_Summary",
() => shapeHelper.Parts_Title_Summary(ContentPart: part, Title: part.Title)),
() => shapeHelper.Parts_Title_Summary(Title: part.Title)),
ContentShape("Parts_Title_SummaryAdmin",
() => shapeHelper.Parts_Title_SummaryAdmin(ContentPart: part, Title: part.Title))
() => shapeHelper.Parts_Title_SummaryAdmin(Title: part.Title))
);
}

View File

@@ -30,7 +30,7 @@ namespace Orchard.Blogs.Drivers {
if (blog == null)
return null;
return shapeHelper.Parts_Blogs_BlogArchives(ContentItem: part.ContentItem, Blog: blog, Archives: _blogPostService.GetArchives(blog));
return shapeHelper.Parts_Blogs_BlogArchives(Blog: blog, Archives: _blogPostService.GetArchives(blog));
});
}

View File

@@ -11,13 +11,13 @@ namespace Orchard.Blogs.Drivers {
protected override DriverResult Display(BlogPart part, string displayType, dynamic shapeHelper) {
return Combined(
ContentShape("Parts_Blogs_Blog_Manage",
() => shapeHelper.Parts_Blogs_Blog_Manage(ContentPart: part)),
() => shapeHelper.Parts_Blogs_Blog_Manage()),
ContentShape("Parts_Blogs_Blog_Description",
() => shapeHelper.Parts_Blogs_Blog_Description(ContentPart: part, Description: part.Description)),
() => shapeHelper.Parts_Blogs_Blog_Description(Description: part.Description)),
ContentShape("Parts_Blogs_Blog_SummaryAdmin",
() => shapeHelper.Parts_Blogs_Blog_SummaryAdmin(ContentPart: part, ContentItem: part.ContentItem)),
() => shapeHelper.Parts_Blogs_Blog_SummaryAdmin()),
ContentShape("Parts_Blogs_Blog_BlogPostCount",
() => shapeHelper.Parts_Blogs_Blog_BlogPostCount(ContentPart: part, PostCount: part.PostCount))
() => shapeHelper.Parts_Blogs_Blog_BlogPostCount(PostCount: part.PostCount))
);
}

View File

@@ -22,24 +22,26 @@ namespace Orchard.Blogs.Drivers {
}
protected override DriverResult Display(RecentBlogPostsPart part, string displayType, dynamic shapeHelper) {
BlogPart blog = _blogService.Get(part.ForBlog,VersionOptions.Published).As<BlogPart>();
return ContentShape("Parts_Blogs_RecentBlogPosts", () => {
BlogPart blog = _blogService.Get(part.ForBlog);
if (blog == null) {
return null;
}
if (blog == null) {
return null;
}
var blogPosts =_contentManager.Query(VersionOptions.Published, "BlogPost")
.Join<CommonPartRecord>().Where(cr => cr.Container == blog.Record.ContentItemRecord)
.OrderByDescending(cr => cr.CreatedUtc)
.Slice(0, part.Count)
.Select(ci => ci.As<BlogPostPart>());
var blogPosts = _contentManager.Query(VersionOptions.Published, "BlogPost")
.Join<CommonPartRecord>().Where(cr => cr.Container == blog.Record.ContentItemRecord)
.OrderByDescending(cr => cr.CreatedUtc)
.Slice(0, part.Count)
.Select(ci => ci.As<BlogPostPart>());
var list = shapeHelper.List();
list.AddRange(blogPosts.Select(bp => _contentManager.BuildDisplay(bp, "Summary")));
var list = shapeHelper.List();
list.AddRange(blogPosts.Select(bp => _contentManager.BuildDisplay(bp, "Summary")));
var blogPostList = shapeHelper.Parts_Blogs_BlogPost_List(ContentPart: part, ContentItems: list);
var blogPostList = shapeHelper.Parts_Blogs_BlogPost_List(ContentItems: list);
return ContentShape(shapeHelper.Parts_Blogs_RecentBlogPosts(ContentItem: part.ContentItem, ContentItems: blogPostList, Blog: blog));
return shapeHelper.Parts_Blogs_RecentBlogPosts(ContentItems: blogPostList, Blog: blog);
});
}
protected override DriverResult Editor(RecentBlogPostsPart part, dynamic shapeHelper) {

View File

@@ -1,3 +1,4 @@
using System;
using JetBrains.Annotations;
using Orchard.Comments.Models;
using Orchard.Comments.Services;
@@ -13,14 +14,16 @@ namespace Orchard.Comments.Drivers {
}
protected override DriverResult Display(CommentsContainerPart part, string displayType, dynamic shapeHelper) {
var commentsForCommentedContent = _commentService.GetCommentsForCommentedContent(part.ContentItem.Id);
Func<int> pendingCount = () => commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count();
return Combined(
ContentShape("Parts_Comments_Count",
() => shapeHelper.Parts_Comments_Count(ContentPart: part, CommentCount: commentsForCommentedContent.Count(), PendingCount: commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count())),
() => shapeHelper.Parts_Comments_Count(CommentCount: commentsForCommentedContent.Count(), PendingCount: pendingCount)),
ContentShape("Parts_Comments_Count_SummaryAdmin",
() => shapeHelper.Parts_Comments_Count_SummaryAdmin(ContentPart: part, CommentCount: commentsForCommentedContent.Count(), PendingCount: commentsForCommentedContent.Where(x => x.Status == CommentStatus.Pending).Count()))
() => shapeHelper.Parts_Comments_Count_SummaryAdmin(CommentCount: commentsForCommentedContent.Count(), PendingCount: pendingCount))
);
}
}

View File

@@ -23,11 +23,11 @@ namespace Orchard.Comments.Drivers {
return Combined(
ContentShape("Parts_Comments",
() => shapeHelper.Parts_Comments(ContentPart: part)),
() => shapeHelper.Parts_Comments()),
ContentShape("Parts_Comments_Count",
() => shapeHelper.Parts_Comments_Count(ContentPart: part, CommentCount: commentsForCommentedContent.Count(), PendingCount: pendingCount)),
() => shapeHelper.Parts_Comments_Count(CommentCount: commentsForCommentedContent.Count(), PendingCount: pendingCount)),
ContentShape("Parts_Comments_Count_SummaryAdmin",
() => shapeHelper.Parts_Comments_Count_SummaryAdmin(ContentPart: part, CommentCount: commentsForCommentedContent.Count(), PendingCount: pendingCount))
() => shapeHelper.Parts_Comments_Count_SummaryAdmin(CommentCount: commentsForCommentedContent.Count(), PendingCount: pendingCount))
);
}

View File

@@ -24,13 +24,13 @@ namespace Orchard.DesignerTools.Services {
private int _shapeId;
public ShapeTracingFactory(
WorkContext workContext,
IWorkContextAccessor workContextAccessor,
IShapeTableManager shapeTableManager,
IThemeManager themeManager,
IWebSiteFolder webSiteFolder,
IAuthorizer authorizer
) {
_workContext = workContext;
_workContext = workContextAccessor.GetContext();
_shapeTableManager = shapeTableManager;
_themeManager = themeManager;
_webSiteFolder = webSiteFolder;

View File

@@ -13,10 +13,10 @@ namespace Orchard.Email.Services
private readonly IOrchardServices _orchardServices;
private readonly WorkContext _workContext;
public MissingSettingsBanner(IOrchardServices orchardServices, WorkContext workContext)
public MissingSettingsBanner(IOrchardServices orchardServices, IWorkContextAccessor workContextAccessor)
{
_orchardServices = orchardServices;
_workContext = workContext;
_workContext = workContextAccessor.GetContext();
T = NullLocalizer.Instance;
}

View File

@@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.Drivers;
using Orchard.Core.Containers.Models;
namespace Orchard.Lists.Drivers {
public class ContainerPartDriver : ContentPartDriver<ContainerPart>{
protected override DriverResult Display(ContainerPart part, string displayType, dynamic shapeHelper) {
return ContentShape("Parts_Container_Contained_SummaryAdmin",
() => shapeHelper.Parts_Container_Contained_SummaryAdmin(ContentPart: part)
() => shapeHelper.Parts_Container_Contained_SummaryAdmin()
);
}
}

View File

@@ -27,11 +27,11 @@ namespace Orchard.Localization.Drivers {
: part.Id;
return Combined(
ContentShape("Parts_Localization_ContentTranslations",
() => shapeHelper.Parts_Localization_ContentTranslations(ContentPart: part, MasterId: masterId, Localizations: GetDisplayLocalizations(part, VersionOptions.Published))),
() => shapeHelper.Parts_Localization_ContentTranslations(MasterId: masterId, Localizations: GetDisplayLocalizations(part, VersionOptions.Published))),
ContentShape("Parts_Localization_ContentTranslations_Summary",
() => shapeHelper.Parts_Localization_ContentTranslations_Summary(ContentPart: part, MasterId: masterId, Localizations: GetDisplayLocalizations(part, VersionOptions.Published))),
() => shapeHelper.Parts_Localization_ContentTranslations_Summary(MasterId: masterId, Localizations: GetDisplayLocalizations(part, VersionOptions.Published))),
ContentShape("Parts_Localization_ContentTranslations_SummaryAdmin",
() => shapeHelper.Parts_Localization_ContentTranslations_SummaryAdmin(ContentPart: part, MasterId: masterId, Localizations: GetDisplayLocalizations(part, VersionOptions.Latest)))
() => shapeHelper.Parts_Localization_ContentTranslations_SummaryAdmin(MasterId: masterId, Localizations: GetDisplayLocalizations(part, VersionOptions.Latest)))
);
}

View File

@@ -3,6 +3,7 @@ using System.Linq;
using System.Web.Mvc;
using System.Web.Routing;
using Orchard.Data.Migration;
using Orchard.Environment;
using Orchard.Environment.Extensions;
using Orchard.Localization;
using Orchard.Modules.Extensions;
@@ -20,9 +21,9 @@ namespace Orchard.Modules.Data.Migration {
private readonly IDataMigrationManager _dataMigrationManager;
private readonly WorkContext _workContext;
public DataMigrationNotificationProvider(IDataMigrationManager dataMigrationManager, WorkContext workContext) {
public DataMigrationNotificationProvider(IDataMigrationManager dataMigrationManager, IWorkContextAccessor workContextAccessor) {
_dataMigrationManager = dataMigrationManager;
_workContext = workContext;
_workContext = workContextAccessor.GetContext();
T = NullLocalizer.Instance;
}

View File

@@ -42,11 +42,11 @@ namespace Orchard.PublishLater.Drivers {
protected override DriverResult Display(PublishLaterPart part, string displayType, dynamic shapeHelper) {
return Combined(
ContentShape("Parts_PublishLater_Metadata",
() => shapeHelper.Parts_PublishLater_Metadata(ContentPart: part, ScheduledPublishUtc: part.ScheduledPublishUtc.Value)),
() => shapeHelper.Parts_PublishLater_Metadata(ScheduledPublishUtc: part.ScheduledPublishUtc.Value)),
ContentShape("Parts_PublishLater_Metadata_Summary",
() => shapeHelper.Parts_PublishLater_Metadata_Summary(ContentPart: part, ScheduledPublishUtc: part.ScheduledPublishUtc.Value)),
() => shapeHelper.Parts_PublishLater_Metadata_Summary(ScheduledPublishUtc: part.ScheduledPublishUtc.Value)),
ContentShape("Parts_PublishLater_Metadata_SummaryAdmin",
() => shapeHelper.Parts_PublishLater_Metadata_SummaryAdmin(ContentPart: part, ScheduledPublishUtc: part.ScheduledPublishUtc.Value))
() => shapeHelper.Parts_PublishLater_Metadata_SummaryAdmin(ScheduledPublishUtc: part.ScheduledPublishUtc.Value))
);
}

View File

@@ -33,7 +33,7 @@ namespace Orchard.Tags.Drivers {
protected override DriverResult Display(TagsPart part, string displayType, dynamic shapeHelper) {
return ContentShape("Parts_Tags_ShowTags",
() => shapeHelper.Parts_Tags_ShowTags(ContentPart: part, Tags: part.CurrentTags));
() => shapeHelper.Parts_Tags_ShowTags(Tags: part.CurrentTags));
}
protected override DriverResult Editor(TagsPart part, dynamic shapeHelper) {

View File

@@ -0,0 +1,35 @@
using System;
using System.Web.Security;
using Orchard.ContentManagement.Drivers;
using Orchard.Users.Models;
namespace Orchard.Users.Drivers {
public class UserPartDriver : ContentPartDriver<UserPart> {
protected override void Importing(UserPart part, ContentManagement.Handlers.ImportContentContext context) {
part.Record.Email = context.Attribute(part.PartDefinition.Name, "Email");
part.Record.EmailChallengeToken = context.Attribute(part.PartDefinition.Name, "EmailChallengeToken");
part.Record.EmailStatus = (UserStatus)Enum.Parse(typeof(UserStatus), context.Attribute(part.PartDefinition.Name, "EmailStatus"));
part.Record.HashAlgorithm = context.Attribute(part.PartDefinition.Name, "HashAlgorithm");
part.Record.NormalizedUserName = context.Attribute(part.PartDefinition.Name, "NormalizedUserName");
part.Record.Password = context.Attribute(part.PartDefinition.Name, "Password");
part.Record.PasswordFormat = (MembershipPasswordFormat)Enum.Parse(typeof(MembershipPasswordFormat), context.Attribute(part.PartDefinition.Name, "PasswordFormat"));
part.Record.PasswordSalt = context.Attribute(part.PartDefinition.Name, "PasswordSalt");
part.Record.RegistrationStatus = (UserStatus)Enum.Parse(typeof(UserStatus), context.Attribute(part.PartDefinition.Name, "RegistrationStatus"));
part.Record.UserName = context.Attribute(part.PartDefinition.Name, "UserName");
}
protected override void Exporting(UserPart part, ContentManagement.Handlers.ExportContentContext context) {
context.Element(part.PartDefinition.Name).SetAttributeValue("Email", part.Record.Email);
context.Element(part.PartDefinition.Name).SetAttributeValue("EmailChallengeToken", part.Record.EmailChallengeToken);
context.Element(part.PartDefinition.Name).SetAttributeValue("EmailStatus", part.Record.EmailStatus);
context.Element(part.PartDefinition.Name).SetAttributeValue("HashAlgorithm", part.Record.HashAlgorithm);
context.Element(part.PartDefinition.Name).SetAttributeValue("NormalizedUserName", part.Record.NormalizedUserName);
context.Element(part.PartDefinition.Name).SetAttributeValue("Password", part.Record.Password);
context.Element(part.PartDefinition.Name).SetAttributeValue("PasswordFormat", part.Record.PasswordFormat);
context.Element(part.PartDefinition.Name).SetAttributeValue("PasswordSalt", part.Record.PasswordSalt);
context.Element(part.PartDefinition.Name).SetAttributeValue("RegistrationStatus", part.Record.RegistrationStatus);
context.Element(part.PartDefinition.Name).SetAttributeValue("UserName", part.Record.UserName);
}
}
}

View File

@@ -1,4 +1,6 @@
using Orchard.Data.Migration;
using Orchard.ContentManagement.MetaData;
using Orchard.Data.Migration;
using Orchard.Core.Contents.Extensions;
namespace Orchard.Users {
public class UsersDataMigration : DataMigrationImpl {
@@ -34,5 +36,11 @@ namespace Orchard.Users {
return 1;
}
public int UpdateFrom1() {
ContentDefinitionManager.AlterTypeDefinition("User", cfg => cfg.Creatable(false));
return 2;
}
}
}

View File

@@ -58,6 +58,7 @@
<Compile Include="Commands\UserCommands.cs" />
<Compile Include="Controllers\AccountController.cs" />
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="Drivers\UserPartDriver.cs" />
<Compile Include="Migrations.cs" />
<Compile Include="Events\UserContext.cs" />
<Compile Include="Handlers\UserMessagesAlteration.cs" />

View File

@@ -9,9 +9,9 @@ namespace Orchard.Warmup.Services {
private readonly IOrchardServices _orchardServices;
private readonly WorkContext _workContext;
public SettingsBanner(IOrchardServices orchardServices, WorkContext workContext) {
public SettingsBanner(IOrchardServices orchardServices, IWorkContextAccessor workContextAccessor) {
_orchardServices = orchardServices;
_workContext = workContext;
_workContext = workContextAccessor.GetContext();
T = NullLocalizer.Instance;
}

View File

@@ -16,15 +16,27 @@ namespace Orchard.ContentManagement.Drivers {
}
DriverResult IContentFieldDriver.BuildDisplayShape(BuildDisplayContext context) {
return Process(context.ContentItem, (part, field) => Display(part, field, context.DisplayType, context.New));
return Process(context.ContentItem, (part, field) => {
context.ContentPart = part;
context.ContentField = field;
return Display(part, field, context.DisplayType, context.New);
});
}
DriverResult IContentFieldDriver.BuildEditorShape(BuildEditorContext context) {
return Process(context.ContentItem, (part, field) => Editor(part, field, context.New));
return Process(context.ContentItem, (part, field) => {
context.ContentPart = part;
context.ContentField = field;
return Editor(part, field, context.New);
});
}
DriverResult IContentFieldDriver.UpdateEditorShape(UpdateEditorContext context) {
return Process(context.ContentItem, (part, field) => Editor(part, field, context.Updater, context.New));
return Process(context.ContentItem, (part, field) => {
context.ContentPart = part;
context.ContentField = field;
return Editor(part, field, context.Updater, context.New);
});
}
void IContentFieldDriver.Importing(ImportContentContext context) {
@@ -75,7 +87,7 @@ namespace Orchard.ContentManagement.Drivers {
return contentFieldInfo;
}
protected virtual void GetContentItemMetadata(ContentPart part, TField field, ContentItemMetadata metadata) { return; }
protected virtual void GetContentItemMetadata(ContentPart part, TField field, ContentItemMetadata metadata) { }
protected virtual DriverResult Display(ContentPart part, TField field, string displayType, dynamic shapeHelper) { return null; }
protected virtual DriverResult Editor(ContentPart part, TField field, dynamic shapeHelper) { return null; }
@@ -105,19 +117,34 @@ namespace Orchard.ContentManagement.Drivers {
}
private ContentShapeResult ContentShapeImplementation(string shapeType, string differentiator, Func<BuildShapeContext, object> shapeBuilder) {
return new ContentShapeResult(shapeType, Prefix, ctx => AddAlternates(shapeBuilder(ctx), differentiator)).Differentiator(differentiator);
return new ContentShapeResult(shapeType, Prefix, ctx => AddAlternates(shapeBuilder(ctx), ctx, differentiator)).Differentiator(differentiator);
}
private static object AddAlternates(dynamic shape, string differentiator) {
private static object AddAlternates(dynamic shape, BuildShapeContext ctx, string differentiator) {
// automatically add shape alternates for shapes added by fields
// for fields on dynamic parts the part name is the same as the content type name
ShapeMetadata metadata = shape.Metadata;
ContentPart part = shape.ContentPart;
// if no ContentField property has been set, assign it
if (shape.ContentPart == null) {
shape.ContentPart = ctx.ContentField;
}
// if no ContentPart property has been set, assign it
if (shape.ContentPart == null) {
shape.ContentPart = ctx.ContentPart;
}
// if no ContentItem property has been set, assign it
if (shape.ContentItem == null) {
shape.ContentItem = ctx.ContentItem;
}
var shapeType = metadata.Type;
var fieldName = differentiator ?? String.Empty;
var partName = part != null ? part.PartDefinition.Name : String.Empty;
var contentType = part != null ? part.ContentItem.ContentType : String.Empty;
var partName = shape.ContentPart.PartDefinition.Name;
var contentType = shape.ContentItem.ContentType;
var dynamicType = string.Equals(partName, contentType, StringComparison.Ordinal);
// [ShapeType__FieldName] e.g. Fields/Common.Text-Teaser

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.MetaData;
using Orchard.DisplayManagement;
@@ -17,17 +18,38 @@ namespace Orchard.ContentManagement.Drivers {
DriverResult IContentPartDriver.BuildDisplay(BuildDisplayContext context) {
var part = context.ContentItem.As<TContent>();
return part == null ? null : Display(part, context.DisplayType, context.New);
if(part == null) {
return null;
}
context.ContentPart = part;
return Display(part, context.DisplayType, context.New);
}
DriverResult IContentPartDriver.BuildEditor(BuildEditorContext context) {
var part = context.ContentItem.As<TContent>();
return part == null ? null : Editor(part, context.New);
if (part == null) {
return null;
}
context.ContentPart = part;
return Editor(part, context.New);
}
DriverResult IContentPartDriver.UpdateEditor(UpdateEditorContext context) {
var part = context.ContentItem.As<TContent>();
return part == null ? null : Editor(part, context.Updater, context.New);
if (part == null) {
return null;
}
context.ContentPart = part;
return Editor(part, context.Updater, context.New);
}
void IContentPartDriver.Importing(ImportContentContext context) {
@@ -54,16 +76,16 @@ namespace Orchard.ContentManagement.Drivers {
Exported(part, context);
}
protected virtual void GetContentItemMetadata(TContent context, ContentItemMetadata metadata) { return; }
protected virtual void GetContentItemMetadata(TContent context, ContentItemMetadata metadata) {}
protected virtual DriverResult Display(TContent part, string displayType, dynamic shapeHelper) { return null; }
protected virtual DriverResult Editor(TContent part, dynamic shapeHelper) { return null; }
protected virtual DriverResult Editor(TContent part, IUpdateModel updater, dynamic shapeHelper) { return null; }
protected virtual void Importing(TContent part, ImportContentContext context) { return; }
protected virtual void Imported(TContent part, ImportContentContext context) { return; }
protected virtual void Exporting(TContent part, ExportContentContext context) { return; }
protected virtual void Exported(TContent part, ExportContentContext context) { return; }
protected virtual void Importing(TContent part, ImportContentContext context) {}
protected virtual void Imported(TContent part, ImportContentContext context) {}
protected virtual void Exporting(TContent part, ExportContentContext context) {}
protected virtual void Exported(TContent part, ExportContentContext context) {}
[Obsolete("Provided while transitioning to factory variations")]
public ContentShapeResult ContentShape(IShape shape) {
@@ -79,25 +101,29 @@ namespace Orchard.ContentManagement.Drivers {
}
private ContentShapeResult ContentShapeImplementation(string shapeType, Func<BuildShapeContext, object> shapeBuilder) {
return new ContentShapeResult(shapeType, Prefix, ctx => AddAlternates(shapeBuilder(ctx)));
return new ContentShapeResult(shapeType, Prefix, ctx => AddAlternates(shapeBuilder(ctx), ctx));
}
private static object AddAlternates(dynamic shape) {
private static dynamic AddAlternates(dynamic shape, BuildShapeContext ctx) {
ShapeMetadata metadata = shape.Metadata;
ContentPart part = shape.ContentPart;
var id = part != null ? part.ContentItem.Id.ToString() : String.Empty;
// if no ContentPart property has been set, assign it
if (shape.ContentPart == null) {
shape.ContentPart = ctx.ContentPart;
}
// if no ContentItem property has been set, assign it
if (shape.ContentItem == null) {
shape.ContentItem = ctx.ContentItem;
}
var shapeType = metadata.Type;
var contentType = part != null ? part.ContentItem.ContentType : String.Empty;
// [ShapeType]__[Id] e.g. Parts/Common.Metadata-42
if ( !string.IsNullOrEmpty(id) ) {
metadata.Alternates.Add(shapeType + "__" + id);
}
metadata.Alternates.Add(shapeType + "__" + ctx.ContentItem.Id.ToString(CultureInfo.InvariantCulture));
// [ShapeType]__[ContentType] e.g. Parts/Common.Metadata-BlogPost
if ( !string.IsNullOrEmpty(contentType) ) {
metadata.Alternates.Add(shapeType + "__" + contentType);
}
metadata.Alternates.Add(shapeType + "__" + ctx.ContentItem.ContentType);
return shape;
}

View File

@@ -1,12 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Orchard.ContentManagement.Handlers;
using Orchard.ContentManagement.MetaData;
using Orchard.Logging;
namespace Orchard.ContentManagement.Drivers.Coordinators {
[UsedImplicitly]
/// <summary>
/// This component coordinates how parts are taking part in the rendering when some content needs to be rendered.
/// It will dispatch BuildDisplay/BuildEditor to all <see cref="IContentPartDriver"/> implementations.
/// </summary>
public class ContentPartDriverCoordinator : ContentHandlerBase {
private readonly IEnumerable<IContentPartDriver> _drivers;
private readonly IContentDefinitionManager _contentDefinitionManager;

View File

@@ -1,12 +1,12 @@
using System;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Descriptors;
using Orchard.DisplayManagement.Descriptors.ShapePlacementStrategy;
namespace Orchard.ContentManagement.Handlers {
public class BuildShapeContext {
protected BuildShapeContext(IShape shape, IContent content, string groupId, IShapeFactory shapeFactory) {
Shape = shape;
Content = content;
ContentItem = content.ContentItem;
New = shapeFactory;
GroupId = groupId;
@@ -14,7 +14,10 @@ namespace Orchard.ContentManagement.Handlers {
}
public dynamic Shape { get; private set; }
public IContent Content { get; private set; }
public ContentItem ContentItem { get; private set; }
public ContentPart ContentPart { get; set; }
public ContentField ContentField { get; set; }
public dynamic New { get; private set; }
public string GroupId { get; private set; }

View File

@@ -49,7 +49,7 @@ namespace Orchard.DisplayManagement.Descriptors.ShapeAttributeStrategy {
ShapeAttributeOccurrence attributeOccurrence,
ShapeDescriptor descriptor) {
return context => {
var serviceInstance = _componentContext.Resolve(attributeOccurrence.Registration, Enumerable.Empty<Parameter>());
var serviceInstance = _componentContext.ResolveComponent(attributeOccurrence.Registration, Enumerable.Empty<Parameter>());
// oversimplification for the sake of evolving
return PerformInvoke(context, attributeOccurrence.MethodInfo, serviceInstance);

View File

@@ -13,7 +13,7 @@ namespace Orchard.Environment.AutofacUtil.DynamicProxy2 {
_dynamicProxyContext = dynamicProxyContext;
}
public IEnumerable<ConstructorInfo> FindConstructors(Type targetType) {
public ConstructorInfo[] FindConstructors(Type targetType) {
Type proxyType;
if (_dynamicProxyContext.TryGetProxy(targetType, out proxyType)) {
return _constructorFinder.FindConstructors(proxyType);

View File

@@ -46,7 +46,7 @@ namespace Orchard.Environment.AutofacUtil.DynamicProxy2 {
object value;
if (e.Component.Metadata.TryGetValue(InterceptorServicesKey, out value)) {
var interceptorServices = (IEnumerable<Service>)value;
var interceptors = interceptorServices.Select(service => e.Context.Resolve(service)).Cast<IInterceptor>().ToArray();
var interceptors = interceptorServices.Select(service => e.Context.ResolveService(service)).Cast<IInterceptor>().ToArray();
var parameter = new PositionalParameter(0, interceptors);
e.Parameters = new[] { parameter }.Concat(e.Parameters).ToArray();
}

View File

@@ -2,6 +2,8 @@ using System;
using System.Collections.Generic;
using Autofac;
using Autofac.Core;
using Autofac.Core.Lifetime;
using Autofac.Core.Resolving;
namespace Orchard.Environment.AutofacUtil {
public class LifetimeScopeContainer : IContainer {
@@ -11,8 +13,8 @@ namespace Orchard.Environment.AutofacUtil {
_lifetimeScope = lifetimeScope;
}
public object Resolve(IComponentRegistration registration, IEnumerable<Parameter> parameters) {
return _lifetimeScope.Resolve(registration, parameters);
public object ResolveComponent(IComponentRegistration registration, IEnumerable<Parameter> parameters) {
return _lifetimeScope.ResolveComponent(registration, parameters);
}
public IComponentRegistry ComponentRegistry {
@@ -45,5 +47,9 @@ namespace Orchard.Environment.AutofacUtil {
public object Tag {
get { return _lifetimeScope.Tag; }
}
public event EventHandler<LifetimeScopeBeginningEventArgs> ChildLifetimeScopeBeginning;
public event EventHandler<LifetimeScopeEndingEventArgs> CurrentScopeEnding;
public event EventHandler<ResolveOperationBeginningEventArgs> ResolveOperationBeginning;
}
}

View File

@@ -21,7 +21,7 @@ namespace Orchard.Environment {
value = null;
return false;
}
return key == null ? scope.TryResolve(serviceType, out value) : scope.TryResolve(key, serviceType, out value);
return key == null ? scope.TryResolve(serviceType, out value) : scope.TryResolveKeyed(key, serviceType, out value);
}
bool TryResolve(string key, Type serviceType, out object value) {

View File

@@ -45,10 +45,12 @@ namespace Orchard.Environment.ShellBuilders {
if (descriptor.Features.Any(feature => feature.Name == "Orchard.Framework"))
features = features.Concat(BuiltinFeatures());
var modules = BuildBlueprint(features, IsModule, BuildModule);
var dependencies = BuildBlueprint(features, IsDependency, (t, f) => BuildDependency(t, f, descriptor));
var controllers = BuildBlueprint(features, IsController, BuildController);
var records = BuildBlueprint(features, IsRecord, (t, f) => BuildRecord(t, f, settings));
var excludedTypes = GetExcludedTypes(features);
var modules = BuildBlueprint(features, IsModule, BuildModule, excludedTypes);
var dependencies = BuildBlueprint(features, IsDependency, (t, f) => BuildDependency(t, f, descriptor), excludedTypes);
var controllers = BuildBlueprint(features, IsController, BuildController, excludedTypes);
var records = BuildBlueprint(features, IsRecord, (t, f) => BuildRecord(t, f, settings), excludedTypes);
var result = new ShellBlueprint {
Settings = settings,
@@ -62,6 +64,21 @@ namespace Orchard.Environment.ShellBuilders {
return result;
}
private static IEnumerable<string> GetExcludedTypes(IEnumerable<Feature> features) {
var excludedTypes = new HashSet<string>();
// Identify replaced types
foreach (Feature feature in features) {
foreach (Type type in feature.ExportedTypes) {
foreach (OrchardSuppressDependencyAttribute replacedType in type.GetCustomAttributes(typeof(OrchardSuppressDependencyAttribute), false)) {
excludedTypes.Add(replacedType.FullName);
}
}
}
return excludedTypes;
}
private static IEnumerable<Feature> BuiltinFeatures() {
yield return new Feature {
Descriptor = new FeatureDescriptor {
@@ -81,17 +98,8 @@ namespace Orchard.Environment.ShellBuilders {
private static IEnumerable<T> BuildBlueprint<T>(
IEnumerable<Feature> features,
Func<Type, bool> predicate,
Func<Type, Feature, T> selector) {
HashSet<string> excludedTypes = new HashSet<string>();
// Identify replaced types
foreach(Feature feature in features) {
foreach (Type type in feature.ExportedTypes) {
foreach (OrchardSuppressDependencyAttribute replacedType in type.GetCustomAttributes(typeof(OrchardSuppressDependencyAttribute), false)) {
excludedTypes.Add(replacedType.FullName);
}
}
}
Func<Type, Feature, T> selector,
IEnumerable<string> excludedTypes ) {
// Load types excluding the replaced types
return features.SelectMany(

View File

@@ -102,7 +102,7 @@ namespace Orchard.Environment.ShellBuilders {
.OnActivating(e => {
var controller = e.Instance as Controller;
if (controller != null)
controller.ActionInvoker = (IActionInvoker)e.Context.Resolve(new TypedService(typeof(IActionInvoker)));
controller.ActionInvoker = (IActionInvoker)e.Context.ResolveService(new TypedService(typeof(IActionInvoker)));
});
}

View File

@@ -20,7 +20,7 @@ namespace Orchard.Environment {
IHttpContextAccessor httpContextAccessor,
ILifetimeScope lifetimeScope) {
_httpContextAccessor = httpContextAccessor;
_lifetimeScope = lifetimeScope;
_lifetimeScope = lifetimeScope.Resolve<ILifetimeScope>();
}
public WorkContext GetContext(HttpContextBase httpContext) {

View File

@@ -16,7 +16,7 @@ namespace Orchard.Environment {
.As<IWorkContextAccessor>()
.InstancePerMatchingLifetimeScope("shell");
builder.Register(ctx => new WorkContextImplementation(ctx))
builder.Register(ctx => new WorkContextImplementation(ctx.Resolve<IComponentContext>()))
.As<WorkContext>()
.InstancePerMatchingLifetimeScope("work");
@@ -104,7 +104,7 @@ namespace Orchard.Environment {
T value;
if (!workValues.Values.TryGetValue(w, out value)) {
value = (T)workValues.ComponentContext.Resolve(valueRegistration, p);
value = (T)workValues.ComponentContext.ResolveComponent(valueRegistration, p);
workValues.Values[w] = value;
}
return value;

View File

@@ -73,7 +73,7 @@ namespace Orchard.FileSystems.VirtualPath {
/// Note: This method doesn't detect all cases of malformed paths, it merely checks
/// for *some* cases of malformed paths, so this is not a replacement for full virtual path
/// verification through VirtualPathUtilty methods.
/// In other wors, !IsMalformed does *not* imply "IsWellformed".
/// In other words, !IsMalformed does *not* imply "IsWellformed".
/// </summary>
public bool IsMalformedVirtualPath(string virtualPath) {
if (string.IsNullOrEmpty(virtualPath))
@@ -137,6 +137,10 @@ namespace Orchard.FileSystems.VirtualPath {
return HostingEnvironment.VirtualPathProvider.GetFileHash(virtualPath, dependencies);
}
public virtual void DeleteFile(string virtualPath) {
File.Delete(MapPath(virtualPath));
}
public virtual string MapPath(string virtualPath) {
return HostingEnvironment.MapPath(virtualPath);
}
@@ -165,5 +169,9 @@ namespace Orchard.FileSystems.VirtualPath {
public virtual void CreateDirectory(string virtualPath) {
Directory.CreateDirectory(MapPath(virtualPath));
}
public virtual void DeleteDirectory(string virtualPath) {
Directory.Delete(MapPath(virtualPath));
}
}
}

View File

@@ -17,10 +17,12 @@ namespace Orchard.FileSystems.VirtualPath {
DateTime GetFileLastWriteTimeUtc(string virtualPath);
string GetFileHash(string virtualPath);
string GetFileHash(string virtualPath, IEnumerable<string> dependencies);
void DeleteFile(string virtualPath);
bool DirectoryExists(string virtualPath);
void CreateDirectory(string virtualPath);
string GetDirectoryName(string virtualPath);
void DeleteDirectory(string virtualPath);
IEnumerable<string> ListFiles(string path);
IEnumerable<string> ListDirectories(string path);

View File

@@ -23,7 +23,7 @@ namespace Orchard.Mvc {
if (workContext != null && serviceKey != null) {
var key = new KeyedService(serviceKey, typeof (T));
object value;
if (workContext.Resolve<ILifetimeScope>().TryResolve(key, out value)) {
if (workContext.Resolve<ILifetimeScope>().TryResolveService(key, out value)) {
instance = (T) value;
return true;
}

View File

@@ -3,7 +3,6 @@ using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.WebPages;
using Autofac;
using Orchard.DisplayManagement;
using Orchard.DisplayManagement.Shapes;
using Orchard.Localization;
@@ -63,10 +62,27 @@ namespace Orchard.Mvc.ViewEngines.Razor {
public WorkContext WorkContext { get { return _workContext; } }
public dynamic New { get { return ShapeFactory; } }
public IDisplayHelperFactory DisplayHelperFactory { get; set; }
public IShapeFactory ShapeFactory { get; set; }
public IAuthorizer Authorizer { get; set; }
private IDisplayHelperFactory _displayHelperFactory;
public IDisplayHelperFactory DisplayHelperFactory {
get {
return _displayHelperFactory ?? (_displayHelperFactory = _workContext.Resolve<IDisplayHelperFactory>());
}
}
private IShapeFactory _shapeFactory;
public IShapeFactory ShapeFactory {
get {
return _shapeFactory ?? (_shapeFactory = _workContext.Resolve<IShapeFactory>());
}
}
private IAuthorizer _authorizer;
public IAuthorizer Authorizer {
get {
return _authorizer ?? (_authorizer = _workContext.Resolve<IAuthorizer>());
}
}
public ScriptRegister Script {
get {
@@ -120,7 +136,6 @@ namespace Orchard.Mvc.ViewEngines.Razor {
base.InitHelpers();
_workContext = ViewContext.GetWorkContext();
_workContext.Resolve<IComponentContext>().InjectUnsetProperties(this);
_display = DisplayHelperFactory.CreateHelper(ViewContext, this);
_layout = _workContext.Layout;

View File

@@ -35,10 +35,26 @@ namespace Orchard.Mvc {
public dynamic Layout { get { return _layout; } }
public WorkContext WorkContext { get { return _workContext; } }
public IDisplayHelperFactory DisplayHelperFactory { get; set; }
private IDisplayHelperFactory _displayHelperFactory;
public IDisplayHelperFactory DisplayHelperFactory {
get {
return _displayHelperFactory ?? (_displayHelperFactory = _workContext.Resolve<IDisplayHelperFactory>());
}
}
public IAuthorizer Authorizer { get; set; }
private IShapeFactory _shapeFactory;
public IShapeFactory ShapeFactory {
get {
return _shapeFactory ?? (_shapeFactory = _workContext.Resolve<IShapeFactory>());
}
}
private IAuthorizer _authorizer;
public IAuthorizer Authorizer {
get {
return _authorizer ?? (_authorizer = _workContext.Resolve<IAuthorizer>());
}
}
public ResourceRegister Style {
get {
@@ -51,7 +67,6 @@ namespace Orchard.Mvc {
base.InitHelpers();
_workContext = ViewContext.GetWorkContext();
_workContext.Resolve<IComponentContext>().InjectUnsetProperties(this);
_localizer = LocalizationUtilities.Resolve(ViewContext, AppRelativeVirtualPath);
_display = DisplayHelperFactory.CreateHelper(ViewContext, this);

View File

@@ -27,10 +27,26 @@ namespace Orchard.Mvc {
public dynamic Layout { get { return _layout; } }
public WorkContext WorkContext { get { return _workContext; } }
public IDisplayHelperFactory DisplayHelperFactory { get; set; }
public IShapeFactory ShapeFactory { get; set; }
private IDisplayHelperFactory _displayHelperFactory;
public IDisplayHelperFactory DisplayHelperFactory {
get {
return _displayHelperFactory ?? (_displayHelperFactory = _workContext.Resolve<IDisplayHelperFactory>());
}
}
public IAuthorizer Authorizer { get; set; }
private IShapeFactory _shapeFactory;
public IShapeFactory ShapeFactory {
get {
return _shapeFactory ?? (_shapeFactory = _workContext.Resolve<IShapeFactory>());
}
}
private IAuthorizer _authorizer;
public IAuthorizer Authorizer {
get {
return _authorizer ?? (_authorizer = _workContext.Resolve<IAuthorizer>());
}
}
public ScriptRegister Script {
get {
@@ -68,7 +84,6 @@ namespace Orchard.Mvc {
public override void RenderView(ViewContext viewContext) {
_workContext = viewContext.GetWorkContext();
_workContext.Resolve<IComponentContext>().InjectUnsetProperties(this);
_localizer = LocalizationUtilities.Resolve(viewContext, AppRelativeVirtualPath);
_display = DisplayHelperFactory.CreateHelper(viewContext, this);

View File

@@ -33,7 +33,7 @@ namespace Orchard.Wcf {
throw new ArgumentNullException("registration");
}
return _workContext.Resolve<ILifetimeScope>().Resolve(registration, Enumerable.Empty<Parameter>());
return _workContext.Resolve<ILifetimeScope>().ResolveComponent(registration, Enumerable.Empty<Parameter>());
}
}
}