BaseEntity.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Controller.IO;
  6. using MediaBrowser.Controller.Providers;
  7. namespace MediaBrowser.Controller.Entities
  8. {
  9. /// <summary>
  10. /// Provides a base entity for all of our types
  11. /// </summary>
  12. public abstract class BaseEntity
  13. {
  14. public string Name { get; set; }
  15. public Guid Id { get; set; }
  16. public string Path { get; set; }
  17. public Folder Parent { get; set; }
  18. public string PrimaryImagePath { get; set; }
  19. public DateTime DateCreated { get; set; }
  20. public DateTime DateModified { get; set; }
  21. public override string ToString()
  22. {
  23. return Name;
  24. }
  25. protected Dictionary<Guid, BaseProviderInfo> _providerData;
  26. /// <summary>
  27. /// Holds persistent data for providers like last refresh date.
  28. /// Providers can use this to determine if they need to refresh.
  29. /// The BaseProviderInfo class can be extended to hold anything a provider may need.
  30. ///
  31. /// Keyed by a unique provider ID.
  32. /// </summary>
  33. public Dictionary<Guid, BaseProviderInfo> ProviderData
  34. {
  35. get
  36. {
  37. if (_providerData == null) _providerData = new Dictionary<Guid, BaseProviderInfo>();
  38. return _providerData;
  39. }
  40. set
  41. {
  42. _providerData = value;
  43. }
  44. }
  45. protected ItemResolveEventArgs _resolveArgs;
  46. /// <summary>
  47. /// We attach these to the item so that we only ever have to hit the file system once
  48. /// (this includes the children of the containing folder)
  49. /// Use ResolveArgs.FileSystemChildren to check for the existence of files instead of File.Exists
  50. /// </summary>
  51. public ItemResolveEventArgs ResolveArgs
  52. {
  53. get
  54. {
  55. if (_resolveArgs == null)
  56. {
  57. _resolveArgs = new ItemResolveEventArgs()
  58. {
  59. FileInfo = FileData.GetFileData(this.Path),
  60. Parent = this.Parent,
  61. Cancel = false,
  62. Path = this.Path
  63. };
  64. _resolveArgs = FileSystemHelper.FilterChildFileSystemEntries(_resolveArgs, (this.Parent != null && this.Parent.IsRoot));
  65. }
  66. return _resolveArgs;
  67. }
  68. set
  69. {
  70. _resolveArgs = value;
  71. }
  72. }
  73. /// <summary>
  74. /// Refresh metadata on us by execution our provider chain
  75. /// </summary>
  76. /// <returns>true if a provider reports we changed</returns>
  77. public bool RefreshMetadata()
  78. {
  79. Kernel.Instance.ExecuteMetadataProviders(this).ConfigureAwait(false);
  80. return true;
  81. }
  82. }
  83. }