Ejemplo n.º 1
0
        internal async Task <PrtgOrphan> GetTreeAsync(Either <PrtgObject, int> objectOrId)
        {
            if (IsRoot(objectOrId) && !RequestType.Contains(TreeRequestType.Lazy))
            {
                return(await GetTreeFastAsync().ConfigureAwait(false));
            }

            if (!objectOrId.IsLeft)
            {
                Token.ThrowIfCancellationRequested();

                if (objectOrId.Right == WellKnownId.Root)
                {
                    objectOrId = await client.GetGroupAsync(WellKnownId.Root).ConfigureAwait(false);
                }
                else
                {
                    objectOrId = await client.GetObjectAsync(objectOrId.Right, true).ConfigureAwait(false);
                }
            }

            //With each additional level we parse, a new TreeBuilderLevel will be constructed and recursed
            var level = new TreeBuilderLevel(objectOrId.Left, this);

            return(await level.ProcessObjectAsync().ConfigureAwait(false));
        }
Ejemplo n.º 2
0
        internal PrtgOrphan GetTree(Either <PrtgObject, int> objectOrId)
        {
            if (IsRoot(objectOrId) && !RequestType.Contains(TreeRequestType.Lazy))
            {
                return(GetTreeFast());
            }

            if (!objectOrId.IsLeft)
            {
                Token.ThrowIfCancellationRequested();

                if (objectOrId.Right == WellKnownId.Root)
                {
                    objectOrId = client.GetGroup(WellKnownId.Root);
                }
                else
                {
                    objectOrId = client.GetObject(objectOrId.Right, true);
                }
            }

            //With each additional level we parse, a new TreeBuilderLevel will be constructed and recursed
            var level = new TreeBuilderLevel(objectOrId.Left, this);

            return(level.ProcessObject());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves <see cref="ITreeValue"/> values objects from a set of object factories, retrieves the children
        /// of each object from the next <see cref="TreeBuilderLevel"/> and encapsulates the object and its children in a <see cref="PrtgOrphan"/>.
        /// </summary>
        /// <param name="factories">The factories to retrieve objects from.</param>
        /// <returns>A list of <see cref="PrtgOrphan"/> objects encapsulating the values returnd from the factories and their respective children.</returns>
        private async Task <List <PrtgOrphan> > GetOrphansAsync(params ObjectFactory[] factories)
        {
            List <Tuple <ITreeValue, ObjectFactory> > results = new List <Tuple <ITreeValue, ObjectFactory> >();

            foreach (var factory in factories)
            {
                Token.ThrowIfCancellationRequested();

                var objs = await factory.ObjectsAsync(Value.Id.Value, Token).ConfigureAwait(false);

                results.AddRange(objs.Select(o => Tuple.Create(o, factory)));
            }

            ProgressManager.OnLevelWidthKnown(Value, ValueType, results.Count);

            var orphans = new List <PrtgOrphan>();

            foreach (var item in results)
            {
                ProgressManager.OnProcessValue(item.Item1);

                var level = new TreeBuilderLevel(item.Item1, item.Item2.Type, item.Item2.Orphan, builder);

                orphans.Add(await level.ProcessObjectAsync().ConfigureAwait(false));
            }

            return(orphans);
        }
Ejemplo n.º 4
0
        private async Task <PrtgOrphan> GetTreeFastAsync()
        {
            var config = new FastAsyncHelper();

            if (Options.Contains(TreeParseOption.Probes))
            {
                config.Probe.CreateTask = GetFastObjectsAsync(PrtgNodeType.Probe, client.GetProbesAsync());
            }

            if (Options.Contains(TreeParseOption.Groups))
            {
                config.Group.CreateTask = GetFastObjectsAsync(PrtgNodeType.Group, client.GetGroupsAsync());
            }
            else
            {
                config.Group.CreateTask = GetFastObjectsAsync(PrtgNodeType.Group, client.GetGroupsAsync(Property.Id, WellKnownId.Root), true);
            }

            if (Options.Contains(TreeParseOption.Devices))
            {
                config.Device.CreateTask = GetFastObjectsAsync(PrtgNodeType.Device, client.GetDevicesAsync());
            }

            if (Options.Contains(TreeParseOption.Sensors))
            {
                config.Sensor.CreateTask = GetFastObjectsAsync(PrtgNodeType.Sensor, client.GetSensorsAsync());
            }

            await config.Stage1Async().ConfigureAwait(false);

            //Await sensors separately so we don't kill PRTG
            await config.Stage2Async().ConfigureAwait(false);

            ObjectManager = new CachedObjectManager(
                client,
                await config.Sensor.Task.ConfigureAwait(false),
                await config.Device.Task.ConfigureAwait(false),
                await config.Group.Task.ConfigureAwait(false),
                await config.Probe.Task.ConfigureAwait(false)
                );

            var root = (await config.Group.Task.ConfigureAwait(false)).First(g => g.Id == WellKnownId.Root);

            var level = new TreeBuilderLevel(root, this);

            return(await level.ProcessObjectAsync().ConfigureAwait(false));
        }
Ejemplo n.º 5
0
        private PrtgOrphan GetTreeFast()
        {
            List <Probe>  probes  = null;
            List <Group>  groups  = null;
            List <Device> devices = null;
            List <Sensor> sensors = null;

            List <Action <int, int> > actions = new List <Action <int, int> >();

            using (ProgressManager.ProcessLevel())
            {
                if (Options.Contains(TreeParseOption.Probes))
                {
                    actions.Add((i, t) =>
                    {
                        ProgressManager.OnProcessType(PrtgNodeType.Probe, i, t);
                        probes = client.GetProbes();
                    });
                }

                if (Options.Contains(TreeParseOption.Groups))
                {
                    actions.Add((i, t) =>
                    {
                        ProgressManager.OnProcessType(PrtgNodeType.Group, i, t);
                        groups = client.GetGroups();
                    });
                }
                else
                {
                    actions.Add((i, t) => { groups = client.GetGroups(Property.Id, WellKnownId.Root); });
                }

                if (Options.Contains(TreeParseOption.Devices))
                {
                    actions.Add((i, t) =>
                    {
                        ProgressManager.OnProcessType(PrtgNodeType.Device, i, t);
                        devices = client.GetDevices();
                    });
                }

                if (Options.Contains(TreeParseOption.Sensors))
                {
                    actions.Add((i, t) =>
                    {
                        ProgressManager.OnProcessType(PrtgNodeType.Sensor, 4, 4);
                        sensors = client.GetSensors();
                    });
                }

                for (var i = 1; i <= actions.Count; i++)
                {
                    actions[i - 1](i, actions.Count);
                }

                ObjectManager = new CachedObjectManager(
                    client,
                    sensors,
                    devices,
                    groups,
                    probes
                    );
            }

            ProgressManager = new TreeProgressManager(null);

            var root = groups.First(g => g.Id == WellKnownId.Root);

            var level = new TreeBuilderLevel(root, this);

            return(level.ProcessObject());
        }
Ejemplo n.º 6
0
        private PrtgOrphan GetTreeFast()
        {
            List <Probe>  probes  = null;
            List <Group>  groups  = null;
            List <Device> devices = null;
            List <Sensor> sensors = null;

            List <Action <int, int> > actions = new List <Action <int, int> >();

            using (ProgressManager.ProcessLevel())
            {
                if (Options.Contains(TreeParseOption.Probes))
                {
                    actions.Add((i, t) =>
                    {
                        ProgressManager.OnProcessType(PrtgNodeType.Probe, i, t);
                        probes = client.GetProbes();
                    });
                }

                if (Options.Contains(TreeParseOption.Groups))
                {
                    actions.Add((i, t) =>
                    {
                        ProgressManager.OnProcessType(PrtgNodeType.Group, i, t);
                        groups = client.GetGroups();
                    });
                }
                else
                {
                    actions.Add((i, t) => { groups = client.GetGroups(Property.Id, WellKnownId.Root); });
                }

                if (Options.Contains(TreeParseOption.Devices))
                {
                    actions.Add((i, t) =>
                    {
                        ProgressManager.OnProcessType(PrtgNodeType.Device, i, t);
                        devices = client.GetDevices();
                    });
                }

                if (Options.Contains(TreeParseOption.Sensors))
                {
                    actions.Add((i, t) =>
                    {
                        ProgressManager.OnProcessType(PrtgNodeType.Sensor, 4, 4);
                        sensors = client.GetSensors();
                    });
                }

                for (var i = 1; i <= actions.Count; i++)
                {
                    actions[i - 1](i, actions.Count);
                }

                ObjectManager = new CachedObjectManager(
                    client,
                    sensors,
                    devices,
                    groups,
                    probes
                    );
            }

            //If we're just after the most common objects, skip showing progress as we already have everything.
            //Otherwise, show progress as normal so we know that we're trying to retrieve properties and triggers
            if (!(Options.Contains(TreeParseOption.Triggers) || Options.Contains(TreeParseOption.Properties)))
            {
                ProgressManager = new TreeProgressManager(null);
            }

            var root = groups.First(g => g.Id == WellKnownId.Root);

            var level = new TreeBuilderLevel(root, this);

            return(level.ProcessObject());
        }