U4-9322 - wire EventMessages, cleanup

This commit is contained in:
Stephan
2017-01-31 18:19:03 +01:00
parent 97a76d5ad4
commit ac9b484d3d
5 changed files with 21 additions and 32 deletions
+8 -23
View File
@@ -14,8 +14,6 @@ namespace Umbraco.Core.Scoping
private bool _disposed;
private UmbracoDatabase _database;
private IEventDispatcher _eventDispatcher;
private EventMessages _messages;
public NoScope(ScopeProvider scopeProvider)
{
@@ -37,7 +35,7 @@ namespace Umbraco.Core.Scoping
}
/// <inheritdoc />
public IsolatedRuntimeCache IsolatedRuntimeCache { get { throw new NotImplementedException(); } }
public IsolatedRuntimeCache IsolatedRuntimeCache { get { throw new NotSupportedException(); } }
/// <inheritdoc />
public UmbracoDatabase Database
@@ -61,55 +59,42 @@ namespace Umbraco.Core.Scoping
/// <inheritdoc />
public EventMessages Messages
{
get
{
EnsureNotDisposed();
// fixme - should be a 'no scope event messages' of some sort
return _messages ?? (_messages = new EventMessages());
}
get { throw new NotSupportedException(); }
}
public EventMessages MessagesOrNull
{
get
{
EnsureNotDisposed();
return _messages;
}
get { throw new NotSupportedException(); }
}
/// <inheritdoc />
public IEventDispatcher Events
{
get
{
EnsureNotDisposed();
return _eventDispatcher ?? (_eventDispatcher = new PassThroughEventDispatcher());
}
get { throw new NotSupportedException(); }
}
/// <inheritdoc />
public void Complete()
{
throw new NotImplementedException();
throw new NotSupportedException();
}
/// <inheritdoc />
public T Enlist<T>(string key, Func<T> creator)
{
throw new NotImplementedException();
throw new NotSupportedException();
}
/// <inheritdoc />
public T Enlist<T>(string key, Func<T> creator, ActionTime actionTimes, Action<ActionTime, bool, T> action)
{
throw new NotImplementedException();
throw new NotSupportedException();
}
/// <inheritdoc />
public void Enlist(string key, ActionTime actionTimes, Action<ActionTime, bool> action)
{
throw new NotImplementedException();
throw new NotSupportedException();
}
private void EnsureNotDisposed()
+5 -2
View File
@@ -78,7 +78,6 @@ namespace Umbraco.Core.Scoping
{
// steal everything from NoScope
_database = noScope.DatabaseOrNull;
_messages = noScope.MessagesOrNull;
// make sure the NoScope can be replaced ie not in a transaction
if (_database != null && _database.InTransaction)
@@ -203,7 +202,11 @@ namespace Umbraco.Core.Scoping
{
EnsureNotDisposed();
if (ParentScope != null) return ParentScope.Messages;
return _messages ?? (_messages = new EventMessages());
//return _messages ?? (_messages = new EventMessages());
// ok, this isn't pretty, but it works
// TODO kill the message factory and let the scope manage it all
return ApplicationContext.Current.Services.EventMessagesFactory.Get();
}
}
@@ -8,6 +8,7 @@ using Umbraco.Core.Scoping;
namespace Umbraco.Tests.Scoping
{
[TestFixture]
[NUnit.Framework.Ignore("Cannot dispatch events on NoScope!")]
public class PassThroughEventDispatcherTests
{
[Test]
@@ -94,7 +94,7 @@ namespace Umbraco.Tests.Scoping
[TestCase(true)]
[TestCase(false)]
public void TriggerEvents(bool complete)
public void EventsDispatchmode_PassThrough(bool complete)
{
var counter = 0;
@@ -125,7 +125,7 @@ namespace Umbraco.Tests.Scoping
[TestCase(true)]
[TestCase(false)]
public void QueueAndDiscardEvents(bool complete)
public void EventsDispatchMode_Passive(bool complete)
{
DoThing1 += OnDoThingFail;
DoThing2 += OnDoThingFail;
@@ -150,7 +150,7 @@ namespace Umbraco.Tests.Scoping
[TestCase(true)]
[TestCase(false)]
public void QueueAndRaiseEvents(bool complete)
public void EventsDispatchMode_Scope(bool complete)
{
var counter = 0;
IScope ambientScope = null;
+4 -4
View File
@@ -363,7 +363,7 @@ namespace umbraco.DataLayer
//private static MethodInfo CloseMethod { get; set; }
private static readonly object ScopeProvider;
private static readonly PropertyInfo ScopeProviderAmbientOrNoScopeProperty;
private static readonly MethodInfo ScopeProviderAmbientOrNoScopeMethod;
private static readonly PropertyInfo ScopeDatabaseProperty;
private static readonly PropertyInfo ConnectionProperty;
private static readonly FieldInfo TransactionField;
@@ -396,8 +396,8 @@ namespace umbraco.DataLayer
if (databaseContextScopeProviderField == null) throw new Exception("oops: databaseContextScopeProviderField.");
ScopeProvider = databaseContextScopeProviderField.GetValue(databaseContext);
ScopeProviderAmbientOrNoScopeProperty = scopeProviderType.GetProperty("AmbientOrNoScope", BindingFlags.Instance | BindingFlags.Public);
if (ScopeProviderAmbientOrNoScopeProperty == null) throw new Exception("oops: ScopeProviderAmbientOrNoScopeProperty.");
ScopeProviderAmbientOrNoScopeMethod = scopeProviderType.GetMethod("GetAmbientOrNoScope", BindingFlags.Instance | BindingFlags.Public);
if (ScopeProviderAmbientOrNoScopeMethod == null) throw new Exception("oops: ScopeProviderAmbientOrNoScopeMethod.");
ScopeDatabaseProperty = scopeType.GetProperty("Database", BindingFlags.Instance | BindingFlags.Public);
if (ScopeDatabaseProperty == null) throw new Exception("oops: ScopeDatabaseProperty.");
@@ -416,7 +416,7 @@ namespace umbraco.DataLayer
public CurrentConnectionUsing()
{
var scope = ScopeProviderAmbientOrNoScopeProperty.GetValue(ScopeProvider);
var scope = ScopeProviderAmbientOrNoScopeMethod.Invoke(ScopeProvider, NoArgs);
_database = ScopeDatabaseProperty.GetValue(scope);
var connection = ConnectionProperty.GetValue(_database, NoArgs);