From 1cfaae90b871277df89f6b0e30497fac5f53a24a Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Sat, 17 Apr 2010 17:03:07 -0700 Subject: [PATCH] Building out composition strategy Four main component types are populated from topology Additional information for table/area/controller name populated Some core types for records added automatically --HG-- branch : dev --- .../Builders/SessionFactoryBuilderTests.cs | 8 +- src/Orchard.Tests/Data/RepositoryTests.cs | 20 ++-- src/Orchard.Tests/DataUtility.cs | 2 +- .../DefaultCompositionStrategyTests.cs | 103 ++++++++++-------- .../Environment/DefaultOrchardHostTests.cs | 4 +- .../Extensions/ExtensionManagerTests.cs | 44 ++++---- .../Environment/Utility/Build.cs | 50 +++++++++ src/Orchard.Tests/FluentDbTests.cs | 16 +-- src/Orchard.Tests/LinqToNHibernateTests.cs | 10 +- .../Orchard.Framework.Tests.csproj | 5 +- .../Records/{Bar.cs => BarRecord.cs} | 2 +- .../Records/{Foo.cs => FooRecord.cs} | 2 +- .../Records/ContentItemAlteration.cs | 6 +- src/Orchard/Data/Builders/AbstractBuilder.cs | 6 +- .../Data/Builders/ISessionFactoryBuilder.cs | 2 +- .../Conventions/RecordTableNameConvention.cs | 4 +- src/Orchard/Data/SessionFactoryHolder.cs | 2 +- .../Environment/DefaultCompositionStrategy.cs | 51 ++++++--- src/Orchard/Environment/DefaultOrchardHost.cs | 3 - .../Extensions/ExtensionManager.cs | 43 ++++---- .../Environment/Extensions/Models/Feature.cs | 2 +- .../Extensions/Models/FeatureDescriptor.cs | 3 +- .../Extensions/Records/ExtensionRecord.cs | 13 --- src/Orchard/Orchard.Framework.csproj | 1 - 24 files changed, 236 insertions(+), 166 deletions(-) create mode 100644 src/Orchard.Tests/Environment/Utility/Build.cs rename src/Orchard.Tests/Records/{Bar.cs => BarRecord.cs} (84%) rename src/Orchard.Tests/Records/{Foo.cs => FooRecord.cs} (79%) delete mode 100644 src/Orchard/Environment/Extensions/Records/ExtensionRecord.cs diff --git a/src/Orchard.Tests/Data/Builders/SessionFactoryBuilderTests.cs b/src/Orchard.Tests/Data/Builders/SessionFactoryBuilderTests.cs index 37679bff5..08d19c375 100644 --- a/src/Orchard.Tests/Data/Builders/SessionFactoryBuilderTests.cs +++ b/src/Orchard.Tests/Data/Builders/SessionFactoryBuilderTests.cs @@ -48,7 +48,7 @@ namespace Orchard.Tests.Data.Builders { [Test] public void SQLiteSchemaShouldBeGeneratedAndUsable() { var recordDescriptors = new[] { - new RecordDescriptor {Prefix = "Hello", Type = typeof (Foo)} + new RecordDescriptor_Obsolete {Prefix = "Hello", Type = typeof (FooRecord)} }; var manager = (ISessionFactoryBuilder)new SessionFactoryBuilder(); var sessionFactory = manager.BuildSessionFactory(new SessionFactoryParameters { @@ -60,7 +60,7 @@ namespace Orchard.Tests.Data.Builders { var session = sessionFactory.OpenSession(); - var foo = new Foo { Name = "hi there" }; + var foo = new FooRecord { Name = "hi there" }; session.Save(foo); session.Flush(); session.Close(); @@ -77,7 +77,7 @@ namespace Orchard.Tests.Data.Builders { CreateSqlServerDatabase(databasePath); var recordDescriptors = new[] { - new RecordDescriptor {Prefix = "Hello", Type = typeof (Foo)} + new RecordDescriptor_Obsolete {Prefix = "Hello", Type = typeof (FooRecord)} }; var manager = (ISessionFactoryBuilder)new SessionFactoryBuilder(); @@ -92,7 +92,7 @@ namespace Orchard.Tests.Data.Builders { var session = sessionFactory.OpenSession(); - var foo = new Foo { Name = "hi there" }; + var foo = new FooRecord { Name = "hi there" }; session.Save(foo); session.Flush(); session.Close(); diff --git a/src/Orchard.Tests/Data/RepositoryTests.cs b/src/Orchard.Tests/Data/RepositoryTests.cs index 907425fb2..553d22f3c 100644 --- a/src/Orchard.Tests/Data/RepositoryTests.cs +++ b/src/Orchard.Tests/Data/RepositoryTests.cs @@ -19,9 +19,9 @@ namespace Orchard.Tests.Data { [SetUp] public void Init() { - _sessionFactory = DataUtility.CreateSessionFactory(_databaseFilePath, typeof(Foo)); + _sessionFactory = DataUtility.CreateSessionFactory(_databaseFilePath, typeof(FooRecord)); _session = _sessionFactory.OpenSession(); - _fooRepos = new Repository(new StubLocator(_session)); + _fooRepos = new Repository(new StubLocator(_session)); } [TearDown] @@ -36,15 +36,15 @@ namespace Orchard.Tests.Data { #endregion - private IRepository _fooRepos; + private IRepository _fooRepos; private ISession _session; private string _databaseFilePath; private ISessionFactory _sessionFactory; private void CreateThreeFoos() { - _fooRepos.Create(new Foo { Name = "one" }); - _fooRepos.Create(new Foo { Name = "two" }); - _fooRepos.Create(new Foo { Name = "three" }); + _fooRepos.Create(new FooRecord { Name = "one" }); + _fooRepos.Create(new FooRecord { Name = "two" }); + _fooRepos.Create(new FooRecord { Name = "three" }); } [Test] @@ -121,7 +121,7 @@ namespace Orchard.Tests.Data { // If look at the "LinqOrderByCanBeUsedToControlResults", you will see this query // works fine is the static type of "foos" is "IEnumerable"... - IOrderedQueryable foos = + IOrderedQueryable foos = from f in _fooRepos.Table where f.Name == "two" || f.Name == "three" orderby f.Name, f.Id ascending @@ -138,7 +138,7 @@ namespace Orchard.Tests.Data { public void LinqOrderByCanBeUsedToControlResults() { CreateThreeFoos(); - IEnumerable foos = + IEnumerable foos = from f in _fooRepos.Table where f.Name == "two" || f.Name == "three" orderby f.Name, f.Id ascending @@ -152,7 +152,7 @@ namespace Orchard.Tests.Data { [Test] public void RangeShouldSliceResults() { for (var x = 0; x != 40; ++x) { - _fooRepos.Create(new Foo { Name = x.ToString().PadLeft(8, '0') }); + _fooRepos.Create(new FooRecord { Name = x.ToString().PadLeft(8, '0') }); } var foos = _fooRepos.Fetch( @@ -167,7 +167,7 @@ namespace Orchard.Tests.Data { [Test] public void RepositoryCanCreateFetchAndDelete() { - var foo1 = new Foo { Name = "yadda" }; + var foo1 = new FooRecord { Name = "yadda" }; _fooRepos.Create(foo1); var foo2 = _fooRepos.Get(foo1.Id); diff --git a/src/Orchard.Tests/DataUtility.cs b/src/Orchard.Tests/DataUtility.cs index 4235de057..c7ce8e04e 100644 --- a/src/Orchard.Tests/DataUtility.cs +++ b/src/Orchard.Tests/DataUtility.cs @@ -19,7 +19,7 @@ namespace Orchard.Tests { //var persistenceModel = AutoMap.Source(new Types(types)) // .Alterations(alt => AddAlterations(alt, types)) // .Conventions.AddFromAssemblyOf(); - var persistenceModel = AbstractBuilder.CreatePersistenceModel(types.Select(t => new RecordDescriptor { Prefix = "Test", Type = t })); + var persistenceModel = AbstractBuilder.CreatePersistenceModel(types.Select(t => new RecordDescriptor_Obsolete { Prefix = "Test", Type = t })); return Fluently.Configure() .Database(SQLiteConfiguration.Standard.UsingFile(fileName).ShowSql()) diff --git a/src/Orchard.Tests/Environment/DefaultCompositionStrategyTests.cs b/src/Orchard.Tests/Environment/DefaultCompositionStrategyTests.cs index 337c45e8c..a4594921c 100644 --- a/src/Orchard.Tests/Environment/DefaultCompositionStrategyTests.cs +++ b/src/Orchard.Tests/Environment/DefaultCompositionStrategyTests.cs @@ -7,11 +7,13 @@ using Autofac; using Autofac.Core; using Moq; using NUnit.Framework; +using Orchard.ContentManagement.Records; using Orchard.Environment; using Orchard.Environment.Extensions; using Orchard.Environment.Extensions.Models; using Orchard.Environment.Topology; -using Orchard.Environment.Topology.Models; +using Orchard.Tests.Environment.Utility; +using Orchard.Tests.Records; using Orchard.Tests.Utility; namespace Orchard.Tests.Environment { @@ -45,7 +47,7 @@ namespace Orchard.Tests.Environment { private IEnumerable StubLoadFeatures(IEnumerable featureDescriptors) { return featureDescriptors.Select(featureDescriptor => new Feature { - FeatureDescriptor = featureDescriptor, + Descriptor = featureDescriptor, ExportedTypes = _featureTypes[featureDescriptor.Name] }); } @@ -80,11 +82,11 @@ namespace Orchard.Tests.Environment { var foo = topology.Dependencies.SingleOrDefault(t => t.Type == typeof(FooService1)); Assert.That(foo, Is.Not.Null); - Assert.That(foo.Feature.FeatureDescriptor.Name, Is.EqualTo("Foo")); + Assert.That(foo.Feature.Descriptor.Name, Is.EqualTo("Foo")); var bar = topology.Dependencies.SingleOrDefault(t => t.Type == typeof(BarService1)); Assert.That(bar, Is.Not.Null); - Assert.That(bar.Feature.FeatureDescriptor.Name, Is.EqualTo("Bar")); + Assert.That(bar.Feature.Descriptor.Name, Is.EqualTo("Bar")); } public interface IFooService : IDependency { @@ -141,8 +143,8 @@ namespace Orchard.Tests.Environment { var alpha = topology.Modules.Single(x => x.Type == typeof (AlphaModule)); var beta = topology.Modules.Single(x => x.Type == typeof (BetaModule)); - Assert.That(alpha.Feature.FeatureDescriptor.Name, Is.EqualTo("Foo")); - Assert.That(beta.Feature.FeatureDescriptor.Name, Is.EqualTo("Bar")); + Assert.That(alpha.Feature.Descriptor.Name, Is.EqualTo("Foo")); + Assert.That(beta.Feature.Descriptor.Name, Is.EqualTo("Bar")); } public class AlphaModule : Module { @@ -155,11 +157,11 @@ namespace Orchard.Tests.Environment { } [Test] - public void ControllersArePutIntoTopology() { + public void ControllersArePutIntoTopologyWithAreaAndControllerName() { var descriptor = Build.TopologyDescriptor().WithFeatures("Foo Plus", "Bar Minus"); _extensionDescriptors = new[] { - Build.ExtensionDescriptor("Foo").WithFeatures("Foo", "Foo Plus"), + Build.ExtensionDescriptor("MyCompany.Foo", "Foo").WithFeatures("Foo", "Foo Plus"), Build.ExtensionDescriptor("Bar").WithFeatures("Bar", "Bar Minus"), }; @@ -175,15 +177,15 @@ namespace Orchard.Tests.Environment { var delta = topology.Controllers.Single(x => x.Type == typeof (DeltaController)); var epsilon = topology.Controllers.Single(x => x.Type == typeof (EpsilonController)); - Assert.That(gamma.Feature.FeatureDescriptor.Name, Is.EqualTo("Foo Plus")); - Assert.That(gamma.AreaName, Is.EqualTo("Foo")); + Assert.That(gamma.Feature.Descriptor.Name, Is.EqualTo("Foo Plus")); + Assert.That(gamma.AreaName, Is.EqualTo("MyCompany.Foo")); Assert.That(gamma.ControllerName, Is.EqualTo("Gamma")); - Assert.That(delta.Feature.FeatureDescriptor.Name, Is.EqualTo("Bar Minus")); + Assert.That(delta.Feature.Descriptor.Name, Is.EqualTo("Bar Minus")); Assert.That(delta.AreaName, Is.EqualTo("Bar")); Assert.That(delta.ControllerName, Is.EqualTo("Delta")); - Assert.That(epsilon.Feature.FeatureDescriptor.Name, Is.EqualTo("Bar Minus")); + Assert.That(epsilon.Feature.Descriptor.Name, Is.EqualTo("Bar Minus")); Assert.That(epsilon.AreaName, Is.EqualTo("Bar")); Assert.That(epsilon.ControllerName, Is.EqualTo("Epsilon")); } @@ -203,47 +205,54 @@ namespace Orchard.Tests.Environment { throw new NotImplementedException(); } } - } + + [Test] + public void RecordsArePutIntoTopologyWithTableName() { + var descriptor = Build.TopologyDescriptor().WithFeatures("Foo Plus", "Bar", "Bar Minus"); - static class Build { - - public static ShellTopologyDescriptor TopologyDescriptor() { - var descriptor = new ShellTopologyDescriptor { - EnabledFeatures = Enumerable.Empty(), - Parameters = Enumerable.Empty(), + _extensionDescriptors = new[] { + Build.ExtensionDescriptor("MyCompany.Foo", "Foo").WithFeatures("Foo", "Foo Plus"), + Build.ExtensionDescriptor("Bar").WithFeatures("Bar", "Bar Minus"), }; - return descriptor; + + _featureTypes["Foo"] = Enumerable.Empty(); + _featureTypes["Foo Plus"] = new[] { typeof(FooRecord) }; + _featureTypes["Bar"] = new[] { typeof(BarRecord) }; + _featureTypes["Bar Minus"] = Enumerable.Empty(); + + var compositionStrategy = _container.Resolve(); + var topology = compositionStrategy.Compose(descriptor); + + var foo = topology.Records.Single(x => x.Type == typeof (FooRecord)); + var bar = topology.Records.Single(x => x.Type == typeof (BarRecord)); + + Assert.That(foo.Feature.Descriptor.Name, Is.EqualTo("Foo Plus")); + Assert.That(foo.TableName, Is.EqualTo("MyCompany_Foo_FooRecord")); + + Assert.That(bar.Feature.Descriptor.Name, Is.EqualTo("Bar")); + Assert.That(bar.TableName, Is.EqualTo("Bar_BarRecord")); } - public static ShellTopologyDescriptor WithFeatures(this ShellTopologyDescriptor descriptor, params string[] names) { - descriptor.EnabledFeatures = descriptor.EnabledFeatures.Concat( - names.Select(name => new TopologyFeature { Name = name })); + [Test] + public void CoreRecordsAreAddedAutomatically() { + var descriptor = Build.TopologyDescriptor(); + + var compositionStrategy = _container.Resolve(); + var topology = compositionStrategy.Compose(descriptor); - return descriptor; - } + var ct = topology.Records.Single(x => x.Type == typeof (ContentTypeRecord)); + var ci = topology.Records.Single(x => x.Type == typeof (ContentItemRecord)); + var civ = topology.Records.Single(x => x.Type == typeof (ContentItemVersionRecord)); + + Assert.That(ct.Feature.Descriptor.Name, Is.EqualTo("Core")); + Assert.That(ct.TableName, Is.EqualTo("Core_ContentTypeRecord")); - public static ShellTopologyDescriptor WithParameter(this ShellTopologyDescriptor descriptor, string name, string value) { - descriptor.Parameters = descriptor.Parameters.Concat( - new[] { new TopologyParameter { Component = typeof(TComponent).FullName, Name = name, Value = value } }); - - return descriptor; - } - - public static ExtensionDescriptor ExtensionDescriptor(string name) { - var descriptor = new ExtensionDescriptor { - Name = name, - DisplayName = name, - Features = Enumerable.Empty(), - }; - return descriptor; - } - - public static ExtensionDescriptor WithFeatures(this ExtensionDescriptor descriptor, params string[] names) { - descriptor.Features = descriptor.Features.Concat( - names.Select(name => new FeatureDescriptor() { Name = name })); - - return descriptor; - } + Assert.That(ci.Feature.Descriptor.Name, Is.EqualTo("Core")); + Assert.That(ci.TableName, Is.EqualTo("Core_ContentItemRecord")); + + Assert.That(civ.Feature.Descriptor.Name, Is.EqualTo("Core")); + Assert.That(civ.TableName, Is.EqualTo("Core_ContentItemVersionRecord")); + } } } diff --git a/src/Orchard.Tests/Environment/DefaultOrchardHostTests.cs b/src/Orchard.Tests/Environment/DefaultOrchardHostTests.cs index 9c737dd95..158bded48 100644 --- a/src/Orchard.Tests/Environment/DefaultOrchardHostTests.cs +++ b/src/Orchard.Tests/Environment/DefaultOrchardHostTests.cs @@ -118,8 +118,8 @@ namespace Orchard.Tests.Environment { } public class StubCompositionStrategy : ICompositionStrategy_Obsolete, ICompositionStrategy { - public IEnumerable GetRecordDescriptors() { - return Enumerable.Empty(); + public IEnumerable GetRecordDescriptors_Obsolete() { + return Enumerable.Empty(); } public ShellTopology Compose(ShellTopologyDescriptor descriptor) { diff --git a/src/Orchard.Tests/Environment/Extensions/ExtensionManagerTests.cs b/src/Orchard.Tests/Environment/Extensions/ExtensionManagerTests.cs index c0d5b9159..cfd022b28 100644 --- a/src/Orchard.Tests/Environment/Extensions/ExtensionManagerTests.cs +++ b/src/Orchard.Tests/Environment/Extensions/ExtensionManagerTests.cs @@ -44,10 +44,10 @@ namespace Orchard.Tests.Environment.Extensions { var stream = parser.ParseYamlStream(new TextInput(Manifests[name]), out success); if (success) { return new ParseResult { - Location = "~/InMemory", - Name = name, - YamlDocument = stream.Documents.Single() - }; + Location = "~/InMemory", + Name = name, + YamlDocument = stream.Documents.Single() + }; } return null; } @@ -113,14 +113,14 @@ features: Assert.That(descriptor.OrchardVersion, Is.EqualTo("1")); Assert.That(descriptor.Features.Count(), Is.EqualTo(1)); Assert.That(descriptor.Features.First().Name, Is.EqualTo("SuperWiki")); - Assert.That(descriptor.Features.First().ExtensionName, Is.EqualTo("SuperWiki")); + Assert.That(descriptor.Features.First().Extension.Name, Is.EqualTo("SuperWiki")); Assert.That(descriptor.Features.First().Description, Is.EqualTo("My super wiki module for Orchard.")); } [Test] public void ExtensionDescriptorsShouldBeParsedForCompleteModuleTxt() { - _folders.Manifests.Add("AnotherWiki", @" + _folders.Manifests.Add("MyCompany.AnotherWiki", @" name: AnotherWiki author: Coder Notaprogrammer website: http://anotherwiki.codeplex.com @@ -146,7 +146,8 @@ features: "); var descriptor = _manager.AvailableExtensions().Single(); - Assert.That(descriptor.Name, Is.EqualTo("AnotherWiki")); + Assert.That(descriptor.Name, Is.EqualTo("MyCompany.AnotherWiki")); + Assert.That(descriptor.DisplayName, Is.EqualTo("AnotherWiki")); Assert.That(descriptor.Author, Is.EqualTo("Coder Notaprogrammer")); Assert.That(descriptor.WebSite, Is.EqualTo("http://anotherwiki.codeplex.com")); Assert.That(descriptor.Version, Is.EqualTo("1.2.3")); @@ -155,7 +156,7 @@ features: foreach (var featureDescriptor in descriptor.Features) { switch (featureDescriptor.Name) { case "AnotherWiki": - Assert.That(featureDescriptor.ExtensionName, Is.EqualTo("AnotherWiki")); + Assert.That(featureDescriptor.Extension, Is.SameAs(descriptor)); Assert.That(featureDescriptor.Description, Is.EqualTo("My super wiki module for Orchard.")); Assert.That(featureDescriptor.Category, Is.EqualTo("Content types")); Assert.That(featureDescriptor.Dependencies.Count(), Is.EqualTo(2)); @@ -163,7 +164,7 @@ features: Assert.That(featureDescriptor.Dependencies.Contains("Search")); break; case "AnotherWiki Editor": - Assert.That(featureDescriptor.ExtensionName, Is.EqualTo("AnotherWiki")); + Assert.That(featureDescriptor.Extension, Is.SameAs(descriptor)); Assert.That(featureDescriptor.Description, Is.EqualTo("A rich editor for wiki contents.")); Assert.That(featureDescriptor.Category, Is.EqualTo("Input methods")); Assert.That(featureDescriptor.Dependencies.Count(), Is.EqualTo(2)); @@ -171,7 +172,7 @@ features: Assert.That(featureDescriptor.Dependencies.Contains("AnotherWiki")); break; case "AnotherWiki DistributionList": - Assert.That(featureDescriptor.ExtensionName, Is.EqualTo("AnotherWiki")); + Assert.That(featureDescriptor.Extension, Is.SameAs(descriptor)); Assert.That(featureDescriptor.Description, Is.EqualTo("Sends e-mail alerts when wiki contents gets published.")); Assert.That(featureDescriptor.Category, Is.EqualTo("Email")); Assert.That(featureDescriptor.Dependencies.Count(), Is.EqualTo(2)); @@ -179,7 +180,7 @@ features: Assert.That(featureDescriptor.Dependencies.Contains("Email Subscriptions")); break; case "AnotherWiki Captcha": - Assert.That(featureDescriptor.ExtensionName, Is.EqualTo("AnotherWiki")); + Assert.That(featureDescriptor.Extension, Is.SameAs(descriptor)); Assert.That(featureDescriptor.Description, Is.EqualTo("Kills spam. Or makes it zombie-like.")); Assert.That(featureDescriptor.Category, Is.EqualTo("Spam")); Assert.That(featureDescriptor.Dependencies.Count(), Is.EqualTo(2)); @@ -223,16 +224,17 @@ features: [Test] public void ExtensionManagerTestFeatureAttribute() { var extensionManager = new Moq.Mock(); - extensionManager.Setup(x => x.ActiveExtensions_Obsolete()).Returns(new[] { - new ExtensionEntry { - Descriptor = new ExtensionDescriptor { - Name = "Module", - Features = new[] { - new FeatureDescriptor { Name = "Module", ExtensionName = "Module" }, - new FeatureDescriptor { Name = "TestFeature", ExtensionName = "Module" } - }}, - ExportedTypes = new[] { typeof(Alpha), typeof(Beta), typeof(Phi) } - }}); + var extensionEntry = new ExtensionEntry { + Descriptor = new ExtensionDescriptor { Name = "Module"}, + ExportedTypes = new[] { typeof(Alpha), typeof(Beta), typeof(Phi) } + }; + extensionEntry.Descriptor.Features = new[] { + new FeatureDescriptor + {Name = "Module", Extension = extensionEntry.Descriptor}, + new FeatureDescriptor + {Name = "TestFeature", Extension = extensionEntry.Descriptor} + }; + extensionManager.Setup(x => x.ActiveExtensions_Obsolete()).Returns(new[] {extensionEntry}); foreach (var type in extensionManager.Object.ActiveExtensions_Obsolete().SelectMany(x => x.ExportedTypes)) { foreach (OrchardFeatureAttribute featureAttribute in type.GetCustomAttributes(typeof(OrchardFeatureAttribute), false)) { diff --git a/src/Orchard.Tests/Environment/Utility/Build.cs b/src/Orchard.Tests/Environment/Utility/Build.cs new file mode 100644 index 000000000..d4db542da --- /dev/null +++ b/src/Orchard.Tests/Environment/Utility/Build.cs @@ -0,0 +1,50 @@ +using System.Linq; +using Orchard.Environment.Extensions.Models; +using Orchard.Environment.Topology.Models; + +namespace Orchard.Tests.Environment.Utility { + static class Build { + + public static ShellTopologyDescriptor TopologyDescriptor() { + var descriptor = new ShellTopologyDescriptor { + EnabledFeatures = Enumerable.Empty(), + Parameters = Enumerable.Empty(), + }; + return descriptor; + } + + public static ShellTopologyDescriptor WithFeatures(this ShellTopologyDescriptor descriptor, params string[] names) { + descriptor.EnabledFeatures = descriptor.EnabledFeatures.Concat( + names.Select(name => new TopologyFeature { Name = name })); + + return descriptor; + } + + public static ShellTopologyDescriptor WithParameter(this ShellTopologyDescriptor descriptor, string name, string value) { + descriptor.Parameters = descriptor.Parameters.Concat( + new[] { new TopologyParameter { Component = typeof(TComponent).FullName, Name = name, Value = value } }); + + return descriptor; + } + + public static ExtensionDescriptor ExtensionDescriptor(string name, string displayName) { + var descriptor = new ExtensionDescriptor { + Name = name, + DisplayName = displayName, + Features = Enumerable.Empty(), + }; + return descriptor; + } + + public static ExtensionDescriptor ExtensionDescriptor(string name) { + return ExtensionDescriptor(name, name); + } + + public static ExtensionDescriptor WithFeatures(this ExtensionDescriptor descriptor, params string[] names) { + descriptor.Features = descriptor.Features.Concat( + names.Select(name => new FeatureDescriptor { Extension=descriptor , Name = name, })); + + return descriptor; + } + } +} \ No newline at end of file diff --git a/src/Orchard.Tests/FluentDbTests.cs b/src/Orchard.Tests/FluentDbTests.cs index 4e8ac5e41..c7168484a 100644 --- a/src/Orchard.Tests/FluentDbTests.cs +++ b/src/Orchard.Tests/FluentDbTests.cs @@ -32,7 +32,7 @@ namespace Orchard.Tests { [Test] public void CreatingSchemaForStatedClassesInTempFile() { - var types = new Types(typeof (Foo), typeof (Bar)); + var types = new Types(typeof (FooRecord), typeof (BarRecord)); var sessionFactory = Fluently.Configure() .Database(SQLiteConfiguration.Standard.UsingFile("temp")) @@ -41,12 +41,12 @@ namespace Orchard.Tests { .BuildSessionFactory(); var session = sessionFactory.OpenSession(); - session.Save(new Foo {Name = "Hello"}); - session.Save(new Bar {Height = 3, Width = 4.5m}); + session.Save(new FooRecord {Name = "Hello"}); + session.Save(new BarRecord {Height = 3, Width = 4.5m}); session.Close(); session = sessionFactory.OpenSession(); - var foos = session.CreateCriteria().List(); + var foos = session.CreateCriteria().List(); Assert.That(foos.Count, Is.EqualTo(1)); Assert.That(foos, Has.All.Property("Name").EqualTo("Hello")); session.Close(); @@ -64,17 +64,17 @@ namespace Orchard.Tests { [Test] public void UsingDataUtilityToBuildSessionFactory() { - var factory = DataUtility.CreateSessionFactory(typeof (Foo), typeof (Bar)); + var factory = DataUtility.CreateSessionFactory(typeof (FooRecord), typeof (BarRecord)); var session = factory.OpenSession(); - var foo1 = new Foo {Name = "world"}; + var foo1 = new FooRecord {Name = "world"}; session.Save(foo1); session.Close(); session = factory.OpenSession(); - var foo2 = session.CreateCriteria() + var foo2 = session.CreateCriteria() .Add(Restrictions.Eq("Name", "world")) - .List().Single(); + .List().Single(); session.Close(); Assert.That(foo1, Is.Not.SameAs(foo2)); diff --git a/src/Orchard.Tests/LinqToNHibernateTests.cs b/src/Orchard.Tests/LinqToNHibernateTests.cs index b9c8e3717..0ba8b5d7a 100644 --- a/src/Orchard.Tests/LinqToNHibernateTests.cs +++ b/src/Orchard.Tests/LinqToNHibernateTests.cs @@ -11,11 +11,11 @@ namespace Orchard.Tests { [SetUp] public void Init() { - var sessionFactory = DataUtility.CreateSessionFactory(typeof (Foo)); + var sessionFactory = DataUtility.CreateSessionFactory(typeof (FooRecord)); using (var session = sessionFactory.OpenSession()) { - session.Save(new Foo {Name = "one"}); - session.Save(new Foo {Name = "two"}); - session.Save(new Foo {Name = "three"}); + session.Save(new FooRecord {Name = "one"}); + session.Save(new FooRecord {Name = "two"}); + session.Save(new FooRecord {Name = "three"}); } _session = sessionFactory.OpenSession(); } @@ -31,7 +31,7 @@ namespace Orchard.Tests { [Test] public void WhereClauseShouldLimitResults() { - var foos = from f in _session.Linq() where f.Name == "two" || f.Name == "one" select f; + var foos = from f in _session.Linq() where f.Name == "two" || f.Name == "one" select f; Assert.That(foos.Count(), Is.EqualTo(2)); Assert.That(foos, Has.Some.Property("Name").EqualTo("one")); diff --git a/src/Orchard.Tests/Orchard.Framework.Tests.csproj b/src/Orchard.Tests/Orchard.Framework.Tests.csproj index 0eb8f1eee..2e72a001a 100644 --- a/src/Orchard.Tests/Orchard.Framework.Tests.csproj +++ b/src/Orchard.Tests/Orchard.Framework.Tests.csproj @@ -157,6 +157,7 @@ + @@ -194,8 +195,8 @@ - - + + diff --git a/src/Orchard.Tests/Records/Bar.cs b/src/Orchard.Tests/Records/BarRecord.cs similarity index 84% rename from src/Orchard.Tests/Records/Bar.cs rename to src/Orchard.Tests/Records/BarRecord.cs index 15c7d91dc..1d460eb58 100644 --- a/src/Orchard.Tests/Records/Bar.cs +++ b/src/Orchard.Tests/Records/BarRecord.cs @@ -1,5 +1,5 @@ namespace Orchard.Tests.Records { - public class Bar { + public class BarRecord { public virtual int Id { get; set; } public virtual decimal Height { get; set; } public virtual decimal Width { get; set; } diff --git a/src/Orchard.Tests/Records/Foo.cs b/src/Orchard.Tests/Records/FooRecord.cs similarity index 79% rename from src/Orchard.Tests/Records/Foo.cs rename to src/Orchard.Tests/Records/FooRecord.cs index 8a260ae6e..276db6308 100644 --- a/src/Orchard.Tests/Records/Foo.cs +++ b/src/Orchard.Tests/Records/FooRecord.cs @@ -1,5 +1,5 @@ namespace Orchard.Tests.Records { - public class Foo { + public class FooRecord { public virtual int Id { get; set; } public virtual string Name { get; set; } } diff --git a/src/Orchard/ContentManagement/Records/ContentItemAlteration.cs b/src/Orchard/ContentManagement/Records/ContentItemAlteration.cs index 55f250435..b4f02d832 100644 --- a/src/Orchard/ContentManagement/Records/ContentItemAlteration.cs +++ b/src/Orchard/ContentManagement/Records/ContentItemAlteration.cs @@ -12,14 +12,14 @@ using Orchard.Environment; namespace Orchard.ContentManagement.Records { class ContentItemAlteration : IAutoMappingAlteration { - private readonly IEnumerable _recordDescriptors; + private readonly IEnumerable _recordDescriptors; [UsedImplicitly] public ContentItemAlteration() { - _recordDescriptors = Enumerable.Empty(); + _recordDescriptors = Enumerable.Empty(); } - public ContentItemAlteration(IEnumerable recordDescriptors) { + public ContentItemAlteration(IEnumerable recordDescriptors) { _recordDescriptors = recordDescriptors; } diff --git a/src/Orchard/Data/Builders/AbstractBuilder.cs b/src/Orchard/Data/Builders/AbstractBuilder.cs index b90768ed4..98baadf06 100644 --- a/src/Orchard/Data/Builders/AbstractBuilder.cs +++ b/src/Orchard/Data/Builders/AbstractBuilder.cs @@ -41,7 +41,7 @@ namespace Orchard.Data.Builders { } } - public static AutoPersistenceModel CreatePersistenceModel(IEnumerable recordDescriptors) { + public static AutoPersistenceModel CreatePersistenceModel(IEnumerable recordDescriptors) { return AutoMap.Source(new TypeSource(recordDescriptors)) // Ensure that namespaces of types are never auto-imported, so that // identical type names from different namespaces can be mapped without ambiguity @@ -58,9 +58,9 @@ namespace Orchard.Data.Builders { } class TypeSource : ITypeSource { - private readonly IEnumerable _recordDescriptors; + private readonly IEnumerable _recordDescriptors; - public TypeSource(IEnumerable recordDescriptors) { _recordDescriptors = recordDescriptors; } + public TypeSource(IEnumerable recordDescriptors) { _recordDescriptors = recordDescriptors; } public IEnumerable GetTypes() { return _recordDescriptors.Select(descriptor => descriptor.Type); } } diff --git a/src/Orchard/Data/Builders/ISessionFactoryBuilder.cs b/src/Orchard/Data/Builders/ISessionFactoryBuilder.cs index feb9b1ebe..b671108cc 100644 --- a/src/Orchard/Data/Builders/ISessionFactoryBuilder.cs +++ b/src/Orchard/Data/Builders/ISessionFactoryBuilder.cs @@ -16,6 +16,6 @@ namespace Orchard.Data.Builders { public bool CreateDatabase { get; set; } public bool UpdateSchema { get; set; } - public IEnumerable RecordDescriptors { get; set; } + public IEnumerable RecordDescriptors { get; set; } } } diff --git a/src/Orchard/Data/Conventions/RecordTableNameConvention.cs b/src/Orchard/Data/Conventions/RecordTableNameConvention.cs index 344824e92..6ace895a8 100644 --- a/src/Orchard/Data/Conventions/RecordTableNameConvention.cs +++ b/src/Orchard/Data/Conventions/RecordTableNameConvention.cs @@ -6,9 +6,9 @@ using Orchard.Environment; namespace Orchard.Data.Conventions { public class RecordTableNameConvention : IClassConvention { - private readonly IEnumerable _descriptors; + private readonly IEnumerable _descriptors; - public RecordTableNameConvention(IEnumerable descriptors) { + public RecordTableNameConvention(IEnumerable descriptors) { _descriptors = descriptors; } diff --git a/src/Orchard/Data/SessionFactoryHolder.cs b/src/Orchard/Data/SessionFactoryHolder.cs index 8ec6e2f32..034ca5bb5 100644 --- a/src/Orchard/Data/SessionFactoryHolder.cs +++ b/src/Orchard/Data/SessionFactoryHolder.cs @@ -77,7 +77,7 @@ namespace Orchard.Data { ConnectionString = _shellSettings.DataConnectionString, CreateDatabase = createDatabase, UpdateSchema = updateSchema, - RecordDescriptors = _compositionStrategy.GetRecordDescriptors(), + RecordDescriptors = _compositionStrategy.GetRecordDescriptors_Obsolete(), }); return sessionFactory; diff --git a/src/Orchard/Environment/DefaultCompositionStrategy.cs b/src/Orchard/Environment/DefaultCompositionStrategy.cs index ee7002c3c..77ba9b6c2 100644 --- a/src/Orchard/Environment/DefaultCompositionStrategy.cs +++ b/src/Orchard/Environment/DefaultCompositionStrategy.cs @@ -8,7 +8,6 @@ using Orchard.ContentManagement; using Orchard.ContentManagement.Records; using Orchard.Environment.Extensions; using Orchard.Environment.Extensions.Models; -using Orchard.Environment.Extensions.Records; using Orchard.Environment.Topology; using Orchard.Environment.Topology.Models; using Orchard.Utility.Extensions; @@ -17,10 +16,10 @@ namespace Orchard.Environment { //TEMP: This will be replaced by packaging system public interface ICompositionStrategy_Obsolete { - IEnumerable GetRecordDescriptors(); + IEnumerable GetRecordDescriptors_Obsolete(); } - public class RecordDescriptor { + public class RecordDescriptor_Obsolete { public Type Type { get; set; } public string Prefix { get; set; } } @@ -33,12 +32,11 @@ namespace Orchard.Environment { } public ShellTopology Compose(ShellTopologyDescriptor topologyDescriptor) { - var featureDescriptors = _extensionManager.AvailableExtensions() .SelectMany(extensionDescriptor => extensionDescriptor.Features) .Where(featureDescriptor => IsFeatureEnabledInTopology(featureDescriptor, topologyDescriptor)); - var features = _extensionManager.LoadFeatures(featureDescriptors); + var features = _extensionManager.LoadFeatures(featureDescriptors).Concat(CoreFeatures()); return new ShellTopology { Modules = BuildTopology(features, IsModule, BuildModule), @@ -48,6 +46,25 @@ namespace Orchard.Environment { }; } + private static IEnumerable CoreFeatures() { + var core = new Feature { + Descriptor = new FeatureDescriptor { + Name = "Core", + Extension = new ExtensionDescriptor { + Name = "Core", + DisplayName = "Core", + AntiForgery = "enabled", + }, + }, + ExportedTypes = new[] { + typeof (ContentTypeRecord), + typeof (ContentItemRecord), + typeof (ContentItemVersionRecord), + }, + }; + return new[] { core }; + } + private static bool IsFeatureEnabledInTopology(FeatureDescriptor featureDescriptor, ShellTopologyDescriptor topologyDescriptor) { return topologyDescriptor.EnabledFeatures.Any(topologyFeature => topologyFeature.Name == featureDescriptor.Name); @@ -89,7 +106,7 @@ namespace Orchard.Environment { } private static ControllerTopology BuildController(Type type, Feature feature) { - var areaName = feature.FeatureDescriptor.ExtensionName; + var areaName = feature.Descriptor.Extension.Name; var controllerName = type.Name; if (controllerName.EndsWith("Controller")) @@ -113,16 +130,22 @@ namespace Orchard.Environment { } private static RecordTopology BuildRecord(Type type, Feature feature) { - return new RecordTopology { Type = type, Feature = feature }; + var extensionDescriptor = feature.Descriptor.Extension; + var extensionName = extensionDescriptor.Name.Replace('.', '_'); + + return new RecordTopology { + Type = type, + Feature = feature, + TableName = extensionName + '_' + type.Name, + }; } - public IEnumerable GetRecordDescriptors() { - var descriptors = new List{ - new RecordDescriptor { Prefix = "Core", Type = typeof (ContentTypeRecord)}, - new RecordDescriptor { Prefix = "Core", Type = typeof (ContentItemRecord)}, - new RecordDescriptor { Prefix = "Core", Type = typeof (ContentItemVersionRecord)}, - new RecordDescriptor { Prefix = "Core", Type = typeof (ExtensionRecord)}, + public IEnumerable GetRecordDescriptors_Obsolete() { + var descriptors = new List{ + new RecordDescriptor_Obsolete { Prefix = "Core", Type = typeof (ContentTypeRecord)}, + new RecordDescriptor_Obsolete { Prefix = "Core", Type = typeof (ContentItemRecord)}, + new RecordDescriptor_Obsolete { Prefix = "Core", Type = typeof (ContentItemVersionRecord)}, }; foreach (var extension in _extensionManager.ActiveExtensions_Obsolete()) { @@ -133,7 +156,7 @@ namespace Orchard.Environment { var recordDescriptors = extension .ExportedTypes .Where(IsRecordType) - .Select(type => new RecordDescriptor { Prefix = prefix, Type = type }); + .Select(type => new RecordDescriptor_Obsolete { Prefix = prefix, Type = type }); descriptors.AddRange(recordDescriptors); } diff --git a/src/Orchard/Environment/DefaultOrchardHost.cs b/src/Orchard/Environment/DefaultOrchardHost.cs index 50abe3deb..e2fb304b6 100644 --- a/src/Orchard/Environment/DefaultOrchardHost.cs +++ b/src/Orchard/Environment/DefaultOrchardHost.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Web.Mvc; using Autofac; @@ -7,8 +6,6 @@ using System.Collections.Generic; using Orchard.Environment.Configuration; using Orchard.Environment.Extensions; using Orchard.Environment.ShellBuilders; -using Orchard.Environment.Topology; -using Orchard.Environment.Topology.Models; using Orchard.Mvc; using Orchard.Mvc.ViewEngines; using Orchard.Utility.Extensions; diff --git a/src/Orchard/Environment/Extensions/ExtensionManager.cs b/src/Orchard/Environment/Extensions/ExtensionManager.cs index 90f6a0616..e50eb59ee 100644 --- a/src/Orchard/Environment/Extensions/ExtensionManager.cs +++ b/src/Orchard/Environment/Extensions/ExtensionManager.cs @@ -69,30 +69,31 @@ namespace Orchard.Environment.Extensions { .Where(x => x.Key is Scalar) .ToDictionary(x => ((Scalar)x.Key).Text, x => x.Value); - return new ExtensionDescriptor { - Location = parseResult.Location, - Name = name, - ExtensionType = extensionType, - DisplayName = GetValue(fields, "name"), - Description = GetValue(fields, "description"), - Version = GetValue(fields, "version"), - OrchardVersion = GetValue(fields, "orchardversion"), - Author = GetValue(fields, "author"), - WebSite = GetValue(fields, "website"), - Tags = GetValue(fields, "tags"), - AntiForgery = GetValue(fields, "antiforgery"), - Features = GetFeaturesForExtension(GetMapping(fields, "features"), name), - }; + var extensionDescriptor = new ExtensionDescriptor { + Location = parseResult.Location, + Name = name, + ExtensionType = extensionType, + DisplayName = GetValue(fields, "name") ?? name, + Description = GetValue(fields, "description"), + Version = GetValue(fields, "version"), + OrchardVersion = GetValue(fields, "orchardversion"), + Author = GetValue(fields, "author"), + WebSite = GetValue(fields, "website"), + Tags = GetValue(fields, "tags"), + AntiForgery = GetValue(fields, "antiforgery"), + }; + extensionDescriptor.Features = GetFeaturesForExtension(GetMapping(fields, "features"), extensionDescriptor); + return extensionDescriptor; } - private static IEnumerable GetFeaturesForExtension(Mapping features, string name) { + private static IEnumerable GetFeaturesForExtension(Mapping features, ExtensionDescriptor extensionDescriptor) { List featureDescriptors = new List(); if (features == null) return featureDescriptors; foreach (var entity in features.Entities) { FeatureDescriptor featureDescriptor = new FeatureDescriptor { - ExtensionName = name, - Name = entity.Key.ToString(), - }; + Extension = extensionDescriptor, + Name = entity.Key.ToString(), + }; Mapping featureMapping = (Mapping)entity.Value; foreach (var featureEntity in featureMapping.Entities) { if (String.Equals(featureEntity.Key.ToString(), "description", StringComparison.OrdinalIgnoreCase)) { @@ -135,9 +136,9 @@ namespace Orchard.Environment.Extensions { } return new Feature { - FeatureDescriptor = featureDescriptor, - ExportedTypes = featureTypes - }; + Descriptor = featureDescriptor, + ExportedTypes = featureTypes + }; } private static string GetSourceFeatureNameForType(Type type, string extensionName) { diff --git a/src/Orchard/Environment/Extensions/Models/Feature.cs b/src/Orchard/Environment/Extensions/Models/Feature.cs index ed732f22a..b23cd0950 100644 --- a/src/Orchard/Environment/Extensions/Models/Feature.cs +++ b/src/Orchard/Environment/Extensions/Models/Feature.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace Orchard.Environment.Extensions.Models { public class Feature { - public FeatureDescriptor FeatureDescriptor { get; set; } + public FeatureDescriptor Descriptor { get; set; } public IEnumerable ExportedTypes { get; set; } } } \ No newline at end of file diff --git a/src/Orchard/Environment/Extensions/Models/FeatureDescriptor.cs b/src/Orchard/Environment/Extensions/Models/FeatureDescriptor.cs index 87bb77846..525601add 100644 --- a/src/Orchard/Environment/Extensions/Models/FeatureDescriptor.cs +++ b/src/Orchard/Environment/Extensions/Models/FeatureDescriptor.cs @@ -1,6 +1,7 @@ namespace Orchard.Environment.Extensions.Models { public class FeatureDescriptor { - public string ExtensionName { get; set; } + public ExtensionDescriptor Extension { get; set; } + public string Name { get; set; } public string Description { get; set; } public string Category { get; set; } diff --git a/src/Orchard/Environment/Extensions/Records/ExtensionRecord.cs b/src/Orchard/Environment/Extensions/Records/ExtensionRecord.cs deleted file mode 100644 index f7a5b7099..000000000 --- a/src/Orchard/Environment/Extensions/Records/ExtensionRecord.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Orchard.Environment.Extensions.Records { - public class ExtensionRecord { - public ExtensionRecord() { -// ReSharper disable DoNotCallOverridableMethodsInConstructor - Enabled = true; -// ReSharper restore DoNotCallOverridableMethodsInConstructor - } - - public virtual int Id { get; set; } - public virtual string Name { get; set; } - public virtual bool Enabled { get; set; } - } -} \ No newline at end of file diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index 6c4409b56..a28eb0af7 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -194,7 +194,6 @@ -