added user data save reason

This commit is contained in:
Luke Pulverenti 2013-10-02 13:23:10 -04:00
parent bb4c918bf8
commit 1f7bc3e61d
9 changed files with 66 additions and 13 deletions

View File

@ -1,7 +1,7 @@
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using ServiceStack.ServiceHost;
using ServiceStack.Text.Controller;
using System;
@ -228,7 +228,7 @@ namespace MediaBrowser.Api.UserLibrary
// Set favorite status
data.IsFavorite = isFavorite;
await UserDataRepository.SaveUserData(userId, key, data, CancellationToken.None).ConfigureAwait(false);
await UserDataRepository.SaveUserData(userId, key, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);
data = UserDataRepository.GetUserData(userId, key);
@ -254,7 +254,7 @@ namespace MediaBrowser.Api.UserLibrary
data.Likes = likes;
await UserDataRepository.SaveUserData(userId, key, data, CancellationToken.None).ConfigureAwait(false);
await UserDataRepository.SaveUserData(userId, key, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);
data = UserDataRepository.GetUserData(userId, key);

View File

@ -3,9 +3,9 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
using ServiceStack.ServiceHost;
using System;
@ -593,7 +593,7 @@ namespace MediaBrowser.Api.UserLibrary
// Set favorite status
data.IsFavorite = isFavorite;
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
await _userDataRepository.SaveUserData(user.Id, key, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);
data = _userDataRepository.GetUserData(user.Id, key);
@ -635,7 +635,7 @@ namespace MediaBrowser.Api.UserLibrary
data.Likes = likes;
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
await _userDataRepository.SaveUserData(user.Id, key, data, UserDataSaveReason.UpdateUserRating, CancellationToken.None).ConfigureAwait(false);
data = _userDataRepository.GetUserData(user.Id, key);

View File

@ -1349,7 +1349,7 @@ namespace MediaBrowser.Controller.Entities
data.LastPlayedDate = datePlayed ?? data.LastPlayedDate;
data.Played = true;
await userManager.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
await userManager.SaveUserData(user.Id, key, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
}
/// <summary>
@ -1378,7 +1378,7 @@ namespace MediaBrowser.Controller.Entities
data.LastPlayedDate = null;
data.Played = false;
await userManager.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
await userManager.SaveUserData(user.Id, key, data, UserDataSaveReason.TogglePlayed, CancellationToken.None).ConfigureAwait(false);
}
/// <summary>

View File

@ -1,10 +1,14 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Entities;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Library
{
/// <summary>
/// Interface IUserDataManager
/// </summary>
public interface IUserDataManager
{
/// <summary>
@ -13,9 +17,10 @@ namespace MediaBrowser.Controller.Library
/// <param name="userId">The user id.</param>
/// <param name="key">The key.</param>
/// <param name="userData">The user data.</param>
/// <param name="reason">The reason.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken);
Task SaveUserData(Guid userId, string key, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken);
/// <summary>
/// Gets the user data.

View File

@ -0,0 +1,30 @@

namespace MediaBrowser.Model.Entities
{
/// <summary>
/// Enum UserDataSaveReason
/// </summary>
public enum UserDataSaveReason
{
/// <summary>
/// The playback start
/// </summary>
PlaybackStart,
/// <summary>
/// The playback progress
/// </summary>
PlaybackProgress,
/// <summary>
/// The playback finished
/// </summary>
PlaybackFinished,
/// <summary>
/// The toggle played
/// </summary>
TogglePlayed,
/// <summary>
/// The update user rating
/// </summary>
UpdateUserRating
}
}

View File

@ -61,6 +61,7 @@
<Compile Include="Entities\ItemReview.cs" />
<Compile Include="Entities\MediaUrl.cs" />
<Compile Include="Entities\MetadataFields.cs" />
<Compile Include="Entities\UserDataSaveReason.cs" />
<Compile Include="Entities\Video3DFormat.cs" />
<Compile Include="Games\GameSystem.cs" />
<Compile Include="IO\IIsoManager.cs" />

View File

@ -1,6 +1,7 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using System;
using System.Collections.Concurrent;
@ -35,9 +36,19 @@ namespace MediaBrowser.Server.Implementations.Library
/// <param name="userId">The user id.</param>
/// <param name="key">The key.</param>
/// <param name="userData">The user data.</param>
/// <param name="reason">The reason.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
public async Task SaveUserData(Guid userId, string key, UserItemData userData, CancellationToken cancellationToken)
/// <exception cref="System.ArgumentNullException">
/// userData
/// or
/// cancellationToken
/// or
/// userId
/// or
/// key
/// </exception>
public async Task SaveUserData(Guid userId, string key, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken)
{
if (userData == null)
{

View File

@ -6,6 +6,7 @@ using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Session;
using System;
@ -252,7 +253,7 @@ namespace MediaBrowser.Server.Implementations.Session
data.Played = true;
}
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
await _userDataRepository.SaveUserData(user.Id, key, data, UserDataSaveReason.PlaybackStart, CancellationToken.None).ConfigureAwait(false);
// Nothing to save here
// Fire events to inform plugins
@ -295,7 +296,7 @@ namespace MediaBrowser.Server.Implementations.Session
var data = _userDataRepository.GetUserData(user.Id, key);
UpdatePlayState(info.Item, data, info.PositionTicks.Value);
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
await _userDataRepository.SaveUserData(user.Id, key, data, UserDataSaveReason.PlaybackProgress, CancellationToken.None).ConfigureAwait(false);
}
EventHelper.QueueEventIfNotNull(PlaybackProgress, this, new PlaybackProgressEventArgs
@ -348,7 +349,7 @@ namespace MediaBrowser.Server.Implementations.Session
data.PlaybackPositionTicks = 0;
}
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
await _userDataRepository.SaveUserData(user.Id, key, data, UserDataSaveReason.PlaybackFinished, CancellationToken.None).ConfigureAwait(false);
EventHelper.QueueEventIfNotNull(PlaybackStopped, this, new PlaybackProgressEventArgs
{

View File

@ -672,6 +672,11 @@ namespace MediaBrowser.ServerApplication
OnApplicationUpdated(package.version);
}
/// <summary>
/// Creates the HTTP client.
/// </summary>
/// <param name="enableHttpCompression">if set to <c>true</c> [enable HTTP compression].</param>
/// <returns>HttpClient.</returns>
protected override HttpClient CreateHttpClient(bool enableHttpCompression)
{
return HttpClientFactory.GetHttpClient(enableHttpCompression);