signalR connection is now called directly rather than using a command to reduce overhead.

pull/3113/head
kayone 10 years ago
parent 1e29a2f4ee
commit 322ff2af8c

@ -43,9 +43,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.AspNet.SignalR.Client">
<HintPath>..\packages\Microsoft.AspNet.SignalR.Client.2.1.1\lib\net40\Microsoft.AspNet.SignalR.Client.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net40\Newtonsoft.Json.dll</HintPath>

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.SignalR.Client" version="2.1.1" targetFramework="net40" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net40" />
</packages>

@ -5,6 +5,7 @@ using NzbDrone.Api.Episodes;
using NzbDrone.Api.Extensions;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Tv;
using NzbDrone.SignalR;
namespace NzbDrone.Api.Calendar
{
@ -13,10 +14,10 @@ namespace NzbDrone.Api.Calendar
private readonly IEpisodeService _episodeService;
private readonly SeriesRepository _seriesRepository;
public CalendarModule(ICommandExecutor commandExecutor,
public CalendarModule(IBroadcastSignalRMessage signalRBroadcaster,
IEpisodeService episodeService,
SeriesRepository seriesRepository)
: base(episodeService, commandExecutor, "calendar")
: base(episodeService, signalRBroadcaster, "calendar")
{
_episodeService = episodeService;
_seriesRepository = seriesRepository;

@ -10,6 +10,7 @@ using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Commands.Tracking;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.ProgressMessaging;
using NzbDrone.SignalR;
namespace NzbDrone.Api.Commands
@ -20,8 +21,8 @@ namespace NzbDrone.Api.Commands
private readonly IContainer _container;
private readonly ITrackCommands _trackCommands;
public CommandModule(ICommandExecutor commandExecutor, IContainer container, ITrackCommands trackCommands)
: base(commandExecutor)
public CommandModule(ICommandExecutor commandExecutor,IBroadcastSignalRMessage signalRBroadcaster, IContainer container, ITrackCommands trackCommands)
: base(signalRBroadcaster)
{
_commandExecutor = commandExecutor;
_container = container;

@ -2,16 +2,15 @@
using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Api.Episodes;
using NzbDrone.Api.REST;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Api.Mapping;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Tv;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.SignalR;
namespace NzbDrone.Api.EpisodeFiles
{
@ -24,13 +23,13 @@ namespace NzbDrone.Api.EpisodeFiles
private readonly IQualityUpgradableSpecification _qualityUpgradableSpecification;
private readonly Logger _logger;
public EpisodeModule(ICommandExecutor commandExecutor,
public EpisodeModule(IBroadcastSignalRMessage signalRBroadcaster,
IMediaFileService mediaFileService,
IRecycleBinProvider recycleBinProvider,
ISeriesService seriesService,
IQualityUpgradableSpecification qualityUpgradableSpecification,
Logger logger)
: base(commandExecutor)
: base(signalRBroadcaster)
{
_mediaFileService = mediaFileService;
_recycleBinProvider = recycleBinProvider;

@ -4,6 +4,7 @@ using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Tv;
using NzbDrone.Api.Mapping;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.SignalR;
namespace NzbDrone.Api.Episodes
{
@ -13,8 +14,9 @@ namespace NzbDrone.Api.Episodes
private readonly IEpisodeService _episodeService;
private readonly IQualityUpgradableSpecification _qualityUpgradableSpecification;
public EpisodeModule(ICommandExecutor commandExecutor, ISeriesService seriesService, IEpisodeService episodeService, IQualityUpgradableSpecification qualityUpgradableSpecification)
: base(episodeService, commandExecutor)
public EpisodeModule(IBroadcastSignalRMessage signalRBroadcaster, ISeriesService seriesService, IEpisodeService episodeService,
IQualityUpgradableSpecification qualityUpgradableSpecification)
: base(episodeService, signalRBroadcaster)
{
_seriesService = seriesService;
_episodeService = episodeService;

@ -2,9 +2,9 @@
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.Download;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Tv;
using NzbDrone.SignalR;
namespace NzbDrone.Api.Episodes
{
@ -14,16 +14,16 @@ namespace NzbDrone.Api.Episodes
{
private readonly IEpisodeService _episodeService;
protected EpisodeModuleWithSignalR(IEpisodeService episodeService, ICommandExecutor commandExecutor)
: base(commandExecutor)
protected EpisodeModuleWithSignalR(IEpisodeService episodeService, IBroadcastSignalRMessage signalRBroadcaster)
: base(signalRBroadcaster)
{
_episodeService = episodeService;
GetResourceById = GetEpisode;
}
protected EpisodeModuleWithSignalR(IEpisodeService episodeService, ICommandExecutor commandExecutor, string resource)
: base(commandExecutor, resource)
protected EpisodeModuleWithSignalR(IEpisodeService episodeService, IBroadcastSignalRMessage signalRBroadcaster, string resource)
: base(signalRBroadcaster, resource)
{
_episodeService = episodeService;

@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.HealthCheck;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.SignalR;
namespace NzbDrone.Api.Health
{
@ -12,8 +11,8 @@ namespace NzbDrone.Api.Health
{
private readonly IHealthCheckService _healthCheckService;
public HealthModule(ICommandExecutor commandExecutor, IHealthCheckService healthCheckService)
: base(commandExecutor)
public HealthModule(IBroadcastSignalRMessage signalRBroadcaster, IHealthCheckService healthCheckService)
: base(signalRBroadcaster)
{
_healthCheckService = healthCheckService;
GetResourceAll = GetHealth;

@ -1,7 +1,6 @@
using NzbDrone.Api.REST;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.SignalR;
@ -11,17 +10,17 @@ namespace NzbDrone.Api
where TResource : RestResource, new()
where TModel : ModelBase
{
private readonly ICommandExecutor _commandExecutor;
private readonly IBroadcastSignalRMessage _signalRBroadcaster;
protected NzbDroneRestModuleWithSignalR(ICommandExecutor commandExecutor)
protected NzbDroneRestModuleWithSignalR(IBroadcastSignalRMessage signalRBroadcaster)
{
_commandExecutor = commandExecutor;
_signalRBroadcaster = signalRBroadcaster;
}
protected NzbDroneRestModuleWithSignalR(ICommandExecutor commandExecutor, string resource)
protected NzbDroneRestModuleWithSignalR(IBroadcastSignalRMessage signalRBroadcaster, string resource)
: base(resource)
{
_commandExecutor = commandExecutor;
_signalRBroadcaster = signalRBroadcaster;
}
public void Handle(ModelEvent<TModel> message)
@ -34,30 +33,25 @@ namespace NzbDrone.Api
BroadcastResourceChange(message.Action, message.Model.Id);
}
protected void BroadcastResourceChange(ModelAction action, TResource resource)
{
var signalRMessage = new SignalRMessage
{
Name = Resource,
Body = new ResourceChangeMessage<TResource>(resource, action)
};
_commandExecutor.PublishCommand(new BroadcastSignalRMessage(signalRMessage));
}
protected void BroadcastResourceChange(ModelAction action, int id)
{
var resource = GetResourceById(id);
BroadcastResourceChange(action, resource);
}
protected void BroadcastResourceChange(ModelAction action, TResource resource)
{
var signalRMessage = new SignalRMessage
{
Name = Resource,
Body = new ResourceChangeMessage<TResource>(resource, action)
};
_commandExecutor.PublishCommand(new BroadcastSignalRMessage(signalRMessage));
_signalRBroadcaster.BroadcastMessage(signalRMessage);
}
protected void BroadcastResourceChange(ModelAction action)
{
var signalRMessage = new SignalRMessage
@ -66,7 +60,7 @@ namespace NzbDrone.Api
Body = new ResourceChangeMessage<TResource>(action)
};
_commandExecutor.PublishCommand(new BroadcastSignalRMessage(signalRMessage));
_signalRBroadcaster.BroadcastMessage(signalRMessage);
}
}
}

@ -2,9 +2,9 @@
using System.Linq;
using NzbDrone.Core.Datastore.Events;
using NzbDrone.Core.Download.Pending;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Queue;
using NzbDrone.SignalR;
namespace NzbDrone.Api.Queue
{
@ -14,8 +14,8 @@ namespace NzbDrone.Api.Queue
private readonly IQueueService _queueService;
private readonly IPendingReleaseService _pendingReleaseService;
public QueueModule(ICommandExecutor commandExecutor, IQueueService queueService, IPendingReleaseService pendingReleaseService)
: base(commandExecutor)
public QueueModule(IBroadcastSignalRMessage broadcastSignalRMessage, IQueueService queueService, IPendingReleaseService pendingReleaseService)
: base(broadcastSignalRMessage)
{
_queueService = queueService;
_pendingReleaseService = pendingReleaseService;

@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using FluentValidation;
using FluentValidation.Results;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.RootFolders;
using NzbDrone.Api.Mapping;
using NzbDrone.Core.Validation.Paths;
using NzbDrone.SignalR;
namespace NzbDrone.Api.RootFolders
{
@ -14,11 +12,11 @@ namespace NzbDrone.Api.RootFolders
private readonly IRootFolderService _rootFolderService;
public RootFolderModule(IRootFolderService rootFolderService,
ICommandExecutor commandExecutor,
IBroadcastSignalRMessage signalRBroadcaster,
RootFolderValidator rootFolderValidator,
PathExistsValidator pathExistsValidator,
DroneFactoryValidator droneFactoryValidator)
: base(commandExecutor)
: base(signalRBroadcaster)
{
_rootFolderService = rootFolderService;

@ -15,6 +15,7 @@ using NzbDrone.Api.Mapping;
using NzbDrone.Core.Tv.Events;
using NzbDrone.Core.Validation.Paths;
using NzbDrone.Core.DataAugmentation.Scene;
using NzbDrone.SignalR;
namespace NzbDrone.Api.Series
{
@ -31,7 +32,7 @@ namespace NzbDrone.Api.Series
private readonly ISceneMappingService _sceneMappingService;
private readonly IMapCoversToLocal _coverMapper;
public SeriesModule(ICommandExecutor commandExecutor,
public SeriesModule(IBroadcastSignalRMessage signalRBroadcaster,
ISeriesService seriesService,
ISeriesStatisticsService seriesStatisticsService,
ISceneMappingService sceneMappingService,
@ -42,7 +43,7 @@ namespace NzbDrone.Api.Series
DroneFactoryValidator droneFactoryValidator,
SeriesAncestorValidator seriesAncestorValidator
)
: base(commandExecutor)
: base(signalRBroadcaster)
{
_seriesService = seriesService;
_seriesStatisticsService = seriesStatisticsService;

@ -1,10 +1,9 @@
using System;
using System.Linq;
using System.Linq;
using NzbDrone.Api.Episodes;
using NzbDrone.Api.Extensions;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Tv;
using NzbDrone.SignalR;
namespace NzbDrone.Api.Wanted
{
@ -13,8 +12,8 @@ namespace NzbDrone.Api.Wanted
private readonly IEpisodeCutoffService _episodeCutoffService;
private readonly ISeriesRepository _seriesRepository;
public CutoffModule(IEpisodeService episodeService, IEpisodeCutoffService episodeCutoffService, ISeriesRepository seriesRepository, ICommandExecutor commandExecutor)
:base(episodeService, commandExecutor, "wanted/cutoff")
public CutoffModule(IEpisodeService episodeService, IEpisodeCutoffService episodeCutoffService, ISeriesRepository seriesRepository, IBroadcastSignalRMessage signalRBroadcaster)
: base(episodeService, signalRBroadcaster, "wanted/cutoff")
{
_episodeCutoffService = episodeCutoffService;
_seriesRepository = seriesRepository;

@ -5,6 +5,7 @@ using NzbDrone.Api.Extensions;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Tv;
using NzbDrone.SignalR;
namespace NzbDrone.Api.Wanted
{
@ -13,8 +14,8 @@ namespace NzbDrone.Api.Wanted
private readonly IEpisodeService _episodeService;
private readonly ISeriesRepository _seriesRepository;
public MissingModule(IEpisodeService episodeService, ISeriesRepository seriesRepository, ICommandExecutor commandExecutor)
:base(episodeService, commandExecutor, "wanted/missing")
public MissingModule(IEpisodeService episodeService, ISeriesRepository seriesRepository, IBroadcastSignalRMessage signalRBroadcaster)
: base(episodeService, signalRBroadcaster, "wanted/missing")
{
_episodeService = episodeService;
_seriesRepository = seriesRepository;

@ -79,8 +79,8 @@ namespace NzbDrone.Core.Test.Messaging.Commands
[Test]
public void should_return_false_when_only_one_has_null_property()
{
var command1 = new BroadcastSignalRMessage(null);
var command2 = new BroadcastSignalRMessage(new SignalRMessage());
var command1 = new EpisodeSearchCommand(null);
var command2 = new EpisodeSearchCommand(new List<int>());
CommandEqualityComparer.Instance.Equals(command1, command2).Should().BeFalse();
}

@ -102,9 +102,6 @@ namespace NzbDrone.Core.Jobs
public void Handle(CommandExecutedEvent message)
{
if (message.Command.GetType().Name == "BroadcastSignalRMessage")
return;
var scheduledTask = _scheduledTaskRepository.All().SingleOrDefault(c => c.TypeName == message.Command.GetType().FullName);
if (scheduledTask != null)
@ -122,7 +119,7 @@ namespace NzbDrone.Core.Jobs
var downloadedEpisodes = _scheduledTaskRepository.GetDefinition(typeof(DownloadedEpisodesScanCommand));
downloadedEpisodes.Interval = _configService.DownloadedEpisodesScanInterval;
_scheduledTaskRepository.UpdateMany(new List<ScheduledTask>{ rss, downloadedEpisodes });
_scheduledTaskRepository.UpdateMany(new List<ScheduledTask> { rss, downloadedEpisodes });
}
}
}

@ -1,14 +0,0 @@
using NzbDrone.Core.Messaging.Commands;
namespace NzbDrone.SignalR
{
public class BroadcastSignalRMessage : Command
{
public SignalRMessage Body { get; private set; }
public BroadcastSignalRMessage(SignalRMessage body)
{
Body = body;
}
}
}

@ -50,7 +50,6 @@
<Compile Include="..\NzbDrone.Common\Properties\SharedAssemblyInfo.cs">
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="BroadcastSignalRMessage.cs" />
<Compile Include="NoOpPerformanceCounterManager.cs" />
<Compile Include="NzbDronePersistentConnection.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

@ -4,7 +4,12 @@ using NzbDrone.Core.Messaging.Commands;
namespace NzbDrone.SignalR
{
public sealed class NzbDronePersistentConnection : PersistentConnection, IExecute<BroadcastSignalRMessage>
public interface IBroadcastSignalRMessage
{
void BroadcastMessage(SignalRMessage message);
}
public sealed class NzbDronePersistentConnection : PersistentConnection, IBroadcastSignalRMessage
{
private IPersistentConnectionContext Context
{
@ -14,9 +19,9 @@ namespace NzbDrone.SignalR
}
}
public void Execute(BroadcastSignalRMessage message)
public void BroadcastMessage(SignalRMessage message)
{
Context.Connection.Broadcast(message.Body);
Context.Connection.Broadcast(message);
}
}
}
Loading…
Cancel
Save