sync updates

This commit is contained in:
Luke Pulverenti 2015-02-04 15:16:23 -05:00
parent e6ea26e3de
commit 046a1de253
13 changed files with 173 additions and 12 deletions

View File

@ -130,6 +130,7 @@
<Compile Include="SearchService.cs" />
<Compile Include="Session\SessionsService.cs" />
<Compile Include="SimilarItemsHelper.cs" />
<Compile Include="Sync\SyncJobsWebSocketListener.cs" />
<Compile Include="Sync\SyncService.cs" />
<Compile Include="System\ActivityLogService.cs" />
<Compile Include="System\ActivityLogWebSocketListener.cs" />

View File

@ -1,5 +1,4 @@
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Logging;

View File

@ -0,0 +1,101 @@
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Sync;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Sync;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MediaBrowser.Api.Sync
{
/// <summary>
/// Class SessionInfoWebSocketListener
/// </summary>
class SyncJobsWebSocketListener : BasePeriodicWebSocketListener<IEnumerable<SyncJob>, WebSocketListenerState>
{
/// <summary>
/// Gets the name.
/// </summary>
/// <value>The name.</value>
protected override string Name
{
get { return "SyncJobs"; }
}
private readonly ISyncManager _syncManager;
private string _userId;
private string _targetId;
public SyncJobsWebSocketListener(ILogger logger, ISyncManager syncManager)
: base(logger)
{
_syncManager = syncManager;
_syncManager.SyncJobCancelled += _syncManager_SyncJobCancelled;
_syncManager.SyncJobCreated += _syncManager_SyncJobCreated;
_syncManager.SyncJobUpdated += _syncManager_SyncJobUpdated;
}
protected override void ParseMessageParams(string[] values)
{
base.ParseMessageParams(values);
if (values.Length > 0)
{
_userId = values[0];
}
if (values.Length > 1)
{
_targetId = values[1];
}
}
void _syncManager_SyncJobUpdated(object sender, Model.Events.GenericEventArgs<SyncJob> e)
{
SendData(false);
}
void _syncManager_SyncJobCreated(object sender, Model.Events.GenericEventArgs<SyncJobCreationResult> e)
{
SendData(true);
}
void _syncManager_SyncJobCancelled(object sender, Model.Events.GenericEventArgs<SyncJob> e)
{
SendData(true);
}
/// <summary>
/// Gets the data to send.
/// </summary>
/// <param name="state">The state.</param>
/// <returns>Task{SystemInfo}.</returns>
protected override async Task<IEnumerable<SyncJob>> GetDataToSend(WebSocketListenerState state)
{
var jobs = await _syncManager.GetJobs(new SyncJobQuery
{
UserId = _userId,
TargetId = _targetId
}).ConfigureAwait(false);
return jobs.Items;
}
protected override bool SendOnTimer
{
get
{
return false;
}
}
protected override void Dispose(bool dispose)
{
_syncManager.SyncJobCancelled -= _syncManager_SyncJobCancelled;
_syncManager.SyncJobCreated -= _syncManager_SyncJobCreated;
_syncManager.SyncJobUpdated -= _syncManager_SyncJobUpdated;
base.Dispose(dispose);
}
}
}

View File

@ -93,6 +93,11 @@ namespace MediaBrowser.Controller.Net
}
}
protected virtual void ParseMessageParams(string[] values)
{
}
/// <summary>
/// Starts sending messages over a web socket
/// </summary>
@ -104,6 +109,11 @@ namespace MediaBrowser.Controller.Net
var dueTimeMs = long.Parse(vals[0], UsCulture);
var periodMs = long.Parse(vals[1], UsCulture);
if (vals.Length > 2)
{
ParseMessageParams(vals.Skip(2).ToArray());
}
var cancellationTokenSource = new CancellationTokenSource();
Logger.Info("{1} Begin transmitting over websocket to {0}", message.Connection.RemoteEndPoint, GetType().Name);

View File

@ -893,6 +893,22 @@ namespace MediaBrowser.Model.ApiClient
/// <param name="keepExistingAuth">if set to <c>true</c> [keep existing authentication].</param>
void ChangeServerLocation(string address, bool keepExistingAuth = false);
/// <summary>
/// Starts the receiving synchronize jobs updates.
/// </summary>
/// <param name="intervalMs">The interval ms.</param>
/// <param name="userId">The user identifier.</param>
/// <param name="targetId">The target identifier.</param>
/// <returns>Task.</returns>
Task StartReceivingSyncJobsUpdates(int intervalMs, string userId, string targetId);
/// <summary>
/// Stops the receiving synchronize jobs updates.
/// </summary>
/// <param name="intervalMs">The interval ms.</param>
/// <returns>Task.</returns>
Task StopReceivingSyncJobsUpdates(int intervalMs);
/// <summary>
/// Starts the receiving session updates.
/// </summary>

View File

@ -7,6 +7,7 @@ using MediaBrowser.Model.Sync;
using MediaBrowser.Model.Tasks;
using MediaBrowser.Model.Updates;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Model.ApiClient
{
@ -139,5 +140,9 @@ namespace MediaBrowser.Model.ApiClient
/// Occurs when [synchronize job cancelled].
/// </summary>
event EventHandler<GenericEventArgs<SyncJob>> SyncJobCancelled;
/// <summary>
/// Occurs when [synchronize jobs updated].
/// </summary>
event EventHandler<GenericEventArgs<List<SyncJob>>> SyncJobsUpdated;
}
}

View File

@ -16,6 +16,11 @@ namespace MediaBrowser.Model.Sync
/// <value>The device identifier.</value>
public string TargetId { get; set; }
/// <summary>
/// Gets or sets the name of the target.
/// </summary>
/// <value>The name of the target.</value>
public string TargetName { get; set; }
/// <summary>
/// Gets or sets the quality.
/// </summary>
/// <value>The quality.</value>

View File

@ -144,7 +144,7 @@ namespace MediaBrowser.Server.Implementations.Sync
return UpdateJobStatus(job, result.Items.ToList());
}
private Task UpdateJobStatus(SyncJob job, List<SyncJobItem> jobItems)
private async Task UpdateJobStatus(SyncJob job, List<SyncJobItem> jobItems)
{
job.ItemCount = jobItems.Count;
@ -204,7 +204,9 @@ namespace MediaBrowser.Server.Implementations.Sync
job.Status = SyncJobStatus.Transferring;
}
return _syncRepo.Update(job);
await _syncRepo.Update(job).ConfigureAwait(false);
((SyncManager)_syncManager).OnSyncJobUpdated(job);
}
public async Task<IEnumerable<BaseItem>> GetItemsForSync(SyncCategory? category, string parentId, IEnumerable<string> itemIds, User user, bool unwatchedOnly)

View File

@ -174,7 +174,7 @@ namespace MediaBrowser.Server.Implementations.Sync
return returnResult;
}
public Task UpdateJob(SyncJob job)
public async Task UpdateJob(SyncJob job)
{
// Get fresh from the db and only update the fields that are supported to be changed.
var instance = _repo.GetJob(job.Id);
@ -185,7 +185,21 @@ namespace MediaBrowser.Server.Implementations.Sync
instance.SyncNewContent = job.SyncNewContent;
instance.ItemLimit = job.ItemLimit;
return _repo.Update(instance);
await _repo.Update(instance).ConfigureAwait(false);
OnSyncJobUpdated(instance);
}
internal void OnSyncJobUpdated(SyncJob job)
{
if (SyncJobUpdated != null)
{
EventHelper.FireEventIfNotNull(SyncJobUpdated, this, new GenericEventArgs<SyncJob>
{
Argument = job
}, _logger);
}
}
public async Task<QueryResult<SyncJob>> GetJobs(SyncJobQuery query)
@ -202,6 +216,14 @@ namespace MediaBrowser.Server.Implementations.Sync
private async Task FillMetadata(SyncJob job)
{
var target = GetSyncTargets(job.UserId)
.FirstOrDefault(i => string.Equals(i.Id, job.TargetId, StringComparison.OrdinalIgnoreCase));
if (target != null)
{
job.TargetName = target.Name;
}
var item = job.RequestedItemIds
.Select(_libraryManager.GetItemById)
.FirstOrDefault(i => i != null);

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.556</version>
<version>3.0.559</version>
<title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.556" />
<dependency id="MediaBrowser.Common" version="3.0.559" />
<dependency id="NLog" version="3.1.0.0" />
<dependency id="SimpleInjector" version="2.6.1" />
</dependencies>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common</id>
<version>3.0.556</version>
<version>3.0.559</version>
<title>MediaBrowser.Common</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Model.Signed</id>
<version>3.0.556</version>
<version>3.0.559</version>
<title>MediaBrowser.Model - Signed Edition</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Server.Core</id>
<version>3.0.556</version>
<version>3.0.559</version>
<title>Media Browser.Server.Core</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Media Browser Server.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.556" />
<dependency id="MediaBrowser.Common" version="3.0.559" />
</dependencies>
</metadata>
<files>