PowerShell/src/Microsoft.Management.Infrastructure.CimCmdlets/CimAsyncOperation.cs

596 lines
20 KiB
C#
Raw Normal View History

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#region Using directives
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Management.Automation;
using System.Threading;
#endregion
namespace Microsoft.Management.Infrastructure.CimCmdlets
{
/// <summary>
/// <para>
/// Async operation base class, it will issue async operation through
/// 1...* CimSession object(s), processing the async results, extended
/// pssemantics operations, and manage the lifecycle of created
/// CimSession object(s).
/// </para>
/// </summary>
internal abstract class CimAsyncOperation : IDisposable
{
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="CimAsyncOperation"/> class.
/// </summary>
protected CimAsyncOperation()
{
this.moreActionEvent = new ManualResetEventSlim(false);
this.actionQueue = new ConcurrentQueue<CimBaseAction>();
this._disposed = 0;
this.operationCount = 0;
}
#endregion
#region Event handler
/// <summary>
/// <para>
/// Handler used to handle new action event from
/// <seealso cref="CimSessionProxy"/> object.
/// </para>
/// </summary>
/// <param name="cimSession">
/// <seealso cref="CimSession"/> object raised the event
/// </param>
/// <param name="actionArgs">Event argument.</param>
protected void NewCmdletActionHandler(object cimSession, CmdletActionEventArgs actionArgs)
{
DebugHelper.WriteLogEx("Disposed {0}, action type = {1}", 0, this.Disposed, actionArgs.Action);
if (this.Disposed)
{
if (actionArgs.Action is CimSyncAction)
{
// unblock the thread waiting for response
(actionArgs.Action as CimSyncAction).OnComplete();
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
return;
}
bool isEmpty = this.actionQueue.IsEmpty;
this.actionQueue.Enqueue(actionArgs.Action);
if (isEmpty)
{
this.moreActionEvent.Set();
}
}
/// <summary>
/// <para>
/// Handler used to handle new operation event from
/// <seealso cref="CimSessionProxy"/> object.
/// </para>
/// </summary>
/// <param name="cimSession">
/// <seealso cref="CimSession"/> object raised the event.
/// </param>
/// <param name="actionArgs">Event argument.</param>
protected void OperationCreatedHandler(object cimSession, OperationEventArgs actionArgs)
{
DebugHelper.WriteLogEx();
lock (this.a_lock)
{
this.operationCount++;
}
}
/// <summary>
/// <para>
/// Handler used to handle operation deletion event from
/// <seealso cref="CimSessionProxy"/> object.
/// </para>
/// </summary>
/// <param name="cimSession">
/// <seealso cref="CimSession"/> object raised the event.
/// </param>
/// <param name="actionArgs">Event argument.</param>
protected void OperationDeletedHandler(object cimSession, OperationEventArgs actionArgs)
{
DebugHelper.WriteLogEx();
lock (this.a_lock)
{
this.operationCount--;
if (this.operationCount == 0)
{
this.moreActionEvent.Set();
}
}
}
#endregion
/// <summary>
/// <para>
/// process all actions in the action queue
/// </para>
/// </summary>
/// <param name="cmdletOperation">
/// Wrapper of cmdlet, <seealso cref="CmdletOperationBase"/> for details.
/// </param>
public void ProcessActions(CmdletOperationBase cmdletOperation)
{
if (!this.actionQueue.IsEmpty)
{
CimBaseAction action;
while (GetActionAndRemove(out action))
{
action.Execute(cmdletOperation);
if (this.Disposed)
{
break;
}
}
}
}
/// <summary>
/// <para>
/// Process remaining actions until all operations are completed or
/// current cmdlet is terminated by user.
/// </para>
/// </summary>
/// <param name="cmdletOperation">
/// Wrapper of cmdlet, <seealso cref="CmdletOperationBase"/> for details.
/// </param>
public void ProcessRemainActions(CmdletOperationBase cmdletOperation)
{
DebugHelper.WriteLogEx();
while (true)
{
ProcessActions(cmdletOperation);
if (!this.IsActive())
{
DebugHelper.WriteLogEx("Either disposed or all operations completed.", 2);
break;
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
try
{
this.moreActionEvent.Wait();
this.moreActionEvent.Reset();
}
catch (ObjectDisposedException ex)
{
// This might happen if this object is being disposed,
// while another thread is processing the remaining actions
DebugHelper.WriteLogEx("moreActionEvent was disposed: {0}.", 2, ex);
break;
}
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
ProcessActions(cmdletOperation);
}
#region helper methods
/// <summary>
/// <para>
/// Get action object from action queue.
/// </para>
/// </summary>
/// <param name="action">Next action to execute.</param>
/// <returns>True indicates there is an valid action, otherwise false.</returns>
protected bool GetActionAndRemove(out CimBaseAction action)
{
return this.actionQueue.TryDequeue(out action);
}
/// <summary>
/// <para>
/// Add temporary <seealso cref="CimSessionProxy"/> object to cache.
/// </para>
/// </summary>
/// <param name="sessionproxy">Cimsession wrapper object.</param>
protected void AddCimSessionProxy(CimSessionProxy sessionproxy)
{
lock (cimSessionProxyCacheLock)
{
if (this.cimSessionProxyCache == null)
{
this.cimSessionProxyCache = new List<CimSessionProxy>();
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
if (!this.cimSessionProxyCache.Contains(sessionproxy))
{
this.cimSessionProxyCache.Add(sessionproxy);
}
}
}
/// <summary>
/// <para>
/// Are there active operations?
/// </para>
/// </summary>
/// <returns>True for having active operations, otherwise false.</returns>
protected bool IsActive()
{
DebugHelper.WriteLogEx("Disposed {0}, Operation Count {1}", 2, this.Disposed, this.operationCount);
bool isActive = (!this.Disposed) && (this.operationCount > 0);
return isActive;
}
/// <summary>
/// Create <see cref="CimSessionProxy"/> object.
/// </summary>
/// <param name="session"></param>
protected CimSessionProxy CreateCimSessionProxy(CimSessionProxy originalProxy)
{
CimSessionProxy proxy = new(originalProxy);
this.SubscribeEventAndAddProxytoCache(proxy);
return proxy;
}
/// <summary>
/// Create <see cref="CimSessionProxy"/> object.
/// </summary>
/// <param name="session"></param>
protected CimSessionProxy CreateCimSessionProxy(CimSessionProxy originalProxy, bool passThru)
{
CimSessionProxy proxy = new CimSessionProxySetCimInstance(originalProxy, passThru);
this.SubscribeEventAndAddProxytoCache(proxy);
return proxy;
}
/// <summary>
/// Create <see cref="CimSessionProxy"/> object.
/// </summary>
/// <param name="session"></param>
protected CimSessionProxy CreateCimSessionProxy(CimSession session)
{
CimSessionProxy proxy = new(session);
this.SubscribeEventAndAddProxytoCache(proxy);
return proxy;
}
/// <summary>
/// Create <see cref="CimSessionProxy"/> object.
/// </summary>
/// <param name="session"></param>
protected CimSessionProxy CreateCimSessionProxy(CimSession session, bool passThru)
{
CimSessionProxy proxy = new CimSessionProxySetCimInstance(session, passThru);
this.SubscribeEventAndAddProxytoCache(proxy);
return proxy;
}
/// <summary>
/// Create <see cref="CimSessionProxy"/> object, and
/// add the proxy into cache.
/// </summary>
/// <param name="computerName"></param>
protected CimSessionProxy CreateCimSessionProxy(string computerName)
{
CimSessionProxy proxy = new(computerName);
this.SubscribeEventAndAddProxytoCache(proxy);
return proxy;
}
/// <summary>
/// Create <see cref="CimSessionProxy"/> object, and
/// add the proxy into cache.
/// </summary>
/// <param name="computerName"></param>
/// <param name="cimInstance"></param>
/// <returns></returns>
protected CimSessionProxy CreateCimSessionProxy(string computerName, CimInstance cimInstance)
{
CimSessionProxy proxy = new(computerName, cimInstance);
this.SubscribeEventAndAddProxytoCache(proxy);
return proxy;
}
/// <summary>
/// Create <see cref="CimSessionProxy"/> object, and
/// add the proxy into cache.
/// </summary>
/// <param name="computerName"></param>
/// <param name="cimInstance"></param>
/// <param name="passThru"></param>
protected CimSessionProxy CreateCimSessionProxy(string computerName, CimInstance cimInstance, bool passThru)
{
CimSessionProxy proxy = new CimSessionProxySetCimInstance(computerName, cimInstance, passThru);
this.SubscribeEventAndAddProxytoCache(proxy);
return proxy;
}
/// <summary>
/// Subscribe event from proxy and add proxy to cache.
/// </summary>
/// <param name="proxy"></param>
protected void SubscribeEventAndAddProxytoCache(CimSessionProxy proxy)
{
this.AddCimSessionProxy(proxy);
SubscribeToCimSessionProxyEvent(proxy);
}
/// <summary>
/// <para>
/// Subscribe to the events issued by <see cref="CimSessionProxy"/>.
/// </para>
/// </summary>
/// <param name="proxy"></param>
protected virtual void SubscribeToCimSessionProxyEvent(CimSessionProxy proxy)
{
DebugHelper.WriteLogEx();
proxy.OnNewCmdletAction += this.NewCmdletActionHandler;
proxy.OnOperationCreated += this.OperationCreatedHandler;
proxy.OnOperationDeleted += this.OperationDeletedHandler;
}
/// <summary>
/// Retrieve the base object out if wrapped in psobject.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
protected object GetBaseObject(object value)
{
PSObject psObject = value as PSObject;
if (psObject == null)
{
return value;
}
else
{
object baseObject = psObject.BaseObject;
var arrayObject = baseObject as object[];
if (arrayObject == null)
{
return baseObject;
}
else
{
object[] arraybaseObject = new object[arrayObject.Length];
for (int i = 0; i < arrayObject.Length; i++)
{
arraybaseObject[i] = GetBaseObject(arrayObject[i]);
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
return arraybaseObject;
}
}
}
/// <summary>
/// Retrieve the reference object or reference array object.
/// The returned object has to be either CimInstance or CImInstance[] type,
/// if not thrown exception.
/// </summary>
/// <param name="value"></param>
/// <param name="referenceType">Output the cimtype of the value, either Reference or ReferenceArray.</param>
/// <returns>The object.</returns>
protected object GetReferenceOrReferenceArrayObject(object value, ref CimType referenceType)
{
PSReference cimReference = value as PSReference;
if (cimReference != null)
{
object baseObject = GetBaseObject(cimReference.Value);
if (!(baseObject is CimInstance cimInstance))
{
return null;
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
referenceType = CimType.Reference;
return cimInstance;
}
else
{
object[] cimReferenceArray = value as object[];
if (cimReferenceArray == null)
{
return null;
}
else if (cimReferenceArray[0] is not PSReference)
{
return null;
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
CimInstance[] cimInstanceArray = new CimInstance[cimReferenceArray.Length];
for (int i = 0; i < cimReferenceArray.Length; i++)
{
if (!(cimReferenceArray[i] is PSReference tempCimReference))
{
return null;
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
object baseObject = GetBaseObject(tempCimReference.Value);
cimInstanceArray[i] = baseObject as CimInstance;
if (cimInstanceArray[i] == null)
{
return null;
}
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
referenceType = CimType.ReferenceArray;
return cimInstanceArray;
}
}
#endregion
#region IDisposable
/// <summary>
/// <para>
/// Indicates whether this object was disposed or not
/// </para>
/// </summary>
protected bool Disposed
{
get
{
return this._disposed == 1;
}
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
private int _disposed;
/// <summary>
/// <para>
/// Dispose() calls Dispose(true).
/// Implement IDisposable. Do not make this method virtual.
/// A derived class should not be able to override this method.
/// </para>
/// </summary>
public void Dispose()
{
Dispose(true);
// This object will be cleaned up by the Dispose method.
Spelling comments (#2066) * spelling: comments in src/Microsoft.Management.Infrastructure.CimCmdlets * spelling: comments in src/Microsoft.PackageManagement.ArchiverProviders * spelling: comments in src/Microsoft.PackageManagement.CoreProviders * spelling: comments in src/Microsoft.PackageManagement.MetaProvider.PowerShell * spelling: comments in src/Microsoft.PackageManagement.MsiProvider * spelling: comments in src/Microsoft.PackageManagement.MsuProvider * spelling: comments in src/Microsoft.PackageManagement.NuGetProvider * spelling: comments in src/Microsoft.PackageManagement.PackageSourceListProvider * spelling: comments in src/Microsoft.PackageManagement * spelling: comments in src/Microsoft.PowerShell.Activities * spelling: comments in src/Microsoft.PowerShell.Commands.Diagnostics * spelling: comments in src/Microsoft.PowerShell.Commands.Management * spelling: comments in src/Microsoft.PowerShell.Commands.Utility * spelling: comments in src/Microsoft.PowerShell.ConsoleHost * spelling: comments in src/Microsoft.PowerShell.Core.Activities * spelling: comments in src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext * spelling: comments in src/Microsoft.PowerShell.CoreCLR.Eventing * spelling: comments in src/Microsoft.PowerShell.Diagnostics.Activities * spelling: comments in src/Microsoft.PowerShell.GraphicalHost * spelling: comments in src/Microsoft.PowerShell.LocalAccounts * spelling: comments in src/Microsoft.PowerShell.Management.Activities * spelling: comments in src/Microsoft.PowerShell.PSReadLine * spelling: comments in src/Microsoft.PowerShell.PackageManagement * spelling: comments in src/Microsoft.PowerShell.ScheduledJob * spelling: comments in src/Microsoft.PowerShell.Security.Activities * spelling: comments in src/Microsoft.PowerShell.Security * spelling: comments in src/Microsoft.PowerShell.Utility.Activities * spelling: comments in src/Microsoft.PowerShell.Workflow.ServiceCore * spelling: comments in src/Microsoft.WSMan.Management.Activities * spelling: comments in src/Modules * spelling: comments in src/Schemas * spelling: comments in src/libpsl-native * spelling: comments in src/powershell-native * spelling: comments in build.psm1 * spelling: comments in src/System.Management.Automation/CoreCLR * spelling: comments in src/System.Management.Automation/DscSupport * spelling: comments in src/System.Management.Automation/cimSupport * spelling: comments in src/System.Management.Automation/commands * spelling: comments in src/System.Management.Automation/engine/Modules
2016-08-26 22:46:03 +02:00
// Therefore, you should call GC.SuppressFinalize to
// take this object off the finalization queue
// and prevent finalization code for this object
// from executing a second time.
GC.SuppressFinalize(this);
}
/// <summary>
/// <para>
/// Dispose(bool disposing) executes in two distinct scenarios.
/// If disposing equals true, the method has been called directly
/// or indirectly by a user's code. Managed and unmanaged resources
/// can be disposed.
/// If disposing equals false, the method has been called by the
/// runtime from inside the finalizer and you should not reference
/// other objects. Only unmanaged resources can be disposed.
/// </para>
/// </summary>
/// <param name="disposing">Whether it is directly called.</param>
protected virtual void Dispose(bool disposing)
{
if (Interlocked.CompareExchange(ref this._disposed, 1, 0) == 0)
{
if (disposing)
{
// free managed resources
Cleanup();
}
// free native resources if there are any
}
}
/// <summary>
/// <para>
/// Clean up managed resources.
/// </para>
/// </summary>
private void Cleanup()
{
DebugHelper.WriteLogEx();
// unblock thread that waiting for more actions
this.moreActionEvent.Set();
CimBaseAction action;
while (GetActionAndRemove(out action))
{
DebugHelper.WriteLog("Action {0}", 2, action);
if (action is CimSyncAction)
{
// unblock the thread waiting for response
(action as CimSyncAction).OnComplete();
}
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
if (this.cimSessionProxyCache != null)
{
List<CimSessionProxy> temporaryProxy;
lock (this.cimSessionProxyCache)
{
temporaryProxy = new List<CimSessionProxy>(this.cimSessionProxyCache);
this.cimSessionProxyCache.Clear();
}
// clean up all proxy objects
foreach (CimSessionProxy proxy in temporaryProxy)
{
DebugHelper.WriteLog("Dispose proxy ", 2);
proxy.Dispose();
}
}
this.moreActionEvent.Dispose();
if (this.ackedEvent != null)
{
this.ackedEvent.Dispose();
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
DebugHelper.WriteLog("Cleanup complete.", 2);
}
#endregion
#region private members
/// <summary>
/// Lock object.
/// </summary>
private readonly object a_lock = new();
/// <summary>
/// Number of active operations.
/// </summary>
private uint operationCount;
/// <summary>
/// Event to notify ps thread that more action is available.
/// </summary>
private readonly ManualResetEventSlim moreActionEvent;
/// <summary>
/// The following is the definition of action queue.
Spelling comments (#2066) * spelling: comments in src/Microsoft.Management.Infrastructure.CimCmdlets * spelling: comments in src/Microsoft.PackageManagement.ArchiverProviders * spelling: comments in src/Microsoft.PackageManagement.CoreProviders * spelling: comments in src/Microsoft.PackageManagement.MetaProvider.PowerShell * spelling: comments in src/Microsoft.PackageManagement.MsiProvider * spelling: comments in src/Microsoft.PackageManagement.MsuProvider * spelling: comments in src/Microsoft.PackageManagement.NuGetProvider * spelling: comments in src/Microsoft.PackageManagement.PackageSourceListProvider * spelling: comments in src/Microsoft.PackageManagement * spelling: comments in src/Microsoft.PowerShell.Activities * spelling: comments in src/Microsoft.PowerShell.Commands.Diagnostics * spelling: comments in src/Microsoft.PowerShell.Commands.Management * spelling: comments in src/Microsoft.PowerShell.Commands.Utility * spelling: comments in src/Microsoft.PowerShell.ConsoleHost * spelling: comments in src/Microsoft.PowerShell.Core.Activities * spelling: comments in src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext * spelling: comments in src/Microsoft.PowerShell.CoreCLR.Eventing * spelling: comments in src/Microsoft.PowerShell.Diagnostics.Activities * spelling: comments in src/Microsoft.PowerShell.GraphicalHost * spelling: comments in src/Microsoft.PowerShell.LocalAccounts * spelling: comments in src/Microsoft.PowerShell.Management.Activities * spelling: comments in src/Microsoft.PowerShell.PSReadLine * spelling: comments in src/Microsoft.PowerShell.PackageManagement * spelling: comments in src/Microsoft.PowerShell.ScheduledJob * spelling: comments in src/Microsoft.PowerShell.Security.Activities * spelling: comments in src/Microsoft.PowerShell.Security * spelling: comments in src/Microsoft.PowerShell.Utility.Activities * spelling: comments in src/Microsoft.PowerShell.Workflow.ServiceCore * spelling: comments in src/Microsoft.WSMan.Management.Activities * spelling: comments in src/Modules * spelling: comments in src/Schemas * spelling: comments in src/libpsl-native * spelling: comments in src/powershell-native * spelling: comments in build.psm1 * spelling: comments in src/System.Management.Automation/CoreCLR * spelling: comments in src/System.Management.Automation/DscSupport * spelling: comments in src/System.Management.Automation/cimSupport * spelling: comments in src/System.Management.Automation/commands * spelling: comments in src/System.Management.Automation/engine/Modules
2016-08-26 22:46:03 +02:00
/// The queue holding all actions to be executed in the context of either
/// ProcessRecord or EndProcessing.
/// </summary>
private readonly ConcurrentQueue<CimBaseAction> actionQueue;
/// <summary>
/// Lock object.
/// </summary>
private readonly object cimSessionProxyCacheLock = new();
/// <summary>
/// Cache all <see cref="CimSessionProxy"/> objects related to
/// the current operation.
/// </summary>
private List<CimSessionProxy> cimSessionProxyCache;
#endregion
#region protected members
/// <summary>
/// Event to notify ps thread that either a ACK message sent back
/// or a error happened. Currently only used by
/// <see cref="CimRegisterCimIndication"/>.
/// </summary>
protected ManualResetEventSlim ackedEvent;
#endregion
#region const strings
internal const string ComputerNameArgument = @"ComputerName";
internal const string CimSessionArgument = @"CimSession";
#endregion
}
}