added studio dto

This commit is contained in:
Luke Pulverenti 2013-05-03 23:13:28 -04:00
parent 8290f04e0f
commit 163a1bdbcb
6 changed files with 106 additions and 9 deletions

View File

@ -63,7 +63,7 @@ namespace MediaBrowser.Controller.Dto
if (fields.Contains(ItemFields.Studios)) if (fields.Contains(ItemFields.Studios))
{ {
dto.Studios = item.Studios; tasks.Add(AttachStudios(dto, item));
} }
if (fields.Contains(ItemFields.People)) if (fields.Contains(ItemFields.People))
@ -124,7 +124,7 @@ namespace MediaBrowser.Controller.Dto
if (fields.Contains(ItemFields.Studios)) if (fields.Contains(ItemFields.Studios))
{ {
dto.Studios = item.Studios; tasks.Add(AttachStudios(dto, item));
} }
if (fields.Contains(ItemFields.People)) if (fields.Contains(ItemFields.People))
@ -644,6 +644,67 @@ namespace MediaBrowser.Controller.Dto
} }
} }
/// <summary>
/// Attaches the studios.
/// </summary>
/// <param name="dto">The dto.</param>
/// <param name="item">The item.</param>
/// <returns>Task.</returns>
private async Task AttachStudios(BaseItemDto dto, BaseItem item)
{
if (item.Studios == null)
{
return;
}
var studios = item.Studios.ToList();
dto.Studios = new StudioDto[studios.Count];
var entities = await Task.WhenAll(studios.Distinct(StringComparer.OrdinalIgnoreCase).Select(c =>
Task.Run(async () =>
{
try
{
return await _libraryManager.GetStudio(c).ConfigureAwait(false);
}
catch (IOException ex)
{
_logger.ErrorException("Error getting studio {0}", ex, c);
return null;
}
})
)).ConfigureAwait(false);
var dictionary = entities.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
for (var i = 0; i < studios.Count; i++)
{
var studio = studios[i];
var studioDto = new StudioDto
{
Name = studio
};
Studio entity;
if (dictionary.TryGetValue(studio, out entity))
{
var primaryImagePath = entity.PrimaryImagePath;
if (!string.IsNullOrEmpty(primaryImagePath))
{
studioDto.PrimaryImageTag = Kernel.Instance.ImageManager.GetImageCacheTag(entity, ImageType.Primary, primaryImagePath);
}
}
dto.Studios[i] = studioDto;
}
}
/// <summary> /// <summary>
/// If an item does not any backdrops, this can be used to find the first parent that does have one /// If an item does not any backdrops, this can be used to find the first parent that does have one
/// </summary> /// </summary>

View File

@ -160,7 +160,7 @@ namespace MediaBrowser.Model.Dto
/// Gets or sets the studios. /// Gets or sets the studios.
/// </summary> /// </summary>
/// <value>The studios.</value> /// <value>The studios.</value>
public List<string> Studios { get; set; } public StudioDto[] Studios { get; set; }
/// <summary> /// <summary>
/// If the item does not have a logo, this will hold the Id of the Parent that has one. /// If the item does not have a logo, this will hold the Id of the Parent that has one.

View File

@ -51,4 +51,40 @@ namespace MediaBrowser.Model.Dto
/// </summary> /// </summary>
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
} }
/// <summary>
/// Class StudioDto
/// </summary>
public class StudioDto
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name { get; set; }
/// <summary>
/// Gets or sets the primary image tag.
/// </summary>
/// <value>The primary image tag.</value>
public Guid? PrimaryImageTag { get; set; }
/// <summary>
/// Gets a value indicating whether this instance has primary image.
/// </summary>
/// <value><c>true</c> if this instance has primary image; otherwise, <c>false</c>.</value>
[IgnoreDataMember]
public bool HasPrimaryImage
{
get
{
return PrimaryImageTag.HasValue;
}
}
/// <summary>
/// Occurs when [property changed].
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
}
} }

View File

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

View File

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

View File

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