private HistoryInfo GetHistoryEntryToInvoke(History history) { using (InvokeHistoryCommand._trace.TraceMethod()) { HistoryInfo historyInfo = (HistoryInfo)null; if (this._id == null) { HistoryInfo[] entries = history.GetEntries(0L, 1L, (SwitchParameter)true); if (entries.Length == 1) { historyInfo = entries[0]; } else { this.ThrowTerminatingError(new ErrorRecord((Exception) new InvalidOperationException(ResourceManagerCache.FormatResourceString("History", "NoLastHistoryEntryFound")), "InvokeHistoryNoLastHistoryEntryFound", ErrorCategory.InvalidOperation, (object)null)); } } else { this.PopulateIdAndCommandLine(); if (this._commandLine != null) { HistoryInfo[] entries = history.GetEntries(0L, -1L, (SwitchParameter)false); for (int index = entries.Length - 1; index >= 0; --index) { if (entries[index].CommandLine.StartsWith(this._commandLine, StringComparison.CurrentCulture)) { historyInfo = entries[index]; break; } } if (historyInfo == null) { this.ThrowTerminatingError(new ErrorRecord((Exception) new ArgumentException(ResourceManagerCache.FormatResourceString("History", "NoHistoryForCommandline", (object)this._commandLine)), "InvokeHistoryNoHistoryForCommandline", ErrorCategory.ObjectNotFound, (object)this._commandLine)); } } else if (this._historyId <= 0L) { this.ThrowTerminatingError(new ErrorRecord((Exception) new ArgumentOutOfRangeException("Id", ResourceManagerCache.FormatResourceString("History", "InvalidIdGetHistory", (object)this._historyId)), "InvokeHistoryInvalidIdGetHistory", ErrorCategory.InvalidArgument, (object)this._historyId)); } else { historyInfo = history.GetEntry(this._historyId); if (historyInfo == null || historyInfo.Id != this._historyId) { this.ThrowTerminatingError(new ErrorRecord((Exception) new ArgumentException(ResourceManagerCache.FormatResourceString("History", "NoHistoryForId", (object)this._historyId)), "InvokeHistoryNoHistoryForId", ErrorCategory.ObjectNotFound, (object)this._historyId)); } } } return(historyInfo); } }
private HistoryInfo GetHistoryEntryToInvoke(History history) { HistoryInfo entry = null; if (this._id == null) { HistoryInfo[] infoArray = history.GetEntries((long)0L, 1L, true); if (infoArray.Length == 1) { return(infoArray[0]); } Exception exception = new InvalidOperationException(StringUtil.Format(HistoryStrings.NoLastHistoryEntryFound, new object[0])); base.ThrowTerminatingError(new ErrorRecord(exception, "InvokeHistoryNoLastHistoryEntryFound", ErrorCategory.InvalidOperation, null)); return(entry); } this.PopulateIdAndCommandLine(); if (this._commandLine == null) { if (this._historyId <= 0L) { Exception exception3 = new ArgumentOutOfRangeException("Id", StringUtil.Format(HistoryStrings.InvalidIdGetHistory, this._historyId)); base.ThrowTerminatingError(new ErrorRecord(exception3, "InvokeHistoryInvalidIdGetHistory", ErrorCategory.InvalidArgument, this._historyId)); return(entry); } entry = history.GetEntry(this._historyId); if ((entry == null) || (entry.Id != this._historyId)) { Exception exception4 = new ArgumentException(StringUtil.Format(HistoryStrings.NoHistoryForId, this._historyId)); base.ThrowTerminatingError(new ErrorRecord(exception4, "InvokeHistoryNoHistoryForId", ErrorCategory.ObjectNotFound, this._historyId)); } return(entry); } HistoryInfo[] infoArray2 = history.GetEntries((long)0L, -1L, false); for (int i = infoArray2.Length - 1; i >= 0; i--) { if (infoArray2[i].CommandLine.StartsWith(this._commandLine, StringComparison.CurrentCulture)) { entry = infoArray2[i]; break; } } if (entry == null) { Exception exception2 = new ArgumentException(StringUtil.Format(HistoryStrings.NoHistoryForCommandline, this._commandLine)); base.ThrowTerminatingError(new ErrorRecord(exception2, "InvokeHistoryNoHistoryForCommandline", ErrorCategory.ObjectNotFound, this._commandLine)); } return(entry); }
protected override void ProcessRecord() { History history = ((LocalRunspace)base.Context.CurrentRunspace).History; if (this._id != null) { if (!this._countParameterSpecified) { foreach (long num in this._id) { HistoryInfo entry = history.GetEntry(num); if ((entry != null) && (entry.Id == num)) { base.WriteObject(entry); } else { Exception exception = new ArgumentException(StringUtil.Format(HistoryStrings.NoHistoryForId, num)); base.WriteError(new ErrorRecord(exception, "GetHistoryNoHistoryForId", ErrorCategory.ObjectNotFound, num)); } } } else if (this._id.Length > 1) { Exception exception2 = new ArgumentException(StringUtil.Format(HistoryStrings.NoCountWithMultipleIds, new object[0])); base.ThrowTerminatingError(new ErrorRecord(exception2, "GetHistoryNoCountWithMultipleIds", ErrorCategory.InvalidArgument, this._count)); } else { long id = this._id[0]; base.WriteObject(history.GetEntries(id, (long)this._count, false), true); } } else { if (!this._countParameterSpecified) { this._count = history.Buffercapacity(); } HistoryInfo[] infoArray = history.GetEntries((long)0L, (long)this._count, true); for (long i = infoArray.Length - 1; i >= 0L; i -= 1L) { base.WriteObject(infoArray[(int)((IntPtr)i)]); } } }
protected override void ProcessRecord() { using (GetHistoryCommand._trace.TraceMethod()) { History history = ((LocalRunspace)this.Context.CurrentRunspace).History; if (this._id != null) { if (!this._countParamterSpecified) { foreach (long id in this._id) { HistoryInfo entry = history.GetEntry(id); if (entry != null && entry.Id == id) { this.WriteObject((object)entry); } else { this.WriteError(new ErrorRecord((Exception) new ArgumentException(ResourceManagerCache.FormatResourceString("History", "NoHistoryForId", (object)id)), "GetHistoryNoHistoryForId", ErrorCategory.ObjectNotFound, (object)id)); } } } else if (this._id.Length > 1) { this.ThrowTerminatingError(new ErrorRecord((Exception) new ArgumentException(ResourceManagerCache.FormatResourceString("History", "NoCountWithMultipleIds")), "GetHistoryNoCountWithMultipleIds", ErrorCategory.InvalidArgument, (object)this._count)); } else { long id = this._id[0]; this.WriteObject((object)history.GetEntries(id, (long)this._count, (SwitchParameter)false), true); } } else { HistoryInfo[] entries = history.GetEntries(0L, (long)this._count, (SwitchParameter)true); for (long index = (long)(entries.Length - 1); index >= 0L; --index) { this.WriteObject((object)entries[index]); } } } }
private HistoryInfo GetHistoryEntryToInvoke(History history) { HistoryInfo entry = null; if (this._id == null) { HistoryInfo[] infoArray = history.GetEntries((long) 0L, 1L, true); if (infoArray.Length == 1) { return infoArray[0]; } Exception exception = new InvalidOperationException(StringUtil.Format(HistoryStrings.NoLastHistoryEntryFound, new object[0])); base.ThrowTerminatingError(new ErrorRecord(exception, "InvokeHistoryNoLastHistoryEntryFound", ErrorCategory.InvalidOperation, null)); return entry; } this.PopulateIdAndCommandLine(); if (this._commandLine == null) { if (this._historyId <= 0L) { Exception exception3 = new ArgumentOutOfRangeException("Id", StringUtil.Format(HistoryStrings.InvalidIdGetHistory, this._historyId)); base.ThrowTerminatingError(new ErrorRecord(exception3, "InvokeHistoryInvalidIdGetHistory", ErrorCategory.InvalidArgument, this._historyId)); return entry; } entry = history.GetEntry(this._historyId); if ((entry == null) || (entry.Id != this._historyId)) { Exception exception4 = new ArgumentException(StringUtil.Format(HistoryStrings.NoHistoryForId, this._historyId)); base.ThrowTerminatingError(new ErrorRecord(exception4, "InvokeHistoryNoHistoryForId", ErrorCategory.ObjectNotFound, this._historyId)); } return entry; } HistoryInfo[] infoArray2 = history.GetEntries((long) 0L, -1L, false); for (int i = infoArray2.Length - 1; i >= 0; i--) { if (infoArray2[i].CommandLine.StartsWith(this._commandLine, StringComparison.CurrentCulture)) { entry = infoArray2[i]; break; } } if (entry == null) { Exception exception2 = new ArgumentException(StringUtil.Format(HistoryStrings.NoHistoryForCommandline, this._commandLine)); base.ThrowTerminatingError(new ErrorRecord(exception2, "InvokeHistoryNoHistoryForCommandline", ErrorCategory.ObjectNotFound, this._commandLine)); } return entry; }
private HistoryInfo GetHistoryEntryToInvoke(History history) { HistoryInfo entry = null; //User didn't specify any input parameter. Invoke the last //entry if (_id == null) { HistoryInfo[] entries = history.GetEntries(0, 1, true); if (entries.Length == 1) { entry = entries[0]; } else { Exception ex = new InvalidOperationException ( StringUtil.Format(HistoryStrings.NoLastHistoryEntryFound) ); ThrowTerminatingError ( new ErrorRecord ( ex, "InvokeHistoryNoLastHistoryEntryFound", ErrorCategory.InvalidOperation, null ) ); } } else { //Parse input PopulateIdAndCommandLine(); //User specified a commandline. Get list of all history entries //and find latest match if (_commandLine != null) { HistoryInfo[] entries = history.GetEntries(0, -1, false); // and search backwards through the entries for (int i = entries.Length - 1; i >= 0; i--) { if (entries[i].CommandLine.StartsWith(_commandLine, StringComparison.CurrentCulture)) { entry = entries[i]; break; } } if (entry == null) { Exception ex = new ArgumentException ( StringUtil.Format(HistoryStrings.NoHistoryForCommandline, _commandLine) ); ThrowTerminatingError ( new ErrorRecord ( ex, "InvokeHistoryNoHistoryForCommandline", ErrorCategory.ObjectNotFound, _commandLine ) ); } } else { if (_historyId <= 0) { Exception ex = new ArgumentOutOfRangeException ( "Id", StringUtil.Format(HistoryStrings.InvalidIdGetHistory, _historyId) ); ThrowTerminatingError ( new ErrorRecord ( ex, "InvokeHistoryInvalidIdGetHistory", ErrorCategory.InvalidArgument, _historyId ) ); } else { //Retrieve the command at the index we've specified entry = history.GetEntry(_historyId); if (entry == null || entry.Id != _historyId) { Exception ex = new ArgumentException ( StringUtil.Format(HistoryStrings.NoHistoryForId, _historyId) ); ThrowTerminatingError ( new ErrorRecord ( ex, "InvokeHistoryNoHistoryForId", ErrorCategory.ObjectNotFound, _historyId ) ); } } } } return entry; }