/// <summary> /// Invokes the callback scriptblock as configured. /// </summary> /// <param name="Caller">The object containing the information pertaining to the calling command.</param> /// <param name="Invoker">The meta object representing the invoking command.</param> /// <param name="Data">Extra data that was passed to the event</param> public void Invoke(CallerInfo Caller, PSCmdlet Invoker, object Data) { Hashtable table = new Hashtable(StringComparer.InvariantCultureIgnoreCase); table["Command"] = Invoker.MyInvocation.MyCommand.Name; table["ModuleName"] = Invoker.MyInvocation.MyCommand.ModuleName; table["CallerFunction"] = Caller.CallerFunction; table["CallerModule"] = Caller.CallerModule; table["Data"] = Data; try { if (BreakAffinity) { lock (_InvokeLock) { UtilityHost.ImportScriptBlock(ScriptBlock); ScriptBlock.Invoke(table); } } else { ScriptBlock.Invoke(table); } } catch (Exception e) { throw new CallbackException(this, e); } }
/// <summary> /// This will import the events into the current execution context, breaking runspace affinity /// </summary> public void LocalizeEvents() { UtilityHost.ImportScriptBlock(BeginEvent, true); UtilityHost.ImportScriptBlock(StartEvent, true); UtilityHost.ImportScriptBlock(MessageEvent, true); UtilityHost.ImportScriptBlock(ErrorEvent, true); UtilityHost.ImportScriptBlock(EndEvent, true); UtilityHost.ImportScriptBlock(FinalEvent, true); }
/// <summary> /// Resets the current scriptblock's sessionstate to either the current runspace's current sessionstate or its global sessionstate. /// </summary> /// <param name="ScriptBlock">The scriptblock to import</param> /// <param name="Global">Whether to import into the global sessionstate</param> /// <returns>The imported ScriptBlock</returns> public static ScriptBlock Import(this ScriptBlock ScriptBlock, bool Global = false) { UtilityHost.ImportScriptBlock(ScriptBlock, Global); return(ScriptBlock); }
/// <summary> /// Resets the current scriptblock's sessionstate to the current runspace's current sessionstate. /// </summary> /// <param name="ScriptBlock">The scriptblock to import</param> /// <returns>The imported scriptblock</returns> public static ScriptBlock ToLocal(this ScriptBlock ScriptBlock) { UtilityHost.ImportScriptBlock(ScriptBlock); return(ScriptBlock); }
/// <summary> /// Resets the current scriptblock's sessionstate to the current runspace's global sessionstate. /// </summary> /// <param name="ScriptBlock">The scriptblock to globalize</param> /// <returns>The globalized scriptblock</returns> public static ScriptBlock ToGlobal(this ScriptBlock ScriptBlock) { UtilityHost.ImportScriptBlock(ScriptBlock, true); return(ScriptBlock); }