// 20120816 public void runScriptBlocks( System.Collections.Generic.List<ScriptBlock> scriptblocks, PSCmdletBase cmdlet, // 20130318 //bool eventHandlers) bool eventHandlers, object[] parameters) { try { if (scriptblocks != null && scriptblocks.Count > 0) { foreach (ScriptBlock sb in scriptblocks) { if (sb != null) { try { if (eventHandlers) { cmdlet.WriteVerbose(cmdlet, "run event handler"); runScriptBlock runner = new runScriptBlock(runSBEvent); runner(sb, cmdlet.EventSource, cmdlet.EventArgs); } else { cmdlet.WriteVerbose(cmdlet, "run action with parameters"); // 20130318 //runScriptBlock runner = new runScriptBlock(runSBAction); //runner(sb, cmdlet.EventSource, cmdlet.EventArgs); runScriptBlockWithParameters runnerWithParams = new runScriptBlockWithParameters(runSBActionWithParams); runnerWithParams(sb, parameters); } } catch (Exception eInner) { // 20130318 // ErrorRecord err = // new ErrorRecord( // eInner, // "InvokeException", // ErrorCategory.OperationStopped, // sb); // err.ErrorDetails = // new ErrorDetails("Error in " + // sb.ToString()); // WriteError(this, err, false); // this.WriteError( // this, // "Error in " + // sb.ToString() + // ". " + // eInner.Message, // "InvokeException", // ErrorCategory.OperationStopped, // // 20130318 // //false); // true); throw; } } } } } catch (Exception eOuter) { // 20130318 // WriteError(this, // new ErrorRecord(eOuter, "runScriptBlocks", ErrorCategory.InvalidArgument, null), // true); // this.WriteError( // this, // eOuter.Message, // "runScriptBlocks", // ErrorCategory.InvalidArgument, // true); throw; } }
// 20120816 public void runScriptBlocks( System.Collections.Generic.List<ScriptBlock> scriptblocks, PSCmdletBase cmdlet, // 20130318 //bool eventHandlers) bool eventHandlers, object[] parameters) { try { if (scriptblocks != null && scriptblocks.Count > 0) { cmdlet.WriteVerbose(cmdlet, "there are " + scriptblocks.Count.ToString() + " scriptblock(s) to run"); foreach (ScriptBlock sb in scriptblocks) { if (sb != null) { try { if (eventHandlers) { cmdlet.WriteVerbose(cmdlet, "run event handler"); runScriptBlock runner = new runScriptBlock(runSBEvent); runner(sb, cmdlet.EventSource, cmdlet.EventArgs); } else { cmdlet.WriteVerbose(cmdlet, "run action with parameters"); // 20130318 //runScriptBlock runner = new runScriptBlock(runSBAction); //runner(sb, cmdlet.EventSource, cmdlet.EventArgs); runScriptBlockWithParameters runnerWithParams = new runScriptBlockWithParameters(runSBActionWithParams); cmdlet.WriteVerbose(cmdlet, "the scriptblock runner has been created"); // 20130606 try { cmdlet.WriteVerbose(cmdlet, "listing parameters"); if (null == parameters || 0 == parameters.Length) { cmdlet.WriteVerbose(cmdlet, "there are no parameters"); } else { foreach (var singleParam in parameters) { cmdlet.WriteVerbose(cmdlet, singleParam); } } } catch (Exception eListParameters) { cmdlet.WriteVerbose(cmdlet, eListParameters.Message); } runnerWithParams(sb, parameters); cmdlet.WriteVerbose(cmdlet, "the scriptblock runner has finished"); } } catch (Exception eInner) { // 20130318 // ErrorRecord err = // new ErrorRecord( // eInner, // "InvokeException", // ErrorCategory.OperationStopped, // sb); // err.ErrorDetails = // new ErrorDetails("Error in " + // sb.ToString()); // WriteError(this, err, false); // this.WriteError( // this, // "Error in " + // sb.ToString() + // ". " + // eInner.Message, // "InvokeException", // ErrorCategory.OperationStopped, // // 20130318 // //false); // true); // 20130606 cmdlet.WriteVerbose(cmdlet, eInner.Message); //throw; throw new Exception("Failed to run scriptblock"); } } } } } catch (Exception eOuter) { // 20130318 // WriteError(this, // new ErrorRecord(eOuter, "runScriptBlocks", ErrorCategory.InvalidArgument, null), // true); // this.WriteError( // this, // eOuter.Message, // "runScriptBlocks", // ErrorCategory.InvalidArgument, // true); // 20130606 cmdlet.WriteVerbose(cmdlet, eOuter.Message); //throw; throw new Exception("Failed to run scriptblocks"); } }
public void runScriptBlocks( List <ScriptBlock> scriptblocks, PSCmdletBase cmdlet, bool eventHandlers, object[] parameters) { try { if (scriptblocks != null && scriptblocks.Count > 0) { // cmdlet.WriteVerbose(cmdlet, "there are " + scriptblocks.Count + " scriptblock(s) to run"); foreach (var sb in scriptblocks) { if (sb != null) { try { if (eventHandlers) { // cmdlet.WriteVerbose(cmdlet, "run event handler"); var runner = new runScriptBlock(runSBEvent); runner(sb, cmdlet.EventSource, cmdlet.EventArgs); } else { // cmdlet.WriteVerbose(cmdlet, "run action with parameters"); //runScriptBlock runner = new runScriptBlock(runSBAction); //runner(sb, cmdlet.EventSource, cmdlet.EventArgs); var runnerWithParams = new runScriptBlockWithParameters(runSBActionWithParams); // cmdlet.WriteVerbose(cmdlet, "the scriptblock runner has been created"); // 20130606 try { cmdlet.WriteVerbose(cmdlet, "listing parameters"); if (null == parameters || 0 == parameters.Length) { cmdlet.WriteVerbose(cmdlet, "there are no parameters"); } else { foreach (var singleParam in parameters) { cmdlet.WriteVerbose(cmdlet, singleParam); } } } catch (Exception eListParameters) { cmdlet.WriteVerbose(cmdlet, eListParameters.Message); } runnerWithParams(sb, parameters); // cmdlet.WriteVerbose(cmdlet, "the scriptblock runner has finished"); } } catch (Exception) { // 20130318 // ErrorRecord err = // new ErrorRecord( // eInner, // "InvokeException", // ErrorCategory.OperationStopped, // sb); // err.ErrorDetails = // new ErrorDetails("Error in " + // sb.ToString()); // WriteError(this, err, false); // this.WriteError( // this, // "Error in " + // sb.ToString() + // ". " + // eInner.Message, // "InvokeException", // ErrorCategory.OperationStopped, // // 20130318 // //false); // true); // cmdlet.WriteVerbose(cmdlet, eInner.Message); throw new Exception("Failed to run scriptblock"); } } } } } catch (Exception) { // WriteError(this, // new ErrorRecord(eOuter, "runScriptBlocks", ErrorCategory.InvalidArgument, null), // true); // this.WriteError( // this, // eOuter.Message, // "runScriptBlocks", // ErrorCategory.InvalidArgument, // true); // cmdlet.WriteVerbose(cmdlet, eOuter.Message); throw new Exception("Failed to run scriptblocks"); } }