2019-01-06 20:50:43 +00:00
|
|
|
using Emby.Dlna.Common;
|
2016-10-29 22:22:20 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Security;
|
|
|
|
using System.Text;
|
2016-10-29 22:34:54 +00:00
|
|
|
using Emby.Dlna.Server;
|
2016-10-29 22:22:20 +00:00
|
|
|
|
2016-10-29 22:34:54 +00:00
|
|
|
namespace Emby.Dlna.Service
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
|
|
|
public class ServiceXmlBuilder
|
|
|
|
{
|
|
|
|
public string GetXml(IEnumerable<ServiceAction> actions, IEnumerable<StateVariable> stateVariables)
|
|
|
|
{
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
|
|
|
builder.Append("<?xml version=\"1.0\"?>");
|
|
|
|
builder.Append("<scpd xmlns=\"urn:schemas-upnp-org:service-1-0\">");
|
|
|
|
|
|
|
|
builder.Append("<specVersion>");
|
|
|
|
builder.Append("<major>1</major>");
|
|
|
|
builder.Append("<minor>0</minor>");
|
|
|
|
builder.Append("</specVersion>");
|
|
|
|
|
|
|
|
AppendActionList(builder, actions);
|
|
|
|
AppendServiceStateTable(builder, stateVariables);
|
|
|
|
|
|
|
|
builder.Append("</scpd>");
|
|
|
|
|
|
|
|
return builder.ToString();
|
|
|
|
}
|
|
|
|
|
2019-01-06 20:50:43 +00:00
|
|
|
private static void AppendActionList(StringBuilder builder, IEnumerable<ServiceAction> actions)
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
|
|
|
builder.Append("<actionList>");
|
|
|
|
|
|
|
|
foreach (var item in actions)
|
|
|
|
{
|
|
|
|
builder.Append("<action>");
|
|
|
|
|
|
|
|
builder.Append("<name>" + DescriptionXmlBuilder.Escape(item.Name ?? string.Empty) + "</name>");
|
|
|
|
|
|
|
|
builder.Append("<argumentList>");
|
|
|
|
|
|
|
|
foreach (var argument in item.ArgumentList)
|
|
|
|
{
|
|
|
|
builder.Append("<argument>");
|
|
|
|
|
|
|
|
builder.Append("<name>" + DescriptionXmlBuilder.Escape(argument.Name ?? string.Empty) + "</name>");
|
|
|
|
builder.Append("<direction>" + DescriptionXmlBuilder.Escape(argument.Direction ?? string.Empty) + "</direction>");
|
|
|
|
builder.Append("<relatedStateVariable>" + DescriptionXmlBuilder.Escape(argument.RelatedStateVariable ?? string.Empty) + "</relatedStateVariable>");
|
|
|
|
|
|
|
|
builder.Append("</argument>");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.Append("</argumentList>");
|
|
|
|
|
|
|
|
builder.Append("</action>");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.Append("</actionList>");
|
|
|
|
}
|
|
|
|
|
2019-01-06 20:50:43 +00:00
|
|
|
private static void AppendServiceStateTable(StringBuilder builder, IEnumerable<StateVariable> stateVariables)
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
|
|
|
builder.Append("<serviceStateTable>");
|
|
|
|
|
|
|
|
foreach (var item in stateVariables)
|
|
|
|
{
|
|
|
|
var sendEvents = item.SendsEvents ? "yes" : "no";
|
|
|
|
|
|
|
|
builder.Append("<stateVariable sendEvents=\"" + sendEvents + "\">");
|
|
|
|
|
|
|
|
builder.Append("<name>" + DescriptionXmlBuilder.Escape(item.Name ?? string.Empty) + "</name>");
|
|
|
|
builder.Append("<dataType>" + DescriptionXmlBuilder.Escape(item.DataType ?? string.Empty) + "</dataType>");
|
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
if (item.AllowedValues.Length > 0)
|
2016-10-29 22:22:20 +00:00
|
|
|
{
|
|
|
|
builder.Append("<allowedValueList>");
|
|
|
|
foreach (var allowedValue in item.AllowedValues)
|
|
|
|
{
|
|
|
|
builder.Append("<allowedValue>" + DescriptionXmlBuilder.Escape(allowedValue) + "</allowedValue>");
|
|
|
|
}
|
|
|
|
builder.Append("</allowedValueList>");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.Append("</stateVariable>");
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.Append("</serviceStateTable>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|