private bool DeletePreviewFoldersBlock(string path, bool keepLastVersions, int minimumNodeId, int blockSize, out int lastDeletedId)
        {
            lastDeletedId = 0;

            if (!LoadPreviewFoldersBlock(path, keepLastVersions, minimumNodeId, blockSize, out var buffer))
            {
                return(false);
            }

            var pathBag     = new ConcurrentBag <string>();
            var workerBlock = new ActionBlock <NodeInfo>(
                async node =>
            {
                if (!keepLastVersions || IsFolderDeletable(node.Path))
                {
                    await DeleteContentFromDb(node.Id);
                    OnFolderDeleted?.Invoke(node.Id, EventArgs.Empty);

                    if (!string.IsNullOrEmpty(node.Path))
                    {
                        pathBag.Add(node.Path);
                    }
                }
            },
                new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = MaxDegreeOfParallelism
            });

            foreach (var folder in buffer)
            {
                workerBlock.Post(folder);
            }

            lastDeletedId = buffer.Max(n => n.Id);

            workerBlock.Complete();
            workerBlock.Completion.Wait();

            Trace.Write("Removing preview folder block from the index.");

            IndexManager.IndexingEngine.WriteIndex(pathBag.SelectMany(p => new[]
            {
                new SnTerm(IndexFieldName.InTree, p),
                new SnTerm(IndexFieldName.Path, p)
            }),
                                                   null, null);

            return(true);
        }
Beispiel #2
0
        private bool DeleteEmptyPreviewFoldersBlock(string path, int blockSize)
        {
            if (!LoadEmptyPreviewFoldersBlock(path, blockSize, out var buffer))
            {
                return(false);
            }

            var pathBag     = new ConcurrentBag <string>();
            var workerBlock = new ActionBlock <NodeInfo>(
                async node =>
            {
                await DeleteContentFromDb(node.Id);
                OnFolderDeleted?.Invoke(node.Id, EventArgs.Empty);

                if (!string.IsNullOrEmpty(node.Path))
                {
                    pathBag.Add(node.Path);
                }
            },
                new ExecutionDataflowBlockOptions {
                MaxDegreeOfParallelism = MaxDegreeOfParallelism
            });

            foreach (var folder in buffer)
            {
                workerBlock.Post(folder);
            }

            workerBlock.Complete();
            workerBlock.Completion.Wait();

            Trace.Write("Removing preview folder block from the index.");

            IndexManager.IndexingEngine.WriteIndexAsync(pathBag.SelectMany(p => new[]
            {
                new SnTerm(IndexFieldName.InTree, p),
                new SnTerm(IndexFieldName.Path, p)
            }),
                                                        null, null, CancellationToken.None).GetAwaiter().GetResult();

            return(true);
        }