Esempio n. 1
0
        /// <summary>
        /// <para>
        /// Handler used to handle new action event from
        /// <seealso cref="CimSessionProxy"/> object.
        /// </para>
        /// </summary>
        /// <param name="cimSession">
        /// <seealso cref="CimSession"/> object raised the event
        /// </param>
        /// <param name="actionArgs">event argument</param>
        private void CimIndicationHandler(object cimSession, CmdletActionEventArgs actionArgs)
        {
            DebugHelper.WriteLogEx("action is {0}. Disposed {1}", 0, actionArgs.Action, this.Disposed);

            if (this.Disposed)
            {
                return;
            }

            // NOTES: should move after this.Disposed, but need to log the exception
            CimWriteError cimWriteError = actionArgs.Action as CimWriteError;

            if (cimWriteError != null)
            {
                this.exception = cimWriteError.Exception;
                if (!this.ackedEvent.IsSet)
                {
                    // an exception happened
                    DebugHelper.WriteLogEx("an exception happened", 0);
                    this.ackedEvent.Set();
                    return;
                }
                EventHandler <CimSubscriptionEventArgs> temp = this.OnNewSubscriptionResult;
                if (temp != null)
                {
                    DebugHelper.WriteLog("Raise an exception event", 2);

                    temp(this, new CimSubscriptionExceptionEventArgs(this.exception));
                }
                DebugHelper.WriteLog("Got an exception: {0}", 2, exception);
            }

            CimWriteResultObject cimWriteResultObject = actionArgs.Action as CimWriteResultObject;

            if (cimWriteResultObject != null)
            {
                CimSubscriptionResult result = cimWriteResultObject.Result as CimSubscriptionResult;
                if (result != null)
                {
                    EventHandler <CimSubscriptionEventArgs> temp = this.OnNewSubscriptionResult;
                    if (temp != null)
                    {
                        DebugHelper.WriteLog("Raise an result event", 2);
                        temp(this, new CimSubscriptionResultEventArgs(result));
                    }
                }
                else
                {
                    if (!this.ackedEvent.IsSet)
                    {
                        // an ACK message returned
                        DebugHelper.WriteLogEx("an ack message happened", 0);
                        this.ackedEvent.Set();
                        return;
                    }
                    else
                    {
                        DebugHelper.WriteLogEx("an ack message should not happen here", 0);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// <para>
        /// Handle async event triggered by <see cref="CimResultObserver<T>"/>
        /// </para>
        /// </summary>
        /// <param name="observer">object triggered the event</param>
        /// <param name="resultArgs">async result event argument</param>
        internal void ResultEventHandler(
            object observer,
            AsyncResultEventArgsBase resultArgs)
        {
            DebugHelper.WriteLogEx();
            switch (resultArgs.resultType)
            {
                case AsyncResultType.Completion:
                    {
                        DebugHelper.WriteLog("ResultEventHandler::Completion", 4);

                        AsyncResultCompleteEventArgs args = resultArgs as AsyncResultCompleteEventArgs;
                        this.FireOperationDeletedEvent(args.observable, true);
                    }
                    break;
                case AsyncResultType.Exception:
                    {
                        AsyncResultErrorEventArgs args = resultArgs as AsyncResultErrorEventArgs;
                        DebugHelper.WriteLog("ResultEventHandler::Exception {0}", 4, args.error);

                        using (CimWriteError action = new CimWriteError(args.error, this.invocationContextObject, args.context))
                        {
                            this.FireNewActionEvent(action);
                        }
                        this.FireOperationDeletedEvent(args.observable, false);
                    }
                    break;
                case AsyncResultType.Result:
                    {
                        AsyncResultObjectEventArgs args = resultArgs as AsyncResultObjectEventArgs;
                        DebugHelper.WriteLog("ResultEventHandler::Result {0}", 4, args.resultObject);
                        object resultObject = args.resultObject;
                        if (!this.isDefaultSession)
                        {
                            AddShowComputerNameMarker(resultObject);
                        }
                        if (this.ObjectPreProcess != null)
                        {
                            resultObject = this.ObjectPreProcess.Process(resultObject);
                        }
#if DEBUG
                        resultObject = PostProcessCimInstance(resultObject);
#endif
                        CimWriteResultObject action = new CimWriteResultObject(resultObject, this.ContextObject);
                        this.FireNewActionEvent(action);
                    }
                    break;
                default:
                    break;
            }
        }
Esempio n. 3
0
 /// <summary>
 /// <para>
 /// WriteError callback
 /// </para>
 /// </summary>
 /// <param name="instance"></param>
 /// <returns></returns>
 public CimResponseType WriteError(CimInstance instance)
 {
     DebugHelper.WriteLogEx("Error:{0}", 0, instance);
     try
     {
         CimWriteError action = new CimWriteError(instance, this.invocationContextObject);
         this.FireNewActionEvent(action);
         return action.GetResponse();
     }
     catch (Exception ex)
     {
         DebugHelper.WriteLogEx("{0}", 0, ex);
         return CimResponseType.NoToAll;
     }
 }
 private void CimIndicationHandler(object cimSession, CmdletActionEventArgs actionArgs)
 {
     object[] action = new object[2];
     action[0] = actionArgs.Action;
     action[1] = base.Disposed;
     DebugHelper.WriteLogEx("action is {0}. Disposed {1}", 0, action);
     if (!base.Disposed)
     {
         CimWriteError cimWriteError = actionArgs.Action as CimWriteError;
         if (cimWriteError != null)
         {
             this.exception = cimWriteError.Exception;
             if (this.ackedEvent.IsSet)
             {
                 EventHandler <CimSubscriptionEventArgs> eventHandler = this.OnNewSubscriptionResult;
                 if (eventHandler != null)
                 {
                     DebugHelper.WriteLog("Raise an exception event", 2);
                     eventHandler(this, new CimSubscriptionExceptionEventArgs(this.exception));
                 }
                 object[] objArray = new object[1];
                 objArray[0] = this.exception;
                 DebugHelper.WriteLog("Got an exception: {0}", 2, objArray);
             }
             else
             {
                 DebugHelper.WriteLogEx("an exception happened", 0);
                 this.ackedEvent.Set();
                 return;
             }
         }
         CimWriteResultObject cimWriteResultObject = actionArgs.Action as CimWriteResultObject;
         if (cimWriteResultObject != null)
         {
             CimSubscriptionResult result = cimWriteResultObject.Result as CimSubscriptionResult;
             if (result == null)
             {
                 if (this.ackedEvent.IsSet)
                 {
                     DebugHelper.WriteLogEx("an ack message should not happen here", 0);
                 }
                 else
                 {
                     DebugHelper.WriteLogEx("an ack message happened", 0);
                     this.ackedEvent.Set();
                     return;
                 }
             }
             else
             {
                 EventHandler <CimSubscriptionEventArgs> eventHandler1 = this.OnNewSubscriptionResult;
                 if (eventHandler1 != null)
                 {
                     DebugHelper.WriteLog("Raise an result event", 2);
                     eventHandler1(this, new CimSubscriptionResultEventArgs(result));
                     return;
                 }
             }
         }
         return;
     }
     else
     {
         return;
     }
 }
Esempio n. 5
0
		public CimResponseType WriteError(CimInstance instance)
		{
			CimResponseType response;
			object[] objArray = new object[1];
			objArray[0] = instance;
			DebugHelper.WriteLogEx("Error:{0}", 0, objArray);
			try
			{
				CimWriteError cimWriteError = new CimWriteError(instance, this.invocationContextObject);
				this.FireNewActionEvent(cimWriteError);
				response = cimWriteError.GetResponse();
			}
			catch (Exception exception1)
			{
				Exception exception = exception1;
				object[] objArray1 = new object[1];
				objArray1[0] = exception;
				DebugHelper.WriteLogEx("{0}", 0, objArray1);
				response = CimResponseType.NoToAll;
			}
			return response;
		}
Esempio n. 6
0
		internal void ResultEventHandler(object observer, AsyncResultEventArgsBase resultArgs)
		{
			DebugHelper.WriteLogEx();
			AsyncResultType asyncResultType = resultArgs.resultType;
			switch (asyncResultType)
			{
				case AsyncResultType.Result:
				{
					AsyncResultObjectEventArgs asyncResultObjectEventArg = resultArgs as AsyncResultObjectEventArgs;
					object[] objArray = new object[1];
					objArray[0] = asyncResultObjectEventArg.resultObject;
					DebugHelper.WriteLog("ResultEventHandler::Result {0}", 4, objArray);
					object obj = asyncResultObjectEventArg.resultObject;
					if (!this.isDefaultSession)
					{
						CimSessionProxy.AddShowComputerNameMarker(obj);
					}
					if (this.ObjectPreProcess != null)
					{
						obj = this.ObjectPreProcess.Process(obj);
					}
					CimWriteResultObject cimWriteResultObject = new CimWriteResultObject(obj, this.ContextObject);
					this.FireNewActionEvent(cimWriteResultObject);
					return;
				}
				case AsyncResultType.Exception:
				{
					AsyncResultErrorEventArgs asyncResultErrorEventArg = resultArgs as AsyncResultErrorEventArgs;
					object[] objArray1 = new object[1];
					objArray1[0] = asyncResultErrorEventArg.error;
					DebugHelper.WriteLog("ResultEventHandler::Exception {0}", 4, objArray1);
					using (CimWriteError cimWriteError = new CimWriteError(asyncResultErrorEventArg.error, this.invocationContextObject, asyncResultErrorEventArg.context))
					{
						this.FireNewActionEvent(cimWriteError);
					}
					this.FireOperationDeletedEvent(asyncResultErrorEventArg.observable, false);
					return;
				}
				case AsyncResultType.Completion:
				{
					DebugHelper.WriteLog("ResultEventHandler::Completion", 4);
					AsyncResultCompleteEventArgs asyncResultCompleteEventArg = resultArgs as AsyncResultCompleteEventArgs;
					this.FireOperationDeletedEvent(asyncResultCompleteEventArg.observable, true);
					return;
				}
				default:
				{
					return;
				}
			}
		}