Beispiel #1
0
		internal static Exception CheckPowershellForException(string cmdletName, CommandType commandType, System.Management.Automation.PowerShell powerShell)
		{
			Exception streamException = PSCommand.CheckInvocationStateInfoForException(powerShell.InvocationStateInfo);
			if (streamException == null)
			{
				streamException = PSCommand.GetStreamException(cmdletName, powerShell.Streams);
			}
			string commandText = powerShell.Commands.Commands[0].CommandText;
			if (streamException != null)
			{
				if (!(streamException.GetType() == typeof(ItemNotFoundException)) || commandType != CommandType.Read && commandType != CommandType.Delete && commandType != CommandType.Update)
				{
					streamException = new CommandInvocationFailedException(commandText, streamException);
				}
				else
				{
					if (commandType == CommandType.Read || commandType == CommandType.Delete)
					{
						string[] str = new string[7];
						str[0] = "Cmdlet ";
						str[1] = cmdletName;
						str[2] = " generated ItemNotFoundException exception. Command string was ";
						str[3] = commandText;
						str[4] = ". But this is a ";
						str[5] = commandType.ToString();
						str[6] = "operation, so suppressing that message";
						TraceHelper.Current.DebugMessage(string.Concat(str));
						streamException = null;
					}
					else
					{
						string[] strArrays = new string[5];
						strArrays[0] = "Cmdlet ";
						strArrays[1] = cmdletName;
						strArrays[2] = " generated ItemNotFoundException exception. Command string was ";
						strArrays[3] = commandText;
						strArrays[4] = ". But the operation is Update, so throwing DataServiceException with 404";
						TraceHelper.Current.DebugMessage(string.Concat(strArrays));
						streamException = new DataServiceException(0x194, null, Resources.ResourceNotFoundException, null, streamException);
					}
				}
			}
			return streamException;
		}
Beispiel #2
0
 public CommandInvocationFailedException(string command, Exception innerException) : base(CommandInvocationFailedException.GetExceptionMessage(command, innerException), innerException)
 {
     this.CommandName = command;
     if (innerException == null)
     {
         TraceHelper.Current.CommandInvocationFailedException(command, string.Empty, string.Empty);
     }
     else
     {
         TraceHelper.Current.CommandInvocationFailedException(command, innerException.GetType().ToString(), innerException.Message);
     }
     base.Trace();
 }