示例#1
0
 public void CheckForCycles(
     BindingExtenderBox box
     )
 {
     using (new DTimer(_diagnosticReporter, "Dpdt cycle checker time taken"))
     {
         _cycleChecker.CheckForCycles(box);
     }
 }
示例#2
0
        public void CheckForCycles(
            BindingExtenderBox box
            )
        {
            if (box is null)
            {
                throw new ArgumentNullException(nameof(box));
            }

            var cycles = new HashSet <CycleFoundException>(
                new OrderIndependentCycleFoundEqualityComparer()
                );

            foreach (var pair in box.Groups.Shuffle())
            {
                var group = pair.Value;
                foreach (var bindingExtender in group.BindingExtenders.Shuffle())
                {
                    try
                    {
                        var used = new Subgraph();

                        CheckForCyclesInternal(
                            ref used,
                            box,
                            bindingExtender.BindingContainer
                            );
                    }
                    catch (CycleFoundException cfe)
                    {
                        if (!cycles.Contains(cfe))
                        {
                            cycles.Add(cfe);
                        }
                    }
                }
            }

            foreach (var cycle in cycles)
            {
                if (cycle.StrictConculsion)
                {
                    throw new DpdtException(
                              DpdtExceptionTypeEnum.CircularDependency,
                              $"A circular dependency was found: [{cycle.GetStringRepresentation()}]"
                              );
                }
                else
                {
                    _reporter.ReportWarning(
                        $"Perhaps a circular dependency was found",
                        $"Perhaps a circular dependency was found, please take a look: [{cycle.GetStringRepresentation()}]"
                        );
                }
            }
        }
示例#3
0
        private void CheckForCyclesInternal(
            ref Subgraph used,
            BindingExtenderBox box,
            IBindingContainer bindingContainer
            )
        {
            if (used is null)
            {
                throw new ArgumentNullException(nameof(used));
            }

            if (box is null)
            {
                throw new ArgumentNullException(nameof(box));
            }

            if (bindingContainer is null)
            {
                throw new ArgumentNullException(nameof(bindingContainer));
            }

            used.AppendOrFailIfExists(
                bindingContainer,
                !bindingContainer.IsConditional
                );

            if (box.TryGetChildren(bindingContainer, true, out var pairs))
            {
                foreach (var pair in pairs)
                {
                    var used2 = used.Clone();

                    CheckForCyclesInternal(
                        ref used2,
                        box,
                        pair.BindingExtender.BindingContainer
                        );
                }
            }
        }