Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrtgOrphan{TValue}"/> class with a specified tree value and children.
 /// </summary>
 /// <param name="value">The tree value to encapsulate in this orphan.</param>
 /// <param name="children">The children of this orphan.</param>
 /// <param name="type">The type of this orphan.</param>
 internal PrtgOrphan(ITreeValue value, IEnumerable <PrtgOrphan> children, PrtgNodeType type) : base(value, children, type)
 {
     if (value == null)
     {
         throw new ArgumentNullException(nameof(value));
     }
 }
Esempio n. 2
0
        internal static PrtgOrphan Object(ITreeValue value, IEnumerable <PrtgOrphan> children)
        {
            if (value is Probe)
            {
                return(Probe((Probe)value, children));
            }

            if (value is Group)
            {
                return(Group((Group)value, children));
            }

            if (value is Device)
            {
                return(Device((Device)value, children));
            }

            if (value is Sensor)
            {
                return(Sensor((Sensor)value, children));
            }

            if (value is NotificationTrigger)
            {
                return(Trigger((NotificationTrigger)value));
            }

            if (value is PropertyValuePair)
            {
                return(Property((PropertyValuePair)value));
            }

            throw new NotImplementedException($"Don't know what type of orphan object of type '{value.GetType().FullName}' should be.");
        }
Esempio n. 3
0
 internal TreeBuilderLevel(ITreeValue value, PrtgNodeType valueType, Func <ITreeValue, IEnumerable <PrtgOrphan>, PrtgOrphan> getOrphan, TreeBuilder builder)
 {
     Value        = value;
     ValueType    = valueType;
     GetOrphan    = getOrphan;
     this.builder = builder;
 }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PrtgOrphan"/> class.
        /// </summary>
        /// <param name="value">The value this orphan encapsulates.</param>
        /// <param name="children">The children of this orphan.</param>
        /// <param name="type">The type of this orphan.</param>
        internal PrtgOrphan(ITreeValue value, IEnumerable <PrtgOrphan> children, PrtgNodeType type) : base(ReduceChildren(children), (int)type)
        {
            Value = value;

            //We only have a cached enumeration of children when we lazily retrieved them from PRTG in a TreeLevelBuilder.
            //As such, skip validating the children.
            if (!(children is CachedEnumerableIterator <PrtgOrphan>))
            {
                ValidateChildren(Children);
            }
        }
Esempio n. 5
0
        private static PrtgNodeType GetNodeType(ITreeValue value)
        {
            if (value is ISensor)
            {
                return(PrtgNodeType.Sensor);
            }

            if (value is IDevice)
            {
                return(PrtgNodeType.Device);
            }

            if (value is IGroup)
            {
                return(PrtgNodeType.Group);
            }

            if (value is IProbe)
            {
                return(PrtgNodeType.Probe);
            }

            if (value is NotificationTrigger)
            {
                return(PrtgNodeType.Trigger);
            }

            if (value is PropertyValuePair)
            {
                return(PrtgNodeType.Property);
            }

            if (value.GetType() == typeof(PrtgObject))
            {
                throw new NotSupportedException($"Cannot process value '{value}' of type '{value.GetType()}': value must be a specific type of {nameof(PrtgObject)}.");
            }

            throw new NotImplementedException($"Don't know what type of object '{value}' is.");
        }
        public void OnLevelBegin(ITreeValue value, PrtgNodeType type, int depth)
        {
            var typeDescription = IObjectExtensions.GetTypeDescription(value.GetType());

            var str = typeDescription.ToLower();

            if (value.Id == WellKnownId.Root)
            {
                ProgressManager.InitialDescription = "Processing children of 'Root' Group";
            }
            else
            {
                ProgressManager.InitialDescription = $"Processing children of {str} '{value}'";

                if (value is IPrtgObject)
                {
                    ProgressManager.InitialDescription += $" (ID: {value.Id})";
                }
            }

            var activity = depth == 1 ? "PRTG Tree Search" : $"PRTG {typeDescription} Tree Search";

            ProgressManager.WriteProgress(activity, $"Retrieving children of {str} '{value}'");
        }
Esempio n. 7
0
 internal TreeBuilderLevel(ITreeValue value, TreeBuilder builder) :
     this(value, GetNodeType(value), PrtgOrphan.Object, builder)
 {
 }
 internal override PrtgNode Update(ITreeValue value, IEnumerable <PrtgNode> children)
 {
     return(ValidateAndUpdate <PropertyNode>(children, PrtgNodeType.Property, PropertyCollection));
 }
Esempio n. 9
0
 /// <summary>
 /// Encapsulates a <see cref="Device"/> and its children as a <see cref="DeviceOrphan"/>.
 /// </summary>
 /// <param name="value">The device to encapsulate.</param>
 /// <param name="children">The children of the device.</param>
 /// <returns>A <see cref="DeviceOrphan"/> encapsulating the specified <see cref="Device"/> and children.</returns>
 public override PrtgOrphan Orphan(ITreeValue value, IEnumerable <PrtgOrphan> children) =>
 PrtgOrphan.Device((IDevice)value, children);
Esempio n. 10
0
 public void OnProcessValue(ITreeValue value)
 {
     progressCallback?.OnProcessValue(value);
 }
Esempio n. 11
0
 internal static PrtgOrphan Object(ITreeValue value, params PrtgOrphan[] children) =>
 Object(value, (IEnumerable <PrtgOrphan>)children);
Esempio n. 12
0
 /// <summary>
 /// Creates a new <see cref="PrtgNode"/> if the specified <paramref name="value"/> and <paramref name="children"/>
 /// differ from the values stored in this object.
 /// </summary>
 /// <param name="value">The tree value to compare against.</param>
 /// <param name="children">The children to compare against.</param>
 /// <returns>If the value or children do not match those stored in this object, a new object containing those values. Otherwise, this object.</returns>
 internal abstract PrtgNode Update(ITreeValue value, IEnumerable <PrtgNode> children);
Esempio n. 13
0
 internal abstract PrtgOrphan Update(ITreeValue value, IEnumerable <PrtgOrphan> children);
Esempio n. 14
0
 public void OnLevelBegin(ITreeValue value, PrtgNodeType type)
 {
     progressCallback?.OnLevelBegin(value, type, depthManager.Depth);
 }
Esempio n. 15
0
 /// <summary>
 /// Encapsulates a <see cref="Sensor"/> and its children as a <see cref="SensorOrphan"/>.
 /// </summary>
 /// <param name="value">The sensor to encapsulate.</param>
 /// <param name="children">The children of the sensor.</param>
 /// <returns>A <see cref="SensorOrphan"/> encapsulating the specified <see cref="Sensor"/> and children.</returns>
 public override PrtgOrphan Orphan(ITreeValue value, IEnumerable <PrtgOrphan> children) =>
 PrtgOrphan.Sensor((Sensor)value, children);
 public void OnProcessValue(ITreeValue value)
 {
     ProgressManager.UpdateRecordsProcessed(ProgressManager.CurrentRecord, null, true);
 }
Esempio n. 17
0
 public void OnLevelWidthKnown(ITreeValue parent, PrtgNodeType parentType, int width)
 {
     progressCallback?.OnLevelWidthKnown(parent, parentType, width);
 }
Esempio n. 18
0
 /// <summary>
 /// Encapsulates a <see cref="NotificationTrigger"/> and its children as a <see cref="TriggerOrphan"/>.
 /// </summary>
 /// <param name="value">The notification trigger to encapsulate.</param>
 /// <param name="children">The children of the notification trigger.</param>
 /// <returns>A <see cref="TriggerOrphan"/> encapsulating the specified <see cref="NotificationTrigger"/> and children.</returns>
 public override PrtgOrphan Orphan(ITreeValue value, IEnumerable <PrtgOrphan> children) =>
 PrtgOrphan.Trigger((NotificationTrigger)value);
Esempio n. 19
0
 internal override PrtgOrphan Update(ITreeValue value, IEnumerable <PrtgOrphan> children)
 {
     return(ValidateAndUpdate <TriggerOrphan>(children, PrtgNodeType.Trigger, TriggerCollection));
 }
Esempio n. 20
0
 /// <summary>
 /// Encapsulates a <see cref="Probe"/> and its children as a <see cref="ProbeOrphan"/>.
 /// </summary>
 /// <param name="value">The probe to encapsulate.</param>
 /// <param name="children">The children of the probe.</param>
 /// <returns>A <see cref="ProbeOrphan"/> encapsulating the specified <see cref="Probe"/> and children.</returns>
 public override PrtgOrphan Orphan(ITreeValue value, IEnumerable <PrtgOrphan> children) =>
 PrtgOrphan.Probe((Probe)value, children);
 public void OnLevelWidthKnown(ITreeValue parent, PrtgNodeType type, int width)
 {
     ProgressManager.TotalRecords = width;
 }
Esempio n. 22
0
 /// <summary>
 /// Encapsulates an <see cref="ITreeValue"/> and its children as a <see cref="PrtgOrphan"/>.
 /// </summary>
 /// <param name="value">The object to encapsulate.</param>
 /// <param name="children">The children of the object.</param>
 /// <returns>A <see cref="PrtgOrphan"/> encapsulating the specified <see cref="ITreeValue"/> and children.</returns>
 public abstract PrtgOrphan Orphan(ITreeValue value, IEnumerable <PrtgOrphan> children);
Esempio n. 23
0
 /// <summary>
 /// Creates a new <see cref="PrtgOrphan"/> if the specified <paramref name="value"/> and <paramref name="children"/>
 /// differ from the values stored in this object.<para/>
 /// Redirects to <see cref="Update(TValue, IEnumerable{PrtgOrphan})"/> to provide type safety.
 /// </summary>
 /// <param name="value">The tree value to compare against.</param>
 /// <param name="children">The children to compare against.</param>
 /// <returns>If the value or children do not match those stored in this object, a new object containing those values. Otherwise, this object.</returns>
 internal override PrtgOrphan Update(ITreeValue value, IEnumerable <PrtgOrphan> children) => Update((TValue)value, children);
Esempio n. 24
0
 internal override PrtgOrphan Update(ITreeValue value, IEnumerable <PrtgOrphan> children)
 {
     //By default we prohibit modifying the children of a collection. Specific overrides (such as PropertyOrphanCollection
     //and TriggerOrphanCollection) may override this method to re-allow this behavior.
     throw new NotSupportedException($"Modifying the children of a {GetType().Name} is not supported.");
 }
Esempio n. 25
0
 /// <summary>
 /// Encapsulates a <see cref="Group"/> and its children as a <see cref="GroupOrphan"/>.
 /// </summary>
 /// <param name="value">The group to encapsulate.</param>
 /// <param name="children">The children of the group.</param>
 /// <returns>A <see cref="GroupOrphan"/> encapsulating the specified <see cref="Group"/> and children.</returns>
 public override PrtgOrphan Orphan(ITreeValue value, IEnumerable <PrtgOrphan> children) =>
 PrtgOrphan.Group((IGroup)value, children);
Esempio n. 26
0
 /// <summary>
 /// Encapsulates a <see cref="PropertyValuePair"/> and its children as a <see cref="PropertyOrphan"/>.
 /// </summary>
 /// <param name="value">The property to encapsulate.</param>
 /// <param name="children">The children of the property.</param>
 /// <returns>A <see cref="PropertyOrphan"/> encapsulating the specified <see cref="PropertyValuePair"/> and children.</returns>
 public override PrtgOrphan Orphan(ITreeValue value, IEnumerable <PrtgOrphan> children) =>
 PrtgOrphan.Property((PropertyValuePair)value);