ControlHandler.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Xml;
  4. using Emby.Dlna.Service;
  5. using MediaBrowser.Common.Extensions;
  6. using MediaBrowser.Controller.Configuration;
  7. using Microsoft.Extensions.Logging;
  8. namespace Emby.Dlna.MediaReceiverRegistrar
  9. {
  10. /// <summary>
  11. /// Defines the <see cref="ControlHandler" />.
  12. /// </summary>
  13. public class ControlHandler : BaseControlHandler
  14. {
  15. /// <summary>
  16. /// Initializes a new instance of the <see cref="ControlHandler"/> class.
  17. /// </summary>
  18. /// <param name="config">The <see cref="IServerConfigurationManager"/> for use with the <see cref="ControlHandler"/> instance.</param>
  19. /// <param name="logger">The <see cref="ILogger"/> for use with the <see cref="ControlHandler"/> instance.</param>
  20. public ControlHandler(IServerConfigurationManager config, ILogger logger)
  21. : base(config, logger)
  22. {
  23. }
  24. /// <inheritdoc />
  25. protected override void WriteResult(string methodName, IDictionary<string, string> methodParams, XmlWriter xmlWriter)
  26. {
  27. if (string.Equals(methodName, "IsAuthorized", StringComparison.OrdinalIgnoreCase))
  28. {
  29. HandleIsAuthorized(xmlWriter);
  30. return;
  31. }
  32. if (string.Equals(methodName, "IsValidated", StringComparison.OrdinalIgnoreCase))
  33. {
  34. HandleIsValidated(xmlWriter);
  35. return;
  36. }
  37. throw new ResourceNotFoundException("Unexpected control request name: " + methodName);
  38. }
  39. /// <summary>
  40. /// Records that the handle is authorized in the xml stream.
  41. /// </summary>
  42. /// <param name="xmlWriter">The <see cref="XmlWriter"/>.</param>
  43. private static void HandleIsAuthorized(XmlWriter xmlWriter)
  44. => xmlWriter.WriteElementString("Result", "1");
  45. /// <summary>
  46. /// Records that the handle is validated in the xml stream.
  47. /// </summary>
  48. /// <param name="xmlWriter">The <see cref="XmlWriter"/>.</param>
  49. private static void HandleIsValidated(XmlWriter xmlWriter)
  50. => xmlWriter.WriteElementString("Result", "1");
  51. }
  52. }