Ejemplo n.º 1
0
 internal static void Validate(PrtgNode node, string[] expected)
 {
     node.PrettyPrint(new PrtgPrettyValidator(expected));
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NewPropertyNode"/> class.
 /// </summary>
 public NewPropertyNode() : base((p, c) => PrtgNode.Property(p), () => new GetObjectProperty())
 {
 }
Ejemplo n.º 3
0
        public void Tree_PrettyPrint_TwoChildren_OneHasTwoChildren_WithOneGrandChildCollectionEach()
        {
            var tree = PrtgNode.Group(Group("PRTG Network Monitor", 0),
                                      PrtgNode.Probe(Probe("Probe 1"),
                                                     PrtgNode.Group(Group(),
                                                                    PrtgNode.TriggerCollection(PrtgNode.Trigger(Trigger()))
                                                                    ),
                                                     PrtgNode.Group(Group("Linux"),
                                                                    PrtgNode.TriggerCollection(PrtgNode.Trigger(Trigger("Ticket Notification")))
                                                                    )
                                                     ),
                                      PrtgNode.Probe(Probe("Probe 2"))
                                      );

            var expected = new[]
            {
                "PRTG Network Monitor",
                "├──Probe 1",
                "│  ├──Servers",
                "│  │  └──Email to Admin",
                "│  └──Linux",
                "│     └──Ticket Notification",
                "└──Probe 2"
            };

            Validate(tree, expected);
        }
 /// <summary>
 /// Visits a node via the <see cref="innerVisitor"/>.
 /// </summary>
 /// <param name="node">The node to visit.</param>
 protected override void DefaultVisit(PrtgNode node) => innerVisitor.Visit(node);
Ejemplo n.º 5
0
        private FlagEnum <TreeNodeDifference> GetDifference(PrtgNode first, PrtgNode second, TreeNodeDifference[] interestedDifferences)
        {
            var differences = new List <TreeNodeDifference>();

            if (first == null && second == null)
            {
                return(TreeNodeDifference.None);
            }

            if (first != null && second == null)
            {
                differences.Add(TreeNodeDifference.Removed);
            }

            if (first == null && second != null)
            {
                differences.Add(TreeNodeDifference.Added);
            }

            if (first != null && second != null)
            {
                if (first.GetType() != second.GetType())
                {
                    differences.Add(TreeNodeDifference.Type);
                }

                //Collections don't have values, so there's no point checking value properties for them
                if (first.Value != null && second.Value != null)
                {
                    Debug.Assert(first.Value.Id == second.Value.Id, "If two nodes had different IDs one of them should have been replaced in the comparison visitor with null.");

                    if (first.Value.ParentId != second.Value.ParentId)
                    {
                        differences.Add(TreeNodeDifference.ParentId);
                    }

                    if (first.Value.Name != second.Value.Name)
                    {
                        differences.Add(TreeNodeDifference.Name);
                    }

                    if (first.Value is ISensorOrDeviceOrGroupOrProbe && second.Value is ISensorOrDeviceOrGroupOrProbe)
                    {
                        if (((ISensorOrDeviceOrGroupOrProbe)first.Value).Position !=
                            ((ISensorOrDeviceOrGroupOrProbe)second.Value).Position)
                        {
                            differences.Add(TreeNodeDifference.Position);
                        }
                    }

                    if (first.Value is PropertyValuePair && second.Value is PropertyValuePair)
                    {
                        if (!string.Equals(((PropertyValuePair)first.Value).Value?.ToString(), ((PropertyValuePair)second.Value).Value?.ToString()))
                        {
                            differences.Add(TreeNodeDifference.Value);
                        }
                    }
                }

                if ((first.Children.Count > 0 && second.Children.Count == 0 || second.Children.Count > 0 && first.Children.Count == 0))
                {
                    differences.Add(TreeNodeDifference.HasChildren);
                }

                if (first.Children.Count != second.Children.Count)
                {
                    differences.Add(TreeNodeDifference.NumberOfChildren);
                }
            }

            Debug.Assert(
                (differences.Contains(TreeNodeDifference.Added) ||
                 differences.Contains(TreeNodeDifference.Removed)) &&
                differences.Count > 1 ?
                false :
                true,
                "Cannot contain more than one difference when the difference is Added or Removed"
                );

            if (interestedDifferences != null && interestedDifferences.Length > 0)
            {
                var interestedFlags = new FlagEnum <TreeNodeDifference>(interestedDifferences);

                if (interestedFlags != TreeNodeDifference.None)
                {
                    var proposedDifferences = new FlagEnum <TreeNodeDifference>(differences.ToArray());

                    var result = proposedDifferences & interestedFlags;

                    return(result);
                }
            }

            return(new FlagEnum <TreeNodeDifference>(differences.ToArray()));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NewTriggerNode"/> class.
 /// </summary>
 public NewTriggerNode() : base((t, c) => PrtgNode.Trigger(t), () => new GetNotificationTrigger())
 {
 }
Ejemplo n.º 7
0
 private void Validate(PrtgNode node, string[] expected)
 {
     node.PrettyPrint(new PrtgPrettyValidator(expected));
 }