private CimSession(SessionHandle handle, string computerName) { this._disposeThreadSafetyLock = new object(); this._handle = handle; this.ComputerName = computerName; this.InstanceId = Guid.NewGuid(); CimApplication.AddTracking(this); }
public IEnumerator <TItem> GetEnumerator() { CimOperation cimOperation; TEnumerator tEnumerator = this.CreateEnumerator(); IDisposable disposable = CimApplication.AssertNoPendingShutdown(); using (disposable) { OperationHandle operationHandle = this._operationStarter(tEnumerator); operationHandle.SetExtraFinalizationAction(new Action(tEnumerator.InternalFinalizationHelper)); cimOperation = new CimOperation(operationHandle, this._cancellationToken); } tEnumerator.SetOperation(cimOperation); return(tEnumerator); }
public static CimSession Create(string computerName, CimSessionOptions sessionOptions) { IPAddress pAddress = null; InstanceHandle instanceHandle = null; SessionHandle sessionHandle = null; CimSession cimSession; string protocol; DestinationOptionsHandle destinationOptionsHandle; string str = computerName; if (!string.IsNullOrEmpty(str) && IPAddress.TryParse(str, out pAddress) && pAddress.AddressFamily == AddressFamily.InterNetworkV6 && str[0] != '[') { str = string.Concat("[", str, "]"); } IDisposable disposable = CimApplication.AssertNoPendingShutdown(); using (disposable) { ApplicationHandle handle = CimApplication.Handle; if (sessionOptions == null) { protocol = null; } else { protocol = sessionOptions.Protocol; } string str1 = str; if (sessionOptions == null) { destinationOptionsHandle = null; } else { destinationOptionsHandle = sessionOptions.DestinationOptionsHandle ?? sessionOptions.DestinationOptionsHandleOnDemand; } MiResult miResult = ApplicationMethods.NewSession(handle, protocol, str1, destinationOptionsHandle, out instanceHandle, out sessionHandle); if (miResult != MiResult.NOT_FOUND) { CimException.ThrowIfMiResultFailure(miResult, instanceHandle); CimSession cimSession1 = new CimSession(sessionHandle, computerName); cimSession = cimSession1; } else { throw new CimException(miResult, null, instanceHandle, System.Management.Automation.Strings.UnrecognizedProtocolName); } } return cimSession; }
protected virtual void Dispose(bool disposing) { lock (this._disposeThreadSafetyLock) { if (!this._disposed) { this._disposed = true; } else { return; } } if (disposing) { this._handle.Dispose(); CimApplication.RemoveTracking(this); } }
internal CimOperation(OperationHandle handle, CancellationToken?cancellationToken) { Action action = null; this._cancellationModeLock = new object(); this._cancelVsCloseLock = new object(); this._handle = handle; if (cancellationToken.HasValue) { CimOperation cimOperation = this; CancellationToken value = cancellationToken.Value; CancellationToken cancellationTokenPointer = value; if (action == null) { action = () => this.Cancel(CancellationMode.ThrowOperationCancelledException); } cimOperation._cancellationTokenRegistration = cancellationTokenPointer.Register(action); } CimApplication.AddTracking(this); }
protected virtual void Dispose(bool disposing) { if (!this._disposed) { if (disposing) { this.Close(); if (this._cancellationTokenRegistration != null) { this._cancellationTokenRegistration.Dispose(); this._cancellationTokenRegistration = null; } CimApplication.RemoveTracking(this); } this._disposed = true; return; } else { return; } }
public IDisposable Subscribe(IObserver <TResult> observer) { CimOperation cimOperation; if (observer != null) { TObserverProxy tObserverProxy = this.CreateObserverProxy(observer); tObserverProxy.SetReportOperationStarted(this._reportOperationStarted); IDisposable disposable = CimApplication.AssertNoPendingShutdown(); using (disposable) { OperationHandle operationHandle = this._operationStarter(tObserverProxy); cimOperation = new CimOperation(operationHandle, this._cancellationToken); } tObserverProxy.SetOperation(cimOperation); return(new CimAsyncCancellationDisposable(cimOperation)); } else { throw new ArgumentNullException("observer"); } }