예제 #1
0
        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);
            }
        }
예제 #2
0
 public void Wait()
 {
     lock (this) {
         if (_currentCommand != null)
         {
             _currentCommand.Wait();
             _currentCommand = null;
         }
     }
 }
예제 #3
0
        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));
        }