示例#1
0
 public IEnumerable <PSObject> Invoke()
 {
     if (!this.asyncInvoke)
     {
         Collection <PSObject> result = null;
         using (RunspaceProxy runspaceProxy = new RunspaceProxy(this.runspaceMediator, true))
         {
             IPowerShellProxy powerShellProxy = ProxyPSCommand.PowerShellProxyFactory(runspaceProxy, this.cmd);
             result = powerShellProxy.Invoke <PSObject>();
             if (powerShellProxy.Errors != null && powerShellProxy.Errors.Count != 0 && powerShellProxy.Errors[0].Exception != null)
             {
                 throw powerShellProxy.Errors[0].Exception;
             }
             if (powerShellProxy.Warnings != null && powerShellProxy.Warnings.Count != 0)
             {
                 foreach (WarningRecord warningRecord in powerShellProxy.Warnings)
                 {
                     this.writeWarning(new LocalizedString(warningRecord.Message));
                 }
             }
         }
         return(result);
     }
     return(new CmdletProxyDataReader(this.runspaceMediator, this.cmd, this.writeWarning));
 }
示例#2
0
        internal static IEnumerable <PSObject> RPSProxyExecution(Guid cmdletUniqueId, PSCommand command, string serverFqn, ExchangeRunspaceConfiguration runspaceConfig, int serverVersion, bool asyncProxying, Task.TaskWarningLoggingDelegate writeWarning)
        {
            Uri uri = ProxyHelper.BuildCmdletProxyUri(serverFqn, runspaceConfig, serverVersion);
            IEnumerable <PSObject> result;

            try
            {
                RemoteConnectionInfo connectionInfo = ProxyHelper.BuildProxyWSManConnectionInfo(uri);
                ProxyPSCommand       proxyPSCommand = new ProxyPSCommand(connectionInfo, command, asyncProxying, writeWarning);
                result = proxyPSCommand.Invoke();
            }
            catch (Exception)
            {
                CmdletLogger.SafeAppendGenericInfo(cmdletUniqueId, "TargetUri", uri.ToString());
                throw;
            }
            return(result);
        }