Exemplo n.º 1
0
 protected void AddChildrenInternal(IEnumerable <BaseItem> children)
 {
     lock (_childrenSyncLock)
     {
         var newChildren = ActualChildren.ToList();
         newChildren.AddRange(children);
         _children = newChildren;
     }
 }
Exemplo n.º 2
0
 protected void AddChildInternal(BaseItem child)
 {
     lock (_childrenSyncLock)
     {
         var newChildren = ActualChildren.ToList();
         newChildren.Add(child);
         _children = newChildren;
     }
 }
Exemplo n.º 3
0
        private async Task RefreshMetadataRecursive(MetadataRefreshOptions refreshOptions, bool recursive, IProgress <double> progress, CancellationToken cancellationToken)
        {
            var children = ActualChildren.ToList();

            var percentages = new Dictionary <Guid, double>(children.Count);

            var tasks = new List <Task>();

            foreach (var child in children)
            {
                if (tasks.Count >= 3)
                {
                    await Task.WhenAll(tasks).ConfigureAwait(false);

                    tasks.Clear();
                }

                cancellationToken.ThrowIfCancellationRequested();
                var innerProgress = new ActionableProgress <double>();

                // Avoid implicitly captured closure
                var currentChild = child;
                innerProgress.RegisterAction(p =>
                {
                    lock (percentages)
                    {
                        percentages[currentChild.Id] = p / 100;

                        var percent = percentages.Values.Sum();
                        percent    /= children.Count;
                        percent    *= 100;
                        progress.Report(percent);
                    }
                });

                if (child.IsFolder)
                {
                    await RefreshChildMetadata(child, refreshOptions, recursive, innerProgress, cancellationToken)
                    .ConfigureAwait(false);
                }
                else
                {
                    // Avoid implicitly captured closure
                    var taskChild = child;

                    tasks.Add(Task.Run(async() => await RefreshChildMetadata(taskChild, refreshOptions, false, innerProgress, cancellationToken).ConfigureAwait(false), cancellationToken));
                }
            }

            await Task.WhenAll(tasks).ConfigureAwait(false);

            progress.Report(100);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Clears the children.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Task.</returns>
        public Task ClearChildren(CancellationToken cancellationToken)
        {
            var items = ActualChildren.ToList();

            ClearChildrenInternal();

            foreach (var item in items)
            {
                LibraryManager.ReportItemRemoved(item);
            }

            return(ItemRepository.SaveChildren(Id, ActualChildren.Select(i => i.Id).ToList(), cancellationToken));
        }
Exemplo n.º 5
0
        private async Task RefreshMetadataRecursive(MetadataRefreshOptions refreshOptions, bool recursive, IProgress <double> progress, CancellationToken cancellationToken)
        {
            var children = ActualChildren.ToList();

            var percentages = new Dictionary <Guid, double>(children.Count);
            var numComplete = 0;
            var count       = children.Count;

            foreach (var child in children)
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (child.IsFolder)
                {
                    var innerProgress = new ActionableProgress <double>();

                    // Avoid implicitly captured closure
                    var currentChild = child;
                    innerProgress.RegisterAction(p =>
                    {
                        lock (percentages)
                        {
                            percentages[currentChild.Id] = p / 100;

                            var innerPercent = percentages.Values.Sum();
                            innerPercent    /= count;
                            innerPercent    *= 100;
                            progress.Report(innerPercent);
                        }
                    });

                    await RefreshChildMetadata(child, refreshOptions, recursive, innerProgress, cancellationToken)
                    .ConfigureAwait(false);
                }
                else
                {
                    await RefreshChildMetadata(child, refreshOptions, false, new Progress <double>(), cancellationToken)
                    .ConfigureAwait(false);
                }

                numComplete++;
                double percent = numComplete;
                percent /= count;
                percent *= 100;

                progress.Report(percent);
            }

            progress.Report(100);
        }