Ejemplo n.º 1
0
        internal string GetCommonObjectBaseType()
        {
            var baseType = PrtgProgressCmdlet.GetTypeDescription(objects.First().GetType()).ToLower();

            if (objects.Count > 1)
            {
                baseType += "s";
            }

            return(baseType);
        }
        public IEnumerable <TRet> StreamResultsWithProgress <TRet>(TParam parameters, int?count, Func <IEnumerable <TRet> > getFiltered = null)
        {
            cmdlet.ProgressManager.Scenario = ProgressScenario.StreamProgress;

            if (!cmdlet.ProgressManager.WatchStream)
            {
                cmdlet.ProgressManager.WriteProgress($"PRTG {PrtgProgressCmdlet.GetTypeDescription(typeof(TObject))} Search", "Detecting total number of items");

                StreamCount = cmdlet.GetStreamTotalObjects(parameters);
                SetTotalExist(StreamCount.Value);
            }
            else
            {
                cmdlet.ProgressManager.WriteProgress($"PRTG {PrtgProgressCmdlet.GetTypeDescription(typeof(TObject))} Watcher", "Waiting for first event");
                StreamCount = 1000;
            }

            IEnumerable <TRet> records;

            //Normally if a filter has been specified PrtgAPI won't stream, and so the custom parameters are not necessary.
            //However, if a cmdlet has specified it wants to force a stream, we apply our filters and use our custom parameters.
            if (ForceStream)
            {
                records = getFiltered == null?StreamRecords <TRet>(parameters, count) : getFiltered();
            }
            else
            {
                records = StreamRecords <TRet>(parameters, count);
            }

            if (StreamCount > streamThreshold || cmdlet.ProgressManager.WatchStream)
            {
                //We'll be replacing this progress record, so just null it out via a call to CompleteProgress()
                //We strategically set the TotalRecords AFTER calling this method, to avoid CompleteProgress truly completing the record
                cmdlet.ProgressManager.CompleteProgress();
                cmdlet.SetObjectSearchProgress(ProcessingOperation.Retrieving);
                cmdlet.ProgressManager.TotalRecords = StreamCount;
            }
            else //We won't be showing progress, so complete this record
            {
                cmdlet.ProgressManager.TotalRecords = StreamCount;
                cmdlet.ProgressManager.CompleteProgress();
            }

            return(records);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// If <see cref="Batch"/> is true, queues the object for processing after all items have been identified. Otherwise, executes this cmdlet's action immediately.
 /// </summary>
 /// <param name="obj">The object to process.</param>
 protected void ExecuteOrQueue(IObject obj)
 {
     ExecuteOrQueue(obj, $"Queuing {PrtgProgressCmdlet.GetTypeDescription(obj.GetType()).ToLower()} '{obj.Name}'");
 }
Ejemplo n.º 4
0
        internal string GetMultiTypeListSummary()
        {
            var toProcess = objects;
            var remaining = 0;

            if (objects.Count > 10)
            {
                var amount = 10;

                if (objects.Count == 11)
                {
                    amount = 9;
                }

                toProcess = objects.Take(amount).ToList();
                remaining = objects.Count - amount;
            }

            var grouped = toProcess.GroupBy(t => PrtgProgressCmdlet.GetTypeDescription(t.GetType())).ToList();

            var builder = new StringBuilder();

            for (int i = 0; i < grouped.Count; i++)
            {
                //Add the BaseType (e.g. sensor(s))
                builder.Append(grouped[i].Key.ToLower());

                if (grouped[i].Count() > 1)
                {
                    builder.Append("s");
                }

                builder.Append(" ");

                var groupItems = grouped[i].ToList();

                //Add each object name (e.g. 'Ping', 'DNS' and 'Uptime'
                for (int j = 0; j < groupItems.Count(); j++)
                {
                    builder.Append($"'{groupItems[j].Name}'");

                    if (j < groupItems.Count - 2)
                    {
                        builder.Append(", ");
                    }
                    else if (j == groupItems.Count - 2)
                    {
                        //If there's more than 1 group and we're not the last group, OR if there are remaining items, dont say "and"

                        if ((grouped.Count > 1 && i == grouped.Count - 1 || grouped.Count == 1) && remaining == 0)
                        {
                            builder.Append(" and ");
                        }
                        else
                        {
                            builder.Append(", ");
                        }
                    }
                }

                //Add a delimiter for the next group based on whether we'll also have to
                //report the number of objects we didn't name afterwards
                if (i < grouped.Count - 2)
                {
                    builder.Append(", ");
                }
                else if (i == grouped.Count - 2)
                {
                    builder.Append(remaining > 0 ? ", " : " and ");
                }
            }

            if (remaining > 0)
            {
                builder.Append($" and {remaining} others");
            }

            return(builder.ToString());
        }
Ejemplo n.º 5
0
        internal void DisplayResolutionError(Type type, int retriesRemaining)
        {
            var typeName = PrtgProgressCmdlet.GetTypeDescription(type).ToLower();

            WriteWarning($"'{MyInvocation.MyCommand}' failed to resolve {typeName}: object is still being created. Retries remaining: {retriesRemaining}");
        }