Merge branch 'v8/dev' into v8/contrib

This commit is contained in:
Sebastiaan Janssen
2021-03-31 13:01:25 +02:00
28 changed files with 961 additions and 305 deletions

View File

@@ -18,5 +18,5 @@ using System.Resources;
[assembly: AssemblyVersion("8.0.0")]
// these are FYI and changed automatically
[assembly: AssemblyFileVersion("8.12.1")]
[assembly: AssemblyInformationalVersion("8.12.1")]
[assembly: AssemblyFileVersion("8.12.2")]
[assembly: AssemblyInformationalVersion("8.12.2")]

View File

@@ -1,10 +1,10 @@
using System.IO;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Configuration.Grid;
using Umbraco.Core.Configuration.HealthChecks;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Dashboards;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
@@ -48,6 +48,8 @@ namespace Umbraco.Core
configDir,
factory.GetInstance<ManifestParser>(),
factory.GetInstance<IRuntimeState>().Debug));
configs.Add<IContentDashboardSettings>(() => new ContentDashboardSettings());
}
}
}

View File

@@ -395,7 +395,6 @@ namespace Umbraco.Core.Configuration
}
}
/// <summary>
/// An int value representing the time in milliseconds to lock the database for a write operation
/// </summary>

View File

@@ -110,6 +110,11 @@ namespace Umbraco.Core
/// </summary>
public const string UseHttps = "Umbraco.Core.UseHttps";
/// <summary>
/// A true/false value indicating whether the content dashboard should be visible for all user groups.
/// </summary>
public const string AllowContentDashboardAccessToAllUsers = "Umbraco.Core.AllowContentDashboardAccessToAllUsers";
/// <summary>
/// TODO: FILL ME IN
/// </summary>

View File

@@ -0,0 +1,24 @@
using System.Configuration;
namespace Umbraco.Core.Dashboards
{
public class ContentDashboardSettings: IContentDashboardSettings
{
/// <summary>
/// Gets a value indicating whether the content dashboard should be available to all users.
/// </summary>
/// <value>
/// <c>true</c> if the dashboard is visible for all user groups; otherwise, <c>false</c>
/// and the default access rules for that dashboard will be in use.
/// </value>
public bool AllowContentDashboardAccessToAllUsers
{
get
{
bool.TryParse(ConfigurationManager.AppSettings[Constants.AppSettings.AllowContentDashboardAccessToAllUsers], out var value);
return value;
}
}
}
}

View File

@@ -0,0 +1,14 @@
namespace Umbraco.Core.Dashboards
{
public interface IContentDashboardSettings
{
/// <summary>
/// Gets a value indicating whether the content dashboard should be available to all users.
/// </summary>
/// <value>
/// <c>true</c> if the dashboard is visible for all user groups; otherwise, <c>false</c>
/// and the default access rules for that dashboard will be in use.
/// </value>
bool AllowContentDashboardAccessToAllUsers { get; }
}
}

View File

@@ -179,7 +179,14 @@ namespace Umbraco.Core.Runtime
_listenTask = _mainDomLock.ListenAsync();
_listenCompleteTask = _listenTask.ContinueWith(t =>
{
_logger.Debug<MainDom>("Listening task completed with {TaskStatus}", _listenTask.Status);
if (_listenTask.Exception != null)
{
_logger.Warn<MainDom>("Listening task completed with {TaskStatus}, Exception: {Exception}", _listenTask.Status, _listenTask.Exception);
}
else
{
_logger.Debug<MainDom>("Listening task completed with {TaskStatus}", _listenTask.Status);
}
OnSignal("signal");
}, TaskScheduler.Default); // Must explicitly specify this, see https://blog.stephencleary.com/2013/10/continuewith-is-dangerous-too.html

View File

@@ -86,7 +86,7 @@ namespace Umbraco.Core.Runtime
// wait to get a write lock
_sqlServerSyntax.WriteLock(db, TimeSpan.FromMilliseconds(millisecondsTimeout), Constants.Locks.MainDom);
}
catch(SqlException ex)
catch (SqlException ex)
{
if (IsLockTimeoutException(ex))
{
@@ -126,7 +126,7 @@ namespace Umbraco.Core.Runtime
}
return await WaitForExistingAsync(tempId, millisecondsTimeout);
return await WaitForExistingAsync(tempId, millisecondsTimeout).ConfigureAwait(false);
}
public Task ListenAsync()
@@ -139,13 +139,15 @@ namespace Umbraco.Core.Runtime
// Create a long running task (dedicated thread)
// to poll to check if we are still the MainDom registered in the DB
return Task.Factory.StartNew(
ListeningLoop,
_cancellationTokenSource.Token,
TaskCreationOptions.LongRunning,
// Must explicitly specify this, see https://blog.stephencleary.com/2013/10/continuewith-is-dangerous-too.html
TaskScheduler.Default);
using (ExecutionContext.SuppressFlow())
{
return Task.Factory.StartNew(
ListeningLoop,
_cancellationTokenSource.Token,
TaskCreationOptions.LongRunning,
// Must explicitly specify this, see https://blog.stephencleary.com/2013/10/continuewith-is-dangerous-too.html
TaskScheduler.Default);
}
}
/// <summary>
@@ -227,11 +229,29 @@ namespace Umbraco.Core.Runtime
}
finally
{
db?.CompleteTransaction();
db?.Dispose();
// Even if any of the above fail like BeginTransaction, or even a query after the
// Transaction is started, the calls below will not throw. I've tried all sorts of
// combinations to see if I can make this throw but I can't. In any case, we'll be
// extra safe and try/catch/log
try
{
db?.CompleteTransaction();
}
catch (Exception ex)
{
_logger.Error<SqlMainDomLock>(ex, "Unexpected error completing transaction.");
}
try
{
db?.Dispose();
}
catch (Exception ex)
{
_logger.Error<SqlMainDomLock>(ex, "Unexpected error completing disposing.");
}
}
}
}
}
@@ -245,37 +265,40 @@ namespace Umbraco.Core.Runtime
{
var updatedTempId = tempId + UpdatedSuffix;
return Task.Run(() =>
using (ExecutionContext.SuppressFlow())
{
try
return Task.Run(() =>
{
using var db = _dbFactory.CreateDatabase();
var watch = new Stopwatch();
watch.Start();
while (true)
try
{
// poll very often, we need to take over as fast as we can
// local testing shows the actual query to be executed from client/server is approx 300ms but would change depending on environment/IO
Thread.Sleep(1000);
using var db = _dbFactory.CreateDatabase();
var acquired = TryAcquire(db, tempId, updatedTempId);
if (acquired.HasValue)
return acquired.Value;
if (watch.ElapsedMilliseconds >= millisecondsTimeout)
var watch = new Stopwatch();
watch.Start();
while (true)
{
return AcquireWhenMaxWaitTimeElapsed(db);
// poll very often, we need to take over as fast as we can
// local testing shows the actual query to be executed from client/server is approx 300ms but would change depending on environment/IO
Thread.Sleep(1000);
var acquired = TryAcquire(db, tempId, updatedTempId);
if (acquired.HasValue)
return acquired.Value;
if (watch.ElapsedMilliseconds >= millisecondsTimeout)
{
return AcquireWhenMaxWaitTimeElapsed(db);
}
}
}
}
catch (Exception ex)
{
_logger.Error<SqlMainDomLock>(ex, "An error occurred trying to acquire and waiting for existing SqlMainDomLock to shutdown");
return false;
}
catch (Exception ex)
{
_logger.Error<SqlMainDomLock>(ex, "An error occurred trying to acquire and waiting for existing SqlMainDomLock to shutdown");
return false;
}
}, _cancellationTokenSource.Token);
}, _cancellationTokenSource.Token);
}
}
private bool? TryAcquire(IUmbracoDatabase db, string tempId, string updatedTempId)

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Events;
@@ -36,11 +37,10 @@ namespace Umbraco.Core.Scoping
private IEventDispatcher _eventDispatcher;
private object _dictionaryLocker;
// ReadLocks and WriteLocks if we're the outer most scope it's those owned by the entire chain
// If we're a child scope it's those that we have requested.
internal readonly Dictionary<int, int> ReadLocks;
internal readonly Dictionary<int, int> WriteLocks;
private HashSet<int> _readLocks;
private HashSet<int> _writeLocks;
internal Dictionary<Guid, Dictionary<int, int>> ReadLocks;
internal Dictionary<Guid, Dictionary<int, int>> WriteLocks;
// initializes a new scope
private Scope(ScopeProvider scopeProvider,
@@ -67,8 +67,6 @@ namespace Umbraco.Core.Scoping
Detachable = detachable;
_dictionaryLocker = new object();
ReadLocks = new Dictionary<int, int>();
WriteLocks = new Dictionary<int, int>();
#if DEBUG_SCOPES
_scopeProvider.RegisterScope(this);
@@ -345,6 +343,8 @@ namespace Umbraco.Core.Scoping
if (this != _scopeProvider.AmbientScope)
{
var failedMessage = $"The {nameof(Scope)} {this.InstanceId} being disposed is not the Ambient {nameof(Scope)} {(_scopeProvider.AmbientScope?.InstanceId.ToString() ?? "NULL")}. This typically indicates that a child {nameof(Scope)} was not disposed, or flowed to a child thread that was not awaited, or concurrent threads are accessing the same {nameof(Scope)} (Ambient context) which is not supported. If using Task.Run (or similar) as a fire and forget tasks or to run threads in parallel you must suppress execution context flow with ExecutionContext.SuppressFlow() and ExecutionContext.RestoreFlow().";
#if DEBUG_SCOPES
var ambient = _scopeProvider.AmbientScope;
_logger.Debug<Scope>("Dispose error (" + (ambient == null ? "no" : "other") + " ambient)");
@@ -356,24 +356,21 @@ namespace Umbraco.Core.Scoping
+ "- ambient ctor ->\r\n" + ambientInfos.CtorStack + "\r\n"
+ "- dispose ctor ->\r\n" + disposeInfos.CtorStack + "\r\n");
#else
throw new InvalidOperationException("Not the ambient scope.");
throw new InvalidOperationException(failedMessage);
#endif
}
// Decrement the lock counters on the parent if any.
if (ParentScope != null)
ClearLocks(InstanceId);
if (ParentScope is null)
{
lock (_dictionaryLocker)
// We're the parent scope, make sure that locks of all scopes has been cleared
// Since we're only reading we don't have to be in a lock
if (ReadLocks?.Count > 0 || WriteLocks?.Count > 0)
{
foreach (var readLockPair in ReadLocks)
{
DecrementReadLock(readLockPair.Key, readLockPair.Value);
}
foreach (var writeLockPair in WriteLocks)
{
DecrementWriteLock(writeLockPair.Key, writeLockPair.Value);
}
var exception = new InvalidOperationException($"All scopes has not been disposed from parent scope: {InstanceId}, see log for more details.");
_logger.Error<Scope>(exception, GenerateUnclearedScopesLogMessage());
throw exception;
}
}
@@ -396,6 +393,42 @@ namespace Umbraco.Core.Scoping
GC.SuppressFinalize(this);
}
/// <summary>
/// Generates a log message with all scopes that hasn't cleared their locks, including how many, and what locks they have requested.
/// </summary>
/// <returns>Log message.</returns>
private string GenerateUnclearedScopesLogMessage()
{
// Dump the dicts into a message for the locks.
StringBuilder builder = new StringBuilder();
builder.AppendLine($"Lock counters aren't empty, suggesting a scope hasn't been properly disposed, parent id: {InstanceId}");
WriteLockDictionaryToString(ReadLocks, builder, "read locks");
WriteLockDictionaryToString(WriteLocks, builder, "write locks");
return builder.ToString();
}
/// <summary>
/// Writes a locks dictionary to a <see cref="StringBuilder"/> for logging purposes.
/// </summary>
/// <param name="dict">Lock dictionary to report on.</param>
/// <param name="builder">String builder to write to.</param>
/// <param name="dictName">The name to report the dictionary as.</param>
private void WriteLockDictionaryToString(Dictionary<Guid, Dictionary<int, int>> dict, StringBuilder builder, string dictName)
{
if (dict?.Count > 0)
{
builder.AppendLine($"Remaining {dictName}:");
foreach (var instance in dict)
{
builder.AppendLine($"Scope {instance.Key}");
foreach (var lockCounter in instance.Value)
{
builder.AppendLine($"\tLock ID: {lockCounter.Key} - times requested: {lockCounter.Value}");
}
}
}
}
private void DisposeLastScope()
{
// figure out completed
@@ -516,207 +549,157 @@ namespace Umbraco.Core.Scoping
?? (_logUncompletedScopes = Current.Configs.CoreDebug().LogUncompletedScopes)).Value;
/// <summary>
/// Decrements the count of the ReadLocks with a specific lock object identifier we currently hold
/// Increment the counter of a locks dictionary, either ReadLocks or WriteLocks,
/// for a specific scope instance and lock identifier. Must be called within a lock.
/// </summary>
/// <param name="lockId">Lock object identifier to decrement</param>
/// <param name="amountToDecrement">Amount to decrement the lock count with</param>
public void DecrementReadLock(int lockId, int amountToDecrement)
/// <param name="lockId">Lock ID to increment.</param>
/// <param name="instanceId">Instance ID of the scope requesting the lock.</param>
/// <param name="locks">Reference to the dictionary to increment on</param>
private void IncrementLock(int lockId, Guid instanceId, ref Dictionary<Guid, Dictionary<int, int>> locks)
{
// If we aren't the outermost scope, pass it on to the parent.
if (ParentScope != null)
{
ParentScope.DecrementReadLock(lockId, amountToDecrement);
return;
}
// Since we've already checked that we're the parent in the WriteLockInner method, we don't need to check again.
// If it's the very first time a lock has been requested the WriteLocks dict hasn't been instantiated yet.
locks ??= new Dictionary<Guid, Dictionary<int, int>>();
lock (_dictionaryLocker)
// Try and get the dict associated with the scope id.
var locksDictFound = locks.TryGetValue(instanceId, out var locksDict);
if (locksDictFound)
{
ReadLocks[lockId] -= amountToDecrement;
locksDict.TryGetValue(lockId, out var value);
locksDict[lockId] = value + 1;
}
else
{
// The scope hasn't requested a lock yet, so we have to create a dict for it.
locks.Add(instanceId, new Dictionary<int, int>());
locks[instanceId][lockId] = 1;
}
}
/// <summary>
/// Decrements the count of the WriteLocks with a specific lock object identifier we currently hold.
/// Clears all lock counters for a given scope instance, signalling that the scope has been disposed.
/// </summary>
/// <param name="lockId">Lock object identifier to decrement.</param>
/// <param name="amountToDecrement">Amount to decrement the lock count with</param>
public void DecrementWriteLock(int lockId, int amountToDecrement)
/// <param name="instanceId">Instance ID of the scope to clear.</param>
private void ClearLocks(Guid instanceId)
{
// If we aren't the outermost scope, pass it on to the parent.
if (ParentScope != null)
if (ParentScope is not null)
{
ParentScope.DecrementWriteLock(lockId, amountToDecrement);
return;
ParentScope.ClearLocks(instanceId);
}
lock (_dictionaryLocker)
else
{
WriteLocks[lockId] -= amountToDecrement;
}
}
/// <summary>
/// Increment the count of the read locks we've requested
/// </summary>
/// <remarks>
/// This should only be done on child scopes since it's then used to decrement the count later.
/// </remarks>
/// <param name="lockIds"></param>
private void IncrementRequestedReadLock(params int[] lockIds)
{
// We need to keep track of what lockIds we have requested locks for to be able to decrement them.
if (ParentScope != null)
{
foreach (var lockId in lockIds)
lock (_dictionaryLocker)
{
lock (_dictionaryLocker)
{
if (ReadLocks.ContainsKey(lockId))
{
ReadLocks[lockId] += 1;
}
else
{
ReadLocks[lockId] = 1;
}
}
}
}
}
/// <summary>
/// Increment the count of the write locks we've requested
/// </summary>
/// <remarks>
/// This should only be done on child scopes since it's then used to decrement the count later.
/// </remarks>
/// <param name="lockIds"></param>
private void IncrementRequestedWriteLock(params int[] lockIds)
{
// We need to keep track of what lockIds we have requested locks for to be able to decrement them.
if (ParentScope != null)
{
foreach (var lockId in lockIds)
{
lock (_dictionaryLocker)
{
if (WriteLocks.ContainsKey(lockId))
{
WriteLocks[lockId] += 1;
}
else
{
WriteLocks[lockId] = 1;
}
}
ReadLocks?.Remove(instanceId);
WriteLocks?.Remove(instanceId);
}
}
}
/// <inheritdoc />
public void ReadLock(params int[] lockIds)
{
IncrementRequestedReadLock(lockIds);
ReadLockInner(null, lockIds);
}
public void ReadLock(params int[] lockIds) => ReadLockInner(InstanceId, null, lockIds);
/// <inheritdoc />
public void ReadLock(TimeSpan timeout, int lockId)
{
IncrementRequestedReadLock(lockId);
ReadLockInner(timeout, lockId);
}
public void ReadLock(TimeSpan timeout, int lockId) => ReadLockInner(InstanceId, timeout, lockId);
/// <inheritdoc />
public void WriteLock(params int[] lockIds)
{
IncrementRequestedWriteLock(lockIds);
WriteLockInner(null, lockIds);
}
public void WriteLock(params int[] lockIds) => WriteLockInner(InstanceId, null, lockIds);
/// <inheritdoc />
public void WriteLock(TimeSpan timeout, int lockId)
{
IncrementRequestedWriteLock(lockId);
WriteLockInner(timeout, lockId);
}
public void WriteLock(TimeSpan timeout, int lockId) => WriteLockInner(InstanceId, timeout, lockId);
/// <summary>
/// Handles acquiring a read lock, will delegate it to the parent if there are any.
/// </summary>
/// <param name="instanceId">Instance ID of the requesting scope.</param>
/// <param name="timeout">Optional database timeout in milliseconds.</param>
/// <param name="lockIds">Array of lock object identifiers.</param>
internal void ReadLockInner(TimeSpan? timeout = null, params int[] lockIds)
private void ReadLockInner(Guid instanceId, TimeSpan? timeout = null, params int[] lockIds)
{
if (ParentScope != null)
if (ParentScope is not null)
{
// Delegate acquiring the lock to the parent if any.
ParentScope.ReadLockInner(timeout, lockIds);
return;
// If we have a parent we delegate lock creation to parent.
ParentScope.ReadLockInner(instanceId, timeout, lockIds);
}
// If we are the parent, then handle the lock request.
foreach (var lockId in lockIds)
else
{
lock (_dictionaryLocker)
{
// Only acquire the lock if we haven't done so yet.
if (!ReadLocks.ContainsKey(lockId))
{
if (timeout is null)
{
// We want a lock with a custom timeout
ObtainReadLock(lockId);
}
else
{
// We just want an ordinary lock.
ObtainTimoutReadLock(lockId, timeout.Value);
}
// Add the lockId as a key to the dict.
ReadLocks[lockId] = 0;
}
ReadLocks[lockId] += 1;
}
// We are the outermost scope, handle the lock request.
LockInner(instanceId, ref ReadLocks, ref _readLocks, ObtainReadLock, ObtainTimeoutReadLock, timeout, lockIds);
}
}
/// <summary>
/// Handles acquiring a write lock with a specified timeout, will delegate it to the parent if there are any.
/// </summary>
/// <param name="instanceId">Instance ID of the requesting scope.</param>
/// <param name="timeout">Optional database timeout in milliseconds.</param>
/// <param name="lockIds">Array of lock object identifiers.</param>
internal void WriteLockInner(TimeSpan? timeout = null, params int[] lockIds)
private void WriteLockInner(Guid instanceId, TimeSpan? timeout = null, params int[] lockIds)
{
if (ParentScope != null)
if (ParentScope is not null)
{
// If we have a parent we delegate lock creation to parent.
ParentScope.WriteLockInner(timeout, lockIds);
return;
ParentScope.WriteLockInner(instanceId, timeout, lockIds);
}
foreach (var lockId in lockIds)
else
{
lock (_dictionaryLocker)
{
// Only acquire lock if we haven't yet (WriteLocks not containing the key)
if (!WriteLocks.ContainsKey(lockId))
{
if (timeout is null)
{
ObtainWriteLock(lockId);
}
else
{
ObtainTimeoutWriteLock(lockId, timeout.Value);
}
// Add the lockId as a key to the dict.
WriteLocks[lockId] = 0;
}
// We are the outermost scope, handle the lock request.
LockInner(instanceId, ref WriteLocks, ref _writeLocks, ObtainWriteLock, ObtainTimeoutWriteLock, timeout, lockIds);
}
}
// Increment count of the lock by 1.
WriteLocks[lockId] += 1;
/// <summary>
/// Handles acquiring a lock, this should only be called from the outermost scope.
/// </summary>
/// <param name="instanceId">Instance ID of the scope requesting the lock.</param>
/// <param name="locks">Reference to the applicable locks dictionary (ReadLocks or WriteLocks).</param>
/// <param name="locksSet">Reference to the applicable locks hashset (_readLocks or _writeLocks).</param>
/// <param name="obtainLock">Delegate used to request the lock from the database without a timeout.</param>
/// <param name="obtainLockTimeout">Delegate used to request the lock from the database with a timeout.</param>
/// <param name="timeout">Optional timeout parameter to specify a timeout.</param>
/// <param name="lockIds">Lock identifiers to lock on.</param>
private void LockInner(Guid instanceId, ref Dictionary<Guid, Dictionary<int, int>> locks, ref HashSet<int> locksSet,
Action<int> obtainLock, Action<int, TimeSpan> obtainLockTimeout, TimeSpan? timeout = null,
params int[] lockIds)
{
lock (_dictionaryLocker)
{
locksSet ??= new HashSet<int>();
foreach (var lockId in lockIds)
{
// Only acquire the lock if we haven't done so yet.
if (!locksSet.Contains(lockId))
{
IncrementLock(lockId, instanceId, ref locks);
locksSet.Add(lockId);
try
{
if (timeout is null)
{
// We just want an ordinary lock.
obtainLock(lockId);
}
else
{
// We want a lock with a custom timeout
obtainLockTimeout(lockId, timeout.Value);
}
}
catch
{
// Something went wrong and we didn't get the lock
// Since we at this point have determined that we haven't got any lock with an ID of LockID, it's safe to completely remove it instead of decrementing.
locks[instanceId].Remove(lockId);
// It needs to be removed from the HashSet as well, because that's how we determine to acquire a lock.
locksSet.Remove(lockId);
throw;
}
}
else
{
// We already have a lock, but need to update the dictionary for debugging purposes.
IncrementLock(lockId, instanceId, ref locks);
}
}
}
}
@@ -735,10 +718,10 @@ namespace Umbraco.Core.Scoping
/// </summary>
/// <param name="lockId">Lock object identifier to lock.</param>
/// <param name="timeout">TimeSpan specifying the timout period.</param>
private void ObtainTimoutReadLock(int lockId, TimeSpan timeout)
private void ObtainTimeoutReadLock(int lockId, TimeSpan timeout)
{
var syntax2 = Database.SqlContext.SqlSyntax as ISqlSyntaxProvider2;
if (syntax2 == null)
if (syntax2 is null)
{
throw new InvalidOperationException($"{Database.SqlContext.SqlSyntax.GetType()} is not of type {typeof(ISqlSyntaxProvider2)}");
}
@@ -763,7 +746,7 @@ namespace Umbraco.Core.Scoping
private void ObtainTimeoutWriteLock(int lockId, TimeSpan timeout)
{
var syntax2 = Database.SqlContext.SqlSyntax as ISqlSyntaxProvider2;
if (syntax2 == null)
if (syntax2 is null)
{
throw new InvalidOperationException($"{Database.SqlContext.SqlSyntax.GetType()} is not of type {typeof(ISqlSyntaxProvider2)}");
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Runtime.Remoting.Messaging;
using System.Web;
@@ -240,6 +241,9 @@ namespace Umbraco.Core.Scoping
var value = GetHttpContextObject<ScopeContext>(ContextItemKey, false);
return value ?? GetCallContextObject<ScopeContext>(ContextItemKey);
}
[Obsolete("This setter is not used and will be removed in future versions")]
[EditorBrowsable(EditorBrowsableState.Never)]
set
{
// clear both

View File

@@ -133,6 +133,8 @@
<Compile Include="Constants-SqlTemplates.cs" />
<Compile Include="Logging\ILogger2.cs" />
<Compile Include="Logging\Logger2Extensions.cs" />
<Compile Include="Dashboards\ContentDashboardSettings.cs" />
<Compile Include="Dashboards\IContentDashboardSettings.cs" />
<Compile Include="Exceptions\UnattendedInstallException.cs" />
<Compile Include="Migrations\Upgrade\V_8_0_0\Models\ContentTypeDto80.cs" />
<Compile Include="Migrations\Upgrade\V_8_0_0\Models\PropertyDataDto80.cs" />

View File

@@ -24,8 +24,8 @@ namespace Umbraco.Examine
// note
// wrapping all operations that end up calling base.SafelyProcessQueueItems in a safe call
// context because they will fork a thread/task/whatever which should *not* capture our
// call context (and the database it can contain)! ideally we should be able to override
// SafelyProcessQueueItems but that's not possible in the current version of Examine.
// call context (and the database it can contain)!
// TODO: FIX Examine to not flow the ExecutionContext so callers don't need to worry about this!
/// <summary>
/// Used to store the path of a content object
@@ -99,6 +99,9 @@ namespace Umbraco.Examine
{
if (CanInitialize())
{
// Use SafeCallContext to prevent the current CallContext flow to child
// tasks executed in the base class so we don't leak Scopes.
// TODO: See notes at the top of this class
using (new SafeCallContext())
{
base.PerformDeleteFromIndex(itemIds, onComplete);
@@ -106,6 +109,20 @@ namespace Umbraco.Examine
}
}
protected override void PerformIndexItems(IEnumerable<ValueSet> values, Action<IndexOperationEventArgs> onComplete)
{
if (CanInitialize())
{
// Use SafeCallContext to prevent the current CallContext flow to child
// tasks executed in the base class so we don't leak Scopes.
// TODO: See notes at the top of this class
using (new SafeCallContext())
{
base.PerformIndexItems(values, onComplete);
}
}
}
/// <summary>
/// Returns true if the Umbraco application is in a state that we can initialize the examine indexes
/// </summary>

View File

@@ -1,5 +1,13 @@
/// <reference types="Cypress" />
import { DocumentTypeBuilder, ContentBuilder, AliasHelper } from 'umbraco-cypress-testhelpers';
import {
DocumentTypeBuilder,
ContentBuilder,
AliasHelper,
GridDataTypeBuilder,
PartialViewMacroBuilder,
MacroBuilder
} from 'umbraco-cypress-testhelpers';
context('Content', () => {
beforeEach(() => {
@@ -14,6 +22,23 @@ context('Content', () => {
cy.get('.umb-tree-item__inner').should('exist', {timeout: 10000});
}
function createSimpleMacro(name){
const insertMacro = new PartialViewMacroBuilder()
.withName(name)
.withContent(`@inherits Umbraco.Web.Macros.PartialViewMacroPage
<h1>Acceptance test</h1>`)
.build();
const macroWithPartial = new MacroBuilder()
.withName(name)
.withPartialViewMacro(insertMacro)
.withRenderInEditor()
.withUseInEditor()
.build();
cy.saveMacroWithPartial(macroWithPartial);
}
it('Copy content', () => {
const rootDocTypeName = "Test document type";
const childDocTypeName = "Child test document type";
@@ -596,4 +621,181 @@ context('Content', () => {
cy.umbracoEnsureTemplateNameNotExists(pickerDocTypeName);
cy.umbracoEnsureDocumentTypeNameNotExists(pickedDocTypeName);
});
it('Content with macro in RTE', () => {
const viewMacroName = 'Content with macro in RTE';
const partialFileName = viewMacroName + '.cshtml';
cy.umbracoEnsureMacroNameNotExists(viewMacroName);
cy.umbracoEnsurePartialViewMacroFileNameNotExists(partialFileName);
cy.umbracoEnsureDocumentTypeNameNotExists(viewMacroName);
cy.umbracoEnsureTemplateNameNotExists(viewMacroName);
cy.deleteAllContent();
// First thing first we got to create the macro we will be inserting
createSimpleMacro(viewMacroName);
// Now we need to create a document type with a rich text editor where we can insert the macro
// The document type must have a template as well in order to ensure that the content is displayed correctly
const alias = AliasHelper.toAlias(viewMacroName);
const docType = new DocumentTypeBuilder()
.withName(viewMacroName)
.withAlias(alias)
.withAllowAsRoot(true)
.withDefaultTemplate(alias)
.addGroup()
.addRichTextProperty()
.withAlias('text')
.done()
.done()
.build();
cy.saveDocumentType(docType).then((generatedDocType) => {
// Might as wel initally create the content here, the less GUI work during the test the better
const contentNode = new ContentBuilder()
.withContentTypeAlias(generatedDocType["alias"])
.withAction('saveNew')
.addVariant()
.withName(viewMacroName)
.withSave(true)
.done()
.build();
cy.saveContent(contentNode);
});
// Edit the macro template in order to have something to verify on when rendered.
cy.editTemplate(viewMacroName, `@inherits Umbraco.Web.Mvc.UmbracoViewPage
@using ContentModels = Umbraco.Web.PublishedModels;
@{
Layout = null;
}
@{
if (Model.HasValue("text")){
@(Model.Value("text"))
}
} `);
// Enter content
refreshContentTree();
cy.umbracoTreeItem("content", [viewMacroName]).click();
// Insert macro
cy.get('#mceu_13-button').click();
cy.get('.umb-card-grid-item').contains(viewMacroName).click();
// Save and publish
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click();
cy.umbracoSuccessNotification().should('be.visible');
// Ensure that the view gets rendered correctly
const expected = `<h1>Acceptance test</h1><p> </p>`;
cy.umbracoVerifyRenderedViewContent('/', expected, true).should('be.true');
// Cleanup
cy.umbracoEnsureMacroNameNotExists(viewMacroName);
cy.umbracoEnsurePartialViewMacroFileNameNotExists(partialFileName);
cy.umbracoEnsureDocumentTypeNameNotExists(viewMacroName);
cy.umbracoEnsureTemplateNameNotExists(viewMacroName);
});
it('Content with macro in grid', () => {
const name = 'Content with macro in grid';
const macroName = 'Grid macro';
const macroFileName = macroName + '.cshtml';
cy.umbracoEnsureDataTypeNameNotExists(name);
cy.umbracoEnsureDocumentTypeNameNotExists(name);
cy.umbracoEnsureTemplateNameNotExists(name);
cy.umbracoEnsureMacroNameNotExists(macroName);
cy.umbracoEnsurePartialViewMacroFileNameNotExists(macroFileName);
cy.deleteAllContent();
createSimpleMacro(macroName);
const grid = new GridDataTypeBuilder()
.withName(name)
.withDefaultGrid()
.build();
const alias = AliasHelper.toAlias(name);
// Save grid and get the ID
cy.saveDataType(grid).then((dataType) => {
// Create a document type using the data type
const docType = new DocumentTypeBuilder()
.withName(name)
.withAlias(alias)
.withAllowAsRoot(true)
.withDefaultTemplate(alias)
.addGroup()
.addCustomProperty(dataType['id'])
.withAlias('grid')
.done()
.done()
.build();
cy.saveDocumentType(docType).then((generatedDocType) => {
const contentNode = new ContentBuilder()
.withContentTypeAlias(generatedDocType["alias"])
.addVariant()
.withName(name)
.withSave(true)
.done()
.build();
cy.saveContent(contentNode);
});
});
// Edit the template to allow us to verify the rendered view
cy.editTemplate(name, `@inherits Umbraco.Web.Mvc.UmbracoViewPage
@using ContentModels = Umbraco.Web.PublishedModels;
@{
Layout = null;
}
@Html.GetGridHtml(Model, "grid")`);
// Act
// Enter content
refreshContentTree();
cy.umbracoTreeItem("content", [name]).click();
// Click add
cy.get(':nth-child(2) > .preview-row > .preview-col > .preview-cell').click(); // Choose 1 column layout.
cy.get('.umb-column > .templates-preview > :nth-child(2) > .ng-binding').click(); // Choose headline
cy.get('.umb-cell-placeholder').click();
// Click macro
cy.get(':nth-child(4) > .umb-card-grid-item > :nth-child(1)').click();
// Select the macro
cy.get('.umb-card-grid-item').contains(macroName).click();
// Save and publish
cy.umbracoButtonByLabelKey('buttons_saveAndPublish').click();
cy.umbracoSuccessNotification().should('be.visible');
const expected = `
<div class="umb-grid">
<div class="grid-section">
<div>
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<div>
<h1>Acceptance test</h1>
</div>
</div>
</div>
</div>
</div>
</div>
</div>`
cy.umbracoVerifyRenderedViewContent('/', expected, true).should('be.true');
// Clean
cy.umbracoEnsureDataTypeNameNotExists(name);
cy.umbracoEnsureDocumentTypeNameNotExists(name);
cy.umbracoEnsureTemplateNameNotExists(name);
cy.umbracoEnsureMacroNameNotExists(macroName);
cy.umbracoEnsurePartialViewMacroFileNameNotExists(macroFileName);
});
});

View File

@@ -6,7 +6,10 @@ context('Languages', () => {
});
it('Add language', () => {
const name = "Kyrgyz (Kyrgyzstan)"; // Must be an option in the select box
// For some reason the languages to chose fom seems to be translated differently than normal, as an example:
// My system is set to EN (US), but most languages are translated into Danish for some reason
// Aghem seems untranslated though?
const name = "Aghem"; // Must be an option in the select box
cy.umbracoEnsureLanguageNameNotExists(name);

View File

@@ -23,14 +23,18 @@ context('Templates', () => {
cy.umbracoEnsureTemplateNameNotExists(name);
createTemplate();
// We have to wait for the ace editor to load, because when the editor is loading it will "steal" the focus briefly,
// which causes the save event to fire if we've added something to the header field, causing errors.
cy.wait(500);
//Type name
cy.umbracoEditorHeaderName(name);
// Save
// We must drop focus for the auto save event to occur.
cy.get('.btn-success').focus();
// And then wait for the auto save event to finish by finding the page in the tree view.
// This is a bit of a roundabout way to find items in a treev view since we dont use umbracoTreeItem
// but we must be able to wait for the save evnent to finish, and we can't do that with umbracoTreeItem
// This is a bit of a roundabout way to find items in a tree view since we dont use umbracoTreeItem
// but we must be able to wait for the save event to finish, and we can't do that with umbracoTreeItem
cy.get('[data-element="tree-item-templates"] > :nth-child(2) > .umb-animated > .umb-tree-item__inner > .umb-tree-item__label')
.contains(name).should('be.visible', { timeout: 10000 });
// Now that the auto save event has finished we can save

View File

@@ -49,7 +49,7 @@ function resetTourData() {
{
"alias": "umbIntroIntroduction",
"completed": false,
"disabled": false
"disabled": true
};
cy.getCookie('UMB-XSRF-TOKEN', { log: false }).then((token) => {

View File

@@ -7,10 +7,10 @@
},
"devDependencies": {
"cross-env": "^7.0.2",
"cypress": "^6.0.1",
"cypress": "^6.8.0",
"ncp": "^2.0.0",
"prompt": "^1.0.0",
"umbraco-cypress-testhelpers": "^1.0.0-beta-52"
"umbraco-cypress-testhelpers": "^1.0.0-beta-53"
},
"dependencies": {
"typescript": "^3.9.2"

View File

@@ -2,6 +2,7 @@
using System.Collections;
using System.Runtime.Remoting.Messaging;
using System.Threading;
using System.Threading.Tasks;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Persistence;
@@ -24,6 +25,119 @@ namespace Umbraco.Tests.Scoping
Assert.IsNull(ScopeProvider.AmbientScope); // gone
}
[Test]
public void GivenUncompletedScopeOnChildThread_WhenTheParentCompletes_TheTransactionIsRolledBack()
{
ScopeProvider scopeProvider = ScopeProvider;
Assert.IsNull(ScopeProvider.AmbientScope);
IScope mainScope = scopeProvider.CreateScope();
var t = Task.Run(() =>
{
IScope nested = scopeProvider.CreateScope();
Thread.Sleep(2000);
nested.Dispose();
});
Thread.Sleep(1000); // mimic some long running operation that is shorter than the other thread
mainScope.Complete();
Assert.Throws<InvalidOperationException>(() => mainScope.Dispose());
Task.WaitAll(t);
}
[Test]
public void GivenNonDisposedChildScope_WhenTheParentDisposes_ThenInvalidOperationExceptionThrows()
{
// this all runs in the same execution context so the AmbientScope reference isn't a copy
ScopeProvider scopeProvider = ScopeProvider;
Assert.IsNull(ScopeProvider.AmbientScope);
IScope mainScope = scopeProvider.CreateScope();
IScope nested = scopeProvider.CreateScope(); // not disposing
InvalidOperationException ex = Assert.Throws<InvalidOperationException>(() => mainScope.Dispose());
Console.WriteLine(ex);
}
[Test]
public void GivenChildThread_WhenParentDisposedBeforeChild_ParentScopeThrows()
{
// The ambient context is NOT thread safe, even though it has locks, etc...
// This all just goes to show that concurrent threads with scopes is a no-go.
var childWait = new ManualResetEventSlim(false);
var parentWait = new ManualResetEventSlim(false);
ScopeProvider scopeProvider = ScopeProvider;
Assert.IsNull(ScopeProvider.AmbientScope);
IScope mainScope = scopeProvider.CreateScope();
var t = Task.Run(() =>
{
Console.WriteLine("Child Task start: " + scopeProvider.AmbientScope.InstanceId);
// This will evict the parent from the ScopeProvider.StaticCallContextObjects
// and replace it with the child
IScope nested = scopeProvider.CreateScope();
childWait.Set();
Console.WriteLine("Child Task scope created: " + scopeProvider.AmbientScope.InstanceId);
parentWait.Wait(); // wait for the parent thread
Console.WriteLine("Child Task before dispose: " + scopeProvider.AmbientScope.InstanceId);
// This will evict the child from the ScopeProvider.StaticCallContextObjects
// and replace it with the parent
nested.Dispose();
Console.WriteLine("Child Task after dispose: " + scopeProvider.AmbientScope.InstanceId);
});
childWait.Wait(); // wait for the child to start and create the scope
// This is a confusing thing (this is not the case in netcore), this is NULL because the
// parent thread's scope ID was evicted from the ScopeProvider.StaticCallContextObjects
// so now the ambient context is null because the GUID in the CallContext doesn't match
// the GUID in the ScopeProvider.StaticCallContextObjects.
Assert.IsNull(scopeProvider.AmbientScope);
// now dispose the main without waiting for the child thread to join
// This will throw because at this stage a child scope has been created which means
// it is the Ambient (top) scope but here we're trying to dispose the non top scope.
Assert.Throws<InvalidOperationException>(() => mainScope.Dispose());
parentWait.Set(); // tell child thread to proceed
Task.WaitAll(t); // wait for the child to dispose
mainScope.Dispose(); // now it's ok
Console.WriteLine("Parent Task disposed: " + scopeProvider.AmbientScope?.InstanceId);
}
[Test]
public void GivenChildThread_WhenChildDisposedBeforeParent_OK()
{
ScopeProvider scopeProvider = ScopeProvider;
Assert.IsNull(ScopeProvider.AmbientScope);
IScope mainScope = scopeProvider.CreateScope();
// Task.Run will flow the execution context unless ExecutionContext.SuppressFlow() is explicitly called.
// This is what occurs in normal async behavior since it is expected to await (and join) the main thread,
// but if Task.Run is used as a fire and forget thread without being done correctly then the Scope will
// flow to that thread.
var t = Task.Run(() =>
{
Console.WriteLine("Child Task start: " + scopeProvider.AmbientScope.InstanceId);
IScope nested = scopeProvider.CreateScope();
Console.WriteLine("Child Task before dispose: " + scopeProvider.AmbientScope.InstanceId);
nested.Dispose();
Console.WriteLine("Child Task after disposed: " + scopeProvider.AmbientScope.InstanceId);
});
Console.WriteLine("Parent Task waiting: " + scopeProvider.AmbientScope?.InstanceId);
Task.WaitAll(t);
Console.WriteLine("Parent Task disposing: " + scopeProvider.AmbientScope.InstanceId);
mainScope.Dispose();
Console.WriteLine("Parent Task disposed: " + scopeProvider.AmbientScope?.InstanceId);
Assert.Pass();
}
[Test]
public void SimpleCreateScope()
{

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Moq;
using NPoco;
using NUnit.Framework;
@@ -9,6 +10,7 @@ using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.SqlSyntax;
using Umbraco.Core.Scoping;
using Umbraco.Tests.TestHelpers;
namespace Umbraco.Tests.Scoping
{
@@ -72,6 +74,30 @@ namespace Umbraco.Tests.Scoping
syntaxProviderMock.Verify(x => x.WriteLock(It.IsAny<IDatabase>(), Constants.Locks.Languages), Times.Once);
}
[Test]
public void WriteLock_Acquired_Only_Once_When_InnerScope_Disposed()
{
var scopeProvider = GetScopeProvider(out var syntaxProviderMock);
using (var outerScope = scopeProvider.CreateScope())
{
outerScope.WriteLock(Constants.Locks.Languages);
using (var innerScope = scopeProvider.CreateScope())
{
innerScope.WriteLock(Constants.Locks.Languages);
innerScope.WriteLock(Constants.Locks.ContentTree);
innerScope.Complete();
}
outerScope.WriteLock(Constants.Locks.ContentTree);
outerScope.Complete();
}
syntaxProviderMock.Verify(x => x.WriteLock(It.IsAny<IDatabase>(), Constants.Locks.Languages), Times.Once);
syntaxProviderMock.Verify(x => x.WriteLock(It.IsAny<IDatabase>(), Constants.Locks.ContentTree), Times.Once);
}
[Test]
public void WriteLock_With_Timeout_Acquired_Only_Once_Per_Key(){
var scopeProvider = GetScopeProvider(out var syntaxProviderMock);
@@ -176,31 +202,58 @@ namespace Umbraco.Tests.Scoping
syntaxProviderMock.Verify(x => x.ReadLock(It.IsAny<IDatabase>(), timeOut, Constants.Locks.Languages), Times.Once);
}
[Test]
public void ReadLock_Acquired_Only_Once_When_InnerScope_Disposed()
{
var scopeProvider = GetScopeProvider(out var syntaxProviderMock);
using (var outerScope = scopeProvider.CreateScope())
{
outerScope.ReadLock(Constants.Locks.Languages);
using (var innerScope = scopeProvider.CreateScope())
{
innerScope.ReadLock(Constants.Locks.Languages);
innerScope.ReadLock(Constants.Locks.ContentTree);
innerScope.Complete();
}
outerScope.ReadLock(Constants.Locks.ContentTree);
outerScope.Complete();
}
syntaxProviderMock.Verify(x => x.ReadLock(It.IsAny<IDatabase>(), Constants.Locks.Languages), Times.Once);
syntaxProviderMock.Verify(x => x.ReadLock(It.IsAny<IDatabase>(), Constants.Locks.ContentTree), Times.Once);
}
[Test]
public void WriteLocks_Count_correctly_If_Lock_Requested_Twice_In_Scope()
{
var scopeProvider = GetScopeProvider(out var syntaxProviderMock);
Guid innerscopeId;
using (var outerscope = scopeProvider.CreateScope())
{
var realOuterScope = (Scope) outerscope;
outerscope.WriteLock(Constants.Locks.ContentTree);
outerscope.WriteLock(Constants.Locks.ContentTree);
Assert.AreEqual(2, realOuterScope.WriteLocks[Constants.Locks.ContentTree]);
Assert.AreEqual(2, realOuterScope.WriteLocks[outerscope.InstanceId][Constants.Locks.ContentTree]);
using (var innerScope = scopeProvider.CreateScope())
{
innerscopeId = innerScope.InstanceId;
innerScope.WriteLock(Constants.Locks.ContentTree);
innerScope.WriteLock(Constants.Locks.ContentTree);
Assert.AreEqual(4, realOuterScope.WriteLocks[Constants.Locks.ContentTree]);
Assert.AreEqual(2, realOuterScope.WriteLocks[outerscope.InstanceId][Constants.Locks.ContentTree]);
Assert.AreEqual(2, realOuterScope.WriteLocks[innerscopeId][Constants.Locks.ContentTree]);
innerScope.WriteLock(Constants.Locks.Languages);
innerScope.WriteLock(Constants.Locks.Languages);
Assert.AreEqual(2, realOuterScope.WriteLocks[Constants.Locks.Languages]);
Assert.AreEqual(2, realOuterScope.WriteLocks[innerScope.InstanceId][Constants.Locks.Languages]);
innerScope.Complete();
}
Assert.AreEqual(0, realOuterScope.WriteLocks[Constants.Locks.Languages]);
Assert.AreEqual(2, realOuterScope.WriteLocks[Constants.Locks.ContentTree]);
Assert.AreEqual(2, realOuterScope.WriteLocks[realOuterScope.InstanceId][Constants.Locks.ContentTree]);
Assert.IsFalse(realOuterScope.WriteLocks.ContainsKey(innerscopeId));
outerscope.Complete();
}
}
@@ -209,27 +262,32 @@ namespace Umbraco.Tests.Scoping
public void ReadLocks_Count_correctly_If_Lock_Requested_Twice_In_Scope()
{
var scopeProvider = GetScopeProvider(out var syntaxProviderMock);
Guid innerscopeId;
using (var outerscope = scopeProvider.CreateScope())
{
var realOuterScope = (Scope) outerscope;
outerscope.ReadLock(Constants.Locks.ContentTree);
outerscope.ReadLock(Constants.Locks.ContentTree);
Assert.AreEqual(2, realOuterScope.ReadLocks[Constants.Locks.ContentTree]);
Assert.AreEqual(2, realOuterScope.ReadLocks[outerscope.InstanceId][Constants.Locks.ContentTree]);
using (var innerScope = scopeProvider.CreateScope())
{
innerscopeId = innerScope.InstanceId;
innerScope.ReadLock(Constants.Locks.ContentTree);
innerScope.ReadLock(Constants.Locks.ContentTree);
Assert.AreEqual(4, realOuterScope.ReadLocks[Constants.Locks.ContentTree]);
Assert.AreEqual(2, realOuterScope.ReadLocks[outerscope.InstanceId][Constants.Locks.ContentTree]);
Assert.AreEqual(2, realOuterScope.ReadLocks[innerScope.InstanceId][Constants.Locks.ContentTree]);
innerScope.ReadLock(Constants.Locks.Languages);
innerScope.ReadLock(Constants.Locks.Languages);
Assert.AreEqual(2, realOuterScope.ReadLocks[Constants.Locks.Languages]);
Assert.AreEqual(2, realOuterScope.ReadLocks[innerScope.InstanceId][Constants.Locks.Languages]);
innerScope.Complete();
}
Assert.AreEqual(0, realOuterScope.ReadLocks[Constants.Locks.Languages]);
Assert.AreEqual(2, realOuterScope.ReadLocks[Constants.Locks.ContentTree]);
Assert.AreEqual(2, realOuterScope.ReadLocks[outerscope.InstanceId][Constants.Locks.ContentTree]);
Assert.IsFalse(realOuterScope.ReadLocks.ContainsKey(innerscopeId));
outerscope.Complete();
}
}
@@ -238,51 +296,61 @@ namespace Umbraco.Tests.Scoping
public void Nested_Scopes_WriteLocks_Count_Correctly()
{
var scopeProvider = GetScopeProvider(out var syntaxProviderMock);
Guid innerScope1Id, innerScope2Id;
using (var outerScope = scopeProvider.CreateScope())
using (var parentScope = scopeProvider.CreateScope())
{
var parentScope = (Scope) outerScope;
outerScope.WriteLock(Constants.Locks.ContentTree);
outerScope.WriteLock(Constants.Locks.ContentTypes);
var realParentScope = (Scope) parentScope;
parentScope.WriteLock(Constants.Locks.ContentTree);
parentScope.WriteLock(Constants.Locks.ContentTypes);
Assert.AreEqual(1, parentScope.WriteLocks[Constants.Locks.ContentTree], $"parentScope after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, parentScope.WriteLocks[Constants.Locks.ContentTypes], $"parentScope after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.WriteLocks[realParentScope.InstanceId][Constants.Locks.ContentTree], $"parentScope after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.WriteLocks[realParentScope.InstanceId][Constants.Locks.ContentTypes], $"parentScope after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
using (var innerScope1 = scopeProvider.CreateScope())
{
innerScope1Id = innerScope1.InstanceId;
innerScope1.WriteLock(Constants.Locks.ContentTree);
innerScope1.WriteLock(Constants.Locks.ContentTypes);
innerScope1.WriteLock(Constants.Locks.Languages);
Assert.AreEqual(2, parentScope.WriteLocks[Constants.Locks.ContentTree], $"childScope1 after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(2, parentScope.WriteLocks[Constants.Locks.ContentTypes], $"childScope1 after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, parentScope.WriteLocks[Constants.Locks.Languages], $"childScope1 after locks acquired: {nameof(Constants.Locks.Languages)}");
Assert.AreEqual(1, realParentScope.WriteLocks[realParentScope.InstanceId][Constants.Locks.ContentTree], $"innerScope1, parent instance, after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.WriteLocks[realParentScope.InstanceId][Constants.Locks.ContentTypes], $"innerScope1, parent instance, after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.WriteLocks[innerScope1.InstanceId][Constants.Locks.ContentTree], $"innerScope1, innerScope1 instance, after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.WriteLocks[innerScope1.InstanceId][Constants.Locks.ContentTypes], $"innerScope1, innerScope1 instance, after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.WriteLocks[innerScope1.InstanceId][Constants.Locks.Languages], $"innerScope1, innerScope1 instance, after locks acquired: {nameof(Constants.Locks.Languages)}");
using (var innerScope2 = scopeProvider.CreateScope())
{
innerScope2Id = innerScope2.InstanceId;
innerScope2.WriteLock(Constants.Locks.ContentTree);
innerScope2.WriteLock(Constants.Locks.MediaTypes);
Assert.AreEqual(3, parentScope.WriteLocks[Constants.Locks.ContentTree], $"childScope2 after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(2, parentScope.WriteLocks[Constants.Locks.ContentTypes], $"childScope2 after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, parentScope.WriteLocks[Constants.Locks.Languages], $"childScope2 after locks acquired: {nameof(Constants.Locks.Languages)}");
Assert.AreEqual(1, parentScope.WriteLocks[Constants.Locks.MediaTypes], $"childScope2 after locks acquired: {nameof(Constants.Locks.MediaTypes)}");
Assert.AreEqual(1, realParentScope.WriteLocks[realParentScope.InstanceId][Constants.Locks.ContentTree], $"innerScope2, parent instance, after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.WriteLocks[realParentScope.InstanceId][Constants.Locks.ContentTypes], $"innerScope2, parent instance, after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.WriteLocks[innerScope1.InstanceId][Constants.Locks.ContentTree], $"innerScope2, innerScope1 instance, after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.WriteLocks[innerScope1.InstanceId][Constants.Locks.ContentTypes], $"innerScope2, innerScope1 instance, after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.WriteLocks[innerScope1.InstanceId][Constants.Locks.Languages], $"innerScope2, innerScope1 instance, after locks acquired: {nameof(Constants.Locks.Languages)}");
Assert.AreEqual(1, realParentScope.WriteLocks[innerScope2.InstanceId][Constants.Locks.ContentTree], $"innerScope2, innerScope2 instance, after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.WriteLocks[innerScope2.InstanceId][Constants.Locks.MediaTypes], $"innerScope2, innerScope2 instance, after locks acquired: {nameof(Constants.Locks.MediaTypes)}");
innerScope2.Complete();
}
Assert.AreEqual(2, parentScope.WriteLocks[Constants.Locks.ContentTree], $"childScope1 after inner scope disposed: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(2, parentScope.WriteLocks[Constants.Locks.ContentTypes], $"childScope1 after inner scope disposed: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, parentScope.WriteLocks[Constants.Locks.Languages], $"childScope1 after inner scope disposed: {nameof(Constants.Locks.Languages)}");
Assert.AreEqual(0, parentScope.WriteLocks[Constants.Locks.MediaTypes], $"childScope1 after inner scope disposed: {nameof(Constants.Locks.MediaTypes)}");
Assert.AreEqual(1, realParentScope.WriteLocks[realParentScope.InstanceId][Constants.Locks.ContentTree], $"innerScope1, parent instance, after innserScope2 disposed: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.WriteLocks[realParentScope.InstanceId][Constants.Locks.ContentTypes], $"innerScope1, parent instance, after innserScope2 disposed: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.WriteLocks[innerScope1.InstanceId][Constants.Locks.ContentTree], $"innerScope1, innerScope1 instance, after innserScope2 disposed: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.WriteLocks[innerScope1.InstanceId][Constants.Locks.ContentTypes], $"innerScope1, innerScope1 instance, after innserScope2 disposed: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.WriteLocks[innerScope1.InstanceId][Constants.Locks.Languages], $"innerScope1, innerScope1 instance, after innserScope2 disposed: {nameof(Constants.Locks.Languages)}");
Assert.IsFalse(realParentScope.WriteLocks.ContainsKey(innerScope2Id));
innerScope1.Complete();
}
Assert.AreEqual(1, parentScope.WriteLocks[Constants.Locks.ContentTree], $"parentScope after inner scopes disposed: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, parentScope.WriteLocks[Constants.Locks.ContentTypes], $"parentScope after inner scopes disposed: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(0, parentScope.WriteLocks[Constants.Locks.Languages], $"parentScope after inner scopes disposed: {nameof(Constants.Locks.Languages)}");
Assert.AreEqual(0, parentScope.WriteLocks[Constants.Locks.MediaTypes], $"parentScope after inner scopes disposed: {nameof(Constants.Locks.MediaTypes)}");
Assert.AreEqual(1, realParentScope.WriteLocks[realParentScope.InstanceId][Constants.Locks.ContentTree], $"parentScope after inner scopes disposed: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.WriteLocks[realParentScope.InstanceId][Constants.Locks.ContentTypes], $"parentScope after inner scopes disposed: {nameof(Constants.Locks.ContentTypes)}");
Assert.IsFalse(realParentScope.WriteLocks.ContainsKey(innerScope2Id));
Assert.IsFalse(realParentScope.WriteLocks.ContainsKey(innerScope1Id));
outerScope.Complete();
parentScope.Complete();
}
}
@@ -290,48 +358,166 @@ namespace Umbraco.Tests.Scoping
public void Nested_Scopes_ReadLocks_Count_Correctly()
{
var scopeProvider = GetScopeProvider(out var syntaxProviderMock);
Guid innerScope1Id, innerScope2Id;
using (var outerScope = scopeProvider.CreateScope())
using (var parentScope = scopeProvider.CreateScope())
{
var parentScope = (Scope) outerScope;
outerScope.ReadLock(Constants.Locks.ContentTree);
outerScope.ReadLock(Constants.Locks.ContentTypes);
Assert.AreEqual(1, parentScope.ReadLocks[Constants.Locks.ContentTree], $"parentScope after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, parentScope.ReadLocks[Constants.Locks.ContentTypes], $"parentScope after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
var realParentScope = (Scope) parentScope;
parentScope.ReadLock(Constants.Locks.ContentTree);
parentScope.ReadLock(Constants.Locks.ContentTypes);
Assert.AreEqual(1, realParentScope.ReadLocks[realParentScope.InstanceId][Constants.Locks.ContentTree], $"parentScope after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.ReadLocks[realParentScope.InstanceId][Constants.Locks.ContentTypes], $"parentScope after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
using (var innserScope1 = scopeProvider.CreateScope())
{
innerScope1Id = innserScope1.InstanceId;
innserScope1.ReadLock(Constants.Locks.ContentTree);
innserScope1.ReadLock(Constants.Locks.ContentTypes);
innserScope1.ReadLock(Constants.Locks.Languages);
Assert.AreEqual(2, parentScope.ReadLocks[Constants.Locks.ContentTree], $"childScope1 after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(2, parentScope.ReadLocks[Constants.Locks.ContentTypes], $"childScope1 after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, parentScope.ReadLocks[Constants.Locks.Languages], $"childScope1 after locks acquired: {nameof(Constants.Locks.Languages)}");
Assert.AreEqual(1, realParentScope.ReadLocks[realParentScope.InstanceId][Constants.Locks.ContentTree], $"innerScope1, parent instance, after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.ReadLocks[realParentScope.InstanceId][Constants.Locks.ContentTypes], $"innerScope1, parent instance, after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.ReadLocks[innserScope1.InstanceId][Constants.Locks.ContentTree], $"innerScope1, innerScope1 instance, after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.ReadLocks[innserScope1.InstanceId][Constants.Locks.ContentTypes], $"innerScope1, innerScope1 instance, after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.ReadLocks[innserScope1.InstanceId][Constants.Locks.Languages], $"innerScope1, innerScope1 instance, after locks acquired: {nameof(Constants.Locks.Languages)}");
using (var innerScope2 = scopeProvider.CreateScope())
{
innerScope2Id = innerScope2.InstanceId;
innerScope2.ReadLock(Constants.Locks.ContentTree);
innerScope2.ReadLock(Constants.Locks.MediaTypes);
Assert.AreEqual(3, parentScope.ReadLocks[Constants.Locks.ContentTree], $"childScope2 after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(2, parentScope.ReadLocks[Constants.Locks.ContentTypes], $"childScope2 after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, parentScope.ReadLocks[Constants.Locks.Languages], $"childScope2 after locks acquired: {nameof(Constants.Locks.Languages)}");
Assert.AreEqual(1, parentScope.ReadLocks[Constants.Locks.MediaTypes], $"childScope2 after locks acquired: {nameof(Constants.Locks.MediaTypes)}");
Assert.AreEqual(1, realParentScope.ReadLocks[realParentScope.InstanceId][Constants.Locks.ContentTree], $"innerScope2, parent instance, after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.ReadLocks[realParentScope.InstanceId][Constants.Locks.ContentTypes], $"innerScope2, parent instance, after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.ReadLocks[innserScope1.InstanceId][Constants.Locks.ContentTree], $"innerScope2, innerScope1 instance, after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.ReadLocks[innserScope1.InstanceId][Constants.Locks.ContentTypes], $"innerScope2, innerScope1 instance, after locks acquired: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.ReadLocks[innserScope1.InstanceId][Constants.Locks.Languages], $"innerScope2, innerScope1 instance, after locks acquired: {nameof(Constants.Locks.Languages)}");
Assert.AreEqual(1, realParentScope.ReadLocks[innerScope2.InstanceId][Constants.Locks.ContentTree], $"innerScope2, innerScope2 instance, after locks acquired: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.ReadLocks[innerScope2.InstanceId][Constants.Locks.MediaTypes], $"innerScope2, innerScope2 instance, after locks acquired: {nameof(Constants.Locks.MediaTypes)}");
innerScope2.Complete();
}
Assert.AreEqual(2, parentScope.ReadLocks[Constants.Locks.ContentTree], $"childScope1 after inner scope disposed: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(2, parentScope.ReadLocks[Constants.Locks.ContentTypes], $"childScope1 after inner scope disposed: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, parentScope.ReadLocks[Constants.Locks.Languages], $"childScope1 after inner scope disposed: {nameof(Constants.Locks.Languages)}");
Assert.AreEqual(0, parentScope.ReadLocks[Constants.Locks.MediaTypes], $"childScope1 after inner scope disposed: {nameof(Constants.Locks.MediaTypes)}");
Assert.AreEqual(1, realParentScope.ReadLocks[realParentScope.InstanceId][Constants.Locks.ContentTree], $"innerScope1, parent instance, after innerScope2 disposed: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.ReadLocks[realParentScope.InstanceId][Constants.Locks.ContentTypes], $"innerScope1, parent instance, after innerScope2 disposed: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.ReadLocks[innserScope1.InstanceId][Constants.Locks.ContentTree], $"innerScope1, innerScope1 instance, after innerScope2 disposed: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.ReadLocks[innserScope1.InstanceId][Constants.Locks.ContentTypes], $"innerScope1, innerScope1 instance, after innerScope2 disposed: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(1, realParentScope.ReadLocks[innserScope1.InstanceId][Constants.Locks.Languages], $"innerScope1, innerScope1 instance, after innerScope2 disposed: {nameof(Constants.Locks.Languages)}");
Assert.IsFalse(realParentScope.ReadLocks.ContainsKey(innerScope2Id));
innserScope1.Complete();
}
Assert.AreEqual(1, parentScope.ReadLocks[Constants.Locks.ContentTree], $"parentScope after inner scopes disposed: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, parentScope.ReadLocks[Constants.Locks.ContentTypes], $"parentScope after inner scopes disposed: {nameof(Constants.Locks.ContentTypes)}");
Assert.AreEqual(0, parentScope.ReadLocks[Constants.Locks.Languages], $"parentScope after inner scopes disposed: {nameof(Constants.Locks.Languages)}");
Assert.AreEqual(0, parentScope.ReadLocks[Constants.Locks.MediaTypes], $"parentScope after inner scopes disposed: {nameof(Constants.Locks.MediaTypes)}");
outerScope.Complete();
Assert.AreEqual(1, realParentScope.ReadLocks[realParentScope.InstanceId][Constants.Locks.ContentTree], $"parentScope after innerScope1 disposed: {nameof(Constants.Locks.ContentTree)}");
Assert.AreEqual(1, realParentScope.ReadLocks[realParentScope.InstanceId][Constants.Locks.ContentTypes], $"parentScope after innerScope1 disposed: {nameof(Constants.Locks.ContentTypes)}");
Assert.IsFalse(realParentScope.ReadLocks.ContainsKey(innerScope2Id));
Assert.IsFalse(realParentScope.ReadLocks.ContainsKey(innerScope1Id));
parentScope.Complete();
}
}
[Test]
public void WriteLock_Doesnt_Increment_On_Error()
{
var scopeProvider = GetScopeProvider(out var syntaxProviderMock);
syntaxProviderMock.Setup(x => x.WriteLock(It.IsAny<IDatabase>(), It.IsAny<int[]>())).Throws(new Exception("Boom"));
using (var scope = scopeProvider.CreateScope())
{
var realScope = (Scope) scope;
Assert.Throws<Exception>(() => scope.WriteLock(Constants.Locks.Languages));
Assert.IsFalse(realScope.WriteLocks[scope.InstanceId].ContainsKey(Constants.Locks.Languages));
scope.Complete();
}
}
[Test]
public void ReadLock_Doesnt_Increment_On_Error()
{
var scopeProvider = GetScopeProvider(out var syntaxProviderMock);
syntaxProviderMock.Setup(x => x.ReadLock(It.IsAny<IDatabase>(), It.IsAny<int[]>())).Throws(new Exception("Boom"));
using (var scope = scopeProvider.CreateScope())
{
var realScope = (Scope) scope;
Assert.Throws<Exception>(() => scope.ReadLock(Constants.Locks.Languages));
Assert.IsFalse(realScope.ReadLocks[scope.InstanceId].ContainsKey(Constants.Locks.Languages));
scope.Complete();
}
}
[Test]
public void Scope_Throws_If_ReadLocks_Not_Cleared()
{
var scopeprovider = GetScopeProvider(out var syntaxProviderMock);
var scope = (Scope) scopeprovider.CreateScope();
try
{
// Request a lock to create the ReadLocks dict.
scope.ReadLock(Constants.Locks.Domains);
var readDict = new Dictionary<int, int>();
readDict[Constants.Locks.Languages] = 1;
scope.ReadLocks[Guid.NewGuid()] = readDict;
Assert.Throws<InvalidOperationException>(() => scope.Dispose());
}
finally
{
// We have to clear so we can properly dispose the scope, otherwise it'll mess with other tests.
scope.ReadLocks?.Clear();
scope.Dispose();
}
}
[Test]
public void Scope_Throws_If_WriteLocks_Not_Cleared()
{
var scopeprovider = GetScopeProvider(out var syntaxProviderMock);
var scope = (Scope) scopeprovider.CreateScope();
try
{
// Request a lock to create the WriteLocks dict.
scope.WriteLock(Constants.Locks.Domains);
var writeDict = new Dictionary<int, int>();
writeDict[Constants.Locks.Languages] = 1;
scope.WriteLocks[Guid.NewGuid()] = writeDict;
Assert.Throws<InvalidOperationException>(() => scope.Dispose());
}
finally
{
// We have to clear so we can properly dispose the scope, otherwise it'll mess with other tests.
scope.WriteLocks?.Clear();
scope.Dispose();
}
}
[Test]
public void WriteLocks_Not_Created_Until_First_Lock()
{
var scopeProvider = GetScopeProvider(out var syntaxProviderMock);
using (var scope = scopeProvider.CreateScope())
{
var realScope = (Scope) scope;
Assert.IsNull(realScope.WriteLocks);
}
}
[Test]
public void ReadLocks_Not_Created_Until_First_Lock()
{
var scopeProvider = GetScopeProvider(out var syntaxProviderMock);
using (var scope = scopeProvider.CreateScope())
{
var realScope = (Scope) scope;
Assert.IsNull(realScope.ReadLocks);
}
}
}

View File

@@ -104,7 +104,7 @@ namespace Umbraco.Tests.Services
var threads = new List<Thread>();
var exceptions = new List<Exception>();
Debug.WriteLine("Starting...");
Console.WriteLine("Starting...");
var done = TraceLocks();
@@ -114,12 +114,12 @@ namespace Umbraco.Tests.Services
{
try
{
Debug.WriteLine("[{0}] Running...", Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("[{0}] Running...", Thread.CurrentThread.ManagedThreadId);
var name1 = "test-" + Guid.NewGuid();
var content1 = contentService.Create(name1, -1, "umbTextpage");
Debug.WriteLine("[{0}] Saving content #1.", Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("[{0}] Saving content #1.", Thread.CurrentThread.ManagedThreadId);
Save(contentService, content1);
Thread.Sleep(100); //quick pause for maximum overlap!
@@ -127,7 +127,7 @@ namespace Umbraco.Tests.Services
var name2 = "test-" + Guid.NewGuid();
var content2 = contentService.Create(name2, -1, "umbTextpage");
Debug.WriteLine("[{0}] Saving content #2.", Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("[{0}] Saving content #2.", Thread.CurrentThread.ManagedThreadId);
Save(contentService, content2);
}
catch (Exception e)
@@ -139,16 +139,16 @@ namespace Umbraco.Tests.Services
}
// start all threads
Debug.WriteLine("Starting threads");
Console.WriteLine("Starting threads");
threads.ForEach(x => x.Start());
// wait for all to complete
Debug.WriteLine("Joining threads");
Console.WriteLine("Joining threads");
threads.ForEach(x => x.Join());
done.Set();
Debug.WriteLine("Checking exceptions");
Console.WriteLine("Checking exceptions");
if (exceptions.Count == 0)
{
//now look up all items, there should be 40!
@@ -172,7 +172,7 @@ namespace Umbraco.Tests.Services
var threads = new List<Thread>();
var exceptions = new List<Exception>();
Debug.WriteLine("Starting...");
Console.WriteLine("Starting...");
var done = TraceLocks();
@@ -182,18 +182,18 @@ namespace Umbraco.Tests.Services
{
try
{
Debug.WriteLine("[{0}] Running...", Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("[{0}] Running...", Thread.CurrentThread.ManagedThreadId);
var name1 = "test-" + Guid.NewGuid();
var media1 = mediaService.CreateMedia(name1, -1, Constants.Conventions.MediaTypes.Folder);
Debug.WriteLine("[{0}] Saving media #1.", Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("[{0}] Saving media #1.", Thread.CurrentThread.ManagedThreadId);
Save(mediaService, media1);
Thread.Sleep(100); //quick pause for maximum overlap!
var name2 = "test-" + Guid.NewGuid();
var media2 = mediaService.CreateMedia(name2, -1, Constants.Conventions.MediaTypes.Folder);
Debug.WriteLine("[{0}] Saving media #2.", Thread.CurrentThread.ManagedThreadId);
Console.WriteLine("[{0}] Saving media #2.", Thread.CurrentThread.ManagedThreadId);
Save(mediaService, media2);
}
catch (Exception e)

View File

@@ -29,10 +29,6 @@
var defaultFocusedElement = getAutoFocusElement(focusableElements);
var firstFocusableElement = focusableElements[0];
var lastFocusableElement = focusableElements[focusableElements.length -1];
// We need to add the tabbing-active class in order to highlight the focused button since the default style is
// outline: none; set in the stylesheet specifically
bodyElement.classList.add('tabbing-active');
// If there is no default focused element put focus on the first focusable element in the nodelist
if(defaultFocusedElement === null ){

View File

@@ -15,6 +15,7 @@
right: 0;
border-radius: 3px;
box-shadow: 0 0 2px 0px @ui-outline, inset 0 0 2px 2px @ui-outline;
pointer-events: none;
}
}

View File

@@ -308,7 +308,14 @@ select[size] {
input[type="file"],
input[type="radio"],
input[type="checkbox"] {
.umb-outline();
&:focus {
border-color: @inputBorderFocus;
outline: 0;
.tabbing-active & {
outline: 2px solid @ui-outline;
}
}
}

View File

@@ -347,9 +347,9 @@
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>8121</DevelopmentServerPort>
<DevelopmentServerPort>8122</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:8121</IISUrl>
<IISUrl>http://localhost:8122</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>

View File

@@ -37,6 +37,7 @@
<add key="Umbraco.Core.TimeOutInMinutes" value="20" />
<add key="Umbraco.Core.DefaultUILanguage" value="en-US" />
<add key="Umbraco.Core.UseHttps" value="false" />
<add key="Umbraco.Core.AllowContentDashboardAccessToAllUsers" value="true"/>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
<add key="webpages:Enabled" value="false" />

View File

@@ -1,15 +1,21 @@
using Umbraco.Core;
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Dashboards;
using Umbraco.Core.Services;
namespace Umbraco.Web.Dashboards
{
[Weight(10)]
public class ContentDashboard : IDashboard
{
private readonly IContentDashboardSettings _dashboardSettings;
private readonly IUserService _userService;
private IAccessRule[] _accessRulesFromConfig;
public string Alias => "contentIntro";
public string[] Sections => new [] { "content" };
public string[] Sections => new[] { "content" };
public string View => "views/dashboard/default/startupdashboardintro.html";
@@ -17,13 +23,54 @@ namespace Umbraco.Web.Dashboards
{
get
{
var rules = new IAccessRule[]
var rules = AccessRulesFromConfig;
if (rules.Length == 0)
{
new AccessRule {Type = AccessRuleType.Deny, Value = Constants.Security.TranslatorGroupAlias},
new AccessRule {Type = AccessRuleType.Grant, Value = Constants.Security.AdminGroupAlias}
};
rules = new IAccessRule[]
{
new AccessRule {Type = AccessRuleType.Deny, Value = Constants.Security.TranslatorGroupAlias},
new AccessRule {Type = AccessRuleType.Grant, Value = Constants.Security.AdminGroupAlias}
};
}
return rules;
}
}
private IAccessRule[] AccessRulesFromConfig
{
get
{
if (_accessRulesFromConfig is null)
{
var rules = new List<IAccessRule>();
if (_dashboardSettings.AllowContentDashboardAccessToAllUsers)
{
var allUserGroups = _userService.GetAllUserGroups();
foreach (var userGroup in allUserGroups)
{
rules.Add(new AccessRule
{
Type = AccessRuleType.Grant,
Value = userGroup.Alias
});
}
}
_accessRulesFromConfig = rules.ToArray();
}
return _accessRulesFromConfig;
}
}
public ContentDashboard(IContentDashboardSettings dashboardSettings, IUserService userService)
{
_dashboardSettings = dashboardSettings;
_userService = userService;
}
}
}

View File

@@ -17,6 +17,7 @@ using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Services;
using Umbraco.Core.Dashboards;
using Umbraco.Core.Models;
using Umbraco.Web.Services;
namespace Umbraco.Web.Editors
@@ -52,8 +53,9 @@ namespace Umbraco.Web.Editors
var allowedSections = string.Join(",", user.AllowedSections);
var language = user.Language;
var version = UmbracoVersion.SemanticVersion.ToSemanticString();
var isAdmin = user.IsAdmin();
var url = string.Format(baseUrl + "{0}?section={0}&allowed={1}&lang={2}&version={3}", section, allowedSections, language, version);
var url = string.Format(baseUrl + "{0}?section={0}&allowed={1}&lang={2}&version={3}&admin={4}", section, allowedSections, language, version, isAdmin);
var key = "umbraco-dynamic-dashboard-" + language + allowedSections.Replace(",", "-") + section;
var content = AppCaches.RuntimeCache.GetCacheItem<JObject>(key);

View File

@@ -319,7 +319,10 @@ namespace Umbraco.Web.Scheduling
// create a new token source since this is a new process
_shutdownTokenSource = new CancellationTokenSource();
_shutdownToken = _shutdownTokenSource.Token;
_runningTask = Task.Run(async () => await Pump().ConfigureAwait(false), _shutdownToken);
using (ExecutionContext.SuppressFlow())
{
_runningTask = Task.Run(async () => await Pump().ConfigureAwait(false), _shutdownToken);
}
_logger.Debug<BackgroundTaskRunner, string>("{LogPrefix} Starting", _logPrefix);
}
@@ -544,10 +547,14 @@ namespace Umbraco.Web.Scheduling
try
{
if (bgTask.IsAsync)
{
// configure await = false since we don't care about the context, we're on a background thread.
await bgTask.RunAsync(token).ConfigureAwait(false);
}
else
{
bgTask.Run();
}
}
finally // ensure we disposed - unless latched again ie wants to re-run
{
@@ -710,14 +717,20 @@ namespace Umbraco.Web.Scheduling
// with a single aspnet thread during shutdown and we don't want to delay other calls to IRegisteredObject.Stop.
if (!immediate)
{
return Task.Run(StopInitial, CancellationToken.None);
using (ExecutionContext.SuppressFlow())
{
return Task.Run(StopInitial, CancellationToken.None);
}
}
else
{
lock (_locker)
{
if (_terminated) return Task.CompletedTask;
return Task.Run(StopImmediate, CancellationToken.None);
using (ExecutionContext.SuppressFlow())
{
return Task.Run(StopImmediate, CancellationToken.None);
}
}
}
}