From fb562817bcff3fac85ed961b734fba191f0b99f3 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 5 Dec 2019 14:03:09 +0100 Subject: [PATCH] Moved more files to abstractions and eliminated the use of JObject --- src/Umbraco.Abstractions/ContentExtensions.cs | 57 +++++++++++++++++++ .../Deploy/ArtifactBase.cs | 9 ++- .../Events/ContentPublishedEventArgs.cs | 0 .../Events/ContentPublishingEventArgs.cs | 0 .../Events/ContentSavedEventArgs.cs | 0 .../Events/ContentSavingEventArgs.cs | 0 .../Events/ExportedMemberEventArgs.cs | 2 +- .../Events/ImportPackageEventArgs.cs | 0 .../Events/QueuingEventDispatcherBase.cs | 0 .../Events/UninstallPackageEventArgs.cs | 0 .../Manifest/IPackageManifest.cs | 0 .../Manifest/ManifestContentAppFactory.cs | 0 .../Manifest/ManifestWatcher.cs | 2 +- .../PackageActions/AllowDoctype.cs | 16 ++++-- .../PackageActions/PublishRootDocument.cs | 15 +++-- .../Packaging/PackagesRepository.cs | 6 +- .../ManifestValueValidatorCollection.cs | 14 +++-- .../Validators/DelimitedValueValidator.cs | 29 ++++------ .../Validators/RegexValidator.cs | 2 +- .../Validators/RequiredValidator.cs | 5 -- src/Umbraco.Configuration/GlobalSettings.cs | 9 ++- .../Compose/AuditEventsComponent.cs | 2 +- .../Compose/RelateOnTrashComponent.cs | 36 ++++++------ .../CompositionExtensions/Services.cs | 1 + src/Umbraco.Core/ContentExtensions.cs | 46 --------------- .../Logging/Viewer/LogViewerComposer.cs | 3 +- .../Manifest/DataEditorConverter.cs | 8 ++- src/Umbraco.Core/Manifest/ManifestParser.cs | 6 +- .../Manifest/ValueValidatorConverter.cs | 2 +- .../PropertyEditors/DataEditor.cs | 21 +++---- .../PropertyEditors/DataValueEditor.cs | 8 ++- src/Umbraco.Core/Umbraco.Core.csproj | 38 ++++--------- .../Manifest/ManifestParserTests.cs | 41 ++++++++++++- .../CreatedPackagesRepositoryTests.cs | 2 + src/Umbraco.Tests/TestHelpers/TestObjects.cs | 4 +- .../MultipleTextStringPropertyEditor.cs | 29 ++++++++-- .../PropertyEditors/TagConfigurationEditor.cs | 7 ++- .../PropertyEditors/TagsPropertyEditor.cs | 6 +- src/Umbraco.Web/Umbraco.Web.csproj | 8 +-- 39 files changed, 259 insertions(+), 175 deletions(-) create mode 100644 src/Umbraco.Abstractions/ContentExtensions.cs rename src/{Umbraco.Core => Umbraco.Abstractions}/Deploy/ArtifactBase.cs (89%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/ContentPublishedEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/ContentPublishingEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/ContentSavedEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/ContentSavingEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/ExportedMemberEventArgs.cs (87%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/ImportPackageEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/QueuingEventDispatcherBase.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Events/UninstallPackageEventArgs.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Manifest/IPackageManifest.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Manifest/ManifestContentAppFactory.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Manifest/ManifestWatcher.cs (97%) rename src/{Umbraco.Core => Umbraco.Abstractions}/PackageActions/AllowDoctype.cs (87%) rename src/{Umbraco.Core => Umbraco.Abstractions}/PackageActions/PublishRootDocument.cs (84%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Packaging/PackagesRepository.cs (99%) rename src/{Umbraco.Core => Umbraco.Abstractions}/PropertyEditors/Validators/DelimitedValueValidator.cs (70%) rename src/{Umbraco.Core => Umbraco.Abstractions}/PropertyEditors/Validators/RegexValidator.cs (97%) rename src/{Umbraco.Core => Umbraco.Abstractions}/PropertyEditors/Validators/RequiredValidator.cs (94%) diff --git a/src/Umbraco.Abstractions/ContentExtensions.cs b/src/Umbraco.Abstractions/ContentExtensions.cs new file mode 100644 index 0000000000..b5d5915137 --- /dev/null +++ b/src/Umbraco.Abstractions/ContentExtensions.cs @@ -0,0 +1,57 @@ +using System.Xml.Linq; +using Umbraco.Core.Models; +using Umbraco.Core.Services; + +namespace Umbraco.Core +{ + public static class ContentExtensions + { + #region XML methods + + /// + /// Creates the full xml representation for the object and all of it's descendants + /// + /// to generate xml for + /// + /// Xml representation of the passed in + internal static XElement ToDeepXml(this IContent content, IEntityXmlSerializer serializer) + { + return serializer.Serialize(content, false, true); + } + + /// + /// Creates the xml representation for the object + /// + /// to generate xml for + /// + /// Xml representation of the passed in + public static XElement ToXml(this IContent content, IEntityXmlSerializer serializer) + { + return serializer.Serialize(content, false, false); + } + + + /// + /// Creates the xml representation for the object + /// + /// to generate xml for + /// + /// Xml representation of the passed in + public static XElement ToXml(this IMedia media, IEntityXmlSerializer serializer) + { + return serializer.Serialize(media); + } + + /// + /// Creates the xml representation for the object + /// + /// to generate xml for + /// + /// Xml representation of the passed in + public static XElement ToXml(this IMember member, IEntityXmlSerializer serializer) + { + return serializer.Serialize(member); + } + #endregion + } +} diff --git a/src/Umbraco.Core/Deploy/ArtifactBase.cs b/src/Umbraco.Abstractions/Deploy/ArtifactBase.cs similarity index 89% rename from src/Umbraco.Core/Deploy/ArtifactBase.cs rename to src/Umbraco.Abstractions/Deploy/ArtifactBase.cs index f645c50824..432726699e 100644 --- a/src/Umbraco.Core/Deploy/ArtifactBase.cs +++ b/src/Umbraco.Abstractions/Deploy/ArtifactBase.cs @@ -1,13 +1,14 @@ using System; using System.Collections.Generic; using System.Linq; -using Newtonsoft.Json; +using System.Runtime.Serialization; namespace Umbraco.Core.Deploy { /// /// Provides a base class to all artifacts. /// + [DataContract] public abstract class ArtifactBase : IArtifact where TUdi : Udi { @@ -34,14 +35,16 @@ namespace Umbraco.Core.Deploy get { return Udi; } } + [DataMember] public TUdi Udi { get; set; } - [JsonIgnore] + [IgnoreDataMember] public string Checksum { get { return _checksum.Value; } } + [DataMember] public IEnumerable Dependencies { get { return _dependencies; } @@ -50,7 +53,9 @@ namespace Umbraco.Core.Deploy #endregion + [DataMember] public string Name { get; set; } + [DataMember] public string Alias { get; set; } } } diff --git a/src/Umbraco.Core/Events/ContentPublishedEventArgs.cs b/src/Umbraco.Abstractions/Events/ContentPublishedEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/ContentPublishedEventArgs.cs rename to src/Umbraco.Abstractions/Events/ContentPublishedEventArgs.cs diff --git a/src/Umbraco.Core/Events/ContentPublishingEventArgs.cs b/src/Umbraco.Abstractions/Events/ContentPublishingEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/ContentPublishingEventArgs.cs rename to src/Umbraco.Abstractions/Events/ContentPublishingEventArgs.cs diff --git a/src/Umbraco.Core/Events/ContentSavedEventArgs.cs b/src/Umbraco.Abstractions/Events/ContentSavedEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/ContentSavedEventArgs.cs rename to src/Umbraco.Abstractions/Events/ContentSavedEventArgs.cs diff --git a/src/Umbraco.Core/Events/ContentSavingEventArgs.cs b/src/Umbraco.Abstractions/Events/ContentSavingEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/ContentSavingEventArgs.cs rename to src/Umbraco.Abstractions/Events/ContentSavingEventArgs.cs diff --git a/src/Umbraco.Core/Events/ExportedMemberEventArgs.cs b/src/Umbraco.Abstractions/Events/ExportedMemberEventArgs.cs similarity index 87% rename from src/Umbraco.Core/Events/ExportedMemberEventArgs.cs rename to src/Umbraco.Abstractions/Events/ExportedMemberEventArgs.cs index 9c91f3e5bd..45b4366677 100644 --- a/src/Umbraco.Core/Events/ExportedMemberEventArgs.cs +++ b/src/Umbraco.Abstractions/Events/ExportedMemberEventArgs.cs @@ -4,7 +4,7 @@ using Umbraco.Core.Models.Membership; namespace Umbraco.Core.Events { - internal class ExportedMemberEventArgs : EventArgs + public class ExportedMemberEventArgs : EventArgs { public IMember Member { get; } public MemberExportModel Exported { get; } diff --git a/src/Umbraco.Core/Events/ImportPackageEventArgs.cs b/src/Umbraco.Abstractions/Events/ImportPackageEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/ImportPackageEventArgs.cs rename to src/Umbraco.Abstractions/Events/ImportPackageEventArgs.cs diff --git a/src/Umbraco.Core/Events/QueuingEventDispatcherBase.cs b/src/Umbraco.Abstractions/Events/QueuingEventDispatcherBase.cs similarity index 100% rename from src/Umbraco.Core/Events/QueuingEventDispatcherBase.cs rename to src/Umbraco.Abstractions/Events/QueuingEventDispatcherBase.cs diff --git a/src/Umbraco.Core/Events/UninstallPackageEventArgs.cs b/src/Umbraco.Abstractions/Events/UninstallPackageEventArgs.cs similarity index 100% rename from src/Umbraco.Core/Events/UninstallPackageEventArgs.cs rename to src/Umbraco.Abstractions/Events/UninstallPackageEventArgs.cs diff --git a/src/Umbraco.Core/Manifest/IPackageManifest.cs b/src/Umbraco.Abstractions/Manifest/IPackageManifest.cs similarity index 100% rename from src/Umbraco.Core/Manifest/IPackageManifest.cs rename to src/Umbraco.Abstractions/Manifest/IPackageManifest.cs diff --git a/src/Umbraco.Core/Manifest/ManifestContentAppFactory.cs b/src/Umbraco.Abstractions/Manifest/ManifestContentAppFactory.cs similarity index 100% rename from src/Umbraco.Core/Manifest/ManifestContentAppFactory.cs rename to src/Umbraco.Abstractions/Manifest/ManifestContentAppFactory.cs diff --git a/src/Umbraco.Core/Manifest/ManifestWatcher.cs b/src/Umbraco.Abstractions/Manifest/ManifestWatcher.cs similarity index 97% rename from src/Umbraco.Core/Manifest/ManifestWatcher.cs rename to src/Umbraco.Abstractions/Manifest/ManifestWatcher.cs index ba9c468eda..8d81ac3de5 100644 --- a/src/Umbraco.Core/Manifest/ManifestWatcher.cs +++ b/src/Umbraco.Abstractions/Manifest/ManifestWatcher.cs @@ -7,7 +7,7 @@ using Umbraco.Core.Logging; namespace Umbraco.Core.Manifest { - internal class ManifestWatcher : DisposableObjectSlim + public class ManifestWatcher : DisposableObjectSlim { private static readonly object Locker = new object(); private static volatile bool _isRestarting; diff --git a/src/Umbraco.Core/PackageActions/AllowDoctype.cs b/src/Umbraco.Abstractions/PackageActions/AllowDoctype.cs similarity index 87% rename from src/Umbraco.Core/PackageActions/AllowDoctype.cs rename to src/Umbraco.Abstractions/PackageActions/AllowDoctype.cs index 2e37061c31..c68d116e25 100644 --- a/src/Umbraco.Core/PackageActions/AllowDoctype.cs +++ b/src/Umbraco.Abstractions/PackageActions/AllowDoctype.cs @@ -1,8 +1,8 @@ using System.Collections; using System.Linq; using System.Xml.Linq; -using Umbraco.Core.Composing; using Umbraco.Core.Models; +using Umbraco.Core.Services; namespace Umbraco.Core.PackageActions { @@ -12,6 +12,12 @@ namespace Umbraco.Core.PackageActions /// public class AllowDoctype : IPackageAction { + private readonly IContentTypeService _contentTypeService; + + public AllowDoctype(IContentTypeService contentTypeService) + { + _contentTypeService = contentTypeService; + } #region IPackageAction Members @@ -31,8 +37,8 @@ namespace Umbraco.Core.PackageActions //global::umbraco.cms.businesslogic.ContentType ct = global::umbraco.cms.businesslogic.ContentType.GetByAlias(doctypeName); //global::umbraco.cms.businesslogic.ContentType parentct = global::umbraco.cms.businesslogic.ContentType.GetByAlias(parentDoctypeName); - var ct = Current.Services.ContentTypeService.Get(doctypeName); - var parentct = Current.Services.ContentTypeService.Get(parentDoctypeName); + var ct = _contentTypeService.Get(doctypeName); + var parentct = _contentTypeService.Get(parentDoctypeName); if (ct != null && parentct != null) { @@ -57,7 +63,7 @@ namespace Umbraco.Core.PackageActions var so = 0; parentct.AllowedContentTypes = ids.Select(x => new ContentTypeSort(x, so++)); //parentct.Save(); - Current.Services.ContentTypeService.Save(parentct); + _contentTypeService.Save(parentct); return true; } } @@ -85,6 +91,6 @@ namespace Umbraco.Core.PackageActions } #endregion - + } } diff --git a/src/Umbraco.Core/PackageActions/PublishRootDocument.cs b/src/Umbraco.Abstractions/PackageActions/PublishRootDocument.cs similarity index 84% rename from src/Umbraco.Core/PackageActions/PublishRootDocument.cs rename to src/Umbraco.Abstractions/PackageActions/PublishRootDocument.cs index 55955a4c8f..ff871142d6 100644 --- a/src/Umbraco.Core/PackageActions/PublishRootDocument.cs +++ b/src/Umbraco.Abstractions/PackageActions/PublishRootDocument.cs @@ -1,5 +1,5 @@ using System.Xml.Linq; -using Umbraco.Core.Composing; +using Umbraco.Core.Services; namespace Umbraco.Core.PackageActions { @@ -9,6 +9,13 @@ namespace Umbraco.Core.PackageActions /// public class PublishRootDocument : IPackageAction { + private readonly IContentService _contentService; + + public PublishRootDocument(IContentService contentService) + { + _contentService = contentService; + } + #region IPackageAction Members /// @@ -25,14 +32,14 @@ namespace Umbraco.Core.PackageActions string documentName = xmlData.AttributeValue("documentName"); - var rootDocs = Current.Services.ContentService.GetRootContent(); + var rootDocs = _contentService.GetRootContent(); foreach (var rootDoc in rootDocs) { if (rootDoc.Name.Trim() == documentName.Trim() && rootDoc.ContentType != null) { // TODO: variants? - Current.Services.ContentService.SaveAndPublishBranch(rootDoc, true); + _contentService.SaveAndPublishBranch(rootDoc, true); break; } } @@ -59,6 +66,6 @@ namespace Umbraco.Core.PackageActions return "publishRootDocument"; } #endregion - + } } diff --git a/src/Umbraco.Core/Packaging/PackagesRepository.cs b/src/Umbraco.Abstractions/Packaging/PackagesRepository.cs similarity index 99% rename from src/Umbraco.Core/Packaging/PackagesRepository.cs rename to src/Umbraco.Abstractions/Packaging/PackagesRepository.cs index 6682f289bf..a2a30f3a06 100644 --- a/src/Umbraco.Core/Packaging/PackagesRepository.cs +++ b/src/Umbraco.Abstractions/Packaging/PackagesRepository.cs @@ -5,7 +5,6 @@ using System.IO; using System.IO.Compression; using System.Linq; using System.Xml.Linq; -using Umbraco.Core.Composing; using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -19,7 +18,7 @@ namespace Umbraco.Core.Packaging /// /// Manages the storage of installed/created package definitions /// - internal class PackagesRepository : ICreatedPackagesRepository, IInstalledPackagesRepository + public class PackagesRepository : ICreatedPackagesRepository, IInstalledPackagesRepository { private readonly IContentService _contentService; private readonly IContentTypeService _contentTypeService; @@ -61,6 +60,7 @@ namespace Umbraco.Core.Packaging IIOHelper ioHelper, IEntityXmlSerializer serializer, ILogger logger, IUmbracoVersion umbracoVersion, + IGlobalSettings globalSettings, string packageRepositoryFileName, string tempFolderPath = null, string packagesFolderPath = null, string mediaFolderPath = null) { @@ -78,7 +78,7 @@ namespace Umbraco.Core.Packaging _tempFolderPath = tempFolderPath ?? Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "PackageFiles"; _packagesFolderPath = packagesFolderPath ?? Constants.SystemDirectories.Packages; - _mediaFolderPath = mediaFolderPath ?? Current.Configs.Global().UmbracoMediaPath + "/created-packages"; + _mediaFolderPath = mediaFolderPath ?? globalSettings.UmbracoMediaPath + "/created-packages"; _parser = new PackageDefinitionXmlParser(logger, umbracoVersion); _umbracoVersion = umbracoVersion; diff --git a/src/Umbraco.Abstractions/PropertyEditors/ManifestValueValidatorCollection.cs b/src/Umbraco.Abstractions/PropertyEditors/ManifestValueValidatorCollection.cs index 62f2e0ca1d..0f3719dd8c 100644 --- a/src/Umbraco.Abstractions/PropertyEditors/ManifestValueValidatorCollection.cs +++ b/src/Umbraco.Abstractions/PropertyEditors/ManifestValueValidatorCollection.cs @@ -12,14 +12,20 @@ namespace Umbraco.Core.PropertyEditors { } public IManifestValueValidator Create(string name) + { + var v = GetByName(name); + + // TODO: what is this exactly? + // we cannot return this instance, need to clone it? + return (IManifestValueValidator) Activator.CreateInstance(v.GetType()); // ouch + } + + public IManifestValueValidator GetByName(string name) { var v = this.FirstOrDefault(x => x.ValidationName.InvariantEquals(name)); if (v == null) throw new InvalidOperationException($"Could not find a validator named \"{name}\"."); - - // TODO: what is this exactly? - // we cannot return this instance, need to clone it? - return (IManifestValueValidator) Activator.CreateInstance(v.GetType()); // ouch + return v; } } } diff --git a/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs b/src/Umbraco.Abstractions/PropertyEditors/Validators/DelimitedValueValidator.cs similarity index 70% rename from src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs rename to src/Umbraco.Abstractions/PropertyEditors/Validators/DelimitedValueValidator.cs index c3dca609d2..38912091c0 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/DelimitedValueValidator.cs +++ b/src/Umbraco.Abstractions/PropertyEditors/Validators/DelimitedValueValidator.cs @@ -2,15 +2,13 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Text.RegularExpressions; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; namespace Umbraco.Core.PropertyEditors.Validators { /// /// A validator that validates a delimited set of values against a common regex /// - internal sealed class DelimitedValueValidator : IManifestValueValidator + public sealed class DelimitedValueValidator : IManifestValueValidator { /// public string ValidationName => "Delimited"; @@ -18,7 +16,8 @@ namespace Umbraco.Core.PropertyEditors.Validators /// /// Gets or sets the configuration, when parsed as . /// - public JObject Configuration { get; set; } + public DelimitedValueValidatorConfig Configuration { get; set; } + /// public IEnumerable Validate(object value, string valueType, object dataTypeConfiguration) @@ -26,20 +25,8 @@ namespace Umbraco.Core.PropertyEditors.Validators // TODO: localize these! if (value != null) { - var delimiter = ","; - Regex regex = null; - if (Configuration is JObject jobject) - { - if (jobject["delimiter"] != null) - { - delimiter = jobject["delimiter"].ToString(); - } - if (jobject["pattern"] != null) - { - var regexPattern = jobject["pattern"].ToString(); - regex = new Regex(regexPattern); - } - } + var delimiter = Configuration?.Delimiter ?? ","; + var regex = (Configuration?.Pattern != null) ? new Regex(Configuration.Pattern) : null; var stringVal = value.ToString(); var split = stringVal.Split(new[] { delimiter }, StringSplitOptions.RemoveEmptyEntries); @@ -63,4 +50,10 @@ namespace Umbraco.Core.PropertyEditors.Validators } } } + + public class DelimitedValueValidatorConfig + { + public string Delimiter { get; set; } + public string Pattern { get; set; } + } } diff --git a/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs b/src/Umbraco.Abstractions/PropertyEditors/Validators/RegexValidator.cs similarity index 97% rename from src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs rename to src/Umbraco.Abstractions/PropertyEditors/Validators/RegexValidator.cs index 651596635b..f1e3bc73c2 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/RegexValidator.cs +++ b/src/Umbraco.Abstractions/PropertyEditors/Validators/RegexValidator.cs @@ -27,7 +27,7 @@ namespace Umbraco.Core.PropertyEditors.Validators /// and the regular expression is supplied at validation time. This constructor is also used when /// the validator is used as an and the regular expression /// is supplied via the method. - public RegexValidator() : this(Current.HasFactory ? Current.Services.TextService : null, null) + public RegexValidator(ILocalizedTextService textService) : this(textService, null) { } /// diff --git a/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs b/src/Umbraco.Abstractions/PropertyEditors/Validators/RequiredValidator.cs similarity index 94% rename from src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs rename to src/Umbraco.Abstractions/PropertyEditors/Validators/RequiredValidator.cs index e47ca56333..8880ff5acf 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/RequiredValidator.cs +++ b/src/Umbraco.Abstractions/PropertyEditors/Validators/RequiredValidator.cs @@ -13,11 +13,6 @@ namespace Umbraco.Core.PropertyEditors.Validators private readonly ILocalizedTextService _textService; const string ValueCannotBeNull = "Value cannot be null"; const string ValueCannotBeEmpty = "Value cannot be empty"; - - public RequiredValidator() : this(Current.HasFactory ? Current.Services.TextService : null) - { - } - public RequiredValidator(ILocalizedTextService textService) { _textService = textService; diff --git a/src/Umbraco.Configuration/GlobalSettings.cs b/src/Umbraco.Configuration/GlobalSettings.cs index fea5de726f..93c3419bb0 100644 --- a/src/Umbraco.Configuration/GlobalSettings.cs +++ b/src/Umbraco.Configuration/GlobalSettings.cs @@ -301,12 +301,17 @@ namespace Umbraco.Core.Configuration { try { - return int.Parse(ConfigurationManager.AppSettings[Constants.AppSettings.VersionCheckPeriod]); + var val = ConfigurationManager.AppSettings[Constants.AppSettings.VersionCheckPeriod]; + if (!(val is null)) + { + return int.Parse(val); + } } catch { - return 7; + // Ignore } + return 7; } } diff --git a/src/Umbraco.Core/Compose/AuditEventsComponent.cs b/src/Umbraco.Core/Compose/AuditEventsComponent.cs index 6ebe5a2acd..8913addb24 100644 --- a/src/Umbraco.Core/Compose/AuditEventsComponent.cs +++ b/src/Umbraco.Core/Compose/AuditEventsComponent.cs @@ -46,7 +46,7 @@ namespace Umbraco.Core.Compose public void Terminate() { } - internal static IUser UnknownUser => new User { Id = Constants.Security.UnknownUserId, Name = Constants.Security.UnknownUserName, Email = "" }; + public static IUser UnknownUser => new User { Id = Constants.Security.UnknownUserId, Name = Constants.Security.UnknownUserName, Email = "" }; private IUser CurrentPerformingUser { diff --git a/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs b/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs index 8371f9b279..2cca37298b 100644 --- a/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs +++ b/src/Umbraco.Core/Compose/RelateOnTrashComponent.cs @@ -9,22 +9,33 @@ namespace Umbraco.Core.Compose { public sealed class RelateOnTrashComponent : IComponent { + private readonly IRelationService _relationService; + private readonly IEntityService _entityService; + private readonly ILocalizedTextService _textService; + + public RelateOnTrashComponent(IRelationService relationService, IEntityService entityService, ILocalizedTextService textService) + { + _relationService = relationService; + _entityService = entityService; + _textService = textService; + } + public void Initialize() { - ContentService.Moved += ContentService_Moved; - ContentService.Trashed += ContentService_Trashed; - MediaService.Moved += MediaService_Moved; - MediaService.Trashed += MediaService_Trashed; + ContentService.Moved += (sender, args) => ContentService_Moved(sender, args, _relationService); + ContentService.Trashed += (sender, args) => ContentService_Trashed(sender, args, _relationService, _entityService, _textService); + MediaService.Moved += (sender, args) => MediaService_Moved(sender, args, _relationService); + MediaService.Trashed += (sender, args) => MediaService_Trashed(sender, args, _relationService, _entityService, _textService); } public void Terminate() { } - private static void ContentService_Moved(IContentService sender, MoveEventArgs e) + private static void ContentService_Moved(IContentService sender, MoveEventArgs e, IRelationService relationService) { foreach (var item in e.MoveInfoCollection.Where(x => x.OriginalPath.Contains(Constants.System.RecycleBinContentString))) { - var relationService = Current.Services.RelationService; + const string relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias; var relations = relationService.GetByChildId(item.Entity.Id); @@ -35,11 +46,10 @@ namespace Umbraco.Core.Compose } } - private static void MediaService_Moved(IMediaService sender, MoveEventArgs e) + private static void MediaService_Moved(IMediaService sender, MoveEventArgs e, IRelationService relationService) { foreach (var item in e.MoveInfoCollection.Where(x => x.OriginalPath.Contains(Constants.System.RecycleBinMediaString))) { - var relationService = Current.Services.RelationService; const string relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias; var relations = relationService.GetByChildId(item.Entity.Id); foreach (var relation in relations.Where(x => x.RelationType.Alias.InvariantEquals(relationTypeAlias))) @@ -49,11 +59,8 @@ namespace Umbraco.Core.Compose } } - private static void ContentService_Trashed(IContentService sender, MoveEventArgs e) + private static void ContentService_Trashed(IContentService sender, MoveEventArgs e, IRelationService relationService, IEntityService entityService, ILocalizedTextService textService) { - var relationService = Current.Services.RelationService; - var entityService = Current.Services.EntityService; - var textService = Current.Services.TextService; const string relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentDocumentOnDeleteAlias; var relationType = relationService.GetRelationTypeByAlias(relationTypeAlias); @@ -94,11 +101,8 @@ namespace Umbraco.Core.Compose } } - private static void MediaService_Trashed(IMediaService sender, MoveEventArgs e) + private static void MediaService_Trashed(IMediaService sender, MoveEventArgs e, IRelationService relationService, IEntityService entityService, ILocalizedTextService textService) { - var relationService = Current.Services.RelationService; - var entityService = Current.Services.EntityService; - var textService = Current.Services.TextService; const string relationTypeAlias = Constants.Conventions.RelationTypes.RelateParentMediaFolderOnDeleteAlias; var relationType = relationService.GetRelationTypeByAlias(relationTypeAlias); // check that the relation-type exists, if not, then recreate it diff --git a/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs b/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs index b0cd80d93f..a615630c85 100644 --- a/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs +++ b/src/Umbraco.Core/Composing/CompositionExtensions/Services.cs @@ -97,6 +97,7 @@ namespace Umbraco.Core.Composing.CompositionExtensions factory.GetInstance(), factory.GetInstance(), factory.GetInstance(), + factory.GetInstance(), packageRepoFileName); private static LocalizedTextServiceFileSources SourcesFactory(IFactory container) diff --git a/src/Umbraco.Core/ContentExtensions.cs b/src/Umbraco.Core/ContentExtensions.cs index db553c3b4a..4fd309f134 100644 --- a/src/Umbraco.Core/ContentExtensions.cs +++ b/src/Umbraco.Core/ContentExtensions.cs @@ -262,53 +262,7 @@ namespace Umbraco.Core #endregion - #region XML methods - /// - /// Creates the full xml representation for the object and all of it's descendants - /// - /// to generate xml for - /// - /// Xml representation of the passed in - internal static XElement ToDeepXml(this IContent content, IEntityXmlSerializer serializer) - { - return serializer.Serialize(content, false, true); - } - - /// - /// Creates the xml representation for the object - /// - /// to generate xml for - /// - /// Xml representation of the passed in - public static XElement ToXml(this IContent content, IEntityXmlSerializer serializer) - { - return serializer.Serialize(content, false, false); - } - - - /// - /// Creates the xml representation for the object - /// - /// to generate xml for - /// - /// Xml representation of the passed in - public static XElement ToXml(this IMedia media, IEntityXmlSerializer serializer) - { - return serializer.Serialize(media); - } - - /// - /// Creates the xml representation for the object - /// - /// to generate xml for - /// - /// Xml representation of the passed in - public static XElement ToXml(this IMember member, IEntityXmlSerializer serializer) - { - return serializer.Serialize(member); - } - #endregion #region Dirty diff --git a/src/Umbraco.Core/Logging/Viewer/LogViewerComposer.cs b/src/Umbraco.Core/Logging/Viewer/LogViewerComposer.cs index f92ca0140a..79680a3d53 100644 --- a/src/Umbraco.Core/Logging/Viewer/LogViewerComposer.cs +++ b/src/Umbraco.Core/Logging/Viewer/LogViewerComposer.cs @@ -1,5 +1,4 @@ -using Umbraco.Core.Compose; -using Umbraco.Core.Composing; +using Umbraco.Core.Composing; using Umbraco.Core.IO; namespace Umbraco.Core.Logging.Viewer diff --git a/src/Umbraco.Core/Manifest/DataEditorConverter.cs b/src/Umbraco.Core/Manifest/DataEditorConverter.cs index 437d1eb159..5c0948fa5f 100644 --- a/src/Umbraco.Core/Manifest/DataEditorConverter.cs +++ b/src/Umbraco.Core/Manifest/DataEditorConverter.cs @@ -19,16 +19,18 @@ namespace Umbraco.Core.Manifest private readonly IIOHelper _ioHelper; private readonly IDataTypeService _dataTypeService; private readonly ILocalizationService _localizationService; + private readonly ILocalizedTextService _textService; /// /// Initializes a new instance of the class. /// - public DataEditorConverter(ILogger logger, IIOHelper ioHelper, IDataTypeService dataTypeService, ILocalizationService localizationService) + public DataEditorConverter(ILogger logger, IIOHelper ioHelper, IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService textService) { _logger = logger; _ioHelper = ioHelper; _dataTypeService = dataTypeService; _localizationService = localizationService; + _textService = textService; } /// @@ -83,7 +85,7 @@ namespace Umbraco.Core.Manifest // explicitly assign a value editor of type ValueEditor // (else the deserializer will try to read it before setting it) // (and besides it's an interface) - target.ExplicitValueEditor = new DataValueEditor(_dataTypeService, _localizationService); + target.ExplicitValueEditor = new DataValueEditor(_dataTypeService, _localizationService, _textService); // in the manifest, validators are a simple dictionary eg // { @@ -155,7 +157,7 @@ namespace Umbraco.Core.Manifest if (jobject.Property("view") != null) { // explicitly assign a value editor of type ParameterValueEditor - target.ExplicitValueEditor = new DataValueEditor(_dataTypeService, _localizationService); + target.ExplicitValueEditor = new DataValueEditor(_dataTypeService, _localizationService, _textService); // move the 'view' property jobject["editor"] = new JObject { ["view"] = jobject["view"] }; diff --git a/src/Umbraco.Core/Manifest/ManifestParser.cs b/src/Umbraco.Core/Manifest/ManifestParser.cs index ff8237038b..fe76af7428 100644 --- a/src/Umbraco.Core/Manifest/ManifestParser.cs +++ b/src/Umbraco.Core/Manifest/ManifestParser.cs @@ -19,6 +19,7 @@ namespace Umbraco.Core.Manifest public class ManifestParser : IManifestParser { private readonly IJsonSerializer _jsonSerializer; + private readonly ILocalizedTextService _localizedTextService; private static readonly string Utf8Preamble = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble()); private readonly IAppPolicyCache _cache; @@ -34,10 +35,11 @@ namespace Umbraco.Core.Manifest /// /// Initializes a new instance of the class. /// - public ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, ILogger logger, IIOHelper ioHelper, IDataTypeService dataTypeService, ILocalizationService localizationService, IJsonSerializer jsonSerializer) + public ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, ILogger logger, IIOHelper ioHelper, IDataTypeService dataTypeService, ILocalizationService localizationService, IJsonSerializer jsonSerializer, ILocalizedTextService localizedTextService) : this(appCaches, validators, filters, "~/App_Plugins", logger, ioHelper, dataTypeService, localizationService) { _jsonSerializer = jsonSerializer; + _localizedTextService = localizedTextService; } /// @@ -174,7 +176,7 @@ namespace Umbraco.Core.Manifest if (string.IsNullOrWhiteSpace(text)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(text)); var manifest = JsonConvert.DeserializeObject(text, - new DataEditorConverter(_logger, _ioHelper, _dataTypeService, _localizationService), + new DataEditorConverter(_logger, _ioHelper, _dataTypeService, _localizationService, _localizedTextService), new ValueValidatorConverter(_validators), new DashboardAccessRuleConverter()); diff --git a/src/Umbraco.Core/Manifest/ValueValidatorConverter.cs b/src/Umbraco.Core/Manifest/ValueValidatorConverter.cs index 75b0b2573b..743ad23192 100644 --- a/src/Umbraco.Core/Manifest/ValueValidatorConverter.cs +++ b/src/Umbraco.Core/Manifest/ValueValidatorConverter.cs @@ -26,7 +26,7 @@ namespace Umbraco.Core.Manifest if (string.IsNullOrWhiteSpace(type)) throw new InvalidOperationException("Could not get the type of the validator."); - return _validators.Create(type); + return _validators.GetByName(type); // jObject["configuration"] is going to be deserialized in a Configuration property, if any } diff --git a/src/Umbraco.Core/PropertyEditors/DataEditor.cs b/src/Umbraco.Core/PropertyEditors/DataEditor.cs index 047c0f0683..fdb9be3f4b 100644 --- a/src/Umbraco.Core/PropertyEditors/DataEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataEditor.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using Newtonsoft.Json; +using System.Runtime.Serialization; using Umbraco.Core.Composing; using Umbraco.Core.Logging; @@ -16,6 +16,7 @@ namespace Umbraco.Core.PropertyEditors /// [DebuggerDisplay("{" + nameof(DebuggerDisplay) + "(),nq}")] [HideFromTypeFinder] + [DataContract] public class DataEditor : IDataEditor { private IDictionary _defaultConfiguration; @@ -55,27 +56,27 @@ namespace Umbraco.Core.PropertyEditors protected ILogger Logger { get; } /// - [JsonProperty("alias", Required = Required.Always)] + [DataMember(Name = "alias", IsRequired = true)] public string Alias { get; internal set; } /// - [JsonIgnore] + [IgnoreDataMember] public EditorType Type { get; } /// - [JsonProperty("name", Required = Required.Always)] + [DataMember(Name = "name", IsRequired = true)] public string Name { get; internal set; } /// - [JsonProperty("icon")] + [DataMember(Name = "icon")] public string Icon { get; internal set; } /// - [JsonProperty("group")] + [DataMember(Name = "group")] public string Group { get; internal set; } /// - [JsonIgnore] + [IgnoreDataMember] public bool IsDeprecated { get; } /// @@ -121,7 +122,7 @@ namespace Umbraco.Core.PropertyEditors /// Gets or sets an explicit value editor. /// /// Used for manifest data editors. - [JsonProperty("editor")] + [DataMember(Name = "editor")] public IDataValueEditor ExplicitValueEditor { get; set; } /// @@ -139,11 +140,11 @@ namespace Umbraco.Core.PropertyEditors /// Gets or sets an explicit configuration editor. /// /// Used for manifest data editors. - [JsonProperty("config")] + [DataMember(Name = "config")] public IConfigurationEditor ExplicitConfigurationEditor { get; set; } /// - [JsonProperty("defaultConfig")] + [DataMember(Name = "defaultConfig")] public IDictionary DefaultConfiguration { // for property value editors, get the ConfigurationEditor.DefaultConfiguration diff --git a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs index afd77a3479..6d1e46e090 100644 --- a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs @@ -20,14 +20,16 @@ namespace Umbraco.Core.PropertyEditors /// public class DataValueEditor : IDataValueEditor { + private readonly ILocalizedTextService _localizedTextService; protected IDataTypeService DataTypeService { get; } protected ILocalizationService LocalizationService { get; } /// /// Initializes a new instance of the class. /// - public DataValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService) // for tests, and manifest + public DataValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService localizedTextService) // for tests, and manifest { + _localizedTextService = localizedTextService; ValueType = ValueTypes.String; Validators = new List(); DataTypeService = dataTypeService; @@ -110,12 +112,12 @@ namespace Umbraco.Core.PropertyEditors /// /// Gets the validator used to validate the special property type -level "required". /// - public virtual IValueRequiredValidator RequiredValidator => new RequiredValidator(); //TODO: Pass in the ILocalizedTextService here and not rely on Current! + public virtual IValueRequiredValidator RequiredValidator => new RequiredValidator(_localizedTextService); /// /// Gets the validator used to validate the special property type -level "format". /// - public virtual IValueFormatValidator FormatValidator => new RegexValidator(); //TODO: Pass in the ILocalizedTextService here and not rely on Current! + public virtual IValueFormatValidator FormatValidator => new RegexValidator(_localizedTextService); /// /// If this is true than the editor will be displayed full width without a label diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 273468654f..5f6a877415 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -127,16 +127,19 @@ --> - + + + + + + + - - - @@ -148,19 +151,12 @@ - - - - - - - + - @@ -210,9 +206,6 @@ - - - @@ -261,7 +254,6 @@ - @@ -300,9 +292,6 @@ - - - @@ -335,11 +324,8 @@ - - - @@ -347,7 +333,6 @@ - @@ -786,9 +771,6 @@ - - - @@ -811,6 +793,10 @@ {29aa69d9-b597-4395-8d42-43b1263c240a} Umbraco.Abstractions + + {3ae7bf57-966b-45a5-910a-954d7c554441} + Umbraco.Infrastructure + \ No newline at end of file diff --git a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs index fb980fc986..24938e462e 100644 --- a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs +++ b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs @@ -30,9 +30,46 @@ namespace Umbraco.Tests.Manifest var validators = new IManifestValueValidator[] { new RequiredValidator(Mock.Of()), - new RegexValidator(Mock.Of(), null) + new RegexValidator(Mock.Of(), null), + new DelimitedValueValidator(), }; - _parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty()), Mock.Of(), TestHelper.IOHelper, Mock.Of(), Mock.Of(), new JsonNetSerializer()); + _parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty()), Mock.Of(), TestHelper.IOHelper, Mock.Of(), Mock.Of(), new JsonNetSerializer(), Mock.Of()); + } + + [Test] + public void DelimitedValueValidator() + { + + const string json = @"{'propertyEditors': [ + { + alias: 'Test.Test2', + name: 'Test 2', + isParameterEditor: true, + defaultConfig: { key1: 'some default val' }, + editor: { + view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html', + valueType: 'int', + validation: { + delimited: { + delimiter: ',', + pattern: '^[a-zA-Z]*$' + } + } + } + } +]}"; + + var manifest = _parser.ParseManifest(json); + + Assert.AreEqual(1, manifest.ParameterEditors.Length); + Assert.AreEqual(1, manifest.ParameterEditors[0].GetValueEditor().Validators.Count); + + Assert.IsTrue(manifest.ParameterEditors[0].GetValueEditor().Validators[0] is DelimitedValueValidator); + var validator = manifest.ParameterEditors[0].GetValueEditor().Validators[0] as DelimitedValueValidator; + + Assert.IsNotNull(validator.Configuration); + Assert.AreEqual(",", validator.Configuration.Delimiter); + Assert.AreEqual("^[a-zA-Z]*$", validator.Configuration.Pattern); } [Test] diff --git a/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs b/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs index b101f9f7fe..d7a99aedfd 100644 --- a/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs +++ b/src/Umbraco.Tests/Packaging/CreatedPackagesRepositoryTests.cs @@ -7,6 +7,7 @@ using System.Xml.Linq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Composing; +using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Models.Packaging; using Umbraco.Core.Packaging; @@ -43,6 +44,7 @@ namespace Umbraco.Tests.Packaging IOHelper, Factory.GetInstance(), Logger, UmbracoVersion, + Factory.GetInstance(), "createdPackages.config", //temp paths tempFolderPath: "~/" + _testBaseFolder + "/temp", diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 50288f9ac3..e9942506f2 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -179,9 +179,9 @@ namespace Umbraco.Tests.TestHelpers return new PackagingService( auditService.Value, new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value, ioHelper, - new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders), logger, umbracoVersion, "createdPackages.config"), + new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders), logger, umbracoVersion, globalSettings, "createdPackages.config"), new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value, ioHelper, - new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders), logger, umbracoVersion, "installedPackages.config"), + new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders), logger, umbracoVersion, globalSettings, "installedPackages.config"), new PackageInstallation( new PackageDataInstallation(logger, fileService.Value, macroService.Value, localizationService.Value, dataTypeService.Value, entityService.Value, contentTypeService.Value, contentService.Value, propertyEditorCollection, scopeProvider), new PackageFileInstallation(compiledPackageXmlParser, ioHelper, new ProfilingLogger(logger, new TestProfiler())), diff --git a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs index 4bcb868253..96a17c8001 100644 --- a/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/MultipleTextStringPropertyEditor.cs @@ -29,18 +29,24 @@ namespace Umbraco.Web.PropertyEditors public class MultipleTextStringPropertyEditor : DataEditor { private readonly IIOHelper _ioHelper; + private readonly IDataTypeService _dataTypeService; + private readonly ILocalizationService _localizationService; + private readonly ILocalizedTextService _localizedTextService; /// /// Initializes a new instance of the class. /// - public MultipleTextStringPropertyEditor(ILogger logger, IIOHelper ioHelper) + public MultipleTextStringPropertyEditor(ILogger logger, IIOHelper ioHelper, IDataTypeService dataTypeService, ILocalizationService localizationService, ILocalizedTextService localizedTextService) : base(logger) { _ioHelper = ioHelper; + _dataTypeService = dataTypeService; + _localizationService = localizationService; + _localizedTextService = localizedTextService; } /// - protected override IDataValueEditor CreateValueEditor() => new MultipleTextStringPropertyValueEditor(Current.Services.DataTypeService, Current.Services.LocalizationService,Attribute); + protected override IDataValueEditor CreateValueEditor() => new MultipleTextStringPropertyValueEditor(_dataTypeService, _localizationService,Attribute, _localizedTextService); /// protected override IConfigurationEditor CreateConfigurationEditor() => new MultipleTextStringConfigurationEditor(_ioHelper); @@ -50,9 +56,13 @@ namespace Umbraco.Web.PropertyEditors /// internal class MultipleTextStringPropertyValueEditor : DataValueEditor { - public MultipleTextStringPropertyValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, DataEditorAttribute attribute) + private readonly ILocalizedTextService _localizedTextService; + + public MultipleTextStringPropertyValueEditor(IDataTypeService dataTypeService, ILocalizationService localizationService, DataEditorAttribute attribute, ILocalizedTextService localizedTextService) : base(dataTypeService, localizationService, attribute) - { } + { + _localizedTextService = localizedTextService; + } /// /// The value passed in from the editor will be an array of simple objects so we'll need to parse them to get the string @@ -112,11 +122,18 @@ namespace Umbraco.Web.PropertyEditors /// A custom FormatValidator is used as for multiple text strings, each string should individually be checked /// against the configured regular expression, rather than the JSON representing all the strings as a whole. /// - public override IValueFormatValidator FormatValidator => new MultipleTextStringFormatValidator(); + public override IValueFormatValidator FormatValidator => new MultipleTextStringFormatValidator(_localizedTextService); } internal class MultipleTextStringFormatValidator : IValueFormatValidator { + private readonly ILocalizedTextService _localizedTextService; + + public MultipleTextStringFormatValidator(ILocalizedTextService localizedTextService) + { + _localizedTextService = localizedTextService; + } + public IEnumerable ValidateFormat(object value, string valueType, string format) { var asArray = value as JArray; @@ -128,7 +145,7 @@ namespace Umbraco.Web.PropertyEditors var textStrings = asArray.OfType() .Where(x => x["value"] != null) .Select(x => x["value"].Value()); - var textStringValidator = new RegexValidator(); + var textStringValidator = new RegexValidator(_localizedTextService); foreach (var textString in textStrings) { var validationResults = textStringValidator.ValidateFormat(textString, valueType, format).ToList(); diff --git a/src/Umbraco.Web/PropertyEditors/TagConfigurationEditor.cs b/src/Umbraco.Web/PropertyEditors/TagConfigurationEditor.cs index ae7cdb1e40..aed32f10a1 100644 --- a/src/Umbraco.Web/PropertyEditors/TagConfigurationEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TagConfigurationEditor.cs @@ -6,6 +6,7 @@ using Umbraco.Core.IO; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.PropertyEditors.Validators; +using Umbraco.Core.Services; namespace Umbraco.Web.PropertyEditors { @@ -14,10 +15,10 @@ namespace Umbraco.Web.PropertyEditors /// public class TagConfigurationEditor : ConfigurationEditor { - public TagConfigurationEditor(ManifestValueValidatorCollection validators, IIOHelper ioHelper) : base(ioHelper) + public TagConfigurationEditor(ManifestValueValidatorCollection validators, IIOHelper ioHelper, ILocalizedTextService localizedTextService) : base(ioHelper) { - Field(nameof(TagConfiguration.Group)).Validators.Add(new RequiredValidator()); - Field(nameof(TagConfiguration.StorageType)).Validators.Add(new RequiredValidator()); + Field(nameof(TagConfiguration.Group)).Validators.Add(new RequiredValidator(localizedTextService)); + Field(nameof(TagConfiguration.StorageType)).Validators.Add(new RequiredValidator(localizedTextService)); } public override Dictionary ToConfigurationEditor(TagConfiguration configuration) diff --git a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs index 932497d297..2c40f7f50a 100644 --- a/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/TagsPropertyEditor.cs @@ -27,17 +27,19 @@ namespace Umbraco.Web.PropertyEditors { private readonly ManifestValueValidatorCollection _validators; private readonly IIOHelper _ioHelper; + private readonly ILocalizedTextService _localizedTextService; - public TagsPropertyEditor(ManifestValueValidatorCollection validators, ILogger logger, IIOHelper ioHelper) + public TagsPropertyEditor(ManifestValueValidatorCollection validators, ILogger logger, IIOHelper ioHelper, ILocalizedTextService localizedTextService) : base(logger) { _validators = validators; _ioHelper = ioHelper; + _localizedTextService = localizedTextService; } protected override IDataValueEditor CreateValueEditor() => new TagPropertyValueEditor(Current.Services.DataTypeService, Current.Services.LocalizationService, Attribute); - protected override IConfigurationEditor CreateConfigurationEditor() => new TagConfigurationEditor(_validators, _ioHelper); + protected override IConfigurationEditor CreateConfigurationEditor() => new TagConfigurationEditor(_validators, _ioHelper, _localizedTextService); internal class TagPropertyValueEditor : DataValueEditor { diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 37e76c8c2d..a669ed82f8 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -144,6 +144,10 @@ + + + + @@ -306,10 +310,6 @@ - - - -