2024-03-18 23:48:35 +00:00
|
|
|
using System;
|
|
|
|
using System.Threading;
|
2015-06-03 18:17:50 +00:00
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.ProgressMessaging
|
|
|
|
{
|
|
|
|
public static class ProgressMessageContext
|
|
|
|
{
|
2024-03-18 23:48:35 +00:00
|
|
|
private static AsyncLocal<CommandModel> _commandModelAsync = new AsyncLocal<CommandModel>();
|
|
|
|
|
2015-06-03 18:17:50 +00:00
|
|
|
[ThreadStatic]
|
|
|
|
private static CommandModel _commandModel;
|
|
|
|
|
|
|
|
[ThreadStatic]
|
|
|
|
private static bool _reentrancyLock;
|
2020-01-03 12:49:24 +00:00
|
|
|
|
2015-06-03 18:17:50 +00:00
|
|
|
public static CommandModel CommandModel
|
|
|
|
{
|
2024-03-18 23:48:35 +00:00
|
|
|
get
|
|
|
|
{
|
|
|
|
return _commandModel ?? _commandModelAsync.Value;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_commandModel = value;
|
|
|
|
_commandModelAsync.Value = value;
|
|
|
|
}
|
2015-06-03 18:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static bool LockReentrancy()
|
|
|
|
{
|
|
|
|
if (_reentrancyLock)
|
2020-01-03 12:49:24 +00:00
|
|
|
{
|
2015-06-03 18:17:50 +00:00
|
|
|
return false;
|
2020-01-03 12:49:24 +00:00
|
|
|
}
|
2015-06-03 18:17:50 +00:00
|
|
|
|
|
|
|
_reentrancyLock = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void UnlockReentrancy()
|
|
|
|
{
|
|
|
|
_reentrancyLock = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|