// Token: 0x060010AA RID: 4266 RVA: 0x00032EEC File Offset: 0x000310EC internal RunspaceMediator GetRunspacePooledMediatorInstance(MonadMediatorPoolKey key) { if (key == null) { throw new ArgumentNullException("key"); } if (this.connectionPooledInstace != null) { RunspaceMediator runspaceMediator = null; MonadRunspaceCache result = null; for (int i = 0; i < this.runspaceMediatorSize; i++) { if (key.Equals(this.currentKey[i]) && !this.connectionPooledInstanceCache[i].IsDisposed) { runspaceMediator = this.connectionPooledInstace[i]; result = this.connectionPooledInstanceCache[i]; break; } } if (runspaceMediator != null) { this.CleanUpCache(this.connectionPooledInstanceCache, this.inactivityCacheCleanupThreshold, result); return(runspaceMediator); } } else { lock (this.syncInstance) { if (this.connectionPooledInstace == null) { this.connectionPooledInstace = new RunspaceMediator[this.runspaceMediatorSize]; this.connectionPooledInstanceCache = new MonadRunspaceCache[this.runspaceMediatorSize]; this.currentKey = new MonadMediatorPoolKey[this.runspaceMediatorSize]; } } } RunspaceMediator result2; lock (this.syncInstance) { this.CleanUpCache(this.connectionPooledInstanceCache, this.inactivityCacheCleanupThreshold, null); int num = this.ResolveNextCacheToReplace(); if (this.connectionPooledInstanceCache[num] != null && !this.connectionPooledInstanceCache[num].IsDisposed) { this.connectionPooledInstanceCache[num].Dispose(); } this.connectionPooledInstanceCache[num] = new MonadRunspaceCache(); this.connectionPooledInstace[num] = new RunspaceMediator(new MonadRemoteRunspaceFactory(key.ConnectionInfo, key.ServerSettings), this.connectionPooledInstanceCache[num]); this.currentKey[num] = key; this.lastUpdatedKey = num; result2 = this.connectionPooledInstace[num]; } return(result2); }
// Token: 0x0600100D RID: 4109 RVA: 0x00030D28 File Offset: 0x0002EF28 internal MonadConnection(CommandInteractionHandler uiHandler, RunspaceMediator mediator, RunspaceServerSettingsPresentationObject serverSettings) { this.SyncRoot = new object(); base..ctor(); ExTraceGlobals.IntegrationTracer.Information((long)this.GetHashCode(), "new MonadConnection(RunspaceMediator)"); if (uiHandler == null) { throw new ArgumentNullException("uiHandler"); } if (mediator == null) { throw new ArgumentNullException("mediator"); } this.pooled = true; this.timeout = 0; this.InteractionHandler = uiHandler; this.mediator = mediator; this.state = ConnectionState.Closed; this.serverSettings = serverSettings; }
public CmdletProxyDataReader(RunspaceMediator runspaceMediator, PSCommand cmd, Task.TaskWarningLoggingDelegate writeWarning) { this.runspaceProxy = new RunspaceProxy(runspaceMediator, true); bool flag = false; try { this.shellProxy = new PowerShellProxy(this.runspaceProxy, cmd); this.writeWarning = writeWarning; this.asyncResult = (PowerShellAsyncResult <PSObject>) this.shellProxy.BeginInvoke(null, null); PSDataCollection <PSObject> output = this.asyncResult.Output; this.shellProxy.PowerShell.InvocationStateChanged += this.PipelineStateChanged; output.DataAdded += this.PipelineDataAdded; flag = true; } finally { if (!flag) { this.Close(); } } }
public PowerShellResults <O> Invoke <O>(RunspaceMediator runspaceMediator, IEnumerable pipelineInput, WebServiceParameters parameters, CmdletActivity activity, bool isGetListAsync) { return(this.command.Invoke(runspaceMediator, pipelineInput, parameters, activity, isGetListAsync)); }
protected DataSourceService(RunspaceMediator runspaceMediator) { this.runspaceMediator = runspaceMediator; }
private static PowerShellResults <O> InvokeCore <O>(PSCommand psCommand, RunspaceMediator runspaceMediator, IEnumerable pipelineInput, WebServiceParameters parameters, CmdletActivity activity, bool isGetListAsync) { Func <WarningRecord, string> func = null; Func <Command, string> func2 = null; PSCommandExtension.EnsureNoWriteTaskInGetRequest(psCommand, parameters); PowerShellResults <O> powerShellResults = new PowerShellResults <O>(); ExTraceGlobals.EventLogTracer.TraceInformation <string, EcpTraceFormatter <PSCommand> >(0, 0L, "{0} tries to invoke {1}. For more details, refer to task trace", RbacPrincipal.Current.NameForEventLog, psCommand.GetTraceFormatter()); using (RunspaceProxy runspaceProxy = new RunspaceProxy(runspaceMediator)) { runspaceProxy.SetVariable("ConfirmPreference", "None"); if (parameters != null) { psCommand.AddParameters(parameters); } using (PowerShell powerShell = runspaceProxy.CreatePowerShell(psCommand)) { List <PSObject> list = null; if (activity != null) { AsyncServiceManager.RegisterPowerShellToActivity(powerShell, activity, pipelineInput, out list, isGetListAsync); } else { AsyncServiceManager.RegisterPowerShell(powerShell); } int requestLatency = 0; DateTime utcNow = DateTime.UtcNow; try { TaskPerformanceRecord taskPerformanceRecord = new TaskPerformanceRecord(psCommand.GetCmdletName(), PSCommandExtension.powerShellLatencyDetectionContextFactory, EcpEventLogConstants.Tuple_EcpPowerShellInvoked, EcpEventLogConstants.Tuple_EcpPowerShellCompleted, EcpEventLogExtensions.EventLog, new IPerformanceDataProvider[] { PerformanceContext.Current, RpcDataProvider.Instance, TaskPerformanceData.CmdletInvoked, TaskPerformanceData.BeginProcessingInvoked, TaskPerformanceData.ProcessRecordInvoked, TaskPerformanceData.EndProcessingInvoked, EcpPerformanceData.PowerShellInvoke }); try { using (EcpPerformanceData.PowerShellInvoke.StartRequestTimer()) { if (list == null) { powerShellResults.Output = powerShell.Invoke <O>(pipelineInput).ToArray <O>(); } else { powerShell.Invoke <PSObject>(pipelineInput, list); powerShellResults.Output = Array <O> .Empty; } } } finally { requestLatency = (int)taskPerformanceRecord.Stop().TotalMilliseconds; IDisposable disposable2 = taskPerformanceRecord; if (disposable2 != null) { disposable2.Dispose(); } } List <ErrorRecord> list2 = new List <ErrorRecord>(); bool flag = false; foreach (ErrorRecord errorRecord in powerShell.Streams.Error) { if (!flag) { flag = PSCommandExtension.TryPatchShouldContinueException(errorRecord, psCommand, parameters); } list2.Add(new ErrorRecord(errorRecord)); } powerShellResults.ErrorRecords = list2.ToArray(); PowerShellResults powerShellResults2 = powerShellResults; IEnumerable <WarningRecord> warning = powerShell.Streams.Warning; if (func == null) { func = ((WarningRecord warningRecord) => warningRecord.Message); } powerShellResults2.Warnings = warning.Select(func).ToArray <string>(); } catch (RuntimeException ex) { PSCommandExtension.TryPatchShouldContinueException(ex.ErrorRecord, psCommand, parameters); ErrorRecord errorRecord2; if (ex.ErrorRecord != null && !(ex is ParameterBindingException)) { errorRecord2 = new ErrorRecord(ex.ErrorRecord); } else { errorRecord2 = new ErrorRecord(ex); } powerShellResults.ErrorRecords = new ErrorRecord[] { errorRecord2 }; } finally { string text = HttpContext.Current.Request.QueryString["reqId"]; ServerLogEvent logEvent = new ServerLogEvent(psCommand, pipelineInput, requestLatency, string.IsNullOrEmpty(text) ? string.Empty : text, (powerShellResults.ErrorRecords != null && powerShellResults.ErrorRecords.Length > 0) ? powerShellResults.ErrorRecords.ToLogString() : string.Empty, (powerShellResults.Output != null) ? powerShellResults.Output.Length : 0); ServerLogger.Instance.LogEvent(logEvent); } PowerShellResults powerShellResults3 = powerShellResults; IEnumerable <Command> commands = psCommand.Commands; if (func2 == null) { func2 = ((Command cmd) => cmd.CommandText); } powerShellResults3.Cmdlets = commands.Select(func2).ToArray <string>(); if (powerShellResults.ErrorRecords.Length > 0) { ExTraceGlobals.EventLogTracer.TraceError <string, EcpTraceFormatter <PSCommand>, EcpTraceFormatter <ErrorRecord[]> >(0, 0L, "{0} invoked {1} and encountered errors: {2}", RbacPrincipal.Current.NameForEventLog, psCommand.GetTraceFormatter(), powerShellResults.ErrorRecords.GetTraceFormatter()); } CmdExecuteInfo cmdExecuteInfo = CmdletLogger.CaculateLogAndSaveToContext(powerShell, utcNow, powerShellResults.ErrorRecords); if (cmdExecuteInfo != null) { powerShellResults.CmdletLogInfo = new CmdExecuteInfo[] { cmdExecuteInfo }; } } } return(powerShellResults); }
public static PowerShellResults <O> Invoke <O>(this PSCommand psCommand, RunspaceMediator runspaceMediator, IEnumerable pipelineInput, WebServiceParameters parameters) { return(PSCommandExtension.InvokeCore <O>(psCommand, runspaceMediator, pipelineInput, parameters, null, false)); }
public static PowerShellResults <O> Invoke <O>(this PSCommand psCommand, RunspaceMediator runspaceMediator, IEnumerable pipelineInput, WebServiceParameters parameters, CmdletActivity activity, bool isGetListAsync) { return(PSCommandExtension.InvokeCore <O>(psCommand, runspaceMediator, pipelineInput, parameters, activity, isGetListAsync)); }
public PowerShellResults Invoke(RunspaceMediator runspaceMediator) { return(this.command.Invoke(runspaceMediator)); }
public static PowerShellResults Invoke(this PSCommand psCommand, RunspaceMediator runspaceMediator) { PowerShellResults results = null; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.InvokeCmdletLatency, delegate { using (RunspaceProxy runspace = new RunspaceProxy(runspaceMediator)) { try { ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.InvokeCmdletExcludeRunspaceCreationLatency, delegate { using (PowerShell powerShell = runspace.CreatePowerShell(psCommand)) { try { Collection <PSObject> output = null; ElapsedTimeWatcher.Watch(RequestStatistics.RequestStatItem.InvokeCmdletExclusiveLatency, delegate { output = powerShell.Invoke(); }); ErrorRecord[] array = new ErrorRecord[powerShell.Streams.Error.Count]; powerShell.Streams.Error.CopyTo(array, 0); results = new PowerShellResults(output, new Collection <ErrorRecord>(array)); } catch (RuntimeException ex) { ErrorRecord errorRecord3; if (ex.ErrorRecord != null && !(ex is ParameterBindingException)) { errorRecord3 = ex.ErrorRecord; } else { errorRecord3 = new ErrorRecord(ex, string.Empty, ErrorCategory.NotSpecified, null); } results = new PowerShellResults(new Collection <ErrorRecord>(new ErrorRecord[] { errorRecord3 })); } } }); } catch (OverBudgetException exception) { ErrorRecord errorRecord = new ErrorRecord(exception, string.Empty, ErrorCategory.NotSpecified, null); results = new PowerShellResults(new Collection <ErrorRecord>(new ErrorRecord[] { errorRecord })); } catch (ADTransientException exception2) { ErrorRecord errorRecord2 = new ErrorRecord(exception2, string.Empty, ErrorCategory.NotSpecified, null); results = new PowerShellResults(new Collection <ErrorRecord>(new ErrorRecord[] { errorRecord2 })); } } }); return(results); }
// Token: 0x0600100C RID: 4108 RVA: 0x00030D1D File Offset: 0x0002EF1D internal MonadConnection(CommandInteractionHandler uiHandler, RunspaceMediator mediator) : this(uiHandler, mediator, null) { }