Пример #1
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}'");
        }
Пример #2
0
 private ProgressTask(Lazy <List <TResult> > task, PrtgProgressCmdlet cmdlet)
 {
     this.task   = task;
     this.cmdlet = cmdlet;
 }
Пример #3
0
 /// <summary>
 /// Create a sequence of progress tasks for processing a process containing two or more operations.
 /// </summary>
 /// <typeparam name="TNewResult">The type of object returned by the first operation.</typeparam>
 /// <param name="func">The first operation to execute.</param>
 /// <param name="cmdlet">The cmdlet that should display progress.</param>
 /// <param name="typeDescription">The type description use for the progress.</param>
 /// <param name="operationDescription">The progress description to use for the first operation.</param>
 /// <returns></returns>
 public static ProgressTask <TNewResult> Create <TNewResult>(Func <List <TNewResult> > func, PrtgProgressCmdlet cmdlet, string typeDescription, string operationDescription)
 {
     return(new ProgressTask <TNewResult>(() =>
     {
         cmdlet.TypeDescription = typeDescription;
         cmdlet.OperationTypeDescription = operationDescription;
         cmdlet.DisplayProgress(false);
         return func();
     }, cmdlet));
 }
Пример #4
0
 private ProgressTask(Func <List <TResult> > function, PrtgProgressCmdlet cmdlet)
 {
     task        = new Lazy <List <TResult> >(function);
     this.cmdlet = cmdlet;
 }
Пример #5
0
 /// <summary>
 /// Invokes this cmdlet's action against the current object in the pipeline.
 /// </summary>
 protected override void PerformSingleOperation()
 {
     ExecuteOperation(() => client.RenameObject(Object.Id, Name), $"Renaming {PrtgProgressCmdlet.GetTypeDescription(Object).ToLower()} '{Object.Name}' to '{Name}'");
 }
Пример #6
0
        private void ProcessUnsafeRecord()
        {
            string continueStr;
            string whatIfStr;

            if (ParameterSetName == ParameterSet.RawProperty)
            {
                var vals   = RawValue.Select(v => $"'{v}'").ToList();
                var plural = vals.Count > 1 ? "s" : "";

                continueStr = $"property '{RawProperty}' to value{plural} {string.Join(", ", vals)}";
                whatIfStr   = "{RawProperty} = '{RawValue}'";
            }
            else if (ParameterSetName == ParameterSet.Raw)
            {
                var vals = parameters.Select(p => $"{p.Name} = '{p.Value}'");
                whatIfStr   = $"{string.Join(", ", vals)}";
                continueStr = $"properties {whatIfStr}";
            }
            else
            {
                throw new NotImplementedException($"Don't know how to handle parameter set '{ParameterSetName}'");
            }

            if (Force || ShouldContinue($"Are you sure you want to set raw object {continueStr} on {PrtgProgressCmdlet.GetTypeDescription(Object.GetType()).ToLower()} '{Object.Name}'? This may cause minor corruption if the specified value is not valid for the target property. Only proceed if you know what you are doing.", "WARNING!"))
            {
                if (ShouldProcess($"{Object.Name} (ID: {Object.Id})", $"Set-ObjectProperty {whatIfStr}"))
                {
                    ExecuteOrQueue(Object);
                }
            }
        }
Пример #7
0
 /// <summary>
 /// Invokes this cmdlet's action against the current object in the pipeline.
 /// </summary>
 protected override void PerformSingleOperation()
 {
     ExecuteOperation(() => client.RemoveObject(Object.Id), $"Removing {PrtgProgressCmdlet.GetTypeDescription(Object).ToLower()} '{Object.Name}' (ID: {Object.Id})");
 }
Пример #8
0
        /// <summary>
        /// Performs enhanced record-by-record processing functionality for the cmdlet.
        /// </summary>
        protected override void ProcessRecordEx()
        {
            if (ShouldProcess($"'{Object.Name}' (ID: {Object.Id})"))
            {
                if (Force.IsPresent || ShouldContinue($"Are you sure you want to delete {PrtgProgressCmdlet.GetTypeDescription(Object).ToLower()} '{Object.Name}' (ID: {Object.Id})", "WARNING!"))
                {
                    if (Force.IsPresent && batch == null)
                    {
                        Batch = true;
                    }

                    ExecuteOrQueue(Object);
                }
            }
        }