protected virtual void Dispose(bool disposeManagedResources) { if (!this.disposed && disposeManagedResources) { if (this.runspace != null) { this.runspace.Store.Return(this.runspace); } if (this.executionToken != null) { this.executionToken.Release(); this.executionToken = null; } if (this.timer != null) { this.timer.Dispose(); this.timer = null; } if (this.userCacheLocked) { DataServiceController.Current.UserDataCache.TryUnlockKey(this.runspace.Borrower); this.userCacheLocked = false; } } this.disposed = true; }
public PipelineInvocation(Envelope <PSRunspace, UserContext> runspace, ResourceType entityType) { UserData userDatum = null; this.runspace = runspace; this.entityType = entityType; this.ID = Guid.NewGuid(); this.Status = PipelineState.Executing; this.WaitMsec = 0; this.OutputFormat = null; this.ExpirationTime = DateTimeHelper.UtcNow; this.outputQuotaExceeded = false; this.outputObjects = new PSDataCollection <PSObject>(); this.Errors = new Collection <ErrorRecord>(); this.finished = new ManualResetEvent(false); this.TestHookCompletionCallback = new AsyncCallback(this.AsyncCallback); if (runspace != null) { this.executionToken = DataServiceController.Current.GetAuthorizedUserIdentity(runspace.Borrower); this.executionToken.AddRef(); DataServiceController.Current.UserDataCache.TryLockKey(runspace.Borrower, out userDatum); this.userCacheLocked = true; } this.timer = new PswsTimer(new ElapsedEventHandler(this.TimerCallback), DataServiceController.Current.Configuration.PowerShell.Quotas.MaxExecutionTime, false, false); }
public IEnumerator <DSResource> InvokeAsync(Expression expression, bool noStreamingResponse) { IEnumerator <DSResource> enumerator; this.AddImmutableParameters(); this.cmdletInfo.VerifyMandatoryParameterAdded(this.parameters.Keys, this.commonParameterFlag); this.ConvertCollectionParameters(); SafeRefCountedContainer <WindowsIdentity> authorizedUserIdentity = DataServiceController.Current.GetAuthorizedUserIdentity(this.runspace.Borrower); WindowsImpersonationContext windowsImpersonationContext = authorizedUserIdentity.Instance.Impersonate(); using (windowsImpersonationContext) { TraceHelper.Current.BeginOperation0("PowerShell.Create"); this.powerShell = System.Management.Automation.PowerShell.Create(); TraceHelper.Current.EndOperation("PowerShell.Create"); TraceHelper.Current.BeginOperation0("RunspaceContext.Create"); DefaultRunspaceContext defaultRunspaceContext = DefaultRunspaceContext.Create(this.runspace.Item.Runspace); using (defaultRunspaceContext) { TraceHelper.Current.EndOperation("RunspaceContext.Create"); EventHandler <DataAddedEventArgs> eventHandler = new EventHandler <DataAddedEventArgs>(this.DataAddedEventHandler); if (this.entityType == null) { eventHandler = null; } IEnumerator <DSResource> enumerator1 = this.InvokeCmdletAsync(this.powerShell, expression, eventHandler, new AsyncCallback(this.ExecutionCompletionEventHandler), noStreamingResponse); this.ExecutionCompletionEventHandler(this.asynchronousResult); enumerator = enumerator1; } } return(enumerator); }
protected virtual void Dispose(bool disposeManagedResources) { if (!this.disposed && disposeManagedResources) { try { SafeRefCountedContainer <WindowsIdentity> authorizedUserIdentity = DataServiceController.Current.GetAuthorizedUserIdentity(this.dataContext.UserContext); authorizedUserIdentity.Release(); } catch (UnauthorizedAccessException unauthorizedAccessException) { } } this.disposed = true; }
public PipelineInvocation(Envelope<PSRunspace, UserContext> runspace, ResourceType entityType) { UserData userDatum = null; this.runspace = runspace; this.entityType = entityType; this.ID = Guid.NewGuid(); this.Status = PipelineState.Executing; this.WaitMsec = 0; this.OutputFormat = null; this.ExpirationTime = DateTimeHelper.UtcNow; this.outputQuotaExceeded = false; this.outputObjects = new PSDataCollection<PSObject>(); this.Errors = new Collection<ErrorRecord>(); this.finished = new ManualResetEvent(false); this.TestHookCompletionCallback = new AsyncCallback(this.AsyncCallback); if (runspace != null) { this.executionToken = DataServiceController.Current.GetAuthorizedUserIdentity(runspace.Borrower); this.executionToken.AddRef(); DataServiceController.Current.UserDataCache.TryLockKey(runspace.Borrower, out userDatum); this.userCacheLocked = true; } this.timer = new PswsTimer(new ElapsedEventHandler(this.TimerCallback), DataServiceController.Current.Configuration.PowerShell.Quotas.MaxExecutionTime, false, false); }