123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- using MediaBrowser.Dlna.Common;
- using MediaBrowser.Model.Dlna;
- using System.Collections.Generic;
- using System.Security;
- using System.Text;
- namespace MediaBrowser.Dlna.Server
- {
- public class ContentDirectoryXmlBuilder
- {
- private readonly DeviceProfile _profile;
- public ContentDirectoryXmlBuilder(DeviceProfile profile)
- {
- _profile = profile;
- }
- public string GetXml()
- {
- 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);
- AppendServiceStateTable(builder);
- builder.Append("</scpd>");
- return builder.ToString();
- }
- private void AppendActionList(StringBuilder builder)
- {
- builder.Append("<actionList>");
- foreach (var item in new ServiceActionListBuilder().GetActions())
- {
- builder.Append("<action>");
- builder.Append("<name>" + SecurityElement.Escape(item.Name ?? string.Empty) + "</name>");
- builder.Append("<argumentList>");
- foreach (var argument in item.ArgumentList)
- {
- builder.Append("<argument>");
- builder.Append("<name>" + SecurityElement.Escape(argument.Name ?? string.Empty) + "</name>");
- builder.Append("<direction>" + SecurityElement.Escape(argument.Direction ?? string.Empty) + "</direction>");
- builder.Append("<relatedStateVariable>" + SecurityElement.Escape(argument.RelatedStateVariable ?? string.Empty) + "</relatedStateVariable>");
-
- builder.Append("</argument>");
- }
- builder.Append("</argumentList>");
-
- builder.Append("</action>");
- }
-
- builder.Append("</actionList>");
- }
- private void AppendServiceStateTable(StringBuilder builder)
- {
- builder.Append("<serviceStateTable>");
- foreach (var item in GetStateVariables())
- {
- var sendEvents = item.SendsEvents ? "yes" : "no";
- builder.Append("<stateVariable sendEvents=\"" + sendEvents + "\">");
- builder.Append("<name>" + SecurityElement.Escape(item.Name ?? string.Empty) + "</name>");
- builder.Append("<dataType>" + SecurityElement.Escape(item.DataType ?? string.Empty) + "</dataType>");
- if (item.AllowedValues.Count > 0)
- {
- builder.Append("<allowedValueList>");
- foreach (var allowedValue in item.AllowedValues)
- {
- builder.Append("<allowedValue>" + SecurityElement.Escape(allowedValue) + "</allowedValue>");
- }
- builder.Append("</allowedValueList>");
- }
- builder.Append("</stateVariable>");
- }
- builder.Append("</serviceStateTable>");
- }
- private IEnumerable<StateVariable> GetStateVariables()
- {
- var list = new List<StateVariable>();
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_SortCriteria",
- DataType = "string",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_UpdateID",
- DataType = "ui4",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_SearchCriteria",
- DataType = "string",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_Filter",
- DataType = "string",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_Result",
- DataType = "string",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_Index",
- DataType = "ui4",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_ObjectID",
- DataType = "string",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "SortCapabilities",
- DataType = "string",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "SearchCapabilities",
- DataType = "string",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_Count",
- DataType = "ui4",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_BrowseFlag",
- DataType = "string",
- SendsEvents = false,
- AllowedValues = new List<string>
- {
- "BrowseMetadata",
- "BrowseDirectChildren"
- }
- });
- list.Add(new StateVariable
- {
- Name = "SystemUpdateID",
- DataType = "ui4",
- SendsEvents = true
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_BrowseLetter",
- DataType = "string",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_CategoryType",
- DataType = "ui4",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_RID",
- DataType = "ui4",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_PosSec",
- DataType = "ui4",
- SendsEvents = false
- });
- list.Add(new StateVariable
- {
- Name = "A_ARG_TYPE_Featurelist",
- DataType = "string",
- SendsEvents = false
- });
-
- return list;
- }
- public override string ToString()
- {
- return GetXml();
- }
- }
- }
|