Year.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Runtime.Serialization;
  6. namespace MediaBrowser.Controller.Entities
  7. {
  8. /// <summary>
  9. /// Class Year
  10. /// </summary>
  11. public class Year : BaseItem, IItemByName
  12. {
  13. /// <summary>
  14. /// Gets the user data key.
  15. /// </summary>
  16. /// <returns>System.String.</returns>
  17. protected override string CreateUserDataKey()
  18. {
  19. return "Year-" + Name;
  20. }
  21. /// <summary>
  22. /// Returns the folder containing the item.
  23. /// If the item is a folder, it returns the folder itself
  24. /// </summary>
  25. /// <value>The containing folder path.</value>
  26. [IgnoreDataMember]
  27. public override string ContainingFolderPath
  28. {
  29. get
  30. {
  31. return Path;
  32. }
  33. }
  34. public override bool CanDelete()
  35. {
  36. return false;
  37. }
  38. /// <summary>
  39. /// Gets a value indicating whether this instance is owned item.
  40. /// </summary>
  41. /// <value><c>true</c> if this instance is owned item; otherwise, <c>false</c>.</value>
  42. [IgnoreDataMember]
  43. public override bool IsOwnedItem
  44. {
  45. get
  46. {
  47. return false;
  48. }
  49. }
  50. public override bool IsSaveLocalMetadataEnabled()
  51. {
  52. return true;
  53. }
  54. public IEnumerable<BaseItem> GetTaggedItems(IEnumerable<BaseItem> inputItems)
  55. {
  56. int year;
  57. var usCulture = new CultureInfo("en-US");
  58. if (!int.TryParse(Name, NumberStyles.Integer, usCulture, out year))
  59. {
  60. return inputItems;
  61. }
  62. return inputItems.Where(i => i.ProductionYear.HasValue && i.ProductionYear.Value == year);
  63. }
  64. public int? GetYearValue()
  65. {
  66. int i;
  67. if (int.TryParse(Name, NumberStyles.Integer, CultureInfo.InvariantCulture, out i))
  68. {
  69. return i;
  70. }
  71. return null;
  72. }
  73. public Func<BaseItem, bool> GetItemFilter()
  74. {
  75. var val = GetYearValue();
  76. return i => i.ProductionYear.HasValue && val.HasValue && i.ProductionYear.Value == val.Value;
  77. }
  78. [IgnoreDataMember]
  79. public override bool SupportsPeople
  80. {
  81. get
  82. {
  83. return false;
  84. }
  85. }
  86. }
  87. }