Esempio n. 1
0
        private void SetSourceIdObject()
        {
            var sensor = client.GetSensors(Property.Id, SourceId).FirstOrDefault();

            if (sensor != null)
            {
                sourceObj         = sensor;
                sourceObjResolver = GetSensors;
                return;
            }

            var device = client.GetDevices(Property.Id, SourceId).FirstOrDefault();

            if (device != null)
            {
                sourceObj         = device;
                sourceObjResolver = GetDevices;
                return;
            }

            var group = client.GetGroups(Property.Id, SourceId).FirstOrDefault();

            if (group != null)
            {
                sourceObj         = group;
                sourceObjResolver = GetGroups;
                return;
            }

            throw new PSArgumentException($"Cannot clone object with ID '{SourceId}' as it is not a sensor, device or group.");
        }
Esempio n. 2
0
        private PSObject GetNotificationTriggerTypes()
        {
            PrtgObject prtgObject = Object;

            if (prtgObject == null)
            {
                prtgObject = client.GetObject(ObjectId);
            }

            var types = client.GetNotificationTriggerTypes(prtgObject);

            var names = Enum.GetValues(typeof(TriggerType)).Cast <TriggerType>().ToList();

            var obj = new PSObject();

            obj.TypeNames.Insert(0, "PrtgAPI.TriggerTypePSObject");

            obj.Properties.Add(new PSNoteProperty("Name", prtgObject.Name));
            obj.Properties.Add(new PSNoteProperty("ObjectId", prtgObject.Id));

            foreach (var name in names)
            {
                obj.Properties.Add(new PSNoteProperty(name.ToString(), types.Contains(name)));
            }

            return(obj);
        }
Esempio n. 3
0
        private void UpdateScenarioProgress_MultipleCmdlets(ProgressStage stage, PrtgObject obj)
        {
            if (ProgressManager.ExpectsContainsProgress)
            {
                if (stage == ProgressStage.PreLoop)
                {
                    ProgressManager.RemovePreviousOperation();
                }
                else if (stage == ProgressStage.BeforeEach)
                {
                    if (!ProgressManager.PipeFromPrtgCmdletPostProcessMode)
                    {
                        ProgressManager.UpdateRecordsProcessed(ProgressManager.CurrentRecord, obj);
                    }
                }
                else //PostLoop
                {
                    ProgressManager.CompleteProgress();
                }
            }

            if (stage == ProgressStage.PostLoop)
            {
                ProgressManager.MaybeCompletePreviousProgress();
            }
        }
Esempio n. 4
0
        internal string GetSingleOperationProgressMessage(PrtgObject obj, int[] ids, string action, string typeDescription, string operationDescription = null)
        {
            if (obj == null && ids.Length == 0)
            {
                throw new ArgumentException($"{nameof(ids)} must be specified when {nameof(obj)} is null.");
            }

            string str;

            //e.g. Acknowledging sensor 'Ping' forever
            if (obj != null)
            {
                str = $"{action} {typeDescription} '{obj.Name}' (ID: {obj.Id})";
            }
            else
            {
                str = $"{action} {typeDescription} {("ID".Plural(ids))} {(string.Join(", ", ids))}";
            }

            if (operationDescription != null)
            {
                str += $" {operationDescription}";
            }

            return(str);
        }
Esempio n. 5
0
        private void ExecuteOperation(PrtgObject obj, string url)
        {
            var server = PrtgRequestMessage.AddUrlPrefix(client.Server);

            if (ShouldProcess($"'{obj}' (ID: {obj.Id}, Type: {obj.Type})"))
            {
                ExecuteOperation(() => Process.Start($"{server}{url}"), $"Opening {obj.GetTypeDescription()} '{obj.Name}'");
            }
        }
Esempio n. 6
0
        internal string TypeDescriptionOrDefault(PrtgObject obj, string @default = "object")
        {
            if (obj == null)
            {
                return(@default);
            }

            return(obj.GetTypeDescription().ToLower());
        }
Esempio n. 7
0
        internal int[] GetSingleOperationId(PrtgObject obj, int[] id)
        {
            if (obj != null)
            {
                return new[] { obj.Id }
            }
            ;

            return(id);
        }
Esempio n. 8
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>
 /// <param name="progressMessage">The progress message to display.</param>
 protected void ExecuteOrQueue(PrtgObject obj, string progressMessage)
 {
     if (Batch.IsPresent)
     {
         ExecuteQueueOperation(obj, progressMessage);
     }
     else
     {
         PerformSingleOperation();
     }
 }
Esempio n. 9
0
        public void Tree_Builds_UntypedObject()
        {
            var probe = new PrtgObject {
                Id = 1001
            };

            var response = new TreeRequestResponse(TreeRequestScenario.ContainerWithChild);

            var client = BaseTest.Initialize_Client(response);

            AssertEx.Throws <NotSupportedException>(
                () => client.GetTree(probe),
                "Cannot process value"
                );
        }
Esempio n. 10
0
        internal static IEnumerable <IGrouping <int, NotificationAction> > GroupActionSchedules(List <NotificationAction> actions)
        {
            var actionsWithSchedules = actions
                                       .GroupBy(a => PrtgObject.GetId(a.lazyScheduleStr)).ToList();

            foreach (var group in actionsWithSchedules)
            {
                if (group.Key == -1)
                {
                    foreach (var action in group)
                    {
                        action.schedule = new LazyValue <Schedule>(action.lazyScheduleStr, () => new Schedule(action.lazyScheduleStr));
                    }
                }
                else
                {
                    yield return(group);
                }
            }
        }
Esempio n. 11
0
        internal string GetShouldProcessMessage(PrtgObject obj, int[] ids, string details = null)
        {
            if (obj == null && ids.Length == 0)
            {
                throw new ArgumentException($"{nameof(ids)} must be specified when {nameof(obj)} is null.");
            }

            if (obj != null)
            {
                var str = $"'{obj.Name}' (ID: {obj.Id}";

                if (details != null)
                {
                    str += $", {details})";
                }
                else
                {
                    str += ")";
                }

                return(str);
            }

            string idStr;

            if (ids.Length == 1)
            {
                idStr = $"ID {ids[0]}";
            }
            else
            {
                idStr = $"{("ID".Plural(ids))} {(string.Join(", ", ids))}";
            }

            if (details != null)
            {
                idStr += $" ({details})";
            }

            return(idStr);
        }
Esempio n. 12
0
        internal static TProperty Get <TProperty>(this PrtgObject obj, Func <TProperty> getValue)
        {
            if (obj is ILazy)
            {
                var lazy = (ILazy)obj;

                lock (lazy.LazyLock)
                {
                    if (lazy.LazyInitialized == false)
                    {
                        if (lazy.LazyXml != null)
                        {
                            XmlDeserializer <PrtgObject> .UpdateType(lazy.LazyXml.Value, obj);
                        }

                        lazy.LazyInitialized = true;
                    }
                }
            }

            return(getValue());
        }
Esempio n. 13
0
        private void ExecuteOperation(PrtgObject obj, string url)
        {
            var server = PrtgUrl.AddUrlPrefix(client.Server);

            ExecuteOperation(() => Process.Start($"{server}{url}"), $"Opening {PrtgProgressCmdlet.GetTypeDescription(obj)} '{obj.Name}'");
        }
Esempio n. 14
0
 /// <summary>
 /// Queues an object for execution after all objects have been identified.
 /// </summary>
 /// <param name="obj">The object to queue.</param>
 /// <param name="progressMessage">The progress message to display.</param>
 private void ExecuteQueueOperation(PrtgObject obj, string progressMessage)
 {
     ExecuteOperation(() => QueueObject(obj), progressMessage);
 }
Esempio n. 15
0
 private void QueueObject(PrtgObject obj)
 {
     objects.Add(obj);
 }
Esempio n. 16
0
        private void ExecuteOperation(PrtgObject obj, string url)
        {
            var server = PrtgRequestMessage.AddUrlPrefix(client.Server);

            ExecuteOperation(() => Process.Start($"{server}{url}"), $"Opening {obj.GetTypeDescription()} '{obj.Name}'");
        }
Esempio n. 17
0
        private CloneCmdletConfig GetCmdletConfig()
        {
            CloneCmdletConfig parameters;

            switch (ParameterSetName)
            {
            case ParameterSet.SensorToDestination:
                parameters = new CloneCmdletConfig(
                    Sensor,
                    Name ?? Sensor.Name,
                    GetSensors
                    );
                break;

            case ParameterSet.DeviceToDestination:
                parameters = new CloneCmdletConfig(
                    Device,
                    string.IsNullOrEmpty(Name) ? $"Clone of {Device.Name}" : Name,
                    Host ?? Device.Host,
                    GetDevices
                    );
                break;

            case ParameterSet.GroupToDestination:
                parameters = new CloneCmdletConfig(
                    Group,
                    Name ?? Group.Name,
                    GetGroups
                    );
                break;

            case ParameterSet.TriggerToDestination:
                parameters = new CloneCmdletConfig(Trigger, null, null);
                break;

            case ParameterSet.TargetForSource:
                DestinationId = Destination.Id;
                parameters    = new CloneCmdletConfig(sourceObj, sourceObj.Name, sourceObjResolver);
                break;

            case ParameterSet.Manual:
                sourceObj = client.GetObject(SourceId);

                if (!MyInvocation.BoundParameters.ContainsKey(nameof(DestinationId)))
                {
                    DestinationId = sourceObj.ParentId;
                }

                parameters = new CloneCmdletConfig(sourceObj, Name ?? $"Clone of {sourceObj.Name}", GetObjects);
                break;

            default:
                throw new UnknownParameterSetException(ParameterSetName);
            }

            if (ParameterSetName != ParameterSet.TriggerToDestination)
            {
                parameters.AllowBasic = true;
            }

            return(parameters);
        }
Esempio n. 18
0
        private void UpdateScenarioProgress_VariableToMultipleCmdlet(ProgressStage stage, PrtgObject obj)
        {
            if (stage == ProgressStage.PreLoop)
            {
                if (ProgressManager.PipelineContainsOperation)
                {
                    if (!ProgressManager.LastInChain)
                    {
                        SetObjectSearchProgress(ProcessingOperation.Processing);
                    }

                    if (ProgressManager.ExpectsContainsProgress)
                    {
                        ProgressManager.RemovePreviousOperation();
                    }
                }
            }
            else if (stage == ProgressStage.BeforeEach)
            {
                //When a variable to cmdlet chain contains an operation, responsibility of updating the number of records processed
                //"resets", and we become responsible for updating our own count again. If that operation was a multi operation cmdlet
                //operating in both batch and paass through mode however, we're still acting as if we've piped from a variable
                if (ProgressManager.PipelineContainsOperation && ProgressManager.ExpectsContainsProgress && !ProgressManager.PipeFromPrtgCmdletPostProcessMode)
                {
                    ProgressManager.UpdateRecordsProcessed(ProgressManager.CurrentRecord, obj);
                }
            }
            else //PostLoop
            {
                UpdateScenarioProgress_VariableToSingleCmdlet(stage);
            }
        }