diff --git a/src/Umbraco.Core/AssemblyExtensions.cs b/src/Umbraco.Core/AssemblyExtensions.cs index df4487c197..666dce18fc 100644 --- a/src/Umbraco.Core/AssemblyExtensions.cs +++ b/src/Umbraco.Core/AssemblyExtensions.cs @@ -19,7 +19,41 @@ namespace Umbraco.Core return new FileInfo(path); } - /// + /// + /// Returns true if the assembly is the App_Code assembly + /// + /// + /// + public static bool IsAppCodeAssembly(this Assembly assembly) + { + if (assembly.FullName.StartsWith("App_Code")) + { + try + { + Assembly.Load("App_Code"); + return true; + } + catch (FileNotFoundException) + { + //this will occur if it cannot load the assembly + return false; + } + } + return false; + } + + /// + /// Returns true if the assembly is the compiled global asax. + /// + /// + /// + public static bool IsGlobalAsaxAssembly(this Assembly assembly) + { + //only way I can figure out how to test is by the name + return assembly.FullName.StartsWith("App_global.asax"); + } + + /// /// Returns the file used to load the assembly /// /// diff --git a/src/Umbraco.Core/Persistence/DefaultDatabaseFactory.cs b/src/Umbraco.Core/Persistence/DefaultDatabaseFactory.cs index bdfc8697f8..f55b5c189c 100644 --- a/src/Umbraco.Core/Persistence/DefaultDatabaseFactory.cs +++ b/src/Umbraco.Core/Persistence/DefaultDatabaseFactory.cs @@ -1,3 +1,4 @@ +using System; using System.Web; using Umbraco.Core.Configuration; @@ -16,7 +17,12 @@ namespace Umbraco.Core.Persistence private readonly string _connectionStringName; private readonly string _connectionString; private readonly string _providerName; - private static volatile UmbracoDatabase _globalInstance = null; + + //very important to have ThreadStatic: + // see: http://issues.umbraco.org/issue/U4-2172 + [ThreadStatic] + private static volatile UmbracoDatabase _nonHttpInstance; + private static readonly object Locker = new object(); /// @@ -55,25 +61,25 @@ namespace Umbraco.Core.Persistence //no http context, create the singleton global object if (HttpContext.Current == null) { - if (_globalInstance == null) + if (_nonHttpInstance == null) { lock (Locker) { //double check - if (_globalInstance == null) + if (_nonHttpInstance == null) { - _globalInstance = string.IsNullOrEmpty(_connectionString) == false && + _nonHttpInstance = string.IsNullOrEmpty(_providerName) == false && string.IsNullOrEmpty(_providerName) == false string.IsNullOrEmpty(_providerName) == false ? new UmbracoDatabase(_connectionString, _providerName) : new UmbracoDatabase(_connectionStringName); } } } - return _globalInstance; + return _nonHttpInstance; } //we have an http context, so only create one per request - if (!HttpContext.Current.Items.Contains(typeof(DefaultDatabaseFactory))) + if (HttpContext.Current.Items.Contains(typeof(DefaultDatabaseFactory)) == false) { HttpContext.Current.Items.Add(typeof (DefaultDatabaseFactory), string.IsNullOrEmpty(_connectionString) == false && @@ -88,7 +94,7 @@ namespace Umbraco.Core.Persistence { if (HttpContext.Current == null) { - _globalInstance.Dispose(); + _nonHttpInstance.Dispose(); } else { diff --git a/src/Umbraco.Core/TypeFinder.cs b/src/Umbraco.Core/TypeFinder.cs index d91cebf429..81be7564c0 100644 --- a/src/Umbraco.Core/TypeFinder.cs +++ b/src/Umbraco.Core/TypeFinder.cs @@ -19,8 +19,6 @@ using Umbraco.Core.IO; namespace Umbraco.Core { - //TODO: Get the App_Code stuff in here from the old one - /// /// A utility class to find all classes of a certain type by reflection in the current bin folder /// of the web application. @@ -281,42 +279,66 @@ namespace Umbraco.Core "CookComputing." }; + /// + /// Finds any classes derived from the type T that contain the attribute TAttribute + /// + /// + /// + /// public static IEnumerable FindClassesOfTypeWithAttribute() where TAttribute : Attribute { return FindClassesOfTypeWithAttribute(GetAssembliesWithKnownExclusions(), true); } + /// + /// Finds any classes derived from the type T that contain the attribute TAttribute + /// + /// + /// + /// + /// public static IEnumerable FindClassesOfTypeWithAttribute(IEnumerable assemblies) where TAttribute : Attribute { return FindClassesOfTypeWithAttribute(assemblies, true); } - public static IEnumerable FindClassesOfTypeWithAttribute(IEnumerable assemblies, - bool onlyConcreteClasses) - where TAttribute : Attribute + /// + /// Finds any classes derived from the type T that contain the attribute TAttribute + /// + /// + /// + /// + /// + /// + public static IEnumerable FindClassesOfTypeWithAttribute( + IEnumerable assemblies, + bool onlyConcreteClasses) + where TAttribute : Attribute + { + return FindClassesOfTypeWithAttribute(typeof (T), assemblies, onlyConcreteClasses); + } + + /// + /// Finds any classes derived from the assignTypeFrom Type that contain the attribute TAttribute + /// + /// + /// + /// + /// + /// + public static IEnumerable FindClassesOfTypeWithAttribute( + Type assignTypeFrom, + IEnumerable assemblies, + bool onlyConcreteClasses) + where TAttribute : Attribute { if (assemblies == null) throw new ArgumentNullException("assemblies"); - - // a assembly cant contain types that are assignable to a type it doesn't reference - assemblies = RemoveAssembliesThatDontReferenceAssemblyOfType(typeof (T), assemblies); - // a assembly cant contain types with a attribute it doesn't reference - assemblies = RemoveAssembliesThatDontReferenceAssemblyOfType(typeof (TAttribute), assemblies); - - var l = new List(); - foreach(var a in assemblies) - { - var types = from t in GetTypesWithFormattedException(a) - where !t.IsInterface - && typeof (T).IsAssignableFrom(t) - && t.GetCustomAttributes(false).Any() - && (!onlyConcreteClasses || (t.IsClass && !t.IsAbstract)) - select t; - l.AddRange(types); - } - - return l; + + return GetClasses(assignTypeFrom, assemblies, onlyConcreteClasses, + //the additional filter will ensure that any found types also have the attribute applied. + t => t.GetCustomAttributes(false).Any()); } /// @@ -340,7 +362,7 @@ namespace Umbraco.Core { if (assemblies == null) throw new ArgumentNullException("assemblies"); - return GetAssignablesFromType(assemblies, onlyConcreteClasses); + return GetClasses(typeof(T), assemblies, onlyConcreteClasses); } /// @@ -367,66 +389,50 @@ namespace Umbraco.Core return FindClassesWithAttribute(typeof(T), assemblies, onlyConcreteClasses); } - /// - /// Finds the classes with attribute. - /// - /// The attribute type - /// The assemblies. - /// if set to true only concrete classes. - /// - public static IEnumerable FindClassesWithAttribute(Type type, IEnumerable assemblies, - bool onlyConcreteClasses) - { - if (assemblies == null) throw new ArgumentNullException("assemblies"); - if (!TypeHelper.IsTypeAssignableFrom(type)) - throw new ArgumentException("The type specified: " + type + " is not an Attribute type"); - // a assembly cant contain types with a attribute it doesn't reference - assemblies = RemoveAssembliesThatDontReferenceAssemblyOfType(type, assemblies); + /// + /// Finds any classes with the attribute. + /// + /// The attribute type + /// The assemblies. + /// if set to true only concrete classes. + /// + public static IEnumerable FindClassesWithAttribute( + Type attributeType, + IEnumerable assemblies, + bool onlyConcreteClasses) + { + if (assemblies == null) throw new ArgumentNullException("assemblies"); - var l = new List(); - foreach (var a in assemblies) - { - var types = from t in GetTypesWithFormattedException(a) - where - !t.IsInterface && t.GetCustomAttributes(type, false).Any() && - (!onlyConcreteClasses || (t.IsClass && !t.IsAbstract)) - select t; - l.AddRange(types); - } + if (TypeHelper.IsTypeAssignableFrom(attributeType) == false) + throw new ArgumentException("The type specified: " + attributeType + " is not an Attribute type"); - return l; - } - /// - /// Removes assemblies that doesn't reference the assembly of the type we are looking for. - /// - /// - /// - /// - private static IEnumerable RemoveAssembliesThatDontReferenceAssemblyOfType(Type type, IEnumerable assemblies) - { - // Avoid scanning assembly if it doesn't contain a reference to the assembly containing the type we are looking for - // to the assembly containing the attribute we are looking for - var assemblyNameOfType = type.Assembly.GetName().Name; + var foundAssignableTypes = new List(); - return assemblies - .Where(assembly => assembly == type.Assembly - || HasReferenceToAssemblyWithName(assembly, assemblyNameOfType)).ToList(); - } - /// - /// checks if the assembly has a reference with the same name as the expected assembly name. - /// - /// - /// - /// - private static bool HasReferenceToAssemblyWithName(Assembly assembly, string expectedAssemblyName) - { - return assembly - .GetReferencedAssemblies() - .Select(a => a.Name) - .Contains(expectedAssemblyName, StringComparer.Ordinal); - } + var assemblyList = assemblies.ToArray(); - /// + //find all assembly references that are referencing the attribute type's assembly since we + //should only be scanning those assemblies because any other assembly will definitely not + //contain a class that has this attribute. + var referencedAssemblies = TypeHelper.GetReferencedAssemblies(attributeType, assemblyList); + + foreach (var a in referencedAssemblies) + { + //get all types in the assembly that are sub types of the current type + var allTypes = GetTypesWithFormattedException(a).ToArray(); + + var types = allTypes.Where(t => TypeHelper.IsNonStaticClass(t) + && (onlyConcreteClasses == false || t.IsAbstract == false) + //the type must have this attribute + && t.GetCustomAttributes(attributeType, false).Any()); + + foundAssignableTypes.AddRange(types); + } + + return foundAssignableTypes; + } + + + /// /// Finds the classes with attribute. /// /// @@ -452,34 +458,96 @@ namespace Umbraco.Core #region Private methods - /// - /// Gets a collection of assignables of type T from a collection of assemblies - /// - /// - /// - /// - /// - private static IEnumerable GetAssignablesFromType(IEnumerable assemblies, bool onlyConcreteClasses) + /// + /// Finds types that are assignable from the assignTypeFrom parameter and will scan for these types in the assembly + /// list passed in, however we will only scan assemblies that have a reference to the assignTypeFrom Type or any type + /// deriving from the base type. + /// + /// + /// + /// + /// An additional filter to apply for what types will actually be included in the return value + /// + private static IEnumerable GetClasses( + Type assignTypeFrom, + IEnumerable assemblies, + bool onlyConcreteClasses, + Func additionalFilter = null) { - return GetTypes(typeof(T), assemblies, onlyConcreteClasses); - } + //the default filter will always return true. + if (additionalFilter == null) + { + additionalFilter = type => true; + } - private static IEnumerable GetTypes(Type assignTypeFrom, IEnumerable assemblies, bool onlyConcreteClasses) - { - // a assembly cant contain types that are assignable to a type it doesn't reference - assemblies = RemoveAssembliesThatDontReferenceAssemblyOfType(assignTypeFrom, assemblies); + var foundAssignableTypes = new List(); + + var assemblyList = assemblies.ToArray(); + + //find all assembly references that are referencing the current type's assembly since we + //should only be scanning those assemblies because any other assembly will definitely not + //contain sub type's of the one we're currently looking for + var referencedAssemblies = TypeHelper.GetReferencedAssemblies(assignTypeFrom, assemblyList); + + //get a list of non-referenced assemblies (we'll use this when we recurse below) + var otherAssemblies = assemblyList.Where(x => referencedAssemblies.Contains(x) == false).ToArray(); + + //loop through the referenced assemblies + foreach (var a in referencedAssemblies) + { + //get all types in the assembly that are sub types of the current type + var allSubTypes = GetTypesWithFormattedException(a) + .Where(assignTypeFrom.IsAssignableFrom) + .ToArray(); + + //now filter the types based on the onlyConcreteClasses flag, not interfaces, not static classes + var filteredTypes = allSubTypes + .Where(t => (TypeHelper.IsNonStaticClass(t) + && (onlyConcreteClasses == false || t.IsAbstract == false) + && additionalFilter(t))) + .ToArray(); + + //add the types to our list to return + foundAssignableTypes.AddRange(filteredTypes); + + //now we need to include types that may be inheriting from sub classes of the type being searched for + //so we will search in assemblies that reference those types too. + foreach (var subTypesInAssembly in allSubTypes.GroupBy(x => x.Assembly)) + { + + //So that we are not scanning too much, we need to group the sub types: + // * if there is more than 1 sub type in the same assembly then we should only search on the 'lowest base' type. + // * We should also not search for sub types if the type is sealed since you cannot inherit from a sealed class + // * We should not search for sub types if the type is static since you cannot inherit from them. + var subTypeList = subTypesInAssembly + .Where(t => t.IsSealed == false && TypeHelper.IsStaticClass(t) == false) + .ToArray(); + + var baseClassAttempt = TypeHelper.GetLowestBaseType(subTypeList); + + //if there's a base class amongst the types then we'll only search for that type. + //otherwise we'll have to search for all of them. + var subTypesToSearch = new List(); + if (baseClassAttempt.Success) + { + subTypesToSearch.Add(baseClassAttempt.Result); + } + else + { + subTypesToSearch.AddRange(subTypeList); + } + + foreach (var typeToSearch in subTypesToSearch) + { + //recursively find the types inheriting from this sub type in the other non-scanned assemblies. + var foundTypes = GetClasses(typeToSearch, otherAssemblies, onlyConcreteClasses); + foundAssignableTypes.AddRange(foundTypes); + } + + } - var l = new List(); - foreach (var a in assemblies) - { - var types = from t in GetTypesWithFormattedException(a) - where - !t.IsInterface && assignTypeFrom.IsAssignableFrom(t) && - (!onlyConcreteClasses || (t.IsClass && !t.IsAbstract)) - select t; - l.AddRange(types); } - return l; + return foundAssignableTypes; } private static IEnumerable GetTypesWithFormattedException(Assembly a) diff --git a/src/Umbraco.Core/TypeHelper.cs b/src/Umbraco.Core/TypeHelper.cs index d422e6bc4d..26dd2a8402 100644 --- a/src/Umbraco.Core/TypeHelper.cs +++ b/src/Umbraco.Core/TypeHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -15,6 +16,109 @@ namespace Umbraco.Core private static readonly ConcurrentDictionary GetFieldsCache = new ConcurrentDictionary(); private static readonly ConcurrentDictionary, PropertyInfo[]> GetPropertiesCache = new ConcurrentDictionary, PropertyInfo[]>(); + /// + /// Find all assembly references that are referencing the assignTypeFrom Type's assembly found in the assemblyList + /// + /// + /// + /// + /// + /// If the assembly of the assignTypeFrom Type is in the App_Code assembly, then we return nothing since things cannot + /// reference that assembly, same with the global.asax assembly. + /// + public static Assembly[] GetReferencedAssemblies(Type assignTypeFrom, IEnumerable assemblies) + { + //check if it is the app_code assembly. + //check if it is App_global.asax assembly + if (assignTypeFrom.Assembly.IsAppCodeAssembly() || assignTypeFrom.Assembly.IsGlobalAsaxAssembly()) + { + return Enumerable.Empty().ToArray(); + } + + //find all assembly references that are referencing the current type's assembly since we + //should only be scanning those assemblies because any other assembly will definitely not + //contain sub type's of the one we're currently looking for + return assemblies + .Where(assembly => + assembly == assignTypeFrom.Assembly || HasReferenceToAssemblyWithName(assembly, assignTypeFrom.Assembly.GetName().Name)) + .ToArray(); + } + + /// + /// checks if the assembly has a reference with the same name as the expected assembly name. + /// + /// + /// + /// + private static bool HasReferenceToAssemblyWithName(Assembly assembly, string expectedAssemblyName) + { + return assembly + .GetReferencedAssemblies() + .Select(a => a.Name) + .Contains(expectedAssemblyName, StringComparer.Ordinal); + } + + /// + /// Returns true if the type is a class and is not static + /// + /// + /// + public static bool IsNonStaticClass(Type t) + { + return t.IsClass && IsStaticClass(t) == false; + } + + /// + /// Returns true if the type is a static class + /// + /// + /// + /// + /// In IL a static class is abstract and sealed + /// see: http://stackoverflow.com/questions/1175888/determine-if-a-type-is-static + /// + public static bool IsStaticClass(Type type) + { + return type.IsAbstract && type.IsSealed; + } + + /// + /// Finds a lowest base class amongst a collection of types + /// + /// + /// + /// + /// The term 'lowest' refers to the most base class of the type collection. + /// If a base type is not found amongst the type collection then an invalid attempt is returned. + /// + public static Attempt GetLowestBaseType(params Type[] types) + { + if (types.Length == 0) + { + return Attempt.False; + } + if (types.Length == 1) + { + return new Attempt(true, types[0]); + } + + foreach (var curr in types) + { + var others = types.Except(new[] {curr}); + + //is the curr type a common denominator for all others ? + var isBase = others.All(curr.IsAssignableFrom); + + //if this type is the base for all others + if (isBase) + { + return new Attempt(true, curr); + } + } + + return Attempt.False; + } + /// /// Determines whether the type is assignable from the specified implementation , /// and caches the result across the application using a . diff --git a/src/Umbraco.Tests/PluginManagerTests.cs b/src/Umbraco.Tests/PluginManagerTests.cs index 6fc7442045..dbb1d1ddde 100644 --- a/src/Umbraco.Tests/PluginManagerTests.cs +++ b/src/Umbraco.Tests/PluginManagerTests.cs @@ -316,7 +316,7 @@ namespace Umbraco.Tests public void Resolves_DataTypes() { var types = PluginManager.Current.ResolveDataTypes(); - Assert.AreEqual(37, types.Count()); + Assert.AreEqual(38, types.Count()); } [Test] diff --git a/src/Umbraco.Tests/TypeFinderTests.cs b/src/Umbraco.Tests/TypeFinderTests.cs index 1e0fe16e4c..85b8bc9c9d 100644 --- a/src/Umbraco.Tests/TypeFinderTests.cs +++ b/src/Umbraco.Tests/TypeFinderTests.cs @@ -16,7 +16,6 @@ using SqlCE4Umbraco; using Umbraco.Core; using Umbraco.Core.IO; using Umbraco.Tests; -using Umbraco.Tests.PartialTrust; using Umbraco.Tests.TestHelpers; using Umbraco.Web.BaseRest; using umbraco; @@ -30,8 +29,9 @@ using umbraco.uicontrols; namespace Umbraco.Tests { - /// - /// Full Trust benchmark tests for typefinder and the old typefinder + + /// + /// Tests for typefinder /// [TestFixture] public class TypeFinderTests @@ -63,7 +63,8 @@ namespace Umbraco.Tests typeof(TypeFinder).Assembly, typeof(ISqlHelper).Assembly, typeof(ICultureDictionary).Assembly, - typeof(Tag).Assembly + typeof(Tag).Assembly, + typeof(UmbracoExamine.BaseUmbracoIndexer).Assembly }; } @@ -80,8 +81,12 @@ namespace Umbraco.Tests [Test] public void Find_Classes_Of_Type() { - var typesFound = TypeFinder.FindClassesOfType(_assemblies); - Assert.AreEqual(2, typesFound.Count()); + var typesFound = TypeFinder.FindClassesOfType(_assemblies); + var originalTypesFound = TypeFinderOriginal.FindClassesOfType(_assemblies); + + Assert.AreEqual(originalTypesFound.Count(), typesFound.Count()); + Assert.AreEqual(4, typesFound.Count()); + Assert.AreEqual(4, originalTypesFound.Count()); } [Test] @@ -153,6 +158,18 @@ namespace Umbraco.Tests } + public class MyTag : ITag + { + public int Id { get; private set; } + public string TagCaption { get; private set; } + public string Group { get; private set; } + } + + public class MySuperTag : MyTag + { + + } + [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class MyTestAttribute : Attribute { diff --git a/src/Umbraco.Tests/TypeHelperTests.cs b/src/Umbraco.Tests/TypeHelperTests.cs new file mode 100644 index 0000000000..93bde4439c --- /dev/null +++ b/src/Umbraco.Tests/TypeHelperTests.cs @@ -0,0 +1,84 @@ +using System; +using System.ComponentModel; +using System.Data.Common; +using System.Data.Odbc; +using System.Data.OleDb; +using System.Data.SqlClient; +using NUnit.Framework; +using Umbraco.Core; +using Umbraco.Tests.PartialTrust; +using Umbraco.Web; +using UmbracoExamine; +using umbraco; +using umbraco.presentation; +using umbraco.presentation.nodeFactory; +using umbraco.presentation.umbraco.Search; + +namespace Umbraco.Tests +{ + /// + /// Tests for TypeHelper + /// + [TestFixture] + public class TypeHelperTests : AbstractPartialTrustFixture + { + + [Test] + public void Is_Static_Class() + { + Assert.IsTrue(TypeHelper.IsStaticClass(typeof(TypeHelper))); + Assert.IsFalse(TypeHelper.IsStaticClass(typeof(TypeHelperTests))); + } + + [Test] + public void Find_Common_Base_Class() + { + var t1 = TypeHelper.GetLowestBaseType(typeof (OleDbCommand), + typeof (OdbcCommand), + typeof (SqlCommand)); + Assert.IsFalse(t1.Success); + + var t2 = TypeHelper.GetLowestBaseType(typeof (OleDbCommand), + typeof (OdbcCommand), + typeof (SqlCommand), + typeof (Component)); + Assert.IsTrue(t2.Success); + Assert.AreEqual(typeof(Component), t2.Result); + + var t3 = TypeHelper.GetLowestBaseType(typeof (OleDbCommand), + typeof (OdbcCommand), + typeof (SqlCommand), + typeof (Component), + typeof (Component).BaseType); + Assert.IsTrue(t3.Success); + Assert.AreEqual(typeof(MarshalByRefObject), t3.Result); + + var t4 = TypeHelper.GetLowestBaseType(typeof(OleDbCommand), + typeof(OdbcCommand), + typeof(SqlCommand), + typeof(Component), + typeof(Component).BaseType, + typeof(int)); + Assert.IsFalse(t4.Success); + + var t5 = TypeHelper.GetLowestBaseType(typeof(UmbracoEventManager)); + Assert.IsTrue(t5.Success); + Assert.AreEqual(typeof(UmbracoEventManager), t5.Result); + + var t6 = TypeHelper.GetLowestBaseType(typeof (IApplicationEventHandler), + typeof (LegacyScheduledTasks), + typeof(CacheHelperExtensions.CacheHelperApplicationEventListener)); + Assert.IsTrue(t6.Success); + Assert.AreEqual(typeof(IApplicationEventHandler), t6.Result); + + } + + public override void TestSetup() + { + } + + public override void TestTearDown() + { + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index dcb262ff8c..af6e0ba99a 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -342,6 +342,7 @@ + diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs index 306e1526da..cf7088c5d5 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentTypeControlNew.ascx.cs @@ -130,6 +130,23 @@ namespace umbraco.controls } } + /// + /// A class to track the async state for deleting a doc type property + /// + private class DeleteAsyncState + { + public Umbraco.Web.UmbracoContext UmbracoContext { get; private set; } + public GenericPropertyWrapper GenericPropertyWrapper { get; private set; } + + public DeleteAsyncState( + Umbraco.Web.UmbracoContext umbracoContext, + GenericPropertyWrapper genericPropertyWrapper) + { + UmbracoContext = umbracoContext; + GenericPropertyWrapper = genericPropertyWrapper; + } + } + /// /// A class to track the async state for saving the doc type /// diff --git a/src/WebPi/parameters.xml b/src/WebPi/parameters.xml index 0eb8da7152..350520407d 100644 --- a/src/WebPi/parameters.xml +++ b/src/WebPi/parameters.xml @@ -123,7 +123,7 @@ This is used to create a login and assign permissions. The SQL tags indicates it is a parameter required for SQL. The DbAdminPassword tag indicates it should be used when the user is creating a new database. If they're not, it can be filled in with the DbUserPassword value. --> - + diff --git a/src/umbraco.editorControls/mediapicker/MediaPickerDataType.cs b/src/umbraco.editorControls/mediapicker/MediaPickerDataType.cs index 4eac9d1ac7..6417b91fd0 100644 --- a/src/umbraco.editorControls/mediapicker/MediaPickerDataType.cs +++ b/src/umbraco.editorControls/mediapicker/MediaPickerDataType.cs @@ -3,36 +3,26 @@ using Umbraco.Core; namespace umbraco.editorControls.mediapicker { - /// - /// Summary description for MemberPickerDataType. - /// - public class MemberPickerDataType : cms.businesslogic.datatype.BaseDataType,interfaces.IDataType - { - private interfaces.IDataEditor _Editor; - private interfaces.IData _baseData; - private interfaces.IDataPrevalue _prevalueeditor; + //TODO: Properly rename this for a major release + public class MediaPickerDataType : MemberPickerDataType + { } - public override interfaces.IDataEditor DataEditor - { - get - { - if (_Editor == null) - _Editor = new mediaChooser(Data, - ((MediaPickerPrevalueEditor)PrevalueEditor).ShowPreview, - ((MediaPickerPrevalueEditor)PrevalueEditor).ShowAdvancedDialog); - return _Editor; - } - } + [Obsolete("Renamed to MediaPickerDataType because.. that is what it was all along")] + public class MemberPickerDataType : cms.businesslogic.datatype.BaseDataType, interfaces.IDataType + { + private interfaces.IDataEditor _editor; + private interfaces.IData _baseData; + private interfaces.IDataPrevalue _prevalueeditor; - public override interfaces.IData Data - { - get - { - if (_baseData == null) - _baseData = new cms.businesslogic.datatype.DefaultData(this); - return _baseData; - } - } + public override interfaces.IDataEditor DataEditor + { + get { return _editor ?? (_editor = new mediaChooser(Data, ((MediaPickerPrevalueEditor)PrevalueEditor).ShowPreview, ((MediaPickerPrevalueEditor)PrevalueEditor).ShowAdvancedDialog)); } + } + + public override interfaces.IData Data + { + get { return _baseData ?? (_baseData = new cms.businesslogic.datatype.DefaultData(this)); } + } public override Guid Id @@ -42,21 +32,16 @@ namespace umbraco.editorControls.mediapicker return new Guid(Constants.PropertyEditors.MediaPicker); } } - public override string DataTypeName - { - get - { - return "Media Picker"; - } - } - public override interfaces.IDataPrevalue PrevalueEditor - { - get - { - if (_prevalueeditor == null) - _prevalueeditor = new MediaPickerPrevalueEditor(this); - return _prevalueeditor; - } - } - } + + + public override string DataTypeName + { + get { return "Media Picker"; } + } + + public override interfaces.IDataPrevalue PrevalueEditor + { + get { return _prevalueeditor ?? (_prevalueeditor = new MediaPickerPrevalueEditor(this)); } + } + } } diff --git a/src/umbraco.editorControls/memberpicker/MemberPickerDataType.cs b/src/umbraco.editorControls/memberpicker/MemberPickerDataType.cs index 052765d877..1041160b0a 100644 --- a/src/umbraco.editorControls/memberpicker/MemberPickerDataType.cs +++ b/src/umbraco.editorControls/memberpicker/MemberPickerDataType.cs @@ -3,52 +3,34 @@ using Umbraco.Core; namespace umbraco.editorControls.memberpicker { - /// - /// Summary description for MemberPickerDataType. - /// - public class MemberPickerDataType : cms.businesslogic.datatype.BaseDataType,interfaces.IDataType - { - private interfaces.IDataEditor _Editor; - private interfaces.IData _baseData; - private interfaces.IDataPrevalue _prevalueeditor; + public class MemberPickerDataType : cms.businesslogic.datatype.BaseDataType, interfaces.IDataType + { + private interfaces.IDataEditor _editor; + private interfaces.IData _baseData; + private interfaces.IDataPrevalue _prevalueeditor; - public override interfaces.IDataEditor DataEditor - { - get - { - if (_Editor == null) - _Editor = new memberPicker(Data); - return _Editor; - } - } + public override interfaces.IDataEditor DataEditor + { + get { return _editor ?? (_editor = new memberPicker(Data)); } + } - public override interfaces.IData Data - { - get - { - if (_baseData == null) - _baseData = new cms.businesslogic.datatype.DefaultData(this); - return _baseData; - } - } - public override string DataTypeName - { - get {return "Member Picker";} - } + public override interfaces.IData Data + { + get { return _baseData ?? (_baseData = new cms.businesslogic.datatype.DefaultData(this)); } + } + public override string DataTypeName + { + get { return "Member Picker"; } + } - public override Guid Id - { + public override Guid Id + { get { return new Guid(Constants.PropertyEditors.MemberPicker); } - } + } - public override interfaces.IDataPrevalue PrevalueEditor - { - get - { - if (_prevalueeditor == null) - _prevalueeditor = new DefaultPrevalueEditor(this,false); - return _prevalueeditor; - } - } - } + public override interfaces.IDataPrevalue PrevalueEditor + { + get { return _prevalueeditor ?? (_prevalueeditor = new DefaultPrevalueEditor(this, false)); } + } + } }