|
|
@ -15,8 +15,6 @@ namespace NzbDrone.Core.ProgressMessaging
|
|
|
|
private readonly IManageCommandQueue _commandQueueManager;
|
|
|
|
private readonly IManageCommandQueue _commandQueueManager;
|
|
|
|
private static LoggingRule _rule;
|
|
|
|
private static LoggingRule _rule;
|
|
|
|
|
|
|
|
|
|
|
|
private const string REENTRY_LOCK = "ProgressMessagingLock";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ProgressMessageTarget(IEventAggregator eventAggregator, IManageCommandQueue commandQueueManager)
|
|
|
|
public ProgressMessageTarget(IEventAggregator eventAggregator, IManageCommandQueue commandQueueManager)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_eventAggregator = eventAggregator;
|
|
|
|
_eventAggregator = eventAggregator;
|
|
|
@ -25,29 +23,20 @@ namespace NzbDrone.Core.ProgressMessaging
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Write(LogEventInfo logEvent)
|
|
|
|
protected override void Write(LogEventInfo logEvent)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!ReentryPreventionCheck()) return;
|
|
|
|
var command = ProgressMessageContext.CommandModel;
|
|
|
|
|
|
|
|
|
|
|
|
var command = GetCurrentCommand();
|
|
|
|
if (!IsClientMessage(logEvent, command)) return;
|
|
|
|
|
|
|
|
|
|
|
|
if (IsClientMessage(logEvent, command))
|
|
|
|
if (!ProgressMessageContext.LockReentrancy()) return;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_commandQueueManager.SetMessage(command, logEvent.FormattedMessage);
|
|
|
|
_commandQueueManager.SetMessage(command, logEvent.FormattedMessage);
|
|
|
|
_eventAggregator.PublishEvent(new CommandUpdatedEvent(command));
|
|
|
|
_eventAggregator.PublishEvent(new CommandUpdatedEvent(command));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finally
|
|
|
|
MappedDiagnosticsContext.Remove(REENTRY_LOCK);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CommandModel GetCurrentCommand()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var commandId = MappedDiagnosticsContext.Get("CommandId");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (String.IsNullOrWhiteSpace(commandId))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
ProgressMessageContext.UnlockReentrancy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return _commandQueueManager.Get(Convert.ToInt32(commandId));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool IsClientMessage(LogEventInfo logEvent, CommandModel command)
|
|
|
|
private bool IsClientMessage(LogEventInfo logEvent, CommandModel command)
|
|
|
@ -60,20 +49,6 @@ namespace NzbDrone.Core.ProgressMessaging
|
|
|
|
return logEvent.Properties.ContainsKey("Status");
|
|
|
|
return logEvent.Properties.ContainsKey("Status");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool ReentryPreventionCheck()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var reentryLock = MappedDiagnosticsContext.Get(REENTRY_LOCK);
|
|
|
|
|
|
|
|
var commandId = MappedDiagnosticsContext.Get("CommandId");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (reentryLock.IsNullOrWhiteSpace() || reentryLock != commandId)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MappedDiagnosticsContext.Set(REENTRY_LOCK, MappedDiagnosticsContext.Get("CommandId"));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Handle(ApplicationStartedEvent message)
|
|
|
|
public void Handle(ApplicationStartedEvent message)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_rule = new LoggingRule("*", LogLevel.Trace, this);
|
|
|
|
_rule = new LoggingRule("*", LogLevel.Trace, this);
|
|
|
|