Updated some of the Object resolver code, adds new protected AddTypes method, renamed method on Legacy resolver.
Fixes yet another issue with templates and package installs.
This commit is contained in:
@@ -31,7 +31,7 @@ namespace Umbraco.Core
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureRefreshersList();
|
||||
EnsureIdsAreTracked();
|
||||
return Values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Umbraco.Core
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureRefreshersList();
|
||||
EnsureIdsAreTracked();
|
||||
return Values;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace Umbraco.Core.ObjectResolution
|
||||
@@ -20,7 +21,7 @@ namespace Umbraco.Core.ObjectResolution
|
||||
where TResolved : class
|
||||
where TResolver : class
|
||||
{
|
||||
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
@@ -35,10 +36,7 @@ namespace Umbraco.Core.ObjectResolution
|
||||
protected LegacyTransientObjectsResolver(IEnumerable<Type> refreshers)
|
||||
: base(ObjectLifetimeScope.Transient) // new objects every time
|
||||
{
|
||||
foreach (var l in refreshers)
|
||||
{
|
||||
this.AddType(l);
|
||||
}
|
||||
AddTypes(refreshers);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -63,16 +61,16 @@ namespace Umbraco.Core.ObjectResolution
|
||||
/// <returns></returns>
|
||||
public TResolved GetById(Guid id)
|
||||
{
|
||||
EnsureRefreshersList();
|
||||
EnsureIdsAreTracked();
|
||||
return !_trackIdToType.ContainsKey(id)
|
||||
? null
|
||||
: PluginManager.Current.CreateInstance<TResolved>(_trackIdToType[id]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populates the refreshers dictionary to allow us to instantiate a type by Id since the ICacheRefresher type doesn't contain any metadata
|
||||
/// Populates the ids -> Type dictionary to allow us to instantiate a type by Id since these legacy types doesn't contain any metadata
|
||||
/// </summary>
|
||||
protected void EnsureRefreshersList()
|
||||
protected void EnsureIdsAreTracked()
|
||||
{
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
{
|
||||
|
||||
@@ -97,6 +97,10 @@ namespace Umbraco.Core.ObjectResolution
|
||||
protected ObjectLifetimeScope LifetimeScope { get; private set; }
|
||||
|
||||
private int _defaultPluginWeight = 10;
|
||||
private bool _supportsAdd = true;
|
||||
private bool _supportsInsert = true;
|
||||
private bool _supportsClear = true;
|
||||
private bool _supportsRemove = true;
|
||||
|
||||
/// <summary>
|
||||
/// Used in conjunction with GetSortedValues and WeightedPluginAttribute, if any of the objects
|
||||
@@ -185,11 +189,14 @@ namespace Umbraco.Core.ObjectResolution
|
||||
/// Removes a type.
|
||||
/// </summary>
|
||||
/// <param name="value">The type to remove.</param>
|
||||
public virtual void RemoveType(Type value)
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
public void RemoveType(Type value)
|
||||
{
|
||||
if (!SupportsRemove)
|
||||
throw new InvalidOperationException("This resolver does not support Removing types");
|
||||
|
||||
using (new WriteLock(_lock))
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
InstanceTypes.Remove(value);
|
||||
}
|
||||
}
|
||||
@@ -203,21 +210,42 @@ namespace Umbraco.Core.ObjectResolution
|
||||
RemoveType(typeof (T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// protected method allow the inheritor to add many types at once
|
||||
/// </summary>
|
||||
/// <param name="types"></param>
|
||||
protected void AddTypes(IEnumerable<Type> types)
|
||||
{
|
||||
using (var l = new WriteLock(_lock))
|
||||
{
|
||||
foreach(var t in types)
|
||||
{
|
||||
EnsureCorrectType(t);
|
||||
if (InstanceTypes.Contains(t))
|
||||
{
|
||||
throw new InvalidOperationException("The Type " + t + " already exists in the collection");
|
||||
};
|
||||
InstanceTypes.Add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a Type to the end of the list.
|
||||
/// </summary>
|
||||
/// <param name="value">The object to be added.</param>
|
||||
public virtual void AddType(Type value)
|
||||
public void AddType(Type value)
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
if (!SupportsAdd)
|
||||
throw new InvalidOperationException("This resolver does not support Adding new types");
|
||||
|
||||
using (var l = new WriteLock(_lock))
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
if (InstanceTypes.Contains(value))
|
||||
{
|
||||
throw new InvalidOperationException("The Type " + value + " already exists in the collection");
|
||||
};
|
||||
|
||||
l.UpgradeToWriteLock();
|
||||
InstanceTypes.Add(value);
|
||||
}
|
||||
}
|
||||
@@ -234,8 +262,11 @@ namespace Umbraco.Core.ObjectResolution
|
||||
/// <summary>
|
||||
/// Clears the list.
|
||||
/// </summary>
|
||||
public virtual void Clear()
|
||||
public void Clear()
|
||||
{
|
||||
if (!SupportsClear)
|
||||
throw new InvalidOperationException("This resolver does not support Clearing types");
|
||||
|
||||
using (new WriteLock(_lock))
|
||||
{
|
||||
InstanceTypes.Clear();
|
||||
@@ -247,11 +278,14 @@ namespace Umbraco.Core.ObjectResolution
|
||||
/// </summary>
|
||||
/// <param name="index">The zero-based index at which the object should be inserted.</param>
|
||||
/// <param name="value">The object to insert.</param>
|
||||
public virtual void InsertType(int index, Type value)
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
public void InsertType(int index, Type value)
|
||||
{
|
||||
if (!SupportsInsert)
|
||||
throw new InvalidOperationException("This resolver does not support Inserting new types");
|
||||
|
||||
using (var l = new UpgradeableReadLock(_lock))
|
||||
{
|
||||
EnsureCorrectType(value);
|
||||
if (InstanceTypes.Contains(value))
|
||||
{
|
||||
throw new InvalidOperationException("The Type " + value + " already exists in the collection");
|
||||
@@ -278,5 +312,24 @@ namespace Umbraco.Core.ObjectResolution
|
||||
throw new InvalidOperationException("The resolver " + this.GetType() + " can only accept types of " + typeof(TResolved) + ". The Type passed in to this method is " + t);
|
||||
}
|
||||
|
||||
protected virtual bool SupportsAdd
|
||||
{
|
||||
get { return _supportsAdd; }
|
||||
}
|
||||
|
||||
protected virtual bool SupportsInsert
|
||||
{
|
||||
get { return _supportsInsert; }
|
||||
}
|
||||
|
||||
protected virtual bool SupportsClear
|
||||
{
|
||||
get { return _supportsClear; }
|
||||
}
|
||||
|
||||
protected virtual bool SupportsRemove
|
||||
{
|
||||
get { return _supportsRemove; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,24 +30,24 @@ namespace Umbraco.Web
|
||||
get { return Values.OfType<IApplicationEventHandler>(); }
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
protected override bool SupportsClear
|
||||
{
|
||||
throw new NotSupportedException("This class does not support this method");
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override void AddType(Type value)
|
||||
protected override bool SupportsAdd
|
||||
{
|
||||
throw new NotSupportedException("This class does not support this method");
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override void InsertType(int index, Type value)
|
||||
protected override bool SupportsInsert
|
||||
{
|
||||
throw new NotSupportedException("This class does not support this method");
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override void RemoveType(Type value)
|
||||
protected override bool SupportsRemove
|
||||
{
|
||||
throw new NotSupportedException("This class does not support this method");
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -343,8 +343,15 @@ namespace umbraco.cms.businesslogic.packager
|
||||
template.Template masterTemplate = template.Template.GetByAlias(master);
|
||||
if (masterTemplate != null) {
|
||||
t.MasterTemplate = template.Template.GetByAlias(master).Id;
|
||||
if (UmbracoSettings.UseAspNetMasterPages)
|
||||
t.SaveMasterPageFile(t.Design);
|
||||
//SD: This appears to always just save an empty template because the design isn't set yet
|
||||
// this fixes an issue now that we have MVC because if there is an empty template and MVC is
|
||||
// the default, it will create a View not a master page and then the system will try to route via
|
||||
// MVC which means that the package will not work anymore.
|
||||
// The code below that imports the templates should suffice because it's actually importing
|
||||
// template data not just blank data.
|
||||
|
||||
//if (UmbracoSettings.UseAspNetMasterPages)
|
||||
// t.SaveMasterPageFile(t.Design);
|
||||
}
|
||||
}
|
||||
// Master templates can only be generated when their master is known
|
||||
|
||||
Reference in New Issue
Block a user