diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-01-01 13:26:31 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-01-01 13:26:31 -0500 |
| commit | b9d17c9bc765a0c59d81db6277300a6860bf8421 (patch) | |
| tree | 8a7c538cb73c27b7e06f0055ce4f0bb45175e7aa /MediaBrowser.Controller/Entities/Folder.cs | |
| parent | 88b638fbd69ed99bde7065f66af433b015977cb7 (diff) | |
add more methods to file system interface
Diffstat (limited to 'MediaBrowser.Controller/Entities/Folder.cs')
| -rw-r--r-- | MediaBrowser.Controller/Entities/Folder.cs | 125 |
1 files changed, 62 insertions, 63 deletions
diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 912b8fa93..a85157a26 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -519,85 +519,84 @@ namespace MediaBrowser.Controller.Entities await Task.WhenAll(tasks).ConfigureAwait(false); } - Tuple<BaseItem, bool> currentTuple = tuple; - - tasks.Add(Task.Run(async () => - { - cancellationToken.ThrowIfCancellationRequested(); - - var child = currentTuple.Item1; - try - { - //refresh it - await child.RefreshMetadata(cancellationToken, forceSave: currentTuple.Item2, forceRefresh: forceRefreshMetadata, resetResolveArgs: false).ConfigureAwait(false); - } - catch (IOException ex) - { - Logger.ErrorException("Error refreshing {0}", ex, child.Path ?? child.Name); - } + tasks.Add(RefreshChild(tuple, progress, percentages, list.Count, cancellationToken, recursive, forceRefreshMetadata)); + } - // Refresh children if a folder and the item changed or recursive is set to true - var refreshChildren = child.IsFolder && (currentTuple.Item2 || (recursive.HasValue && recursive.Value)); + cancellationToken.ThrowIfCancellationRequested(); - if (refreshChildren) - { - // Don't refresh children if explicitly set to false - if (recursive.HasValue && recursive.Value == false) - { - refreshChildren = false; - } - } + await Task.WhenAll(tasks).ConfigureAwait(false); + } - if (refreshChildren) - { - cancellationToken.ThrowIfCancellationRequested(); + private async Task RefreshChild(Tuple<BaseItem, bool> currentTuple, IProgress<double> progress, Dictionary<Guid, double> percentages, int childCount, CancellationToken cancellationToken, bool? recursive, bool forceRefreshMetadata = false) + { + cancellationToken.ThrowIfCancellationRequested(); - var innerProgress = new ActionableProgress<double>(); + var child = currentTuple.Item1; + try + { + //refresh it + await child.RefreshMetadata(cancellationToken, forceSave: currentTuple.Item2, forceRefresh: forceRefreshMetadata, resetResolveArgs: false).ConfigureAwait(false); + } + catch (IOException ex) + { + Logger.ErrorException("Error refreshing {0}", ex, child.Path ?? child.Name); + } - innerProgress.RegisterAction(p => - { - lock (percentages) - { - percentages[child.Id] = p / 100; + // Refresh children if a folder and the item changed or recursive is set to true + var refreshChildren = child.IsFolder && (currentTuple.Item2 || (recursive.HasValue && recursive.Value)); - var percent = percentages.Values.Sum(); - percent /= list.Count; + if (refreshChildren) + { + // Don't refresh children if explicitly set to false + if (recursive.HasValue && recursive.Value == false) + { + refreshChildren = false; + } + } - progress.Report((90 * percent) + 10); - } - }); + if (refreshChildren) + { + cancellationToken.ThrowIfCancellationRequested(); - await ((Folder)child).ValidateChildren(innerProgress, cancellationToken, recursive, forceRefreshMetadata).ConfigureAwait(false); + var innerProgress = new ActionableProgress<double>(); - try - { - // Some folder providers are unable to refresh until children have been refreshed. - await child.RefreshMetadata(cancellationToken, resetResolveArgs: false).ConfigureAwait(false); - } - catch (IOException ex) - { - Logger.ErrorException("Error refreshing {0}", ex, child.Path ?? child.Name); - } - } - else + innerProgress.RegisterAction(p => + { + lock (percentages) { - lock (percentages) - { - percentages[child.Id] = 1; + percentages[child.Id] = p / 100; - var percent = percentages.Values.Sum(); - percent /= list.Count; + var percent = percentages.Values.Sum(); + percent /= childCount; - progress.Report((90 * percent) + 10); - } + progress.Report((90 * percent) + 10); } + }); - }, cancellationToken)); + await ((Folder)child).ValidateChildren(innerProgress, cancellationToken, recursive, forceRefreshMetadata).ConfigureAwait(false); + + try + { + // Some folder providers are unable to refresh until children have been refreshed. + await child.RefreshMetadata(cancellationToken, resetResolveArgs: false).ConfigureAwait(false); + } + catch (IOException ex) + { + Logger.ErrorException("Error refreshing {0}", ex, child.Path ?? child.Name); + } } + else + { + lock (percentages) + { + percentages[child.Id] = 1; - cancellationToken.ThrowIfCancellationRequested(); + var percent = percentages.Values.Sum(); + percent /= childCount; - await Task.WhenAll(tasks).ConfigureAwait(false); + progress.Report((90 * percent) + 10); + } + } } /// <summary> @@ -646,7 +645,7 @@ namespace MediaBrowser.Controller.Entities private bool ContainsPath(string parent, string path) { - return string.Equals(parent, path, StringComparison.OrdinalIgnoreCase) || path.IndexOf(parent.TrimEnd(System.IO.Path.DirectorySeparatorChar) + System.IO.Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase) != -1; + return string.Equals(parent, path, StringComparison.OrdinalIgnoreCase) || FileSystem.ContainsSubPath(parent, path); } /// <summary> |
