PersonXmlSaver.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using MediaBrowser.Controller.Configuration;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Library;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Security;
  7. using System.Text;
  8. using System.Threading;
  9. namespace MediaBrowser.LocalMetadata.Savers
  10. {
  11. /// <summary>
  12. /// Class PersonXmlSaver
  13. /// </summary>
  14. public class PersonXmlSaver : IMetadataFileSaver
  15. {
  16. public string Name
  17. {
  18. get
  19. {
  20. return XmlProviderUtils.Name;
  21. }
  22. }
  23. private readonly IServerConfigurationManager _config;
  24. public PersonXmlSaver(IServerConfigurationManager config)
  25. {
  26. _config = config;
  27. }
  28. /// <summary>
  29. /// Determines whether [is enabled for] [the specified item].
  30. /// </summary>
  31. /// <param name="item">The item.</param>
  32. /// <param name="updateType">Type of the update.</param>
  33. /// <returns><c>true</c> if [is enabled for] [the specified item]; otherwise, <c>false</c>.</returns>
  34. public bool IsEnabledFor(IHasMetadata item, ItemUpdateType updateType)
  35. {
  36. if (!item.SupportsLocalMetadata)
  37. {
  38. return false;
  39. }
  40. return item is Person && updateType >= ItemUpdateType.MetadataDownload;
  41. }
  42. /// <summary>
  43. /// Saves the specified item.
  44. /// </summary>
  45. /// <param name="item">The item.</param>
  46. /// <param name="cancellationToken">The cancellation token.</param>
  47. /// <returns>Task.</returns>
  48. public void Save(IHasMetadata item, CancellationToken cancellationToken)
  49. {
  50. var person = (Person)item;
  51. var builder = new StringBuilder();
  52. builder.Append("<Item>");
  53. XmlSaverHelpers.AddCommonNodes(person, builder);
  54. if (!string.IsNullOrEmpty(person.PlaceOfBirth))
  55. {
  56. builder.Append("<PlaceOfBirth>" + SecurityElement.Escape(person.PlaceOfBirth) + "</PlaceOfBirth>");
  57. }
  58. builder.Append("</Item>");
  59. var xmlFilePath = GetSavePath(item);
  60. XmlSaverHelpers.Save(builder, xmlFilePath, new List<string>
  61. {
  62. "PlaceOfBirth"
  63. }, _config);
  64. }
  65. /// <summary>
  66. /// Gets the save path.
  67. /// </summary>
  68. /// <param name="item">The item.</param>
  69. /// <returns>System.String.</returns>
  70. public string GetSavePath(IHasMetadata item)
  71. {
  72. return Path.Combine(item.Path, "person.xml");
  73. }
  74. }
  75. }