From b5856803e19d6cc5727d827f25fc84b2f518bf1b Mon Sep 17 00:00:00 2001 From: Stephan Date: Wed, 10 Jan 2018 12:48:51 +0100 Subject: [PATCH] DataType refactoring preparation - Entity refactoring --- src/Umbraco.Core/Cache/CacheRefresherBase.cs | 2 +- .../Cache/DefaultRepositoryCachePolicy.cs | 2 +- .../Cache/FullDataSetRepositoryCachePolicy.cs | 2 +- .../Cache/IRepositoryCachePolicy.cs | 2 +- .../Cache/NoCacheRepositoryCachePolicy.cs | 2 +- .../Cache/RepositoryCachePolicyBase.cs | 2 +- .../SingleItemsOnlyRepositoryCachePolicy.cs | 2 +- .../RepositoryCompositionRoot.cs | 2 +- src/Umbraco.Core/Composing/Current.cs | 3 + src/Umbraco.Core/KeyValuePairExtensions.cs | 20 ++ src/Umbraco.Core/Models/AuditItem.cs | 2 +- src/Umbraco.Core/Models/ContentBase.cs | 2 +- src/Umbraco.Core/Models/ContentTypeBase.cs | 2 +- .../Models/ContentTypeBaseExtensions.cs | 20 ++ src/Umbraco.Core/Models/DataType.cs | 166 ++++++++++++++ src/Umbraco.Core/Models/DataTypeDefinition.cs | 182 --------------- src/Umbraco.Core/Models/DictionaryItem.cs | 2 +- .../Models/DictionaryTranslation.cs | 2 +- .../Models/EntityBase/BeingDirtyBase.cs | 184 +++++++++++++++ src/Umbraco.Core/Models/EntityBase/Entity.cs | 214 ------------------ .../Models/EntityBase/EntityBase.cs | 180 +++++++++++++++ .../Models/EntityBase/EntityPath.cs | 8 - .../Models/EntityBase/IAggregateRoot.cs | 8 - .../Models/EntityBase/ICanBeDirty.cs | 4 +- .../Models/EntityBase/IDeletableEntity.cs | 11 - src/Umbraco.Core/Models/EntityBase/IEntity.cs | 15 +- .../Models/EntityBase/IRememberBeingDirty.cs | 4 +- .../Models/EntityBase/ITreeEntity.cs | 42 ++++ .../Models/EntityBase/IUmbracoEntity.cs | 51 ++--- .../EntityBase/TracksChangesEntityBase.cs | 206 ----------------- .../Models/EntityBase/TreeEntityPath.cs | 18 ++ src/Umbraco.Core/Models/File.cs | 2 +- src/Umbraco.Core/Models/Folder.cs | 2 +- src/Umbraco.Core/Models/IDataType.cs | 32 +++ .../Models/IDataTypeDefinition.cs | 18 -- src/Umbraco.Core/Models/IDeepCloneable.cs | 7 +- src/Umbraco.Core/Models/IDictionaryItem.cs | 3 +- src/Umbraco.Core/Models/IDomain.cs | 2 +- src/Umbraco.Core/Models/IFile.cs | 2 +- src/Umbraco.Core/Models/ILanguage.cs | 3 +- src/Umbraco.Core/Models/IMacro.cs | 2 +- src/Umbraco.Core/Models/IMemberGroup.cs | 2 +- src/Umbraco.Core/Models/IMigrationEntry.cs | 2 +- src/Umbraco.Core/Models/IRedirectUrl.cs | 2 +- src/Umbraco.Core/Models/IRelation.cs | 2 +- src/Umbraco.Core/Models/IRelationType.cs | 2 +- .../Models/IServerRegistration.cs | 2 +- src/Umbraco.Core/Models/ITag.cs | 2 +- .../Models/Identity/BackOfficeIdentityUser.cs | 2 +- .../Models/Identity/IIdentityUserLogin.cs | 2 +- .../Models/Identity/IdentityUserLogin.cs | 2 +- src/Umbraco.Core/Models/Language.cs | 2 +- src/Umbraco.Core/Models/Macro.cs | 4 +- src/Umbraco.Core/Models/MacroProperty.cs | 4 +- src/Umbraco.Core/Models/MemberGroup.cs | 2 +- .../Models/Membership/ContentPermissionSet.cs | 4 +- .../Models/Membership/IMembershipUser.cs | 2 +- .../Models/Membership/IUserGroup.cs | 2 +- .../Models/Membership/IUserType.cs | 2 +- src/Umbraco.Core/Models/Membership/User.cs | 6 +- .../Models/Membership/UserGroup.cs | 2 +- .../Models/Membership/UserType.cs | 2 +- src/Umbraco.Core/Models/MigrationEntry.cs | 2 +- .../Models/Packaging/InstallationSummary.cs | 4 +- src/Umbraco.Core/Models/Property.cs | 2 +- src/Umbraco.Core/Models/PropertyGroup.cs | 2 +- src/Umbraco.Core/Models/PropertyType.cs | 20 +- src/Umbraco.Core/Models/PublicAccessEntry.cs | 2 +- src/Umbraco.Core/Models/PublicAccessRule.cs | 2 +- .../DataTypeConfigurationSource.cs | 10 + .../IPublishedContentTypeFactory.cs | 18 +- .../PublishedContent/IPublishedProperty.cs | 2 +- .../PublishedContent/PublishedContentType.cs | 192 ++++++++-------- .../PublishedContentTypeFactory.cs | 29 ++- .../PublishedContent/PublishedDataType.cs | 2 +- .../PublishedContent/PublishedPropertyBase.cs | 23 +- .../PublishedContent/PublishedPropertyType.cs | 83 +++---- .../PublishedContent/RawValueProperty.cs | 37 ++- src/Umbraco.Core/Models/RedirectUrl.cs | 2 +- src/Umbraco.Core/Models/Relation.cs | 2 +- src/Umbraco.Core/Models/RelationType.cs | 2 +- src/Umbraco.Core/Models/ServerRegistration.cs | 2 +- src/Umbraco.Core/Models/StylesheetProperty.cs | 2 +- src/Umbraco.Core/Models/Tag.cs | 2 +- src/Umbraco.Core/Models/Task.cs | 2 +- src/Umbraco.Core/Models/TaskType.cs | 2 +- src/Umbraco.Core/Models/UmbracoDomain.cs | 2 +- src/Umbraco.Core/Models/UmbracoEntity.cs | 24 +- src/Umbraco.Core/Models/UmbracoObjectTypes.cs | 2 +- .../Packaging/Models/UninstallationSummary.cs | 4 +- .../Packaging/PackageInstallation.cs | 4 +- ...efinitionFactory.cs => DataTypeFactory.cs} | 194 ++++++++-------- .../Mappers/DataTypeDefinitionMapper.cs | 36 --- .../Persistence/Mappers/DataTypeMapper.cs | 36 +++ .../Mappers/MapperCollectionBuilder.cs | 2 +- ...onRepository.cs => IDataTypeRepository.cs} | 6 +- .../Repositories/IEntityRepository.cs | 4 +- .../Implement/ContentTypeRepositoryBase.cs | 2 +- ...ionRepository.cs => DataTypeRepository.cs} | 52 ++--- .../Implement/DictionaryRepository.cs | 6 +- .../Implement/EntityRepository.cs | 8 +- .../Implement/ExternalLoginRepository.cs | 6 +- .../Implement/LanguageRepository.cs | 4 +- .../Repositories/Implement/MacroRepository.cs | 8 +- .../Implement/NPocoRepositoryBase.cs | 4 +- .../Implement/PermissionRepository.cs | 6 +- .../Implement/RelationRepository.cs | 6 +- .../Implement/RelationTypeRepository.cs | 6 +- .../Implement/RepositoryBaseOfTIdTEntity.cs | 2 +- .../Implement/SimpleGetRepository.cs | 4 +- .../Repositories/Implement/TagRepository.cs | 8 +- .../Implement/TemplateRepository.cs | 2 +- .../Implement/UserGroupRepository.cs | 8 +- .../PropertyEditors/PropertyEditor.cs | 112 +++++---- .../CheckboxListValueConverter.cs | 2 +- .../ColorPickerValueConverter.cs | 2 +- .../DatePickerValueConverter.cs | 2 +- .../ValueConverters/DecimalValueConverter.cs | 2 +- .../DropdownListMultipleValueConverter.cs | 2 +- ...pdownListMultipleWithKeysValueConverter.cs | 2 +- .../DropdownListValueConverter.cs | 2 +- .../DropdownListWithKeysValueConverter.cs | 2 +- .../EmailAddressValueConverter.cs | 2 +- .../ValueConverters/GridValueConverter.cs | 2 +- .../ImageCropperValueConverter.cs | 4 +- .../ValueConverters/IntegerValueConverter.cs | 2 +- .../ValueConverters/JsonValueConverter.cs | 2 +- .../ValueConverters/LabelValueConverter.cs | 2 +- .../MarkdownEditorValueConverter.cs | 2 +- .../MemberGroupPickerValueConverter.cs | 2 +- .../MultipleTextStringValueConverter.cs | 2 +- .../MustBeStringValueConverter.cs | 2 +- .../RadioButtonListValueConverter.cs | 2 +- .../ValueConverters/SliderValueConverter.cs | 6 +- .../ValueConverters/TagsValueConverter.cs | 4 +- .../TextStringValueConverter.cs | 2 +- .../ValueConverters/TinyMceValueConverter.cs | 2 +- .../UploadPropertyConverter.cs | 2 +- .../ValueConverters/YesNoValueConverter.cs | 2 +- .../Services/EntityXmlSerializer.cs | 16 +- src/Umbraco.Core/Services/IDataTypeService.cs | 80 +++---- src/Umbraco.Core/Services/IEntityService.cs | 4 +- .../Services/IPackagingService.cs | 10 +- .../Services/Implement/ContentService.cs | 51 +---- .../Services/Implement/DataTypeService.cs | 168 +++++++------- .../Services/Implement/EntityService.cs | 6 +- .../Services/Implement/MediaService.cs | 32 +-- .../Services/Implement/MemberService.cs | 14 +- .../Services/Implement/PackagingService.cs | 38 ++-- src/Umbraco.Core/UdiGetterExtensions.cs | 4 +- src/Umbraco.Core/Umbraco.Core.csproj | 23 +- .../XmlPublishedContentInitBenchmarks.cs | 4 +- .../Cache/CacheRefresherComponentTests.cs | 4 +- .../DeepCloneRuntimeCacheProviderTests.cs | 2 +- .../PublishedMediaCacheTests.cs | 4 +- src/Umbraco.Tests/Misc/LibraryTests.cs | 2 +- ...ypeDefinitionTests.cs => DataTypeTests.cs} | 8 +- .../Mapping/ContentTypeModelMappingTests.cs | 32 +-- .../Models/UserExtensionsTests.cs | 4 +- ...ionMapperTest.cs => DataTypeMapperTest.cs} | 108 ++++----- .../Persistence/Querying/ExpressionTests.cs | 2 +- .../Repositories/ContentRepositoryTest.cs | 12 +- .../DataTypeDefinitionRepositoryTest.cs | 60 ++--- .../Plugins/PluginManagerTests.cs | 2 +- .../MultiValuePropertyEditorTests.cs | 6 +- .../Published/ConvertersTests.cs | 8 +- .../Published/NestedContentTests.cs | 2 +- .../Published/PropertyCacheLevelTests.cs | 2 +- .../PublishedContentDataTableTests.cs | 2 +- .../PublishedContentMoreTests.cs | 6 +- .../PublishedContentTestBase.cs | 2 +- .../PublishedContentTestElements.cs | 13 +- .../PublishedContent/PublishedContentTests.cs | 2 +- .../Services/CachedDataTypeServiceTests.cs | 4 +- .../Services/DataTypeServiceTests.cs | 78 +++---- .../Services/Importing/PackageImportTests.cs | 2 +- .../Services/PreValueConverterTests.cs | 6 +- src/Umbraco.Tests/TestHelpers/BaseWebTest.cs | 2 +- .../TestHelpers/Entities/MockedEntity.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestObjects.cs | 2 +- src/Umbraco.Tests/Umbraco.Tests.csproj | 4 +- .../Controllers/ContentControllerUnitTests.cs | 6 +- ...terAllowedOutgoingContentAttributeTests.cs | 2 +- .../Controllers/MediaControllerUnitTests.cs | 6 +- .../UserEditorAuthorizationHelperTests.cs | 16 +- .../Cache/CacheRefresherComponent.cs | 4 +- .../Cache/DataTypeCacheRefresher.cs | 2 +- .../Cache/DistributedCacheExtensions.cs | 4 +- src/Umbraco.Web/Composing/Current.cs | 2 + .../Editors/ContentTypeController.cs | 4 +- src/Umbraco.Web/Editors/DataTypeController.cs | 24 +- .../Editors/DataTypeValidateAttribute.cs | 6 +- .../Editors/PackageInstallController.cs | 2 +- .../ContentEditing/ContentPropertyDto.cs | 2 +- .../Models/ContentEditing/DataTypeSave.cs | 2 +- .../AvailablePropertyEditorsResolver.cs | 4 +- .../Models/Mapping/CodeFileMapperProfile.cs | 4 +- .../Mapping/ContentTypeProfileExtensions.cs | 2 +- .../Models/Mapping/DataTypeMapperProfile.cs | 20 +- .../Models/Mapping/EntityProfileExtensions.cs | 16 +- .../Models/Mapping/MemberMapperProfile.cs | 2 +- .../Models/Mapping/PreValueDisplayResolver.cs | 8 +- .../Mapping/TabsAndPropertiesResolver.cs | 4 +- .../Models/Mapping/TemplateMapperProfile.cs | 2 +- .../Models/Mapping/UserMapperProfile.cs | 6 +- .../Models/PublishedContentBase.cs | 2 +- src/Umbraco.Web/Models/PublishedProperty.cs | 4 +- src/Umbraco.Web/Models/UmbracoProperty.cs | 1 + .../ContentPickerValueConverter.cs | 6 +- .../MacroContainerValueConverter.cs | 2 +- .../MarkdownEditorValueConverter.cs | 2 +- .../MediaPickerLegacyValueConverter.cs | 10 +- .../MediaPickerValueConverter.cs | 6 +- .../MemberPickerValueConverter.cs | 4 +- .../MultiNodeTreePickerValueConverter.cs | 16 +- .../NestedContentManyValueConverter.cs | 2 +- .../NestedContentSingleValueConverter.cs | 2 +- .../NestedContentValueConverterBase.cs | 2 +- .../RelatedLinksLegacyValueConverter.cs | 4 +- .../RelatedLinksValueConverter.cs | 4 +- .../TextStringValueConverter.cs | 2 +- .../PublishedCache/NuCache/ContentStore.cs | 2 +- .../NuCache/Navigable/NavigableContentType.cs | 2 +- .../PublishedCache/NuCache/Property.cs | 4 +- .../NuCache/PublishedContent.cs | 2 +- .../PublishedCache/NuCache/PublishedMember.cs | 2 +- .../NuCache/PublishedSnapshotService.cs | 12 +- .../PublishedContentTypeCache.cs | 6 +- .../PublishedCache/PublishedElement.cs | 2 +- .../PublishedElementPropertyBase.cs | 2 +- .../PublishedCache/PublishedMember.cs | 75 +++--- .../XmlPublishedCache/PublishedMediaCache.cs | 10 +- .../XmlPublishedCache/XmlPublishedContent.cs | 4 +- src/Umbraco.Web/PublishedContentExtensions.cs | 2 +- .../Filters/ContentItemValidationHelper.cs | 2 +- src/Umbraco.Web/umbraco.presentation/page.cs | 13 +- 236 files changed, 1872 insertions(+), 1869 deletions(-) create mode 100644 src/Umbraco.Core/KeyValuePairExtensions.cs create mode 100644 src/Umbraco.Core/Models/ContentTypeBaseExtensions.cs create mode 100644 src/Umbraco.Core/Models/DataType.cs delete mode 100644 src/Umbraco.Core/Models/DataTypeDefinition.cs create mode 100644 src/Umbraco.Core/Models/EntityBase/BeingDirtyBase.cs delete mode 100644 src/Umbraco.Core/Models/EntityBase/Entity.cs create mode 100644 src/Umbraco.Core/Models/EntityBase/EntityBase.cs delete mode 100644 src/Umbraco.Core/Models/EntityBase/EntityPath.cs delete mode 100644 src/Umbraco.Core/Models/EntityBase/IAggregateRoot.cs delete mode 100644 src/Umbraco.Core/Models/EntityBase/IDeletableEntity.cs create mode 100644 src/Umbraco.Core/Models/EntityBase/ITreeEntity.cs delete mode 100644 src/Umbraco.Core/Models/EntityBase/TracksChangesEntityBase.cs create mode 100644 src/Umbraco.Core/Models/EntityBase/TreeEntityPath.cs create mode 100644 src/Umbraco.Core/Models/IDataType.cs delete mode 100644 src/Umbraco.Core/Models/IDataTypeDefinition.cs rename src/Umbraco.Core/Persistence/Factories/{DataTypeDefinitionFactory.cs => DataTypeFactory.cs} (86%) delete mode 100644 src/Umbraco.Core/Persistence/Mappers/DataTypeDefinitionMapper.cs create mode 100644 src/Umbraco.Core/Persistence/Mappers/DataTypeMapper.cs rename src/Umbraco.Core/Persistence/Repositories/{IDataTypeDefinitionRepository.cs => IDataTypeRepository.cs} (53%) rename src/Umbraco.Core/Persistence/Repositories/Implement/{DataTypeDefinitionRepository.cs => DataTypeRepository.cs} (91%) rename src/Umbraco.Tests/Models/{DataTypeDefinitionTests.cs => DataTypeTests.cs} (90%) rename src/Umbraco.Tests/Persistence/Mappers/{DataTypeDefinitionMapperTest.cs => DataTypeMapperTest.cs} (65%) diff --git a/src/Umbraco.Core/Cache/CacheRefresherBase.cs b/src/Umbraco.Core/Cache/CacheRefresherBase.cs index 568c955eda..bb0aa9f589 100644 --- a/src/Umbraco.Core/Cache/CacheRefresherBase.cs +++ b/src/Umbraco.Core/Cache/CacheRefresherBase.cs @@ -100,7 +100,7 @@ namespace Umbraco.Core.Cache /// /// The type of the entities. protected void ClearAllIsolatedCacheByEntityType() - where TEntity : class, IAggregateRoot + where TEntity : class, IEntity { CacheHelper.IsolatedRuntimeCache.ClearCache(); } diff --git a/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs b/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs index 4e668f064d..dde212988f 100644 --- a/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs +++ b/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs @@ -18,7 +18,7 @@ namespace Umbraco.Core.Cache /// If options.GetAllCacheValidateCount then we check against the db when getting many entities. /// internal class DefaultRepositoryCachePolicy : RepositoryCachePolicyBase - where TEntity : class, IAggregateRoot + where TEntity : class, IEntity { private static readonly TEntity[] EmptyEntities = new TEntity[0]; // const private readonly RepositoryCachePolicyOptions _options; diff --git a/src/Umbraco.Core/Cache/FullDataSetRepositoryCachePolicy.cs b/src/Umbraco.Core/Cache/FullDataSetRepositoryCachePolicy.cs index d28896e201..44eb00d5b9 100644 --- a/src/Umbraco.Core/Cache/FullDataSetRepositoryCachePolicy.cs +++ b/src/Umbraco.Core/Cache/FullDataSetRepositoryCachePolicy.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.Cache /// keep as a whole in memory. /// internal class FullDataSetRepositoryCachePolicy : RepositoryCachePolicyBase - where TEntity : class, IAggregateRoot + where TEntity : class, IEntity { private readonly Func _entityGetId; private readonly bool _expires; diff --git a/src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs b/src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs index 09d13cefec..e0a95290c6 100644 --- a/src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs +++ b/src/Umbraco.Core/Cache/IRepositoryCachePolicy.cs @@ -6,7 +6,7 @@ using Umbraco.Core.Scoping; namespace Umbraco.Core.Cache { internal interface IRepositoryCachePolicy - where TEntity : class, IAggregateRoot + where TEntity : class, IEntity { /// /// Gets an entity from the cache, else from the repository. diff --git a/src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs b/src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs index a638a41ce3..035a9967e4 100644 --- a/src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs +++ b/src/Umbraco.Core/Cache/NoCacheRepositoryCachePolicy.cs @@ -7,7 +7,7 @@ using Umbraco.Core.Scoping; namespace Umbraco.Core.Cache { internal class NoCacheRepositoryCachePolicy : IRepositoryCachePolicy - where TEntity : class, IAggregateRoot + where TEntity : class, IEntity { private NoCacheRepositoryCachePolicy() { } diff --git a/src/Umbraco.Core/Cache/RepositoryCachePolicyBase.cs b/src/Umbraco.Core/Cache/RepositoryCachePolicyBase.cs index e38dc0ac6b..6c656257a2 100644 --- a/src/Umbraco.Core/Cache/RepositoryCachePolicyBase.cs +++ b/src/Umbraco.Core/Cache/RepositoryCachePolicyBase.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Cache /// The type of the entity. /// The type of the identifier. internal abstract class RepositoryCachePolicyBase : IRepositoryCachePolicy - where TEntity : class, IAggregateRoot + where TEntity : class, IEntity { private readonly IRuntimeCacheProvider _globalCache; private readonly IScopeAccessor _scopeAccessor; diff --git a/src/Umbraco.Core/Cache/SingleItemsOnlyRepositoryCachePolicy.cs b/src/Umbraco.Core/Cache/SingleItemsOnlyRepositoryCachePolicy.cs index 9ffcbd2b71..a4bb63706a 100644 --- a/src/Umbraco.Core/Cache/SingleItemsOnlyRepositoryCachePolicy.cs +++ b/src/Umbraco.Core/Cache/SingleItemsOnlyRepositoryCachePolicy.cs @@ -14,7 +14,7 @@ namespace Umbraco.Core.Cache /// Used by DictionaryRepository. /// internal class SingleItemsOnlyRepositoryCachePolicy : DefaultRepositoryCachePolicy - where TEntity : class, IAggregateRoot + where TEntity : class, IEntity { public SingleItemsOnlyRepositoryCachePolicy(IRuntimeCacheProvider cache, IScopeAccessor scopeAccessor, RepositoryCachePolicyOptions options) : base(cache, scopeAccessor, options) diff --git a/src/Umbraco.Core/Composing/CompositionRoots/RepositoryCompositionRoot.cs b/src/Umbraco.Core/Composing/CompositionRoots/RepositoryCompositionRoot.cs index 1bac01adc6..c72ecb528f 100644 --- a/src/Umbraco.Core/Composing/CompositionRoots/RepositoryCompositionRoot.cs +++ b/src/Umbraco.Core/Composing/CompositionRoots/RepositoryCompositionRoot.cs @@ -39,7 +39,7 @@ namespace Umbraco.Core.Composing.CompositionRoots container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); - container.RegisterSingleton(); + container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index 8326be987f..98c0725819 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -147,6 +147,9 @@ namespace Umbraco.Core.Composing public static ISqlContext SqlContext => Container.GetInstance(); + public static IPublishedContentTypeFactory PublishedContentTypeFactory + => Container.GetInstance(); + #endregion } } diff --git a/src/Umbraco.Core/KeyValuePairExtensions.cs b/src/Umbraco.Core/KeyValuePairExtensions.cs new file mode 100644 index 0000000000..30fd3fee50 --- /dev/null +++ b/src/Umbraco.Core/KeyValuePairExtensions.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace Umbraco.Core +{ + /// + /// Provides extension methods for the struct. + /// + public static class KeyValuePairExtensions + { + /// + /// Implements key/value pair deconstruction. + /// + /// Allows for foreach ((var k, var v) in ...). + public static void Deconstruct(this KeyValuePair kvp, out TKey key, out TValue value) + { + key = kvp.Key; + value = kvp.Value; + } + } +} diff --git a/src/Umbraco.Core/Models/AuditItem.cs b/src/Umbraco.Core/Models/AuditItem.cs index cd885724d0..993eb784d6 100644 --- a/src/Umbraco.Core/Models/AuditItem.cs +++ b/src/Umbraco.Core/Models/AuditItem.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Models { - public sealed class AuditItem : Entity, IAggregateRoot + public sealed class AuditItem : EntityBase.EntityBase { public AuditItem(int objectId, string comment, AuditType type, int userId) { diff --git a/src/Umbraco.Core/Models/ContentBase.cs b/src/Umbraco.Core/Models/ContentBase.cs index 6adec3db5f..7863e5b6d8 100644 --- a/src/Umbraco.Core/Models/ContentBase.cs +++ b/src/Umbraco.Core/Models/ContentBase.cs @@ -18,7 +18,7 @@ namespace Umbraco.Core.Models [Serializable] [DataContract(IsReference = true)] [DebuggerDisplay("Id: {Id}, Name: {Name}, ContentType: {ContentTypeBase.Alias}")] - public abstract class ContentBase : Entity, IContentBase + public abstract class ContentBase : EntityBase.EntityBase, IContentBase { private static readonly Lazy Ps = new Lazy(); diff --git a/src/Umbraco.Core/Models/ContentTypeBase.cs b/src/Umbraco.Core/Models/ContentTypeBase.cs index 3e5c85f098..d54ce27443 100644 --- a/src/Umbraco.Core/Models/ContentTypeBase.cs +++ b/src/Umbraco.Core/Models/ContentTypeBase.cs @@ -17,7 +17,7 @@ namespace Umbraco.Core.Models [Serializable] [DataContract(IsReference = true)] [DebuggerDisplay("Id: {Id}, Name: {Name}, Alias: {Alias}")] - public abstract class ContentTypeBase : Entity, IContentTypeBase + public abstract class ContentTypeBase : EntityBase.EntityBase, IContentTypeBase { private static readonly Lazy Ps = new Lazy(); diff --git a/src/Umbraco.Core/Models/ContentTypeBaseExtensions.cs b/src/Umbraco.Core/Models/ContentTypeBaseExtensions.cs new file mode 100644 index 0000000000..6a71ff0979 --- /dev/null +++ b/src/Umbraco.Core/Models/ContentTypeBaseExtensions.cs @@ -0,0 +1,20 @@ +using Umbraco.Core.Models.PublishedContent; + +namespace Umbraco.Core.Models +{ + /// + /// Provides extensions methods for . + /// + public static class ContentTypeBaseExtensions + { + public static PublishedItemType GetItemType(this IContentTypeBase contentType) + { + var type = contentType.GetType(); + var itemType = PublishedItemType.Unknown; + if (type == typeof(IContentType)) itemType = PublishedItemType.Content; + else if (type == typeof(IMediaType)) itemType = PublishedItemType.Media; + else if (type == typeof(IMemberType)) itemType = PublishedItemType.Member; + return itemType; + } + } +} diff --git a/src/Umbraco.Core/Models/DataType.cs b/src/Umbraco.Core/Models/DataType.cs new file mode 100644 index 0000000000..2f35115ffd --- /dev/null +++ b/src/Umbraco.Core/Models/DataType.cs @@ -0,0 +1,166 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Reflection; +using System.Runtime.Serialization; +using Umbraco.Core.Models.EntityBase; + +namespace Umbraco.Core.Models +{ + /// + /// Implements . + /// + [Serializable] + [DataContract(IsReference = true)] + public class DataType : EntityBase.EntityBase, IDataType + { + private static readonly Lazy Ps = new Lazy(); + private readonly IDictionary _additionalData; + + private int _parentId; + private string _name; + private int _sortOrder; + private int _level; + private string _path; + private int _creatorId; + private bool _trashed; + private string _propertyEditorAlias; + private DataTypeDatabaseType _databaseType; + + /// + /// Initializes a new instance of the class. + /// + public DataType(int parentId, string propertyEditorAlias) + { + _parentId = parentId; + _propertyEditorAlias = propertyEditorAlias; + + _additionalData = new Dictionary(); + } + + /// + /// Initializes a new instance of the class. + /// + public DataType(string propertyEditorAlias) + { + _parentId = -1; + _propertyEditorAlias = propertyEditorAlias; + + _additionalData = new Dictionary(); + } + + // ReSharper disable once ClassNeverInstantiated.Local + private class PropertySelectors + { + public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); + public readonly PropertyInfo ParentIdSelector = ExpressionHelper.GetPropertyInfo(x => x.ParentId); + public readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo(x => x.SortOrder); + public readonly PropertyInfo LevelSelector = ExpressionHelper.GetPropertyInfo(x => x.Level); + public readonly PropertyInfo PathSelector = ExpressionHelper.GetPropertyInfo(x => x.Path); + public readonly PropertyInfo UserIdSelector = ExpressionHelper.GetPropertyInfo(x => x.CreatorId); + public readonly PropertyInfo TrashedSelector = ExpressionHelper.GetPropertyInfo(x => x.Trashed); + public readonly PropertyInfo PropertyEditorAliasSelector = ExpressionHelper.GetPropertyInfo(x => x.EditorAlias); + public readonly PropertyInfo DatabaseTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.DatabaseType); + } + + /// + [DataMember] + public int ParentId + { + get => _parentId; + set => SetPropertyValueAndDetectChanges(value, ref _parentId, Ps.Value.ParentIdSelector); + } + + /// + [DataMember] + public string Name + { + get => _name; + set => SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); + } + + /// + [DataMember] + public int SortOrder + { + get => _sortOrder; + set => SetPropertyValueAndDetectChanges(value, ref _sortOrder, Ps.Value.SortOrderSelector); + } + + /// + [DataMember] + public int Level + { + get => _level; + set => SetPropertyValueAndDetectChanges(value, ref _level, Ps.Value.LevelSelector); + } + + /// + // fixme - setting this value should be handled by the class not the user + [DataMember] + public string Path + { + get => _path; + set => SetPropertyValueAndDetectChanges(value, ref _path, Ps.Value.PathSelector); + } + + /// + [DataMember] + public int CreatorId + { + get => _creatorId; + set => SetPropertyValueAndDetectChanges(value, ref _creatorId, Ps.Value.UserIdSelector); + } + + /// + // fixme - data types cannot be trashed? + [DataMember] + public bool Trashed + { + get => _trashed; + internal set + { + SetPropertyValueAndDetectChanges(value, ref _trashed, Ps.Value.TrashedSelector); + + // this is a custom property that is not exposed in IUmbracoEntity so add it to the additional data + _additionalData["Trashed"] = value; + } + } + + // fixme - what exactly are we doing with _additionalData? + // are we allocating 1 dictionary for *every* entity? + // not doing it for other entities? + + /// + [DataMember] + public string EditorAlias + { + get => _propertyEditorAlias; + set + { + SetPropertyValueAndDetectChanges(value, ref _propertyEditorAlias, Ps.Value.PropertyEditorAliasSelector); + + // this is a custom property that is not exposed in IUmbracoEntity so add it to the additional data + _additionalData["DatabaseType"] = value; + } + } + + /// + [DataMember] + public DataTypeDatabaseType DatabaseType + { + get => _databaseType; + set + { + SetPropertyValueAndDetectChanges(value, ref _databaseType, Ps.Value.DatabaseTypeSelector); + + // this is a custom property that is not exposed in IUmbracoEntity so add it to the additional data + _additionalData["DatabaseType"] = value; + } + } + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + IDictionary IUmbracoEntity.AdditionalData => _additionalData; + } +} diff --git a/src/Umbraco.Core/Models/DataTypeDefinition.cs b/src/Umbraco.Core/Models/DataTypeDefinition.cs deleted file mode 100644 index eac6a7d5fd..0000000000 --- a/src/Umbraco.Core/Models/DataTypeDefinition.cs +++ /dev/null @@ -1,182 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Reflection; -using System.Runtime.Serialization; -using Umbraco.Core.Logging; -using Umbraco.Core.Models.EntityBase; -using Umbraco.Core.Persistence; -using Umbraco.Core.PropertyEditors; -using Umbraco.Core.Services; - -namespace Umbraco.Core.Models -{ - /// - /// Definition of a DataType/PropertyEditor - /// - /// - /// The definition exists as a database reference between an actual DataType/PropertyEditor - /// (identified by its control id), its prevalues (configuration) and the named DataType in the backoffice UI. - /// - [Serializable] - [DataContract(IsReference = true)] - public class DataTypeDefinition : Entity, IDataTypeDefinition - { - private int _parentId; - private string _name; - private int _sortOrder; - private int _level; - private string _path; - private int _creatorId; - private bool _trashed; - private string _propertyEditorAlias; - private DataTypeDatabaseType _databaseType; - - - public DataTypeDefinition(int parentId, string propertyEditorAlias) - { - _parentId = parentId; - _propertyEditorAlias = propertyEditorAlias; - - _additionalData = new Dictionary(); - } - - public DataTypeDefinition(string propertyEditorAlias) - { - _parentId = -1; - _propertyEditorAlias = propertyEditorAlias; - - _additionalData = new Dictionary(); - } - - private static readonly Lazy Ps = new Lazy(); - - private class PropertySelectors - { - public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); - public readonly PropertyInfo ParentIdSelector = ExpressionHelper.GetPropertyInfo(x => x.ParentId); - public readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo(x => x.SortOrder); - public readonly PropertyInfo LevelSelector = ExpressionHelper.GetPropertyInfo(x => x.Level); - public readonly PropertyInfo PathSelector = ExpressionHelper.GetPropertyInfo(x => x.Path); - public readonly PropertyInfo UserIdSelector = ExpressionHelper.GetPropertyInfo(x => x.CreatorId); - public readonly PropertyInfo TrashedSelector = ExpressionHelper.GetPropertyInfo(x => x.Trashed); - public readonly PropertyInfo PropertyEditorAliasSelector = ExpressionHelper.GetPropertyInfo(x => x.PropertyEditorAlias); - public readonly PropertyInfo DatabaseTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.DatabaseType); - } - - /// - /// Gets or sets the Id of the Parent entity - /// - /// Might not be necessary if handled as a relation? - [DataMember] - public int ParentId - { - get { return _parentId; } - set { SetPropertyValueAndDetectChanges(value, ref _parentId, Ps.Value.ParentIdSelector); } - } - - /// - /// Gets or sets the name of the current entity - /// - [DataMember] - public string Name - { - get { return _name; } - set { SetPropertyValueAndDetectChanges(value, ref _name, Ps.Value.NameSelector); } - } - - /// - /// Gets or sets the sort order of the content entity - /// - [DataMember] - public int SortOrder - { - get { return _sortOrder; } - set { SetPropertyValueAndDetectChanges(value, ref _sortOrder, Ps.Value.SortOrderSelector); } - } - - /// - /// Gets or sets the level of the content entity - /// - [DataMember] - public int Level - { - get { return _level; } - set { SetPropertyValueAndDetectChanges(value, ref _level, Ps.Value.LevelSelector); } - } - - /// - /// Gets or sets the path - /// - [DataMember] - public string Path //Setting this value should be handled by the class not the user - { - get { return _path; } - set { SetPropertyValueAndDetectChanges(value, ref _path, Ps.Value.PathSelector); } - } - - /// - /// Id of the user who created this entity - /// - [DataMember] - public int CreatorId - { - get { return _creatorId; } - set { SetPropertyValueAndDetectChanges(value, ref _creatorId, Ps.Value.UserIdSelector); } - } - - //NOTE: SD: Why do we have this ?? - - /// - /// Boolean indicating whether this entity is Trashed or not. - /// - [DataMember] - public bool Trashed - { - get { return _trashed; } - internal set - { - SetPropertyValueAndDetectChanges(value, ref _trashed, Ps.Value.TrashedSelector); - //This is a custom property that is not exposed in IUmbracoEntity so add it to the additional data - _additionalData["Trashed"] = value; - } - } - - [DataMember] - public string PropertyEditorAlias - { - get { return _propertyEditorAlias; } - set - { - SetPropertyValueAndDetectChanges(value, ref _propertyEditorAlias, Ps.Value.PropertyEditorAliasSelector); - //This is a custom property that is not exposed in IUmbracoEntity so add it to the additional data - _additionalData["DatabaseType"] = value; - } - } - - /// - /// Gets or Sets the DatabaseType for which the DataType's value is saved as - /// - [DataMember] - public DataTypeDatabaseType DatabaseType - { - get { return _databaseType; } - set - { - SetPropertyValueAndDetectChanges(value, ref _databaseType, Ps.Value.DatabaseTypeSelector); - //This is a custom property that is not exposed in IUmbracoEntity so add it to the additional data - _additionalData["DatabaseType"] = value; - } - } - - private readonly IDictionary _additionalData; - /// - /// Some entities may expose additional data that other's might not, this custom data will be available in this collection - /// - [EditorBrowsable(EditorBrowsableState.Never)] - IDictionary IUmbracoEntity.AdditionalData - { - get { return _additionalData; } - } - } -} diff --git a/src/Umbraco.Core/Models/DictionaryItem.cs b/src/Umbraco.Core/Models/DictionaryItem.cs index e32bfd7f76..f97742076b 100644 --- a/src/Umbraco.Core/Models/DictionaryItem.cs +++ b/src/Umbraco.Core/Models/DictionaryItem.cs @@ -12,7 +12,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class DictionaryItem : Entity, IDictionaryItem + public class DictionaryItem : EntityBase.EntityBase, IDictionaryItem { public Func GetLanguage { get; set; } private Guid? _parentId; diff --git a/src/Umbraco.Core/Models/DictionaryTranslation.cs b/src/Umbraco.Core/Models/DictionaryTranslation.cs index ebb24e3992..1df0c4b618 100644 --- a/src/Umbraco.Core/Models/DictionaryTranslation.cs +++ b/src/Umbraco.Core/Models/DictionaryTranslation.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class DictionaryTranslation : Entity, IDictionaryTranslation + public class DictionaryTranslation : EntityBase.EntityBase, IDictionaryTranslation { internal Func GetLanguage { get; set; } diff --git a/src/Umbraco.Core/Models/EntityBase/BeingDirtyBase.cs b/src/Umbraco.Core/Models/EntityBase/BeingDirtyBase.cs new file mode 100644 index 0000000000..c673088984 --- /dev/null +++ b/src/Umbraco.Core/Models/EntityBase/BeingDirtyBase.cs @@ -0,0 +1,184 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using System.Runtime.Serialization; +using Umbraco.Core.Composing; + +namespace Umbraco.Core.Models.EntityBase +{ + /// + /// Provides a base implementation of and . + /// + [Serializable] + [DataContract(IsReference = true)] + public abstract class BeingDirtyBase : IRememberBeingDirty + { + private bool _withChanges = true; // should we track changes? + private Dictionary _currentChanges; // which properties have changed? + private Dictionary _savedChanges; // which properties had changed at last commit? + + #region ICanBeDirty + + /// + public virtual bool IsDirty() + { + return _currentChanges != null && _currentChanges.Any(); + } + + /// + public virtual bool IsPropertyDirty(string propertyName) + { + return _currentChanges != null && _currentChanges.Any(x => x.Key == propertyName); + } + + /// + public virtual IEnumerable GetDirtyProperties() + { + // ReSharper disable once MergeConditionalExpression + return _currentChanges == null + ? Enumerable.Empty() + : _currentChanges.Where(x => x.Value).Select(x => x.Key); + } + + /// + /// Saves dirty properties so they can be checked with WasDirty. + public virtual void ResetDirtyProperties() + { + ResetDirtyProperties(true); + } + + #endregion + + #region IRememberBeingDirty + + /// + public virtual bool WasDirty() + { + return _savedChanges != null && _savedChanges.Any(); + } + + /// + public virtual bool WasPropertyDirty(string propertyName) + { + return _savedChanges != null && _savedChanges.Any(x => x.Key == propertyName); + } + + /// + public void ResetWereDirtyProperties() + { + // note: cannot .Clear() because when memberwise-cloning this will be the SAME + // instance as the one on the clone, so we need to create a new instance. + _savedChanges = null; + } + + /// + public virtual void ResetDirtyProperties(bool rememberDirty) + { + // capture changes if remembering + // clone the dictionary in case it's shared by an entity clone + _savedChanges = rememberDirty && _currentChanges != null + ? _currentChanges.ToDictionary(v => v.Key, v => v.Value) + : null; + + // note: cannot .Clear() because when memberwise-clone this will be the SAME + // instance as the one on the clone, so we need to create a new instance. + _currentChanges = null; + } + + #endregion + + #region Change Tracking + + /// + /// Occurs when a property changes. + /// + public event PropertyChangedEventHandler PropertyChanged; + + /// + /// Registers that a property has changed. + /// + protected virtual void OnPropertyChanged(PropertyInfo propertyInfo) + { + if (_withChanges == false) + return; + + if (_currentChanges == null) + _currentChanges = new Dictionary(); + + _currentChanges[propertyInfo.Name] = true; + + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyInfo.Name)); + } + + /// + /// Disables change tracking. + /// + public void DisableChangeTracking() + { + _withChanges = false; + } + + /// + /// Enables change tracking. + /// + public void EnableChangeTracking() + { + _withChanges = true; + } + + /// + /// Sets a property value, detects changes and manages the dirty flag. + /// + /// The type of the value. + /// The new value. + /// A reference to the value to set. + /// The property selector. + /// A comparer to compare property values. + protected void SetPropertyValueAndDetectChanges(T value, ref T valueRef, PropertyInfo propertySelector, IEqualityComparer comparer = null) + { + if (comparer == null) + { + // if no comparer is provided, use the default provider, as long as the value is not + // an IEnumerable - exclude strings, which are IEnumerable but have a default comparer + var typeofT = typeof(T); + if (!(typeofT == typeof(string)) && typeof(IEnumerable).IsAssignableFrom(typeofT)) + throw new ArgumentNullException(nameof(comparer), "A custom comparer must be supplied for IEnumerable values."); + comparer = EqualityComparer.Default; + } + + // compare values + var changed = _withChanges && comparer.Equals(valueRef, value) == false; + + // assign the new value + valueRef = value; + + // handle change + if (changed) + OnPropertyChanged(propertySelector); + } + + /// + /// Detects changes and manages the dirty flag. + /// + /// The type of the value. + /// The new value. + /// The original value. + /// The property selector. + /// A comparer to compare property values. + /// A value indicating whether we know values have changed and no comparison is required. + protected void DetectChanges(T value, T orig, PropertyInfo propertySelector, IEqualityComparer comparer, bool changed) + { + // compare values + changed = _withChanges && (changed || !comparer.Equals(orig, value)); + + // handle change + if (changed) + OnPropertyChanged(propertySelector); + } + + #endregion + } +} diff --git a/src/Umbraco.Core/Models/EntityBase/Entity.cs b/src/Umbraco.Core/Models/EntityBase/Entity.cs deleted file mode 100644 index f3970cec17..0000000000 --- a/src/Umbraco.Core/Models/EntityBase/Entity.cs +++ /dev/null @@ -1,214 +0,0 @@ -using System; -using System.Diagnostics; -using System.Reflection; -using System.Runtime.Serialization; - -namespace Umbraco.Core.Models.EntityBase -{ - /// - /// Base Abstract Entity - /// - [Serializable] - [DataContract(IsReference = true)] - [DebuggerDisplay("Id: {" + nameof(Id) + "}")] - public abstract class Entity : TracksChangesEntityBase, IEntity //, IRememberBeingDirty, ICanBeDirty - { - private bool _hasIdentity; - private int _id; - private Guid _key; - private DateTime _createDate; - private DateTime _updateDate; - private bool _wasCancelled; - - private static readonly Lazy Ps = new Lazy(); - - // ReSharper disable once ClassNeverInstantiated.Local - private class PropertySelectors - { - public readonly PropertyInfo IdSelector = ExpressionHelper.GetPropertyInfo(x => x.Id); - public readonly PropertyInfo KeySelector = ExpressionHelper.GetPropertyInfo(x => x.Key); - public readonly PropertyInfo CreateDateSelector = ExpressionHelper.GetPropertyInfo(x => x.CreateDate); - public readonly PropertyInfo UpdateDateSelector = ExpressionHelper.GetPropertyInfo(x => x.UpdateDate); - public readonly PropertyInfo HasIdentitySelector = ExpressionHelper.GetPropertyInfo(x => x.HasIdentity); - public readonly PropertyInfo WasCancelledSelector = ExpressionHelper.GetPropertyInfo(x => x.WasCancelled); - } - - /// - /// Integer Id - /// - [DataMember] - public int Id - { - get => _id; - set - { - SetPropertyValueAndDetectChanges(value, ref _id, Ps.Value.IdSelector); - HasIdentity = value != 0; //set the has Identity - } - } - - /// - /// Guid based Id - /// - /// The key is currectly used to store the Unique Id from the - /// umbracoNode table, which many of the entities are based on. - [DataMember] - public Guid Key - { - get - { - // if an entity does NOT have a UniqueId yet, assign one now - if (_key == Guid.Empty) - _key = Guid.NewGuid(); - return _key; - } - set => SetPropertyValueAndDetectChanges(value, ref _key, Ps.Value.KeySelector); - } - - /// - /// Gets or sets the Created Date - /// - [DataMember] - public DateTime CreateDate - { - get => _createDate; - set => SetPropertyValueAndDetectChanges(value, ref _createDate, Ps.Value.CreateDateSelector); - } - - /// - /// Gets or sets the WasCancelled flag, which is used to track - /// whether some action against an entity was cancelled through some event. - /// This only exists so we have a way to check if an event was cancelled through - /// the new api, which also needs to take effect in the legacy api. - /// - [IgnoreDataMember] - [Obsolete("Anytime there's a cancellable method it needs to return an Attempt so we know the outcome instead of this hack, not all services have been updated to use this though yet.")] - internal bool WasCancelled - { - get => _wasCancelled; - set => SetPropertyValueAndDetectChanges(value, ref _wasCancelled, Ps.Value.WasCancelledSelector); - } - - /// - /// Gets or sets the Modified Date - /// - [DataMember] - public DateTime UpdateDate - { - get => _updateDate; - set => SetPropertyValueAndDetectChanges(value, ref _updateDate, Ps.Value.UpdateDateSelector); - } - - [IgnoreDataMember] - public DateTime? DeletedDate { get; set; } - - internal virtual void ResetIdentity() - { - _hasIdentity = false; - _id = default(int); - _key = Guid.Empty; - } - - /// - /// Method to call on entity saved when first added - /// - internal virtual void AddingEntity() - { - if (IsPropertyDirty("CreateDate") == false || _createDate == default(DateTime)) - CreateDate = DateTime.Now; - if (IsPropertyDirty("UpdateDate") == false || _updateDate == default(DateTime)) - UpdateDate = DateTime.Now; - } - - /// - /// Method to call on entity saved/updated - /// - internal virtual void UpdatingEntity() - { - if (IsPropertyDirty("UpdateDate") == false || _updateDate == default(DateTime)) - UpdateDate = DateTime.Now; - - //this is just in case - if (_createDate == default(DateTime)) - CreateDate = DateTime.Now; - } - - /// - /// Indicates whether the current entity has an identity, eg. Id. - /// - [DataMember] - public virtual bool HasIdentity - { - get => _hasIdentity; - protected set => SetPropertyValueAndDetectChanges(value, ref _hasIdentity, Ps.Value.HasIdentitySelector); - } - - //TODO: Make this NOT virtual or even exist really! - public virtual bool SameIdentityAs(IEntity other) - { - return other != null && (ReferenceEquals(this, other) || SameIdentityAs(other as Entity)); - } - - public virtual bool Equals(Entity other) - { - return other != null && (ReferenceEquals(this, other) || SameIdentityAs(other)); - } - - //TODO: Make this NOT virtual or even exist really! - public virtual Type GetRealType() - { - return GetType(); - } - - //TODO: Make this NOT virtual or even exist really! - public virtual bool SameIdentityAs(Entity other) - { - if (ReferenceEquals(null, other)) - return false; - - if (ReferenceEquals(this, other)) - return true; - - if (GetType() == other.GetRealType() && HasIdentity && other.HasIdentity) - return other.Id.Equals(Id); - - return false; - } - - public override bool Equals(object obj) - { - return obj != null && (ReferenceEquals(this, obj) || SameIdentityAs(obj as IEntity)); - } - - public override int GetHashCode() - { - unchecked - { - var hashCode = HasIdentity.GetHashCode(); - hashCode = (hashCode * 397) ^ Id; - hashCode = (hashCode * 397) ^ GetType().GetHashCode(); - return hashCode; - } - } - - public virtual object DeepClone() - { - //Memberwise clone on Entity will work since it doesn't have any deep elements - // for any sub class this will work for standard properties as well that aren't complex object's themselves. - var unused = Key; // ensure that 'this' has a key, before cloning - var clone = (Entity)MemberwiseClone(); - //ensure the clone has it's own dictionaries - clone.ResetChangeTrackingCollections(); - //turn off change tracking - clone.DisableChangeTracking(); - //Automatically deep clone ref properties that are IDeepCloneable - DeepCloneHelper.DeepCloneRefProperties(this, clone); - //this shouldn't really be needed since we're not tracking - clone.ResetDirtyProperties(false); - //re-enable tracking - clone.EnableChangeTracking(); - - return clone; - } - } -} diff --git a/src/Umbraco.Core/Models/EntityBase/EntityBase.cs b/src/Umbraco.Core/Models/EntityBase/EntityBase.cs new file mode 100644 index 0000000000..2055ba584b --- /dev/null +++ b/src/Umbraco.Core/Models/EntityBase/EntityBase.cs @@ -0,0 +1,180 @@ +using System; +using System.Diagnostics; +using System.Reflection; +using System.Runtime.Serialization; + +namespace Umbraco.Core.Models.EntityBase +{ + /// + /// Provides a base class for entities. + /// + [Serializable] + [DataContract(IsReference = true)] + [DebuggerDisplay("Id: {" + nameof(Id) + "}")] + public abstract class EntityBase : BeingDirtyBase, IEntity + { + private static readonly Lazy Ps = new Lazy(); + + private bool _hasIdentity; + private int _id; + private Guid _key; + private DateTime _createDate; + private DateTime _updateDate; + + // ReSharper disable once ClassNeverInstantiated.Local + private class PropertySelectors + { + public readonly PropertyInfo IdSelector = ExpressionHelper.GetPropertyInfo(x => x.Id); + public readonly PropertyInfo KeySelector = ExpressionHelper.GetPropertyInfo(x => x.Key); + public readonly PropertyInfo CreateDateSelector = ExpressionHelper.GetPropertyInfo(x => x.CreateDate); + public readonly PropertyInfo UpdateDateSelector = ExpressionHelper.GetPropertyInfo(x => x.UpdateDate); + } + + /// + [DataMember] + public int Id + { + get => _id; + set + { + SetPropertyValueAndDetectChanges(value, ref _id, Ps.Value.IdSelector); + _hasIdentity = value != 0; + } + } + + /// + [DataMember] + public Guid Key + { + get + { + // if an entity does NOT have a key yet, assign one now + if (_key == Guid.Empty) + _key = Guid.NewGuid(); + return _key; + } + set => SetPropertyValueAndDetectChanges(value, ref _key, Ps.Value.KeySelector); + } + + /// + [DataMember] + public DateTime CreateDate + { + get => _createDate; + set => SetPropertyValueAndDetectChanges(value, ref _createDate, Ps.Value.CreateDateSelector); + } + + /// + [DataMember] + public DateTime UpdateDate + { + get => _updateDate; + set => SetPropertyValueAndDetectChanges(value, ref _updateDate, Ps.Value.UpdateDateSelector); + } + + /// + [DataMember] + public DateTime? DeleteDate { get; set; } // no change tracking - not persisted + + /// + [DataMember] + public virtual bool HasIdentity => _hasIdentity; + + /// + /// Resets the entity identity. + /// + internal virtual void ResetIdentity() + { + _id = default; + _key = Guid.Empty; + _hasIdentity = false; + } + + /// + /// Updates the entity when it is being saved for the first time. + /// + internal virtual void AddingEntity() + { + var now = DateTime.Now; + + // set the create and update dates, if not already set + if (IsPropertyDirty("CreateDate") == false || _createDate == default) + CreateDate = now; + if (IsPropertyDirty("UpdateDate") == false || _updateDate == default) + UpdateDate = now; + } + + /// + /// Updates the entity when it is being saved. + /// + internal virtual void UpdatingEntity() + { + var now = DateTime.Now; + + // just in case + if (_createDate == default) + CreateDate = now; + + // set the update date if not already set + if (IsPropertyDirty("UpdateDate") == false || _updateDate == default) + UpdateDate = now; + } + + public virtual bool Equals(EntityBase other) + { + return other != null && (ReferenceEquals(this, other) || SameIdentityAs(other)); + } + + public override bool Equals(object obj) + { + return obj != null && (ReferenceEquals(this, obj) || SameIdentityAs(obj as EntityBase)); + } + + private bool SameIdentityAs(EntityBase other) + { + if (other == null) return false; + + // same identity if + // - same object (reference equals) + // - or same Clr type, both have identities, and they are identical + + if (ReferenceEquals(this, other)) + return true; + + return GetType() == other.GetType() && HasIdentity && other.HasIdentity && Id == other.Id; + } + + public override int GetHashCode() + { + unchecked + { + var hashCode = HasIdentity.GetHashCode(); + hashCode = (hashCode * 397) ^ Id; + hashCode = (hashCode * 397) ^ GetType().GetHashCode(); + return hashCode; + } + } + + public virtual object DeepClone() + { + // memberwise-clone (ie shallow clone) the entity + var unused = Key; // ensure that 'this' has a key, before cloning + var clone = (EntityBase) MemberwiseClone(); + + // clear changes (ensures the clone has its own dictionaries) + // then disable change tracking + clone.ResetDirtyProperties(false); + clone.DisableChangeTracking(); + + // deep clone ref properties that are IDeepCloneable + DeepCloneHelper.DeepCloneRefProperties(this, clone); + + // clear changes again (just to be sure, because we were not tracking) + // then enable change tracking + clone.ResetDirtyProperties(false); + clone.EnableChangeTracking(); + + return clone; + } + } +} diff --git a/src/Umbraco.Core/Models/EntityBase/EntityPath.cs b/src/Umbraco.Core/Models/EntityBase/EntityPath.cs deleted file mode 100644 index 368d6bd87b..0000000000 --- a/src/Umbraco.Core/Models/EntityBase/EntityPath.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Umbraco.Core.Models.EntityBase -{ - public class EntityPath - { - public int Id { get; set; } - public string Path { get; set; } - } -} diff --git a/src/Umbraco.Core/Models/EntityBase/IAggregateRoot.cs b/src/Umbraco.Core/Models/EntityBase/IAggregateRoot.cs deleted file mode 100644 index 38f4cfbbd0..0000000000 --- a/src/Umbraco.Core/Models/EntityBase/IAggregateRoot.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Umbraco.Core.Models.EntityBase -{ - /// - /// Marker interface for aggregate roots - /// - public interface IAggregateRoot : IDeletableEntity - { } -} diff --git a/src/Umbraco.Core/Models/EntityBase/ICanBeDirty.cs b/src/Umbraco.Core/Models/EntityBase/ICanBeDirty.cs index 536cf11bfc..30b79121f1 100644 --- a/src/Umbraco.Core/Models/EntityBase/ICanBeDirty.cs +++ b/src/Umbraco.Core/Models/EntityBase/ICanBeDirty.cs @@ -8,12 +8,12 @@ namespace Umbraco.Core.Models.EntityBase public interface ICanBeDirty { /// - /// Gets a value indicating whether the current entity is dirty. + /// Determines whether the current entity is dirty. /// bool IsDirty(); /// - /// Gets a value indicating whether a specific property is dirty. + /// Determines whether a specific property is dirty. /// bool IsPropertyDirty(string propName); diff --git a/src/Umbraco.Core/Models/EntityBase/IDeletableEntity.cs b/src/Umbraco.Core/Models/EntityBase/IDeletableEntity.cs deleted file mode 100644 index 910722c184..0000000000 --- a/src/Umbraco.Core/Models/EntityBase/IDeletableEntity.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace Umbraco.Core.Models.EntityBase -{ - public interface IDeletableEntity : IEntity - { - [DataMember] - DateTime? DeletedDate { get; set; } - } -} diff --git a/src/Umbraco.Core/Models/EntityBase/IEntity.cs b/src/Umbraco.Core/Models/EntityBase/IEntity.cs index d871719826..c15eb3ca25 100644 --- a/src/Umbraco.Core/Models/EntityBase/IEntity.cs +++ b/src/Umbraco.Core/Models/EntityBase/IEntity.cs @@ -9,13 +9,13 @@ namespace Umbraco.Core.Models.EntityBase public interface IEntity : IDeepCloneable { /// - /// The integer identifier of the entity. + /// Gets or sets the integer identifier of the entity. /// [DataMember] int Id { get; set; } /// - /// The Guid unique identifier of the entity. + /// Gets or sets the Guid unique identifier of the entity. /// [DataMember] Guid Key { get; set; } @@ -32,6 +32,17 @@ namespace Umbraco.Core.Models.EntityBase [DataMember] DateTime UpdateDate { get; set; } + /// + /// Gets or sets the delete date. + /// + /// + /// The delete date is null when the entity has not been deleted. + /// The delete date has a value when the entity instance has been deleted, but this value + /// is transient and not persisted in database (since the entity does not exist anymore). + /// + [DataMember] + DateTime? DeleteDate { get; set; } + /// /// Gets a value indicating whether the entity has an identity. /// diff --git a/src/Umbraco.Core/Models/EntityBase/IRememberBeingDirty.cs b/src/Umbraco.Core/Models/EntityBase/IRememberBeingDirty.cs index db7f27357b..2e4fb50fe8 100644 --- a/src/Umbraco.Core/Models/EntityBase/IRememberBeingDirty.cs +++ b/src/Umbraco.Core/Models/EntityBase/IRememberBeingDirty.cs @@ -7,13 +7,13 @@ public interface IRememberBeingDirty : ICanBeDirty { /// - /// Gets a value indicating whether the current entity is dirty. + /// Determines whether the current entity is dirty. /// /// A property was dirty if it had been changed and the changes were committed. bool WasDirty(); /// - /// Gets a value indicating whether a specific property was dirty. + /// Determines whether a specific property was dirty. /// /// A property was dirty if it had been changed and the changes were committed. bool WasPropertyDirty(string propertyName); diff --git a/src/Umbraco.Core/Models/EntityBase/ITreeEntity.cs b/src/Umbraco.Core/Models/EntityBase/ITreeEntity.cs new file mode 100644 index 0000000000..e5a53903d4 --- /dev/null +++ b/src/Umbraco.Core/Models/EntityBase/ITreeEntity.cs @@ -0,0 +1,42 @@ +namespace Umbraco.Core.Models.EntityBase +{ + /// + /// Defines an entity that belongs to a tree. + /// + public interface ITreeEntity : IEntity + { + /// + /// Gets or sets the name of the entity. + /// + string Name { get; set; } + + /// + /// Gets or sets the identifier of the parent entity. + /// + int ParentId { get; set; } + + /// + /// Gets or sets the level of the entity. + /// + int Level { get; set; } + + /// + /// Gets or sets the path to the entity. + /// + string Path { get; set; } + + /// + /// Gets or sets the sort order of the entity. + /// + int SortOrder { get; set; } + + /// + /// Gets a value indicating whether this entity is trashed. + /// + /// + /// Trashed entities are located in the recycle bin. + /// Always false for entities that do not support being trashed. + /// + bool Trashed { get; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Models/EntityBase/IUmbracoEntity.cs b/src/Umbraco.Core/Models/EntityBase/IUmbracoEntity.cs index 4d69a78c16..d7ac509788 100644 --- a/src/Umbraco.Core/Models/EntityBase/IUmbracoEntity.cs +++ b/src/Umbraco.Core/Models/EntityBase/IUmbracoEntity.cs @@ -2,51 +2,26 @@ namespace Umbraco.Core.Models.EntityBase { - public interface IUmbracoEntity : IAggregateRoot, IRememberBeingDirty + /// + /// Represents fixme what exactly? + /// + /// + /// An IUmbracoEntity can be related to another via the IRelationService. + /// IUmbracoEntities can be retrieved with the IEntityService. + /// An IUmbracoEntity can participate in notifications. + /// + public interface IUmbracoEntity : ITreeEntity, IRememberBeingDirty { /// - /// Profile of the user who created this Entity + /// Gets or sets the identifier of the user who created this entity. /// int CreatorId { get; set; } /// - /// Gets or sets the level of the Entity - /// - int Level { get; set; } - - /// - /// Gets or Sets the Name of the Entity - /// - string Name { get; set; } - - /// - /// Gets or sets the Id of the Parent Entity - /// - int ParentId { get; set; } - - /// - /// Gets or sets the path to the Entity - /// - string Path { get; set; } - - /// - /// Gets or sets the sort order of the Entity - /// - int SortOrder { get; set; } - - /// - /// Boolean indicating whether this Entity is Trashed or not. - /// If an Entity is Trashed it will be located in the Recyclebin. - /// - /// - /// When content is trashed it should be unpublished. - /// Not all entities support being trashed, they'll always return false. - /// - bool Trashed { get; } - - /// - /// Some entities may expose additional data that other's might not, this custom data will be available in this collection + /// Gets additional data for this entity. /// IDictionary AdditionalData { get; } + + // fixme AdditionalData is never null, then we need a HasAdditionalData for checking values? } } diff --git a/src/Umbraco.Core/Models/EntityBase/TracksChangesEntityBase.cs b/src/Umbraco.Core/Models/EntityBase/TracksChangesEntityBase.cs deleted file mode 100644 index 3b69c64d04..0000000000 --- a/src/Umbraco.Core/Models/EntityBase/TracksChangesEntityBase.cs +++ /dev/null @@ -1,206 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using System.Runtime.Serialization; -using Umbraco.Core.Composing; - -namespace Umbraco.Core.Models.EntityBase -{ - /// - /// A base class for use to implement IRememberBeingDirty/ICanBeDirty - /// - [Serializable] - [DataContract(IsReference = true)] - public abstract class TracksChangesEntityBase : IRememberBeingDirty - { - private bool _changeTrackingEnabled = true; // should we track changes? - private IDictionary _propertyChangedInfo; // which properties have changed? - private IDictionary _lastPropertyChangedInfo; // which properties had changed at last commit? - - /// - /// Gets properties that are dirty. - /// - public virtual IEnumerable GetDirtyProperties() - { - if (_propertyChangedInfo == null) - return Enumerable.Empty(); - - return _propertyChangedInfo.Where(x => x.Value).Select(x => x.Key); - } - - /// - /// Occurs when a property changes. - /// - public event PropertyChangedEventHandler PropertyChanged; - - /// - /// Registers that a property has changed. - /// - protected virtual void OnPropertyChanged(PropertyInfo propertyInfo) - { - if (_changeTrackingEnabled == false) - return; - - if (_propertyChangedInfo == null) - _propertyChangedInfo = new Dictionary(); - - _propertyChangedInfo[propertyInfo.Name] = true; - - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyInfo.Name)); - } - - /// - /// Gets a value indicating whether a specific property is dirty. - /// - public virtual bool IsPropertyDirty(string propertyName) - { - return _propertyChangedInfo != null && _propertyChangedInfo.Any(x => x.Key == propertyName); - } - - /// - /// Gets a value indicating whether a specific property was dirty. - /// - /// A property was dirty if it had been changed and the changes were committed. - public virtual bool WasPropertyDirty(string propertyName) - { - return _lastPropertyChangedInfo != null && _lastPropertyChangedInfo.Any(x => x.Key == propertyName); - } - - /// - /// Gets a value indicating whether the current entity is dirty. - /// - public virtual bool IsDirty() - { - return _propertyChangedInfo != null && _propertyChangedInfo.Any(); - } - - /// - /// Gets a value indicating whether the current entity is dirty. - /// - /// A property was dirty if it had been changed and the changes were committed. - public virtual bool WasDirty() - { - return _lastPropertyChangedInfo != null && _lastPropertyChangedInfo.Any(); - } - - /// - /// Resets dirty properties. - /// - /// Saves dirty properties so they can be checked with WasDirty. - public virtual void ResetDirtyProperties() - { - ResetDirtyProperties(true); - } - - /// - /// Resets dirty properties. - /// - /// A value indicating whether to remember dirty properties. - /// When is true, dirty properties are saved so they can be checked with WasDirty. - public virtual void ResetDirtyProperties(bool rememberDirty) - { - if (rememberDirty && _propertyChangedInfo != null) - { - _lastPropertyChangedInfo = _propertyChangedInfo.ToDictionary(v => v.Key, v => v.Value); - } - - // note: cannot .Clear() because when memberwise-clone this will be the SAME - // instance as the one on the clone, so we need to create a new instance. - _propertyChangedInfo = null; - } - - /// - /// Resets properties that were dirty. - /// - public void ResetWereDirtyProperties() - { - // note: cannot .Clear() because when memberwise-cloning this will be the SAME - // instance as the one on the clone, so we need to create a new instance. - _lastPropertyChangedInfo = null; - } - - /// - /// Resets all change tracking infos. - /// - public void ResetChangeTrackingCollections() - { - _propertyChangedInfo = null; - _lastPropertyChangedInfo = null; - } - - /// - /// Disables change tracking. - /// - public void DisableChangeTracking() - { - _changeTrackingEnabled = false; - } - - /// - /// Enables change tracking. - /// - public void EnableChangeTracking() - { - _changeTrackingEnabled = true; - } - - /// - /// Sets a property value, detects changes and manages the dirty flag. - /// - /// The type of the value. - /// The new value. - /// A reference to the value to set. - /// The property selector. - internal void SetPropertyValueAndDetectChanges(T value, ref T valueRef, PropertyInfo propertySelector) - { - if ((typeof(T) == typeof(string) == false) && TypeHelper.IsTypeAssignableFrom(typeof(T))) - { - throw new InvalidOperationException("This method does not support IEnumerable instances. For IEnumerable instances a manual custom equality check will be required"); - } - - SetPropertyValueAndDetectChanges(value, ref valueRef, propertySelector, EqualityComparer.Default); - } - - /// - /// Sets a property value, detects changes and manages the dirty flag. - /// - /// The type of the value. - /// The new value. - /// A reference to the value to set. - /// The property selector. - /// A comparer to compare property values. - internal void SetPropertyValueAndDetectChanges(T value, ref T valueRef, PropertyInfo propertySelector, IEqualityComparer comparer) - { - var changed = _changeTrackingEnabled && comparer.Equals(valueRef, value) == false; - - valueRef = value; - - if (changed) - OnPropertyChanged(propertySelector); - } - - /// - /// Detects changes and manages the dirty flag. - /// - /// The type of the value. - /// The new value. - /// The original value. - /// The property selector. - /// A comparer to compare property values. - /// A value indicating whether we know values have changed and no comparison is required. - internal void DetectChanges(T value, T orig, PropertyInfo propertySelector, IEqualityComparer comparer, bool changed) - { - if (_changeTrackingEnabled == false) - return; - - if (!changed) - changed = comparer.Equals(orig, value) == false; - - if (changed) - OnPropertyChanged(propertySelector); - } - } -} diff --git a/src/Umbraco.Core/Models/EntityBase/TreeEntityPath.cs b/src/Umbraco.Core/Models/EntityBase/TreeEntityPath.cs new file mode 100644 index 0000000000..746011a85a --- /dev/null +++ b/src/Umbraco.Core/Models/EntityBase/TreeEntityPath.cs @@ -0,0 +1,18 @@ +namespace Umbraco.Core.Models.EntityBase +{ + /// + /// Represents the path of a tree entity. + /// + public class TreeEntityPath + { + /// + /// Gets or sets the identifier of the entity. + /// + public int Id { get; set; } + + /// + /// Gets or sets the path of the entity. + /// + public string Path { get; set; } + } +} diff --git a/src/Umbraco.Core/Models/File.cs b/src/Umbraco.Core/Models/File.cs index 97469d8a49..46e6ec633e 100644 --- a/src/Umbraco.Core/Models/File.cs +++ b/src/Umbraco.Core/Models/File.cs @@ -13,7 +13,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public abstract class File : Entity, IFile + public abstract class File : EntityBase.EntityBase, IFile { private string _path; private string _originalPath; diff --git a/src/Umbraco.Core/Models/Folder.cs b/src/Umbraco.Core/Models/Folder.cs index 945a47eeb4..321d6b69e6 100644 --- a/src/Umbraco.Core/Models/Folder.cs +++ b/src/Umbraco.Core/Models/Folder.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Models { - internal sealed class Folder : Entity + internal sealed class Folder : EntityBase.EntityBase { public Folder(string folderPath) { diff --git a/src/Umbraco.Core/Models/IDataType.cs b/src/Umbraco.Core/Models/IDataType.cs new file mode 100644 index 0000000000..b6d70b890f --- /dev/null +++ b/src/Umbraco.Core/Models/IDataType.cs @@ -0,0 +1,32 @@ +using Umbraco.Core.Models.EntityBase; + +namespace Umbraco.Core.Models +{ + /// + /// Represents a data type. + /// + public interface IDataType : IUmbracoEntity + { + /// + /// Gets or sets the property editor alias. + /// + string EditorAlias { get; set; } + + /// + /// Gets or sets the database type for the data type values. + /// + /// In most cases this is imposed by the property editor, but some editors + /// may support storing different types. + DataTypeDatabaseType DatabaseType { get; set; } + + /// + /// Gets or sets the configuration object. + /// + /// + /// The configuration object is serialized to Json and stored into the database. + /// The serialized Json is deserialized by the property editor, which by default should + /// return a Dictionary{string, object} but could return a typed object e.g. MyEditor.Configuration. + /// + object Configuration { get; set; } + } +} diff --git a/src/Umbraco.Core/Models/IDataTypeDefinition.cs b/src/Umbraco.Core/Models/IDataTypeDefinition.cs deleted file mode 100644 index 814512738a..0000000000 --- a/src/Umbraco.Core/Models/IDataTypeDefinition.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using Umbraco.Core.Models.EntityBase; - -namespace Umbraco.Core.Models -{ - public interface IDataTypeDefinition : IUmbracoEntity - { - /// - /// The Property editor alias assigned to the data type - /// - string PropertyEditorAlias { get; set; } - - /// - /// Gets or Sets the DatabaseType for which the DataType's value is saved as - /// - DataTypeDatabaseType DatabaseType { get; set; } - } -} diff --git a/src/Umbraco.Core/Models/IDeepCloneable.cs b/src/Umbraco.Core/Models/IDeepCloneable.cs index ea41d26dd1..057326b3c7 100644 --- a/src/Umbraco.Core/Models/IDeepCloneable.cs +++ b/src/Umbraco.Core/Models/IDeepCloneable.cs @@ -1,7 +1,8 @@ -using System.Reflection; - -namespace Umbraco.Core.Models +namespace Umbraco.Core.Models { + /// + /// Provides a mean to deep-clone an object. + /// public interface IDeepCloneable { object DeepClone(); diff --git a/src/Umbraco.Core/Models/IDictionaryItem.cs b/src/Umbraco.Core/Models/IDictionaryItem.cs index b4a1deea89..52b969dc4d 100644 --- a/src/Umbraco.Core/Models/IDictionaryItem.cs +++ b/src/Umbraco.Core/Models/IDictionaryItem.cs @@ -2,11 +2,10 @@ using System.Collections.Generic; using System.Runtime.Serialization; using Umbraco.Core.Models.EntityBase; -using Umbraco.Core.Persistence.Mappers; namespace Umbraco.Core.Models { - public interface IDictionaryItem : IAggregateRoot, IRememberBeingDirty, ICanBeDirty + public interface IDictionaryItem : IEntity, IRememberBeingDirty { /// /// Gets or Sets the Parent Id of the Dictionary Item diff --git a/src/Umbraco.Core/Models/IDomain.cs b/src/Umbraco.Core/Models/IDomain.cs index b33c987f9e..ef95f59ded 100644 --- a/src/Umbraco.Core/Models/IDomain.cs +++ b/src/Umbraco.Core/Models/IDomain.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Models { - public interface IDomain : IAggregateRoot, IRememberBeingDirty, ICanBeDirty + public interface IDomain : IEntity, IRememberBeingDirty { int? LanguageId { get; set; } string DomainName { get; set; } diff --git a/src/Umbraco.Core/Models/IFile.cs b/src/Umbraco.Core/Models/IFile.cs index 77cc21a49b..18dcdcdf80 100644 --- a/src/Umbraco.Core/Models/IFile.cs +++ b/src/Umbraco.Core/Models/IFile.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.Models /// Defines a File /// /// Used for Scripts, Stylesheets and Templates - public interface IFile : IAggregateRoot + public interface IFile : IEntity { /// /// Gets the Name of the File including extension diff --git a/src/Umbraco.Core/Models/ILanguage.cs b/src/Umbraco.Core/Models/ILanguage.cs index 125bebf8e2..2fc82df3a8 100644 --- a/src/Umbraco.Core/Models/ILanguage.cs +++ b/src/Umbraco.Core/Models/ILanguage.cs @@ -1,11 +1,10 @@ using System.Globalization; using System.Runtime.Serialization; using Umbraco.Core.Models.EntityBase; -using Umbraco.Core.Persistence.Mappers; namespace Umbraco.Core.Models { - public interface ILanguage : IAggregateRoot, IRememberBeingDirty, ICanBeDirty + public interface ILanguage : IEntity, IRememberBeingDirty { /// /// Gets or sets the Iso Code for the Language diff --git a/src/Umbraco.Core/Models/IMacro.cs b/src/Umbraco.Core/Models/IMacro.cs index 6aafba0a43..7521b22a48 100644 --- a/src/Umbraco.Core/Models/IMacro.cs +++ b/src/Umbraco.Core/Models/IMacro.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Models /// /// Defines a Macro /// - public interface IMacro : IAggregateRoot, IRememberBeingDirty, ICanBeDirty + public interface IMacro : IEntity, IRememberBeingDirty { /// /// Gets or sets the alias of the Macro diff --git a/src/Umbraco.Core/Models/IMemberGroup.cs b/src/Umbraco.Core/Models/IMemberGroup.cs index 0fcf20acb6..1a3d8a3909 100644 --- a/src/Umbraco.Core/Models/IMemberGroup.cs +++ b/src/Umbraco.Core/Models/IMemberGroup.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Models /// /// Represents a member type /// - public interface IMemberGroup : IAggregateRoot, IRememberBeingDirty, ICanBeDirty + public interface IMemberGroup : IEntity, IRememberBeingDirty { /// /// The name of the member group diff --git a/src/Umbraco.Core/Models/IMigrationEntry.cs b/src/Umbraco.Core/Models/IMigrationEntry.cs index 0cc466f1cb..db820b565e 100644 --- a/src/Umbraco.Core/Models/IMigrationEntry.cs +++ b/src/Umbraco.Core/Models/IMigrationEntry.cs @@ -4,7 +4,7 @@ using Umbraco.Core.Models.EntityBase; namespace Umbraco.Core.Models { - public interface IMigrationEntry : IAggregateRoot, IRememberBeingDirty + public interface IMigrationEntry : IEntity, IRememberBeingDirty { string MigrationName { get; set; } SemVersion Version { get; set; } diff --git a/src/Umbraco.Core/Models/IRedirectUrl.cs b/src/Umbraco.Core/Models/IRedirectUrl.cs index 419389f60d..ed28f16855 100644 --- a/src/Umbraco.Core/Models/IRedirectUrl.cs +++ b/src/Umbraco.Core/Models/IRedirectUrl.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.Models /// /// Represents a redirect url. /// - public interface IRedirectUrl : IAggregateRoot, IRememberBeingDirty + public interface IRedirectUrl : IEntity, IRememberBeingDirty { /// /// Gets or sets the identifier of the content item. diff --git a/src/Umbraco.Core/Models/IRelation.cs b/src/Umbraco.Core/Models/IRelation.cs index a80d6543a2..33aafa4f4e 100644 --- a/src/Umbraco.Core/Models/IRelation.cs +++ b/src/Umbraco.Core/Models/IRelation.cs @@ -3,7 +3,7 @@ using Umbraco.Core.Models.EntityBase; namespace Umbraco.Core.Models { - public interface IRelation : IAggregateRoot, IRememberBeingDirty, ICanBeDirty + public interface IRelation : IEntity, IRememberBeingDirty { /// /// Gets or sets the Parent Id of the Relation (Source) diff --git a/src/Umbraco.Core/Models/IRelationType.cs b/src/Umbraco.Core/Models/IRelationType.cs index 913cee9590..df71fdd541 100644 --- a/src/Umbraco.Core/Models/IRelationType.cs +++ b/src/Umbraco.Core/Models/IRelationType.cs @@ -4,7 +4,7 @@ using Umbraco.Core.Models.EntityBase; namespace Umbraco.Core.Models { - public interface IRelationType : IAggregateRoot, IRememberBeingDirty, ICanBeDirty + public interface IRelationType : IEntity, IRememberBeingDirty { /// /// Gets or sets the Name of the RelationType diff --git a/src/Umbraco.Core/Models/IServerRegistration.cs b/src/Umbraco.Core/Models/IServerRegistration.cs index 20513339d8..df7ad57923 100644 --- a/src/Umbraco.Core/Models/IServerRegistration.cs +++ b/src/Umbraco.Core/Models/IServerRegistration.cs @@ -4,7 +4,7 @@ using Umbraco.Core.Sync; namespace Umbraco.Core.Models { - public interface IServerRegistration : IServerAddress, IAggregateRoot, IRememberBeingDirty + public interface IServerRegistration : IServerAddress, IEntity, IRememberBeingDirty { /// /// Gets or sets the server unique identity. diff --git a/src/Umbraco.Core/Models/ITag.cs b/src/Umbraco.Core/Models/ITag.cs index 2f05527ed9..734a355efe 100644 --- a/src/Umbraco.Core/Models/ITag.cs +++ b/src/Umbraco.Core/Models/ITag.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Models /// /// Represents a Tag, which is composed of a Text, Group and NodeCount property. /// - public interface ITag : IAggregateRoot, IRememberBeingDirty, ICanBeDirty + public interface ITag : IEntity, IRememberBeingDirty { [DataMember] string Text { get; set; } diff --git a/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs b/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs index cfabcb2d64..fb6a4f6a86 100644 --- a/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs +++ b/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs @@ -424,7 +424,7 @@ namespace Umbraco.Core.Models.Identity /// /// internal class used to track changes for properties that have it enabled /// - private class ChangeTracker : TracksChangesEntityBase + private class ChangeTracker : BeingDirtyBase { /// /// Make this public so that it's usable diff --git a/src/Umbraco.Core/Models/Identity/IIdentityUserLogin.cs b/src/Umbraco.Core/Models/Identity/IIdentityUserLogin.cs index d4d8e5e08e..39a3b911a4 100644 --- a/src/Umbraco.Core/Models/Identity/IIdentityUserLogin.cs +++ b/src/Umbraco.Core/Models/Identity/IIdentityUserLogin.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Models.Identity { - public interface IIdentityUserLogin : IAggregateRoot, IRememberBeingDirty, ICanBeDirty + public interface IIdentityUserLogin : IEntity, IRememberBeingDirty { /// /// The login provider for the login (i.e. facebook, google) diff --git a/src/Umbraco.Core/Models/Identity/IdentityUserLogin.cs b/src/Umbraco.Core/Models/Identity/IdentityUserLogin.cs index 89d20bc948..46a9f6186b 100644 --- a/src/Umbraco.Core/Models/Identity/IdentityUserLogin.cs +++ b/src/Umbraco.Core/Models/Identity/IdentityUserLogin.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.Models.Identity /// Entity type for a user's login (i.e. facebook, google) /// /// - public class IdentityUserLogin : Entity, IIdentityUserLogin + public class IdentityUserLogin : EntityBase.EntityBase, IIdentityUserLogin { public IdentityUserLogin(string loginProvider, string providerKey, int userId) { diff --git a/src/Umbraco.Core/Models/Language.cs b/src/Umbraco.Core/Models/Language.cs index 98acd7430b..5cc9d4948e 100644 --- a/src/Umbraco.Core/Models/Language.cs +++ b/src/Umbraco.Core/Models/Language.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class Language : Entity, ILanguage + public class Language : EntityBase.EntityBase, ILanguage { private static readonly Lazy Ps = new Lazy(); diff --git a/src/Umbraco.Core/Models/Macro.cs b/src/Umbraco.Core/Models/Macro.cs index c004e040cc..6ae76505f4 100644 --- a/src/Umbraco.Core/Models/Macro.cs +++ b/src/Umbraco.Core/Models/Macro.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class Macro : Entity, IMacro + public class Macro : EntityBase.EntityBase, IMacro { public Macro() { @@ -181,7 +181,7 @@ namespace Umbraco.Core.Models base.ResetDirtyProperties(rememberDirty); foreach (var prop in Properties) { - ((TracksChangesEntityBase)prop).ResetDirtyProperties(rememberDirty); + ((BeingDirtyBase)prop).ResetDirtyProperties(rememberDirty); } } diff --git a/src/Umbraco.Core/Models/MacroProperty.cs b/src/Umbraco.Core/Models/MacroProperty.cs index 2aba3c05a1..5936344a79 100644 --- a/src/Umbraco.Core/Models/MacroProperty.cs +++ b/src/Umbraco.Core/Models/MacroProperty.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class MacroProperty : TracksChangesEntityBase, IMacroProperty, IRememberBeingDirty, IDeepCloneable + public class MacroProperty : BeingDirtyBase, IMacroProperty, IRememberBeingDirty, IDeepCloneable { public MacroProperty() { @@ -84,7 +84,7 @@ namespace Umbraco.Core.Models public readonly PropertyInfo AliasSelector = ExpressionHelper.GetPropertyInfo(x => x.Alias); public readonly PropertyInfo NameSelector = ExpressionHelper.GetPropertyInfo(x => x.Name); public readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo(x => x.SortOrder); - public readonly PropertyInfo IdSelector = ExpressionHelper.GetPropertyInfo(x => x.Id); + public readonly PropertyInfo IdSelector = ExpressionHelper.GetPropertyInfo(x => x.Id); public readonly PropertyInfo PropertyTypeSelector = ExpressionHelper.GetPropertyInfo(x => x.EditorAlias); } diff --git a/src/Umbraco.Core/Models/MemberGroup.cs b/src/Umbraco.Core/Models/MemberGroup.cs index e7f6355ac2..d1dbedab20 100644 --- a/src/Umbraco.Core/Models/MemberGroup.cs +++ b/src/Umbraco.Core/Models/MemberGroup.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class MemberGroup : Entity, IMemberGroup + public class MemberGroup : EntityBase.EntityBase, IMemberGroup { public MemberGroup() { diff --git a/src/Umbraco.Core/Models/Membership/ContentPermissionSet.cs b/src/Umbraco.Core/Models/Membership/ContentPermissionSet.cs index f55093402b..9eba76a09d 100644 --- a/src/Umbraco.Core/Models/Membership/ContentPermissionSet.cs +++ b/src/Umbraco.Core/Models/Membership/ContentPermissionSet.cs @@ -10,7 +10,7 @@ namespace Umbraco.Core.Models.Membership /// /// This implements purely so it can be used with the repository layer which is why it's explicitly implemented. /// - public class ContentPermissionSet : EntityPermissionSet, IAggregateRoot + public class ContentPermissionSet : EntityPermissionSet, IEntity { private readonly IContent _content; @@ -43,7 +43,7 @@ namespace Umbraco.Core.Models.Membership DateTime IEntity.UpdateDate { get; set; } - DateTime? IDeletableEntity.DeletedDate { get; set; } + DateTime? IEntity.DeleteDate { get; set; } object IDeepCloneable.DeepClone() { diff --git a/src/Umbraco.Core/Models/Membership/IMembershipUser.cs b/src/Umbraco.Core/Models/Membership/IMembershipUser.cs index 5a63997795..15ce8bae46 100644 --- a/src/Umbraco.Core/Models/Membership/IMembershipUser.cs +++ b/src/Umbraco.Core/Models/Membership/IMembershipUser.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Models.Membership /// /// Defines the base contract for and /// - public interface IMembershipUser : IAggregateRoot + public interface IMembershipUser : IEntity { object ProviderUserKey { get; set; } string Username { get; set; } diff --git a/src/Umbraco.Core/Models/Membership/IUserGroup.cs b/src/Umbraco.Core/Models/Membership/IUserGroup.cs index 0551fcc8a8..7b27657d09 100644 --- a/src/Umbraco.Core/Models/Membership/IUserGroup.cs +++ b/src/Umbraco.Core/Models/Membership/IUserGroup.cs @@ -3,7 +3,7 @@ using Umbraco.Core.Models.EntityBase; namespace Umbraco.Core.Models.Membership { - public interface IUserGroup : IAggregateRoot + public interface IUserGroup : IEntity { string Alias { get; set; } diff --git a/src/Umbraco.Core/Models/Membership/IUserType.cs b/src/Umbraco.Core/Models/Membership/IUserType.cs index 6d97a0b206..084e0b6c7f 100644 --- a/src/Umbraco.Core/Models/Membership/IUserType.cs +++ b/src/Umbraco.Core/Models/Membership/IUserType.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.Models.Membership { [Obsolete("This should not be used it exists for legacy reasons only, use user groups instead, it will be removed in future versions")] [EditorBrowsable(EditorBrowsableState.Never)] - public interface IUserType : IAggregateRoot + public interface IUserType : IEntity { string Alias { get; set; } string Name { get; set; } diff --git a/src/Umbraco.Core/Models/Membership/User.cs b/src/Umbraco.Core/Models/Membership/User.cs index 9ad1c87108..2d2375cc85 100644 --- a/src/Umbraco.Core/Models/Membership/User.cs +++ b/src/Umbraco.Core/Models/Membership/User.cs @@ -18,7 +18,7 @@ namespace Umbraco.Core.Models.Membership /// [Serializable] [DataContract(IsReference = true)] - public class User : Entity, IUser, IProfile + public class User : EntityBase.EntityBase, IUser, IProfile { /// /// Constructor for creating a new/empty user @@ -321,7 +321,7 @@ namespace Umbraco.Core.Models.Membership Id = realGroup.Id, Key = realGroup.Key, CreateDate = realGroup.CreateDate, - DeletedDate = realGroup.DeletedDate, + DeletedDate = realGroup.DeleteDate, Name = realGroup.Name, Permissions = realGroup.Permissions, UpdateDate = realGroup.UpdateDate @@ -338,7 +338,7 @@ namespace Umbraco.Core.Models.Membership Id = realGroup.Id, Key = realGroup.Key, CreateDate = realGroup.CreateDate, - DeletedDate = realGroup.DeletedDate, + DeletedDate = realGroup.DeleteDate, Name = realGroup.Name, Permissions = realGroup.Permissions, UpdateDate = realGroup.UpdateDate diff --git a/src/Umbraco.Core/Models/Membership/UserGroup.cs b/src/Umbraco.Core/Models/Membership/UserGroup.cs index dc91862e77..cd9e993bce 100644 --- a/src/Umbraco.Core/Models/Membership/UserGroup.cs +++ b/src/Umbraco.Core/Models/Membership/UserGroup.cs @@ -12,7 +12,7 @@ namespace Umbraco.Core.Models.Membership /// [Serializable] [DataContract(IsReference = true)] - internal class UserGroup : Entity, IUserGroup, IReadOnlyUserGroup + internal class UserGroup : EntityBase.EntityBase, IUserGroup, IReadOnlyUserGroup { private int? _startContentId; private int? _startMediaId; diff --git a/src/Umbraco.Core/Models/Membership/UserType.cs b/src/Umbraco.Core/Models/Membership/UserType.cs index 1b8d71f4c0..1f80d0f4b3 100644 --- a/src/Umbraco.Core/Models/Membership/UserType.cs +++ b/src/Umbraco.Core/Models/Membership/UserType.cs @@ -12,7 +12,7 @@ namespace Umbraco.Core.Models.Membership [EditorBrowsable(EditorBrowsableState.Never)] [Serializable] [DataContract(IsReference = true)] - internal class UserType : Entity, IUserType + internal class UserType : EntityBase.EntityBase, IUserType { private string _alias; private string _name; diff --git a/src/Umbraco.Core/Models/MigrationEntry.cs b/src/Umbraco.Core/Models/MigrationEntry.cs index f3f696fd71..9407be8950 100644 --- a/src/Umbraco.Core/Models/MigrationEntry.cs +++ b/src/Umbraco.Core/Models/MigrationEntry.cs @@ -5,7 +5,7 @@ using Umbraco.Core.Models.EntityBase; namespace Umbraco.Core.Models { - public class MigrationEntry : Entity, IMigrationEntry + public class MigrationEntry : EntityBase.EntityBase, IMigrationEntry { public MigrationEntry() { diff --git a/src/Umbraco.Core/Models/Packaging/InstallationSummary.cs b/src/Umbraco.Core/Models/Packaging/InstallationSummary.cs index 4ba6a7a1c7..3eb397d728 100644 --- a/src/Umbraco.Core/Models/Packaging/InstallationSummary.cs +++ b/src/Umbraco.Core/Models/Packaging/InstallationSummary.cs @@ -9,7 +9,7 @@ namespace Umbraco.Core.Models.Packaging public class InstallationSummary { public MetaData MetaData { get; set; } - public IEnumerable DataTypesInstalled { get; set; } + public IEnumerable DataTypesInstalled { get; set; } public IEnumerable LanguagesInstalled { get; set; } public IEnumerable DictionaryItemsInstalled { get; set; } public IEnumerable MacrosInstalled { get; set; } @@ -29,7 +29,7 @@ namespace Umbraco.Core.Models.Packaging summary.Actions = new List(); summary.ContentInstalled = new List(); summary.ContentTypesInstalled = new List(); - summary.DataTypesInstalled = new List(); + summary.DataTypesInstalled = new List(); summary.DictionaryItemsInstalled = new List(); summary.FilesInstalled = new List(); summary.LanguagesInstalled = new List(); diff --git a/src/Umbraco.Core/Models/Property.cs b/src/Umbraco.Core/Models/Property.cs index 0d8ab300c8..365247669c 100644 --- a/src/Umbraco.Core/Models/Property.cs +++ b/src/Umbraco.Core/Models/Property.cs @@ -14,7 +14,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class Property : Entity + public class Property : EntityBase.EntityBase { private List _tagChanges; diff --git a/src/Umbraco.Core/Models/PropertyGroup.cs b/src/Umbraco.Core/Models/PropertyGroup.cs index fbec228201..a458edb387 100644 --- a/src/Umbraco.Core/Models/PropertyGroup.cs +++ b/src/Umbraco.Core/Models/PropertyGroup.cs @@ -13,7 +13,7 @@ namespace Umbraco.Core.Models [Serializable] [DataContract(IsReference = true)] [DebuggerDisplay("Id: {Id}, Name: {Name}")] - public class PropertyGroup : Entity, IEquatable + public class PropertyGroup : EntityBase.EntityBase, IEquatable { private static readonly Lazy Ps = new Lazy(); diff --git a/src/Umbraco.Core/Models/PropertyType.cs b/src/Umbraco.Core/Models/PropertyType.cs index cd5ac63bd3..515a7086ea 100644 --- a/src/Umbraco.Core/Models/PropertyType.cs +++ b/src/Umbraco.Core/Models/PropertyType.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.Models [Serializable] [DataContract(IsReference = true)] [DebuggerDisplay("Id: {Id}, Name: {Name}, Alias: {Alias}")] - public class PropertyType : Entity, IEquatable + public class PropertyType : EntityBase.EntityBase, IEquatable { private static readonly Lazy Ps = new Lazy(); @@ -33,20 +33,20 @@ namespace Umbraco.Core.Models private string _validationRegExp; private ContentVariation _variations; - public PropertyType(IDataTypeDefinition dataTypeDefinition) + public PropertyType(IDataType dataType) { - if (dataTypeDefinition == null) throw new ArgumentNullException("dataTypeDefinition"); + if (dataType == null) throw new ArgumentNullException("dataType"); - if(dataTypeDefinition.HasIdentity) - _dataTypeDefinitionId = dataTypeDefinition.Id; + if(dataType.HasIdentity) + _dataTypeDefinitionId = dataType.Id; - _propertyEditorAlias = dataTypeDefinition.PropertyEditorAlias; - _dataTypeDatabaseType = dataTypeDefinition.DatabaseType; + _propertyEditorAlias = dataType.EditorAlias; + _dataTypeDatabaseType = dataType.DatabaseType; _variations = ContentVariation.InvariantNeutral; } - public PropertyType(IDataTypeDefinition dataTypeDefinition, string propertyTypeAlias) - : this(dataTypeDefinition) + public PropertyType(IDataType dataType, string propertyTypeAlias) + : this(dataType) { _alias = GetAlias(propertyTypeAlias); } @@ -141,7 +141,7 @@ namespace Umbraco.Core.Models /// /// Gets of Sets the Id of the DataType (Definition), which the PropertyType is "wrapping" /// - /// This is actually the Id of the + /// This is actually the Id of the [DataMember] public int DataTypeDefinitionId { diff --git a/src/Umbraco.Core/Models/PublicAccessEntry.cs b/src/Umbraco.Core/Models/PublicAccessEntry.cs index d4b0bc8a3b..0b04bc9782 100644 --- a/src/Umbraco.Core/Models/PublicAccessEntry.cs +++ b/src/Umbraco.Core/Models/PublicAccessEntry.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Models { [Serializable] [DataContract(IsReference = true)] - public class PublicAccessEntry : Entity, IAggregateRoot + public class PublicAccessEntry : EntityBase.EntityBase { private readonly ObservableCollection _ruleCollection; private int _protectedNodeId; diff --git a/src/Umbraco.Core/Models/PublicAccessRule.cs b/src/Umbraco.Core/Models/PublicAccessRule.cs index fe7c4c5e4f..cc21e7a27a 100644 --- a/src/Umbraco.Core/Models/PublicAccessRule.cs +++ b/src/Umbraco.Core/Models/PublicAccessRule.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.Models { [Serializable] [DataContract(IsReference = true)] - public class PublicAccessRule : Entity + public class PublicAccessRule : EntityBase.EntityBase { private string _ruleValue; private string _ruleType; diff --git a/src/Umbraco.Core/Models/PublishedContent/DataTypeConfigurationSource.cs b/src/Umbraco.Core/Models/PublishedContent/DataTypeConfigurationSource.cs index 94a1499ff0..45936de1bf 100644 --- a/src/Umbraco.Core/Models/PublishedContent/DataTypeConfigurationSource.cs +++ b/src/Umbraco.Core/Models/PublishedContent/DataTypeConfigurationSource.cs @@ -27,6 +27,16 @@ namespace Umbraco.Core.Models.PublishedContent /// public object GetDataTypeConfiguration(string editorAlias, int id) { + // fixme - this should all be in IDataTypeService + // + // get data type by id / with -or without- configuration + // configuration should just be 1 json field + // could be in uNodeData? + // then, there is no 'get configuration' at all + // + // and then, could be + // if we consider that the published snapshot service in NuCache does a getall + // fixme - we need a more efficient dataTypeService way of getting these // fixme - would be nice not to pass editorAlias but annoying for tests? //var datatype = _dataTypeService.GetDataTypeDefinitionById(id); diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentTypeFactory.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentTypeFactory.cs index a24923400c..83d4cca078 100644 --- a/src/Umbraco.Core/Models/PublishedContent/IPublishedContentTypeFactory.cs +++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedContentTypeFactory.cs @@ -1,4 +1,4 @@ -namespace Umbraco.Core.Models.PublishedContent +namespace Umbraco. Core.Models.PublishedContent { /// /// Creates published content types. @@ -8,26 +8,28 @@ /// /// Creates a published content type. /// - /// The item type. /// An content type. /// A published content type corresponding to the item type and content type. - PublishedContentType CreateContentType(PublishedItemType itemType, IContentTypeComposition contentType); - // fixme could we derive itemType from contentType? + PublishedContentType CreateContentType(IContentTypeComposition contentType); /// /// Creates a published property type. /// /// The published content type owning the property. /// A property type. - /// A published property type corresponding to the property type and owned by the published content type. + /// Is used by constructor to create property types. PublishedPropertyType CreatePropertyType(PublishedContentType contentType, PropertyType propertyType); /// /// Creates a published property type. /// - /// A value indicating whether the property is created by Umbraco. - /// fixme xplain. - PublishedPropertyType CreatePropertyType(string propertyTypeAlias, int dataTypeId, string editorAlias, bool umbraco = false); + /// The published content type owning the property. + /// The property type alias. + /// The datatype identifier. + /// The property editor alias. FIXME derive from dataTypeId? + /// The variations. + /// Is used by constructor to create special property types. + PublishedPropertyType CreatePropertyType(PublishedContentType contentType, string propertyTypeAlias, int dataTypeId, string propertyEditorAlias, ContentVariation variations); /// /// Creates a published data type. diff --git a/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs b/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs index 1fd9cda069..24c654604c 100644 --- a/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs +++ b/src/Umbraco.Core/Models/PublishedContent/IPublishedProperty.cs @@ -8,7 +8,7 @@ /// /// Gets the alias of the property. /// - string PropertyTypeAlias { get; } + string Alias { get; } /// /// Gets a value indicating whether the property has a value. diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs index 8407c7f4dc..3645835170 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentType.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Umbraco.Core.Composing; namespace Umbraco.Core.Models.PublishedContent { @@ -15,82 +14,51 @@ namespace Umbraco.Core.Models.PublishedContent private readonly PublishedPropertyType[] _propertyTypes; // fast alias-to-index xref containing both the raw alias and its lowercase version - // fixme - benchmark this! private readonly Dictionary _indexes = new Dictionary(); - // fixme used in legacy page.cs that should die - internal PublishedContentType(IContentType contentType) - : this(PublishedItemType.Content, contentType, new CurrentPublishedContentTypeFactory()) - { } - - // fixme above and should die - private class CurrentPublishedContentTypeFactory : IPublishedContentTypeFactory - { - public PublishedContentType CreateContentType(PublishedItemType itemType, IContentTypeComposition contentType) - { - return new PublishedContentType(itemType, contentType, this); - } - - public PublishedPropertyType CreatePropertyType(PublishedContentType contentType, PropertyType propertyType) - { - return new PublishedPropertyType(contentType, propertyType, Current.PublishedModelFactory, Current.PropertyValueConverters, this); - } - - public PublishedPropertyType CreatePropertyType(string propertyTypeAlias, int dataTypeId, string editorAlias, bool umbraco = false) - { - return new PublishedPropertyType(propertyTypeAlias, dataTypeId, editorAlias, umbraco, Current.PublishedModelFactory, Current.PropertyValueConverters, this); - } - - public PublishedDataType CreateDataType(int id, string editorAlias) - { - return new PublishedDataType(id, editorAlias, new DataTypeConfigurationSource(Current.Services.DataTypeService, Current.PropertyEditors)); - } - } - - // this is the main and only true ctor - internal PublishedContentType(PublishedItemType itemType, IContentTypeComposition contentType, IPublishedContentTypeFactory factory) - : this(contentType.Id, contentType.Alias, itemType, contentType.CompositionAliases()) + /// + /// Initializes a new instance of the class with a content type. + /// + public PublishedContentType(IContentTypeComposition contentType, IPublishedContentTypeFactory factory) + : this(contentType.Id, contentType.Alias, contentType.GetItemType(), contentType.CompositionAliases(), contentType.Variations) { var propertyTypes = contentType.CompositionPropertyTypes - .Select(x => factory.CreatePropertyType(this, x)); + .Select(x => factory.CreatePropertyType(this, x)) + .ToList(); + + if (ItemType == PublishedItemType.Member) + EnsureMemberProperties(propertyTypes, factory); - if (itemType == PublishedItemType.Member) - propertyTypes = WithMemberProperties(this, propertyTypes, factory); _propertyTypes = propertyTypes.ToArray(); InitializeIndexes(); } - private PublishedContentType(int id, string alias, PublishedItemType itemType, IEnumerable compositionAliases) + /// + /// Initializes a new instance of the with specific values. + /// + /// + /// This constructor is for tests and is not intended to be used directly from application code. + /// Values are assumed to be consisted and are not checked. + /// + public PublishedContentType(int id, string alias, PublishedItemType itemType, IEnumerable compositionAliases, IEnumerable propertyTypes, ContentVariation variations) + : this (id, alias, itemType, compositionAliases, variations) + { + var propertyTypesA = propertyTypes.ToArray(); + foreach (var propertyType in propertyTypesA) + propertyType.ContentType = this; + _propertyTypes = propertyTypesA; + + InitializeIndexes(); + } + + private PublishedContentType(int id, string alias, PublishedItemType itemType, IEnumerable compositionAliases, ContentVariation variations) { Id = id; Alias = alias; ItemType = itemType; CompositionAliases = new HashSet(compositionAliases, StringComparer.InvariantCultureIgnoreCase); - } - - // internal so it can be used for unit tests - internal PublishedContentType(int id, string alias, IEnumerable propertyTypes, IPublishedContentTypeFactory factory) - : this(id, alias, PublishedItemType.Content, Enumerable.Empty(), propertyTypes, factory) - { } - - // internal so it can be used for unit tests - internal PublishedContentType(int id, string alias, IEnumerable compositionAliases, IEnumerable propertyTypes, IPublishedContentTypeFactory factory) - : this(id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, factory) - { } - - private PublishedContentType(int id, string alias, PublishedItemType itemType, IEnumerable compositionAliases, IEnumerable propertyTypes, IPublishedContentTypeFactory factory) - : this (id, alias, itemType, compositionAliases) - { - var propertyTypesA = propertyTypes.ToArray(); - foreach (var propertyType in propertyTypesA) - propertyType.ContentType = this; - - if (itemType == PublishedItemType.Member) - propertyTypesA = WithMemberProperties(this, propertyTypesA, factory).ToArray(); - _propertyTypes = propertyTypesA; - - InitializeIndexes(); + Variations = variations; } private void InitializeIndexes() @@ -98,66 +66,80 @@ namespace Umbraco.Core.Models.PublishedContent for (var i = 0; i < _propertyTypes.Length; i++) { var propertyType = _propertyTypes[i]; - _indexes[propertyType.PropertyTypeAlias] = i; - _indexes[propertyType.PropertyTypeAlias.ToLowerInvariant()] = i; + _indexes[propertyType.Alias] = i; + _indexes[propertyType.Alias.ToLowerInvariant()] = i; } } - // NOTE: code below defines and add custom, built-in, Umbraco properties for members - // unless they are already user-defined in the content type, then they are skipped - // not sure it's needed really - this is here for safety purposes - private static readonly Dictionary> BuiltinMemberProperties = new Dictionary> + // Members have properties such as IMember LastLoginDate which are plain C# properties and not content + // properties; they are exposed as pseudo content properties, as long as a content property with the + // same alias does not exist already. + private void EnsureMemberProperties(List propertyTypes, IPublishedContentTypeFactory factory) { - // see also PublishedMember class - exposing special properties as properties - { "Email", Tuple.Create(Constants.DataTypes.Textbox, Constants.PropertyEditors.TextboxAlias) }, - { "Username", Tuple.Create(Constants.DataTypes.Textbox, Constants.PropertyEditors.TextboxAlias) }, - { "PasswordQuestion", Tuple.Create(Constants.DataTypes.Textbox, Constants.PropertyEditors.TextboxAlias) }, - { "Comments", Tuple.Create(Constants.DataTypes.Textbox, Constants.PropertyEditors.TextboxAlias) }, - { "IsApproved", Tuple.Create(Constants.DataTypes.Boolean, Constants.PropertyEditors.BooleanAlias) }, - { "IsLockedOut", Tuple.Create(Constants.DataTypes.Boolean, Constants.PropertyEditors.BooleanAlias) }, - { "LastLockoutDate", Tuple.Create(Constants.DataTypes.Datetime, Constants.PropertyEditors.DateTimeAlias) }, - { "CreateDate", Tuple.Create(Constants.DataTypes.Datetime, Constants.PropertyEditors.DateTimeAlias) }, - { "LastLoginDate", Tuple.Create(Constants.DataTypes.Datetime, Constants.PropertyEditors.DateTimeAlias) }, - { "LastPasswordChangeDate", Tuple.Create(Constants.DataTypes.Datetime, Constants.PropertyEditors.DateTimeAlias) }, + var aliases = new HashSet(propertyTypes.Select(x => x.Alias), StringComparer.OrdinalIgnoreCase); + + foreach ((var alias, (var dataTypeId, var editorAlias)) in BuiltinMemberProperties) + { + if (aliases.Contains(alias)) continue; + propertyTypes.Add(factory.CreatePropertyType(this, alias, dataTypeId, editorAlias, ContentVariation.InvariantNeutral)); + } + } + + // fixme - this list somehow also exists in constants, see memberTypeRepository => remove duplicate! + private static readonly Dictionary BuiltinMemberProperties = new Dictionary + { + { "Email", (Constants.DataTypes.Textbox, Constants.PropertyEditors.TextboxAlias) }, + { "Username", (Constants.DataTypes.Textbox, Constants.PropertyEditors.TextboxAlias) }, + { "PasswordQuestion", (Constants.DataTypes.Textbox, Constants.PropertyEditors.TextboxAlias) }, + { "Comments", (Constants.DataTypes.Textbox, Constants.PropertyEditors.TextboxAlias) }, + { "IsApproved", (Constants.DataTypes.Boolean, Constants.PropertyEditors.BooleanAlias) }, + { "IsLockedOut", (Constants.DataTypes.Boolean, Constants.PropertyEditors.BooleanAlias) }, + { "LastLockoutDate", (Constants.DataTypes.Datetime, Constants.PropertyEditors.DateTimeAlias) }, + { "CreateDate", (Constants.DataTypes.Datetime, Constants.PropertyEditors.DateTimeAlias) }, + { "LastLoginDate", (Constants.DataTypes.Datetime, Constants.PropertyEditors.DateTimeAlias) }, + { "LastPasswordChangeDate", (Constants.DataTypes.Datetime, Constants.PropertyEditors.DateTimeAlias) }, }; - private static IEnumerable WithMemberProperties(PublishedContentType contentType, IEnumerable propertyTypes, IPublishedContentTypeFactory factory) - { - var aliases = new HashSet(StringComparer.OrdinalIgnoreCase); - foreach (var propertyType in propertyTypes) - { - aliases.Add(propertyType.PropertyTypeAlias); - yield return propertyType; - } - - foreach (var propertyType in BuiltinMemberProperties - .Where(kvp => aliases.Contains(kvp.Key) == false) - .Select(kvp => factory.CreatePropertyType(kvp.Key, kvp.Value.Item1, kvp.Value.Item2, umbraco: true))) - { - // fixme why would it be null? - if (contentType != null) propertyType.ContentType = contentType; - yield return propertyType; - } - } - #region Content type + /// + /// Gets the content type identifier. + /// public int Id { get; } + /// + /// Gets the content type alias. + /// public string Alias { get; } + /// + /// Gets the content item type. + /// public PublishedItemType ItemType { get; } + /// + /// Gets the aliases of the content types participating in the composition. + /// public HashSet CompositionAliases { get; } + /// + /// Gets the content variations of the content type. + /// + public ContentVariation Variations { get; } + #endregion #region Properties + /// + /// Gets the content type properties. + /// public IEnumerable PropertyTypes => _propertyTypes; - // alias is case-insensitive - // this is the ONLY place where we compare ALIASES! + /// + /// Gets a property type index. + /// + /// The alias is case-insensitive. This is the only place where alias strings are compared. public int GetPropertyIndex(string alias) { if (_indexes.TryGetValue(alias, out var index)) return index; // fastest @@ -165,14 +147,20 @@ namespace Umbraco.Core.Models.PublishedContent return -1; } - // virtual for unit tests + // virtual for unit tests - fixme explain + /// + /// Gets a property type. + /// public virtual PublishedPropertyType GetPropertyType(string alias) { var index = GetPropertyIndex(alias); return GetPropertyType(index); } - // virtual for unit tests + // virtual for unit tests - fixme explain + /// + /// Gets a property type. + /// public virtual PublishedPropertyType GetPropertyType(int index) { return index >= 0 && index < _propertyTypes.Length ? _propertyTypes[index] : null; diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs index 1394ba4387..5a4214eab0 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedContentTypeFactory.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using Umbraco.Core.PropertyEditors; namespace Umbraco.Core.Models.PublishedContent @@ -20,33 +21,39 @@ namespace Umbraco.Core.Models.PublishedContent } /// - public PublishedContentType CreateContentType(PublishedItemType itemType, IContentTypeComposition contentType) + public PublishedContentType CreateContentType(IContentTypeComposition contentType) { - return new PublishedContentType(itemType, contentType, this); + return new PublishedContentType(contentType, this); } - // for tests - internal PublishedContentType CreateContentType(int id, string alias, IEnumerable propertyTypes) + // for tests - fixme what's the point of the factory here? + internal PublishedContentType CreateContentType(int id, string alias, IEnumerable propertyTypes, ContentVariation variations = ContentVariation.InvariantNeutral) { - return new PublishedContentType(id, alias, propertyTypes, this); + return new PublishedContentType(id, alias, PublishedItemType.Content, Enumerable.Empty(), propertyTypes, variations); } - // for tests - internal PublishedContentType CreateContentType(int id, string alias, IEnumerable compositionAliases, IEnumerable propertyTypes) + // for tests - fixme what's the point of the factory here? + internal PublishedContentType CreateContentType(int id, string alias, IEnumerable compositionAliases, IEnumerable propertyTypes, ContentVariation variations = ContentVariation.InvariantNeutral) { - return new PublishedContentType(id, alias, compositionAliases, propertyTypes, this); + return new PublishedContentType(id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, variations); } /// public PublishedPropertyType CreatePropertyType(PublishedContentType contentType, PropertyType propertyType) { - return new PublishedPropertyType(contentType, propertyType, _publishedModelFactory, _propertyValueConverters, this); + return new PublishedPropertyType(contentType, propertyType, _propertyValueConverters, _publishedModelFactory, this); } /// - public PublishedPropertyType CreatePropertyType(string propertyTypeAlias, int dataTypeId, string editorAlias, bool umbraco = false) + public PublishedPropertyType CreatePropertyType(PublishedContentType contentType, string propertyTypeAlias, int dataTypeId, string propertyEditorAlias, ContentVariation variations = ContentVariation.InvariantNeutral) { - return new PublishedPropertyType(propertyTypeAlias, dataTypeId, editorAlias, umbraco, _publishedModelFactory, _propertyValueConverters, this); + return new PublishedPropertyType(contentType, propertyTypeAlias, dataTypeId, propertyEditorAlias, true, variations, _propertyValueConverters, _publishedModelFactory, this); + } + + // for tests + internal PublishedPropertyType CreatePropertyType(string propertyTypeAlias, int dataTypeId, string propertyEditorAlias, bool umbraco = false, ContentVariation variations = ContentVariation.InvariantNeutral) + { + return new PublishedPropertyType(propertyTypeAlias, dataTypeId, propertyEditorAlias, umbraco, variations, _propertyValueConverters, _publishedModelFactory, this); } /// diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedDataType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedDataType.cs index 3e0eb4633e..a6cdc81bba 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedDataType.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedDataType.cs @@ -43,7 +43,7 @@ namespace Umbraco.Core.Models.PublishedContent => _configuration ?? (_configuration = _dataTypeConfigurationSource.GetDataTypeConfiguration(EditorAlias, Id)); /// - /// Gets the data type configuration. + /// Gets the data type typed configuration. /// /// The type of the configuration object. /// The data type configuration. diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs index 34b2ba9495..918bdb86e4 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyBase.cs @@ -9,6 +9,9 @@ namespace Umbraco.Core.Models.PublishedContent /// internal abstract class PublishedPropertyBase : IPublishedProperty { + /// + /// Initializes a new instance of the class. + /// protected PublishedPropertyBase(PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel) { PropertyType = propertyType ?? throw new ArgumentNullException(nameof(propertyType)); @@ -18,6 +21,7 @@ namespace Umbraco.Core.Models.PublishedContent ValidateCacheLevel(PropertyType.CacheLevel, false); } + // validates the cache level private static void ValidateCacheLevel(PropertyCacheLevel cacheLevel, bool validateUnknown) { switch (cacheLevel) @@ -35,14 +39,29 @@ namespace Umbraco.Core.Models.PublishedContent } } + /// + /// Gets the property type. + /// public PublishedPropertyType PropertyType { get; } - public string PropertyTypeAlias => PropertyType.PropertyTypeAlias; + + /// + /// Gets the property reference cache level. + /// public PropertyCacheLevel ReferenceCacheLevel { get; } - // these have to be provided by the actual implementation + /// + public string Alias => PropertyType.Alias; + + /// public abstract bool HasValue(int? languageId = null, string segment = null); + + /// public abstract object GetSourceValue(int? languageId = null, string segment = null); + + /// public abstract object GetValue(int? languageId = null, string segment = null); + + /// public abstract object GetXPathValue(int? languageId = null, string segment = null); } } diff --git a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs index 4329f982c3..0574ff2728 100644 --- a/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs +++ b/src/Umbraco.Core/Models/PublishedContent/PublishedPropertyType.cs @@ -24,46 +24,51 @@ namespace Umbraco.Core.Models.PublishedContent #region Constructors - // the first ctor is the default one, used in PublishedContentType to create the property types - // the second ctor is the test ctor, - // some parameters are optional, and they are all assumed to be valid and consistent - /// - /// Initialize a new instance of the class within a , - /// and with a . + /// Initialize a new instance of the class with a property type. /// - /// The new published property type belongs to the published content type and corresponds to the property type. - public PublishedPropertyType(PublishedContentType contentType, PropertyType propertyType, IPublishedModelFactory publishedModelFactory, PropertyValueConverterCollection propertyValueConverters, IPublishedContentTypeFactory factory) - : this(propertyType.Alias, propertyType.DataTypeDefinitionId, propertyType.PropertyEditorAlias, false, publishedModelFactory, propertyValueConverters, factory) + /// + /// The new published property type belongs to the published content type. + /// + public PublishedPropertyType(PublishedContentType contentType, PropertyType propertyType, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory) + : this(propertyType.Alias, propertyType.DataTypeDefinitionId, propertyType.PropertyEditorAlias, true, propertyType.Variations, propertyValueConverters, publishedModelFactory, factory) { - // PropertyEditor [1:n] DataTypeDefinition [1:n] PropertyType - ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class with specific values. /// /// - /// The new published property type does not belong to a published content type. fixme should they? - /// The values of parameters are assumed to be valid and consistent. - /// + /// This constructor is for tests and is not intended to be used directly from application code. + /// Values are assumed to be consisted and are not checked. + /// The new published property type belongs to the published content type. /// - internal PublishedPropertyType(string propertyTypeAlias, int dataTypeId, string editorAlias, bool umbraco, IPublishedModelFactory publishedModelFactory, PropertyValueConverterCollection propertyValueConverters, IPublishedContentTypeFactory factory) + public PublishedPropertyType(PublishedContentType contentType, string propertyTypeAlias, int dataTypeId, string editorAlias, bool isUserProperty, ContentVariation variations, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory) + : this(propertyTypeAlias, dataTypeId, editorAlias, isUserProperty, variations, propertyValueConverters, publishedModelFactory, factory) { - // ContentType - // - in unit tests, to be set by PublishedContentType when creating it + ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType)); + } + /// + /// Initializes a new instance of the class with specific values. + /// + /// + /// This constructor is for tests and is not intended to be used directly from application code. + /// Values are assumed to be consisted and are not checked. + /// The new published property type does not belong to a published content type. + /// + public PublishedPropertyType(string propertyTypeAlias, int dataTypeId, string editorAlias, bool isUserProperty, ContentVariation variations, PropertyValueConverterCollection propertyValueConverters, IPublishedModelFactory publishedModelFactory, IPublishedContentTypeFactory factory) + { _publishedModelFactory = publishedModelFactory ?? throw new ArgumentNullException(nameof(publishedModelFactory)); _propertyValueConverters = propertyValueConverters ?? throw new ArgumentNullException(nameof(propertyValueConverters)); - PropertyTypeAlias = propertyTypeAlias; + Alias = propertyTypeAlias; - DataTypeId = dataTypeId; - PropertyEditorAlias = editorAlias; - IsUmbraco = umbraco; + IsUserProperty = isUserProperty; + Variations = variations; - DataType = factory.CreateDataType(DataTypeId, PropertyEditorAlias); + DataType = factory.CreateDataType(dataTypeId, editorAlias); } #endregion @@ -72,34 +77,36 @@ namespace Umbraco.Core.Models.PublishedContent /// /// Gets the published content type containing the property type. - /// - // internally set by PublishedContentType constructor - public PublishedContentType ContentType { get; internal set; } + /// + public PublishedContentType ContentType { get; internal set; } // internally set by PublishedContentType constructor /// - /// Gets the data type of the property. + /// Gets the data type. /// public PublishedDataType DataType { get; } /// - /// Gets the alias uniquely identifying the property type. + /// Gets property type alias. /// - public string PropertyTypeAlias { get; } // fixme - should be .ContentType.?? + public string Alias { get; } /// - /// Gets the identifier uniquely identifying the data type supporting the property type. + /// Gets the property editor alias. /// - public int DataTypeId { get; } // fixme - should be .DataType.Id + public string EditorAlias => DataType.EditorAlias; /// - /// Gets the alias uniquely identifying the property editor for the property type. + /// Gets a value indicating whether the property is a user content property. /// - public string PropertyEditorAlias { get; } // fixme - should be .DataType.EditorAlias + /// A non-user content property is a property that has been added to a + /// published content type by Umbraco but does not corresponds to a user-defined + /// published property. + public bool IsUserProperty { get; } /// - /// Gets a value indicating whether the property is an Umbraco-defined property. + /// Gets the content variations of the property type. /// - internal bool IsUmbraco { get; } + public ContentVariation Variations { get; } #endregion @@ -123,7 +130,7 @@ namespace Umbraco.Core.Models.PublishedContent foreach (var converter in _propertyValueConverters) { - if (converter.IsConverter(this) == false) + if (!converter.IsConverter(this)) continue; if (_converter == null) @@ -153,7 +160,7 @@ namespace Umbraco.Core.Models.PublishedContent throw new InvalidOperationException(string.Format("Type '{2}' cannot be an IPropertyValueConverter" + " for property '{1}' of content type '{0}' because type '{3}' has already been detected as a converter" + " for that property, and only one converter can exist for a property.", - ContentType.Alias, PropertyTypeAlias, + ContentType.Alias, Alias, converter.GetType().FullName, _converter.GetType().FullName)); } } @@ -176,7 +183,7 @@ namespace Umbraco.Core.Models.PublishedContent throw new InvalidOperationException(string.Format("Type '{2}' cannot be an IPropertyValueConverter" + " for property '{1}' of content type '{0}' because type '{3}' has already been detected as a converter" + " for that property, and only one converter can exist for a property.", - ContentType.Alias, PropertyTypeAlias, + ContentType.Alias, Alias, converter.GetType().FullName, _converter.GetType().FullName)); } } diff --git a/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs b/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs index d81a8962dc..f938880060 100644 --- a/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs +++ b/src/Umbraco.Core/Models/PublishedContent/RawValueProperty.cs @@ -5,30 +5,45 @@ namespace Umbraco.Core.Models.PublishedContent { /// /// - /// A published property base that uses a raw object value. + /// Represents a published property that has a unique invariant-neutral value + /// and caches conversion results locally. /// - /// Conversions results are stored within the property and will not - /// be refreshed, so this class is not suitable for cached properties. + /// + /// Conversions results are stored within the property and will not + /// be refreshed, so this class is not suitable for cached properties. + /// Does not support variations: the ctor throws if the property type + /// supports variations. + /// internal class RawValueProperty : PublishedPropertyBase { - private readonly object _propertyData; //the value in the db + private readonly object _sourceValue; //the value in the db private readonly Lazy _objectValue; private readonly Lazy _xpathValue; - public override object GetSourceValue(int? languageId = null, string segment = null) => _propertyData; + public override object GetSourceValue(int? languageId = null, string segment = null) + => languageId == null & segment == null ? _sourceValue : null; - public override bool HasValue(int? languageId = null, string segment = null) => _propertyData is string s ? !string.IsNullOrWhiteSpace(s) : _propertyData != null; + public override bool HasValue(int? languageId = null, string segment = null) + { + var sourceValue = GetSourceValue(languageId, segment); + return sourceValue is string s ? !string.IsNullOrWhiteSpace(s) : sourceValue != null; + } - public override object GetValue(int? languageId = null, string segment = null) => _objectValue.Value; + public override object GetValue(int? languageId = null, string segment = null) + => languageId == null & segment == null ? _objectValue.Value : null; - public override object GetXPathValue(int? languageId = null, string segment = null) => _xpathValue.Value; + public override object GetXPathValue(int? languageId = null, string segment = null) + => languageId == null & segment == null ? _xpathValue.Value : null; - public RawValueProperty(PublishedPropertyType propertyType, IPublishedElement content, object propertyData, bool isPreviewing = false) + public RawValueProperty(PublishedPropertyType propertyType, IPublishedElement content, object sourceValue, bool isPreviewing = false) : base(propertyType, PropertyCacheLevel.Unknown) // cache level is ignored { - _propertyData = propertyData; + if (propertyType.Variations != ContentVariation.InvariantNeutral) + throw new ArgumentException("Property types with variations are not supported here.", nameof(propertyType)); - var interValue = new Lazy(() => PropertyType.ConvertSourceToInter(content, _propertyData, isPreviewing)); + _sourceValue = sourceValue; + + var interValue = new Lazy(() => PropertyType.ConvertSourceToInter(content, _sourceValue, isPreviewing)); _objectValue = new Lazy(() => PropertyType.ConvertInterToObject(content, PropertyCacheLevel.Unknown, interValue.Value, isPreviewing)); _xpathValue = new Lazy(() => PropertyType.ConvertInterToXPath(content, PropertyCacheLevel.Unknown, interValue.Value, isPreviewing)); } diff --git a/src/Umbraco.Core/Models/RedirectUrl.cs b/src/Umbraco.Core/Models/RedirectUrl.cs index 752e2490ee..6b42a5c662 100644 --- a/src/Umbraco.Core/Models/RedirectUrl.cs +++ b/src/Umbraco.Core/Models/RedirectUrl.cs @@ -10,7 +10,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class RedirectUrl : Entity, IRedirectUrl + public class RedirectUrl : EntityBase.EntityBase, IRedirectUrl { /// /// Initializes a new instance of the class. diff --git a/src/Umbraco.Core/Models/Relation.cs b/src/Umbraco.Core/Models/Relation.cs index e432c84fc2..a6d3023235 100644 --- a/src/Umbraco.Core/Models/Relation.cs +++ b/src/Umbraco.Core/Models/Relation.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class Relation : Entity, IAggregateRoot, IRelation + public class Relation : EntityBase.EntityBase, IRelation { //NOTE: The datetime column from umbracoRelation is set on CreateDate on the Entity private int _parentId; diff --git a/src/Umbraco.Core/Models/RelationType.cs b/src/Umbraco.Core/Models/RelationType.cs index 0f6ce2ce69..70f14e3571 100644 --- a/src/Umbraco.Core/Models/RelationType.cs +++ b/src/Umbraco.Core/Models/RelationType.cs @@ -12,7 +12,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class RelationType : Entity, IAggregateRoot, IRelationType + public class RelationType : EntityBase.EntityBase, IRelationType { private string _name; private string _alias; diff --git a/src/Umbraco.Core/Models/ServerRegistration.cs b/src/Umbraco.Core/Models/ServerRegistration.cs index b6deafc242..9e0eef340a 100644 --- a/src/Umbraco.Core/Models/ServerRegistration.cs +++ b/src/Umbraco.Core/Models/ServerRegistration.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Models /// /// Represents a registered server in a multiple-servers environment. /// - public class ServerRegistration : Entity, IServerRegistration + public class ServerRegistration : EntityBase.EntityBase, IServerRegistration { private string _serverAddress; private string _serverIdentity; diff --git a/src/Umbraco.Core/Models/StylesheetProperty.cs b/src/Umbraco.Core/Models/StylesheetProperty.cs index 41fbd8d2b4..d014590a06 100644 --- a/src/Umbraco.Core/Models/StylesheetProperty.cs +++ b/src/Umbraco.Core/Models/StylesheetProperty.cs @@ -13,7 +13,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class StylesheetProperty : TracksChangesEntityBase, IValueObject + public class StylesheetProperty : BeingDirtyBase, IValueObject { private string _alias; private string _value; diff --git a/src/Umbraco.Core/Models/Tag.cs b/src/Umbraco.Core/Models/Tag.cs index 526ce9def4..7d45d3afcf 100644 --- a/src/Umbraco.Core/Models/Tag.cs +++ b/src/Umbraco.Core/Models/Tag.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Models { [Serializable] [DataContract(IsReference = true)] - public class Tag : Entity, ITag + public class Tag : EntityBase.EntityBase, ITag { public Tag() { diff --git a/src/Umbraco.Core/Models/Task.cs b/src/Umbraco.Core/Models/Task.cs index cbbe690288..2b0203b75e 100644 --- a/src/Umbraco.Core/Models/Task.cs +++ b/src/Umbraco.Core/Models/Task.cs @@ -10,7 +10,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class Task : Entity, IAggregateRoot + public class Task : EntityBase.EntityBase { private bool _closed; private TaskType _taskType; diff --git a/src/Umbraco.Core/Models/TaskType.cs b/src/Umbraco.Core/Models/TaskType.cs index 72b2e0f459..8440e8b846 100644 --- a/src/Umbraco.Core/Models/TaskType.cs +++ b/src/Umbraco.Core/Models/TaskType.cs @@ -10,7 +10,7 @@ namespace Umbraco.Core.Models /// [Serializable] [DataContract(IsReference = true)] - public class TaskType : Entity, IAggregateRoot + public class TaskType : EntityBase.EntityBase { private string _alias; diff --git a/src/Umbraco.Core/Models/UmbracoDomain.cs b/src/Umbraco.Core/Models/UmbracoDomain.cs index aee3896795..839a8edf51 100644 --- a/src/Umbraco.Core/Models/UmbracoDomain.cs +++ b/src/Umbraco.Core/Models/UmbracoDomain.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.Models { [Serializable] [DataContract(IsReference = true)] - public class UmbracoDomain : Entity, IDomain + public class UmbracoDomain : EntityBase.EntityBase, IDomain { public UmbracoDomain(string domainName) { diff --git a/src/Umbraco.Core/Models/UmbracoEntity.cs b/src/Umbraco.Core/Models/UmbracoEntity.cs index 310a3e51d8..aebf0a4de0 100644 --- a/src/Umbraco.Core/Models/UmbracoEntity.cs +++ b/src/Umbraco.Core/Models/UmbracoEntity.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; -using System.Globalization; using System.Linq; using System.Reflection; -using System.Runtime.CompilerServices; using Umbraco.Core.Models.EntityBase; namespace Umbraco.Core.Models @@ -11,20 +9,26 @@ namespace Umbraco.Core.Models /// /// Implementation of the for internal use. /// - public class UmbracoEntity : Entity, IUmbracoEntity + public class UmbracoEntity : EntityBase.EntityBase, IUmbracoEntity { private static readonly Lazy Ps = new Lazy(); private int _creatorId; + private int _level; private string _name; private int _parentId; private string _path; private int _sortOrder; private bool _trashed; + private bool _hasChildren; + + // fixme - these are for IContent only - MOVE! private bool _published; private bool _edited; + + // fixme - these are for IContentBase only - MOVE! private string _contentTypeAlias; private Guid _nodeObjectTypeId; @@ -189,22 +193,28 @@ namespace Umbraco.Core.Models { var clone = (UmbracoEntity) base.DeepClone(); - // turn off change tracking + // disable change tracking clone.DisableChangeTracking(); - // ensure that any value in the dictionary that is deep cloneable is cloned too + // deep clone additional data properties + // fixme - BUT the values are... only set in EntityRepository to non-deepclonable stuff?! foreach (var key in clone.AdditionalData.Keys.ToArray()) { if (clone.AdditionalData[key] is IDeepCloneable deepCloneable) clone.AdditionalData[key] = deepCloneable.DeepClone(); } - // re-enable tracking - clone.ResetDirtyProperties(false); // why? were not tracking + // enable tracking clone.EnableChangeTracking(); + return clone; } + // fixme + // wtf? is clone.AdditionalData at least shallow cloned? + // and, considering the only thing we put in EntityProperty are strings, + // what's the point of EntityProperty ??? + /// /// A struction that can be contained in the additional data of an UmbracoEntity representing /// a user defined property diff --git a/src/Umbraco.Core/Models/UmbracoObjectTypes.cs b/src/Umbraco.Core/Models/UmbracoObjectTypes.cs index cf75d3c7cd..c58f69d223 100644 --- a/src/Umbraco.Core/Models/UmbracoObjectTypes.cs +++ b/src/Umbraco.Core/Models/UmbracoObjectTypes.cs @@ -122,7 +122,7 @@ namespace Umbraco.Core.Models /// /// Data Type /// - [UmbracoObjectType(Constants.ObjectTypes.Strings.DataType, typeof(IDataTypeDefinition))] + [UmbracoObjectType(Constants.ObjectTypes.Strings.DataType, typeof(IDataType))] [FriendlyName("Data Type")] [UmbracoUdiType(Constants.UdiEntityType.DataType)] DataType, diff --git a/src/Umbraco.Core/Packaging/Models/UninstallationSummary.cs b/src/Umbraco.Core/Packaging/Models/UninstallationSummary.cs index 6f28ba567e..1c31283ee8 100644 --- a/src/Umbraco.Core/Packaging/Models/UninstallationSummary.cs +++ b/src/Umbraco.Core/Packaging/Models/UninstallationSummary.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.Packaging.Models public class UninstallationSummary { public MetaData MetaData { get; set; } - public IEnumerable DataTypesUninstalled { get; set; } + public IEnumerable DataTypesUninstalled { get; set; } public IEnumerable LanguagesUninstalled { get; set; } public IEnumerable DictionaryItemsUninstalled { get; set; } public IEnumerable MacrosUninstalled { get; set; } @@ -29,7 +29,7 @@ namespace Umbraco.Core.Packaging.Models { summary.ContentUninstalled = new List(); summary.ContentTypesUninstalled = new List(); - summary.DataTypesUninstalled = new List(); + summary.DataTypesUninstalled = new List(); summary.DictionaryItemsUninstalled = new List(); summary.FilesUninstalled = new List(); summary.LanguagesUninstalled = new List(); diff --git a/src/Umbraco.Core/Packaging/PackageInstallation.cs b/src/Umbraco.Core/Packaging/PackageInstallation.cs index 48f303d31d..9a62fe8b9a 100644 --- a/src/Umbraco.Core/Packaging/PackageInstallation.cs +++ b/src/Umbraco.Core/Packaging/PackageInstallation.cs @@ -147,7 +147,7 @@ namespace Umbraco.Core.Packaging try { - var dataTypeDefinitions = EmptyEnumerableIfNull(dataTypes) ?? InstallDataTypes(dataTypes, userId); + var dataTypeDefinitions = EmptyEnumerableIfNull(dataTypes) ?? InstallDataTypes(dataTypes, userId); installationSummary.DataTypesInstalled = dataTypeDefinitions; var languagesInstalled = EmptyEnumerableIfNull(languages) ?? InstallLanguages(languages, userId); @@ -412,7 +412,7 @@ namespace Umbraco.Core.Packaging return _packagingService.ImportLanguages(languageElement, userId); } - private IEnumerable InstallDataTypes(XElement dataTypeElements, int userId = 0) + private IEnumerable InstallDataTypes(XElement dataTypeElements, int userId = 0) { if (string.Equals(Constants.Packaging.DataTypesNodeName, dataTypeElements.Name.LocalName) == false) { diff --git a/src/Umbraco.Core/Persistence/Factories/DataTypeDefinitionFactory.cs b/src/Umbraco.Core/Persistence/Factories/DataTypeFactory.cs similarity index 86% rename from src/Umbraco.Core/Persistence/Factories/DataTypeDefinitionFactory.cs rename to src/Umbraco.Core/Persistence/Factories/DataTypeFactory.cs index efe6fa2a3c..4e174f6476 100644 --- a/src/Umbraco.Core/Persistence/Factories/DataTypeDefinitionFactory.cs +++ b/src/Umbraco.Core/Persistence/Factories/DataTypeFactory.cs @@ -1,97 +1,97 @@ -using System; -using System.Globalization; -using Umbraco.Core.Models; -using Umbraco.Core.Persistence.Dtos; - -namespace Umbraco.Core.Persistence.Factories -{ - internal class DataTypeDefinitionFactory - { - private readonly Guid _nodeObjectTypeId; - private int _primaryKey; - - public DataTypeDefinitionFactory(Guid nodeObjectTypeId) - { - _nodeObjectTypeId = nodeObjectTypeId; - } - - #region Implementation of IEntityFactory - - public IDataTypeDefinition BuildEntity(DataTypeDto dto) - { - var dataTypeDefinition = new DataTypeDefinition(dto.PropertyEditorAlias); - - - try - { - dataTypeDefinition.DisableChangeTracking(); - - dataTypeDefinition.CreateDate = dto.NodeDto.CreateDate; - dataTypeDefinition.DatabaseType = dto.DbType.EnumParse(true); - dataTypeDefinition.Id = dto.DataTypeId; - dataTypeDefinition.Key = dto.NodeDto.UniqueId; - dataTypeDefinition.Level = dto.NodeDto.Level; - dataTypeDefinition.UpdateDate = dto.NodeDto.CreateDate; - dataTypeDefinition.Name = dto.NodeDto.Text; - dataTypeDefinition.ParentId = dto.NodeDto.ParentId; - dataTypeDefinition.Path = dto.NodeDto.Path; - dataTypeDefinition.SortOrder = dto.NodeDto.SortOrder; - dataTypeDefinition.Trashed = dto.NodeDto.Trashed; - dataTypeDefinition.CreatorId = dto.NodeDto.UserId.Value; - - // reset dirty initial properties (U4-1946) - dataTypeDefinition.ResetDirtyProperties(false); - return dataTypeDefinition; - } - finally - { - dataTypeDefinition.EnableChangeTracking(); - } - } - - public DataTypeDto BuildDto(IDataTypeDefinition entity) - { - var dataTypeDto = new DataTypeDto - { - PropertyEditorAlias = entity.PropertyEditorAlias, - DataTypeId = entity.Id, - DbType = entity.DatabaseType.ToString(), - NodeDto = BuildNodeDto(entity) - }; - - if (_primaryKey > 0) - { - dataTypeDto.PrimaryKey = _primaryKey; - } - - return dataTypeDto; - } - - #endregion - - public void SetPrimaryKey(int primaryKey) - { - _primaryKey = primaryKey; - } - - private NodeDto BuildNodeDto(IDataTypeDefinition entity) - { - var nodeDto = new NodeDto - { - CreateDate = entity.CreateDate, - NodeId = entity.Id, - Level = short.Parse(entity.Level.ToString(CultureInfo.InvariantCulture)), - NodeObjectType = _nodeObjectTypeId, - ParentId = entity.ParentId, - Path = entity.Path, - SortOrder = entity.SortOrder, - Text = entity.Name, - Trashed = entity.Trashed, - UniqueId = entity.Key, - UserId = entity.CreatorId - }; - - return nodeDto; - } - } -} +using System; +using System.Globalization; +using Umbraco.Core.Models; +using Umbraco.Core.Persistence.Dtos; + +namespace Umbraco.Core.Persistence.Factories +{ + internal class DataTypeFactory + { + private readonly Guid _nodeObjectTypeId; + private int _primaryKey; + + public DataTypeFactory(Guid nodeObjectTypeId) + { + _nodeObjectTypeId = nodeObjectTypeId; + } + + #region Implementation of IEntityFactory + + public IDataType BuildEntity(DataTypeDto dto) + { + var dataTypeDefinition = new DataType(dto.PropertyEditorAlias); + + + try + { + dataTypeDefinition.DisableChangeTracking(); + + dataTypeDefinition.CreateDate = dto.NodeDto.CreateDate; + dataTypeDefinition.DatabaseType = dto.DbType.EnumParse(true); + dataTypeDefinition.Id = dto.DataTypeId; + dataTypeDefinition.Key = dto.NodeDto.UniqueId; + dataTypeDefinition.Level = dto.NodeDto.Level; + dataTypeDefinition.UpdateDate = dto.NodeDto.CreateDate; + dataTypeDefinition.Name = dto.NodeDto.Text; + dataTypeDefinition.ParentId = dto.NodeDto.ParentId; + dataTypeDefinition.Path = dto.NodeDto.Path; + dataTypeDefinition.SortOrder = dto.NodeDto.SortOrder; + dataTypeDefinition.Trashed = dto.NodeDto.Trashed; + dataTypeDefinition.CreatorId = dto.NodeDto.UserId.Value; + + // reset dirty initial properties (U4-1946) + dataTypeDefinition.ResetDirtyProperties(false); + return dataTypeDefinition; + } + finally + { + dataTypeDefinition.EnableChangeTracking(); + } + } + + public DataTypeDto BuildDto(IDataType entity) + { + var dataTypeDto = new DataTypeDto + { + PropertyEditorAlias = entity.EditorAlias, + DataTypeId = entity.Id, + DbType = entity.DatabaseType.ToString(), + NodeDto = BuildNodeDto(entity) + }; + + if (_primaryKey > 0) + { + dataTypeDto.PrimaryKey = _primaryKey; + } + + return dataTypeDto; + } + + #endregion + + public void SetPrimaryKey(int primaryKey) + { + _primaryKey = primaryKey; + } + + private NodeDto BuildNodeDto(IDataType entity) + { + var nodeDto = new NodeDto + { + CreateDate = entity.CreateDate, + NodeId = entity.Id, + Level = short.Parse(entity.Level.ToString(CultureInfo.InvariantCulture)), + NodeObjectType = _nodeObjectTypeId, + ParentId = entity.ParentId, + Path = entity.Path, + SortOrder = entity.SortOrder, + Text = entity.Name, + Trashed = entity.Trashed, + UniqueId = entity.Key, + UserId = entity.CreatorId + }; + + return nodeDto; + } + } +} diff --git a/src/Umbraco.Core/Persistence/Mappers/DataTypeDefinitionMapper.cs b/src/Umbraco.Core/Persistence/Mappers/DataTypeDefinitionMapper.cs deleted file mode 100644 index 85466f65b0..0000000000 --- a/src/Umbraco.Core/Persistence/Mappers/DataTypeDefinitionMapper.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Concurrent; -using Umbraco.Core.Models; -using Umbraco.Core.Persistence.Dtos; - -namespace Umbraco.Core.Persistence.Mappers -{ - /// - /// Represents a to DTO mapper used to translate the properties of the public api - /// implementation to that of the database's DTO as sql: [tableName].[columnName]. - /// - [MapperFor(typeof(DataTypeDefinition))] - [MapperFor(typeof(IDataTypeDefinition))] - public sealed class DataTypeDefinitionMapper : BaseMapper - { - private static readonly ConcurrentDictionary PropertyInfoCacheInstance = new ConcurrentDictionary(); - - internal override ConcurrentDictionary PropertyInfoCache => PropertyInfoCacheInstance; - - protected override void BuildMap() - { - CacheMap(src => src.Id, dto => dto.NodeId); - CacheMap(src => src.CreateDate, dto => dto.CreateDate); - CacheMap(src => src.Level, dto => dto.Level); - CacheMap(src => src.ParentId, dto => dto.ParentId); - CacheMap(src => src.Path, dto => dto.Path); - CacheMap(src => src.SortOrder, dto => dto.SortOrder); - CacheMap(src => src.Name, dto => dto.Text); - CacheMap(src => src.Trashed, dto => dto.Trashed); - CacheMap(src => src.Key, dto => dto.UniqueId); - CacheMap(src => src.CreatorId, dto => dto.UserId); - CacheMap(src => src.PropertyEditorAlias, dto => dto.PropertyEditorAlias); - CacheMap(src => src.DatabaseType, dto => dto.DbType); - - } - } -} diff --git a/src/Umbraco.Core/Persistence/Mappers/DataTypeMapper.cs b/src/Umbraco.Core/Persistence/Mappers/DataTypeMapper.cs new file mode 100644 index 0000000000..3213095f6c --- /dev/null +++ b/src/Umbraco.Core/Persistence/Mappers/DataTypeMapper.cs @@ -0,0 +1,36 @@ +using System.Collections.Concurrent; +using Umbraco.Core.Models; +using Umbraco.Core.Persistence.Dtos; + +namespace Umbraco.Core.Persistence.Mappers +{ + /// + /// Represents a to DTO mapper used to translate the properties of the public api + /// implementation to that of the database's DTO as sql: [tableName].[columnName]. + /// + [MapperFor(typeof(DataType))] + [MapperFor(typeof(IDataType))] + public sealed class DataTypeMapper : BaseMapper + { + private static readonly ConcurrentDictionary PropertyInfoCacheInstance = new ConcurrentDictionary(); + + internal override ConcurrentDictionary PropertyInfoCache => PropertyInfoCacheInstance; + + protected override void BuildMap() + { + CacheMap(src => src.Id, dto => dto.NodeId); + CacheMap(src => src.CreateDate, dto => dto.CreateDate); + CacheMap(src => src.Level, dto => dto.Level); + CacheMap(src => src.ParentId, dto => dto.ParentId); + CacheMap(src => src.Path, dto => dto.Path); + CacheMap(src => src.SortOrder, dto => dto.SortOrder); + CacheMap(src => src.Name, dto => dto.Text); + CacheMap(src => src.Trashed, dto => dto.Trashed); + CacheMap(src => src.Key, dto => dto.UniqueId); + CacheMap(src => src.CreatorId, dto => dto.UserId); + CacheMap(src => src.EditorAlias, dto => dto.PropertyEditorAlias); + CacheMap(src => src.DatabaseType, dto => dto.DbType); + + } + } +} diff --git a/src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs b/src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs index c742624695..6c79254a0f 100644 --- a/src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs +++ b/src/Umbraco.Core/Persistence/Mappers/MapperCollectionBuilder.cs @@ -30,7 +30,7 @@ namespace Umbraco.Core.Persistence.Mappers Add(); Add(); Add(); - Add(); + Add(); Add(); Add(); Add(); diff --git a/src/Umbraco.Core/Persistence/Repositories/IDataTypeDefinitionRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IDataTypeRepository.cs similarity index 53% rename from src/Umbraco.Core/Persistence/Repositories/IDataTypeDefinitionRepository.cs rename to src/Umbraco.Core/Persistence/Repositories/IDataTypeRepository.cs index 20fd586d45..5e1aed9ba0 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IDataTypeDefinitionRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IDataTypeRepository.cs @@ -4,14 +4,14 @@ using Umbraco.Core.Models; namespace Umbraco.Core.Persistence.Repositories { - public interface IDataTypeDefinitionRepository : IReadWriteQueryRepository + public interface IDataTypeRepository : IReadWriteQueryRepository { PreValueCollection GetPreValuesCollectionByDataTypeId(int dataTypeId); string GetPreValueAsString(int preValueId); - void AddOrUpdatePreValues(IDataTypeDefinition dataType, IDictionary values); + void AddOrUpdatePreValues(IDataType dataType, IDictionary values); void AddOrUpdatePreValues(int dataTypeId, IDictionary values); - IEnumerable> Move(IDataTypeDefinition toMove, EntityContainer container); + IEnumerable> Move(IDataType toMove, EntityContainer container); } } diff --git a/src/Umbraco.Core/Persistence/Repositories/IEntityRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IEntityRepository.cs index 9e9f0c73bd..3586bf8e27 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IEntityRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IEntityRepository.cs @@ -21,8 +21,8 @@ namespace Umbraco.Core.Persistence.Repositories UmbracoObjectTypes GetObjectType(int id); UmbracoObjectTypes GetObjectType(Guid key); - IEnumerable GetAllPaths(Guid objectType, params int[] ids); - IEnumerable GetAllPaths(Guid objectType, params Guid[] keys); + IEnumerable GetAllPaths(Guid objectType, params int[] ids); + IEnumerable GetAllPaths(Guid objectType, params Guid[] keys); /// /// Gets paged results diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs index 72e1be760d..354a431d89 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ContentTypeRepositoryBase.cs @@ -698,7 +698,7 @@ AND umbracoNode.id <> @id", } // reset dirty initial properties (U4-1946) - ((Entity)contentType).ResetDirtyProperties(false); + ((EntityBase)contentType).ResetDirtyProperties(false); } } } diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/DataTypeDefinitionRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/DataTypeRepository.cs similarity index 91% rename from src/Umbraco.Core/Persistence/Repositories/Implement/DataTypeDefinitionRepository.cs rename to src/Umbraco.Core/Persistence/Repositories/Implement/DataTypeRepository.cs index fcc14f1059..9159eaacf9 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/DataTypeDefinitionRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/DataTypeRepository.cs @@ -19,13 +19,13 @@ using Umbraco.Core.Services; namespace Umbraco.Core.Persistence.Repositories.Implement { /// - /// Represents a repository for doing CRUD operations for + /// Represents a repository for doing CRUD operations for /// - internal class DataTypeDefinitionRepository : NPocoRepositoryBase, IDataTypeDefinitionRepository + internal class DataTypeRepository : NPocoRepositoryBase, IDataTypeRepository { private readonly DataTypePreValueRepository _preValRepository; - public DataTypeDefinitionRepository(IScopeAccessor scopeAccessor, CacheHelper cache, ILogger logger) + public DataTypeRepository(IScopeAccessor scopeAccessor, CacheHelper cache, ILogger logger) : base(scopeAccessor, cache, logger) { _preValRepository = new DataTypePreValueRepository(scopeAccessor, CacheHelper.NoCache, logger); @@ -33,14 +33,14 @@ namespace Umbraco.Core.Persistence.Repositories.Implement #region Overrides of RepositoryBase - protected override IDataTypeDefinition PerformGet(int id) + protected override IDataType PerformGet(int id) { return GetMany(new[] { id }).FirstOrDefault(); } - protected override IEnumerable PerformGetAll(params int[] ids) + protected override IEnumerable PerformGetAll(params int[] ids) { - var factory = new DataTypeDefinitionFactory(NodeObjectTypeId); + var factory = new DataTypeFactory(NodeObjectTypeId); var dataTypeSql = GetBaseQuery(false); if (ids.Any()) @@ -56,12 +56,12 @@ namespace Umbraco.Core.Persistence.Repositories.Implement return dtos.Select(factory.BuildEntity).ToArray(); } - protected override IEnumerable PerformGetByQuery(IQuery query) + protected override IEnumerable PerformGetByQuery(IQuery query) { - var factory = new DataTypeDefinitionFactory(NodeObjectTypeId); + var factory = new DataTypeFactory(NodeObjectTypeId); var sqlClause = GetBaseQuery(false); - var translator = new SqlTranslator(sqlClause, query); + var translator = new SqlTranslator(sqlClause, query); var sql = translator.Translate(); var dtos = Database.Fetch(sql); @@ -105,9 +105,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement #region Unit of Work Implementation - protected override void PersistNewItem(IDataTypeDefinition entity) + protected override void PersistNewItem(IDataType entity) { - ((DataTypeDefinition)entity).AddingEntity(); + ((DataType)entity).AddingEntity(); //ensure a datatype has a unique name before creating it entity.Name = EnsureUniqueNodeName(entity.Name); @@ -122,7 +122,7 @@ WHERE umbracoNode." + SqlSyntax.GetQuotedColumnName("text") + "= @name", new { n throw new DuplicateNameException("A data type with the name " + entity.Name + " already exists"); } - var factory = new DataTypeDefinitionFactory(NodeObjectTypeId); + var factory = new DataTypeFactory(NodeObjectTypeId); var dto = factory.BuildDto(entity); //Logic for setting Path, Level and SortOrder @@ -155,7 +155,7 @@ WHERE umbracoNode." + SqlSyntax.GetQuotedColumnName("text") + "= @name", new { n entity.ResetDirtyProperties(); } - protected override void PersistUpdatedItem(IDataTypeDefinition entity) + protected override void PersistUpdatedItem(IDataType entity) { entity.Name = EnsureUniqueNodeName(entity.Name, entity.Id); @@ -172,7 +172,7 @@ AND umbracoNode.id <> @id", } //Updates Modified date - ((DataTypeDefinition)entity).UpdatingEntity(); + ((DataType)entity).UpdatingEntity(); //Look up parent to get and set the correct Path if ParentId has changed if (entity.IsPropertyDirty("ParentId")) @@ -187,7 +187,7 @@ AND umbracoNode.id <> @id", entity.SortOrder = maxSortOrder + 1; } - var factory = new DataTypeDefinitionFactory(NodeObjectTypeId); + var factory = new DataTypeFactory(NodeObjectTypeId); //Look up DataTypeDefinition entry to get Primary for updating the DTO var dataTypeDto = Database.SingleOrDefault("WHERE nodeId = @Id", new { Id = entity.Id }); factory.SetPrimaryKey(dataTypeDto.PrimaryKey); @@ -205,7 +205,7 @@ AND umbracoNode.id <> @id", entity.ResetDirtyProperties(); } - protected override void PersistDeletedItem(IDataTypeDefinition entity) + protected override void PersistDeletedItem(IDataType entity) { //Remove Notifications Database.Delete("WHERE nodeId = @Id", new { Id = entity.Id }); @@ -234,7 +234,7 @@ AND umbracoNode.id <> @id", //Delete (base) node data Database.Delete("WHERE uniqueID = @Id", new { Id = entity.Key }); - entity.DeletedDate = DateTime.Now; + entity.DeleteDate = DateTime.Now; } #endregion @@ -274,7 +274,7 @@ AND umbracoNode.id <> @id", AddOrUpdatePreValues(dtd, values); } - public IEnumerable> Move(IDataTypeDefinition toMove, EntityContainer container) + public IEnumerable> Move(IDataType toMove, EntityContainer container) { var parentId = -1; if (container != null) @@ -288,9 +288,9 @@ AND umbracoNode.id <> @id", } //used to track all the moved entities to be given to the event - var moveInfo = new List> + var moveInfo = new List> { - new MoveEventInfo(toMove, toMove.Path, parentId) + new MoveEventInfo(toMove, toMove.Path, parentId) }; var origPath = toMove.Path; @@ -305,12 +305,12 @@ AND umbracoNode.id <> @id", Save(toMove); //update all descendants from the original path, update in order of level - var descendants = Get(Query().Where(type => type.Path.StartsWith(origPath + ","))); + var descendants = Get(Query().Where(type => type.Path.StartsWith(origPath + ","))); var lastParent = toMove; foreach (var descendant in descendants.OrderBy(x => x.Level)) { - moveInfo.Add(new MoveEventInfo(descendant, descendant.Path, descendant.ParentId)); + moveInfo.Add(new MoveEventInfo(descendant, descendant.Path, descendant.ParentId)); descendant.ParentId = lastParent.Id; descendant.Path = string.Concat(lastParent.Path, ",", descendant.Id); @@ -322,7 +322,7 @@ AND umbracoNode.id <> @id", return moveInfo; } - public void AddOrUpdatePreValues(IDataTypeDefinition dataType, IDictionary values) + public void AddOrUpdatePreValues(IDataType dataType, IDictionary values) { var currentVals = new DataTypePreValueDto[] { }; if (dataType.HasIdentity) @@ -422,11 +422,11 @@ AND umbracoNode.id <> @id", /// /// Private class to handle pre-value crud based on units of work with transactions /// - private class PreValueEntity : Entity, IAggregateRoot + private class PreValueEntity : EntityBase { public string Value { get; set; } public string Alias { get; set; } - public IDataTypeDefinition DataType { get; set; } + public IDataType DataType { get; set; } public int SortOrder { get; set; } } @@ -480,7 +480,7 @@ AND umbracoNode.id <> @id", { Database.Execute("DELETE FROM cmsDataTypePreValues WHERE id=@Id", new { Id = entity.Id }); - entity.DeletedDate = DateTime.Now; + entity.DeleteDate = DateTime.Now; } protected override void PersistNewItem(PreValueEntity entity) diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/DictionaryRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/DictionaryRepository.cs index 64020a6dce..856fe6af31 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/DictionaryRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/DictionaryRepository.cs @@ -51,7 +51,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var entity = ConvertFromDto(dto); // reset dirty initial properties (U4-1946) - ((Entity)entity).ResetDirtyProperties(false); + ((EntityBase)entity).ResetDirtyProperties(false); return entity; } @@ -150,7 +150,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistUpdatedItem(IDictionaryItem entity) { - ((Entity)entity).UpdatingEntity(); + ((EntityBase)entity).UpdatingEntity(); foreach (var translation in entity.Translations) translation.Value = translation.Value.ToValidXmlString(); @@ -193,7 +193,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement IsolatedCache.ClearCacheItem(RepositoryCacheKeys.GetKey(entity.ItemKey)); IsolatedCache.ClearCacheItem(RepositoryCacheKeys.GetKey(entity.Key)); - entity.DeletedDate = DateTime.Now; + entity.DeleteDate = DateTime.Now; } private void RecursiveDelete(Guid parentId) diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/EntityRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/EntityRepository.cs index 6205739316..6631f79859 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/EntityRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/EntityRepository.cs @@ -213,25 +213,25 @@ namespace Umbraco.Core.Persistence.Repositories.Implement return entities; } - public virtual IEnumerable GetAllPaths(Guid objectType, params int[] ids) + public virtual IEnumerable GetAllPaths(Guid objectType, params int[] ids) { return ids.Any() ? PerformGetAllPaths(objectType, sql => sql.WhereIn(x => x.NodeId, ids.Distinct())) : PerformGetAllPaths(objectType); } - public virtual IEnumerable GetAllPaths(Guid objectType, params Guid[] keys) + public virtual IEnumerable GetAllPaths(Guid objectType, params Guid[] keys) { return keys.Any() ? PerformGetAllPaths(objectType, sql => sql.WhereIn(x => x.UniqueId, keys.Distinct())) : PerformGetAllPaths(objectType); } - private IEnumerable PerformGetAllPaths(Guid objectType, Action> filter = null) + private IEnumerable PerformGetAllPaths(Guid objectType, Action> filter = null) { var sql = Sql().Select(x => x.NodeId, x => x.Path).From().Where(x => x.NodeObjectType == objectType); filter?.Invoke(sql); - return Database.Fetch(sql); + return Database.Fetch(sql); } public virtual IEnumerable GetByQuery(IQuery query) diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/ExternalLoginRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/ExternalLoginRepository.cs index d5d08402af..9d31c06d49 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/ExternalLoginRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/ExternalLoginRepository.cs @@ -89,7 +89,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement foreach (var entity in dtos.Select(factory.BuildEntity)) { // reset dirty initial properties (U4-1946) - ((TracksChangesEntityBase)entity).ResetDirtyProperties(false); + ((BeingDirtyBase)entity).ResetDirtyProperties(false); yield return entity; } @@ -141,7 +141,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistNewItem(IIdentityUserLogin entity) { - ((Entity)entity).AddingEntity(); + ((EntityBase)entity).AddingEntity(); var factory = new ExternalLoginFactory(); var dto = factory.BuildDto(entity); @@ -154,7 +154,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistUpdatedItem(IIdentityUserLogin entity) { - ((Entity)entity).UpdatingEntity(); + ((EntityBase)entity).UpdatingEntity(); var factory = new ExternalLoginFactory(); var dto = factory.BuildDto(entity); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/LanguageRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/LanguageRepository.cs index b593f6ea35..ffcf771a39 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/LanguageRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/LanguageRepository.cs @@ -105,7 +105,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistNewItem(ILanguage entity) { - ((Entity)entity).AddingEntity(); + ((EntityBase)entity).AddingEntity(); var factory = new LanguageFactory(); var dto = factory.BuildDto(entity); @@ -118,7 +118,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistUpdatedItem(ILanguage entity) { - ((Entity)entity).UpdatingEntity(); + ((EntityBase)entity).UpdatingEntity(); var factory = new LanguageFactory(); var dto = factory.BuildDto(entity); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/MacroRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/MacroRepository.cs index 3167385275..4583fdaef3 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/MacroRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/MacroRepository.cs @@ -45,7 +45,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var entity = factory.BuildEntity(macroDto); // reset dirty initial properties (U4-1946) - ((TracksChangesEntityBase)entity).ResetDirtyProperties(false); + ((BeingDirtyBase)entity).ResetDirtyProperties(false); return entity; } @@ -83,7 +83,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement foreach (var entity in dtos.Select(factory.BuildEntity)) { // reset dirty initial properties (U4-1946) - ((TracksChangesEntityBase)entity).ResetDirtyProperties(false); + ((BeingDirtyBase)entity).ResetDirtyProperties(false); yield return entity; } @@ -133,7 +133,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistNewItem(IMacro entity) { - ((Entity)entity).AddingEntity(); + ((EntityBase)entity).AddingEntity(); var factory = new MacroFactory(); var dto = factory.BuildDto(entity); @@ -154,7 +154,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistUpdatedItem(IMacro entity) { - ((Entity)entity).UpdatingEntity(); + ((EntityBase)entity).UpdatingEntity(); var factory = new MacroFactory(); var dto = factory.BuildDto(entity); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/NPocoRepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/NPocoRepositoryBase.cs index c5cb65a9b6..d34651dbe2 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/NPocoRepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/NPocoRepositoryBase.cs @@ -16,7 +16,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement /// /// internal abstract class NPocoRepositoryBase : RepositoryBase - where TEntity : class, IAggregateRoot + where TEntity : class, IEntity { /// /// Initializes a new instance of the class. @@ -75,7 +75,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement { Database.Execute(delete, new { id = GetEntityId(entity) }); } - entity.DeletedDate = DateTime.Now; + entity.DeleteDate = DateTime.Now; } } } diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/PermissionRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/PermissionRepository.cs index 5d50d03d45..8421678996 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/PermissionRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/PermissionRepository.cs @@ -23,7 +23,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement /// like the normal repository pattern but the standard repository Get commands don't apply and will throw /// internal class PermissionRepository : NPocoRepositoryBase - where TEntity : class, IAggregateRoot + where TEntity : class, IEntity { public PermissionRepository(IScopeAccessor scopeAccessor, CacheHelper cache, ILogger logger) : base(scopeAccessor, cache, logger) @@ -305,8 +305,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement /// protected override void PersistUpdatedItem(ContentPermissionSet entity) { - var asAggregateRoot = (IAggregateRoot)entity; - if (asAggregateRoot.HasIdentity == false) + var asIEntity = (IEntity) entity; + if (asIEntity.HasIdentity == false) { throw new InvalidOperationException("Cannot create permissions for an entity without an Id"); } diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/RelationRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/RelationRepository.cs index 512da44089..2a7955fdfe 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/RelationRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/RelationRepository.cs @@ -88,7 +88,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var entity = factory.BuildEntity(dto); // reset dirty initial properties (U4-1946) - ((TracksChangesEntityBase)entity).ResetDirtyProperties(false); + ((BeingDirtyBase)entity).ResetDirtyProperties(false); return entity; } @@ -136,7 +136,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistNewItem(IRelation entity) { - ((Entity)entity).AddingEntity(); + ((EntityBase)entity).AddingEntity(); var factory = new RelationFactory(entity.RelationType); var dto = factory.BuildDto(entity); @@ -149,7 +149,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistUpdatedItem(IRelation entity) { - ((Entity)entity).UpdatingEntity(); + ((EntityBase)entity).UpdatingEntity(); var factory = new RelationFactory(entity.RelationType); var dto = factory.BuildDto(entity); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/RelationTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/RelationTypeRepository.cs index a247ec11c8..39402a5d5b 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/RelationTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/RelationTypeRepository.cs @@ -84,7 +84,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var entity = factory.BuildEntity(dto); // reset dirty initial properties (U4-1946) - ((TracksChangesEntityBase) entity).ResetDirtyProperties(false); + ((BeingDirtyBase) entity).ResetDirtyProperties(false); return entity; } @@ -133,7 +133,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistNewItem(IRelationType entity) { - ((Entity)entity).AddingEntity(); + ((EntityBase)entity).AddingEntity(); var factory = new RelationTypeFactory(); var dto = factory.BuildDto(entity); @@ -146,7 +146,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistUpdatedItem(IRelationType entity) { - ((Entity)entity).UpdatingEntity(); + ((EntityBase)entity).UpdatingEntity(); var factory = new RelationTypeFactory(); var dto = factory.BuildDto(entity); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/RepositoryBaseOfTIdTEntity.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/RepositoryBaseOfTIdTEntity.cs index b9e9dc182a..3fbcab7b99 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/RepositoryBaseOfTIdTEntity.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/RepositoryBaseOfTIdTEntity.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement /// The type of the entity managed by this repository. /// The type of the entity's unique identifier. internal abstract class RepositoryBase : IReadWriteQueryRepository - where TEntity : class, IAggregateRoot + where TEntity : class, IEntity { private IRepositoryCachePolicy _cachePolicy; diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/SimpleGetRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/SimpleGetRepository.cs index d4ab97030a..568ac65d54 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/SimpleGetRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/SimpleGetRepository.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement /// Simple abstract ReadOnly repository used to simply have PerformGet and PeformGetAll with an underlying cache /// internal abstract class SimpleGetRepository : NPocoRepositoryBase - where TEntity : class, IAggregateRoot + where TEntity : class, IEntity where TDto: class { protected SimpleGetRepository(IScopeAccessor scopeAccessor, CacheHelper cache, ILogger logger) @@ -42,7 +42,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var entity = ConvertToEntity(dto); - if (entity is Entity dirtyEntity) + if (entity is EntityBase dirtyEntity) { // reset dirty initial properties (U4-1946) dirtyEntity.ResetDirtyProperties(false); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/TagRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/TagRepository.cs index 05fa6d8f4d..cb9ba006bb 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/TagRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/TagRepository.cs @@ -32,7 +32,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var entity = factory.BuildEntity(tagDto); // reset dirty initial properties (U4-1946) - ((TracksChangesEntityBase)entity).ResetDirtyProperties(false); + ((BeingDirtyBase)entity).ResetDirtyProperties(false); return entity; } @@ -69,7 +69,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement foreach (var entity in dtos.Select(factory.BuildEntity)) { // reset dirty initial properties (U4-1946) - ((TracksChangesEntityBase)entity).ResetDirtyProperties(false); + ((BeingDirtyBase)entity).ResetDirtyProperties(false); yield return entity; } } @@ -119,7 +119,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistNewItem(ITag entity) { - ((Entity)entity).AddingEntity(); + ((EntityBase)entity).AddingEntity(); var factory = new TagFactory(); var dto = factory.BuildDto(entity); @@ -132,7 +132,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement protected override void PersistUpdatedItem(ITag entity) { - ((Entity)entity).UpdatingEntity(); + ((EntityBase)entity).UpdatingEntity(); var factory = new TagFactory(); var dto = factory.BuildDto(entity); diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs index 04192ac169..ced61658e4 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/TemplateRepository.cs @@ -317,7 +317,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement _masterpagesFileSystem.DeleteFile(masterpageName); } - entity.DeletedDate = DateTime.Now; + entity.DeleteDate = DateTime.Now; } #endregion diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/UserGroupRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/UserGroupRepository.cs index 92a5bbdd44..877b26a27b 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/UserGroupRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/UserGroupRepository.cs @@ -335,7 +335,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement /// /// used to persist a user group with associated users at once /// - private class UserGroupWithUsers : Entity, IAggregateRoot + private class UserGroupWithUsers : EntityBase { public UserGroupWithUsers(IUserGroup userGroup, int[] userIds) { @@ -343,11 +343,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement UserIds = userIds; } - public override bool HasIdentity - { - get => UserGroup.HasIdentity; - protected set => throw new NotSupportedException(); - } + public override bool HasIdentity => UserGroup.HasIdentity; public IUserGroup UserGroup { get; } public int[] UserIds { get; } diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs index e77b86d86a..a7c2b92223 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditor.cs @@ -10,45 +10,45 @@ using Umbraco.Core.Models; namespace Umbraco.Core.PropertyEditors { /// - /// Basic definition of a property editor + /// Provides a base class for property editors. /// /// - /// The Json serialization attributes are required for manifest property editors to work + /// Editors can be deserialized from manifests, which is why the Json serialization + /// attributes are required, and the properties require an internal setter. /// - [DebuggerDisplay("{DebuggerDisplay(),nq}")] + [DebuggerDisplay("{" + nameof(DebuggerDisplay) + "(),nq}")] public class PropertyEditor : IParameterEditor { - /// - /// Exposes a logger - /// - protected ILogger Logger { get; } - private readonly PropertyEditorAttribute _attribute; /// - /// The constructor will setup the property editor based on the attribute if one is found + /// Initializes a new instance of the class. /// public PropertyEditor(ILogger logger) { Logger = logger ?? throw new ArgumentNullException(nameof(logger)); - //defaults + + // defaults Icon = Constants.Icons.PropertyEditor; Group = "common"; - //assign properties based on the attribute if it is found + // assign properties based on the attribute, if it is found _attribute = GetType().GetCustomAttribute(false); - if (_attribute != null) - { - //set the id/name from the attribute - Alias = _attribute.Alias; - Name = _attribute.Name; - IsParameterEditor = _attribute.IsParameterEditor; - Icon = _attribute.Icon; - Group = _attribute.Group; - IsDeprecated = _attribute.IsDeprecated; - } + if (_attribute == null) return; + + Alias = _attribute.Alias; + Name = _attribute.Name; + IsParameterEditor = _attribute.IsParameterEditor; + Icon = _attribute.Icon; + Group = _attribute.Group; + IsDeprecated = _attribute.IsDeprecated; } + /// + /// Gets a logger. + /// + protected ILogger Logger { get; } + /// /// These are assigned by default normally based on property editor attributes or manifest definitions, /// developers have the chance to override CreateValueEditor if they don't want to use the pre-defined instance @@ -62,42 +62,44 @@ namespace Umbraco.Core.PropertyEditors internal PreValueEditor ManifestDefinedPreValueEditor = null; /// - /// Boolean flag determining if this can be used as a parameter editor + /// Gets or sets a value indicating whether this editor can be used as a parameter editor. /// [JsonProperty("isParameterEditor")] public bool IsParameterEditor { get; internal set; } /// - /// The id of the property editor + /// Gets or sets the unique alias of the property editor. /// [JsonProperty("alias", Required = Required.Always)] public string Alias { get; internal set; } /// - /// The name of the property editor + /// Gets or sets the name of the property editor. /// [JsonProperty("name", Required = Required.Always)] public string Name { get; internal set; } /// - /// The icon of the property editor - if not set it uses a default icon + /// Gets or sets the icon of the property editor. /// [JsonProperty("icon")] public string Icon { get; internal set; } /// - /// The group of the property editor - if not set the editor will list as a generic editor + /// Gets or sets the group of the property editor. /// [JsonProperty("group")] public string Group { get; internal set; } + /// + /// Gets or sets a value indicating whether the property editor is deprecated. + /// + [JsonIgnore] + public bool IsDeprecated { get; internal set; } // fixme kill it all in v8 [JsonProperty("editor", Required = Required.Always)] public PropertyValueEditor ValueEditor => CreateValueEditor(); - [JsonIgnore] - public bool IsDeprecated { get; internal set; } // fixme kill it all in v8 - [JsonIgnore] IValueEditor IParameterEditor.ValueEditor => ValueEditor; @@ -113,28 +115,26 @@ namespace Umbraco.Core.PropertyEditors /// /// Creates a value editor instance /// - /// protected virtual PropertyValueEditor CreateValueEditor() { + // handle manifest-defined editors if (ManifestDefinedPropertyValueEditor != null) { - //detect if the view is a virtual path (in most cases, yes) then convert it + // map view path if virtual if (ManifestDefinedPropertyValueEditor.View.StartsWith("~/")) - { ManifestDefinedPropertyValueEditor.View = IOHelper.ResolveUrl(ManifestDefinedPropertyValueEditor.View); - } return ManifestDefinedPropertyValueEditor; } - //create a new editor + // create a new editor var editor = new PropertyValueEditor(); + var view = _attribute?.EditorView; + if (string.IsNullOrWhiteSpace(view)) + throw new InvalidOperationException("The editor does not specify a view."); - if (_attribute.EditorView.IsNullOrWhiteSpace()) - { - throw new NotImplementedException("This method must be implemented if a view is not explicitly set"); - } - - editor.View = _attribute.EditorView.StartsWith("~/") ? IOHelper.ResolveUrl(_attribute.EditorView) : _attribute.EditorView; + if (view.StartsWith("~/")) + view = IOHelper.ResolveUrl(view); + editor.View = view; editor.ValueType = _attribute.ValueType; editor.HideLabel = _attribute.HideLabel; return editor; @@ -142,26 +142,23 @@ namespace Umbraco.Core.PropertyEditors } /// - /// Creates a pre value editor instance + /// Creates a configuration editor instance. /// - /// protected virtual PreValueEditor CreatePreValueEditor() { - //This will not be null if it is a manifest defined editor + // handle manifest-defined editors if (ManifestDefinedPreValueEditor != null) { - foreach (var f in ManifestDefinedPreValueEditor.Fields) + foreach (var field in ManifestDefinedPreValueEditor.Fields) { - //detect if the view is a virtual path (in most cases, yes) then convert it - if (f.View.StartsWith("~/")) - { - f.View = IOHelper.ResolveUrl(f.View); - } + // map view path if virtual + if (field.View.StartsWith("~/")) + field.View = IOHelper.ResolveUrl(field.View); } return ManifestDefinedPreValueEditor; } - //There's no manifest, just return an empty one + // else return an empty one return new PreValueEditor(); } @@ -180,6 +177,9 @@ namespace Umbraco.Core.PropertyEditors public override int GetHashCode() { + // an internal setter is required for de-serialization from manifests + // but we are never going to change the alias once the editor exists + // ReSharper disable once NonReadonlyMemberInGetHashCode return Alias.GetHashCode(); } @@ -216,4 +216,16 @@ namespace Umbraco.Core.PropertyEditors return configuration; } } + + public class PropertyEditor : PropertyEditor + { + public PropertyEditor(ILogger logger) + : base(logger) + { } + + public virtual TConfiguration MapConfiguration(string configuration) + { + return JsonConvert.DeserializeObject(configuration); + } + } } diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs index 02ee59f10d..5dd16ed69e 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/CheckboxListValueConverter.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters private static readonly char[] Comma = { ',' }; public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.CheckBoxListAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.CheckBoxListAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (IEnumerable); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/ColorPickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/ColorPickerValueConverter.cs index c86f569cdf..fa21b83a0f 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/ColorPickerValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/ColorPickerValueConverter.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class ColorPickerValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.ColorPickerAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.ColorPickerAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (string); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/DatePickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/DatePickerValueConverter.cs index 00a25bf564..6ffe57151e 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/DatePickerValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/DatePickerValueConverter.cs @@ -15,7 +15,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters }; public override bool IsConverter(PublishedPropertyType propertyType) - => PropertyEditorAliases.Contains(propertyType.PropertyEditorAlias); + => PropertyEditorAliases.Contains(propertyType.EditorAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (DateTime); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/DecimalValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/DecimalValueConverter.cs index 52530734fb..b42f1e785d 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/DecimalValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/DecimalValueConverter.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class DecimalValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => Constants.PropertyEditors.DecimalAlias.Equals(propertyType.PropertyEditorAlias); + => Constants.PropertyEditors.DecimalAlias.Equals(propertyType.EditorAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (decimal); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListMultipleValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListMultipleValueConverter.cs index 8874ef6d0a..3815e00e01 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListMultipleValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListMultipleValueConverter.cs @@ -9,7 +9,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class DropdownListMultipleValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.DropDownListMultipleAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.DropDownListMultipleAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (IEnumerable); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListMultipleWithKeysValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListMultipleWithKeysValueConverter.cs index 1bdc4ae8db..b20261de60 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListMultipleWithKeysValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListMultipleWithKeysValueConverter.cs @@ -9,7 +9,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class DropdownListMultipleWithKeysValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.DropdownlistMultiplePublishKeysAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.DropdownlistMultiplePublishKeysAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (IEnumerable); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListValueConverter.cs index b6b1aa6dce..5134bd3ab8 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListValueConverter.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class DropdownListValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.DropDownListAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.DropDownListAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (string); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListWithKeysValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListWithKeysValueConverter.cs index 0656128296..7bda5332fe 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListWithKeysValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/DropdownListWithKeysValueConverter.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class DropdownListWithKeysValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.DropdownlistPublishingKeysAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.DropdownlistPublishingKeysAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (int); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/EmailAddressValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/EmailAddressValueConverter.cs index 9406aec0b7..6458c294e4 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/EmailAddressValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/EmailAddressValueConverter.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class EmailAddressValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.EmailAddressAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.EmailAddressAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (string); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs index 666eb4cdc7..4cc93d67a8 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/GridValueConverter.cs @@ -20,7 +20,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class GridValueConverter : JsonValueConverter { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.GridAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.GridAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (JToken); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs index 8ff4cb8c45..2a845bf127 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/ImageCropperValueConverter.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters private readonly IDataTypeService _dataTypeService; public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.ImageCropperAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.ImageCropperAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (JToken); @@ -115,7 +115,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters return sourceString; } - MergePreValues(obj, _dataTypeService, propertyType.DataTypeId); + MergePreValues(obj, _dataTypeService, propertyType.DataType.Id); return obj; } diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/IntegerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/IntegerValueConverter.cs index f89dc2f84a..c663214608 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/IntegerValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/IntegerValueConverter.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class IntegerValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => Constants.PropertyEditors.IntegerAlias.Equals(propertyType.PropertyEditorAlias); + => Constants.PropertyEditors.IntegerAlias.Equals(propertyType.EditorAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (int); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs index a5f2ac3fc5..de695dd4d5 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/JsonValueConverter.cs @@ -23,7 +23,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters /// public override bool IsConverter(PublishedPropertyType propertyType) { - var propertyEditor = Current.PropertyEditors[propertyType.PropertyEditorAlias]; + var propertyEditor = Current.PropertyEditors[propertyType.EditorAlias]; if (propertyEditor == null) return false; return propertyEditor.ValueEditor.ValueType.InvariantEquals(PropertyEditorValueTypes.Json); } diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs index 23f80993e4..63faf19375 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/LabelValueConverter.cs @@ -16,7 +16,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class LabelValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => Constants.PropertyEditors.NoEditAlias.Equals(propertyType.PropertyEditorAlias); + => Constants.PropertyEditors.NoEditAlias.Equals(propertyType.EditorAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (string); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs index 349b32d331..8b6870ba46 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class MarkdownEditorValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => Constants.PropertyEditors.MarkdownEditorAlias.Equals(propertyType.PropertyEditorAlias); + => Constants.PropertyEditors.MarkdownEditorAlias.Equals(propertyType.EditorAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (IHtmlString); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberGroupPickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberGroupPickerValueConverter.cs index 4f63d2a774..4b3965522e 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberGroupPickerValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MemberGroupPickerValueConverter.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class MemberGroupPickerValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.MemberGroupPickerAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.MemberGroupPickerAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (string); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MultipleTextStringValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MultipleTextStringValueConverter.cs index 839281dc99..f581a68dea 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MultipleTextStringValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MultipleTextStringValueConverter.cs @@ -10,7 +10,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class MultipleTextStringValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => Constants.PropertyEditors.MultipleTextstringAlias.Equals(propertyType.PropertyEditorAlias); + => Constants.PropertyEditors.MultipleTextstringAlias.Equals(propertyType.EditorAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (IEnumerable); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MustBeStringValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MustBeStringValueConverter.cs index e27e313e9a..ac4468d8e3 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MustBeStringValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/MustBeStringValueConverter.cs @@ -24,7 +24,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters }; public override bool IsConverter(PublishedPropertyType propertyType) - => Aliases.Contains(propertyType.PropertyEditorAlias); + => Aliases.Contains(propertyType.EditorAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (string); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/RadioButtonListValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/RadioButtonListValueConverter.cs index f48b342636..d71d72c980 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/RadioButtonListValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/RadioButtonListValueConverter.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class RadioButtonListValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.RadioButtonListAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.RadioButtonListAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (int); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs index 47ef12030e..66d46f0e13 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs @@ -19,10 +19,10 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters } public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.SliderAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.SliderAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) - => IsRangeDataType(propertyType.DataTypeId) ? typeof (Range) : typeof (decimal); + => IsRangeDataType(propertyType.DataType.Id) ? typeof (Range) : typeof (decimal); public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType) => PropertyCacheLevel.Element; @@ -32,7 +32,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters if (source == null) return null; - if (IsRangeDataType(propertyType.DataTypeId)) + if (IsRangeDataType(propertyType.DataType.Id)) { var rangeRawValues = source.ToString().Split(','); var minimumAttempt = rangeRawValues[0].TryConvertTo(); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/TagsValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/TagsValueConverter.cs index 54ede366ff..4963aaf606 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/TagsValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/TagsValueConverter.cs @@ -20,7 +20,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters } public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.TagsAlias); + => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.TagsAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (IEnumerable); @@ -31,7 +31,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview) { // if Json storage type deserialzie and return as string array - if (JsonStorageType(propertyType.DataTypeId)) + if (JsonStorageType(propertyType.DataType.Id)) { var jArray = JsonConvert.DeserializeObject(source.ToString()); return jArray.ToObject(); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/TextStringValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/TextStringValueConverter.cs index bd07b55fb6..5ec9ef2f3c 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/TextStringValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/TextStringValueConverter.cs @@ -14,7 +14,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters }; public override bool IsConverter(PublishedPropertyType propertyType) - => PropertyTypeAliases.Contains(propertyType.PropertyEditorAlias); + => PropertyTypeAliases.Contains(propertyType.EditorAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (string); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/TinyMceValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/TinyMceValueConverter.cs index 420053c53d..bb1f0ed78a 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/TinyMceValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/TinyMceValueConverter.cs @@ -11,7 +11,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class TinyMceValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias == Constants.PropertyEditors.TinyMCEAlias; + => propertyType.EditorAlias == Constants.PropertyEditors.TinyMCEAlias; public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (IHtmlString); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/UploadPropertyConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/UploadPropertyConverter.cs index b37a5ea977..8ecdedad33 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/UploadPropertyConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/UploadPropertyConverter.cs @@ -10,7 +10,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class UploadPropertyConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.UploadFieldAlias); + => propertyType.EditorAlias.Equals(Constants.PropertyEditors.UploadFieldAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (string); diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs index d643c190af..795d4e4abb 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.PropertyEditors.ValueConverters public class YesNoValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias == Constants.PropertyEditors.TrueFalseAlias; + => propertyType.EditorAlias == Constants.PropertyEditors.TrueFalseAlias; public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (bool); diff --git a/src/Umbraco.Core/Services/EntityXmlSerializer.cs b/src/Umbraco.Core/Services/EntityXmlSerializer.cs index a7e44e77e2..a152fa29e3 100644 --- a/src/Umbraco.Core/Services/EntityXmlSerializer.cs +++ b/src/Umbraco.Core/Services/EntityXmlSerializer.cs @@ -133,10 +133,10 @@ namespace Umbraco.Core.Services return xml; } - public XElement Serialize(IDataTypeService dataTypeService, IDataTypeDefinition dataTypeDefinition) + public XElement Serialize(IDataTypeService dataTypeService, IDataType dataType) { var prevalues = new XElement("PreValues"); - var prevalueList = dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id) + var prevalueList = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id) .FormatAsDictionary(); var sort = 0; @@ -152,17 +152,17 @@ namespace Umbraco.Core.Services } var xml = new XElement("DataType", prevalues); - xml.Add(new XAttribute("Name", dataTypeDefinition.Name)); + xml.Add(new XAttribute("Name", dataType.Name)); //The 'ID' when exporting is actually the property editor alias (in pre v7 it was the IDataType GUID id) - xml.Add(new XAttribute("Id", dataTypeDefinition.PropertyEditorAlias)); - xml.Add(new XAttribute("Definition", dataTypeDefinition.Key)); - xml.Add(new XAttribute("DatabaseType", dataTypeDefinition.DatabaseType.ToString())); + xml.Add(new XAttribute("Id", dataType.EditorAlias)); + xml.Add(new XAttribute("Definition", dataType.Key)); + xml.Add(new XAttribute("DatabaseType", dataType.DatabaseType.ToString())); var folderNames = string.Empty; - if (dataTypeDefinition.Level != 1) + if (dataType.Level != 1) { //get url encoded folder names - var folders = dataTypeService.GetContainers(dataTypeDefinition) + var folders = dataTypeService.GetContainers(dataType) .OrderBy(x => x.Level) .Select(x => HttpUtility.UrlEncode(x.Name)); diff --git a/src/Umbraco.Core/Services/IDataTypeService.cs b/src/Umbraco.Core/Services/IDataTypeService.cs index 660e06b365..6f3f41b817 100644 --- a/src/Umbraco.Core/Services/IDataTypeService.cs +++ b/src/Umbraco.Core/Services/IDataTypeService.cs @@ -5,7 +5,7 @@ using Umbraco.Core.Models; namespace Umbraco.Core.Services { /// - /// Defines the DataType Service, which is an easy access to operations involving + /// Defines the DataType Service, which is an easy access to operations involving /// public interface IDataTypeService : IService { @@ -14,83 +14,83 @@ namespace Umbraco.Core.Services EntityContainer GetContainer(int containerId); EntityContainer GetContainer(Guid containerId); IEnumerable GetContainers(string folderName, int level); - IEnumerable GetContainers(IDataTypeDefinition dataTypeDefinition); + IEnumerable GetContainers(IDataType dataType); IEnumerable GetContainers(int[] containerIds); Attempt DeleteContainer(int containerId, int userId = 0); Attempt> RenameContainer(int id, string name, int userId = 0); /// - /// Gets a by its Name + /// Gets a by its Name /// - /// Name of the - /// - IDataTypeDefinition GetDataTypeDefinitionByName(string name); + /// Name of the + /// + IDataType GetDataTypeDefinitionByName(string name); /// - /// Gets a by its Id + /// Gets a by its Id /// - /// Id of the - /// - IDataTypeDefinition GetDataTypeDefinitionById(int id); + /// Id of the + /// + IDataType GetDataTypeDefinitionById(int id); /// - /// Gets a by its unique guid Id + /// Gets a by its unique guid Id /// /// Unique guid Id of the DataType - /// - IDataTypeDefinition GetDataTypeDefinitionById(Guid id); + /// + IDataType GetDataTypeDefinitionById(Guid id); /// - /// Gets all objects or those with the ids passed in + /// Gets all objects or those with the ids passed in /// /// Optional array of Ids - /// An enumerable list of objects - IEnumerable GetAllDataTypeDefinitions(params int[] ids); + /// An enumerable list of objects + IEnumerable GetAllDataTypeDefinitions(params int[] ids); /// - /// Saves an + /// Saves an /// - /// to save + /// to save /// Id of the user issueing the save - void Save(IDataTypeDefinition dataTypeDefinition, int userId = 0); + void Save(IDataType dataType, int userId = 0); /// - /// Saves a collection of + /// Saves a collection of /// - /// to save + /// to save /// Id of the user issueing the save - void Save(IEnumerable dataTypeDefinitions, int userId = 0); + void Save(IEnumerable dataTypeDefinitions, int userId = 0); /// - /// Saves a collection of + /// Saves a collection of /// - /// to save + /// to save /// Id of the user issueing the save /// Boolean indicating whether or not to raise events - void Save(IEnumerable dataTypeDefinitions, int userId, bool raiseEvents); + void Save(IEnumerable dataTypeDefinitions, int userId, bool raiseEvents); /// - /// Deletes an + /// Deletes an /// /// - /// Please note that deleting a will remove - /// all the data that references this . + /// Please note that deleting a will remove + /// all the data that references this . /// - /// to delete + /// to delete /// Id of the user issueing the deletion - void Delete(IDataTypeDefinition dataTypeDefinition, int userId = 0); + void Delete(IDataType dataType, int userId = 0); /// - /// Gets a by its control Id + /// Gets a by its control Id /// /// Alias of the property editor - /// Collection of objects with a matching contorl id - IEnumerable GetDataTypeDefinitionByPropertyEditorAlias(string propertyEditorAlias); + /// Collection of objects with a matching contorl id + IEnumerable GetDataTypeDefinitionByPropertyEditorAlias(string propertyEditorAlias); /// - /// Gets all values for an + /// Gets all values for an /// - /// Id of the to retrieve prevalues from + /// Id of the to retrieve prevalues from /// An enumerable list of string values IEnumerable GetPreValuesByDataTypeId(int id); @@ -119,17 +119,17 @@ namespace Umbraco.Core.Services /// /// Saves a list of PreValues for a given DataTypeDefinition /// - /// The DataTypeDefinition to save PreValues for + /// The DataTypeDefinition to save PreValues for /// List of key/value pairs to save - void SavePreValues(IDataTypeDefinition dataTypeDefinition, IDictionary values); + void SavePreValues(IDataType dataType, IDictionary values); /// /// Saves the data type and it's prevalues /// - /// + /// /// /// - void SaveDataTypeAndPreValues(IDataTypeDefinition dataTypeDefinition, IDictionary values, int userId = 0); + void SaveDataTypeAndPreValues(IDataType dataType, IDictionary values, int userId = 0); /// /// Gets a specific PreValue by its Id @@ -138,7 +138,7 @@ namespace Umbraco.Core.Services /// PreValue as a string string GetPreValueAsString(int id); - Attempt> Move(IDataTypeDefinition toMove, int parentId); + Attempt> Move(IDataType toMove, int parentId); } } diff --git a/src/Umbraco.Core/Services/IEntityService.cs b/src/Umbraco.Core/Services/IEntityService.cs index 5b9fdef86a..38eb2a0f05 100644 --- a/src/Umbraco.Core/Services/IEntityService.cs +++ b/src/Umbraco.Core/Services/IEntityService.cs @@ -252,12 +252,12 @@ namespace Umbraco.Core.Services /// /// Gets paths for entities. /// - IEnumerable GetAllPaths(UmbracoObjectTypes umbracoObjectType, params int[] ids); + IEnumerable GetAllPaths(UmbracoObjectTypes umbracoObjectType, params int[] ids); /// /// Gets paths for entities. /// - IEnumerable GetAllPaths(UmbracoObjectTypes umbracoObjectType, params Guid[] keys); + IEnumerable GetAllPaths(UmbracoObjectTypes umbracoObjectType, params Guid[] keys); /// /// Gets the UmbracoObjectType from the integer id of an IUmbracoEntity. diff --git a/src/Umbraco.Core/Services/IPackagingService.cs b/src/Umbraco.Core/Services/IPackagingService.cs index 5a527c1983..ceab6e94bf 100644 --- a/src/Umbraco.Core/Services/IPackagingService.cs +++ b/src/Umbraco.Core/Services/IPackagingService.cs @@ -37,13 +37,13 @@ namespace Umbraco.Core.Services IEnumerable ImportContentTypes(XElement element, bool importStructure, int userId = 0, bool raiseEvents = true); /// - /// Imports and saves package xml as + /// Imports and saves package xml as /// /// Xml to import /// Optional id of the User performing the operation. Default is zero (admin). /// Optional parameter indicating whether or not to raise events /// An enumrable list of generated DataTypeDefinitions - IEnumerable ImportDataTypeDefinitions(XElement element, int userId = 0, bool raiseEvents = true); + IEnumerable ImportDataTypeDefinitions(XElement element, int userId = 0, bool raiseEvents = true); /// /// Imports and saves the 'DictionaryItems' part of the package xml as a list of @@ -146,15 +146,15 @@ namespace Umbraco.Core.Services /// List of data types to export /// Optional parameter indicating whether or not to raise events /// containing the xml representation of the IDataTypeDefinition objects - XElement Export(IEnumerable dataTypeDefinitions, bool raiseEvents = true); + XElement Export(IEnumerable dataTypeDefinitions, bool raiseEvents = true); /// /// Exports a single Data Type /// - /// Data type to export + /// Data type to export /// Optional parameter indicating whether or not to raise events /// containing the xml representation of the IDataTypeDefinition object - XElement Export(IDataTypeDefinition dataTypeDefinition, bool raiseEvents = true); + XElement Export(IDataType dataType, bool raiseEvents = true); /// /// Exports a list of items to xml as an diff --git a/src/Umbraco.Core/Services/Implement/ContentService.cs b/src/Umbraco.Core/Services/Implement/ContentService.cs index 5e0efc4223..e4337f9dac 100644 --- a/src/Umbraco.Core/Services/Implement/ContentService.cs +++ b/src/Umbraco.Core/Services/Implement/ContentService.cs @@ -198,35 +198,6 @@ namespace Umbraco.Core.Services.Implement return content; } - /// - /// Creates an object of a specified content type, at root. - /// - /// This method simply returns a new, non-persisted, IContent without any identity. It - /// is intended as a shortcut to creating new content objects that does not invoke a save - /// operation against the database. - /// - /// The name of the content object. - /// The alias of the content type. - /// The optional id of the user creating the content. - /// The content object. - public IContent CreateContent(string name, string contentTypeAlias, int userId = 0) - { - // not locking since not saving anything - - var contentType = GetContentType(contentTypeAlias); - if (contentType == null) - throw new ArgumentException("No content type with that alias.", nameof(contentTypeAlias)); - - var content = new Content(name, -1, contentType); - using (var scope = ScopeProvider.CreateScope()) - { - CreateContent(scope, content, null, userId, false); - scope.Complete(); - } - - return content; - } - /// /// Creates an object of a specified content type, under a parent. /// @@ -323,29 +294,15 @@ namespace Umbraco.Core.Services.Implement private void CreateContent(IScope scope, Content content, IContent parent, int userId, bool withIdentity) { - // NOTE: I really hate the notion of these Creating/Created events - they are so inconsistent, I've only just found - // out that in these 'WithIdentity' methods, the Saving/Saved events were not fired, wtf. Anyways, they're added now. - var newArgs = parent != null - ? new NewEventArgs(content, content.ContentType.Alias, parent) - : new NewEventArgs(content, content.ContentType.Alias, -1); - - if (scope.Events.DispatchCancelable(Creating, this, newArgs)) - { - content.WasCancelled = true; - return; - } - content.CreatorId = userId; content.WriterId = userId; if (withIdentity) { + // if saving is cancelled, content remains without an identity var saveEventArgs = new SaveEventArgs(content); if (scope.Events.DispatchCancelable(Saving, this, saveEventArgs, "Saving")) - { - content.WasCancelled = true; return; - } _documentRepository.Save(content); @@ -1903,12 +1860,6 @@ namespace Umbraco.Core.Services.Implement /// public static event TypedEventHandler> Saved; - /// - /// Occurs before Create - /// - [Obsolete("Use the Created event instead, the Creating and Created events both offer the same functionality, Creating event has been deprecated.")] - public static event TypedEventHandler> Creating; - /// /// Occurs after Create /// diff --git a/src/Umbraco.Core/Services/Implement/DataTypeService.cs b/src/Umbraco.Core/Services/Implement/DataTypeService.cs index 853c35f409..67b5387cbb 100644 --- a/src/Umbraco.Core/Services/Implement/DataTypeService.cs +++ b/src/Umbraco.Core/Services/Implement/DataTypeService.cs @@ -14,22 +14,22 @@ using Umbraco.Core.Scoping; namespace Umbraco.Core.Services.Implement { /// - /// Represents the DataType Service, which is an easy access to operations involving + /// Represents the DataType Service, which is an easy access to operations involving /// internal class DataTypeService : ScopeRepositoryService, IDataTypeService { - private readonly IDataTypeDefinitionRepository _dataTypeDefinitionRepository; + private readonly IDataTypeRepository _dataTypeRepository; private readonly IDataTypeContainerRepository _dataTypeContainerRepository; private readonly IContentTypeRepository _contentTypeRepository; private readonly IAuditRepository _auditRepository; private readonly IEntityRepository _entityRepository; public DataTypeService(IScopeProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory, - IDataTypeDefinitionRepository dataTypeDefinitionRepository, IDataTypeContainerRepository dataTypeContainerRepository, + IDataTypeRepository dataTypeRepository, IDataTypeContainerRepository dataTypeContainerRepository, IAuditRepository auditRepository, IEntityRepository entityRepository, IContentTypeRepository contentTypeRepository) : base(provider, logger, eventMessagesFactory) { - _dataTypeDefinitionRepository = dataTypeDefinitionRepository; + _dataTypeRepository = dataTypeRepository; _dataTypeContainerRepository = dataTypeContainerRepository; _auditRepository = auditRepository; _entityRepository = entityRepository; @@ -97,15 +97,15 @@ namespace Umbraco.Core.Services.Implement } } - public IEnumerable GetContainers(IDataTypeDefinition dataTypeDefinition) + public IEnumerable GetContainers(IDataType dataType) { - var ancestorIds = dataTypeDefinition.Path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) + var ancestorIds = dataType.Path.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => { var asInt = x.TryConvertTo(); return asInt ? asInt.Result : int.MinValue; }) - .Where(x => x != int.MinValue && x != dataTypeDefinition.Id) + .Where(x => x != int.MinValue && x != dataType.Id) .ToArray(); return GetContainers(ancestorIds); @@ -214,82 +214,82 @@ namespace Umbraco.Core.Services.Implement #endregion /// - /// Gets a by its Name + /// Gets a by its Name /// - /// Name of the - /// - public IDataTypeDefinition GetDataTypeDefinitionByName(string name) + /// Name of the + /// + public IDataType GetDataTypeDefinitionByName(string name) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { - return _dataTypeDefinitionRepository.Get(Query().Where(x => x.Name == name)).FirstOrDefault(); + return _dataTypeRepository.Get(Query().Where(x => x.Name == name)).FirstOrDefault(); } } /// - /// Gets a by its Id + /// Gets a by its Id /// - /// Id of the - /// - public IDataTypeDefinition GetDataTypeDefinitionById(int id) + /// Id of the + /// + public IDataType GetDataTypeDefinitionById(int id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { - return _dataTypeDefinitionRepository.Get(id); + return _dataTypeRepository.Get(id); } } /// - /// Gets a by its unique guid Id + /// Gets a by its unique guid Id /// /// Unique guid Id of the DataType - /// - public IDataTypeDefinition GetDataTypeDefinitionById(Guid id) + /// + public IDataType GetDataTypeDefinitionById(Guid id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { - var query = Query().Where(x => x.Key == id); - return _dataTypeDefinitionRepository.Get(query).FirstOrDefault(); + var query = Query().Where(x => x.Key == id); + return _dataTypeRepository.Get(query).FirstOrDefault(); } } /// - /// Gets a by its control Id + /// Gets a by its control Id /// /// Alias of the property editor - /// Collection of objects with a matching contorl id - public IEnumerable GetDataTypeDefinitionByPropertyEditorAlias(string propertyEditorAlias) + /// Collection of objects with a matching contorl id + public IEnumerable GetDataTypeDefinitionByPropertyEditorAlias(string propertyEditorAlias) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { - var query = Query().Where(x => x.PropertyEditorAlias == propertyEditorAlias); - return _dataTypeDefinitionRepository.Get(query); + var query = Query().Where(x => x.EditorAlias == propertyEditorAlias); + return _dataTypeRepository.Get(query); } } /// - /// Gets all objects or those with the ids passed in + /// Gets all objects or those with the ids passed in /// /// Optional array of Ids - /// An enumerable list of objects - public IEnumerable GetAllDataTypeDefinitions(params int[] ids) + /// An enumerable list of objects + public IEnumerable GetAllDataTypeDefinitions(params int[] ids) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { - return _dataTypeDefinitionRepository.GetMany(ids); + return _dataTypeRepository.GetMany(ids); } } /// - /// Gets all prevalues for an + /// Gets all prevalues for an /// - /// Id of the to retrieve prevalues from + /// Id of the to retrieve prevalues from /// An enumerable list of string values public IEnumerable GetPreValuesByDataTypeId(int id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { - var collection = _dataTypeDefinitionRepository.GetPreValuesCollectionByDataTypeId(id); + var collection = _dataTypeRepository.GetPreValuesCollectionByDataTypeId(id); //now convert the collection to a string list return collection.FormatAsDictionary() .Select(x => x.Value.Value) @@ -306,7 +306,7 @@ namespace Umbraco.Core.Services.Implement { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { - return _dataTypeDefinitionRepository.GetPreValuesCollectionByDataTypeId(id); + return _dataTypeRepository.GetPreValuesCollectionByDataTypeId(id); } } @@ -319,19 +319,19 @@ namespace Umbraco.Core.Services.Implement { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) { - return _dataTypeDefinitionRepository.GetPreValueAsString(id); + return _dataTypeRepository.GetPreValueAsString(id); } } - public Attempt> Move(IDataTypeDefinition toMove, int parentId) + public Attempt> Move(IDataType toMove, int parentId) { var evtMsgs = EventMessagesFactory.Get(); - var moveInfo = new List>(); + var moveInfo = new List>(); using (var scope = ScopeProvider.CreateScope()) { - var moveEventInfo = new MoveEventInfo(toMove, toMove.Path, parentId); - var moveEventArgs = new MoveEventArgs(evtMsgs, moveEventInfo); + var moveEventInfo = new MoveEventInfo(toMove, toMove.Path, parentId); + var moveEventArgs = new MoveEventArgs(evtMsgs, moveEventInfo); if (scope.Events.DispatchCancelable(Moving, this, moveEventArgs)) { scope.Complete(); @@ -347,7 +347,7 @@ namespace Umbraco.Core.Services.Implement if (container == null) throw new DataOperationException(MoveOperationStatusType.FailedParentNotFound); // causes rollback } - moveInfo.AddRange(_dataTypeDefinitionRepository.Move(toMove, container)); + moveInfo.AddRange(_dataTypeRepository.Move(toMove, container)); moveEventArgs.MoveInfoCollection = moveInfo; moveEventArgs.CanCancel = false; @@ -365,57 +365,57 @@ namespace Umbraco.Core.Services.Implement } /// - /// Saves an + /// Saves an /// - /// to save + /// to save /// Id of the user issueing the save - public void Save(IDataTypeDefinition dataTypeDefinition, int userId = 0) + public void Save(IDataType dataType, int userId = 0) { - dataTypeDefinition.CreatorId = userId; + dataType.CreatorId = userId; using (var scope = ScopeProvider.CreateScope()) { - var saveEventArgs = new SaveEventArgs(dataTypeDefinition); + var saveEventArgs = new SaveEventArgs(dataType); if (scope.Events.DispatchCancelable(Saving, this, saveEventArgs)) { scope.Complete(); return; } - if (string.IsNullOrWhiteSpace(dataTypeDefinition.Name)) + if (string.IsNullOrWhiteSpace(dataType.Name)) { throw new ArgumentException("Cannot save datatype with empty name."); } - _dataTypeDefinitionRepository.Save(dataTypeDefinition); + _dataTypeRepository.Save(dataType); saveEventArgs.CanCancel = false; scope.Events.Dispatch(Saved, this, saveEventArgs); - Audit(AuditType.Save, "Save DataTypeDefinition performed by user", userId, dataTypeDefinition.Id); + Audit(AuditType.Save, "Save DataTypeDefinition performed by user", userId, dataType.Id); scope.Complete(); } } /// - /// Saves a collection of + /// Saves a collection of /// - /// to save + /// to save /// Id of the user issueing the save - public void Save(IEnumerable dataTypeDefinitions, int userId = 0) + public void Save(IEnumerable dataTypeDefinitions, int userId = 0) { Save(dataTypeDefinitions, userId, true); } /// - /// Saves a collection of + /// Saves a collection of /// - /// to save + /// to save /// Id of the user issueing the save /// Boolean indicating whether or not to raise events - public void Save(IEnumerable dataTypeDefinitions, int userId, bool raiseEvents) + public void Save(IEnumerable dataTypeDefinitions, int userId, bool raiseEvents) { var dataTypeDefinitionsA = dataTypeDefinitions.ToArray(); - var saveEventArgs = new SaveEventArgs(dataTypeDefinitionsA); + var saveEventArgs = new SaveEventArgs(dataTypeDefinitionsA); using (var scope = ScopeProvider.CreateScope()) { @@ -428,7 +428,7 @@ namespace Umbraco.Core.Services.Implement foreach (var dataTypeDefinition in dataTypeDefinitionsA) { dataTypeDefinition.CreatorId = userId; - _dataTypeDefinitionRepository.Save(dataTypeDefinition); + _dataTypeRepository.Save(dataTypeDefinition); } if (raiseEvents) @@ -492,19 +492,19 @@ namespace Umbraco.Core.Services.Implement /// /// Saves/updates the pre-values /// - /// + /// /// /// /// We need to actually look up each pre-value and maintain it's id if possible - this is because of silly property editors /// like 'dropdown list publishing keys' /// - public void SavePreValues(IDataTypeDefinition dataTypeDefinition, IDictionary values) + public void SavePreValues(IDataType dataType, IDictionary values) { //TODO: Should we raise an event here since we are really saving values for the data type? using (var scope = ScopeProvider.CreateScope()) { - _dataTypeDefinitionRepository.AddOrUpdatePreValues(dataTypeDefinition, values); + _dataTypeRepository.AddOrUpdatePreValues(dataType, values); scope.Complete(); } } @@ -512,14 +512,14 @@ namespace Umbraco.Core.Services.Implement /// /// This will save a data type and it's pre-values in one transaction /// - /// + /// /// /// - public void SaveDataTypeAndPreValues(IDataTypeDefinition dataTypeDefinition, IDictionary values, int userId = 0) + public void SaveDataTypeAndPreValues(IDataType dataType, IDictionary values, int userId = 0) { using (var scope = ScopeProvider.CreateScope()) { - var saveEventArgs = new SaveEventArgs(dataTypeDefinition); + var saveEventArgs = new SaveEventArgs(dataType); if (scope.Events.DispatchCancelable(Saving, this, saveEventArgs)) { scope.Complete(); @@ -528,35 +528,35 @@ namespace Umbraco.Core.Services.Implement // if preValues contain the data type, override the data type definition accordingly if (values != null && values.ContainsKey(Constants.PropertyEditors.PreValueKeys.DataValueType)) - dataTypeDefinition.DatabaseType = PropertyValueEditor.GetDatabaseType(values[Constants.PropertyEditors.PreValueKeys.DataValueType].Value); + dataType.DatabaseType = PropertyValueEditor.GetDatabaseType(values[Constants.PropertyEditors.PreValueKeys.DataValueType].Value); - dataTypeDefinition.CreatorId = userId; + dataType.CreatorId = userId; - _dataTypeDefinitionRepository.Save(dataTypeDefinition); // definition - _dataTypeDefinitionRepository.AddOrUpdatePreValues(dataTypeDefinition, values); //prevalues + _dataTypeRepository.Save(dataType); // definition + _dataTypeRepository.AddOrUpdatePreValues(dataType, values); //prevalues saveEventArgs.CanCancel = false; scope.Events.Dispatch(Saved, this, saveEventArgs); - Audit(AuditType.Save, "Save DataTypeDefinition performed by user", userId, dataTypeDefinition.Id); + Audit(AuditType.Save, "Save DataTypeDefinition performed by user", userId, dataType.Id); scope.Complete(); } } /// - /// Deletes an + /// Deletes an /// /// - /// Please note that deleting a will remove - /// all the data that references this . + /// Please note that deleting a will remove + /// all the data that references this . /// - /// to delete + /// to delete /// Optional Id of the user issueing the deletion - public void Delete(IDataTypeDefinition dataTypeDefinition, int userId = 0) + public void Delete(IDataType dataType, int userId = 0) { using (var scope = ScopeProvider.CreateScope()) { - var deleteEventArgs = new DeleteEventArgs(dataTypeDefinition); + var deleteEventArgs = new DeleteEventArgs(dataType); if (scope.Events.DispatchCancelable(Deleting, this, deleteEventArgs)) { scope.Complete(); @@ -567,13 +567,13 @@ namespace Umbraco.Core.Services.Implement // find ContentTypes using this IDataTypeDefinition on a PropertyType, and delete // fixme - media and members?! // fixme - non-group properties?! - var query = Query().Where(x => x.DataTypeDefinitionId == dataTypeDefinition.Id); + var query = Query().Where(x => x.DataTypeDefinitionId == dataType.Id); var contentTypes = _contentTypeRepository.GetByQuery(query); foreach (var contentType in contentTypes) { foreach (var propertyGroup in contentType.PropertyGroups) { - var types = propertyGroup.PropertyTypes.Where(x => x.DataTypeDefinitionId == dataTypeDefinition.Id).ToList(); + var types = propertyGroup.PropertyTypes.Where(x => x.DataTypeDefinitionId == dataType.Id).ToList(); foreach (var propertyType in types) { propertyGroup.PropertyTypes.Remove(propertyType); @@ -591,11 +591,11 @@ namespace Umbraco.Core.Services.Implement _contentTypeRepository.Save(contentType); } - _dataTypeDefinitionRepository.Delete(dataTypeDefinition); + _dataTypeRepository.Delete(dataType); deleteEventArgs.CanCancel = false; scope.Events.Dispatch(Deleted, this, deleteEventArgs); - Audit(AuditType.Delete, "Delete DataTypeDefinition performed by user", userId, dataTypeDefinition.Id); + Audit(AuditType.Delete, "Delete DataTypeDefinition performed by user", userId, dataType.Id); scope.Complete(); } @@ -616,32 +616,32 @@ namespace Umbraco.Core.Services.Implement /// /// Occurs before Delete /// - public static event TypedEventHandler> Deleting; + public static event TypedEventHandler> Deleting; /// /// Occurs after Delete /// - public static event TypedEventHandler> Deleted; + public static event TypedEventHandler> Deleted; /// /// Occurs before Save /// - public static event TypedEventHandler> Saving; + public static event TypedEventHandler> Saving; /// /// Occurs after Save /// - public static event TypedEventHandler> Saved; + public static event TypedEventHandler> Saved; /// /// Occurs before Move /// - public static event TypedEventHandler> Moving; + public static event TypedEventHandler> Moving; /// /// Occurs after Move /// - public static event TypedEventHandler> Moved; + public static event TypedEventHandler> Moved; #endregion } } diff --git a/src/Umbraco.Core/Services/Implement/EntityService.cs b/src/Umbraco.Core/Services/Implement/EntityService.cs index e1190701d5..e6190f9a8b 100644 --- a/src/Umbraco.Core/Services/Implement/EntityService.cs +++ b/src/Umbraco.Core/Services/Implement/EntityService.cs @@ -39,7 +39,7 @@ namespace Umbraco.Core.Services.Implement _supportedObjectTypes = new Dictionary>> { - {typeof (IDataTypeDefinition).FullName, new Tuple>(UmbracoObjectTypes.DataType, dataTypeService.GetDataTypeDefinitionById)}, + {typeof (IDataType).FullName, new Tuple>(UmbracoObjectTypes.DataType, dataTypeService.GetDataTypeDefinitionById)}, {typeof (IContent).FullName, new Tuple>(UmbracoObjectTypes.Document, contentService.GetById)}, {typeof (IContentType).FullName, new Tuple>(UmbracoObjectTypes.DocumentType, contentTypeService.Get)}, {typeof (IMedia).FullName, new Tuple>(UmbracoObjectTypes.Media, mediaService.GetById)}, @@ -547,7 +547,7 @@ namespace Umbraco.Core.Services.Implement } } - public virtual IEnumerable GetAllPaths(UmbracoObjectTypes umbracoObjectType, params int[] ids) + public virtual IEnumerable GetAllPaths(UmbracoObjectTypes umbracoObjectType, params int[] ids) { var entityType = GetEntityType(umbracoObjectType); var typeFullName = entityType.FullName; @@ -561,7 +561,7 @@ namespace Umbraco.Core.Services.Implement } } - public virtual IEnumerable GetAllPaths(UmbracoObjectTypes umbracoObjectType, params Guid[] keys) + public virtual IEnumerable GetAllPaths(UmbracoObjectTypes umbracoObjectType, params Guid[] keys) { var entityType = GetEntityType(umbracoObjectType); var typeFullName = entityType.FullName; diff --git a/src/Umbraco.Core/Services/Implement/MediaService.cs b/src/Umbraco.Core/Services/Implement/MediaService.cs index 497eee43c3..78c3032df2 100644 --- a/src/Umbraco.Core/Services/Implement/MediaService.cs +++ b/src/Umbraco.Core/Services/Implement/MediaService.cs @@ -274,28 +274,14 @@ namespace Umbraco.Core.Services.Implement private void CreateMedia(IScope scope, Models.Media media, IMedia parent, int userId, bool withIdentity) { - // NOTE: I really hate the notion of these Creating/Created events - they are so inconsistent, I've only just found - // out that in these 'WithIdentity' methods, the Saving/Saved events were not fired, wtf. Anyways, they're added now. - var newArgs = parent != null - ? new NewEventArgs(media, media.ContentType.Alias, parent) - : new NewEventArgs(media, media.ContentType.Alias, -1); - - if (scope.Events.DispatchCancelable(Creating, this, newArgs)) - { - media.WasCancelled = true; - return; - } - media.CreatorId = userId; if (withIdentity) { + // if saving is cancelled, media remains without an identity var saveEventArgs = new SaveEventArgs(media); if (Saving.IsRaisedEventCancelled(saveEventArgs, this)) - { - media.WasCancelled = true; return; - } _mediaRepository.Save(media); @@ -304,14 +290,12 @@ namespace Umbraco.Core.Services.Implement scope.Events.Dispatch(TreeChanged, this, new TreeChange(media, TreeChangeTypes.RefreshNode).ToEventArgs()); } - newArgs.CanCancel = false; - scope.Events.Dispatch(Created, this, newArgs); + scope.Events.Dispatch(Created, this, new NewEventArgs(media, false, media.ContentType.Alias, parent)); - var msg = withIdentity - ? "Media '{0}' was created with Id {1}" - : "Media '{0}' was created"; + if (withIdentity == false) + return; - Audit(AuditType.New, string.Format(msg, media.Name, media.Id), media.CreatorId, media.Id); + Audit(AuditType.New, $"Media '{media.Name}' was created with Id {media.Id}", media.CreatorId, media.Id); } #endregion @@ -1389,12 +1373,6 @@ namespace Umbraco.Core.Services.Implement /// public static event TypedEventHandler> Saved; - /// - /// Occurs before Create - /// - [Obsolete("Use the Created event instead, the Creating and Created events both offer the same functionality, Creating event has been deprecated.")] - public static event TypedEventHandler> Creating; - /// /// Occurs after Create /// diff --git a/src/Umbraco.Core/Services/Implement/MemberService.cs b/src/Umbraco.Core/Services/Implement/MemberService.cs index 2908824379..e976c8c430 100644 --- a/src/Umbraco.Core/Services/Implement/MemberService.cs +++ b/src/Umbraco.Core/Services/Implement/MemberService.cs @@ -316,18 +316,14 @@ namespace Umbraco.Core.Services.Implement private void CreateMember(IScope scope, Member member, int userId, bool withIdentity) { - // there's no Creating event for members - member.CreatorId = userId; if (withIdentity) { + // if saving is cancelled, media remains without an identity var saveEventArgs = new SaveEventArgs(member); if (scope.Events.DispatchCancelable(Saving, this, saveEventArgs)) - { - member.WasCancelled = true; return; - } _memberRepository.Save(member); @@ -337,10 +333,10 @@ namespace Umbraco.Core.Services.Implement scope.Events.Dispatch(Created, this, new NewEventArgs(member, false, member.ContentType.Alias, -1)); - var msg = withIdentity - ? "Member '{0}' was created with Id {1}" - : "Member '{0}' was created"; - Audit(AuditType.New, string.Format(msg, member.Name, member.Id), member.CreatorId, member.Id); + if (withIdentity == false) + return; + + Audit(AuditType.New, $"Member '{member.Name}' was created with Id {member.Id}", member.CreatorId, member.Id); } #endregion diff --git a/src/Umbraco.Core/Services/Implement/PackagingService.cs b/src/Umbraco.Core/Services/Implement/PackagingService.cs index 32340d77d9..4c1ea6d5ba 100644 --- a/src/Umbraco.Core/Services/Implement/PackagingService.cs +++ b/src/Umbraco.Core/Services/Implement/PackagingService.cs @@ -704,7 +704,7 @@ namespace Umbraco.Core.Services.Implement dataTypeDefinition = dataTypeDefinitions.FirstOrDefault(); } } - else if (dataTypeDefinition.PropertyEditorAlias != propertyEditorAlias) + else if (dataTypeDefinition.EditorAlias != propertyEditorAlias) { var dataTypeDefinitions = _dataTypeService.GetDataTypeDefinitionByPropertyEditorAlias(propertyEditorAlias); if (dataTypeDefinitions != null && dataTypeDefinitions.Any()) @@ -812,7 +812,7 @@ namespace Umbraco.Core.Services.Implement /// List of data types to export /// Optional parameter indicating whether or not to raise events /// containing the xml representation of the IDataTypeDefinition objects - public XElement Export(IEnumerable dataTypeDefinitions, bool raiseEvents = true) + public XElement Export(IEnumerable dataTypeDefinitions, bool raiseEvents = true) { var container = new XElement("DataTypes"); foreach (var dataTypeDefinition in dataTypeDefinitions) @@ -825,39 +825,39 @@ namespace Umbraco.Core.Services.Implement /// /// Exports a single Data Type /// - /// Data type to export + /// Data type to export /// Optional parameter indicating whether or not to raise events /// containing the xml representation of the IDataTypeDefinition object - public XElement Export(IDataTypeDefinition dataTypeDefinition, bool raiseEvents = true) + public XElement Export(IDataType dataType, bool raiseEvents = true) { if (raiseEvents) { - if (ExportingDataType.IsRaisedEventCancelled(new ExportEventArgs(dataTypeDefinition, "DataType"), this)) + if (ExportingDataType.IsRaisedEventCancelled(new ExportEventArgs(dataType, "DataType"), this)) return new XElement("DataType"); } var exporter = new EntityXmlSerializer(); - var xml = exporter.Serialize(_dataTypeService, dataTypeDefinition); + var xml = exporter.Serialize(_dataTypeService, dataType); if (raiseEvents) - ExportedDataType.RaiseEvent(new ExportEventArgs(dataTypeDefinition, xml, false), this); + ExportedDataType.RaiseEvent(new ExportEventArgs(dataType, xml, false), this); return xml; } /// - /// Imports and saves package xml as + /// Imports and saves package xml as /// /// Xml to import /// Optional id of the user /// Optional parameter indicating whether or not to raise events /// An enumrable list of generated DataTypeDefinitions - public IEnumerable ImportDataTypeDefinitions(XElement element, int userId = 0, bool raiseEvents = true) + public IEnumerable ImportDataTypeDefinitions(XElement element, int userId = 0, bool raiseEvents = true) { if (raiseEvents) { - if (ImportingDataType.IsRaisedEventCancelled(new ImportEventArgs(element), this)) - return Enumerable.Empty(); + if (ImportingDataType.IsRaisedEventCancelled(new ImportEventArgs(element), this)) + return Enumerable.Empty(); } var name = element.Name.LocalName; @@ -866,7 +866,7 @@ namespace Umbraco.Core.Services.Implement throw new ArgumentException("The passed in XElement is not valid! It does not contain a root element called 'DataTypes' for multiple imports or 'DataType' for a single import."); } - var dataTypes = new Dictionary(); + var dataTypes = new Dictionary(); var dataTypeElements = name.Equals("DataTypes") ? (from doc in element.Elements("DataType") select doc).ToList() : new List { element }; @@ -893,7 +893,7 @@ namespace Umbraco.Core.Services.Implement : DataTypeDatabaseType.Ntext; //the Id field is actually the string property editor Alias - var dataTypeDefinition = new DataTypeDefinition(dataTypeElement.Attribute("Id").Value.Trim()) + var dataTypeDefinition = new DataType(dataTypeElement.Attribute("Id").Value.Trim()) { Key = dataTypeDefinitionId, Name = dataTypeDefinitionName, @@ -925,7 +925,7 @@ namespace Umbraco.Core.Services.Implement } if (raiseEvents) - ImportedDataType.RaiseEvent(new ImportEventArgs(list, element, false), this); + ImportedDataType.RaiseEvent(new ImportEventArgs(list, element, false), this); return list; } @@ -988,7 +988,7 @@ namespace Umbraco.Core.Services.Implement return _dataTypeService.GetContainer(tryCreateFolder.Result.Entity.Id); } - private void SavePrevaluesFromXml(List dataTypes, IEnumerable dataTypeElements) + private void SavePrevaluesFromXml(List dataTypes, IEnumerable dataTypeElements) { foreach (var dataTypeElement in dataTypeElements) { @@ -1809,22 +1809,22 @@ namespace Umbraco.Core.Services.Implement /// /// Occurs before Importing DataType /// - public static event TypedEventHandler> ImportingDataType; + public static event TypedEventHandler> ImportingDataType; /// /// Occurs after DataType is Imported and Saved /// - public static event TypedEventHandler> ImportedDataType; + public static event TypedEventHandler> ImportedDataType; /// /// Occurs before Exporting DataType /// - public static event TypedEventHandler> ExportingDataType; + public static event TypedEventHandler> ExportingDataType; /// /// Occurs after DataType is Exported to Xml /// - public static event TypedEventHandler> ExportedDataType; + public static event TypedEventHandler> ExportedDataType; /// /// Occurs before Importing DictionaryItem diff --git a/src/Umbraco.Core/UdiGetterExtensions.cs b/src/Umbraco.Core/UdiGetterExtensions.cs index 5928664bb5..fd3d430132 100644 --- a/src/Umbraco.Core/UdiGetterExtensions.cs +++ b/src/Umbraco.Core/UdiGetterExtensions.cs @@ -86,7 +86,7 @@ namespace Umbraco.Core /// /// The entity. /// The entity identifier of the entity. - public static GuidUdi GetUdi(this IDataTypeDefinition entity) + public static GuidUdi GetUdi(this IDataType entity) { if (entity == null) throw new ArgumentNullException("entity"); return new GuidUdi(Constants.UdiEntityType.DataType, entity.Key).EnsureClosed(); @@ -287,7 +287,7 @@ namespace Umbraco.Core var contentTypeComposition = entity as IContentTypeComposition; if (contentTypeComposition != null) return contentTypeComposition.GetUdi(); - var dataTypeComposition = entity as IDataTypeDefinition; + var dataTypeComposition = entity as IDataType; if (dataTypeComposition != null) return dataTypeComposition.GetUdi(); var container = entity as EntityContainer; diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index b42b768be8..950133f2da 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -312,6 +312,9 @@ + + + @@ -549,23 +552,21 @@ - + - - - + + - - + @@ -576,7 +577,7 @@ - + @@ -821,7 +822,7 @@ - + @@ -865,7 +866,7 @@ - + @@ -1054,7 +1055,7 @@ - + @@ -1068,7 +1069,7 @@ - + diff --git a/src/Umbraco.Tests.Benchmarks/XmlPublishedContentInitBenchmarks.cs b/src/Umbraco.Tests.Benchmarks/XmlPublishedContentInitBenchmarks.cs index 6af5ab454a..918c8f55c6 100644 --- a/src/Umbraco.Tests.Benchmarks/XmlPublishedContentInitBenchmarks.cs +++ b/src/Umbraco.Tests.Benchmarks/XmlPublishedContentInitBenchmarks.cs @@ -296,11 +296,11 @@ namespace Umbraco.Tests.Benchmarks properties = contentType.PropertyTypes.Select(p => { XmlNode n; - return propertyNodes.TryGetValue(p.PropertyTypeAlias.ToLowerInvariant(), out n) + return propertyNodes.TryGetValue(p.Alias.ToLowerInvariant(), out n) ? new XmlPublishedProperty(p, null, isPreviewing, n) : new XmlPublishedProperty(p, null, isPreviewing); }).Cast().ToDictionary( - x => x.PropertyTypeAlias, + x => x.Alias, x => x, StringComparer.OrdinalIgnoreCase); } diff --git a/src/Umbraco.Tests/Cache/CacheRefresherComponentTests.cs b/src/Umbraco.Tests/Cache/CacheRefresherComponentTests.cs index e7175d744f..ee3e13e2cb 100644 --- a/src/Umbraco.Tests/Cache/CacheRefresherComponentTests.cs +++ b/src/Umbraco.Tests/Cache/CacheRefresherComponentTests.cs @@ -50,8 +50,8 @@ namespace Umbraco.Tests.Cache new EventDefinition>(null, serviceContext.LocalizationService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.LocalizationService, new DeleteEventArgs(Enumerable.Empty())), - new EventDefinition>(null, serviceContext.DataTypeService, new SaveEventArgs(Enumerable.Empty())), - new EventDefinition>(null, serviceContext.DataTypeService, new DeleteEventArgs(Enumerable.Empty())), + new EventDefinition>(null, serviceContext.DataTypeService, new SaveEventArgs(Enumerable.Empty())), + new EventDefinition>(null, serviceContext.DataTypeService, new DeleteEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.FileService, new SaveEventArgs(Enumerable.Empty())), new EventDefinition>(null, serviceContext.FileService, new DeleteEventArgs(Enumerable.Empty())), diff --git a/src/Umbraco.Tests/Cache/DeepCloneRuntimeCacheProviderTests.cs b/src/Umbraco.Tests/Cache/DeepCloneRuntimeCacheProviderTests.cs index f257858ed8..4fd4c49eb0 100644 --- a/src/Umbraco.Tests/Cache/DeepCloneRuntimeCacheProviderTests.cs +++ b/src/Umbraco.Tests/Cache/DeepCloneRuntimeCacheProviderTests.cs @@ -95,7 +95,7 @@ namespace Umbraco.Tests.Cache return "succ" + i; } - private class TestClass : TracksChangesEntityBase, IDeepCloneable + private class TestClass : BeingDirtyBase, IDeepCloneable { public TestClass() { diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs index 5822ebec88..136929d4cf 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs @@ -295,7 +295,7 @@ namespace Umbraco.Tests.Cache.PublishedCache // callback to get the children: we're not going to test this so ignore (dd, n) => new List(), // callback to get a property - (dd, a) => dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(a)), + (dd, a) => dd.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(a)), null, // cache provider ContentTypesCache, // no xpath @@ -305,7 +305,7 @@ namespace Umbraco.Tests.Cache.PublishedCache //callback to get the children (dd, n) => children, // callback to get a property - (dd, a) => dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(a)), + (dd, a) => dd.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(a)), null, // cache provider ContentTypesCache, // no xpath diff --git a/src/Umbraco.Tests/Misc/LibraryTests.cs b/src/Umbraco.Tests/Misc/LibraryTests.cs index bcdfc30c03..c6cf2204e2 100644 --- a/src/Umbraco.Tests/Misc/LibraryTests.cs +++ b/src/Umbraco.Tests/Misc/LibraryTests.cs @@ -38,7 +38,7 @@ namespace Umbraco.Tests.Misc // AutoPublishedContentType will auto-generate other properties factory.CreatePropertyType("content", 0, "?"), }; - var type = new AutoPublishedContentType(0, "anything", propertyTypes, factory); + var type = new AutoPublishedContentType(0, "anything", propertyTypes); ContentTypesCache.GetPublishedContentTypeByAlias = (alias) => type; Debug.Print("INIT LIB {0}", ContentTypesCache.Get(PublishedItemType.Content, "anything") diff --git a/src/Umbraco.Tests/Models/DataTypeDefinitionTests.cs b/src/Umbraco.Tests/Models/DataTypeTests.cs similarity index 90% rename from src/Umbraco.Tests/Models/DataTypeDefinitionTests.cs rename to src/Umbraco.Tests/Models/DataTypeTests.cs index a6a7827363..40689b451c 100644 --- a/src/Umbraco.Tests/Models/DataTypeDefinitionTests.cs +++ b/src/Umbraco.Tests/Models/DataTypeTests.cs @@ -8,12 +8,12 @@ using Umbraco.Core.Serialization; namespace Umbraco.Tests.Models { [TestFixture] - public class DataTypeDefinitionTests + public class DataTypeTests { [Test] public void Can_Deep_Clone() { - var dtd = new DataTypeDefinition(9, Guid.NewGuid().ToString()) + var dtd = new DataType(9, Guid.NewGuid().ToString()) { CreateDate = DateTime.Now, CreatorId = 5, @@ -28,7 +28,7 @@ namespace Umbraco.Tests.Models Trashed = true, UpdateDate = DateTime.Now }; - var clone = (DataTypeDefinition) dtd.DeepClone(); + var clone = (DataType) dtd.DeepClone(); Assert.AreNotSame(clone, dtd); Assert.AreEqual(clone, dtd); @@ -58,7 +58,7 @@ namespace Umbraco.Tests.Models { var ss = new SerializationService(new JsonNetSerializer()); - var dtd = new DataTypeDefinition(9, Guid.NewGuid().ToString()) + var dtd = new DataType(9, Guid.NewGuid().ToString()) { CreateDate = DateTime.Now, CreatorId = 5, diff --git a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs index 59c209266c..4318457811 100644 --- a/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs +++ b/src/Umbraco.Tests/Models/Mapping/ContentTypeModelMappingTests.cs @@ -91,10 +91,10 @@ namespace Umbraco.Tests.Models.Mapping // setup the mocks to return the data we want to test against... _dataTypeService.Setup(x => x.GetDataTypeDefinitionById(It.IsAny())) - .Returns(Mock.Of( + .Returns(Mock.Of( definition => definition.Id == 555 - && definition.PropertyEditorAlias == "myPropertyType" + && definition.EditorAlias == "myPropertyType" && definition.DatabaseType == DataTypeDatabaseType.Nvarchar)); var display = CreateMemberTypeSave(); @@ -150,10 +150,10 @@ namespace Umbraco.Tests.Models.Mapping // setup the mocks to return the data we want to test against... _dataTypeService.Setup(x => x.GetDataTypeDefinitionById(It.IsAny())) - .Returns(Mock.Of( + .Returns(Mock.Of( definition => definition.Id == 555 - && definition.PropertyEditorAlias == "myPropertyType" + && definition.EditorAlias == "myPropertyType" && definition.DatabaseType == DataTypeDatabaseType.Nvarchar)); var display = CreateMediaTypeSave(); @@ -207,10 +207,10 @@ namespace Umbraco.Tests.Models.Mapping // setup the mocks to return the data we want to test against... _dataTypeService.Setup(x => x.GetDataTypeDefinitionById(It.IsAny())) - .Returns(Mock.Of( + .Returns(Mock.Of( definition => definition.Id == 555 - && definition.PropertyEditorAlias == "myPropertyType" + && definition.EditorAlias == "myPropertyType" && definition.DatabaseType == DataTypeDatabaseType.Nvarchar)); @@ -281,10 +281,10 @@ namespace Umbraco.Tests.Models.Mapping // setup the mocks to return the data we want to test against... _dataTypeService.Setup(x => x.GetDataTypeDefinitionById(It.IsAny())) - .Returns(Mock.Of( + .Returns(Mock.Of( definition => definition.Id == 555 - && definition.PropertyEditorAlias == "myPropertyType" + && definition.EditorAlias == "myPropertyType" && definition.DatabaseType == DataTypeDatabaseType.Nvarchar)); @@ -308,10 +308,10 @@ namespace Umbraco.Tests.Models.Mapping // setup the mocks to return the data we want to test against... _dataTypeService.Setup(x => x.GetDataTypeDefinitionById(It.IsAny())) - .Returns(Mock.Of( + .Returns(Mock.Of( definition => definition.Id == 555 - && definition.PropertyEditorAlias == "myPropertyType" + && definition.EditorAlias == "myPropertyType" && definition.DatabaseType == DataTypeDatabaseType.Nvarchar)); @@ -517,7 +517,7 @@ namespace Umbraco.Tests.Models.Mapping public void MemberPropertyGroupBasic_To_MemberPropertyGroup() { _dataTypeService.Setup(x => x.GetDataTypeDefinitionById(It.IsAny())) - .Returns(new DataTypeDefinition("test")); + .Returns(new DataType("test")); var basic = new PropertyGroupBasic { @@ -586,7 +586,7 @@ namespace Umbraco.Tests.Models.Mapping public void PropertyGroupBasic_To_PropertyGroup() { _dataTypeService.Setup(x => x.GetDataTypeDefinitionById(It.IsAny())) - .Returns(new DataTypeDefinition("test")); + .Returns(new DataType("test")); var basic = new PropertyGroupBasic { @@ -652,7 +652,7 @@ namespace Umbraco.Tests.Models.Mapping public void MemberPropertyTypeBasic_To_PropertyType() { _dataTypeService.Setup(x => x.GetDataTypeDefinitionById(It.IsAny())) - .Returns(new DataTypeDefinition("test")); + .Returns(new DataType("test")); var basic = new MemberPropertyTypeBasic() { @@ -686,7 +686,7 @@ namespace Umbraco.Tests.Models.Mapping public void PropertyTypeBasic_To_PropertyType() { _dataTypeService.Setup(x => x.GetDataTypeDefinitionById(It.IsAny())) - .Returns(new DataTypeDefinition("test")); + .Returns(new DataType("test")); var basic = new PropertyTypeBasic() { @@ -908,7 +908,7 @@ namespace Umbraco.Tests.Models.Mapping public void MemberPropertyTypeBasic_To_MemberPropertyTypeDisplay() { _dataTypeService.Setup(x => x.GetDataTypeDefinitionById(It.IsAny())) - .Returns(new DataTypeDefinition("test")); + .Returns(new DataType("test")); var basic = new MemberPropertyTypeBasic() { @@ -946,7 +946,7 @@ namespace Umbraco.Tests.Models.Mapping public void PropertyTypeBasic_To_PropertyTypeDisplay() { _dataTypeService.Setup(x => x.GetDataTypeDefinitionById(It.IsAny())) - .Returns(new DataTypeDefinition("test")); + .Returns(new DataType("test")); var basic = new PropertyTypeBasic() { diff --git a/src/Umbraco.Tests/Models/UserExtensionsTests.cs b/src/Umbraco.Tests/Models/UserExtensionsTests.cs index 60c91a7743..2c6f927262 100644 --- a/src/Umbraco.Tests/Models/UserExtensionsTests.cs +++ b/src/Umbraco.Tests/Models/UserExtensionsTests.cs @@ -32,7 +32,7 @@ namespace Umbraco.Tests.Models var esmock = new Mock(); esmock .Setup(x => x.GetAllPaths(It.IsAny(), It.IsAny())) - .Returns((type, ids) => new[] { new EntityPath { Id = startNodeId, Path = startNodePath } }); + .Returns((type, ids) => new[] { new TreeEntityPath { Id = startNodeId, Path = startNodePath } }); Assert.AreEqual(outcome, user.HasPathAccess(content, esmock.Object)); } @@ -84,7 +84,7 @@ namespace Umbraco.Tests.Models var esmock = new Mock(); esmock .Setup(x => x.GetAllPaths(It.IsAny(), It.IsAny())) - .Returns((type, ids) => paths.Where(x => ids.Contains(x.Key)).Select(x => new EntityPath { Id = x.Key, Path = x.Value })); + .Returns((type, ids) => paths.Where(x => ids.Contains(x.Key)).Select(x => new TreeEntityPath { Id = x.Key, Path = x.Value })); var comma = new[] { ',' }; diff --git a/src/Umbraco.Tests/Persistence/Mappers/DataTypeDefinitionMapperTest.cs b/src/Umbraco.Tests/Persistence/Mappers/DataTypeMapperTest.cs similarity index 65% rename from src/Umbraco.Tests/Persistence/Mappers/DataTypeDefinitionMapperTest.cs rename to src/Umbraco.Tests/Persistence/Mappers/DataTypeMapperTest.cs index f015874ce0..1c04b2f467 100644 --- a/src/Umbraco.Tests/Persistence/Mappers/DataTypeDefinitionMapperTest.cs +++ b/src/Umbraco.Tests/Persistence/Mappers/DataTypeMapperTest.cs @@ -1,54 +1,54 @@ -using NUnit.Framework; -using Umbraco.Core.Persistence.Mappers; -using Umbraco.Core.Persistence.SqlSyntax; - -namespace Umbraco.Tests.Persistence.Mappers -{ - [TestFixture] - public class DataTypeDefinitionMapperTest - { - [Test] - public void Can_Map_Id_Property() - { - - // Act - string column = new DataTypeDefinitionMapper().Map(new SqlCeSyntaxProvider(), "Id"); - - // Assert - Assert.That(column, Is.EqualTo("[umbracoNode].[id]")); - } - - [Test] - public void Can_Map_Key_Property() - { - - // Act - string column = new DataTypeDefinitionMapper().Map(new SqlCeSyntaxProvider(), "Key"); - - // Assert - Assert.That(column, Is.EqualTo("[umbracoNode].[uniqueId]")); - } - - [Test] - public void Can_Map_DatabaseType_Property() - { - - // Act - string column = new DataTypeDefinitionMapper().Map(new SqlCeSyntaxProvider(), "DatabaseType"); - - // Assert - Assert.That(column, Is.EqualTo("[cmsDataType].[dbType]")); - } - - [Test] - public void Can_Map_PropertyEditorAlias_Property() - { - - // Act - string column = new DataTypeDefinitionMapper().Map(new SqlCeSyntaxProvider(), "PropertyEditorAlias"); - - // Assert - Assert.That(column, Is.EqualTo("[cmsDataType].[propertyEditorAlias]")); - } - } -} +using NUnit.Framework; +using Umbraco.Core.Persistence.Mappers; +using Umbraco.Core.Persistence.SqlSyntax; + +namespace Umbraco.Tests.Persistence.Mappers +{ + [TestFixture] + public class DataTypeMapperTest + { + [Test] + public void Can_Map_Id_Property() + { + + // Act + string column = new DataTypeMapper().Map(new SqlCeSyntaxProvider(), "Id"); + + // Assert + Assert.That(column, Is.EqualTo("[umbracoNode].[id]")); + } + + [Test] + public void Can_Map_Key_Property() + { + + // Act + string column = new DataTypeMapper().Map(new SqlCeSyntaxProvider(), "Key"); + + // Assert + Assert.That(column, Is.EqualTo("[umbracoNode].[uniqueId]")); + } + + [Test] + public void Can_Map_DatabaseType_Property() + { + + // Act + string column = new DataTypeMapper().Map(new SqlCeSyntaxProvider(), "DatabaseType"); + + // Assert + Assert.That(column, Is.EqualTo("[cmsDataType].[dbType]")); + } + + [Test] + public void Can_Map_PropertyEditorAlias_Property() + { + + // Act + string column = new DataTypeMapper().Map(new SqlCeSyntaxProvider(), "PropertyEditorAlias"); + + // Assert + Assert.That(column, Is.EqualTo("[cmsDataType].[propertyEditorAlias]")); + } + } +} diff --git a/src/Umbraco.Tests/Persistence/Querying/ExpressionTests.cs b/src/Umbraco.Tests/Persistence/Querying/ExpressionTests.cs index 52900d6934..e2fab9e8ee 100644 --- a/src/Umbraco.Tests/Persistence/Querying/ExpressionTests.cs +++ b/src/Umbraco.Tests/Persistence/Querying/ExpressionTests.cs @@ -22,7 +22,7 @@ namespace Umbraco.Tests.Persistence.Querying [Test] public void Equals_Claus_With_Two_Entity_Values() { - var dataType = new DataTypeDefinition(-1, "Test") + var dataType = new DataType(-1, "Test") { Id = 12345 }; diff --git a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs index d202fc8f71..f23ac16795 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/ContentRepositoryTest.cs @@ -40,13 +40,13 @@ namespace Umbraco.Tests.Persistence.Repositories base.TearDown(); } - private DocumentRepository CreateRepository(IScopeAccessor scopeAccessor, out ContentTypeRepository contentTypeRepository, out DataTypeDefinitionRepository dtdRepository, CacheHelper cacheHelper = null) + private DocumentRepository CreateRepository(IScopeAccessor scopeAccessor, out ContentTypeRepository contentTypeRepository, out DataTypeRepository dtdRepository, CacheHelper cacheHelper = null) { cacheHelper = cacheHelper ?? CacheHelper; TemplateRepository tr; var ctRepository = CreateRepository(scopeAccessor, out contentTypeRepository, out tr); - dtdRepository = new DataTypeDefinitionRepository(scopeAccessor, cacheHelper, Logger); + dtdRepository = new DataTypeRepository(scopeAccessor, cacheHelper, Logger); return ctRepository; } @@ -120,7 +120,7 @@ namespace Umbraco.Tests.Persistence.Repositories var provider = TestObjects.GetScopeProvider(Logger); using (var scope = provider.CreateScope()) { - var repository = CreateRepository((IScopeAccessor) provider, out var contentTypeRepository, out DataTypeDefinitionRepository _); + var repository = CreateRepository((IScopeAccessor) provider, out var contentTypeRepository, out DataTypeRepository _); var versions = new List(); var hasPropertiesContentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage"); @@ -293,7 +293,7 @@ namespace Umbraco.Tests.Persistence.Repositories var provider = TestObjects.GetScopeProvider(Logger); using (var scope = provider.CreateScope()) { - var repository = CreateRepository((IScopeAccessor) provider, out var contentTypeRepository, out DataTypeDefinitionRepository _); + var repository = CreateRepository((IScopeAccessor) provider, out var contentTypeRepository, out DataTypeRepository _); var emptyContentType = MockedContentTypes.CreateBasicContentType(); var hasPropertiesContentType = MockedContentTypes.CreateSimpleContentType("umbTextpage1", "Textpage"); @@ -343,9 +343,9 @@ namespace Umbraco.Tests.Persistence.Repositories var provider = TestObjects.GetScopeProvider(Logger); using (var scope = provider.CreateScope()) { - var repository = CreateRepository((IScopeAccessor) provider, out var contentTypeRepository, out DataTypeDefinitionRepository dataTypeDefinitionRepository); + var repository = CreateRepository((IScopeAccessor) provider, out var contentTypeRepository, out DataTypeRepository dataTypeDefinitionRepository); - var dtd = new DataTypeDefinition(-1, Constants.PropertyEditors.DecimalAlias) { Name = "test", DatabaseType = DataTypeDatabaseType.Decimal }; + var dtd = new DataType(-1, Constants.PropertyEditors.DecimalAlias) { Name = "test", DatabaseType = DataTypeDatabaseType.Decimal }; dataTypeDefinitionRepository.Save(dtd); const string decimalPropertyAlias = "decimalProperty"; diff --git a/src/Umbraco.Tests/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs index 97843b1228..2348111aef 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs @@ -57,9 +57,9 @@ namespace Umbraco.Tests.Persistence.Repositories } } - private IDataTypeDefinitionRepository CreateRepository() + private IDataTypeRepository CreateRepository() { - return Container.GetInstance(); + return Container.GetInstance(); } private EntityContainerRepository CreateContainerRepository(IScopeAccessor scopeAccessor) @@ -83,14 +83,14 @@ namespace Umbraco.Tests.Persistence.Repositories var container2 = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "blah2", ParentId = container1.Id }; containerRepository.Save(container2); - var dataType = (IDataTypeDefinition)new DataTypeDefinition(container2.Id, Constants.PropertyEditors.RadioButtonListAlias) + var dataType = (IDataType)new DataType(container2.Id, Constants.PropertyEditors.RadioButtonListAlias) { Name = "dt1" }; repository.Save(dataType); //create a - var dataType2 = (IDataTypeDefinition)new DataTypeDefinition(dataType.Id, Constants.PropertyEditors.RadioButtonListAlias) + var dataType2 = (IDataType)new DataType(dataType.Id, Constants.PropertyEditors.RadioButtonListAlias) { Name = "dt2" }; @@ -162,7 +162,7 @@ namespace Umbraco.Tests.Persistence.Repositories var container = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "blah" }; containerRepository.Save(container); - var dataTypeDefinition = new DataTypeDefinition(container.Id, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" }; + var dataTypeDefinition = new DataType(container.Id, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" }; repository.Save(dataTypeDefinition); Assert.AreEqual(container.Id, dataTypeDefinition.ParentId); @@ -182,7 +182,7 @@ namespace Umbraco.Tests.Persistence.Repositories var container = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "blah" }; containerRepository.Save(container); - IDataTypeDefinition dataType = new DataTypeDefinition(container.Id, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" }; + IDataType dataType = new DataType(container.Id, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" }; repository.Save(dataType); // Act @@ -206,19 +206,19 @@ namespace Umbraco.Tests.Persistence.Repositories using (var scope = provider.CreateScope()) { var repository = CreateRepository(); - IDataTypeDefinition dataTypeDefinition = new DataTypeDefinition(-1, Constants.PropertyEditors.RadioButtonListAlias) {Name = "test"}; + IDataType dataType = new DataType(-1, Constants.PropertyEditors.RadioButtonListAlias) {Name = "test"}; - repository.Save(dataTypeDefinition); + repository.Save(dataType); - var id = dataTypeDefinition.Id; + var id = dataType.Id; Assert.That(id, Is.GreaterThan(0)); // Act - dataTypeDefinition = repository.Get(id); + dataType = repository.Get(id); // Assert - Assert.That(dataTypeDefinition, Is.Not.Null); - Assert.That(dataTypeDefinition.HasIdentity, Is.True); + Assert.That(dataType, Is.Not.Null); + Assert.That(dataType.HasIdentity, Is.True); } } @@ -295,7 +295,7 @@ namespace Umbraco.Tests.Persistence.Repositories var repository = CreateRepository(); // Act - var query = scope.SqlContext.Query().Where(x => x.PropertyEditorAlias == Constants.PropertyEditors.RadioButtonListAlias); + var query = scope.SqlContext.Query().Where(x => x.EditorAlias == Constants.PropertyEditors.RadioButtonListAlias); var result = repository.Get(query); // Assert @@ -316,7 +316,7 @@ namespace Umbraco.Tests.Persistence.Repositories var repository = CreateRepository(); // Act - var query = scope.SqlContext.Query().Where(x => x.Name.StartsWith("D")); + var query = scope.SqlContext.Query().Where(x => x.Name.StartsWith("D")); int count = repository.Count(query); // Assert @@ -333,7 +333,7 @@ namespace Umbraco.Tests.Persistence.Repositories using (var scope = provider.CreateScope()) { var repository = CreateRepository(); - var dataTypeDefinition = new DataTypeDefinition("Test.TestEditor") + var dataTypeDefinition = new DataType("Test.TestEditor") { DatabaseType = DataTypeDatabaseType.Integer, Name = "AgeDataType", @@ -364,7 +364,7 @@ namespace Umbraco.Tests.Persistence.Repositories using (var scope = provider.CreateScope()) { var repository = CreateRepository(); - var dataTypeDefinition = new DataTypeDefinition("Test.blah") + var dataTypeDefinition = new DataType("Test.blah") { DatabaseType = DataTypeDatabaseType.Integer, Name = "AgeDataType", @@ -375,7 +375,7 @@ namespace Umbraco.Tests.Persistence.Repositories // Act var definition = repository.Get(dataTypeDefinition.Id); definition.Name = "AgeDataType Updated"; - definition.PropertyEditorAlias = "Test.TestEditor"; //change + definition.EditorAlias = "Test.TestEditor"; //change repository.Save(definition); var definitionUpdated = repository.Get(dataTypeDefinition.Id); @@ -383,7 +383,7 @@ namespace Umbraco.Tests.Persistence.Repositories // Assert Assert.That(definitionUpdated, Is.Not.Null); Assert.That(definitionUpdated.Name, Is.EqualTo("AgeDataType Updated")); - Assert.That(definitionUpdated.PropertyEditorAlias, Is.EqualTo("Test.TestEditor")); + Assert.That(definitionUpdated.EditorAlias, Is.EqualTo("Test.TestEditor")); } } @@ -396,7 +396,7 @@ namespace Umbraco.Tests.Persistence.Repositories using (var scope = provider.CreateScope()) { var repository = CreateRepository(); - var dataTypeDefinition = new DataTypeDefinition("Test.TestEditor") + var dataTypeDefinition = new DataType("Test.TestEditor") { DatabaseType = DataTypeDatabaseType.Integer, Name = "AgeDataType", @@ -447,7 +447,7 @@ namespace Umbraco.Tests.Persistence.Repositories using (var scope = provider.CreateScope()) { var repository = CreateRepository(); - var dataTypeDefinition = new DataTypeDefinition(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" }; + var dataTypeDefinition = new DataType(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" }; repository.Save(dataTypeDefinition); var dtid = dataTypeDefinition.Id; @@ -469,7 +469,7 @@ namespace Umbraco.Tests.Persistence.Repositories using (var scope = provider.CreateScope()) { var repository = CreateRepository(); - var dataTypeDefinition = new DataTypeDefinition(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" }; + var dataTypeDefinition = new DataType(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" }; repository.Save(dataTypeDefinition); var dtid = dataTypeDefinition.Id; @@ -485,15 +485,15 @@ namespace Umbraco.Tests.Persistence.Repositories [Test] public void Can_Get_Pre_Value_Collection_With_Cache() { - DataTypeDefinition dtd; + DataType dtd; var provider = TestObjects.GetScopeProvider(Logger); var accessor = (IScopeAccessor) provider; using (var scope = provider.CreateScope()) { - var repository = Container.GetInstance(); - dtd = new DataTypeDefinition(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" }; + var repository = Container.GetInstance(); + dtd = new DataType(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" }; repository.Save(dtd); scope.Database.Insert(new DataTypePreValueDto { DataTypeNodeId = dtd.Id, SortOrder = 0, Value = "test1" }); @@ -504,7 +504,7 @@ namespace Umbraco.Tests.Persistence.Repositories } // note: see CreateCacheHelper, this test uses a special cache - var cache = CacheHelper.IsolatedRuntimeCache.GetCache(); + var cache = CacheHelper.IsolatedRuntimeCache.GetCache(); Assert.IsTrue(cache); var cached = cache.Result .GetCacheItemsByKeySearch(CacheKeys.DataTypePreValuesCacheKey + "_" + dtd.Id); @@ -517,7 +517,7 @@ namespace Umbraco.Tests.Persistence.Repositories [Test] public void Can_Get_Pre_Value_As_String_With_Cache() { - DataTypeDefinition dtd; + DataType dtd; object id; var provider = TestObjects.GetScopeProvider(Logger); @@ -525,8 +525,8 @@ namespace Umbraco.Tests.Persistence.Repositories using (var scope = provider.CreateScope()) { - var repository = Container.GetInstance(); - dtd = new DataTypeDefinition(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" }; + var repository = Container.GetInstance(); + dtd = new DataType(-1, Constants.PropertyEditors.RadioButtonListAlias) { Name = "test" }; repository.Save(dtd); id = scope.Database.Insert(new DataTypePreValueDto() { DataTypeNodeId = dtd.Id, SortOrder = 0, Value = "test1" }); @@ -537,7 +537,7 @@ namespace Umbraco.Tests.Persistence.Repositories } // note: see CreateCacheHelper, this test uses a special cache - var cache = CacheHelper.IsolatedRuntimeCache.GetCache(); + var cache = CacheHelper.IsolatedRuntimeCache.GetCache(); Assert.IsTrue(cache); var cached = cache.Result .GetCacheItemsByKeySearch(CacheKeys.DataTypePreValuesCacheKey + "_" + dtd.Id); @@ -548,7 +548,7 @@ namespace Umbraco.Tests.Persistence.Repositories using (var scope = provider.CreateScope()) { - var repository = Container.GetInstance(); + var repository = Container.GetInstance(); //ensure it still gets resolved! var val = repository.GetPreValueAsString(Convert.ToInt32(id)); Assert.AreEqual("test1", val); diff --git a/src/Umbraco.Tests/Plugins/PluginManagerTests.cs b/src/Umbraco.Tests/Plugins/PluginManagerTests.cs index 98f99845b4..8c9bf351f6 100644 --- a/src/Umbraco.Tests/Plugins/PluginManagerTests.cs +++ b/src/Umbraco.Tests/Plugins/PluginManagerTests.cs @@ -257,7 +257,7 @@ AnotherContentFinder public void Resolves_Assigned_Mappers() { var foundTypes1 = _manager.GetAssignedMapperTypes(); - Assert.AreEqual(29, foundTypes1.Count()); + Assert.AreEqual(28, foundTypes1.Count()); } [Test] diff --git a/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs b/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs index 51e93c75d1..7b20e37a6b 100644 --- a/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs +++ b/src/Umbraco.Tests/PropertyEditors/MultiValuePropertyEditorTests.cs @@ -32,7 +32,7 @@ namespace Umbraco.Tests.PropertyEditors var dataTypeService = dataTypeServiceMock.Object; var editor = new PublishValuesMultipleValueEditor(true, dataTypeService, Mock.Of(), new PropertyValueEditor()); - var prop = new Property(1, new PropertyType(new DataTypeDefinition(1, "Test.TestEditor"))); + var prop = new Property(1, new PropertyType(new DataType(1, "Test.TestEditor"))); prop.SetValue("1234,4567,8910"); var result = editor.ConvertDbToString(prop.PropertyType, prop.GetValue(), new Mock().Object); @@ -57,7 +57,7 @@ namespace Umbraco.Tests.PropertyEditors var dataTypeService = dataTypeServiceMock.Object; var editor = new PublishValuesMultipleValueEditor(false, dataTypeService, Mock.Of(), new PropertyValueEditor()); - var prop = new Property(1, new PropertyType(new DataTypeDefinition(1, "Test.TestEditor"))); + var prop = new Property(1, new PropertyType(new DataType(1, "Test.TestEditor"))); prop.SetValue("1234,4567,8910"); var result = editor.ConvertDbToString(prop.PropertyType, prop.GetValue(), new Mock().Object); @@ -81,7 +81,7 @@ namespace Umbraco.Tests.PropertyEditors var dataTypeService = dataTypeServiceMock.Object; var editor = new PublishValueValueEditor(dataTypeService, new PropertyValueEditor(), Mock.Of()); - var prop = new Property(1, new PropertyType(new DataTypeDefinition(1, "Test.TestEditor"))); + var prop = new Property(1, new PropertyType(new DataType(1, "Test.TestEditor"))); prop.SetValue("1234"); var result = editor.ConvertDbToString(prop.PropertyType, prop.GetValue(), new Mock().Object); diff --git a/src/Umbraco.Tests/Published/ConvertersTests.cs b/src/Umbraco.Tests/Published/ConvertersTests.cs index c28cd7480a..3aa3e11896 100644 --- a/src/Umbraco.Tests/Published/ConvertersTests.cs +++ b/src/Umbraco.Tests/Published/ConvertersTests.cs @@ -40,7 +40,7 @@ namespace Umbraco.Tests.Published private class SimpleConverter1 : IPropertyValueConverter { public bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals("editor1"); + => propertyType.EditorAlias.InvariantEquals("editor1"); public Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (int); @@ -106,7 +106,7 @@ namespace Umbraco.Tests.Published } public bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals("editor2"); + => propertyType.EditorAlias.InvariantEquals("editor2"); public Type GetPropertyValueType(PublishedPropertyType propertyType) // the first version would be the "generic" version, but say we want to be more precise @@ -222,7 +222,7 @@ namespace Umbraco.Tests.Published public class SimpleConverter3A : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias == "editor1"; + => propertyType.EditorAlias == "editor1"; public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (string); @@ -241,7 +241,7 @@ namespace Umbraco.Tests.Published } public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias == "editor2"; + => propertyType.EditorAlias == "editor2"; public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (IEnumerable<>).MakeGenericType(ModelType.For("content1")); diff --git a/src/Umbraco.Tests/Published/NestedContentTests.cs b/src/Umbraco.Tests/Published/NestedContentTests.cs index 7c5bb494d6..6e52ba4f3d 100644 --- a/src/Umbraco.Tests/Published/NestedContentTests.cs +++ b/src/Umbraco.Tests/Published/NestedContentTests.cs @@ -280,7 +280,7 @@ namespace Umbraco.Tests.Published public override IEnumerable Properties { get; } public override IPublishedProperty GetProperty(string alias) { - return Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias)); + return Properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias)); } } } diff --git a/src/Umbraco.Tests/Published/PropertyCacheLevelTests.cs b/src/Umbraco.Tests/Published/PropertyCacheLevelTests.cs index 2130357374..bf1dc2ca44 100644 --- a/src/Umbraco.Tests/Published/PropertyCacheLevelTests.cs +++ b/src/Umbraco.Tests/Published/PropertyCacheLevelTests.cs @@ -198,7 +198,7 @@ namespace Umbraco.Tests.Published public int InterConverts { get; private set; } public bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.InvariantEquals("editor1"); + => propertyType.EditorAlias.InvariantEquals("editor1"); public Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof(int); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs index 9aa6037374..aab1ce64ef 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentDataTableTests.cs @@ -216,7 +216,7 @@ namespace Umbraco.Tests.PublishedContent public IPublishedProperty GetProperty(string alias) { - return Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias)); + return Properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias)); } public IPublishedProperty GetProperty(string alias, bool recurse) diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs index cf82e0844d..7119e8b4c8 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs @@ -219,7 +219,7 @@ namespace Umbraco.Tests.PublishedContent { new SolidPublishedProperty { - PropertyTypeAlias = "prop1", + Alias = "prop1", SolidHasValue = true, SolidValue = 1234, SolidSourceValue = "1234" @@ -242,7 +242,7 @@ namespace Umbraco.Tests.PublishedContent { new SolidPublishedProperty { - PropertyTypeAlias = "prop1", + Alias = "prop1", SolidHasValue = true, SolidValue = 1234, SolidSourceValue = "1234" @@ -265,7 +265,7 @@ namespace Umbraco.Tests.PublishedContent { new SolidPublishedProperty { - PropertyTypeAlias = "prop1", + Alias = "prop1", SolidHasValue = true, SolidValue = 1234, SolidSourceValue = "1234" diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs index e818328fd8..9682450016 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestBase.cs @@ -43,7 +43,7 @@ namespace Umbraco.Tests.PublishedContent // AutoPublishedContentType will auto-generate other properties publishedContentTypeFactory.CreatePropertyType("content", 0, Constants.PropertyEditors.TinyMCEAlias), }; - var type = new AutoPublishedContentType(0, "anything", propertyTypes, publishedContentTypeFactory); + var type = new AutoPublishedContentType(0, "anything", propertyTypes); ContentTypesCache.GetPublishedContentTypeByAlias = alias => type; var umbracoContext = GetUmbracoContext("/test"); diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs index fa5ec7c160..ed7b4aea20 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs @@ -4,6 +4,7 @@ using System.Linq; using Moq; using Umbraco.Core; using Umbraco.Core.Cache; +using Umbraco.Core.Models; using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.PropertyEditors; using Umbraco.Web; @@ -215,7 +216,7 @@ namespace Umbraco.Tests.PublishedContent public IPublishedProperty GetProperty(string alias) { - return Properties.FirstOrDefault(p => p.PropertyTypeAlias.InvariantEquals(alias)); + return Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias)); } public IPublishedProperty GetProperty(string alias, bool recurse) @@ -247,7 +248,7 @@ namespace Umbraco.Tests.PublishedContent class SolidPublishedProperty : IPublishedProperty { - public string PropertyTypeAlias { get; set; } + public string Alias { get; set; } public object SolidSourceValue { get; set; } public object SolidValue { get; set; } public bool SolidHasValue { get; set; } @@ -319,12 +320,12 @@ namespace Umbraco.Tests.PublishedContent private static readonly PublishedPropertyType Default = Factory.CreatePropertyType("*", 0, "?"); - public AutoPublishedContentType(int id, string alias, IEnumerable propertyTypes, IPublishedContentTypeFactory publishedContentTypeFactory) - : base(id, alias, Enumerable.Empty(), propertyTypes, publishedContentTypeFactory) + public AutoPublishedContentType(int id, string alias, IEnumerable propertyTypes) + : base(id, alias, PublishedItemType.Content, Enumerable.Empty(), propertyTypes, ContentVariation.InvariantNeutral) { } - public AutoPublishedContentType(int id, string alias, IEnumerable compositionAliases, IEnumerable propertyTypes, IPublishedContentTypeFactory publishedContentTypeFactory) - : base(id, alias, compositionAliases, propertyTypes, publishedContentTypeFactory) + public AutoPublishedContentType(int id, string alias, IEnumerable compositionAliases, IEnumerable propertyTypes) + : base(id, alias, PublishedItemType.Content, compositionAliases, propertyTypes, ContentVariation.InvariantNeutral) { } public override PublishedPropertyType GetPropertyType(string alias) diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs index 40939630c1..3de7c4f32f 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs @@ -50,7 +50,7 @@ namespace Umbraco.Tests.PublishedContent factory.CreatePropertyType("testRecursive", 0, "?"), }; var compositionAliases = new[] { "MyCompositionAlias" }; - var type = new AutoPublishedContentType(0, "anything", compositionAliases, propertyTypes, factory); + var type = new AutoPublishedContentType(0, "anything", compositionAliases, propertyTypes); ContentTypesCache.GetPublishedContentTypeByAlias = alias => type; } diff --git a/src/Umbraco.Tests/Services/CachedDataTypeServiceTests.cs b/src/Umbraco.Tests/Services/CachedDataTypeServiceTests.cs index 17ca466541..63146f5b07 100644 --- a/src/Umbraco.Tests/Services/CachedDataTypeServiceTests.cs +++ b/src/Umbraco.Tests/Services/CachedDataTypeServiceTests.cs @@ -20,8 +20,8 @@ namespace Umbraco.Tests.Services { var dataTypeService = ServiceContext.DataTypeService; - IDataTypeDefinition dataTypeDefinition = new DataTypeDefinition(-1, "Test.TestEditor") { Name = "Testing Textfield", DatabaseType = DataTypeDatabaseType.Ntext }; - dataTypeService.Save(dataTypeDefinition); + IDataType dataType = new DataType(-1, "Test.TestEditor") { Name = "Testing Textfield", DatabaseType = DataTypeDatabaseType.Ntext }; + dataTypeService.Save(dataType); //Get all the first time (no cache) var all = dataTypeService.GetAllDataTypeDefinitions(); diff --git a/src/Umbraco.Tests/Services/DataTypeServiceTests.cs b/src/Umbraco.Tests/Services/DataTypeServiceTests.cs index 5bdf084239..29560f59cc 100644 --- a/src/Umbraco.Tests/Services/DataTypeServiceTests.cs +++ b/src/Umbraco.Tests/Services/DataTypeServiceTests.cs @@ -24,15 +24,15 @@ namespace Umbraco.Tests.Services var dataTypeService = ServiceContext.DataTypeService; // Act - IDataTypeDefinition dataTypeDefinition = new DataTypeDefinition(-1, "Test.TestEditor") { Name = "Testing Textfield", DatabaseType = DataTypeDatabaseType.Ntext }; - dataTypeService.Save(dataTypeDefinition); + IDataType dataType = new DataType(-1, "Test.TestEditor") { Name = "Testing Textfield", DatabaseType = DataTypeDatabaseType.Ntext }; + dataTypeService.Save(dataType); // Assert - Assert.That(dataTypeDefinition, Is.Not.Null); - Assert.That(dataTypeDefinition.HasIdentity, Is.True); + Assert.That(dataType, Is.Not.Null); + Assert.That(dataType.HasIdentity, Is.True); - dataTypeDefinition = dataTypeService.GetDataTypeDefinitionById(dataTypeDefinition.Id); - Assert.That(dataTypeDefinition, Is.Not.Null); + dataType = dataTypeService.GetDataTypeDefinitionById(dataType.Id); + Assert.That(dataType, Is.Not.Null); } [Test] @@ -67,20 +67,20 @@ namespace Umbraco.Tests.Services var textBoxAlias = Constants.PropertyEditors.TextboxAlias; // Act - IDataTypeDefinition dataTypeDefinition = new DataTypeDefinition(-1, textBoxAlias) { Name = "Testing prevals", DatabaseType = DataTypeDatabaseType.Ntext }; - dataTypeService.Save(dataTypeDefinition); - dataTypeService.SavePreValues(dataTypeDefinition, new Dictionary + IDataType dataType = new DataType(-1, textBoxAlias) { Name = "Testing prevals", DatabaseType = DataTypeDatabaseType.Ntext }; + dataTypeService.Save(dataType); + dataTypeService.SavePreValues(dataType, new Dictionary { {"preVal1", new PreValue("Hello")}, {"preVal2", new PreValue("World")} }); //re-get - dataTypeDefinition = dataTypeService.GetDataTypeDefinitionById(dataTypeDefinition.Id); - var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id); + dataType = dataTypeService.GetDataTypeDefinitionById(dataType.Id); + var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id); // Assert - Assert.That(dataTypeDefinition, Is.Not.Null); - Assert.That(dataTypeDefinition.HasIdentity, Is.True); + Assert.That(dataType, Is.Not.Null); + Assert.That(dataType.HasIdentity, Is.True); Assert.AreEqual(true, preVals.IsDictionaryBased); Assert.AreEqual(2, preVals.PreValuesAsDictionary.Keys.Count); Assert.AreEqual("preVal1", preVals.PreValuesAsDictionary.Keys.First()); @@ -97,19 +97,19 @@ namespace Umbraco.Tests.Services var textBoxAlias = Constants.PropertyEditors.TextboxAlias; // Act - IDataTypeDefinition dataTypeDefinition = new DataTypeDefinition(-1, textBoxAlias) { Name = "Testing prevals", DatabaseType = DataTypeDatabaseType.Ntext }; - dataTypeService.SaveDataTypeAndPreValues(dataTypeDefinition, new Dictionary + IDataType dataType = new DataType(-1, textBoxAlias) { Name = "Testing prevals", DatabaseType = DataTypeDatabaseType.Ntext }; + dataTypeService.SaveDataTypeAndPreValues(dataType, new Dictionary { {"preVal1", new PreValue("Hello")}, {"preVal2", new PreValue("World")} }); //re-get - dataTypeDefinition = dataTypeService.GetDataTypeDefinitionById(dataTypeDefinition.Id); - var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id); + dataType = dataTypeService.GetDataTypeDefinitionById(dataType.Id); + var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id); // Assert - Assert.That(dataTypeDefinition, Is.Not.Null); - Assert.That(dataTypeDefinition.HasIdentity, Is.True); + Assert.That(dataType, Is.Not.Null); + Assert.That(dataType.HasIdentity, Is.True); Assert.AreEqual(true, preVals.IsDictionaryBased); Assert.AreEqual(2, preVals.PreValuesAsDictionary.Keys.Count); Assert.AreEqual("preVal1", preVals.PreValuesAsDictionary.Keys.First()); @@ -126,24 +126,24 @@ namespace Umbraco.Tests.Services var textBoxAlias = Constants.PropertyEditors.TextboxAlias; // Act - IDataTypeDefinition dataTypeDefinition = new DataTypeDefinition(-1, textBoxAlias) { Name = "Testing prevals", DatabaseType = DataTypeDatabaseType.Ntext }; - dataTypeService.SaveDataTypeAndPreValues(dataTypeDefinition, new Dictionary + IDataType dataType = new DataType(-1, textBoxAlias) { Name = "Testing prevals", DatabaseType = DataTypeDatabaseType.Ntext }; + dataTypeService.SaveDataTypeAndPreValues(dataType, new Dictionary { {"preVal1", new PreValue("Hello")}, {"preVal2", new PreValue("World")} }); //re-get - dataTypeDefinition = dataTypeService.GetDataTypeDefinitionById(dataTypeDefinition.Id); - var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id); + dataType = dataTypeService.GetDataTypeDefinitionById(dataType.Id); + var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id); //update them (ensure Ids are there!) var asDictionary = preVals.FormatAsDictionary(); asDictionary["preVal1"].Value = "Hello2"; asDictionary["preVal2"].Value = "World2"; - dataTypeService.SavePreValues(dataTypeDefinition, asDictionary); + dataTypeService.SavePreValues(dataType, asDictionary); - var preValsAgain = dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id); + var preValsAgain = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id); // Assert @@ -163,23 +163,23 @@ namespace Umbraco.Tests.Services var textBoxAlias = Constants.PropertyEditors.TextboxAlias; // Act - IDataTypeDefinition dataTypeDefinition = new DataTypeDefinition(-1, textBoxAlias) { Name = "Testing prevals", DatabaseType = DataTypeDatabaseType.Ntext }; - dataTypeService.SaveDataTypeAndPreValues(dataTypeDefinition, new Dictionary + IDataType dataType = new DataType(-1, textBoxAlias) { Name = "Testing prevals", DatabaseType = DataTypeDatabaseType.Ntext }; + dataTypeService.SaveDataTypeAndPreValues(dataType, new Dictionary { {"preVal1", new PreValue("Hello")}, {"preVal2", new PreValue("World")} }); //re-get - dataTypeDefinition = dataTypeService.GetDataTypeDefinitionById(dataTypeDefinition.Id); - var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id); + dataType = dataTypeService.GetDataTypeDefinitionById(dataType.Id); + var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id); //update them (ensure Ids are there!) var asDictionary = preVals.FormatAsDictionary(); asDictionary.Remove("preVal2"); - dataTypeService.SavePreValues(dataTypeDefinition, asDictionary); + dataTypeService.SavePreValues(dataType, asDictionary); - var preValsAgain = dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id); + var preValsAgain = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id); // Assert @@ -197,17 +197,17 @@ namespace Umbraco.Tests.Services var textBoxAlias = Constants.PropertyEditors.TextboxAlias; // Act - IDataTypeDefinition dataTypeDefinition = new DataTypeDefinition(-1, textBoxAlias) { Name = "Testing prevals", DatabaseType = DataTypeDatabaseType.Ntext }; - dataTypeService.Save(dataTypeDefinition); - dataTypeService.SavePreValues(dataTypeDefinition.Id, new[] {"preVal1", "preVal2"}); + IDataType dataType = new DataType(-1, textBoxAlias) { Name = "Testing prevals", DatabaseType = DataTypeDatabaseType.Ntext }; + dataTypeService.Save(dataType); + dataTypeService.SavePreValues(dataType.Id, new[] {"preVal1", "preVal2"}); //re-get - dataTypeDefinition = dataTypeService.GetDataTypeDefinitionById(dataTypeDefinition.Id); - var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id); + dataType = dataTypeService.GetDataTypeDefinitionById(dataType.Id); + var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id); // Assert - Assert.That(dataTypeDefinition, Is.Not.Null); - Assert.That(dataTypeDefinition.HasIdentity, Is.True); + Assert.That(dataType, Is.Not.Null); + Assert.That(dataType.HasIdentity, Is.True); Assert.AreEqual(false, preVals.IsDictionaryBased); Assert.AreEqual(2, preVals.PreValuesAsArray.Count()); Assert.AreEqual("preVal1", preVals.PreValuesAsArray.First().Value); @@ -221,7 +221,7 @@ namespace Umbraco.Tests.Services var dataTypeService = ServiceContext.DataTypeService; // Act - var dataTypeDefinition = new DataTypeDefinition(-1, "Test.TestEditor") { Name = string.Empty, DatabaseType = DataTypeDatabaseType.Ntext }; + var dataTypeDefinition = new DataType(-1, "Test.TestEditor") { Name = string.Empty, DatabaseType = DataTypeDatabaseType.Ntext }; // Act & Assert Assert.Throws(() => dataTypeService.Save(dataTypeDefinition)); diff --git a/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs b/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs index b55a64bc62..af5dbf6fe9 100644 --- a/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs +++ b/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs @@ -320,7 +320,7 @@ namespace Umbraco.Tests.Services.Importing // Assert Assert.That(dataTypeDefinitions, Is.Not.Null); Assert.That(dataTypeDefinitions.Any(), Is.True); - Assert.AreEqual(Constants.PropertyEditors.CheckBoxListAlias, dataTypeDefinitions.First().PropertyEditorAlias); + Assert.AreEqual(Constants.PropertyEditors.CheckBoxListAlias, dataTypeDefinitions.First().EditorAlias); Assert.That(contents, Is.Not.Null); Assert.That(contentTypes.Any(), Is.True); Assert.That(contents.Any(), Is.True); diff --git a/src/Umbraco.Tests/Services/PreValueConverterTests.cs b/src/Umbraco.Tests/Services/PreValueConverterTests.cs index c8c7de2cde..9dd088704b 100644 --- a/src/Umbraco.Tests/Services/PreValueConverterTests.cs +++ b/src/Umbraco.Tests/Services/PreValueConverterTests.cs @@ -23,7 +23,7 @@ namespace Umbraco.Tests.Services new Tuple(new PreValue(13, "value4"), "key4", 1) }; - var result = DataTypeDefinitionRepository.PreValueConverter.ConvertToPreValuesCollection(list); + var result = DataTypeRepository.PreValueConverter.ConvertToPreValuesCollection(list); Assert.Throws(() => { @@ -49,7 +49,7 @@ namespace Umbraco.Tests.Services new Tuple(new PreValue(13, "value4"), "", 1) }; - var result = DataTypeDefinitionRepository.PreValueConverter.ConvertToPreValuesCollection(list); + var result = DataTypeRepository.PreValueConverter.ConvertToPreValuesCollection(list); Assert.Throws(() => { @@ -75,7 +75,7 @@ namespace Umbraco.Tests.Services new Tuple(new PreValue(13, "value4"), "key4", 1) }; - var result = DataTypeDefinitionRepository.PreValueConverter.ConvertToPreValuesCollection(list); + var result = DataTypeRepository.PreValueConverter.ConvertToPreValuesCollection(list); Assert.Throws(() => { diff --git a/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs b/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs index b58a9856ca..4dd0096d5b 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs @@ -25,7 +25,7 @@ namespace Umbraco.Tests.TestHelpers // need to specify a custom callback for unit tests // AutoPublishedContentTypes generates properties automatically var factory = new PublishedContentTypeFactory(Mock.Of(), new PropertyValueConverterCollection(Array.Empty()), Mock.Of()); - var type = new AutoPublishedContentType(0, "anything", new PublishedPropertyType[] { }, factory); + var type = new AutoPublishedContentType(0, "anything", new PublishedPropertyType[] { }); ContentTypesCache.GetPublishedContentTypeByAlias = alias => type; } diff --git a/src/Umbraco.Tests/TestHelpers/Entities/MockedEntity.cs b/src/Umbraco.Tests/TestHelpers/Entities/MockedEntity.cs index d139ec398c..7e90d24efe 100644 --- a/src/Umbraco.Tests/TestHelpers/Entities/MockedEntity.cs +++ b/src/Umbraco.Tests/TestHelpers/Entities/MockedEntity.cs @@ -6,7 +6,7 @@ namespace Umbraco.Tests.TestHelpers.Entities { [Serializable] [DataContract(IsReference = true)] - public class MockedEntity : Entity + public class MockedEntity : EntityBase { [DataMember] public string Alias { get; set; } diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 27204252fa..01066507ce 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -155,7 +155,7 @@ namespace Umbraco.Tests.TestHelpers var idkMap = new IdkMap(scopeProvider); var userService = GetLazyService(container, c => new UserService(scopeProvider, logger, eventMessagesFactory, runtimeState, GetRepo(c), GetRepo(c))); - var dataTypeService = GetLazyService(container, c => new DataTypeService(scopeProvider, logger, eventMessagesFactory, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c))); + var dataTypeService = GetLazyService(container, c => new DataTypeService(scopeProvider, logger, eventMessagesFactory, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c))); var contentService = GetLazyService(container, c => new ContentService(scopeProvider, logger, eventMessagesFactory, mediaFileSystem, GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c), GetRepo(c))); var notificationService = GetLazyService(container, c => new NotificationService(scopeProvider, userService.Value, contentService.Value, logger, GetRepo(c))); var serverRegistrationService = GetLazyService(container, c => new ServerRegistrationService(scopeProvider, logger, eventMessagesFactory, GetRepo(c))); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 8f2975f2a4..42e0486901 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -342,7 +342,7 @@ - + @@ -486,7 +486,7 @@ - + diff --git a/src/Umbraco.Tests/Web/Controllers/ContentControllerUnitTests.cs b/src/Umbraco.Tests/Web/Controllers/ContentControllerUnitTests.cs index 82571b22f3..e34ad6771d 100644 --- a/src/Umbraco.Tests/Web/Controllers/ContentControllerUnitTests.cs +++ b/src/Umbraco.Tests/Web/Controllers/ContentControllerUnitTests.cs @@ -85,7 +85,7 @@ namespace Umbraco.Tests.Web.Controllers var userService = userServiceMock.Object; var entityServiceMock = new Mock(); entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny(), It.IsAny())) - .Returns(new[] { Mock.Of(entity => entity.Id == 9876 && entity.Path == "-1,9876") }); + .Returns(new[] { Mock.Of(entity => entity.Id == 9876 && entity.Path == "-1,9876") }); var entityService = entityServiceMock.Object; //act @@ -216,7 +216,7 @@ namespace Umbraco.Tests.Web.Controllers var userService = userServiceMock.Object; var entityServiceMock = new Mock(); entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny(), It.IsAny())) - .Returns(new[] { Mock.Of(entity => entity.Id == 1234 && entity.Path == "-1,1234") }); + .Returns(new[] { Mock.Of(entity => entity.Id == 1234 && entity.Path == "-1,1234") }); var entityService = entityServiceMock.Object; //act @@ -240,7 +240,7 @@ namespace Umbraco.Tests.Web.Controllers var userService = userServiceMock.Object; var entityServiceMock = new Mock(); entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny(), It.IsAny())) - .Returns(new[] { Mock.Of(entity => entity.Id == 1234 && entity.Path == "-1,1234") }); + .Returns(new[] { Mock.Of(entity => entity.Id == 1234 && entity.Path == "-1,1234") }); var entityService = entityServiceMock.Object; //act diff --git a/src/Umbraco.Tests/Web/Controllers/FilterAllowedOutgoingContentAttributeTests.cs b/src/Umbraco.Tests/Web/Controllers/FilterAllowedOutgoingContentAttributeTests.cs index 4cde7ad8bd..ff191b6fe6 100644 --- a/src/Umbraco.Tests/Web/Controllers/FilterAllowedOutgoingContentAttributeTests.cs +++ b/src/Umbraco.Tests/Web/Controllers/FilterAllowedOutgoingContentAttributeTests.cs @@ -93,7 +93,7 @@ namespace Umbraco.Tests.Web.Controllers var userService = userServiceMock.Object; var entityServiceMock = new Mock(); entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny(), It.IsAny())) - .Returns(new[] { Mock.Of(entity => entity.Id == 5 && entity.Path == "-1,5") }); + .Returns(new[] { Mock.Of(entity => entity.Id == 5 && entity.Path == "-1,5") }); var entityService = entityServiceMock.Object; var att = new FilterAllowedOutgoingContentAttribute(typeof(IEnumerable), userService, entityService); diff --git a/src/Umbraco.Tests/Web/Controllers/MediaControllerUnitTests.cs b/src/Umbraco.Tests/Web/Controllers/MediaControllerUnitTests.cs index 95a0ea4955..6efe348bc8 100644 --- a/src/Umbraco.Tests/Web/Controllers/MediaControllerUnitTests.cs +++ b/src/Umbraco.Tests/Web/Controllers/MediaControllerUnitTests.cs @@ -73,7 +73,7 @@ namespace Umbraco.Tests.Web.Controllers var mediaService = mediaServiceMock.Object; var entityServiceMock = new Mock(); entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny(), It.IsAny())) - .Returns(new[] { Mock.Of(entity => entity.Id == 9876 && entity.Path == "-1,9876") }); + .Returns(new[] { Mock.Of(entity => entity.Id == 9876 && entity.Path == "-1,9876") }); var entityService = entityServiceMock.Object; //act @@ -115,7 +115,7 @@ namespace Umbraco.Tests.Web.Controllers var mediaService = mediaServiceMock.Object; var entityServiceMock = new Mock(); entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny(), It.IsAny())) - .Returns(new[] { Mock.Of(entity => entity.Id == 1234 && entity.Path == "-1,1234") }); + .Returns(new[] { Mock.Of(entity => entity.Id == 1234 && entity.Path == "-1,1234") }); var entityService = entityServiceMock.Object; //act @@ -157,7 +157,7 @@ namespace Umbraco.Tests.Web.Controllers var mediaService = mediaServiceMock.Object; var entityServiceMock = new Mock(); entityServiceMock.Setup(x => x.GetAllPaths(It.IsAny(), It.IsAny())) - .Returns(new[] { Mock.Of(entity => entity.Id == 1234 && entity.Path == "-1,1234") }); + .Returns(new[] { Mock.Of(entity => entity.Id == 1234 && entity.Path == "-1,1234") }); var entityService = entityServiceMock.Object; //act diff --git a/src/Umbraco.Tests/Web/Controllers/UserEditorAuthorizationHelperTests.cs b/src/Umbraco.Tests/Web/Controllers/UserEditorAuthorizationHelperTests.cs index 12e20dd08c..ed181f00f0 100644 --- a/src/Umbraco.Tests/Web/Controllers/UserEditorAuthorizationHelperTests.cs +++ b/src/Umbraco.Tests/Web/Controllers/UserEditorAuthorizationHelperTests.cs @@ -134,7 +134,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Setup(service => service.GetAllPaths(It.IsAny(), It.IsAny())) .Returns((UmbracoObjectTypes objType, int[] ids) => { - return ids.Select(x => new EntityPath {Path = nodePaths[x], Id = x}); + return ids.Select(x => new TreeEntityPath {Path = nodePaths[x], Id = x}); }); var authHelper = new UserEditorAuthorizationHelper( @@ -172,7 +172,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Setup(service => service.GetAllPaths(It.IsAny(), It.IsAny())) .Returns((UmbracoObjectTypes objType, int[] ids) => { - return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x }); + return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x }); }); var authHelper = new UserEditorAuthorizationHelper( @@ -210,7 +210,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Setup(service => service.GetAllPaths(It.IsAny(), It.IsAny())) .Returns((UmbracoObjectTypes objType, int[] ids) => { - return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x }); + return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x }); }); var authHelper = new UserEditorAuthorizationHelper( @@ -248,7 +248,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Setup(service => service.GetAllPaths(It.IsAny(), It.IsAny())) .Returns((UmbracoObjectTypes objType, int[] ids) => { - return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x }); + return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x }); }); var authHelper = new UserEditorAuthorizationHelper( @@ -286,7 +286,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Setup(service => service.GetAllPaths(It.IsAny(), It.IsAny())) .Returns((UmbracoObjectTypes objType, int[] ids) => { - return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x }); + return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x }); }); var authHelper = new UserEditorAuthorizationHelper( @@ -324,7 +324,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Setup(service => service.GetAllPaths(It.IsAny(), It.IsAny())) .Returns((UmbracoObjectTypes objType, int[] ids) => { - return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x }); + return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x }); }); var authHelper = new UserEditorAuthorizationHelper( @@ -362,7 +362,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Setup(service => service.GetAllPaths(It.IsAny(), It.IsAny())) .Returns((UmbracoObjectTypes objType, int[] ids) => { - return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x }); + return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x }); }); var authHelper = new UserEditorAuthorizationHelper( @@ -400,7 +400,7 @@ namespace Umbraco.Tests.Web.Controllers entityService.Setup(service => service.GetAllPaths(It.IsAny(), It.IsAny())) .Returns((UmbracoObjectTypes objType, int[] ids) => { - return ids.Select(x => new EntityPath { Path = nodePaths[x], Id = x }); + return ids.Select(x => new TreeEntityPath { Path = nodePaths[x], Id = x }); }); var authHelper = new UserEditorAuthorizationHelper( diff --git a/src/Umbraco.Web/Cache/CacheRefresherComponent.cs b/src/Umbraco.Web/Cache/CacheRefresherComponent.cs index 70cb53ab9a..ef1665e3c2 100644 --- a/src/Umbraco.Web/Cache/CacheRefresherComponent.cs +++ b/src/Umbraco.Web/Cache/CacheRefresherComponent.cs @@ -373,13 +373,13 @@ namespace Umbraco.Web.Cache #region DataTypeService - private void DataTypeService_Saved(IDataTypeService sender, SaveEventArgs e) + private void DataTypeService_Saved(IDataTypeService sender, SaveEventArgs e) { foreach (var entity in e.SavedEntities) _distributedCache.RefreshDataTypeCache(entity); } - private void DataTypeService_Deleted(IDataTypeService sender, DeleteEventArgs e) + private void DataTypeService_Deleted(IDataTypeService sender, DeleteEventArgs e) { foreach (var entity in e.DeletedEntities) _distributedCache.RemoveDataTypeCache(entity); diff --git a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs index 9f93718521..542553e5e6 100644 --- a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs @@ -49,7 +49,7 @@ namespace Umbraco.Web.Cache ClearAllIsolatedCacheByEntityType(); ClearAllIsolatedCacheByEntityType(); - var dataTypeCache = CacheHelper.IsolatedRuntimeCache.GetCache(); + var dataTypeCache = CacheHelper.IsolatedRuntimeCache.GetCache(); foreach (var payload in payloads) { diff --git a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs index 01b974435b..c9d800e10d 100644 --- a/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs +++ b/src/Umbraco.Web/Cache/DistributedCacheExtensions.cs @@ -125,14 +125,14 @@ namespace Umbraco.Web.Cache #region DataTypeCache - public static void RefreshDataTypeCache(this DistributedCache dc, IDataTypeDefinition dataType) + public static void RefreshDataTypeCache(this DistributedCache dc, IDataType dataType) { if (dataType == null) return; var payloads = new[] { new DataTypeCacheRefresher.JsonPayload(dataType.Id, dataType.Key, false) }; dc.RefreshByPayload(DataTypeCacheRefresher.UniqueId, payloads); } - public static void RemoveDataTypeCache(this DistributedCache dc, IDataTypeDefinition dataType) + public static void RemoveDataTypeCache(this DistributedCache dc, IDataType dataType) { if (dataType == null) return; var payloads = new[] { new DataTypeCacheRefresher.JsonPayload(dataType.Id, dataType.Key, true) }; diff --git a/src/Umbraco.Web/Composing/Current.cs b/src/Umbraco.Web/Composing/Current.cs index 43e970b1e3..2ee71df4e4 100644 --- a/src/Umbraco.Web/Composing/Current.cs +++ b/src/Umbraco.Web/Composing/Current.cs @@ -256,6 +256,8 @@ namespace Umbraco.Web.Composing public static ISqlContext SqlContext=> CoreCurrent.SqlContext; + public static IPublishedContentTypeFactory PublishedContentTypeFactory => CoreCurrent.PublishedContentTypeFactory; + #endregion } } diff --git a/src/Umbraco.Web/Editors/ContentTypeController.cs b/src/Umbraco.Web/Editors/ContentTypeController.cs index 2380f09079..76e19eb452 100644 --- a/src/Umbraco.Web/Editors/ContentTypeController.cs +++ b/src/Umbraco.Web/Editors/ContentTypeController.cs @@ -125,11 +125,11 @@ namespace Umbraco.Web.Editors } var preVals = Current.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(id); - var editor = Current.PropertyEditors[dataTypeDiff.PropertyEditorAlias]; + var editor = Current.PropertyEditors[dataTypeDiff.EditorAlias]; return new ContentPropertyDisplay() { - Editor = dataTypeDiff.PropertyEditorAlias, + Editor = dataTypeDiff.EditorAlias, Validation = new PropertyTypeValidation() { }, View = editor.ValueEditor.View, Config = editor.PreValueEditor.ConvertDbToEditor(editor.DefaultPreValues, preVals) diff --git a/src/Umbraco.Web/Editors/DataTypeController.cs b/src/Umbraco.Web/Editors/DataTypeController.cs index ca0c00455b..b7d1c1bbb9 100644 --- a/src/Umbraco.Web/Editors/DataTypeController.cs +++ b/src/Umbraco.Web/Editors/DataTypeController.cs @@ -41,7 +41,7 @@ namespace Umbraco.Web.Editors public DataTypeDisplay GetByName(string name) { var dataType = Services.DataTypeService.GetDataTypeDefinitionByName(name); - return dataType == null ? null : Mapper.Map(dataType); + return dataType == null ? null : Mapper.Map(dataType); } /// @@ -56,7 +56,7 @@ namespace Umbraco.Web.Editors { throw new HttpResponseException(HttpStatusCode.NotFound); } - return Mapper.Map(dataType); + return Mapper.Map(dataType); } /// @@ -81,8 +81,8 @@ namespace Umbraco.Web.Editors public DataTypeDisplay GetEmpty(int parentId) { - var dt = new DataTypeDefinition(parentId, ""); - return Mapper.Map(dt); + var dt = new DataType(parentId, ""); + return Mapper.Map(dt); } /// @@ -98,7 +98,7 @@ namespace Umbraco.Web.Editors throw new HttpResponseException(HttpStatusCode.NotFound); } - return Mapper.Map(dt); + return Mapper.Map(dt); } /// @@ -113,12 +113,12 @@ namespace Umbraco.Web.Editors //if it doesnt exist yet, we will create it. if (dt == null) { - dt = new DataTypeDefinition(Constants.PropertyEditors.ListViewAlias); + dt = new DataType(Constants.PropertyEditors.ListViewAlias); dt.Name = Constants.Conventions.DataTypes.ListViewPrefix + contentTypeAlias; Services.DataTypeService.Save(dt); } - return Mapper.Map(dt); + return Mapper.Map(dt); } /// @@ -151,10 +151,10 @@ namespace Umbraco.Web.Editors //now, lets check if the data type has the current editor selected, if that is true //we will need to wire up it's saved values. Otherwise it's an existing data type //that is changing it's underlying property editor, in which case there's no values. - if (dataType.PropertyEditorAlias == editorAlias) + if (dataType.EditorAlias == editorAlias) { //this is the currently assigned pre-value editor, return with values. - return Mapper.Map>(dataType); + return Mapper.Map>(dataType); } //these are new pre-values, so just return the field editors with default values @@ -220,7 +220,7 @@ namespace Umbraco.Web.Editors throw new HttpResponseException(Request.CreateValidationErrorResponse(ModelState)); } - var display = Mapper.Map(dataType.PersistedDataType); + var display = Mapper.Map(dataType.PersistedDataType); display.AddSuccessNotification(Services.TextService.Localize("speechBubbles/dataTypeSaved"), ""); //now return the updated model @@ -289,7 +289,7 @@ namespace Umbraco.Web.Editors { return Services.DataTypeService .GetAllDataTypeDefinitions() - .Select(Mapper.Map).Where(x => x.IsSystemDataType == false); + .Select(Mapper.Map).Where(x => x.IsSystemDataType == false); } /// @@ -306,7 +306,7 @@ namespace Umbraco.Web.Editors { var dataTypes = Services.DataTypeService .GetAllDataTypeDefinitions() - .Select(Mapper.Map) + .Select(Mapper.Map) .ToArray(); var propertyEditors = Current.PropertyEditors.ToArray(); diff --git a/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs b/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs index 863a30cb70..632f8cbe2e 100644 --- a/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs +++ b/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs @@ -59,7 +59,7 @@ namespace Umbraco.Web.Editors dataType.PropertyEditor = propertyEditor; //Validate the data type exists or create one if required - IDataTypeDefinition persisted; + IDataType persisted; switch (dataType.Action) { case ContentSaveAction.Save: @@ -75,8 +75,8 @@ namespace Umbraco.Web.Editors break; case ContentSaveAction.SaveNew: //create the persisted model from mapping the saved model - persisted = Mapper.Map(dataType); - ((DataTypeDefinition)persisted).ResetIdentity(); + persisted = Mapper.Map(dataType); + ((DataType)persisted).ResetIdentity(); break; default: actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, new ArgumentOutOfRangeException()); diff --git a/src/Umbraco.Web/Editors/PackageInstallController.cs b/src/Umbraco.Web/Editors/PackageInstallController.cs index da1e9d5f10..897d9085e8 100644 --- a/src/Umbraco.Web/Editors/PackageInstallController.cs +++ b/src/Umbraco.Web/Editors/PackageInstallController.cs @@ -97,7 +97,7 @@ namespace Umbraco.Web.Editors var removedMacros = new List(); var removedContentTypes = new List(); var removedDictionaryItems = new List(); - var removedDataTypes = new List(); + var removedDataTypes = new List(); var removedFiles = new List(); //Uninstall templates diff --git a/src/Umbraco.Web/Models/ContentEditing/ContentPropertyDto.cs b/src/Umbraco.Web/Models/ContentEditing/ContentPropertyDto.cs index 29b75b618e..8fe0317159 100644 --- a/src/Umbraco.Web/Models/ContentEditing/ContentPropertyDto.cs +++ b/src/Umbraco.Web/Models/ContentEditing/ContentPropertyDto.cs @@ -10,7 +10,7 @@ namespace Umbraco.Web.Models.ContentEditing /// internal class ContentPropertyDto : ContentPropertyBasic { - public IDataTypeDefinition DataType { get; set; } + public IDataType DataType { get; set; } public string Label { get; set; } public string Description { get; set; } public bool IsRequired { get; set; } diff --git a/src/Umbraco.Web/Models/ContentEditing/DataTypeSave.cs b/src/Umbraco.Web/Models/ContentEditing/DataTypeSave.cs index 1045d1227a..27b7aee1ef 100644 --- a/src/Umbraco.Web/Models/ContentEditing/DataTypeSave.cs +++ b/src/Umbraco.Web/Models/ContentEditing/DataTypeSave.cs @@ -32,7 +32,7 @@ namespace Umbraco.Web.Models.ContentEditing /// The real persisted data type /// [IgnoreDataMember] - internal IDataTypeDefinition PersistedDataType { get; set; } + internal IDataType PersistedDataType { get; set; } /// /// The PropertyEditor assigned diff --git a/src/Umbraco.Web/Models/Mapping/AvailablePropertyEditorsResolver.cs b/src/Umbraco.Web/Models/Mapping/AvailablePropertyEditorsResolver.cs index e7c18790b8..7d1a808171 100644 --- a/src/Umbraco.Web/Models/Mapping/AvailablePropertyEditorsResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/AvailablePropertyEditorsResolver.cs @@ -17,7 +17,7 @@ namespace Umbraco.Web.Models.Mapping _contentSection = contentSection; } - public IEnumerable Resolve(IDataTypeDefinition source) + public IEnumerable Resolve(IDataType source) { return Current.PropertyEditors .Where(x => @@ -25,7 +25,7 @@ namespace Umbraco.Web.Models.Mapping // fixme should we support deprecating? //if (_contentSection.ShowDeprecatedPropertyEditors) // return true; - return source.PropertyEditorAlias == x.Alias || x.IsDeprecated == false; + return source.EditorAlias == x.Alias || x.IsDeprecated == false; }) .OrderBy(x => x.Name) .Select(Mapper.Map); diff --git a/src/Umbraco.Web/Models/Mapping/CodeFileMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/CodeFileMapperProfile.cs index 17114ace87..082abfdace 100644 --- a/src/Umbraco.Web/Models/Mapping/CodeFileMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/CodeFileMapperProfile.cs @@ -21,7 +21,7 @@ namespace Umbraco.Web.Models.Mapping .ForMember(dest => dest.Snippet, opt => opt.Ignore()); CreateMap() - .IgnoreDeletableEntityCommonProperties() + .IgnoreEntityCommonProperties() .ForMember(dest => dest.Id, opt => opt.Ignore()) .ForMember(dest => dest.Key, opt => opt.Ignore()) .ForMember(dest => dest.Path, opt => opt.Ignore()) @@ -32,7 +32,7 @@ namespace Umbraco.Web.Models.Mapping .ForMember(dest => dest.HasIdentity, opt => opt.Ignore()); CreateMap() - .IgnoreDeletableEntityCommonProperties() + .IgnoreEntityCommonProperties() .ForMember(dest => dest.Id, opt => opt.Ignore()) .ForMember(dest => dest.Key, opt => opt.Ignore()) .ForMember(dest => dest.Path, opt => opt.Ignore()) diff --git a/src/Umbraco.Web/Models/Mapping/ContentTypeProfileExtensions.cs b/src/Umbraco.Web/Models/Mapping/ContentTypeProfileExtensions.cs index b1302a951c..8595987354 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentTypeProfileExtensions.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentTypeProfileExtensions.cs @@ -168,7 +168,7 @@ namespace Umbraco.Web.Models.Mapping .ForMember(dest => dest.Id, opt => opt.MapFrom(src => Convert.ToInt32(src.Id))) //These get persisted as part of the saving procedure, nothing to do with the display model - .IgnoreDeletableEntityCommonProperties() + .IgnoreEntityCommonProperties() .ForMember(dest => dest.AllowedAsRoot, opt => opt.MapFrom(src => src.AllowAsRoot)) .ForMember(dest => dest.CreatorId, opt => opt.Ignore()) diff --git a/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs index 6fc2e6376a..c7a9749715 100644 --- a/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/DataTypeMapperProfile.cs @@ -50,7 +50,7 @@ namespace Umbraco.Web.Models.Mapping .ForMember(dest => dest.Path, opt => opt.Ignore()) .ForMember(dest => dest.AdditionalData, opt => opt.Ignore()); - CreateMap() + CreateMap() .ForMember(dest => dest.Udi, opt => opt.MapFrom(src => Udi.Create(Constants.UdiEntityType.DataType, src.Key))) .ForMember(dest => dest.HasPrevalues, opt => opt.Ignore()) .ForMember(dest => dest.Icon, opt => opt.Ignore()) @@ -59,7 +59,7 @@ namespace Umbraco.Web.Models.Mapping .ForMember(dest => dest.IsSystemDataType, opt => opt.MapFrom(src => systemIds.Contains(src.Id))) .AfterMap((src, dest) => { - var editor = Current.PropertyEditors[src.PropertyEditorAlias]; + var editor = Current.PropertyEditors[src.EditorAlias]; if (editor != null) { dest.Alias = editor.Alias; @@ -68,11 +68,11 @@ namespace Umbraco.Web.Models.Mapping } }); - CreateMap() + CreateMap() .ForMember(dest => dest.Udi, opt => opt.MapFrom(src => Udi.Create(Constants.UdiEntityType.DataType, src.Key))) .ForMember(dest => dest.AvailableEditors, opt => opt.ResolveUsing(src => availablePropertyEditorsResolver.Resolve(src))) .ForMember(dest => dest.PreValues, opt => opt.ResolveUsing(src => preValueDisplayResolver.Resolve(src))) - .ForMember(dest => dest.SelectedEditor, opt => opt.MapFrom(src => src.PropertyEditorAlias.IsNullOrWhiteSpace() ? null : src.PropertyEditorAlias)) + .ForMember(dest => dest.SelectedEditor, opt => opt.MapFrom(src => src.EditorAlias.IsNullOrWhiteSpace() ? null : src.EditorAlias)) .ForMember(dest => dest.HasPrevalues, opt => opt.Ignore()) .ForMember(dest => dest.Notifications, opt => opt.Ignore()) .ForMember(dest => dest.Icon, opt => opt.Ignore()) @@ -81,7 +81,7 @@ namespace Umbraco.Web.Models.Mapping .ForMember(dest => dest.IsSystemDataType, opt => opt.MapFrom(src => systemIds.Contains(src.Id))) .AfterMap((src, dest) => { - var editor = Current.PropertyEditors[src.PropertyEditorAlias]; + var editor = Current.PropertyEditors[src.EditorAlias]; if (editor != null) { dest.Group = editor.Group; @@ -90,18 +90,18 @@ namespace Umbraco.Web.Models.Mapping }); //gets a list of PreValueFieldDisplay objects from the data type definition - CreateMap>() + CreateMap>() .ConvertUsing(src => preValueDisplayResolver.Resolve(src)); - CreateMap() - .ConstructUsing(src => new DataTypeDefinition(src.SelectedEditor) {CreateDate = DateTime.Now}) - .IgnoreDeletableEntityCommonProperties() + CreateMap() + .ConstructUsing(src => new DataType(src.SelectedEditor) {CreateDate = DateTime.Now}) + .IgnoreEntityCommonProperties() .ForMember(dest => dest.Id, opt => opt.MapFrom(src => Convert.ToInt32(src.Id))) //we have to ignore the Key otherwise this will reset the UniqueId field which should never change! // http://issues.umbraco.org/issue/U4-3911 .ForMember(dest => dest.Key, opt => opt.Ignore()) .ForMember(dest => dest.Path, opt => opt.Ignore()) - .ForMember(dest => dest.PropertyEditorAlias, opt => opt.MapFrom(src => src.SelectedEditor)) + .ForMember(dest => dest.EditorAlias, opt => opt.MapFrom(src => src.SelectedEditor)) .ForMember(dest => dest.DatabaseType, opt => opt.ResolveUsing(src => databaseTypeResolver.Resolve(src))) .ForMember(dest => dest.CreatorId, opt => opt.Ignore()) .ForMember(dest => dest.Level, opt => opt.Ignore()) diff --git a/src/Umbraco.Web/Models/Mapping/EntityProfileExtensions.cs b/src/Umbraco.Web/Models/Mapping/EntityProfileExtensions.cs index 209e1365b8..86519d8b39 100644 --- a/src/Umbraco.Web/Models/Mapping/EntityProfileExtensions.cs +++ b/src/Umbraco.Web/Models/Mapping/EntityProfileExtensions.cs @@ -8,19 +8,6 @@ namespace Umbraco.Web.Models.Mapping /// internal static class EntityProfileExtensions { - /// - /// Ignores readonly properties and the date values - /// - /// - /// - public static IMappingExpression IgnoreDeletableEntityCommonProperties(this IMappingExpression mapping) - where TDest: IDeletableEntity - { - return mapping - .IgnoreEntityCommonProperties() - .ForMember(dest => dest.DeletedDate, opt => opt.Ignore()); - } - /// /// Ignores readonly properties and the date values /// @@ -32,7 +19,8 @@ namespace Umbraco.Web.Models.Mapping return mapping .IgnoreAllPropertiesWithAnInaccessibleSetter() .ForMember(dest => dest.CreateDate, opt => opt.Ignore()) - .ForMember(dest => dest.UpdateDate, opt => opt.Ignore()); + .ForMember(dest => dest.UpdateDate, opt => opt.Ignore()) + .ForMember(dest => dest.DeleteDate, opt => opt.Ignore()); } } } diff --git a/src/Umbraco.Web/Models/Mapping/MemberMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/MemberMapperProfile.cs index 41cf88ba89..9e19c39430 100644 --- a/src/Umbraco.Web/Models/Mapping/MemberMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/MemberMapperProfile.cs @@ -61,7 +61,7 @@ namespace Umbraco.Web.Models.Mapping .ForMember(dest => dest.SortOrder, opt => opt.Ignore()) .ForMember(dest => dest.AdditionalData, opt => opt.Ignore()) .ForMember(dest => dest.FailedPasswordAttempts, opt => opt.Ignore()) - .ForMember(dest => dest.DeletedDate, opt => opt.Ignore()) + .ForMember(dest => dest.DeleteDate, opt => opt.Ignore()) .ForMember(dest => dest.WriterId, opt => opt.Ignore()) //TODO: Support these eventually .ForMember(dest => dest.PasswordQuestion, opt => opt.Ignore()) diff --git a/src/Umbraco.Web/Models/Mapping/PreValueDisplayResolver.cs b/src/Umbraco.Web/Models/Mapping/PreValueDisplayResolver.cs index fb7da2b7a4..0abc8598b6 100644 --- a/src/Umbraco.Web/Models/Mapping/PreValueDisplayResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/PreValueDisplayResolver.cs @@ -43,15 +43,15 @@ namespace Umbraco.Web.Models.Mapping } } - public IEnumerable Resolve(IDataTypeDefinition source) + public IEnumerable Resolve(IDataType source) { PropertyEditor propEd = null; - if (source.PropertyEditorAlias.IsNullOrWhiteSpace() == false) + if (source.EditorAlias.IsNullOrWhiteSpace() == false) { - propEd = Current.PropertyEditors[source.PropertyEditorAlias]; + propEd = Current.PropertyEditors[source.EditorAlias]; if (propEd == null) { - throw new InvalidOperationException("Could not find property editor with alias " + source.PropertyEditorAlias); + throw new InvalidOperationException("Could not find property editor with alias " + source.EditorAlias); } } diff --git a/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs b/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs index 490b93fdaa..0663d7d983 100644 --- a/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/TabsAndPropertiesResolver.cs @@ -150,10 +150,10 @@ namespace Umbraco.Web.Models.Mapping var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dt.Id); - var editor = Current.PropertyEditors[dt.PropertyEditorAlias]; + var editor = Current.PropertyEditors[dt.EditorAlias]; if (editor == null) { - throw new NullReferenceException("The property editor with alias " + dt.PropertyEditorAlias + " does not exist"); + throw new NullReferenceException("The property editor with alias " + dt.EditorAlias + " does not exist"); } var listViewTab = new Tab diff --git a/src/Umbraco.Web/Models/Mapping/TemplateMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/TemplateMapperProfile.cs index 7eb148dbca..3c283cb3a5 100644 --- a/src/Umbraco.Web/Models/Mapping/TemplateMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/TemplateMapperProfile.cs @@ -12,7 +12,7 @@ namespace Umbraco.Web.Models.Mapping .ForMember(dest => dest.Notifications, opt => opt.Ignore()); CreateMap() - .IgnoreDeletableEntityCommonProperties() + .IgnoreEntityCommonProperties() .ForMember(dest => dest.Path, opt => opt.Ignore()) .ForMember(dest => dest.VirtualPath, opt => opt.Ignore()) .ForMember(dest => dest.Path, opt => opt.Ignore()) diff --git a/src/Umbraco.Web/Models/Mapping/UserMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/UserMapperProfile.cs index 84026a34eb..0294ea3da8 100644 --- a/src/Umbraco.Web/Models/Mapping/UserMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/UserMapperProfile.cs @@ -24,7 +24,7 @@ namespace Umbraco.Web.Models.Mapping CreateMap() .ConstructUsing((UserGroupSave save) => new UserGroup { CreateDate = DateTime.Now }) - .IgnoreDeletableEntityCommonProperties() + .IgnoreEntityCommonProperties() .ForMember(dest => dest.Id, opt => opt.Condition(source => GetIntId(source.Id) > 0)) .ForMember(dest => dest.Id, opt => opt.MapFrom(source => GetIntId(source.Id))) .ForMember(dest => dest.Permissions, opt => opt.MapFrom(source => source.DefaultPermissions)) @@ -39,7 +39,7 @@ namespace Umbraco.Web.Models.Mapping //Used for merging existing UserSave to an existing IUser instance - this will not create an IUser instance! CreateMap() - .IgnoreDeletableEntityCommonProperties() + .IgnoreEntityCommonProperties() .ForMember(dest => dest.Id, opt => opt.Condition(src => GetIntId(src.Id) > 0)) .ForMember(dest => dest.SessionTimeout, opt => opt.Ignore()) .ForMember(dest => dest.EmailConfirmedDate, opt => opt.Ignore()) @@ -70,7 +70,7 @@ namespace Umbraco.Web.Models.Mapping }); CreateMap() - .IgnoreDeletableEntityCommonProperties() + .IgnoreEntityCommonProperties() .ForMember(dest => dest.Id, opt => opt.Ignore()) .ForMember(dest => dest.StartContentIds, opt => opt.Ignore()) .ForMember(dest => dest.StartMediaIds, opt => opt.Ignore()) diff --git a/src/Umbraco.Web/Models/PublishedContentBase.cs b/src/Umbraco.Web/Models/PublishedContentBase.cs index 25f43ca42a..099367642c 100644 --- a/src/Umbraco.Web/Models/PublishedContentBase.cs +++ b/src/Umbraco.Web/Models/PublishedContentBase.cs @@ -60,7 +60,7 @@ namespace Umbraco.Web.Models //This is a hack - since we now have 2 properties that support a URL: upload and cropper, we need to detect this since we always // want to return the normal URL and the cropper stores data as json - switch (propType.PropertyEditorAlias) + switch (propType.EditorAlias) { case Constants.PropertyEditors.UploadFieldAlias: _url = prop.GetValue().ToString(); diff --git a/src/Umbraco.Web/Models/PublishedProperty.cs b/src/Umbraco.Web/Models/PublishedProperty.cs index 80d297f129..535b704e7b 100644 --- a/src/Umbraco.Web/Models/PublishedProperty.cs +++ b/src/Umbraco.Web/Models/PublishedProperty.cs @@ -30,11 +30,11 @@ namespace Umbraco.Web.Models return propertyTypes.Select(x => { - var p = properties.SingleOrDefault(xx => xx.Alias == x.PropertyTypeAlias); + var p = properties.SingleOrDefault(xx => xx.Alias == x.Alias); var v = p == null || p.GetValue() == null ? null : p.GetValue(); if (v != null) { - var e = propertyEditors[x.PropertyEditorAlias]; + var e = propertyEditors[x.EditorAlias]; // We are converting to string, even for database values which are integer or // DateTime, which is not optimum. Doing differently would require that we have a way to tell diff --git a/src/Umbraco.Web/Models/UmbracoProperty.cs b/src/Umbraco.Web/Models/UmbracoProperty.cs index ffef9f431f..fc3806486c 100644 --- a/src/Umbraco.Web/Models/UmbracoProperty.cs +++ b/src/Umbraco.Web/Models/UmbracoProperty.cs @@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations; using System.Xml; using Umbraco.Core; using Umbraco.Core.Models; +using DataType = System.ComponentModel.DataAnnotations.DataType; namespace Umbraco.Web.Models { diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs index 1e79915eac..cb34dc7455 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/ContentPickerValueConverter.cs @@ -24,8 +24,8 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters } public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.ContentPickerAlias) - || propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.ContentPicker2Alias); + => propertyType.EditorAlias.Equals(Constants.PropertyEditors.ContentPickerAlias) + || propertyType.EditorAlias.Equals(Constants.PropertyEditors.ContentPicker2Alias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (IPublishedContent); @@ -51,7 +51,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters if (inter == null) return null; - if ((propertyType.PropertyTypeAlias != null && PropertiesToExclude.Contains(propertyType.PropertyTypeAlias.ToLower(CultureInfo.InvariantCulture))) == false) + if ((propertyType.Alias != null && PropertiesToExclude.Contains(propertyType.Alias.ToLower(CultureInfo.InvariantCulture))) == false) { IPublishedContent content; if (inter is int id) diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MacroContainerValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MacroContainerValueConverter.cs index 225216ce8a..5f7494cfb1 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MacroContainerValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/MacroContainerValueConverter.cs @@ -30,7 +30,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters } public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias == Constants.PropertyEditors.MacroContainerAlias; + => propertyType.EditorAlias == Constants.PropertyEditors.MacroContainerAlias; public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (IHtmlString); diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs index 66d865c4ee..66d3ec0639 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/MarkdownEditorValueConverter.cs @@ -12,7 +12,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters public class MarkdownEditorValueConverter : PropertyValueConverterBase { public override bool IsConverter(PublishedPropertyType propertyType) - => Constants.PropertyEditors.MarkdownEditorAlias == propertyType.PropertyEditorAlias; + => Constants.PropertyEditors.MarkdownEditorAlias == propertyType.EditorAlias; public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (IHtmlString); diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerLegacyValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerLegacyValueConverter.cs index b4d8702679..6ce3385f2e 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerLegacyValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerLegacyValueConverter.cs @@ -35,20 +35,20 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters public override bool IsConverter(PublishedPropertyType propertyType) { - return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MultipleMediaPickerAlias); + return propertyType.EditorAlias.Equals(Constants.PropertyEditors.MultipleMediaPickerAlias); } public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType) => PropertyCacheLevel.Snapshot; public override Type GetPropertyValueType(PublishedPropertyType propertyType) - => IsMultipleDataType(propertyType.DataTypeId, propertyType.PropertyEditorAlias) + => IsMultipleDataType(propertyType.DataType.Id, propertyType.EditorAlias) ? typeof (IEnumerable) : typeof (IPublishedContent); public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview) { - if (IsMultipleDataType(propertyType.DataTypeId, propertyType.PropertyEditorAlias)) + if (IsMultipleDataType(propertyType.DataType.Id, propertyType.EditorAlias)) { return source.ToString() .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) @@ -70,7 +70,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters if (nodeIds.Length > 0) { - var error = $"Data type \"{_services.DataTypeService.GetDataTypeDefinitionById(propertyType.DataTypeId).Name}\" is not set to allow multiple items but appears to contain multiple items, check the setting and save the data type again"; + var error = $"Data type \"{_services.DataTypeService.GetDataTypeDefinitionById(propertyType.DataType.Id).Name}\" is not set to allow multiple items but appears to contain multiple items, check the setting and save the data type again"; _logger.Warn(error); throw new Exception(error); @@ -93,7 +93,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters var umbHelper = new UmbracoHelper(_umbracoContextAccessor.UmbracoContext, _services, _appCache); - if (IsMultipleDataType(propertyType.DataTypeId, propertyType.PropertyEditorAlias)) + if (IsMultipleDataType(propertyType.DataType.Id, propertyType.EditorAlias)) { var nodeIds = (int[])source; var multiMediaPicker = Enumerable.Empty(); diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs index f1e0ef6499..e5c978373e 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs @@ -29,11 +29,11 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters public override bool IsConverter(PublishedPropertyType propertyType) { - return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MediaPicker2Alias); + return propertyType.EditorAlias.Equals(Constants.PropertyEditors.MediaPicker2Alias); } public override Type GetPropertyValueType(PublishedPropertyType propertyType) - => IsMultipleDataType(propertyType.DataTypeId, propertyType.PropertyEditorAlias) + => IsMultipleDataType(propertyType.DataType.Id, propertyType.EditorAlias) ? typeof (IEnumerable) : typeof (IPublishedContent); @@ -102,7 +102,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters mediaItems.Add(item); } - if (IsMultipleDataType(propertyType.DataTypeId, propertyType.PropertyEditorAlias)) + if (IsMultipleDataType(propertyType.DataType.Id, propertyType.EditorAlias)) return mediaItems; return mediaItems.FirstOrDefault(); } diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs index 3ccbd41e06..5336b5bbb0 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/MemberPickerValueConverter.cs @@ -19,8 +19,8 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters public override bool IsConverter(PublishedPropertyType propertyType) { - return propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.MemberPickerAlias) - || propertyType.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.MemberPicker2Alias); + return propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.MemberPickerAlias) + || propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.MemberPicker2Alias); } public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType) diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs index ee9ab01952..f71a6e2a7b 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/MultiNodeTreePickerValueConverter.cs @@ -35,8 +35,8 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters public override bool IsConverter(PublishedPropertyType propertyType) { - return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MultiNodeTreePickerAlias) - || propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MultiNodeTreePicker2Alias); + return propertyType.EditorAlias.Equals(Constants.PropertyEditors.MultiNodeTreePickerAlias) + || propertyType.EditorAlias.Equals(Constants.PropertyEditors.MultiNodeTreePicker2Alias); } public override PropertyCacheLevel GetPropertyCacheLevel(PublishedPropertyType propertyType) @@ -47,7 +47,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters public override object ConvertSourceToIntermediate(IPublishedElement owner, PublishedPropertyType propertyType, object source, bool preview) { - if (propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MultiNodeTreePickerAlias)) + if (propertyType.EditorAlias.Equals(Constants.PropertyEditors.MultiNodeTreePickerAlias)) { var nodeIds = source.ToString() .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) @@ -55,7 +55,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters .ToArray(); return nodeIds; } - if (propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MultiNodeTreePicker2Alias)) + if (propertyType.EditorAlias.Equals(Constants.PropertyEditors.MultiNodeTreePicker2Alias)) { var nodeIds = source.ToString() .Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries) @@ -76,11 +76,11 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters //TODO: Inject an UmbracoHelper and create a GetUmbracoHelper method based on either injected or singleton if (UmbracoContext.Current != null) { - if (propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MultiNodeTreePickerAlias)) + if (propertyType.EditorAlias.Equals(Constants.PropertyEditors.MultiNodeTreePickerAlias)) { var nodeIds = (int[])source; - if ((propertyType.PropertyTypeAlias != null && PropertiesToExclude.InvariantContains(propertyType.PropertyTypeAlias)) == false) + if ((propertyType.Alias != null && PropertiesToExclude.InvariantContains(propertyType.Alias)) == false) { var multiNodeTreePicker = new List(); @@ -106,11 +106,11 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters return nodeIds.FirstOrDefault(); } - if (propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.MultiNodeTreePicker2Alias)) + if (propertyType.EditorAlias.Equals(Constants.PropertyEditors.MultiNodeTreePicker2Alias)) { var udis = (Udi[])source; - if ((propertyType.PropertyTypeAlias != null && PropertiesToExclude.InvariantContains(propertyType.PropertyTypeAlias)) == false) + if ((propertyType.Alias != null && PropertiesToExclude.InvariantContains(propertyType.Alias)) == false) { var multiNodeTreePicker = new List(); diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs index 7d112d8994..6e882ddc16 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs @@ -53,7 +53,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters /// public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview) { - using (_proflog.DebugDuration($"ConvertPropertyToNestedContent ({propertyType.DataTypeId})")) + using (_proflog.DebugDuration($"ConvertPropertyToNestedContent ({propertyType.DataType.Id})")) { var value = (string)inter; if (string.IsNullOrWhiteSpace(value)) return null; diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentSingleValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentSingleValueConverter.cs index 75fbcc8ab8..8d74bb0fef 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentSingleValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentSingleValueConverter.cs @@ -52,7 +52,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters /// public override object ConvertIntermediateToObject(IPublishedElement owner, PublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object inter, bool preview) { - using (_proflog.DebugDuration($"ConvertPropertyToNestedContent ({propertyType.DataTypeId})")) + using (_proflog.DebugDuration($"ConvertPropertyToNestedContent ({propertyType.DataType.Id})")) { var value = (string) inter; if (string.IsNullOrWhiteSpace(value)) return null; diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentValueConverterBase.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentValueConverterBase.cs index 80c32d5ca8..b1eb59a164 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentValueConverterBase.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentValueConverterBase.cs @@ -22,7 +22,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters public static bool IsNested(PublishedPropertyType publishedProperty) { - return publishedProperty.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditors.NestedContentAlias); + return publishedProperty.EditorAlias.InvariantEquals(Constants.PropertyEditors.NestedContentAlias); } public static bool IsNestedSingle(PublishedPropertyType publishedProperty) diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksLegacyValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksLegacyValueConverter.cs index a53c606395..c0bc4c41ad 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksLegacyValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksLegacyValueConverter.cs @@ -36,7 +36,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters } public override bool IsConverter(PublishedPropertyType propertyType) - => MatchingEditors.Contains(propertyType.PropertyEditorAlias); + => MatchingEditors.Contains(propertyType.EditorAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (JArray); @@ -65,7 +65,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters { if (type == "internal") { - switch (propertyType.PropertyEditorAlias) + switch (propertyType.EditorAlias) { case Constants.PropertyEditors.RelatedLinksAlias: var intLinkId = a.Value("link"); diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksValueConverter.cs index 2b7bdbe7ec..9fbd9e3677 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/RelatedLinksValueConverter.cs @@ -40,8 +40,8 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters /// The . /// public override bool IsConverter(PublishedPropertyType propertyType) - => propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinksAlias) - || propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditors.RelatedLinks2Alias); + => propertyType.EditorAlias.Equals(Constants.PropertyEditors.RelatedLinksAlias) + || propertyType.EditorAlias.Equals(Constants.PropertyEditors.RelatedLinks2Alias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (JArray); diff --git a/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs b/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs index a18665d6cd..45ce7ed1db 100644 --- a/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs +++ b/src/Umbraco.Web/PropertyEditors/ValueConverters/TextStringValueConverter.cs @@ -17,7 +17,7 @@ namespace Umbraco.Web.PropertyEditors.ValueConverters }; public override bool IsConverter(PublishedPropertyType propertyType) - => PropertyTypeAliases.Contains(propertyType.PropertyEditorAlias); + => PropertyTypeAliases.Contains(propertyType.EditorAlias); public override Type GetPropertyValueType(PublishedPropertyType propertyType) => typeof (string); diff --git a/src/Umbraco.Web/PublishedCache/NuCache/ContentStore.cs b/src/Umbraco.Web/PublishedCache/NuCache/ContentStore.cs index 175b13da16..6915baf60a 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/ContentStore.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/ContentStore.cs @@ -361,7 +361,7 @@ namespace Umbraco.Web.PublishedCache.NuCache var contentTypes = _contentTypesById .Where(kvp => kvp.Value.Value != null && - kvp.Value.Value.PropertyTypes.Any(p => dataTypeIds.Contains(p.DataTypeId))) + kvp.Value.Value.PropertyTypes.Any(p => dataTypeIds.Contains(p.DataType.Id))) .Select(kvp => kvp.Value.Value) .Select(x => getContentType(x.Id)) .Where(x => x != null) // poof, gone, very unlikely and probably an anomaly diff --git a/src/Umbraco.Web/PublishedCache/NuCache/Navigable/NavigableContentType.cs b/src/Umbraco.Web/PublishedCache/NuCache/Navigable/NavigableContentType.cs index 7e93a175d7..068a1866ee 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/Navigable/NavigableContentType.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/Navigable/NavigableContentType.cs @@ -57,7 +57,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.Navigable { Name = contentType.Alias; FieldTypes = BuiltinProperties - .Union(contentType.PropertyTypes.Select(propertyType => new NavigablePropertyType(propertyType.PropertyTypeAlias))) + .Union(contentType.PropertyTypes.Select(propertyType => new NavigablePropertyType(propertyType.Alias))) .ToArray(); } } diff --git a/src/Umbraco.Web/PublishedCache/NuCache/Property.cs b/src/Umbraco.Web/PublishedCache/NuCache/Property.cs index c74e115df9..9a74b66897 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/Property.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/Property.cs @@ -89,11 +89,11 @@ namespace Umbraco.Web.PublishedCache.NuCache // used to cache the recursive *property* for this property internal string RecurseCacheKey => _recurseCacheKey - ?? (_recurseCacheKey = CacheKeys.PropertyRecurse(_contentUid, PropertyTypeAlias, _isPreviewing)); + ?? (_recurseCacheKey = CacheKeys.PropertyRecurse(_contentUid, Alias, _isPreviewing)); // used to cache the CacheValues of this property internal string ValuesCacheKey => _valuesCacheKey - ?? (_valuesCacheKey = CacheKeys.PropertyCacheValues(_contentUid, PropertyTypeAlias, _isPreviewing)); + ?? (_valuesCacheKey = CacheKeys.PropertyCacheValues(_contentUid, Alias, _isPreviewing)); private CacheValues GetCacheValues(PropertyCacheLevel cacheLevel) { diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs index 4628f8dfb3..97f8ee4634 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedContent.cs @@ -33,7 +33,7 @@ namespace Umbraco.Web.PublishedCache.NuCache var properties = new List(); foreach (var propertyType in _contentNode.ContentType.PropertyTypes) { - if (contentData.Properties.TryGetValue(propertyType.PropertyTypeAlias, out var pdatas)) + if (contentData.Properties.TryGetValue(propertyType.Alias, out var pdatas)) properties.Add(new Property(propertyType, this, pdatas, _publishedSnapshotAccessor)); } PropertiesArray = properties.ToArray(); diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedMember.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedMember.cs index 003c291ea9..8b3d01f6e9 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedMember.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedMember.cs @@ -81,7 +81,7 @@ namespace Umbraco.Web.PublishedCache.NuCache private static void AddIf(PublishedContentType contentType, IDictionary properties, string alias, object value) { var propertyType = contentType.GetPropertyType(alias); - if (propertyType == null || propertyType.IsUmbraco == false) return; + if (propertyType == null || propertyType.IsUserProperty) return; properties[alias] = new[] { new PropertyData { Value = value } }; } diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs index 47f97249e5..86599e7a65 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs @@ -278,7 +278,7 @@ namespace Umbraco.Web.PublishedCache.NuCache // content (and types) are read-locked var contentTypes = _serviceContext.ContentTypeService.GetAll() - .Select(x => _publishedContentTypeFactory.CreateContentType(PublishedItemType.Content, x)); + .Select(x => _publishedContentTypeFactory.CreateContentType(x)); _contentStore.UpdateContentTypes(null, contentTypes, null); _localContentDb?.Clear(); @@ -294,7 +294,7 @@ namespace Umbraco.Web.PublishedCache.NuCache private void LoadContentFromLocalDbLocked(IScope scope) { var contentTypes = _serviceContext.ContentTypeService.GetAll() - .Select(x => _publishedContentTypeFactory.CreateContentType(PublishedItemType.Content, x)); + .Select(x => _publishedContentTypeFactory.CreateContentType(x)); _contentStore.UpdateContentTypes(null, contentTypes, null); _logger.Debug("Loading content from local db..."); @@ -346,7 +346,7 @@ namespace Umbraco.Web.PublishedCache.NuCache // locks & notes: see content var mediaTypes = _serviceContext.MediaTypeService.GetAll() - .Select(x => _publishedContentTypeFactory.CreateContentType(PublishedItemType.Media, x)); + .Select(x => _publishedContentTypeFactory.CreateContentType(x)); _mediaStore.UpdateContentTypes(null, mediaTypes, null); _localMediaDb?.Clear(); @@ -362,7 +362,7 @@ namespace Umbraco.Web.PublishedCache.NuCache private void LoadMediaFromLocalDbLocked(IScope scope) { var mediaTypes = _serviceContext.MediaTypeService.GetAll() - .Select(x => _publishedContentTypeFactory.CreateContentType(PublishedItemType.Media, x)); + .Select(x => _publishedContentTypeFactory.CreateContentType(x)); _mediaStore.UpdateContentTypes(null, mediaTypes, null); _logger.Debug("Loading media from local db..."); @@ -848,7 +848,7 @@ namespace Umbraco.Web.PublishedCache.NuCache // some may be missing - not checking here - return contentTypes.Select(x => _publishedContentTypeFactory.CreateContentType(itemType, x)); + return contentTypes.Select(x => _publishedContentTypeFactory.CreateContentType(x)); } private PublishedContentType CreateContentType(PublishedItemType itemType, int id) @@ -869,7 +869,7 @@ namespace Umbraco.Web.PublishedCache.NuCache throw new ArgumentOutOfRangeException(nameof(itemType)); } - return contentType == null ? null : _publishedContentTypeFactory.CreateContentType(itemType, contentType); + return contentType == null ? null : _publishedContentTypeFactory.CreateContentType(contentType); } private void RefreshContentTypesLocked(IEnumerable removedIds, IEnumerable refreshedIds, IEnumerable otherIds, IEnumerable newIds) diff --git a/src/Umbraco.Web/PublishedCache/PublishedContentTypeCache.cs b/src/Umbraco.Web/PublishedCache/PublishedContentTypeCache.cs index 11243e4a7e..b2bc3424b6 100644 --- a/src/Umbraco.Web/PublishedCache/PublishedContentTypeCache.cs +++ b/src/Umbraco.Web/PublishedCache/PublishedContentTypeCache.cs @@ -114,7 +114,7 @@ namespace Umbraco.Web.PublishedCache { _lock.EnterWriteLock(); - var toRemove = _typesById.Values.Where(x => x.PropertyTypes.Any(xx => xx.DataTypeId == id)).ToArray(); + var toRemove = _typesById.Values.Where(x => x.PropertyTypes.Any(xx => xx.DataType.Id == id)).ToArray(); foreach (var type in toRemove) { _typesByAlias.Remove(GetAliasKey(type)); @@ -226,7 +226,7 @@ namespace Umbraco.Web.PublishedCache if (contentType == null) throw new Exception($"ContentTypeService failed to find a {itemType.ToString().ToLower()} type with alias \"{alias}\"."); - return _publishedContentTypeFactory.CreateContentType(itemType, contentType); + return _publishedContentTypeFactory.CreateContentType(contentType); } private PublishedContentType CreatePublishedContentType(PublishedItemType itemType, int id) @@ -253,7 +253,7 @@ namespace Umbraco.Web.PublishedCache if (contentType == null) throw new Exception($"ContentTypeService failed to find a {itemType.ToString().ToLower()} type with id {id}."); - return _publishedContentTypeFactory.CreateContentType(itemType, contentType); + return _publishedContentTypeFactory.CreateContentType(contentType); } // for unit tests - changing the callback must reset the cache obviously diff --git a/src/Umbraco.Web/PublishedCache/PublishedElement.cs b/src/Umbraco.Web/PublishedCache/PublishedElement.cs index e5b26453a4..6c90a28e0d 100644 --- a/src/Umbraco.Web/PublishedCache/PublishedElement.cs +++ b/src/Umbraco.Web/PublishedCache/PublishedElement.cs @@ -35,7 +35,7 @@ namespace Umbraco.Web.PublishedCache .PropertyTypes .Select(propertyType => { - values.TryGetValue(propertyType.PropertyTypeAlias, out var value); + values.TryGetValue(propertyType.Alias, out var value); return (IPublishedProperty) new PublishedElementPropertyBase(propertyType, this, previewing, referenceCacheLevel, value, publishedSnapshotAccessor); }) .ToArray(); diff --git a/src/Umbraco.Web/PublishedCache/PublishedElementPropertyBase.cs b/src/Umbraco.Web/PublishedCache/PublishedElementPropertyBase.cs index 0dbbf4944c..2c5b93f219 100644 --- a/src/Umbraco.Web/PublishedCache/PublishedElementPropertyBase.cs +++ b/src/Umbraco.Web/PublishedCache/PublishedElementPropertyBase.cs @@ -42,7 +42,7 @@ namespace Umbraco.Web.PublishedCache // used to cache the CacheValues of this property // ReSharper disable InconsistentlySynchronizedField internal string ValuesCacheKey => _valuesCacheKey - ?? (_valuesCacheKey = PropertyCacheValues(Element.Key, PropertyTypeAlias, IsPreviewing)); + ?? (_valuesCacheKey = PropertyCacheValues(Element.Key, Alias, IsPreviewing)); // ReSharper restore InconsistentlySynchronizedField protected class CacheValues diff --git a/src/Umbraco.Web/PublishedCache/PublishedMember.cs b/src/Umbraco.Web/PublishedCache/PublishedMember.cs index 78264638cc..0d5e61a683 100644 --- a/src/Umbraco.Web/PublishedCache/PublishedMember.cs +++ b/src/Umbraco.Web/PublishedCache/PublishedMember.cs @@ -25,13 +25,32 @@ namespace Umbraco.Web.PublishedCache _membershipUser = member; _publishedMemberType = publishedMemberType ?? throw new ArgumentNullException(nameof(publishedMemberType)); - var properties = PublishedProperty.MapProperties(_publishedMemberType.PropertyTypes, _member.Properties, + // fixme + // RawValueProperty is used for two things here + // - for the 'map properties' thing that we should really get rid of + // - for populating properties that every member should always have, and that we force-create + // if they are not part of the member type properties - in which case they are created as + // simple raw properties - which are completely invariant + + var _properties = PublishedProperty.MapProperties(_publishedMemberType.PropertyTypes, _member.Properties, (t, v) => new RawValueProperty(t, this, v ?? string.Empty)); - _properties = WithMemberProperties(properties).ToArray(); + + var properties = new List(); + foreach (var propertyType in _publishedMemberType.PropertyTypes) + { + var property = _member.Properties[propertyType.Alias]; + if (property == null) continue; + + //properties.Add(new FooProperty(propertyType, this, property.Values)); + } + EnsureMemberProperties(properties); + _properties = properties.ToArray(); } #region Membership provider member properties + // fixme why this? + public string Email => _membershipUser.Email; public string UserName => _membershipUser.Username; @@ -79,36 +98,38 @@ namespace Umbraco.Web.PublishedCache public override IPublishedProperty GetProperty(string alias) { - return _properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias)); + return _properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias)); } - private IEnumerable WithMemberProperties(IEnumerable properties) + private void EnsureMemberProperties(List properties) { - var propertiesList = properties.ToList(); - var aliases = propertiesList.Select(x => x.PropertyTypeAlias).ToList(); + var aliases = properties.Select(x => x.Alias).ToList(); - if (!aliases.Contains("Email")) - propertiesList.Add(new RawValueProperty(ContentType.GetPropertyType("Email"), this, Email)); - if (!aliases.Contains("UserName")) - propertiesList.Add(new RawValueProperty(ContentType.GetPropertyType("UserName"), this, UserName)); - if (!aliases.Contains("PasswordQuestion")) - propertiesList.Add(new RawValueProperty(ContentType.GetPropertyType("PasswordQuestion"), this, PasswordQuestion)); - if (!aliases.Contains("Comments")) - propertiesList.Add(new RawValueProperty(ContentType.GetPropertyType("Comments"), this, Comments)); - if (!aliases.Contains("IsApproved")) - propertiesList.Add(new RawValueProperty(ContentType.GetPropertyType("IsApproved"), this, IsApproved)); - if (!aliases.Contains("IsLockedOut")) - propertiesList.Add(new RawValueProperty(ContentType.GetPropertyType("IsLockedOut"), this, IsLockedOut)); - if (!aliases.Contains("LastLockoutDate")) - propertiesList.Add(new RawValueProperty(ContentType.GetPropertyType("LastLockoutDate"), this, LastLockoutDate)); - if (!aliases.Contains("CreateDate")) - propertiesList.Add(new RawValueProperty(ContentType.GetPropertyType("CreateDate"), this, CreateDate)); - if (!aliases.Contains("LastLoginDate")) - propertiesList.Add(new RawValueProperty(ContentType.GetPropertyType("LastLoginDate"), this, LastLoginDate)); - if (!aliases.Contains("LastPasswordChangeDate")) - propertiesList.Add(new RawValueProperty(ContentType.GetPropertyType("LastPasswordChangeDate"), this, LastPasswordChangeDate)); + EnsureMemberProperty(properties, aliases, "Email", Email); + EnsureMemberProperty(properties, aliases, "UserName", UserName); + EnsureMemberProperty(properties, aliases, "PasswordQuestion", PasswordQuestion); + EnsureMemberProperty(properties, aliases, "Comments", Comments); + EnsureMemberProperty(properties, aliases, "IsApproved", IsApproved); + EnsureMemberProperty(properties, aliases, "IsLockedOut", IsLockedOut); + EnsureMemberProperty(properties, aliases, "LastLockoutDate", LastLockoutDate); + EnsureMemberProperty(properties, aliases, "CreateDate", CreateDate); + EnsureMemberProperty(properties, aliases, "LastLoginDate", LastLoginDate); + EnsureMemberProperty(properties, aliases, "LastPasswordChangeDate", LastPasswordChangeDate); + } - return propertiesList; + private void EnsureMemberProperty(List properties, List aliases, string alias, object value) + { + // if the property already has a value, nothing to do + if (aliases.Contains(alias)) return; + + // if not a property type, ignore + var propertyType = ContentType.GetPropertyType(alias); + if (propertyType == null) return; + + // create a raw-value property + // note: throws if propertyType variations is not InvariantNeutral + var property = new RawValueProperty(propertyType, this, value); + properties.Add(property); } public override PublishedContentType ContentType => _publishedMemberType; diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs index 2768133072..690ae7e5b7 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs @@ -470,7 +470,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache //lets check if the alias does not exist on the document. //NOTE: Examine will not index empty values and we do not output empty XML Elements to the cache - either of these situations // would mean that the property is missing from the collection whether we are getting the value from Examine or from the library media cache. - if (dd.Properties.All(x => x.PropertyTypeAlias.InvariantEquals(alias) == false)) + if (dd.Properties.All(x => x.Alias.InvariantEquals(alias) == false)) { return null; } @@ -479,13 +479,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache { //We are going to check for a special field however, that is because in some cases we store a 'Raw' //value in the index such as for xml/html. - var rawValue = dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(BaseUmbracoIndexer.RawFieldPrefix + alias)); + var rawValue = dd.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(BaseUmbracoIndexer.RawFieldPrefix + alias)); return rawValue - ?? dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias)); + ?? dd.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias)); } //if its not loaded from examine, then just return the property - return dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias)); + return dd.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias)); } /// @@ -678,7 +678,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache //make sure we create them even if there's no value foreach (var propertyType in _contentType.PropertyTypes) { - var alias = propertyType.PropertyTypeAlias; + var alias = propertyType.Alias; _keysAdded.Add(alias); string value; const bool isPreviewing = false; // false :: never preview a media diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs index 62dbbb406e..0ab219d368 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs @@ -391,11 +391,11 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache properties = new Dictionary(StringComparer.OrdinalIgnoreCase); foreach (var propertyType in contentType.PropertyTypes) { - var val = propertyNodes.TryGetValue(propertyType.PropertyTypeAlias.ToLowerInvariant(), out XmlNode n) + var val = propertyNodes.TryGetValue(propertyType.Alias.ToLowerInvariant(), out XmlNode n) ? new XmlPublishedProperty(propertyType, node, isPreviewing, n) : new XmlPublishedProperty(propertyType, node, isPreviewing); - properties[propertyType.PropertyTypeAlias] = val; + properties[propertyType.Alias] = val; } } diff --git a/src/Umbraco.Web/PublishedContentExtensions.cs b/src/Umbraco.Web/PublishedContentExtensions.cs index edf32c2a1d..be51c36931 100644 --- a/src/Umbraco.Web/PublishedContentExtensions.cs +++ b/src/Umbraco.Web/PublishedContentExtensions.cs @@ -1140,7 +1140,7 @@ namespace Umbraco.Web foreach (var p in from IPublishedProperty p in n.Properties where p.GetSourceValue() != null select p) { // probably want the "object value" of the property here... - userVals[p.PropertyTypeAlias] = p.GetValue(); + userVals[p.Alias] = p.GetValue(); } //add the row data Core.DataTableExtensions.AddRowData(tableData, standardVals, userVals); diff --git a/src/Umbraco.Web/WebApi/Filters/ContentItemValidationHelper.cs b/src/Umbraco.Web/WebApi/Filters/ContentItemValidationHelper.cs index 13983fd1c1..9809c4ea76 100644 --- a/src/Umbraco.Web/WebApi/Filters/ContentItemValidationHelper.cs +++ b/src/Umbraco.Web/WebApi/Filters/ContentItemValidationHelper.cs @@ -119,7 +119,7 @@ namespace Umbraco.Web.WebApi.Filters var editor = p.PropertyEditor; if (editor == null) { - var message = string.Format("The property editor with alias: {0} was not found for property with id {1}", p.DataType.PropertyEditorAlias, p.Id); + var message = string.Format("The property editor with alias: {0} was not found for property with id {1}", p.DataType.EditorAlias, p.Id); Current.Logger.Warn>(message); //actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.NotFound, message); //return false; diff --git a/src/Umbraco.Web/umbraco.presentation/page.cs b/src/Umbraco.Web/umbraco.presentation/page.cs index 1311e28ab5..ad1ac877be 100644 --- a/src/Umbraco.Web/umbraco.presentation/page.cs +++ b/src/Umbraco.Web/umbraco.presentation/page.cs @@ -203,7 +203,7 @@ namespace umbraco { foreach(var p in node.Properties) { - if (_elements.ContainsKey(p.PropertyTypeAlias) == false) + if (_elements.ContainsKey(p.Alias) == false) { // note: legacy used the raw value (see populating from an Xml node below) // so we're doing the same here, using DataValue. If we use Value then every @@ -213,7 +213,7 @@ namespace umbraco // to properly fix this, we'd need to turn the elements collection into some // sort of collection of lazy values. - _elements[p.PropertyTypeAlias] = p.GetSourceValue(); + _elements[p.Alias] = p.GetSourceValue(); } } } @@ -427,12 +427,12 @@ namespace umbraco _creatorName = _inner.GetCreatorProfile().Name; _writerName = _inner.GetWriterProfile().Name; - _contentType = new PublishedContentType(_inner.ContentType); + _contentType = Current.PublishedContentTypeFactory.CreateContentType(_inner.ContentType); _properties = _contentType.PropertyTypes .Select(x => { - var p = _inner.Properties.SingleOrDefault(xx => xx.Alias == x.PropertyTypeAlias); + var p = _inner.Properties.SingleOrDefault(xx => xx.Alias == x.Alias); return p == null ? new PagePublishedProperty(x, this) : new PagePublishedProperty(x, this, p); }) .Cast() @@ -541,11 +541,6 @@ namespace umbraco get { throw new NotImplementedException(); } } - public int GetIndex() - { - throw new NotImplementedException(); - } - public IPublishedContent Parent { get { return _parent; }