本文整理汇总了C#中BaseItem.GetUserDataKey方法的典型用法代码示例。如果您正苦于以下问题:C# BaseItem.GetUserDataKey方法的具体用法?C# BaseItem.GetUserDataKey怎么用?C# BaseItem.GetUserDataKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BaseItem
的用法示例。
在下文中一共展示了BaseItem.GetUserDataKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDate
/// <summary>
/// Gets the date.
/// </summary>
/// <param name="x">The x.</param>
/// <returns>DateTime.</returns>
private DateTime GetDate(BaseItem x)
{
var userdata = UserDataRepository.GetUserData(User.Id, x.GetUserDataKey());
if (userdata != null && userdata.LastPlayedDate.HasValue)
{
return userdata.LastPlayedDate.Value;
}
return DateTime.MinValue;
}
示例2: GetValue
/// <summary>
/// Gets the date.
/// </summary>
/// <param name="x">The x.</param>
/// <returns>DateTime.</returns>
private int GetValue(BaseItem x)
{
var userdata = UserDataRepository.GetUserData(User.Id, x.GetUserDataKey());
if (userdata == null)
{
return 0;
}
return userdata.Played ? 1 : 0;
}
示例3: SaveUserData
/// <summary>
/// Saves the user data.
/// </summary>
/// <param name="userId">The user id.</param>
/// <param name="item">The item.</param>
/// <param name="userData">The user data.</param>
/// <param name="reason">The reason.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">userData
/// or
/// cancellationToken
/// or
/// userId
/// or
/// key</exception>
public async Task SaveUserData(Guid userId, BaseItem item, UserItemData userData, UserDataSaveReason reason, CancellationToken cancellationToken)
{
if (userData == null)
{
throw new ArgumentNullException("userData");
}
if (item == null)
{
throw new ArgumentNullException("item");
}
if (userId == Guid.Empty)
{
throw new ArgumentNullException("userId");
}
cancellationToken.ThrowIfCancellationRequested();
var key = item.GetUserDataKey();
try
{
await Repository.SaveUserData(userId, key, userData, cancellationToken).ConfigureAwait(false);
var newValue = userData;
// Once it succeeds, put it into the dictionary to make it available to everyone else
_userData.AddOrUpdate(GetCacheKey(userId, key), newValue, delegate { return newValue; });
}
catch (Exception ex)
{
_logger.ErrorException("Error saving user data", ex);
throw;
}
EventHelper.FireEventIfNotNull(UserDataSaved, this, new UserDataSaveEventArgs
{
Key = key,
UserData = userData,
SaveReason = reason,
UserId = userId,
Item = item
}, _logger);
}
示例4: OnPlaybackStopped
/// <summary>
/// Used to report that playback has ended for an item
/// </summary>
/// <param name="user">The user.</param>
/// <param name="item">The item.</param>
/// <param name="positionTicks">The position ticks.</param>
/// <param name="clientType">Type of the client.</param>
/// <param name="deviceId">The device id.</param>
/// <param name="deviceName">Name of the device.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">
/// </exception>
public async Task OnPlaybackStopped(User user, BaseItem item, long? positionTicks, string clientType, string deviceId, string deviceName)
{
if (user == null)
{
throw new ArgumentNullException();
}
if (item == null)
{
throw new ArgumentNullException();
}
RemoveNowPlayingItemId(user, clientType, deviceId, deviceName, item);
var key = item.GetUserDataKey();
var data = await _userDataRepository.GetUserData(user.Id, key).ConfigureAwait(false);
if (positionTicks.HasValue)
{
UpdatePlayState(item, data, positionTicks.Value);
}
else
{
// If the client isn't able to report this, then we'll just have to make an assumption
data.PlayCount++;
data.Played = true;
}
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
EventHelper.QueueEventIfNotNull(PlaybackStopped, this, new PlaybackProgressEventArgs
{
Item = item,
User = user,
PlaybackPositionTicks = positionTicks
}, _logger);
}
示例5: OnPlaybackProgress
/// <summary>
/// Used to report playback progress for an item
/// </summary>
/// <param name="user">The user.</param>
/// <param name="item">The item.</param>
/// <param name="positionTicks">The position ticks.</param>
/// <param name="isPaused">if set to <c>true</c> [is paused].</param>
/// <param name="clientType">Type of the client.</param>
/// <param name="deviceId">The device id.</param>
/// <param name="deviceName">Name of the device.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">
/// </exception>
public async Task OnPlaybackProgress(User user, BaseItem item, long? positionTicks, bool isPaused, string clientType, string deviceId, string deviceName)
{
if (user == null)
{
throw new ArgumentNullException();
}
if (item == null)
{
throw new ArgumentNullException();
}
UpdateNowPlayingItemId(user, clientType, deviceId, deviceName, item, isPaused, positionTicks);
var key = item.GetUserDataKey();
if (positionTicks.HasValue)
{
var data = await _userDataRepository.GetUserData(user.Id, key).ConfigureAwait(false);
UpdatePlayState(item, data, positionTicks.Value);
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
}
EventHelper.QueueEventIfNotNull(PlaybackProgress, this, new PlaybackProgressEventArgs
{
Item = item,
User = user,
PlaybackPositionTicks = positionTicks
}, _logger);
}
示例6: OnPlaybackStart
/// <summary>
/// Used to report that playback has started for an item
/// </summary>
/// <param name="user">The user.</param>
/// <param name="item">The item.</param>
/// <param name="clientType">Type of the client.</param>
/// <param name="deviceId">The device id.</param>
/// <param name="deviceName">Name of the device.</param>
/// <exception cref="System.ArgumentNullException">
/// </exception>
public async Task OnPlaybackStart(User user, BaseItem item, string clientType, string deviceId, string deviceName)
{
if (user == null)
{
throw new ArgumentNullException();
}
if (item == null)
{
throw new ArgumentNullException();
}
UpdateNowPlayingItemId(user, clientType, deviceId, deviceName, item, false);
var key = item.GetUserDataKey();
var data = await _userDataRepository.GetUserData(user.Id, key).ConfigureAwait(false);
data.PlayCount++;
data.LastPlayedDate = DateTime.UtcNow;
if (!(item is Video))
{
data.Played = true;
}
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
// Nothing to save here
// Fire events to inform plugins
EventHelper.QueueEventIfNotNull(PlaybackStart, this, new PlaybackProgressEventArgs
{
Item = item,
User = user
}, _logger);
}
示例7: AttachUserSpecificInfo
/// <summary>
/// Attaches the user specific info.
/// </summary>
/// <param name="dto">The dto.</param>
/// <param name="item">The item.</param>
/// <param name="user">The user.</param>
/// <param name="fields">The fields.</param>
private void AttachUserSpecificInfo(BaseItemDto dto, BaseItem item, User user, List<ItemFields> fields)
{
if (item.IsFolder)
{
var hasItemCounts = fields.Contains(ItemFields.ItemCounts);
if (hasItemCounts || fields.Contains(ItemFields.CumulativeRunTimeTicks))
{
var folder = (Folder)item;
if (hasItemCounts)
{
dto.ChildCount = folder.GetChildren(user, true).Count();
}
SetSpecialCounts(folder, user, dto, _userDataRepository);
}
}
var userData = _userDataRepository.GetUserData(user.Id, item.GetUserDataKey());
dto.UserData = GetUserItemDataDto(userData);
if (item.IsFolder)
{
dto.UserData.Played = dto.PlayedPercentage.HasValue && dto.PlayedPercentage.Value >= 100;
}
}
示例8: AttachUserSpecificInfo
/// <summary>
/// Attaches the user specific info.
/// </summary>
/// <param name="dto">The dto.</param>
/// <param name="item">The item.</param>
/// <param name="user">The user.</param>
/// <param name="fields">The fields.</param>
/// <param name="syncProgress">The synchronize progress.</param>
private void AttachUserSpecificInfo(BaseItemDto dto, BaseItem item, User user, List<ItemFields> fields, Dictionary<string, SyncedItemProgress> syncProgress)
{
if (item.IsFolder)
{
var userData = _userDataRepository.GetUserData(user.Id, item.GetUserDataKey());
// Skip the user data manager because we've already looped through the recursive tree and don't want to do it twice
// TODO: Improve in future
dto.UserData = GetUserItemDataDto(userData);
var folder = (Folder)item;
dto.ChildCount = GetChildCount(folder, user);
// These are just far too slow.
// TODO: Disable for CollectionFolder
if (!(folder is UserRootFolder) && !(folder is UserView))
{
SetSpecialCounts(folder, user, dto, fields, syncProgress);
}
dto.UserData.Played = dto.UserData.PlayedPercentage.HasValue && dto.UserData.PlayedPercentage.Value >= 100;
}
else
{
dto.UserData = _userDataRepository.GetUserDataDto(item, user);
}
dto.PlayAccess = item.GetPlayAccess(user);
if (fields.Contains(ItemFields.SeasonUserData))
{
var episode = item as Episode;
if (episode != null)
{
var season = episode.Season;
if (season != null)
{
dto.SeasonUserData = _userDataRepository.GetUserDataDto(season, user);
}
}
}
var userView = item as UserView;
if (userView != null)
{
dto.HasDynamicCategories = userView.ContainsDynamicCategories(user);
}
var collectionFolder = item as ICollectionFolder;
if (collectionFolder != null)
{
dto.HasDynamicCategories = false;
}
}
示例9: AttachUserSpecificInfo
/// <summary>
/// Attaches the user specific info.
/// </summary>
/// <param name="dto">The dto.</param>
/// <param name="item">The item.</param>
/// <param name="user">The user.</param>
/// <param name="fields">The fields.</param>
private void AttachUserSpecificInfo(BaseItemDto dto, BaseItem item, User user, List<ItemFields> fields)
{
if (item.IsFolder)
{
var folder = (Folder)item;
dto.ChildCount = GetChildCount(folder, user);
if (!(folder is UserRootFolder))
{
SetSpecialCounts(folder, user, dto, fields);
}
}
var userData = _userDataRepository.GetUserData(user.Id, item.GetUserDataKey());
dto.UserData = GetUserItemDataDto(userData);
if (item.IsFolder)
{
dto.UserData.Played = dto.PlayedPercentage.HasValue && dto.PlayedPercentage.Value >= 100;
}
}
示例10: OnPlaybackStopped
/// <summary>
/// Used to report that playback has ended for an item
/// </summary>
/// <param name="item">The item.</param>
/// <param name="positionTicks">The position ticks.</param>
/// <param name="sessionId">The session id.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public async Task OnPlaybackStopped(BaseItem item, long? positionTicks, Guid sessionId)
{
if (item == null)
{
throw new ArgumentNullException();
}
if (positionTicks.HasValue && positionTicks.Value < 0)
{
throw new ArgumentOutOfRangeException("positionTicks");
}
var session = Sessions.First(i => i.Id.Equals(sessionId));
RemoveNowPlayingItem(session, item);
var key = item.GetUserDataKey();
var user = session.User;
var data = _userDataRepository.GetUserData(user.Id, key);
if (positionTicks.HasValue)
{
UpdatePlayState(item, data, positionTicks.Value);
}
else
{
// If the client isn't able to report this, then we'll just have to make an assumption
data.PlayCount++;
data.Played = true;
}
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
EventHelper.QueueEventIfNotNull(PlaybackStopped, this, new PlaybackProgressEventArgs
{
Item = item,
User = user,
PlaybackPositionTicks = positionTicks
}, _logger);
}
示例11: OnPlaybackProgress
/// <summary>
/// Used to report playback progress for an item
/// </summary>
/// <param name="item">The item.</param>
/// <param name="positionTicks">The position ticks.</param>
/// <param name="isPaused">if set to <c>true</c> [is paused].</param>
/// <param name="sessionId">The session id.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
/// <exception cref="System.ArgumentOutOfRangeException">positionTicks</exception>
public async Task OnPlaybackProgress(BaseItem item, long? positionTicks, bool isPaused, Guid sessionId)
{
if (item == null)
{
throw new ArgumentNullException();
}
if (positionTicks.HasValue && positionTicks.Value < 0)
{
throw new ArgumentOutOfRangeException("positionTicks");
}
var session = Sessions.First(i => i.Id.Equals(sessionId));
UpdateNowPlayingItem(session, item, isPaused, positionTicks);
var key = item.GetUserDataKey();
var user = session.User;
if (positionTicks.HasValue)
{
var data = _userDataRepository.GetUserData(user.Id, key);
UpdatePlayState(item, data, positionTicks.Value);
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
}
EventHelper.QueueEventIfNotNull(PlaybackProgress, this, new PlaybackProgressEventArgs
{
Item = item,
User = user,
PlaybackPositionTicks = positionTicks
}, _logger);
}
示例12: OnPlaybackStart
/// <summary>
/// Used to report that playback has started for an item
/// </summary>
/// <param name="item">The item.</param>
/// <param name="sessionId">The session id.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
public async Task OnPlaybackStart(BaseItem item, Guid sessionId)
{
if (item == null)
{
throw new ArgumentNullException();
}
var session = Sessions.First(i => i.Id.Equals(sessionId));
UpdateNowPlayingItem(session, item, false);
var key = item.GetUserDataKey();
var user = session.User;
var data = _userDataRepository.GetUserData(user.Id, key);
data.PlayCount++;
data.LastPlayedDate = DateTime.UtcNow;
if (!(item is Video))
{
data.Played = true;
}
await _userDataRepository.SaveUserData(user.Id, key, data, CancellationToken.None).ConfigureAwait(false);
// Nothing to save here
// Fire events to inform plugins
EventHelper.QueueEventIfNotNull(PlaybackStart, this, new PlaybackProgressEventArgs
{
Item = item,
User = user
}, _logger);
}
示例13: AttachUserSpecificInfo
/// <summary>
/// Attaches the user specific info.
/// </summary>
/// <param name="dto">The dto.</param>
/// <param name="item">The item.</param>
/// <param name="user">The user.</param>
/// <param name="fields">The fields.</param>
private void AttachUserSpecificInfo(BaseItemDto dto, BaseItem item, User user, List<ItemFields> fields)
{
if (item.IsFolder && fields.Contains(ItemFields.DisplayPreferencesId))
{
dto.DisplayPreferencesId = ((Folder)item).GetDisplayPreferencesId(user.Id).ToString();
}
if (item.IsFolder)
{
if (fields.Contains(ItemFields.ItemCounts))
{
var folder = (Folder)item;
// Skip sorting since all we want is a count
dto.ChildCount = folder.GetChildren(user, true).Count();
SetSpecialCounts(folder, user, dto, _userDataRepository);
}
}
var userData = _userDataRepository.GetUserData(user.Id, item.GetUserDataKey());
dto.UserData = GetUserItemDataDto(userData);
if (item.IsFolder)
{
dto.UserData.Played = dto.PlayedPercentage.HasValue && dto.PlayedPercentage.Value >= 100;
}
}
示例14: AddBookmarkInfo
private void AddBookmarkInfo(BaseItem item, User user, XmlElement element)
{
var userdata = _userDataManager.GetUserData(user.Id, item.GetUserDataKey());
if (userdata.PlaybackPositionTicks > 0)
{
var dcmInfo = element.OwnerDocument.CreateElement("sec", "dcmInfo", NS_SEC);
dcmInfo.InnerText = string.Format("BM={0}", Convert.ToInt32(TimeSpan.FromTicks(userdata.PlaybackPositionTicks).TotalSeconds).ToString(_usCulture));
element.AppendChild(dcmInfo);
}
}
示例15: GetValue
/// <summary>
/// Gets the date.
/// </summary>
/// <param name="x">The x.</param>
/// <returns>DateTime.</returns>
private int GetValue(BaseItem x)
{
var userdata = UserDataRepository.GetUserData(User.Id, x.GetUserDataKey());
return userdata == null ? 0 : userdata.PlayCount;
}