aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Entities
diff options
context:
space:
mode:
authorebr11 Eric Reed spam <ebr11 Eric Reed spam@reedsplace.com>2012-09-20 11:25:16 -0400
committerebr11 Eric Reed spam <ebr11 Eric Reed spam@reedsplace.com>2012-09-20 11:25:16 -0400
commit4e3ce41880d643a2951dc971f1e8f6e21f57829c (patch)
treefb2efff3008e69627e843289fa1932663e40bbf5 /MediaBrowser.Controller/Entities
parent6edc836ce591c466743a1d94a75cb3537c4835bd (diff)
Some directory-watcher rework - still not working properly
Diffstat (limited to 'MediaBrowser.Controller/Entities')
-rw-r--r--MediaBrowser.Controller/Entities/BaseItem.cs10
-rw-r--r--MediaBrowser.Controller/Entities/Folder.cs59
2 files changed, 36 insertions, 33 deletions
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index 984584e9a5..8bbc942725 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -2,6 +2,7 @@
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.IO;
using System;
+using System.Threading.Tasks;
using System.Collections.Generic;
using System.Linq;
@@ -179,5 +180,14 @@ namespace MediaBrowser.Controller.Entities
data.PlaybackPositionTicks = 0;
}
}
+
+ /// <summary>
+ /// Do whatever refreshing is necessary when the filesystem pertaining to this item has changed.
+ /// </summary>
+ /// <returns></returns>
+ public virtual Task ChangedExternally()
+ {
+ return Task.Run(() => RefreshMetadata());
+ }
}
}
diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs
index 7d58e5e20b..6cf47c2f2d 100644
--- a/MediaBrowser.Controller/Entities/Folder.cs
+++ b/MediaBrowser.Controller/Entities/Folder.cs
@@ -272,7 +272,7 @@ namespace MediaBrowser.Controller.Entities
}
/// <summary>
- /// Finds child BaseItems for a given Folder
+ /// Finds child BaseItems for us
/// </summary>
protected Task<BaseItem>[] GetChildren(WIN32_FIND_DATA[] fileSystemChildren)
{
@@ -329,6 +329,26 @@ namespace MediaBrowser.Controller.Entities
}
/// <summary>
+ /// Folders need to validate and refresh
+ /// </summary>
+ /// <returns></returns>
+ public override Task ChangedExternally()
+ {
+ return Task.Run(() =>
+ {
+ if (this.IsRoot)
+ {
+ Kernel.Instance.ReloadRoot().ConfigureAwait(false);
+ }
+ else
+ {
+ RefreshMetadata();
+ ValidateChildren();
+ }
+ });
+ }
+
+ /// <summary>
/// Since it can be slow to make all of these calculations at once, this method will provide a way to get them all back together
/// </summary>
public ItemSpecialCounts GetSpecialCounts(User user)
@@ -578,17 +598,8 @@ namespace MediaBrowser.Controller.Entities
return result;
}
- foreach (BaseItem item in ActualChildren)
- {
- result = item.FindItemById(id);
-
- if (result != null)
- {
- return result;
- }
- }
-
- return null;
+ //this should be functionally equivilent to what was here since it is IEnum and works on a thread-safe copy
+ return RecursiveChildren.FirstOrDefault(i => i.Id == id);
}
/// <summary>
@@ -596,31 +607,13 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public BaseItem FindByPath(string path)
{
- if (Path.Equals(path, StringComparison.OrdinalIgnoreCase))
+ if (PhysicalLocations.Contains(path, StringComparer.OrdinalIgnoreCase))
{
return this;
}
- foreach (BaseItem item in ActualChildren)
- {
- var folder = item as Folder;
-
- if (folder != null)
- {
- var foundItem = folder.FindByPath(path);
-
- if (foundItem != null)
- {
- return foundItem;
- }
- }
- else if (item.Path.Equals(path, StringComparison.OrdinalIgnoreCase))
- {
- return item;
- }
- }
-
- return null;
+ //this should be functionally equivilent to what was here since it is IEnum and works on a thread-safe copy
+ return RecursiveChildren.FirstOrDefault(i => i.Path.Equals(path, StringComparison.OrdinalIgnoreCase));
}
}
}