internal PSRemotingTransportRedirectException(
     Exception innerException,
     PSRemotingErrorId errorId,
     params object[] args)
     : base(innerException, errorId, args)
 {
 }
Esempio n. 2
0
        internal static TransportErrorOccuredEventArgs ConstructTransportErrorEventArgs(
            IntPtr wsmanAPIHandle,
            IntPtr wsmanSessionHandle,
            WSManNativeApi.WSManError errorStruct,
            TransportMethodEnum transportMethodReportingError,
            PSRemotingErrorId errorResourceID,
            params object[] resourceArgs)
        {
            PSRemotingTransportException e;

            if (errorStruct.errorCode == -2144108135)
            {
                string sessionOptionAsString = WSManNativeApi.WSManGetSessionOptionAsString(wsmanSessionHandle, WSManNativeApi.WSManSessionOption.WSMAN_OPTION_REDIRECT_LOCATION);
                string str = WSManTransportManagerUtils.ParseEscapeWSManErrorMessage(WSManNativeApi.WSManGetErrorMessage(wsmanAPIHandle, errorStruct.errorCode)).Trim();
                e = (PSRemotingTransportException) new PSRemotingTransportRedirectException(sessionOptionAsString, PSRemotingErrorId.URIEndPointNotResolved, new object[2]
                {
                    (object)str,
                    (object)sessionOptionAsString
                });
            }
            else
            {
                e = new PSRemotingTransportException(PSRemotingErrorId.TroubleShootingHelpTopic, new object[1]
                {
                    (object)PSRemotingErrorInvariants.FormatResourceString(errorResourceID, resourceArgs)
                });
                e.TransportMessage = WSManTransportManagerUtils.ParseEscapeWSManErrorMessage(WSManNativeApi.WSManGetErrorMessage(wsmanAPIHandle, errorStruct.errorCode));
            }
            e.ErrorCode = errorStruct.errorCode;
            return(new TransportErrorOccuredEventArgs(e, transportMethodReportingError));
        }
Esempio n. 3
0
 internal PSRemotingDataStructureException(
     Exception innerException,
     PSRemotingErrorId errorId,
     params object[] args)
     : base(PSRemotingErrorInvariants.FormatResourceString(errorId, args), innerException)
 {
     this.SetDefaultErrorRecord();
 }
Esempio n. 4
0
 private RemoteHostCall ConstructWarningMessageForSecureString(
     string computerName,
     PSRemotingErrorId errorId)
 {
     return(new RemoteHostCall(-100L, RemoteHostMethodId.WriteWarningLine, new object[1]
     {
         (object)PSRemotingErrorInvariants.FormatResourceString(errorId, (object)computerName.ToUpper(CultureInfo.CurrentCulture))
     }));
 }
Esempio n. 5
0
        private RemoteRunspace GetRunspaceMatchingSessionId(int sessionId)
        {
            Predicate <PSSession> condition = info => info.Id == sessionId;
            PSRemotingErrorId     remoteRunspaceNotAvailableForSpecifiedSessionId       = PSRemotingErrorId.RemoteRunspaceNotAvailableForSpecifiedSessionId;
            PSRemotingErrorId     remoteRunspaceHasMultipleMatchesForSpecifiedSessionId = PSRemotingErrorId.RemoteRunspaceHasMultipleMatchesForSpecifiedSessionId;
            string tooFewResourceString  = RemotingErrorIdStrings.RemoteRunspaceNotAvailableForSpecifiedSessionId;
            string tooManyResourceString = RemotingErrorIdStrings.RemoteRunspaceHasMultipleMatchesForSpecifiedSessionId;

            return(this.GetRunspaceMatchingCondition(condition, remoteRunspaceNotAvailableForSpecifiedSessionId, remoteRunspaceHasMultipleMatchesForSpecifiedSessionId, tooFewResourceString, tooManyResourceString, sessionId));
        }
Esempio n. 6
0
        private RemoteRunspace GetRunspaceMatchingName(string name)
        {
            Predicate <PSSession> condition = info => info.Name.Equals(name, StringComparison.OrdinalIgnoreCase);
            PSRemotingErrorId     remoteRunspaceNotAvailableForSpecifiedName       = PSRemotingErrorId.RemoteRunspaceNotAvailableForSpecifiedName;
            PSRemotingErrorId     remoteRunspaceHasMultipleMatchesForSpecifiedName = PSRemotingErrorId.RemoteRunspaceHasMultipleMatchesForSpecifiedName;
            string tooFewResourceString  = RemotingErrorIdStrings.RemoteRunspaceNotAvailableForSpecifiedName;
            string tooManyResourceString = RemotingErrorIdStrings.RemoteRunspaceHasMultipleMatchesForSpecifiedName;

            return(this.GetRunspaceMatchingCondition(condition, remoteRunspaceNotAvailableForSpecifiedName, remoteRunspaceHasMultipleMatchesForSpecifiedName, tooFewResourceString, tooManyResourceString, name));
        }
Esempio n. 7
0
 private bool CheckJobCanBeRemoved(
     Job job,
     string parameterName,
     PSRemotingErrorId id,
     params object[] list)
 {
     using (JobCmdletBase.tracer.TraceMethod())
     {
         if (job.IsFinishedState(job.JobStateInfo.State))
         {
             return(true);
         }
         this.WriteError(new ErrorRecord((Exception) new ArgumentException(PSRemotingErrorInvariants.FormatResourceString(id, list), parameterName), "JobObjectNotFinishedCannotBeRemoved", ErrorCategory.InvalidOperation, (object)job));
         return(false);
     }
 }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
 /// <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;
 }
 internal static string FormatResourceString(PSRemotingErrorId messageId, params object[] args) => ResourceManagerCache.FormatResourceString("RemotingErrorIdStrings", messageId.ToString(), args);
Esempio n. 11
0
 /// <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;
 }
Esempio n. 12
0
 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;
 }
Esempio n. 13
0
 internal string GetMessage(PSRemotingErrorId errorId, params object[] args) => args == null?ResourceManagerCache.GetResourceString("RemotingErrorIdStrings", errorId.ToString()) : ResourceManagerCache.FormatResourceString("RemotingErrorIdStrings", errorId.ToString(), args);
Esempio n. 14
0
 internal string GetMessage(PSRemotingErrorId errorId) => this.GetMessage(errorId, (object[])null);
        private void WriteInvalidArgumentError(PSRemotingErrorId errorId, string resourceString, object errorArgument)
        {
            string message = base.GetMessage(resourceString, new object[] { errorArgument });

            base.WriteError(new ErrorRecord(new ArgumentException(message), errorId.ToString(), ErrorCategory.InvalidArgument, errorArgument));
        }
Esempio n. 16
0
        /// <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));
        }
Esempio n. 17
0
        /// <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;
        }
Esempio n. 18
0
 /// <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;
 }
Esempio n. 19
0
 /// <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;
 }