private async Task <IEnumerable <TResult> > WalkNodeAsync <TResult>
        (
            [NotNull] PluginDependencyTreeNode node,
            [NotNull] Func <PluginDependencyTreeNode, Exception, TResult> errorFactory,
            [NotNull] Func <PluginDependencyTreeNode, Task <TResult> > preOperation,
            [CanBeNull] Func <PluginDependencyTreeNode, Task <TResult> > postOperation = null
        )
            where TResult : IResult
        {
            var results = new List <TResult>();

            try
            {
                var result = await preOperation(node);

                results.Add(result);

                if (!result.IsSuccess)
                {
                    results.AddRange(node.GetAllDependants().Select(d => errorFactory(d, null)));
                    return(results);
                }
            }
            catch (Exception e)
            {
                results.Add(errorFactory(node, e));
                results.AddRange(node.GetAllDependants().Select(d => errorFactory(d, null)));
                return(results);
            }

            foreach (var dependant in node.Dependants)
            {
                results.AddRange(await WalkNodeAsync(dependant, errorFactory, preOperation, postOperation));
            }

            if (!(postOperation is null))
            {
                try
                {
                    var result = await postOperation(node);

                    results.Add(result);

                    if (!result.IsSuccess)
                    {
                        results.AddRange(node.GetAllDependants().Select(d => errorFactory(d, null)));
                        return(results);
                    }
                }
                catch (Exception e)
                {
                    results.Add(errorFactory(node, e));
                    results.AddRange(node.GetAllDependants().Select(d => errorFactory(d, null)));
                    return(results);
                }
            }

            return(results);
        }
        /// <summary>
        /// Adds a dependency branch to the tree.
        /// </summary>
        /// <param name="branch">The branch.</param>
        internal void AddBranch([NotNull] PluginDependencyTreeNode branch)
        {
            if (_branches.Contains(branch))
            {
                return;
            }

            _branches.Add(branch);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a dependant to this node.
        /// </summary>
        /// <param name="node">The node.</param>
        internal void AddDependant([NotNull] PluginDependencyTreeNode node)
        {
            if (_dependants.Contains(node))
            {
                return;
            }

            _dependants.Add(node);
        }