/// <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); }
/// <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); }
/// <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); }
/// <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(); }