stub out profile edit page

This commit is contained in:
Luke Pulverenti 2014-03-26 16:14:47 -04:00
parent 6a5b64bcb4
commit 0cfc20ac08
23 changed files with 93 additions and 19 deletions

View File

@ -30,6 +30,18 @@ namespace MediaBrowser.Api
public string Id { get; set; }
}
[Route("/Dlna/Profiles/{ProfileId}", "POST", Summary = "Updates a profile")]
public class UpdateProfile : DeviceProfile, IReturnVoid
{
[ApiMember(Name = "ProfileId", Description = "Profile Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string ProfileId { get; set; }
}
[Route("/Dlna/Profiles", "POST", Summary = "Creates a profile")]
public class CreateProfile : DeviceProfile, IReturnVoid
{
}
public class DlnaService : BaseApiService
{
private readonly IDlnaManager _dlnaManager;
@ -64,5 +76,15 @@ namespace MediaBrowser.Api
{
_dlnaManager.DeleteProfile(request.Id);
}
public void Post(UpdateProfile request)
{
_dlnaManager.UpdateProfile(request);
}
public void Post(CreateProfile request)
{
_dlnaManager.CreateProfile(request);
}
}
}

View File

@ -1,4 +1,5 @@
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
@ -17,9 +18,11 @@ namespace MediaBrowser.Controller.Dlna
public string Name { get; set; }
[XmlIgnore]
[IgnoreDataMember]
public string Id { get; set; }
[XmlIgnore]
public DeviceProfileType ProfileType { get; set; }
/// <summary>
/// Gets or sets the identification.
/// </summary>

View File

@ -24,6 +24,18 @@ namespace MediaBrowser.Controller.Dlna
/// <returns>DeviceProfile.</returns>
DeviceProfile GetDefaultProfile();
/// <summary>
/// Creates the profile.
/// </summary>
/// <param name="profile">The profile.</param>
void CreateProfile(DeviceProfile profile);
/// <summary>
/// Updates the profile.
/// </summary>
/// <param name="profile">The profile.</param>
void UpdateProfile(DeviceProfile profile);
/// <summary>
/// Deletes the profile.
/// </summary>

View File

@ -35,11 +35,11 @@ namespace MediaBrowser.Dlna
{
ExtractProfilesIfNeeded();
var list = GetProfiles(UserProfilesPath)
var list = GetProfiles(UserProfilesPath, DeviceProfileType.User)
.OrderBy(i => i.Name)
.ToList();
list.AddRange(GetProfiles(SystemProfilesPath)
list.AddRange(GetProfiles(SystemProfilesPath, DeviceProfileType.System)
.OrderBy(i => i.Name));
return list;
@ -111,7 +111,13 @@ namespace MediaBrowser.Dlna
public DeviceProfile GetProfile(DeviceIdentification deviceInfo)
{
var profile = GetProfiles().FirstOrDefault(i => IsMatch(deviceInfo, i.Identification));
if (deviceInfo == null)
{
throw new ArgumentNullException("deviceInfo");
}
var profile = GetProfiles()
.FirstOrDefault(i => i.Identification != null && IsMatch(deviceInfo, i.Identification));
if (profile != null)
{
@ -127,12 +133,6 @@ namespace MediaBrowser.Dlna
private bool IsMatch(DeviceIdentification deviceInfo, DeviceIdentification profileInfo)
{
if (profileInfo == null)
{
//There are profiles without identification, ignore thoose
return false;
}
if (!string.IsNullOrWhiteSpace(profileInfo.DeviceDescription))
{
if (deviceInfo.DeviceDescription == null || !Regex.IsMatch(deviceInfo.DeviceDescription, profileInfo.DeviceDescription))
@ -192,6 +192,11 @@ namespace MediaBrowser.Dlna
public DeviceProfile GetProfile(IDictionary<string, string> headers)
{
if (headers == null)
{
throw new ArgumentNullException("headers");
}
return GetProfiles().FirstOrDefault(i => IsMatch(headers, i.Identification));
}
@ -238,14 +243,14 @@ namespace MediaBrowser.Dlna
}
}
private IEnumerable<DeviceProfile> GetProfiles(string path)
private IEnumerable<DeviceProfile> GetProfiles(string path, DeviceProfileType type)
{
try
{
return new DirectoryInfo(path)
.EnumerateFiles("*", SearchOption.TopDirectoryOnly)
.Where(i => string.Equals(i.Extension, ".xml", StringComparison.OrdinalIgnoreCase))
.Select(i => ParseProfileXmlFile(i.FullName))
.Select(i => ParseProfileXmlFile(i.FullName, type))
.Where(i => i != null)
.ToList();
}
@ -255,13 +260,14 @@ namespace MediaBrowser.Dlna
}
}
private DeviceProfile ParseProfileXmlFile(string path)
private DeviceProfile ParseProfileXmlFile(string path, DeviceProfileType type)
{
try
{
var profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);
profile.Id = path.ToLower().GetMD5().ToString("N");
profile.ProfileType = type;
return profile;
}
@ -275,9 +281,14 @@ namespace MediaBrowser.Dlna
public DeviceProfile GetProfile(string id)
{
if (string.IsNullOrWhiteSpace(id))
{
throw new ArgumentNullException("id");
}
var info = GetProfileInfosInternal().First(i => string.Equals(i.Info.Id, id));
return ParseProfileXmlFile(info.Path);
return ParseProfileXmlFile(info.Path, info.Info.Type);
}
private IEnumerable<InternalProfileInfo> GetProfileInfosInternal()
@ -368,6 +379,14 @@ namespace MediaBrowser.Dlna
File.Delete(info.Path);
}
public void CreateProfile(DeviceProfile profile)
{
}
public void UpdateProfile(DeviceProfile profile)
{
}
class InternalProfileInfo
{
internal DeviceProfileInfo Info { get; set; }

View File

@ -8,10 +8,11 @@ namespace MediaBrowser.Dlna.Profiles
{
public DefaultProfile()
{
Name = "Media Browser";
Name = "Generic Device";
ProtocolInfo = "DLNA";
FriendlyName = "Media Browser";
Manufacturer = "Media Browser";
ModelDescription = "Media Browser";
ModelName = "Media Browser";

View File

@ -1,5 +1,5 @@
using System.Xml.Serialization;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Dlna;
using System.Xml.Serialization;
namespace MediaBrowser.Dlna.Profiles
{

View File

@ -1,6 +1,7 @@
<?xml version="1.0"?>
<Profile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>Media Browser</Name>
<Name>Generic Device</Name>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Media Browser</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Media Browser</ModelName>

View File

@ -6,6 +6,7 @@
<Manufacturer>Denon</Manufacturer>
<Headers />
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Media Browser</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Media Browser</ModelName>

View File

@ -7,6 +7,7 @@
<HttpHeaderInfo name="User-Agent" value="LG" match="Substring" />
</Headers>
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Media Browser</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Media Browser</ModelName>

View File

@ -5,6 +5,7 @@
<ModelName>DMA2100us</ModelName>
<Headers />
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Media Browser</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Media Browser</ModelName>

View File

@ -8,6 +8,7 @@
<HttpHeaderInfo name="User-Agent" value="Panasonic MIL DLNA" match="Substring" />
</Headers>
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Media Browser</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Media Browser</ModelName>

View File

@ -5,6 +5,7 @@
<ModelUrl>samsung.com</ModelUrl>
<Headers />
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Media Browser</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Media Browser</ModelName>

View File

@ -7,6 +7,7 @@
<Manufacturer>Sony</Manufacturer>
<Headers />
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName>

View File

@ -9,6 +9,7 @@
<HttpHeaderInfo name="X-AV-Physical-Unit-Info" value="(Blu-ray Disc Player|Home Theater System|Home Theatre System|Media Player)" match="Regex" />
</Headers>
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName>

View File

@ -8,6 +8,7 @@
<HttpHeaderInfo name="X-AV-Client-Info" value=".*KDL-\d{2}[EHLNPB]X\d[01]\d.*" match="Regex" />
</Headers>
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName>

View File

@ -8,6 +8,7 @@
<HttpHeaderInfo name="X-AV-Client-Info" value=".*KDL-\d{2}([A-Z]X\d2\d|CX400).*" match="Regex" />
</Headers>
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName>

View File

@ -8,6 +8,7 @@
<HttpHeaderInfo name="X-AV-Client-Info" value=".*KDL-\d{2}[A-Z]X\d5(\d|G).*" match="Regex" />
</Headers>
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName>

View File

@ -8,6 +8,7 @@
<HttpHeaderInfo name="X-AV-Client-Info" value=".*KDL-\d{2}[WR][5689]\d{2}A.*" match="Regex" />
</Headers>
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName>

View File

@ -8,6 +8,7 @@
<HttpHeaderInfo name="X-AV-Client-Info" value="PLAYSTATION 3" match="Substring" />
</Headers>
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Media Browser</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Media Browser</ModelName>

View File

@ -8,6 +8,7 @@
<HttpHeaderInfo name="User-Agent" value="ALPHA Networks" match="Substring" />
</Headers>
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Media Browser</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Media Browser</ModelName>

View File

@ -8,6 +8,7 @@
<HttpHeaderInfo name="User-Agent" value="Xenon" match="Substring" />
</Headers>
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName>

View File

@ -6,6 +6,7 @@
<ModelName>Xbox One</ModelName>
<Headers />
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Media Browser</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Media Browser</ModelName>

View File

@ -7,6 +7,7 @@
<HttpHeaderInfo name="User-Agent" value="foobar" match="Substring" />
</Headers>
</Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Media Browser</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Media Browser</ModelName>