ControlHandler.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Xml;
  5. using Emby.Dlna.Service;
  6. using MediaBrowser.Common.Extensions;
  7. using MediaBrowser.Controller.Configuration;
  8. using MediaBrowser.Model.Dlna;
  9. using Microsoft.Extensions.Logging;
  10. namespace Emby.Dlna.ConnectionManager
  11. {
  12. /// <summary>
  13. /// Defines the <see cref="ControlHandler" />.
  14. /// </summary>
  15. public class ControlHandler : BaseControlHandler
  16. {
  17. private readonly DeviceProfile _profile;
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="ControlHandler"/> class.
  20. /// </summary>
  21. /// <param name="config">The <see cref="IServerConfigurationManager"/> for use with the <see cref="ControlHandler"/> instance.</param>
  22. /// <param name="logger">The <see cref="ILogger"/> for use with the <see cref="ControlHandler"/> instance.</param>
  23. /// <param name="profile">The <see cref="DeviceProfile"/> for use with the <see cref="ControlHandler"/> instance.</param>
  24. public ControlHandler(IServerConfigurationManager config, ILogger logger, DeviceProfile profile)
  25. : base(config, logger)
  26. {
  27. _profile = profile;
  28. }
  29. /// <inheritdoc />
  30. protected override void WriteResult(string methodName, IDictionary<string, string> methodParams, XmlWriter xmlWriter)
  31. {
  32. if (string.Equals(methodName, "GetProtocolInfo", StringComparison.OrdinalIgnoreCase))
  33. {
  34. HandleGetProtocolInfo(xmlWriter);
  35. return;
  36. }
  37. throw new ResourceNotFoundException("Unexpected control request name: " + methodName);
  38. }
  39. /// <summary>
  40. /// Builds the response to the GetProtocolInfo request.
  41. /// </summary>
  42. /// <param name="xmlWriter">The <see cref="XmlWriter"/>.</param>
  43. private void HandleGetProtocolInfo(XmlWriter xmlWriter)
  44. {
  45. xmlWriter.WriteElementString("Source", _profile.ProtocolInfo);
  46. xmlWriter.WriteElementString("Sink", string.Empty);
  47. }
  48. }
  49. }