2013-04-13 11:02:30 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Model.Dto;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
|
|
|
|
using System;
|
2013-04-17 15:30:20 -07:00
|
|
|
|
using System.Threading.Tasks;
|
2013-04-13 11:02:30 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Controller.Dto
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UserDtoBuilder
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class UserDtoBuilder
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _logger
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="UserDtoBuilder"/> class.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger">The logger.</param>
|
|
|
|
|
public UserDtoBuilder(ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converts a User to a DTOUser
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="user">The user.</param>
|
|
|
|
|
/// <returns>DtoUser.</returns>
|
|
|
|
|
/// <exception cref="System.ArgumentNullException">user</exception>
|
2013-04-17 15:30:20 -07:00
|
|
|
|
public async Task<UserDto> GetUserDto(User user)
|
2013-04-13 11:02:30 -07:00
|
|
|
|
{
|
|
|
|
|
if (user == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("user");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dto = new UserDto
|
|
|
|
|
{
|
|
|
|
|
Id = user.Id.ToString(),
|
|
|
|
|
Name = user.Name,
|
|
|
|
|
HasPassword = !String.IsNullOrEmpty(user.Password),
|
|
|
|
|
LastActivityDate = user.LastActivityDate,
|
|
|
|
|
LastLoginDate = user.LastLoginDate,
|
|
|
|
|
Configuration = user.Configuration
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var image = user.PrimaryImagePath;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(image))
|
|
|
|
|
{
|
|
|
|
|
dto.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(user, ImageType.Primary, image);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-04-17 15:30:20 -07:00
|
|
|
|
await DtoBuilder.AttachPrimaryImageAspectRatio(dto, user, _logger).ConfigureAwait(false);
|
2013-04-13 11:02:30 -07:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
// Have to use a catch-all unfortunately because some .net image methods throw plain Exceptions
|
|
|
|
|
_logger.ErrorException("Error generating PrimaryImageAspectRatio for {0}", ex, user.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|