Exemplo n.º 1
0
        /// <summary>
        /// <para>
        /// Convert ErrorRecord from exception object, <see cref="Exception"/>
        /// can be either <see cref="CimException"/> or general <see cref="Exception"/>.
        /// </para>
        /// </summary>
        /// <param name="inner"></param>
        /// <param name="context">the context starting the operation, which generated the error</param>
        /// <param name="cimResultContext">the CimResultContext used to provide ErrorSource, etc. info.</param>
        /// <returns></returns>
        internal static ErrorRecord ErrorRecordFromAnyException(
            InvocationContext context,
            Exception inner,
            CimResultContext cimResultContext)
        {
            Debug.Assert(inner != null, "Caller should verify inner != null");

            CimException cimException = inner as CimException;
            if (cimException != null)
            {
                return CreateFromCimException(context, cimException, cimResultContext);
            }

            var containsErrorRecord = inner as IContainsErrorRecord;
            if (containsErrorRecord != null)
            {
                return InitializeErrorRecord(context,
                    exception : inner,
                    errorId: "CimCmdlet_" + containsErrorRecord.ErrorRecord.FullyQualifiedErrorId,
                    errorCategory: containsErrorRecord.ErrorRecord.CategoryInfo.Category,
                    cimResultContext: cimResultContext);
            }
            else
            {
                return InitializeErrorRecord(context,
                    exception :inner,
                    errorId: "CimCmdlet_" + inner.GetType().Name,
                    errorCategory: ErrorCategory.NotSpecified,
                    cimResultContext: cimResultContext);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create <see cref="ErrorRecord"/> from <see cref="CimException"/> object.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="cimException"></param>
        /// <param name="cimResultContext">the CimResultContext used to provide ErrorSource, etc. info.</param>
        /// <returns></returns>
        internal static ErrorRecord CreateFromCimException(
            InvocationContext context,
            CimException cimException,
            CimResultContext cimResultContext)
        {
            Debug.Assert(cimException != null, "Caller should verify cimException != null");

            return InitializeErrorRecord(context, cimException, cimResultContext);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create <see cref="ErrorRecord"/> from <see cref="Exception"/> object.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="exception"></param>
 /// <param name="errorId"></param>
 /// <param name="errorCategory"></param>
 /// <param name="cimResultContext">the CimResultContext used to provide ErrorSource, etc. info.</param>
 /// <returns></returns>
 internal static ErrorRecord InitializeErrorRecord(
     InvocationContext context,
     Exception exception,
     string errorId,
     ErrorCategory errorCategory,
     CimResultContext cimResultContext)
 {
     return InitializeErrorRecordCore(
         context,
         exception: exception,
         errorId: errorId,
         errorCategory: errorCategory,
         cimResultContext: cimResultContext);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor with an <see cref="CimInstance"/> error
 /// </summary>
 /// <param name="error"></param>
 public CimWriteError(CimInstance error, InvocationContext context)
 {
     this.error = error;
     this.invocationContext = context;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Construct with an exception object
 /// </summary>
 /// <param name="exception"></param>
 public CimWriteError(Exception exception, InvocationContext context, CimResultContext cimResultContext)
 {
     this.exception = exception;
     this.invocationContext = context;
     this.cimResultContext = cimResultContext;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Create <see cref="ErrorRecord"/> from <see cref="CimException"/> object.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="cimException"></param>
        /// <param name="cimResultContext">the CimResultContext used to provide ErrorSource, etc. info.</param>
        /// <returns></returns>
        internal static ErrorRecord InitializeErrorRecord(
            InvocationContext context,
            CimException cimException,
            CimResultContext cimResultContext)
        {
            ErrorRecord errorRecord = InitializeErrorRecordCore(
                context,
                exception: cimException,
                errorId: cimException.MessageId ?? "MiClientApiError_" + cimException.NativeErrorCode,
                errorCategory: ConvertCimExceptionToErrorCategory(cimException),
                cimResultContext: cimResultContext);

            if (cimException.ErrorData != null)
            {
                errorRecord.CategoryInfo.TargetName = cimException.ErrorSource;
            }
            return errorRecord;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create <see cref="ErrorRecord"/> from <see cref="Exception"/> object.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="exception"></param>
        /// <param name="errorId"></param>
        /// <param name="errorCategory"></param>
        /// <param name="cimResultContext">the CimResultContext used to provide ErrorSource, etc. info.</param>
        /// <returns></returns>
        internal static ErrorRecord InitializeErrorRecordCore(
            InvocationContext context,
            Exception exception,
            string errorId,
            ErrorCategory errorCategory,
            CimResultContext cimResultContext)
        {
            object theTargetObject = null;
            if (cimResultContext != null)
            {
                theTargetObject = cimResultContext.ErrorSource;
            }
            if (theTargetObject == null)
            {
                if (context != null)
                {
                    if (context.TargetCimInstance != null)
                    {
                        theTargetObject = context.TargetCimInstance;
                    }
                }
            }
            ErrorRecord coreErrorRecord = new ErrorRecord(
                exception: exception,
                errorId: errorId,
                errorCategory: errorCategory,
                targetObject: theTargetObject);

            if (context == null)
            {
                return coreErrorRecord;
            }

            System.Management.Automation.Remoting.OriginInfo originInfo = new System.Management.Automation.Remoting.OriginInfo(
                context.ComputerName,
                Guid.Empty);

            ErrorRecord errorRecord = new System.Management.Automation.Runspaces.RemotingErrorRecord(
                coreErrorRecord,
                originInfo);

            DebugHelper.WriteLogEx("Created RemotingErrorRecord.", 0);
            // errorRecord.SetInvocationInfo(jobContext.CmdletInvocationInfo);
            // errorRecord.PreserveInvocationInfoOnce = true;
            return errorRecord;
        }
Exemplo n.º 8
0
		internal static ErrorRecord InitializeErrorRecord(InvocationContext context, CimException cimException, CimResultContext cimResultContext)
		{
			InvocationContext invocationContext = context;
			CimException cimException1 = cimException;
			string messageId = cimException.MessageId;
			string str = messageId;
			if (messageId == null)
			{
				str = string.Concat("MiClientApiError_", cimException.NativeErrorCode);
			}
			ErrorRecord errorSource = ErrorToErrorRecord.InitializeErrorRecordCore(invocationContext, cimException1, str, ErrorToErrorRecord.ConvertCimExceptionToErrorCategory(cimException), cimResultContext);
			if (cimException.ErrorData != null)
			{
				errorSource.CategoryInfo.TargetName = cimException.ErrorSource;
			}
			return errorSource;
		}
Exemplo n.º 9
0
		internal static ErrorRecord InitializeErrorRecordCore(InvocationContext context, Exception exception, string errorId, ErrorCategory errorCategory, CimResultContext cimResultContext)
		{
			object errorSource = null;
			if (cimResultContext != null)
			{
				errorSource = cimResultContext.ErrorSource;
			}
			if (errorSource == null && context != null && context.TargetCimInstance != null)
			{
				errorSource = context.TargetCimInstance;
			}
			ErrorRecord errorRecord = new ErrorRecord(exception, errorId, errorCategory, errorSource);
			if (context != null)
			{
				OriginInfo originInfo = new OriginInfo(context.ComputerName, Guid.Empty);
				ErrorRecord remotingErrorRecord = new RemotingErrorRecord(errorRecord, originInfo);
				DebugHelper.WriteLogEx("Created RemotingErrorRecord.", 0);
				return remotingErrorRecord;
			}
			else
			{
				return errorRecord;
			}
		}
Exemplo n.º 10
0
		internal static ErrorRecord ErrorRecordFromAnyException(InvocationContext context, Exception inner, CimResultContext cimResultContext)
		{
			CimException cimException = inner as CimException;
			if (cimException == null)
			{
				IContainsErrorRecord containsErrorRecord = inner as IContainsErrorRecord;
				if (containsErrorRecord == null)
				{
					return ErrorToErrorRecord.InitializeErrorRecord(context, inner, string.Concat("CimCmdlet_", inner.GetType().Name), ErrorCategory.NotSpecified, cimResultContext);
				}
				else
				{
					return ErrorToErrorRecord.InitializeErrorRecord(context, inner, string.Concat("CimCmdlet_", containsErrorRecord.ErrorRecord.FullyQualifiedErrorId), containsErrorRecord.ErrorRecord.CategoryInfo.Category, cimResultContext);
				}
			}
			else
			{
				return ErrorToErrorRecord.CreateFromCimException(context, cimException, cimResultContext);
			}
		}
Exemplo n.º 11
0
		internal static ErrorRecord CreateFromCimException(InvocationContext context, CimException cimException, CimResultContext cimResultContext)
		{
			return ErrorToErrorRecord.InitializeErrorRecord(context, cimException, cimResultContext);
		}
Exemplo n.º 12
0
 /// <summary>
 /// Construct with an exception object
 /// </summary>
 /// <param name="exception"></param>
 public CimWriteError(Exception exception, InvocationContext context, CimResultContext cimResultContext)
 {
     this.exception         = exception;
     this.invocationContext = context;
     this.cimResultContext  = cimResultContext;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Constructor with an <see cref="CimInstance"/> error
 /// </summary>
 /// <param name="error"></param>
 public CimWriteError(CimInstance error, InvocationContext context)
 {
     this.error             = error;
     this.invocationContext = context;
 }
Exemplo n.º 14
0
		private void CreateSetSession(string computerName, CimSession cimSession, CimSessionOptions sessionOptions, CimOperationOptions operOptions, bool temporaryCimSession)
		{
			string nullComputerName;
			object[] objArray = new object[4];
			objArray[0] = computerName;
			objArray[1] = cimSession;
			objArray[2] = sessionOptions;
			objArray[3] = operOptions;
			DebugHelper.WriteLogEx("computername {0}; cimsession {1}; sessionOptions {2}; operationOptions {3}.", 0, objArray);
			lock (this.stateLock)
			{
				this.CancelOperation = null;
				this.operation = null;
			}
			this.InitOption(operOptions);
			this.protocol = ProtocolType.Wsman;
			this.isTemporaryCimSession = temporaryCimSession;

			if (cimSession == null)
			{
				if (sessionOptions == null)
				{
					this.session = this.CreateCimSessionByComputerName(computerName);
				}
				else
				{
					if (sessionOptions as DComSessionOptions == null)
					{
						this.session = CimSession.Create(computerName, sessionOptions);
					}
					else
					{
						if (ConstValue.IsDefaultComputerName(computerName))
						{
							nullComputerName = ConstValue.NullComputerName;
						}
						else
						{
							nullComputerName = computerName;
						}
						string str = nullComputerName;
						this.session = CimSession.Create(str, sessionOptions);
						this.protocol = ProtocolType.Dcom;
					}
				}
				this.isTemporaryCimSession = true;
			}
			else
			{
				this.session = cimSession;
				CimSessionState cimSessionState = CimSessionBase.GetCimSessionState();
				if (cimSessionState != null)
				{
					CimSessionWrapper cimSessionWrapper = cimSessionState.QuerySession(cimSession);
					if (cimSessionWrapper != null)
					{
						this.protocol = cimSessionWrapper.GetProtocolType();
					}
				}
			}
			if (this.isTemporaryCimSession)
			{
				CimSessionProxy.AddCimSessionToTemporaryCache(this.session);
			}
			this.invocationContextObject = new InvocationContext(this);
			object[] objArray1 = new object[2];
			objArray1[0] = this.protocol;
			objArray1[1] = this.isTemporaryCimSession;
			DebugHelper.WriteLog("Protocol {0}, Is temporary session ? {1}", 1, objArray1);
		}