public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { Wait(); try { // command _currentCommand = new DynamicPowershellCommand(CreatePipeline()) { Command = new Command(GetPropertyValue(LookupCommand(binder.Name), "Name")) }; // parameters var unnamedCount = args.Length - binder.CallInfo.ArgumentNames.Count(); var namedArguments = binder.CallInfo.ArgumentNames.Select((each, index) => new KeyValuePair <string, object>(each, args[index + unnamedCount])); _currentCommand.SetParameters(args.Take(unnamedCount), namedArguments); // invoke AsynchronouslyEnumerableList <ErrorRecord> errors; result = _currentCommand.InvokeAsyncIfPossible(out errors); return(true); } catch (Exception e) { Console.WriteLine(e.Message); result = null; return(false); } }
public void Wait() { lock (this) { if (_currentCommand != null) { _currentCommand.Wait(); _currentCommand = null; } } }
public DynamicPowershellResult Invoke(string functionName, IEnumerable <PersistablePropertyInformation> elements, object objectContainingParameters, IDictionary <string, object> defaults, IDictionary <string, object> forced, out AsynchronouslyEnumerableList <ErrorRecord> errors) { Wait(); // command _currentCommand = new DynamicPowershellCommand(CreatePipeline()) { Command = new Command(GetPropertyValue(LookupCommand(functionName), "Name")) }; // parameters _currentCommand.SetParameters(elements, objectContainingParameters, defaults, forced); // invoke return(_currentCommand.InvokeAsyncIfPossible(out errors)); }