From 2b2db8b8efa04d604abd41bb57a4354477ecba04 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 12 Nov 2019 16:31:08 +1100 Subject: [PATCH] Moves most service interfaces, ensure IOHelper is registered --- .../Querying/StringPropertyMatchType.cs | 0 .../Services/Changes/TreeChange.cs | 2 +- .../Services/Changes/TreeChangeExtensions.cs | 2 +- .../Services/IAuditService.cs | 2 - .../Services/IContentServiceBase.cs | 0 .../Services/IExternalLoginService.cs | 1 - .../Services/IFileService.cs | 0 .../Services/ILocalizationService.cs | 4 +- .../Services/IMacroService.cs | 0 .../Services/IMembershipMemberService.cs | 153 ++++++++++++++++++ .../Services/IMembershipRoleService.cs | 0 .../CompositionExtensions_Essentials.cs | 5 +- src/Umbraco.Core/Runtime/CoreRuntime.cs | 18 ++- .../Changes/ContentTypeChangeExtensions.cs | 2 +- .../Services/IMembershipMemberService.cs | 145 +---------------- .../Services/INotificationService.cs | 2 +- .../Services/Implement/MediaService.cs | 2 +- src/Umbraco.Core/Umbraco.Core.csproj | 14 +- 18 files changed, 184 insertions(+), 168 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Persistence/Querying/StringPropertyMatchType.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/Changes/TreeChange.cs (95%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/Changes/TreeChangeExtensions.cs (88%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/IAuditService.cs (98%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/IContentServiceBase.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/IExternalLoginService.cs (97%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/IFileService.cs (100%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/ILocalizationService.cs (98%) rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/IMacroService.cs (100%) create mode 100644 src/Umbraco.Abstractions/Services/IMembershipMemberService.cs rename src/{Umbraco.Core => Umbraco.Abstractions}/Services/IMembershipRoleService.cs (100%) diff --git a/src/Umbraco.Core/Persistence/Querying/StringPropertyMatchType.cs b/src/Umbraco.Abstractions/Persistence/Querying/StringPropertyMatchType.cs similarity index 100% rename from src/Umbraco.Core/Persistence/Querying/StringPropertyMatchType.cs rename to src/Umbraco.Abstractions/Persistence/Querying/StringPropertyMatchType.cs diff --git a/src/Umbraco.Core/Services/Changes/TreeChange.cs b/src/Umbraco.Abstractions/Services/Changes/TreeChange.cs similarity index 95% rename from src/Umbraco.Core/Services/Changes/TreeChange.cs rename to src/Umbraco.Abstractions/Services/Changes/TreeChange.cs index 81c9b67c3f..605cde87a2 100644 --- a/src/Umbraco.Core/Services/Changes/TreeChange.cs +++ b/src/Umbraco.Abstractions/Services/Changes/TreeChange.cs @@ -3,7 +3,7 @@ using System.Linq; namespace Umbraco.Core.Services.Changes { - internal class TreeChange + public class TreeChange { public TreeChange(TItem changedItem, TreeChangeTypes changeTypes) { diff --git a/src/Umbraco.Core/Services/Changes/TreeChangeExtensions.cs b/src/Umbraco.Abstractions/Services/Changes/TreeChangeExtensions.cs similarity index 88% rename from src/Umbraco.Core/Services/Changes/TreeChangeExtensions.cs rename to src/Umbraco.Abstractions/Services/Changes/TreeChangeExtensions.cs index a5f5efdba9..6971ebc91f 100644 --- a/src/Umbraco.Core/Services/Changes/TreeChangeExtensions.cs +++ b/src/Umbraco.Abstractions/Services/Changes/TreeChangeExtensions.cs @@ -4,7 +4,7 @@ namespace Umbraco.Core.Services.Changes { public static class TreeChangeExtensions { - internal static TreeChange.EventArgs ToEventArgs(this IEnumerable> changes) + public static TreeChange.EventArgs ToEventArgs(this IEnumerable> changes) { return new TreeChange.EventArgs(changes); } diff --git a/src/Umbraco.Core/Services/IAuditService.cs b/src/Umbraco.Abstractions/Services/IAuditService.cs similarity index 98% rename from src/Umbraco.Core/Services/IAuditService.cs rename to src/Umbraco.Abstractions/Services/IAuditService.cs index f9b5aa2d87..de4ec889cd 100644 --- a/src/Umbraco.Core/Services/IAuditService.cs +++ b/src/Umbraco.Abstractions/Services/IAuditService.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; using Umbraco.Core.Models; -using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Persistence.Querying; namespace Umbraco.Core.Services diff --git a/src/Umbraco.Core/Services/IContentServiceBase.cs b/src/Umbraco.Abstractions/Services/IContentServiceBase.cs similarity index 100% rename from src/Umbraco.Core/Services/IContentServiceBase.cs rename to src/Umbraco.Abstractions/Services/IContentServiceBase.cs diff --git a/src/Umbraco.Core/Services/IExternalLoginService.cs b/src/Umbraco.Abstractions/Services/IExternalLoginService.cs similarity index 97% rename from src/Umbraco.Core/Services/IExternalLoginService.cs rename to src/Umbraco.Abstractions/Services/IExternalLoginService.cs index 2342fca0d9..d57bb052af 100644 --- a/src/Umbraco.Core/Services/IExternalLoginService.cs +++ b/src/Umbraco.Abstractions/Services/IExternalLoginService.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Microsoft.AspNet.Identity; using Umbraco.Core.Models.Identity; namespace Umbraco.Core.Services diff --git a/src/Umbraco.Core/Services/IFileService.cs b/src/Umbraco.Abstractions/Services/IFileService.cs similarity index 100% rename from src/Umbraco.Core/Services/IFileService.cs rename to src/Umbraco.Abstractions/Services/IFileService.cs diff --git a/src/Umbraco.Core/Services/ILocalizationService.cs b/src/Umbraco.Abstractions/Services/ILocalizationService.cs similarity index 98% rename from src/Umbraco.Core/Services/ILocalizationService.cs rename to src/Umbraco.Abstractions/Services/ILocalizationService.cs index 019e07493a..4ab71f8ea6 100644 --- a/src/Umbraco.Core/Services/ILocalizationService.cs +++ b/src/Umbraco.Abstractions/Services/ILocalizationService.cs @@ -104,10 +104,10 @@ namespace Umbraco.Core.Services ILanguage GetLanguageById(int id); /// - /// Gets a by its iso code + /// Gets a by its iso code /// /// Iso Code of the language (ie. en-US) - /// + /// ILanguage GetLanguageByIsoCode(string isoCode); /// diff --git a/src/Umbraco.Core/Services/IMacroService.cs b/src/Umbraco.Abstractions/Services/IMacroService.cs similarity index 100% rename from src/Umbraco.Core/Services/IMacroService.cs rename to src/Umbraco.Abstractions/Services/IMacroService.cs diff --git a/src/Umbraco.Abstractions/Services/IMembershipMemberService.cs b/src/Umbraco.Abstractions/Services/IMembershipMemberService.cs new file mode 100644 index 0000000000..a224dfc967 --- /dev/null +++ b/src/Umbraco.Abstractions/Services/IMembershipMemberService.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Umbraco.Core.Models.Membership; +using Umbraco.Core.Persistence.Querying; + +namespace Umbraco.Core.Services +{ + /// + /// Defines part of the UserService/MemberService, which is specific to methods used by the membership provider. + /// The generic type is restricted to . The implementation of this interface uses + /// either for the MemberService or for the UserService. + /// + /// + /// Idea is to have this as an isolated interface so that it can be easily 'replaced' in the membership provider implementation. + /// + public interface IMembershipMemberService : IService + where T : class, IMembershipUser + { + /// + /// Gets the total number of Members or Users based on the count type + /// + /// + /// The way the Online count is done is the same way that it is done in the MS SqlMembershipProvider - We query for any members + /// that have their last active date within the Membership.UserIsOnlineTimeWindow (which is in minutes). It isn't exact science + /// but that is how MS have made theirs so we'll follow that principal. + /// + /// to count by + /// with number of Members or Users for passed in type + int GetCount(MemberCountType countType); + + /// + /// Checks if a Member with the username exists + /// + /// Username to check + /// True if the Member exists otherwise False + bool Exists(string username); + + /// + /// Creates and persists a new + /// + /// An can be of type or + /// Username of the to create + /// Email of the to create + /// This value should be the encoded/encrypted/hashed value for the password that will be stored in the database + /// Alias of the Type + /// + T CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias); + + /// + /// Creates and persists a new + /// + /// An can be of type or + /// Username of the to create + /// Email of the to create + /// This value should be the encoded/encrypted/hashed value for the password that will be stored in the database + /// Alias of the Type + /// IsApproved of the to create + /// + T CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias, bool isApproved); + + /// + /// Gets an by its provider key + /// + /// An can be of type or + /// Id to use for retrieval + /// + T GetByProviderKey(object id); + + /// + /// Get an by email + /// + /// An can be of type or + /// Email to use for retrieval + /// + T GetByEmail(string email); + + /// + /// Get an by username + /// + /// An can be of type or + /// Username to use for retrieval + /// + T GetByUsername(string username); + + /// + /// Deletes an + /// + /// An can be of type or + /// or to Delete + void Delete(T membershipUser); + + /// + /// Saves an + /// + /// An can be of type or + /// or to Save + /// Optional parameter to raise events. + /// Default is True otherwise set to False to not raise events + void Save(T entity, bool raiseEvents = true); + + /// + /// Saves a list of objects + /// + /// An can be of type or + /// to save + /// Optional parameter to raise events. + /// Default is True otherwise set to False to not raise events + void Save(IEnumerable entities, bool raiseEvents = true); + + /// + /// Gets the default MemberType alias + /// + /// By default we'll return the 'writer', but we need to check it exists. If it doesn't we'll + /// return the first type that is not an admin, otherwise if there's only one we will return that one. + /// Alias of the default MemberType + string GetDefaultMemberType(); + + /// + /// Finds a list of objects by a partial email string + /// + /// An can be of type or + /// Partial email string to match + /// Current page index + /// Size of the page + /// Total number of records found (out) + /// The type of match to make as . Default is + /// + IEnumerable FindByEmail(string emailStringToMatch, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith); + + /// + /// Finds a list of objects by a partial username + /// + /// An can be of type or + /// Partial username to match + /// Current page index + /// Size of the page + /// Total number of records found (out) + /// The type of match to make as . Default is + /// + IEnumerable FindByUsername(string login, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith); + + /// + /// Gets a list of paged objects + /// + /// An can be of type or + /// Current page index + /// Size of the page + /// Total number of records found (out) + /// + IEnumerable GetAll(long pageIndex, int pageSize, out long totalRecords); + } +} diff --git a/src/Umbraco.Core/Services/IMembershipRoleService.cs b/src/Umbraco.Abstractions/Services/IMembershipRoleService.cs similarity index 100% rename from src/Umbraco.Core/Services/IMembershipRoleService.cs rename to src/Umbraco.Abstractions/Services/IMembershipRoleService.cs diff --git a/src/Umbraco.Core/CompositionExtensions_Essentials.cs b/src/Umbraco.Core/CompositionExtensions_Essentials.cs index b85479716c..4755e55adf 100644 --- a/src/Umbraco.Core/CompositionExtensions_Essentials.cs +++ b/src/Umbraco.Core/CompositionExtensions_Essentials.cs @@ -1,5 +1,6 @@ using Umbraco.Core.Cache; using Umbraco.Core.Composing; +using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Persistence; @@ -19,7 +20,8 @@ namespace Umbraco.Core AppCaches appCaches, IUmbracoDatabaseFactory databaseFactory, TypeLoader typeLoader, - IRuntimeState state) + IRuntimeState state, + IIOHelper ioHelper) { composition.RegisterUnique(logger); composition.RegisterUnique(profiler); @@ -30,6 +32,7 @@ namespace Umbraco.Core composition.RegisterUnique(factory => factory.GetInstance().SqlContext); composition.RegisterUnique(typeLoader); composition.RegisterUnique(state); + composition.RegisterUnique(ioHelper); } } } diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index c1215553a2..2c4018fbb3 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -42,6 +42,11 @@ namespace Umbraco.Core.Runtime /// protected IProfilingLogger ProfilingLogger { get; private set; } + /// + /// Gets the + /// + protected IIOHelper IOHelper { get; private set; } + /// public IRuntimeState State => _state; @@ -56,6 +61,10 @@ namespace Umbraco.Core.Runtime var profiler = Profiler = GetProfiler(); var profilingLogger = ProfilingLogger = new ProfilingLogger(logger, profiler); + IOHelper = GetIOHelper(); + if (IOHelper == null) + throw new InvalidOperationException($"The object returned from {nameof(GetIOHelper)} cannot be null"); + // the boot loader boots using a container scope, so anything that is PerScope will // be disposed after the boot loader has booted, and anything else will remain. // note that this REQUIRES that perWebRequestScope has NOT been enabled yet, else @@ -130,7 +139,7 @@ namespace Umbraco.Core.Runtime // create the composition composition = new Composition(register, typeLoader, ProfilingLogger, _state, configs); - composition.RegisterEssentials(Logger, Profiler, ProfilingLogger, mainDom, appCaches, databaseFactory, typeLoader, _state); + composition.RegisterEssentials(Logger, Profiler, ProfilingLogger, mainDom, appCaches, databaseFactory, typeLoader, _state, IOHelper); // run handlers RuntimeOptions.DoRuntimeEssentials(composition, appCaches, typeLoader, databaseFactory); @@ -313,6 +322,13 @@ namespace Umbraco.Core.Runtime protected virtual IProfiler GetProfiler() => new LogProfiler(Logger); + /// + /// Gets a + /// + /// + protected virtual IIOHelper GetIOHelper() + => new Umbraco.Core.IO.IOHelper(); + /// /// Gets the application caches. /// diff --git a/src/Umbraco.Core/Services/Changes/ContentTypeChangeExtensions.cs b/src/Umbraco.Core/Services/Changes/ContentTypeChangeExtensions.cs index f783098db0..d9ac97ebcd 100644 --- a/src/Umbraco.Core/Services/Changes/ContentTypeChangeExtensions.cs +++ b/src/Umbraco.Core/Services/Changes/ContentTypeChangeExtensions.cs @@ -3,7 +3,7 @@ using Umbraco.Core.Models; namespace Umbraco.Core.Services.Changes { - internal static class ContentTypeChangeExtensions + public static class ContentTypeChangeExtensions { public static ContentTypeChange.EventArgs ToEventArgs(this IEnumerable> changes) where TItem : class, IContentTypeComposition diff --git a/src/Umbraco.Core/Services/IMembershipMemberService.cs b/src/Umbraco.Core/Services/IMembershipMemberService.cs index 448b0c761a..4ecbaa5338 100644 --- a/src/Umbraco.Core/Services/IMembershipMemberService.cs +++ b/src/Umbraco.Core/Services/IMembershipMemberService.cs @@ -23,148 +23,5 @@ namespace Umbraco.Core.Services IMember CreateMemberWithIdentity(string username, string email, IMemberType memberType); } - /// - /// Defines part of the UserService/MemberService, which is specific to methods used by the membership provider. - /// The generic type is restricted to . The implementation of this interface uses - /// either for the MemberService or for the UserService. - /// - /// - /// Idea is to have this as an isolated interface so that it can be easily 'replaced' in the membership provider implementation. - /// - public interface IMembershipMemberService : IService - where T : class, IMembershipUser - { - /// - /// Gets the total number of Members or Users based on the count type - /// - /// - /// The way the Online count is done is the same way that it is done in the MS SqlMembershipProvider - We query for any members - /// that have their last active date within the Membership.UserIsOnlineTimeWindow (which is in minutes). It isn't exact science - /// but that is how MS have made theirs so we'll follow that principal. - /// - /// to count by - /// with number of Members or Users for passed in type - int GetCount(MemberCountType countType); - - /// - /// Checks if a Member with the username exists - /// - /// Username to check - /// True if the Member exists otherwise False - bool Exists(string username); - - /// - /// Creates and persists a new - /// - /// An can be of type or - /// Username of the to create - /// Email of the to create - /// This value should be the encoded/encrypted/hashed value for the password that will be stored in the database - /// Alias of the Type - /// - T CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias); - - /// - /// Creates and persists a new - /// - /// An can be of type or - /// Username of the to create - /// Email of the to create - /// This value should be the encoded/encrypted/hashed value for the password that will be stored in the database - /// Alias of the Type - /// IsApproved of the to create - /// - T CreateWithIdentity(string username, string email, string passwordValue, string memberTypeAlias, bool isApproved); - - /// - /// Gets an by its provider key - /// - /// An can be of type or - /// Id to use for retrieval - /// - T GetByProviderKey(object id); - - /// - /// Get an by email - /// - /// An can be of type or - /// Email to use for retrieval - /// - T GetByEmail(string email); - - /// - /// Get an by username - /// - /// An can be of type or - /// Username to use for retrieval - /// - T GetByUsername(string username); - - /// - /// Deletes an - /// - /// An can be of type or - /// or to Delete - void Delete(T membershipUser); - - /// - /// Saves an - /// - /// An can be of type or - /// or to Save - /// Optional parameter to raise events. - /// Default is True otherwise set to False to not raise events - void Save(T entity, bool raiseEvents = true); - - /// - /// Saves a list of objects - /// - /// An can be of type or - /// to save - /// Optional parameter to raise events. - /// Default is True otherwise set to False to not raise events - void Save(IEnumerable entities, bool raiseEvents = true); - - /// - /// Gets the default MemberType alias - /// - /// By default we'll return the 'writer', but we need to check it exists. If it doesn't we'll - /// return the first type that is not an admin, otherwise if there's only one we will return that one. - /// Alias of the default MemberType - string GetDefaultMemberType(); - - /// - /// Finds a list of objects by a partial email string - /// - /// An can be of type or - /// Partial email string to match - /// Current page index - /// Size of the page - /// Total number of records found (out) - /// The type of match to make as . Default is - /// - IEnumerable FindByEmail(string emailStringToMatch, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith); - - /// - /// Finds a list of objects by a partial username - /// - /// An can be of type or - /// Partial username to match - /// Current page index - /// Size of the page - /// Total number of records found (out) - /// The type of match to make as . Default is - /// - IEnumerable FindByUsername(string login, long pageIndex, int pageSize, out long totalRecords, StringPropertyMatchType matchType = StringPropertyMatchType.StartsWith); - - /// - /// Gets a list of paged objects - /// - /// An can be of type or - /// Current page index - /// Size of the page - /// Total number of records found (out) - /// - IEnumerable GetAll(long pageIndex, int pageSize, out long totalRecords); - } + } diff --git a/src/Umbraco.Core/Services/INotificationService.cs b/src/Umbraco.Core/Services/INotificationService.cs index a990b1e0ff..1a48d73297 100644 --- a/src/Umbraco.Core/Services/INotificationService.cs +++ b/src/Umbraco.Core/Services/INotificationService.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.Services /// /// /// - /// + /// /// /// void SendNotifications(IUser operatingUser, IEnumerable entities, string action, string actionName, Uri siteUri, diff --git a/src/Umbraco.Core/Services/Implement/MediaService.cs b/src/Umbraco.Core/Services/Implement/MediaService.cs index e9fdedbf33..7928379208 100644 --- a/src/Umbraco.Core/Services/Implement/MediaService.cs +++ b/src/Umbraco.Core/Services/Implement/MediaService.cs @@ -1252,7 +1252,7 @@ namespace Umbraco.Core.Services.Implement /// /// Occurs after change. /// - internal static event TypedEventHandler.EventArgs> TreeChanged; + public static event TypedEventHandler.EventArgs> TreeChanged; #endregion diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 0643b5f2dd..ae12b40349 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -294,13 +294,10 @@ - - - - - + + @@ -894,7 +891,6 @@ - @@ -1067,22 +1063,16 @@ - - - - - -