public static void ProcessRecordEx(PrtgOperationCmdlet cmdlet, Action <Action, string> executeOperation, TriggerParameters parameters, Action executeAndResolve = null, string whatIfAction = null, string whatIfTarget = null)
        {
            if (whatIfAction == null)
            {
                whatIfAction = cmdlet.MyInvocation.MyCommand.Name;
            }

            if (whatIfTarget == null)
            {
                whatIfTarget = $"Object ID: {parameters.ObjectId} (Type: {parameters.Type}, Action: {parameters.OnNotificationAction})";
            }

            if (cmdlet.ShouldProcess(whatIfTarget, whatIfAction))
            {
                if (cmdlet is AddNotificationTrigger)
                {
                    executeOperation(() =>
                    {
                        if (executeAndResolve == null)
                        {
                            PrtgSessionState.Client.AddNotificationTrigger(parameters, false);
                        }
                        else
                        {
                            executeAndResolve();
                        }
                    }, $"Adding notification trigger '{parameters.OnNotificationAction?.Name ?? "None"}' to object ID {parameters.ObjectId}");
                }
                else
                {
                    executeOperation(() => PrtgSessionState.Client.SetNotificationTrigger(parameters), $"Updating notification trigger with ID {parameters.ObjectId} (Sub ID: {parameters.SubId})");
                }
            }
        }
コード例 #2
0
        internal void ProcessRecord()
        {
            var str = Object != null ?
                      $"'{Object.Name}' ({subObjectTypeDescription} ID: {Object.SubId}, {objectTypeDescription} ID: {Object.ObjectId})" :
                      $"{subObjectTypeDescription} ID: {SubId} ({objectTypeDescription} ID: {ObjectId})";

            if (!cmdlet.MyInvocation.BoundParameters.ContainsKey(nameof(Value)) && !DynamicSet())
            {
                throw new ParameterBindingException($"{nameof(Value)} parameter is mandatory, however a value was not specified. If {nameof(Value)} should be empty, specify $null.");
            }

            if (Object != null)
            {
                ObjectId = Object.ObjectId;
                SubId    = Object.SubId;
            }

            if (cmdlet.ShouldProcess(str, $"{cmdlet.MyInvocation.MyCommand} {GetShouldProcessMessage()}"))
            {
                var desc = Object != null ? Object.Name : $"ID {SubId}";

                //Can't batch something if there's no pipeline input
                if (Object == null && multiCmdlet != null)
                {
                    multiCmdlet.Batch = false;
                }

                if (multiCmdlet != null)
                {
                    multiCmdlet.ExecuteOrQueue(Object, $"Queuing {subObjectTypeDescription.ToLower()} '{desc}'");
                }
                else
                {
                    PerformSingleOperation();
                }
            }
        }