Ejemplo n.º 1
0
        public override void Execute(CmdletOperationBase cmdlet)
        {
            ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");
            CimWriteMessageChannel cimWriteMessageChannel = (CimWriteMessageChannel)this.channel;

            switch (cimWriteMessageChannel)
            {
            case CimWriteMessageChannel.Warning:
            {
                cmdlet.WriteWarning(this.message);
                return;
            }

            case CimWriteMessageChannel.Verbose:
            {
                cmdlet.WriteVerbose(this.message);
                return;
            }

            case CimWriteMessageChannel.Debug:
            {
                cmdlet.WriteDebug(this.message);
                return;
            }

            default:
            {
                return;
            }
            }
        }
Ejemplo n.º 2
0
		public override void Execute(CmdletOperationBase cmdlet)
		{
			ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");
			CimWriteMessageChannel cimWriteMessageChannel = (CimWriteMessageChannel)this.channel;
			switch (cimWriteMessageChannel)
			{
				case CimWriteMessageChannel.Warning:
				{
					cmdlet.WriteWarning(this.message);
					return;
				}
				case CimWriteMessageChannel.Verbose:
				{
					cmdlet.WriteVerbose(this.message);
					return;
				}
				case CimWriteMessageChannel.Debug:
				{
					cmdlet.WriteDebug(this.message);
					return;
				}
				default:
				{
					return;
				}
			}
		}
Ejemplo n.º 3
0
		public override void Execute(CmdletOperationBase cmdlet)
		{
			Exception cimException;
			try
			{
				try
				{
					if (this.error != null)
					{
						cimException = new CimException(this.error);
					}
					else
					{
						cimException = this.Exception;
					}
					Exception exception = cimException;
					cmdlet.WriteError(ErrorToErrorRecord.ErrorRecordFromAnyException(this.invocationContext, exception, this.cimResultContext));
					this.responseType = CimResponseType.Yes;
				}
				catch
				{
					this.responseType = CimResponseType.NoToAll;
					throw;
				}
			}
			finally
			{
				this.OnComplete();
			}
		}
Ejemplo n.º 4
0
 public void ProcessRemainActions(CmdletOperationBase cmdletOperation)
 {
     DebugHelper.WriteLogEx();
     while (true)
     {
         this.ProcessActions(cmdletOperation);
         if (this.IsActive())
         {
             try
             {
                 this.moreActionEvent.Wait();
                 this.moreActionEvent.Reset();
             }
             catch (ObjectDisposedException objectDisposedException1)
             {
                 ObjectDisposedException objectDisposedException = objectDisposedException1;
                 object[] objArray = new object[1];
                 objArray[0] = objectDisposedException;
                 DebugHelper.WriteLogEx("moreActionEvent was disposed: {0}.", 2, objArray);
                 break;
             }
         }
         else
         {
             DebugHelper.WriteLogEx("Either disposed or all operations completed.", 2);
             break;
         }
     }
     this.ProcessActions(cmdletOperation);
 }
Ejemplo n.º 5
0
        public override void Execute(CmdletOperationBase cmdlet)
        {
            Exception cimException;

            try
            {
                try
                {
                    if (this.error != null)
                    {
                        cimException = new CimException(this.error);
                    }
                    else
                    {
                        cimException = this.Exception;
                    }
                    Exception exception = cimException;
                    cmdlet.WriteError(ErrorToErrorRecord.ErrorRecordFromAnyException(this.invocationContext, exception, this.cimResultContext));
                    this.responseType = CimResponseType.Yes;
                }
                catch
                {
                    this.responseType = CimResponseType.NoToAll;
                    throw;
                }
            }
            finally
            {
                this.OnComplete();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// <para>
        /// process remaining actions until all operations are completed or
        /// current cmdlet is terminated by user
        /// </para>
        /// </summary>
        /// <param name="cmdletOperation">
        /// wrapper of cmdlet, <seealso cref="CmdletOperationBase"/> for details
        /// </param>
        public void ProcessRemainActions(CmdletOperationBase cmdletOperation)
        {
            DebugHelper.WriteLogEx();

            while (true)
            {
                ProcessActions(cmdletOperation);
                if (!this.IsActive())
                {
                    DebugHelper.WriteLogEx("Either disposed or all operations completed.", 2);
                    break;
                }

                try
                {
                    this.moreActionEvent.Wait();
                    this.moreActionEvent.Reset();
                }
                catch (ObjectDisposedException ex)
                {
                    // This might happen if this object is being disposed,
                    // while another thread is processing the remaining actions
                    DebugHelper.WriteLogEx("moreActionEvent was disposed: {0}.", 2, ex);
                    break;
                }
            }

            ProcessActions(cmdletOperation);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// <para>
 /// process all actions in the action queue
 /// </para>
 /// </summary>
 /// <param name="cmdletOperation">
 /// wrapper of cmdlet, <seealso cref="CmdletOperationBase"/> for details
 /// </param>
 public void ProcessActions(CmdletOperationBase cmdletOperation)
 {
     if (!this.actionQueue.IsEmpty)
     {
         CimBaseAction action;
         while (GetActionAndRemove(out action))
         {
             action.Execute(cmdletOperation);
             if (this.Disposed)
             {
                 break;
             }
         }
     }
 }
Ejemplo n.º 8
0
		public override void Execute(CmdletOperationBase cmdlet)
		{
			object[] objArray = new object[4];
			objArray[0] = this.activity;
			objArray[1] = this.activityID;
			objArray[2] = this.secondsRemaining;
			objArray[3] = this.percentageCompleted;
			DebugHelper.WriteLog("...Activity {0}: id={1}, remain seconds ={2}, percentage completed = {3}", 4, objArray);
			ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");
			ProgressRecord progressRecord = new ProgressRecord(this.activityID, this.activity, this.statusDescription);
			progressRecord.Activity = this.activity;
			progressRecord.ParentActivityId = 0;
			progressRecord.SecondsRemaining = this.secondsRemaining;
			progressRecord.PercentComplete = this.percentageCompleted;
			cmdlet.WriteProgress(progressRecord);
		}
Ejemplo n.º 9
0
		internal void RemoveCimInstance(CimInstance cimInstance, XOperationContextBase context, CmdletOperationBase cmdlet)
		{
			DebugHelper.WriteLogEx();
			string str = cimInstance.ToString();
			if (cmdlet.ShouldProcess(str, "Remove-CimInstance"))
			{
				CimRemoveCimInstanceContext cimRemoveCimInstanceContext = context as CimRemoveCimInstanceContext;
				CimSessionProxy cimSessionProxy = base.CreateCimSessionProxy(cimRemoveCimInstanceContext.Proxy);
				cimSessionProxy.DeleteInstanceAsync(cimRemoveCimInstanceContext.Namespace, cimInstance);
				return;
			}
			else
			{
				return;
			}
		}
Ejemplo n.º 10
0
        public void ProcessActions(CmdletOperationBase cmdletOperation)
        {
            CimBaseAction cimBaseAction = null;

            if (!this.actionQueue.IsEmpty)
            {
                while (this.GetActionAndRemove(out cimBaseAction))
                {
                    cimBaseAction.Execute(cmdletOperation);
                    if (!this.Disposed)
                    {
                        continue;
                    }
                    return;
                }
            }
        }
Ejemplo n.º 11
0
        public override void Execute(CmdletOperationBase cmdlet)
        {
            object[] objArray = new object[4];
            objArray[0] = this.activity;
            objArray[1] = this.activityID;
            objArray[2] = this.secondsRemaining;
            objArray[3] = this.percentageCompleted;
            DebugHelper.WriteLog("...Activity {0}: id={1}, remain seconds ={2}, percentage completed = {3}", 4, objArray);
            ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");
            ProgressRecord progressRecord = new ProgressRecord(this.activityID, this.activity, this.statusDescription);

            progressRecord.Activity         = this.activity;
            progressRecord.ParentActivityId = 0;
            progressRecord.SecondsRemaining = this.secondsRemaining;
            progressRecord.PercentComplete  = this.percentageCompleted;
            cmdlet.WriteProgress(progressRecord);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// <para>
        /// Write message to the target channel
        /// </para>
        /// </summary>
        /// <param name="cmdlet"></param>
        public override void Execute(CmdletOperationBase cmdlet)
        {
            ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");

            switch ((CimWriteMessageChannel)channel)
            {
                case CimWriteMessageChannel.Verbose:
                    cmdlet.WriteVerbose(message);
                    break;
                case CimWriteMessageChannel.Warning:
                    cmdlet.WriteWarning(message);
                    break;
                case CimWriteMessageChannel.Debug:
                    cmdlet.WriteDebug(message);
                    break;
                default:
                    break;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// <para>
        /// Write progress record to powershell
        /// </para>
        /// </summary>
        /// <param name="cmdlet"></param>
        public override void Execute(CmdletOperationBase cmdlet)
        {
            DebugHelper.WriteLog(
                "...Activity {0}: id={1}, remain seconds ={2}, percentage completed = {3}",
                4,
                this.activity,
                this.activityID,
                this.secondsRemaining,
                this.percentageCompleted);

            ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");
            ProgressRecord record = new ProgressRecord(
                this.activityID,
                this.activity,
                this.statusDescription);
            record.Activity = this.activity;
            record.ParentActivityId = 0;
            record.SecondsRemaining = (int)this.secondsRemaining;
            record.PercentComplete = (int)this.percentageCompleted;
            cmdlet.WriteProgress(record);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// <para>
        /// Write progress record to powershell
        /// </para>
        /// </summary>
        /// <param name="cmdlet"></param>
        public override void Execute(CmdletOperationBase cmdlet)
        {
            DebugHelper.WriteLog(
                "...Activity {0}: id={1}, remain seconds ={2}, percentage completed = {3}",
                4,
                this.activity,
                this.activityID,
                this.secondsRemaining,
                this.percentageCompleted);

            ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");
            ProgressRecord record = new ProgressRecord(
                this.activityID,
                this.activity,
                this.statusDescription);

            record.Activity         = this.activity;
            record.ParentActivityId = 0;
            record.SecondsRemaining = (int)this.secondsRemaining;
            record.PercentComplete  = (int)this.percentageCompleted;
            cmdlet.WriteProgress(record);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// <para>
        /// Write message to the target channel
        /// </para>
        /// </summary>
        /// <param name="cmdlet"></param>
        public override void Execute(CmdletOperationBase cmdlet)
        {
            ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");

            switch ((CimWriteMessageChannel)channel)
            {
            case CimWriteMessageChannel.Verbose:
                cmdlet.WriteVerbose(message);
                break;

            case CimWriteMessageChannel.Warning:
                cmdlet.WriteWarning(message);
                break;

            case CimWriteMessageChannel.Debug:
                cmdlet.WriteDebug(message);
                break;

            default:
                break;
            }
        }
Ejemplo n.º 16
0
		internal void AddSessionToCache(CimSession cimSession, XOperationContextBase context, CmdletOperationBase cmdlet)
		{
			string str;
			DebugHelper.WriteLogEx();
			CimNewSession.CimTestCimSessionContext cimTestCimSessionContext = context as CimNewSession.CimTestCimSessionContext;
			uint num = this.sessionState.GenerateSessionId();
			string name = cimTestCimSessionContext.CimSessionWrapper.Name;
			if (name != null)
			{
				str = name;
			}
			else
			{
				object[] cimSessionClassName = new object[2];
				cimSessionClassName[0] = CimSessionState.CimSessionClassName;
				cimSessionClassName[1] = num;
				str = string.Format(CultureInfo.CurrentUICulture, "{0}{1}", cimSessionClassName);
			}
			string str1 = str;
			CimSession cimSession1 = cimTestCimSessionContext.Proxy.Detach();
			PSObject cache = this.sessionState.AddObjectToCache(cimSession1, num, cimSession1.InstanceId, str1, cimTestCimSessionContext.CimSessionWrapper.ComputerName, cimTestCimSessionContext.Proxy.Protocol);
			cmdlet.WriteObject(cache, null);
		}
Ejemplo n.º 17
0
        /// <summary>
        /// <para>
        /// Write error to pipeline
        /// </para>
        /// </summary>
        /// <param name="cmdlet"></param>
        public override void Execute(CmdletOperationBase cmdlet)
        {
            Debug.Assert(cmdlet != null, "Caller should verify that cmdlet != null");
            try
            {
                Exception errorException = (error != null) ? new CimException(error) : this.Exception;

                // PS engine takes care of handling error action
                cmdlet.WriteError(ErrorToErrorRecord.ErrorRecordFromAnyException(this.invocationContext, errorException, this.cimResultContext));

                // if user wants to continue, we will get here
                this.responseType = CimResponseType.Yes;
            }
            catch
            {
                this.responseType = CimResponseType.NoToAll;
                throw;
            }
            finally
            {
                // unblocking the waiting thread
                this.OnComplete();
            }
        }
Ejemplo n.º 18
0
		public void ProcessRemainActions(CmdletOperationBase cmdletOperation)
		{
			DebugHelper.WriteLogEx();
			while (true)
			{
				this.ProcessActions(cmdletOperation);
				if (this.IsActive())
				{
					try
					{
						this.moreActionEvent.Wait();
						this.moreActionEvent.Reset();
					}
					catch (ObjectDisposedException objectDisposedException1)
					{
						ObjectDisposedException objectDisposedException = objectDisposedException1;
						object[] objArray = new object[1];
						objArray[0] = objectDisposedException;
						DebugHelper.WriteLogEx("moreActionEvent was disposed: {0}.", 2, objArray);
						break;
					}
				}
				else
				{
					DebugHelper.WriteLogEx("Either disposed or all operations completed.", 2);
					break;
				}
			}
			this.ProcessActions(cmdletOperation);
		}
Ejemplo n.º 19
0
        /// <summary>
        /// <para>
        /// Invoke cimmethod on given <see cref="CimInstance"/>
        /// </para>
        /// </summary>
        /// <param name="cimInstance"></param>
        public void InvokeCimMethodOnCimInstance(CimInstance cimInstance, XOperationContextBase context, CmdletOperationBase operation)
        {
            DebugHelper.WriteLogEx();
            CimInvokeCimMethodContext cimInvokeCimMethodContext = context as CimInvokeCimMethodContext;

            Debug.Assert(cimInvokeCimMethodContext != null, "CimInvokeCimMethod::InvokeCimMethodOnCimInstance should has CimInvokeCimMethodContext != NULL.");

            string action = string.Format(CultureInfo.CurrentUICulture, actionTemplate, cimInvokeCimMethodContext.MethodName);

            if (!operation.ShouldProcess(cimInstance.ToString(), action))
            {
                return;
            }

            CimSessionProxy proxy = CreateCimSessionProxy(cimInvokeCimMethodContext.Proxy);

            proxy.InvokeMethodAsync(
                cimInvokeCimMethodContext.Namespace,
                cimInstance,
                cimInvokeCimMethodContext.MethodName,
                cimInvokeCimMethodContext.ParametersCollection);
        }
Ejemplo n.º 20
0
		public override void Execute(CmdletOperationBase cmdlet)
		{
			bool flag;
			ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");
			bool flag1 = false;
			bool flag2 = false;
			CimPromptType cimPromptType = this.prompt;
			switch (cimPromptType)
			{
				case CimPromptType.None:
				{
					flag = cmdlet.ShouldProcess(this.message);
					if (!flag)
					{
						if (flag)
						{
							break;
						}
						this.responseType = CimResponseType.None;
						break;
					}
					else
					{
						this.responseType = CimResponseType.Yes;
						break;
					}
				}
				case CimPromptType.Critical:
				{
					flag = cmdlet.ShouldContinue(this.message, "caption", ref flag1, ref flag2);
					if (!flag1)
					{
						if (!flag2)
						{
							if (!flag)
							{
								if (flag)
								{
									break;
								}
								this.responseType = CimResponseType.None;
								break;
							}
							else
							{
								this.responseType = CimResponseType.Yes;
								break;
							}
						}
						else
						{
							this.responseType = CimResponseType.NoToAll;
							break;
						}
					}
					else
					{
						this.responseType = CimResponseType.YesToAll;
						break;
					}
				}
			}
			this.OnComplete();
		}
Ejemplo n.º 21
0
        /// <summary>
        /// <para>
        /// Remove <see cref="CimInstance"/> from namespace specified in cmdlet
        /// </para>
        /// </summary>
        /// <param name="cimInstance"></param>
        internal void RemoveCimInstance(CimInstance cimInstance, XOperationContextBase context, CmdletOperationBase cmdlet)
        {
            DebugHelper.WriteLogEx();

            string target = cimInstance.ToString();
            if (!cmdlet.ShouldProcess(target, action))
            {
                return;
            }

            CimRemoveCimInstanceContext removeContext = context as CimRemoveCimInstanceContext;
            Debug.Assert(removeContext != null, "CimRemoveCimInstance::RemoveCimInstance should has CimRemoveCimInstanceContext != NULL.");

            CimSessionProxy proxy = CreateCimSessionProxy(removeContext.Proxy);
            proxy.DeleteInstanceAsync(removeContext.Namespace, cimInstance);
        }
Ejemplo n.º 22
0
 /// <summary>
 /// <para>
 /// Execute the write operation to given cmdlet object
 /// </para>
 /// </summary>
 /// <param name="cmdlet">
 /// cmdlet wrapper object, to which write result.
 /// <see cref="CmdletOperationBase"/> for details.
 /// </param>
 public virtual void Execute(CmdletOperationBase cmdlet)
 {
 }
Ejemplo n.º 23
0
		public void InvokeCimMethodOnCimInstance(CimInstance cimInstance, XOperationContextBase context, CmdletOperationBase operation)
		{
			DebugHelper.WriteLogEx();
			CimInvokeCimMethod.CimInvokeCimMethodContext cimInvokeCimMethodContext = context as CimInvokeCimMethod.CimInvokeCimMethodContext;
			object[] methodName = new object[1];
			methodName[0] = cimInvokeCimMethodContext.MethodName;
			string str = string.Format(CultureInfo.CurrentUICulture, "Invoke-CimMethod: {0}", methodName);
			if (operation.ShouldProcess(cimInstance.ToString(), str))
			{
				CimSessionProxy cimSessionProxy = base.CreateCimSessionProxy(cimInvokeCimMethodContext.Proxy);
				cimSessionProxy.InvokeMethodAsync(cimInvokeCimMethodContext.Namespace, cimInstance, cimInvokeCimMethodContext.MethodName, cimInvokeCimMethodContext.ParametersCollection);
				return;
			}
			else
			{
				return;
			}
		}
Ejemplo n.º 24
0
        /// <summary>
        /// <para>
        /// process remaining actions until all operations are completed or
        /// current cmdlet is terminated by user
        /// </para>
        /// </summary>
        /// <param name="cmdletOperation">
        /// wrapper of cmdlet, <seealso cref="CmdletOperationBase"/> for details
        /// </param>
        public void ProcessRemainActions(CmdletOperationBase cmdletOperation)
        {
            DebugHelper.WriteLogEx();

            while (true)
            {
                ProcessActions(cmdletOperation);
                if (!this.IsActive())
                {
                    DebugHelper.WriteLogEx("Either disposed or all operations completed.", 2);
                    break;
                }
                try
                {
                    this.moreActionEvent.Wait();
                    this.moreActionEvent.Reset();
                }
                catch (ObjectDisposedException ex)
                {
                    // This might happen if this object is being disposed,
                    // while another thread is processing the remaining actions
                    DebugHelper.WriteLogEx("moreActionEvent was disposed: {0}.", 2, ex);
                    break;
                }
            }
            ProcessActions(cmdletOperation);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// <para>
        /// Write error to pipeline
        /// </para>
        /// </summary>
        /// <param name="cmdlet"></param>
        public override void Execute(CmdletOperationBase cmdlet)
        {
            Debug.Assert(cmdlet != null, "Caller should verify that cmdlet != null");
            try
            {
                Exception errorException = (error != null) ? new CimException(error) : this.Exception;

                // PS engine takes care of handling error action
                cmdlet.WriteError(ErrorToErrorRecord.ErrorRecordFromAnyException(this.invocationContext, errorException, this.cimResultContext));

                // if user wants to continue, we will get here
                this.responseType = CimResponseType.Yes;
            }
            catch
            {
                this.responseType = CimResponseType.NoToAll;
                throw;
            }
            finally
            {
                // unblocking the waiting thread
                this.OnComplete();
            }
        }
Ejemplo n.º 26
0
 public override void Execute(CmdletOperationBase cmdlet)
 {
     ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");
     cmdlet.WriteObject(this.result, base.Context);
 }
Ejemplo n.º 27
0
        public void InvokeCimMethodOnCimInstance(CimInstance cimInstance, XOperationContextBase context, CmdletOperationBase operation)
        {
            DebugHelper.WriteLogEx();
            CimInvokeCimMethod.CimInvokeCimMethodContext cimInvokeCimMethodContext = context as CimInvokeCimMethod.CimInvokeCimMethodContext;
            object[] methodName = new object[1];
            methodName[0] = cimInvokeCimMethodContext.MethodName;
            string str = string.Format(CultureInfo.CurrentUICulture, "Invoke-CimMethod: {0}", methodName);

            if (operation.ShouldProcess(cimInstance.ToString(), str))
            {
                CimSessionProxy cimSessionProxy = base.CreateCimSessionProxy(cimInvokeCimMethodContext.Proxy);
                cimSessionProxy.InvokeMethodAsync(cimInvokeCimMethodContext.Namespace, cimInstance, cimInvokeCimMethodContext.MethodName, cimInvokeCimMethodContext.ParametersCollection);
                return;
            }
            else
            {
                return;
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// <para>
        /// Add session to global cache,
        /// </para>
        /// </summary>
        /// <param name="cimSession"></param>
        /// <param name="context"></param>
        /// <param name="cmdlet"></param>
        internal void AddSessionToCache(CimSession cimSession, XOperationContextBase context, CmdletOperationBase cmdlet)
        {
            DebugHelper.WriteLogEx();

            CimTestCimSessionContext testCimSessionContext = context as CimTestCimSessionContext;
            uint   sessionId           = this.sessionState.GenerateSessionId();
            string originalSessionName = testCimSessionContext.CimSessionWrapper.Name;
            string sessionName         = (originalSessionName != null) ? originalSessionName : string.Format(CultureInfo.CurrentUICulture, @"{0}{1}", CimSessionState.CimSessionClassName, sessionId);

            // detach CimSession from the proxy object
            CimSession createdCimSession = testCimSessionContext.Proxy.Detach();
            PSObject   psObject          = this.sessionState.AddObjectToCache(
                createdCimSession,
                sessionId,
                createdCimSession.InstanceId,
                sessionName,
                testCimSessionContext.CimSessionWrapper.ComputerName,
                testCimSessionContext.Proxy.Protocol);

            cmdlet.WriteObject(psObject, null);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// <para>
        /// Prompt user with the given message and prepared whatif message.
        /// </para>
        /// </summary>
        /// <param name="cmdlet">
        /// cmdlet wrapper object, to which write result.
        /// <see cref="CmdletOperationBase"/> for details.
        /// </param>
        public override void Execute(CmdletOperationBase cmdlet)
        {
            ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");

            bool yestoall = false;
            bool notoall = false;
            bool result = false;

            switch (this.prompt)
            {
                case CimPromptType.Critical:
                    // NOTES: prepare the whatif message and caption
                    try
                    {
                        result = cmdlet.ShouldContinue(message, "caption", ref yestoall, ref notoall);
                        if (yestoall)
                        {
                            this.responseType = CimResponseType.YesToAll;
                        }
                        else if (notoall)
                        {
                            this.responseType = CimResponseType.NoToAll;
                        }
                        else if (result)
                        {
                            this.responseType = CimResponseType.Yes;
                        }
                        else if (!result)
                        {
                            this.responseType = CimResponseType.No;
                        }
                    }
                    catch
                    {
                        this.responseType = CimResponseType.NoToAll;
                        throw;                        
                    }
                    finally
                    {
                        // unblocking the waiting thread
                        this.OnComplete();
                    }                    
                    break;
                case CimPromptType.Normal:
                    try
                    {
                        result = cmdlet.ShouldProcess(message);
                        if (result)
                        {
                            this.responseType = CimResponseType.Yes;
                        }
                        else if (!result)
                        {
                            this.responseType = CimResponseType.No;
                        }
                    }
                    catch
                    {
                        this.responseType = CimResponseType.NoToAll;
                        throw;                        
                    }
                    finally
                    {
                        // unblocking the waiting thread
                        this.OnComplete();
                    }                     
                    break;
                default:
                    break;
            }
            this.OnComplete();
        }  
Ejemplo n.º 30
0
        internal void RemoveCimInstance(CimInstance cimInstance, XOperationContextBase context, CmdletOperationBase cmdlet)
        {
            DebugHelper.WriteLogEx();
            string str = cimInstance.ToString();

            if (cmdlet.ShouldProcess(str, "Remove-CimInstance"))
            {
                CimRemoveCimInstanceContext cimRemoveCimInstanceContext = context as CimRemoveCimInstanceContext;
                CimSessionProxy             cimSessionProxy             = base.CreateCimSessionProxy(cimRemoveCimInstanceContext.Proxy);
                cimSessionProxy.DeleteInstanceAsync(cimRemoveCimInstanceContext.Namespace, cimInstance);
                return;
            }
            else
            {
                return;
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// <para>
        /// Set <see cref="CimInstance"/> with properties specified in cmdlet
        /// </para>
        /// </summary>
        /// <param name="cimInstance"></param>
        public void SetCimInstance(CimInstance cimInstance, CimSetCimInstanceContext context, CmdletOperationBase cmdlet)
        {
            DebugHelper.WriteLog("CimSetCimInstance::SetCimInstance", 4);

            if (!cmdlet.ShouldProcess(cimInstance.ToString(), action))
            {
                return;
            }

            Exception exception = null;
            if (!SetProperty(context.Property, ref cimInstance, ref exception))
            {
                cmdlet.ThrowTerminatingError(exception, action);
                return;
            }
            CimSessionProxy proxy = CreateCimSessionProxy(context.Proxy, context.PassThru);
            proxy.ModifyInstanceAsync(cimInstance.CimSystemProperties.Namespace, cimInstance);
        }
Ejemplo n.º 32
0
 /// <summary>
 /// <para>
 /// process all actions in the action queue
 /// </para>
 /// </summary>
 /// <param name="cmdletOperation">
 /// wrapper of cmdlet, <seealso cref="CmdletOperationBase"/> for details
 /// </param>
 public void ProcessActions(CmdletOperationBase cmdletOperation)
 {
     if (!this.actionQueue.IsEmpty)
     {
         CimBaseAction action;
         while (GetActionAndRemove(out action))
         {
             action.Execute(cmdletOperation);
             if (this.Disposed)
             {
                 break;
             }
         }
     }
 }
Ejemplo n.º 33
0
        internal void AddSessionToCache(CimSession cimSession, XOperationContextBase context, CmdletOperationBase cmdlet)
        {
            string str;

            DebugHelper.WriteLogEx();
            CimNewSession.CimTestCimSessionContext cimTestCimSessionContext = context as CimNewSession.CimTestCimSessionContext;
            uint   num  = this.sessionState.GenerateSessionId();
            string name = cimTestCimSessionContext.CimSessionWrapper.Name;

            if (name != null)
            {
                str = name;
            }
            else
            {
                object[] cimSessionClassName = new object[2];
                cimSessionClassName[0] = CimSessionState.CimSessionClassName;
                cimSessionClassName[1] = num;
                str = string.Format(CultureInfo.CurrentUICulture, "{0}{1}", cimSessionClassName);
            }
            string     str1        = str;
            CimSession cimSession1 = cimTestCimSessionContext.Proxy.Detach();
            PSObject   cache       = this.sessionState.AddObjectToCache(cimSession1, num, cimSession1.InstanceId, str1, cimTestCimSessionContext.CimSessionWrapper.ComputerName, cimTestCimSessionContext.Proxy.Protocol);

            cmdlet.WriteObject(cache, null);
        }
        /// <summary>
        /// <para>
        /// Remove <see cref="CimInstance"/> from namespace specified in cmdlet
        /// </para>
        /// </summary>
        /// <param name="cimInstance"></param>
        internal void RemoveCimInstance(CimInstance cimInstance, XOperationContextBase context, CmdletOperationBase cmdlet)
        {
            DebugHelper.WriteLogEx();

            string target = cimInstance.ToString();

            if (!cmdlet.ShouldProcess(target, action))
            {
                return;
            }

            CimRemoveCimInstanceContext removeContext = context as CimRemoveCimInstanceContext;

            Debug.Assert(removeContext != null, "CimRemoveCimInstance::RemoveCimInstance should has CimRemoveCimInstanceContext != NULL.");

            CimSessionProxy proxy = CreateCimSessionProxy(removeContext.Proxy);

            proxy.DeleteInstanceAsync(removeContext.Namespace, cimInstance);
        }
Ejemplo n.º 35
0
        /// <summary>
        /// <para>
        /// Set <see cref="CimInstance"/> with properties specified in cmdlet
        /// </para>
        /// </summary>
        /// <param name="cimInstance"></param>
        public void SetCimInstance(CimInstance cimInstance, CimSetCimInstanceContext context, CmdletOperationBase cmdlet)
        {
            DebugHelper.WriteLog("CimSetCimInstance::SetCimInstance", 4);

            if (!cmdlet.ShouldProcess(cimInstance.ToString(), action))
            {
                return;
            }

            Exception exception = null;

            if (!SetProperty(context.Property, ref cimInstance, ref exception))
            {
                cmdlet.ThrowTerminatingError(exception, action);
                return;
            }
            CimSessionProxy proxy = CreateCimSessionProxy(context.Proxy, context.PassThru);

            proxy.ModifyInstanceAsync(cimInstance.CimSystemProperties.Namespace, cimInstance);
        }
Ejemplo n.º 36
0
        /// <summary>
        /// <para>
        /// Add session to global cache
        /// </para>
        /// </summary>
        /// <param name="cimSession"></param>
        /// <param name="context"></param>
        /// <param name="cmdlet"></param>
        internal void AddSessionToCache(CimSession cimSession, XOperationContextBase context, CmdletOperationBase cmdlet)
        {
            DebugHelper.WriteLogEx();

            CimTestCimSessionContext testCimSessionContext = context as CimTestCimSessionContext;
            UInt32 sessionId = this.sessionState.GenerateSessionId();
            string originalSessionName = testCimSessionContext.CimSessionWrapper.Name;
            string sessionName = (originalSessionName != null) ? originalSessionName : String.Format(CultureInfo.CurrentUICulture, @"{0}{1}", CimSessionState.CimSessionClassName, sessionId);

            // detach CimSession from the proxy object
            CimSession createdCimSession = testCimSessionContext.Proxy.Detach();
            PSObject psObject = this.sessionState.AddObjectToCache(
                createdCimSession,
                sessionId,
                createdCimSession.InstanceId,
                sessionName,
                testCimSessionContext.CimSessionWrapper.ComputerName,
                testCimSessionContext.Proxy.Protocol);
            cmdlet.WriteObject(psObject, null);
        }
Ejemplo n.º 37
0
        /// <summary>
        /// <para>
        /// Prompt user with the given message and prepared whatif message.
        /// </para>
        /// </summary>
        /// <param name="cmdlet">
        /// cmdlet wrapper object, to which write result.
        /// <see cref="CmdletOperationBase"/> for details.
        /// </param>
        public override void Execute(CmdletOperationBase cmdlet)
        {
            ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");

            bool yestoall = false;
            bool notoall  = false;
            bool result   = false;

            switch (this.prompt)
            {
            case CimPromptType.Critical:
                // NOTES: prepare the whatif message and caption
                try
                {
                    result = cmdlet.ShouldContinue(Message, "caption", ref yestoall, ref notoall);
                    if (yestoall)
                    {
                        this.responseType = CimResponseType.YesToAll;
                    }
                    else if (notoall)
                    {
                        this.responseType = CimResponseType.NoToAll;
                    }
                    else if (result)
                    {
                        this.responseType = CimResponseType.Yes;
                    }
                    else if (!result)
                    {
                        this.responseType = CimResponseType.No;
                    }
                }
                catch
                {
                    this.responseType = CimResponseType.NoToAll;
                    throw;
                }
                finally
                {
                    // unblocking the waiting thread
                    this.OnComplete();
                }

                break;

            case CimPromptType.Normal:
                try
                {
                    result = cmdlet.ShouldProcess(Message);
                    if (result)
                    {
                        this.responseType = CimResponseType.Yes;
                    }
                    else if (!result)
                    {
                        this.responseType = CimResponseType.No;
                    }
                }
                catch
                {
                    this.responseType = CimResponseType.NoToAll;
                    throw;
                }
                finally
                {
                    // unblocking the waiting thread
                    this.OnComplete();
                }

                break;

            default:
                break;
            }

            this.OnComplete();
        }
Ejemplo n.º 38
0
 /// <summary>
 /// <para>
 /// process all actions in the action queue
 /// </para>
 /// </summary>
 /// <param name="cmdletOperation">
 /// wrapper of cmdlet, <seealso cref="CmdletOperationBase"/> for details
 /// </param>
 public void ProcessActions(CmdletOperationBase cmdletOperation)
 {
     this.cimTestSession.ProcessActions(cmdletOperation);
 }
Ejemplo n.º 39
0
        public override void Execute(CmdletOperationBase cmdlet)
        {
            bool flag;

            ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");
            bool          flag1         = false;
            bool          flag2         = false;
            CimPromptType cimPromptType = this.prompt;

            switch (cimPromptType)
            {
            case CimPromptType.None:
            {
                flag = cmdlet.ShouldProcess(this.message);
                if (!flag)
                {
                    if (flag)
                    {
                        break;
                    }
                    this.responseType = CimResponseType.None;
                    break;
                }
                else
                {
                    this.responseType = CimResponseType.Yes;
                    break;
                }
            }

            case CimPromptType.Critical:
            {
                flag = cmdlet.ShouldContinue(this.message, "caption", ref flag1, ref flag2);
                if (!flag1)
                {
                    if (!flag2)
                    {
                        if (!flag)
                        {
                            if (flag)
                            {
                                break;
                            }
                            this.responseType = CimResponseType.None;
                            break;
                        }
                        else
                        {
                            this.responseType = CimResponseType.Yes;
                            break;
                        }
                    }
                    else
                    {
                        this.responseType = CimResponseType.NoToAll;
                        break;
                    }
                }
                else
                {
                    this.responseType = CimResponseType.YesToAll;
                    break;
                }
            }
            }
            this.OnComplete();
        }
Ejemplo n.º 40
0
		public void ProcessActions(CmdletOperationBase cmdletOperation)
		{
			CimBaseAction cimBaseAction = null;
			if (!this.actionQueue.IsEmpty)
			{
				while (this.GetActionAndRemove(out cimBaseAction))
				{
					cimBaseAction.Execute(cmdletOperation);
					if (!this.Disposed)
					{
						continue;
					}
					return;
				}
			}
		}
Ejemplo n.º 41
0
		public virtual void Execute(CmdletOperationBase cmdlet)
		{
		}
Ejemplo n.º 42
0
		public override void Execute(CmdletOperationBase cmdlet)
		{
			ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet");
			cmdlet.WriteObject(this.result, base.Context);
		}
Ejemplo n.º 43
0
 /// <summary>
 /// <para>
 /// Process remaining actions until all operations are completed or
 /// current cmdlet is terminated by user.
 /// </para>
 /// </summary>
 /// <param name="cmdletOperation">
 /// Wrapper of cmdlet, <seealso cref="CmdletOperationBase"/> for details.
 /// </param>
 public void ProcessRemainActions(CmdletOperationBase cmdletOperation)
 {
     this.cimTestSession.ProcessRemainActions(cmdletOperation);
 }
Ejemplo n.º 44
0
        /// <summary>
        /// <para>
        /// Invoke cimmethod on given <see cref="CimInstance"/>
        /// </para>
        /// </summary>
        /// <param name="cimInstance"></param>
        public void InvokeCimMethodOnCimInstance(CimInstance cimInstance, XOperationContextBase context, CmdletOperationBase operation)
        {
            DebugHelper.WriteLogEx();
            CimInvokeCimMethodContext cimInvokeCimMethodContext = context as CimInvokeCimMethodContext;
            Debug.Assert(cimInvokeCimMethodContext != null, "CimInvokeCimMethod::InvokeCimMethodOnCimInstance should has CimInvokeCimMethodContext != NULL.");

            string action = string.Format(CultureInfo.CurrentUICulture, actionTemplate, cimInvokeCimMethodContext.MethodName);
            if (!operation.ShouldProcess(cimInstance.ToString(), action))
            {
                return;
            }

            CimSessionProxy proxy = CreateCimSessionProxy(cimInvokeCimMethodContext.Proxy);
            proxy.InvokeMethodAsync(
                cimInvokeCimMethodContext.Namespace,
                cimInstance,
                cimInvokeCimMethodContext.MethodName,
                cimInvokeCimMethodContext.ParametersCollection);
        }