BaseEntity.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MediaBrowser.Controller.Library;
  5. using MediaBrowser.Controller.IO;
  6. namespace MediaBrowser.Controller.Entities
  7. {
  8. /// <summary>
  9. /// Provides a base entity for all of our types
  10. /// </summary>
  11. public abstract class BaseEntity
  12. {
  13. public string Name { get; set; }
  14. public Guid Id { get; set; }
  15. public string Path { get; set; }
  16. public Folder Parent { get; set; }
  17. public string PrimaryImagePath { get; set; }
  18. public DateTime DateCreated { get; set; }
  19. public DateTime DateModified { get; set; }
  20. public override string ToString()
  21. {
  22. return Name;
  23. }
  24. protected ItemResolveEventArgs _resolveArgs;
  25. /// <summary>
  26. /// We attach these to the item so that we only ever have to hit the file system once
  27. /// (this includes the children of the containing folder)
  28. /// Use ResolveArgs.FileSystemChildren to check for the existence of files instead of File.Exists
  29. /// </summary>
  30. public ItemResolveEventArgs ResolveArgs
  31. {
  32. get
  33. {
  34. if (_resolveArgs == null)
  35. {
  36. _resolveArgs = new ItemResolveEventArgs()
  37. {
  38. FileInfo = FileData.GetFileData(this.Path),
  39. Parent = this.Parent,
  40. Cancel = false,
  41. Path = this.Path
  42. };
  43. _resolveArgs = FileSystemHelper.FilterChildFileSystemEntries(_resolveArgs, (this.Parent != null && this.Parent.IsRoot));
  44. }
  45. return _resolveArgs;
  46. }
  47. set
  48. {
  49. _resolveArgs = value;
  50. }
  51. }
  52. /// <summary>
  53. /// Refresh metadata on us by execution our provider chain
  54. /// </summary>
  55. /// <returns>true if a provider reports we changed</returns>
  56. public bool RefreshMetadata()
  57. {
  58. Kernel.Instance.ExecuteMetadataProviders(this).ConfigureAwait(false);
  59. return true;
  60. }
  61. }
  62. }