/// <summary> /// Write invalid argument error. /// </summary> private void WriteInvalidArgumentError(PSRemotingErrorId errorId, string resourceString, object errorArgument) { String message = GetMessage(resourceString, errorArgument); WriteError(new ErrorRecord(new ArgumentException(message), errorId.ToString(), ErrorCategory.InvalidArgument, errorArgument)); }
/// <summary> /// This constructor takes an redirect URI, error id and optional parameters. /// </summary> /// <param name="redirectLocation"> /// String specifying a redirect location. /// </param> /// <param name="errorId"> /// The error id in the base resource file. /// </param> /// <param name="resourceString"> /// The resource string in the base resource file. /// </param> /// <param name="args"> /// Optional parameters required to format the resource string. /// </param> internal PSRemotingTransportRedirectException(string redirectLocation, PSRemotingErrorId errorId, string resourceString, params object[] args) : base(errorId, resourceString, args) { RedirectLocation = redirectLocation; }
/// <summary> /// Get runspace matching condition. /// </summary> private RemoteRunspace GetRunspaceMatchingCondition( Predicate<PSSession> condition, PSRemotingErrorId tooFew, PSRemotingErrorId tooMany, string tooFewResourceString, string tooManyResourceString, object errorArgument) { // Find matches. List<PSSession> matches = this.RunspaceRepository.Runspaces.FindAll(condition); // Validate. RemoteRunspace remoteRunspace = null; if (matches.Count == 0) { WriteInvalidArgumentError(tooFew, tooFewResourceString, errorArgument); } else if (matches.Count > 1) { WriteInvalidArgumentError(tooMany, tooManyResourceString, errorArgument); } else { remoteRunspace = (RemoteRunspace)matches[0].Runspace; Dbg.Assert(remoteRunspace != null, "Expected remoteRunspace != null"); } return remoteRunspace; }
/// <summary> /// This constructor takes an error id and optional parameters. /// </summary> /// <param name="errorId"> /// The error id in the base resource file. /// </param> /// <param name="resourceString"> /// The resource string in the base resource file. /// </param> /// <param name="args"> /// Optional parameters required to format the resource string. /// </param> internal PSRemotingTransportException(PSRemotingErrorId errorId, string resourceString, params object[] args) : base(PSRemotingErrorInvariants.FormatResourceString(resourceString, args)) { SetDefaultErrorRecord(); _errorCode = (int)errorId; }
private RemoteRunspace GetRunspaceMatchingCondition(Predicate<PSSession> condition, PSRemotingErrorId tooFew, PSRemotingErrorId tooMany, string tooFewResourceString, string tooManyResourceString, object errorArgument) { List<PSSession> list = base.RunspaceRepository.Runspaces.FindAll(condition); RemoteRunspace runspace = null; if (list.Count == 0) { this.WriteInvalidArgumentError(tooFew, tooFewResourceString, errorArgument); return runspace; } if (list.Count > 1) { this.WriteInvalidArgumentError(tooMany, tooManyResourceString, errorArgument); return runspace; } return (RemoteRunspace) list[0].Runspace; }