public void DecreaseIndentation() { TaskLogger.DecreaseIndentation(); }
private bool InternalExecuteScript(string script, bool handleError, int subSteps, LocalizedString statusDescription) { bool result = false; WorkUnit workUnit = new WorkUnit(); bool newSubProgressReceived = false; int completedSubSteps = 0; try { script.TrimEnd(new char[] { '\n' }); string script2 = script.Replace("\n", "\r\n"); if (handleError) { base.WriteVerbose(Strings.ExecutingScriptNonFatal(script2)); } else { base.WriteVerbose(Strings.ExecutingScript(script2)); } script = string.Format("$error.Clear(); {0}", script); MonadCommand monadCommand = new MonadCommand(script, this.monadConnection); monadCommand.CommandType = CommandType.Text; monadCommand.ProgressReport += delegate(object sender, ProgressReportEventArgs e) { if (subSteps == 0) { return; } completedSubSteps = subSteps * e.ProgressRecord.PercentComplete / 100; newSubProgressReceived = true; }; bool flag = false; try { TaskLogger.IncreaseIndentation(); TaskLogger.LogErrorAsWarning = handleError; MonadAsyncResult monadAsyncResult = monadCommand.BeginExecute(new WorkUnit[] { workUnit }); while (!flag) { flag = monadAsyncResult.AsyncWaitHandle.WaitOne(200, false); if (newSubProgressReceived) { base.WriteProgress(this.Description, statusDescription, (this.completedSteps + completedSubSteps) * 100 / this.totalSteps); newSubProgressReceived = false; } if (base.Stopping) { break; } } if (base.Stopping) { monadCommand.Cancel(); } else { monadCommand.EndExecute(monadAsyncResult); } } catch (CommandExecutionException ex) { if (ex.InnerException != null) { throw new ScriptExecutionException(Strings.ErrorCommandExecutionException(script, ex.InnerException.ToString()), ex.InnerException); } throw; } finally { TaskLogger.DecreaseIndentation(); } this.completedSteps += subSteps; result = true; } catch (CmdletInvocationException ex2) { result = false; if (!handleError) { throw; } base.WriteVerbose(Strings.IgnoringException(ex2.ToString())); base.WriteVerbose(Strings.WillContinueProcessing); } if (workUnit.Errors.Count > 0) { result = false; int count = workUnit.Errors.Count; base.WriteVerbose(Strings.ErrorDuringTaskExecution(count)); for (int i = 0; i < count; i++) { ErrorRecord errorRecord = workUnit.Errors[i]; base.WriteVerbose(Strings.ErrorRecordReport(errorRecord.ToString(), i)); if (!handleError) { base.WriteVerbose(Strings.ErrorRecordReport(errorRecord.Exception.ToString(), i)); ScriptExecutionException exception = new ScriptExecutionException(Strings.ErrorCommandExecutionException(script, errorRecord.Exception.ToString()), errorRecord.Exception); this.WriteError(exception, errorRecord.CategoryInfo.Category, errorRecord.TargetObject, false); } } if (handleError) { base.WriteVerbose(Strings.WillIgnoreNoncriticalErrors); base.WriteVerbose(Strings.WillContinueProcessing); } } return(result); }