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; } 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 public class DlnaService : BaseApiService
{ {
private readonly IDlnaManager _dlnaManager; private readonly IDlnaManager _dlnaManager;
@ -64,5 +76,15 @@ namespace MediaBrowser.Api
{ {
_dlnaManager.DeleteProfile(request.Id); _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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -17,9 +18,11 @@ namespace MediaBrowser.Controller.Dlna
public string Name { get; set; } public string Name { get; set; }
[XmlIgnore] [XmlIgnore]
[IgnoreDataMember]
public string Id { get; set; } public string Id { get; set; }
[XmlIgnore]
public DeviceProfileType ProfileType { get; set; }
/// <summary> /// <summary>
/// Gets or sets the identification. /// Gets or sets the identification.
/// </summary> /// </summary>

View File

@ -24,6 +24,18 @@ namespace MediaBrowser.Controller.Dlna
/// <returns>DeviceProfile.</returns> /// <returns>DeviceProfile.</returns>
DeviceProfile GetDefaultProfile(); 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> /// <summary>
/// Deletes the profile. /// Deletes the profile.
/// </summary> /// </summary>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,6 +7,7 @@
<Manufacturer>Sony</Manufacturer> <Manufacturer>Sony</Manufacturer>
<Headers /> <Headers />
</Identification> </Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer> <Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl> <ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName> <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" /> <HttpHeaderInfo name="X-AV-Physical-Unit-Info" value="(Blu-ray Disc Player|Home Theater System|Home Theatre System|Media Player)" match="Regex" />
</Headers> </Headers>
</Identification> </Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer> <Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl> <ManufacturerUrl>http://mediabrowser3.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName> <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" /> <HttpHeaderInfo name="X-AV-Client-Info" value=".*KDL-\d{2}[EHLNPB]X\d[01]\d.*" match="Regex" />
</Headers> </Headers>
</Identification> </Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer> <Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl> <ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName> <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" /> <HttpHeaderInfo name="X-AV-Client-Info" value=".*KDL-\d{2}([A-Z]X\d2\d|CX400).*" match="Regex" />
</Headers> </Headers>
</Identification> </Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer> <Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl> <ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName> <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" /> <HttpHeaderInfo name="X-AV-Client-Info" value=".*KDL-\d{2}[A-Z]X\d5(\d|G).*" match="Regex" />
</Headers> </Headers>
</Identification> </Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer> <Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl> <ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName> <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" /> <HttpHeaderInfo name="X-AV-Client-Info" value=".*KDL-\d{2}[WR][5689]\d{2}A.*" match="Regex" />
</Headers> </Headers>
</Identification> </Identification>
<FriendlyName>Media Browser</FriendlyName>
<Manufacturer>Microsoft Corporation</Manufacturer> <Manufacturer>Microsoft Corporation</Manufacturer>
<ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl> <ManufacturerUrl>http://www.microsoft.com/</ManufacturerUrl>
<ModelName>Windows Media Player Sharing</ModelName> <ModelName>Windows Media Player Sharing</ModelName>

View File

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

View File

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

View File

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

View File

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

View File

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