From 05e62e40bff015b40bc7d66fbc84849e5d6c207d Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Mon, 23 Nov 2020 15:48:35 +0000 Subject: [PATCH 1/3] Fix IDE0032: UseAutoProperty part 2 `src\Microsoft.Management.Infrastructure.CimCmdlets\Microsoft.Management.Infrastructure.CimCmdlets.csproj` https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0032 --- .../CimBaseAction.cs | 15 +- .../CimCommandBase.cs | 139 ++------- .../CimGetCimClass.cs | 38 +-- .../CimIndicationWatcher.cs | 12 +- .../CimInvokeCimMethod.cs | 24 +- .../CimPromptUser.cs | 16 +- .../CimRegisterCimIndication.cs | 46 +-- .../CimResultObserver.cs | 32 +- .../CimSessionOperations.cs | 100 ++----- .../CimSessionProxy.cs | 276 +++++++----------- .../CimSetCimInstance.cs | 36 +-- .../CimWriteError.cs | 62 +--- .../CimWriteMessage.cs | 28 +- .../CimWriteProgress.cs | 58 +--- .../CimWriteResultObject.cs | 14 +- .../GetCimAssociatedInstanceCommand.cs | 56 +--- .../GetCimClassCommand.cs | 54 +--- .../GetCimInstanceCommand.cs | 33 +-- .../InvokeCimMethodCommand.cs | 29 +- .../NewCimInstanceCommand.cs | 18 +- .../NewCimSessionCommand.cs | 63 +--- .../NewCimSessionOptionCommand.cs | 18 +- .../RegisterCimIndicationCommand.cs | 18 +- .../RemoveCimInstanceCommand.cs | 20 +- .../SetCimInstanceCommand.cs | 35 +-- .../Utils.cs | 23 +- 26 files changed, 278 insertions(+), 985 deletions(-) diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimBaseAction.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimBaseAction.cs index 939f6c047a5..a635e5ae765 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimBaseAction.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimBaseAction.cs @@ -44,20 +44,7 @@ public virtual void Execute(CmdletOperationBase cmdlet) /// , object. /// /// - protected XOperationContextBase Context - { - get - { - return this.context; - } - - set - { - this.context = value; - } - } - - private XOperationContextBase context; + protected XOperationContextBase Context { get; set; } } /// diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs index b138c01b806..4744e319c3e 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimCommandBase.cs @@ -31,35 +31,19 @@ internal class ParameterDefinitionEntry /// internal ParameterDefinitionEntry(string parameterSetName, bool mandatory) { - this.mandatory = mandatory; - this.parameterSetName = parameterSetName; + this.IsMandatory = mandatory; + this.ParameterSetName = parameterSetName; } /// /// Property ParameterSetName. /// - internal string ParameterSetName - { - get - { - return this.parameterSetName; - } - } - - private readonly string parameterSetName = null; + internal string ParameterSetName { get; } = null; /// /// Whether the parameter is mandatory to the set. /// - internal bool IsMandatory - { - get - { - return this.mandatory; - } - } - - private readonly bool mandatory = false; + internal bool IsMandatory { get; } = false; } /// @@ -75,8 +59,8 @@ internal class ParameterSetEntry /// internal ParameterSetEntry(UInt32 mandatoryParameterCount) { - this.mandatoryParameterCount = mandatoryParameterCount; - this.isDefaultParameterSet = false; + this.MandatoryParameterCount = mandatoryParameterCount; + this.IsDefaultParameterSet = false; reset(); } @@ -86,8 +70,8 @@ internal ParameterSetEntry(UInt32 mandatoryParameterCount) /// internal ParameterSetEntry(ParameterSetEntry toClone) { - this.mandatoryParameterCount = toClone.MandatoryParameterCount; - this.isDefaultParameterSet = toClone.IsDefaultParameterSet; + this.MandatoryParameterCount = toClone.MandatoryParameterCount; + this.IsDefaultParameterSet = toClone.IsDefaultParameterSet; reset(); } @@ -98,8 +82,8 @@ internal ParameterSetEntry(ParameterSetEntry toClone) /// internal ParameterSetEntry(UInt32 mandatoryParameterCount, bool isDefault) { - this.mandatoryParameterCount = mandatoryParameterCount; - this.isDefaultParameterSet = isDefault; + this.MandatoryParameterCount = mandatoryParameterCount; + this.IsDefaultParameterSet = isDefault; reset(); } @@ -108,107 +92,39 @@ internal ParameterSetEntry(UInt32 mandatoryParameterCount, bool isDefault) /// internal void reset() { - this.setMandatoryParameterCount = this.setMandatoryParameterCountAtBeginProcess; - this.isValueSet = this.isValueSetAtBeginProcess; + this.SetMandatoryParameterCount = this.SetMandatoryParameterCountAtBeginProcess; + this.IsValueSet = this.IsValueSetAtBeginProcess; } /// /// Property DefaultParameterSet /// - internal bool IsDefaultParameterSet - { - get - { - return this.isDefaultParameterSet; - } - } - - private readonly bool isDefaultParameterSet = false; + internal bool IsDefaultParameterSet { get; } = false; /// /// Property MandatoryParameterCount /// - internal UInt32 MandatoryParameterCount - { - get - { - return this.mandatoryParameterCount; - } - } - - private readonly UInt32 mandatoryParameterCount = 0; + internal UInt32 MandatoryParameterCount { get; } = 0; /// /// Property IsValueSet /// - internal bool IsValueSet - { - get - { - return this.isValueSet; - } - - set - { - this.isValueSet = value; - } - } - - private bool isValueSet = false; + internal bool IsValueSet { get; set; } = false; /// /// Property IsValueSetAtBeginProcess /// - internal bool IsValueSetAtBeginProcess - { - get - { - return this.isValueSetAtBeginProcess; - } - - set - { - this.isValueSetAtBeginProcess = value; - } - } - - private bool isValueSetAtBeginProcess = false; + internal bool IsValueSetAtBeginProcess { get; set; } = false; /// /// Property SetMandatoryParameterCount /// - internal UInt32 SetMandatoryParameterCount - { - get - { - return this.setMandatoryParameterCount; - } - - set - { - this.setMandatoryParameterCount = value; - } - } - - private UInt32 setMandatoryParameterCount = 0; + internal UInt32 SetMandatoryParameterCount { get; set; } = 0; /// /// Property SetMandatoryParameterCountAtBeginProcess /// - internal UInt32 SetMandatoryParameterCountAtBeginProcess - { - get - { - return this.setMandatoryParameterCountAtBeginProcess; - } - - set - { - this.setMandatoryParameterCountAtBeginProcess = value; - } - } - - private UInt32 setMandatoryParameterCountAtBeginProcess = 0; + internal UInt32 SetMandatoryParameterCountAtBeginProcess { get; set; } = 0; } /// @@ -531,7 +447,7 @@ internal void CheckParameterSet() { try { - this.parameterSetName = this.parameterBinder.GetParameterSet(); + this.ParameterSetName = this.parameterBinder.GetParameterSet(); } finally { @@ -539,7 +455,7 @@ internal void CheckParameterSet() } } - DebugHelper.WriteLog("current parameterset is: " + this.parameterSetName, 4); + DebugHelper.WriteLog("current parameterset is: " + this.ParameterSetName, 4); } /// @@ -689,13 +605,6 @@ protected virtual void DisposeInternal() /// private readonly object myLock = new(); - /// - /// - /// parameter set name - /// - /// - private string parameterSetName; - /// /// This flag is introduced to resolve the parameter set name /// during process record @@ -747,13 +656,7 @@ internal CimAsyncOperation AsyncOperation /// Get current ParameterSetName of the cmdlet /// /// - internal string ParameterSetName - { - get - { - return this.parameterSetName; - } - } + internal string ParameterSetName { get; private set; } /// /// Gets/Sets cmdlet operation wrapper object. diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimGetCimClass.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimGetCimClass.cs index 1901b12ed83..c8284051335 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimGetCimClass.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimGetCimClass.cs @@ -30,10 +30,10 @@ internal CimGetCimClassContext( string thePropertyName, string theQualifierName) { - this.className = theClassName; - this.methodName = theMethodName; - this.propertyName = thePropertyName; - this.qualifierName = theQualifierName; + this.ClassName = theClassName; + this.MethodName = theMethodName; + this.PropertyName = thePropertyName; + this.QualifierName = theQualifierName; } /// @@ -44,14 +44,7 @@ internal CimGetCimClassContext( /// Wildcard expansion should be allowed. /// /// - public string ClassName - { - get { return className; } - - set { className = value; } - } - - private string className; + public string ClassName { get; set; } /// /// @@ -60,12 +53,7 @@ public string ClassName /// Then Filter the by given methodname /// /// - internal string MethodName - { - get { return methodName; } - } - - private readonly string methodName; + internal string MethodName { get; } /// /// @@ -74,12 +62,7 @@ internal string MethodName /// Filter the by given property name. /// /// - internal string PropertyName - { - get { return propertyName; } - } - - private readonly string propertyName; + internal string PropertyName { get; } /// /// @@ -88,12 +71,7 @@ internal string PropertyName /// Filter the by given methodname /// /// - internal string QualifierName - { - get { return qualifierName; } - } - - private readonly string qualifierName; + internal string QualifierName { get; } } /// diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimIndicationWatcher.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimIndicationWatcher.cs index f64316bd6c7..88f7cd3e89c 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimIndicationWatcher.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimIndicationWatcher.cs @@ -45,15 +45,7 @@ public class CimIndicationEventExceptionEventArgs : CimIndicationEventArgs /// Returns an exception /// /// - public Exception Exception - { - get - { - return exception; - } - } - - private readonly Exception exception; + public Exception Exception { get; } /// /// @@ -64,7 +56,7 @@ public Exception Exception public CimIndicationEventExceptionEventArgs(Exception theException) { context = null; - this.exception = theException; + this.Exception = theException; } } diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimInvokeCimMethod.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimInvokeCimMethod.cs index 8030111fa90..3ebfe9f5a73 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimInvokeCimMethod.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimInvokeCimMethod.cs @@ -40,36 +40,20 @@ internal CimInvokeCimMethodContext(string theNamespace, CimSessionProxy theProxy) { this.proxy = theProxy; - this.methodName = theMethodName; - this.collection = theCollection; + this.MethodName = theMethodName; + this.ParametersCollection = theCollection; this.nameSpace = theNamespace; } /// /// namespace /// - internal string MethodName - { - get - { - return this.methodName; - } - } - - private readonly string methodName; + internal string MethodName { get; } /// /// parameters collection /// - internal CimMethodParametersCollection ParametersCollection - { - get - { - return this.collection; - } - } - - private readonly CimMethodParametersCollection collection; + internal CimMethodParametersCollection ParametersCollection { get; } } /// diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimPromptUser.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimPromptUser.cs index 98fb4ed3fc8..c70de0029b6 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimPromptUser.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimPromptUser.cs @@ -27,7 +27,7 @@ internal sealed class CimPromptUser : CimSyncAction public CimPromptUser(string message, CimPromptType prompt) { - this.message = message; + this.Message = message; this.prompt = prompt; } @@ -54,7 +54,7 @@ public override void Execute(CmdletOperationBase cmdlet) // NOTES: prepare the whatif message and caption try { - result = cmdlet.ShouldContinue(message, "caption", ref yestoall, ref notoall); + result = cmdlet.ShouldContinue(Message, "caption", ref yestoall, ref notoall); if (yestoall) { this.responseType = CimResponseType.YesToAll; @@ -87,7 +87,7 @@ public override void Execute(CmdletOperationBase cmdlet) case CimPromptType.Normal: try { - result = cmdlet.ShouldProcess(message); + result = cmdlet.ShouldProcess(Message); if (result) { this.responseType = CimResponseType.Yes; @@ -121,15 +121,7 @@ public override void Execute(CmdletOperationBase cmdlet) /// /// Prompt message. /// - public string Message - { - get - { - return message; - } - } - - private readonly string message; + public string Message { get; } /// /// Prompt type -Normal or Critical. diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs index ed547444adc..8dd054698a8 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimRegisterCimIndication.cs @@ -47,15 +47,7 @@ internal class CimSubscriptionResultEventArgs : CimSubscriptionEventArgs /// subscription result /// /// - public CimSubscriptionResult Result - { - get - { - return result; - } - } - - private readonly CimSubscriptionResult result; + public CimSubscriptionResult Result { get; } /// /// Constructor @@ -65,7 +57,7 @@ public CimSubscriptionResultEventArgs( CimSubscriptionResult theResult) { this.context = null; - this.result = theResult; + this.Result = theResult; } } @@ -81,15 +73,7 @@ internal class CimSubscriptionExceptionEventArgs : CimSubscriptionEventArgs /// subscription result /// /// - public Exception Exception - { - get - { - return exception; - } - } - - private readonly Exception exception; + public Exception Exception { get; } /// /// Constructor @@ -99,7 +83,7 @@ public CimSubscriptionExceptionEventArgs( Exception theException) { this.context = null; - this.exception = theException; + this.Exception = theException; } } @@ -219,7 +203,7 @@ private void CimIndicationHandler(object cimSession, CmdletActionEventArgs actio CimWriteError cimWriteError = actionArgs.Action as CimWriteError; if (cimWriteError != null) { - this.exception = cimWriteError.Exception; + this.Exception = cimWriteError.Exception; if (!this.ackedEvent.IsSet) { // an exception happened @@ -233,10 +217,10 @@ private void CimIndicationHandler(object cimSession, CmdletActionEventArgs actio { DebugHelper.WriteLog("Raise an exception event", 2); - temp(this, new CimSubscriptionExceptionEventArgs(this.exception)); + temp(this, new CimSubscriptionExceptionEventArgs(this.Exception)); } - DebugHelper.WriteLog("Got an exception: {0}", 2, exception); + DebugHelper.WriteLog("Got an exception: {0}", 2, Exception); } CimWriteResultObject cimWriteResultObject = actionArgs.Action as CimWriteResultObject; @@ -276,7 +260,7 @@ private void WaitForAckMessage() { DebugHelper.WriteLogEx(); this.ackedEvent.Wait(); - if (this.exception != null) + if (this.Exception != null) { DebugHelper.WriteLogEx("error happened", 0); if (this.Cmdlet != null) @@ -285,14 +269,14 @@ private void WaitForAckMessage() // throw terminating error ErrorRecord errorRecord = ErrorToErrorRecord.ErrorRecordFromAnyException( - new InvocationContext(this.TargetComputerName, null), this.exception, null); + new InvocationContext(this.TargetComputerName, null), this.Exception, null); this.Cmdlet.ThrowTerminatingError(errorRecord); } else { DebugHelper.WriteLogEx("Throw exception", 1); // throw exception out - throw this.exception; + throw this.Exception; } } @@ -363,15 +347,7 @@ private CimSessionProxy CreateSessionProxy( /// /// Exception occurred while start the subscription. /// - internal Exception Exception - { - get - { - return exception; - } - } - - private Exception exception; + internal Exception Exception { get; private set; } #endregion diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimResultObserver.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimResultObserver.cs index 19040bfa3e4..72f14982f2e 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimResultObserver.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimResultObserver.cs @@ -37,21 +37,13 @@ internal class CimResultContext /// internal CimResultContext(object ErrorSource) { - this.errorSource = ErrorSource; + this.ErrorSource = ErrorSource; } /// /// ErrorSource property. /// - internal object ErrorSource - { - get - { - return this.errorSource; - } - } - - private readonly object errorSource; + internal object ErrorSource { get; } } #endregion @@ -228,7 +220,7 @@ internal class CimResultObserver : IObserver /// Operation that can be observed. public CimResultObserver(CimSession session, IObservable observable) { - this.session = session; + this.CurrentSession = session; this.observable = observable; } @@ -241,7 +233,7 @@ public CimResultObserver(CimSession session, IObservable observable, CimResultContext cimResultContext) { - this.session = session; + this.CurrentSession = session; this.observable = observable; this.context = cimResultContext; } @@ -260,7 +252,7 @@ public virtual void OnCompleted() try { AsyncResultCompleteEventArgs completeArgs = new( - this.session, this.observable); + this.CurrentSession, this.observable); this.OnNewResult(this, completeArgs); } catch (Exception ex) @@ -281,7 +273,7 @@ public virtual void OnError(Exception error) try { AsyncResultErrorEventArgs errorArgs = new( - this.session, this.observable, error, this.context); + this.CurrentSession, this.observable, error, this.context); this.OnNewResult(this, errorArgs); } catch (Exception ex) @@ -301,7 +293,7 @@ protected void OnNextCore(object value) try { AsyncResultObjectEventArgs resultArgs = new( - this.session, this.observable, value); + this.CurrentSession, this.observable, value); this.OnNewResult(this, resultArgs); } catch (Exception ex) @@ -334,15 +326,7 @@ public virtual void OnNext(T value) /// /// Session object of the operation. /// - protected CimSession CurrentSession - { - get - { - return session; - } - } - - private readonly CimSession session; + protected CimSession CurrentSession { get; } /// /// Async operation that can be observed. diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionOperations.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionOperations.cs index fb9626dd061..b746cfeb0dd 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionOperations.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionOperations.cs @@ -24,67 +24,27 @@ internal class CimSessionWrapper /// /// Id of the cimsession. /// - public uint SessionId - { - get - { - return this.sessionId; - } - } - - private readonly uint sessionId; + public uint SessionId { get; } /// /// InstanceId of the cimsession. /// - public Guid InstanceId - { - get - { - return this.instanceId; - } - } - - private readonly Guid instanceId; + public Guid InstanceId { get; } /// /// Name of the cimsession. /// - public string Name - { - get - { - return this.name; - } - } - - private readonly string name; + public string Name { get; } /// /// Computer name of the cimsession. /// - public string ComputerName - { - get - { - return this.computerName; - } - } - - private readonly string computerName; + public string ComputerName { get; } /// /// Wrapped cimsession object. /// - public CimSession CimSession - { - get - { - return this.cimSession; - } - } - - private readonly CimSession cimSession; + public CimSession CimSession { get; } /// /// Computer name of the cimsession. @@ -127,11 +87,11 @@ internal CimSessionWrapper( CimSession theCimSession, ProtocolType theProtocol) { - this.sessionId = theSessionId; - this.instanceId = theInstanceId; - this.name = theName; - this.computerName = theComputerName; - this.cimSession = theCimSession; + this.SessionId = theSessionId; + this.InstanceId = theInstanceId; + this.Name = theName; + this.ComputerName = theComputerName; + this.CimSession = theCimSession; this.psObject = null; this.protocol = theProtocol; } @@ -140,18 +100,18 @@ internal PSObject GetPSObject() { if (psObject == null) { - psObject = new PSObject(this.cimSession); - psObject.Properties.Add(new PSNoteProperty(CimSessionState.idPropName, this.sessionId)); - psObject.Properties.Add(new PSNoteProperty(CimSessionState.namePropName, this.name)); - psObject.Properties.Add(new PSNoteProperty(CimSessionState.instanceidPropName, this.instanceId)); + psObject = new PSObject(this.CimSession); + psObject.Properties.Add(new PSNoteProperty(CimSessionState.idPropName, this.SessionId)); + psObject.Properties.Add(new PSNoteProperty(CimSessionState.namePropName, this.Name)); + psObject.Properties.Add(new PSNoteProperty(CimSessionState.instanceidPropName, this.InstanceId)); psObject.Properties.Add(new PSNoteProperty(CimSessionState.computernamePropName, this.ComputerName)); psObject.Properties.Add(new PSNoteProperty(CimSessionState.protocolPropName, this.Protocol)); } else { psObject.Properties[CimSessionState.idPropName].Value = this.SessionId; - psObject.Properties[CimSessionState.namePropName].Value = this.name; - psObject.Properties[CimSessionState.instanceidPropName].Value = this.instanceId; + psObject.Properties[CimSessionState.namePropName].Value = this.Name; + psObject.Properties[CimSessionState.instanceidPropName].Value = this.InstanceId; psObject.Properties[CimSessionState.computernamePropName].Value = this.ComputerName; psObject.Properties[CimSessionState.protocolPropName].Value = this.Protocol; } @@ -919,22 +879,14 @@ internal CimTestCimSessionContext( CimSessionWrapper wrapper) { this.proxy = theProxy; - this.cimSessionWrapper = wrapper; + this.CimSessionWrapper = wrapper; this.nameSpace = null; } /// /// Namespace /// - internal CimSessionWrapper CimSessionWrapper - { - get - { - return this.cimSessionWrapper; - } - } - - private readonly CimSessionWrapper cimSessionWrapper; + internal CimSessionWrapper CimSessionWrapper { get; } } /// @@ -945,7 +897,7 @@ internal CimSessionWrapper CimSessionWrapper internal CimNewSession() : base() { this.cimTestSession = new CimTestSession(); - this._disposed = false; + this.Disposed = false; } /// @@ -1062,15 +1014,7 @@ public void ProcessRemainActions(CmdletOperationBase cmdletOperation) /// Indicates whether this object was disposed or not. /// /// - protected bool Disposed - { - get - { - return _disposed; - } - } - - private bool _disposed; + protected bool Disposed { get; private set; } /// /// @@ -1104,13 +1048,13 @@ public void Dispose() /// Whether it is directly called. protected virtual void Dispose(bool disposing) { - if (!this._disposed) + if (!this.Disposed) { if (disposing) { // free managed resources this.cimTestSession.Dispose(); - this._disposed = true; + this.Disposed = true; } // free native resources if there are any } diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs index ec0ac65eab3..45c04c37e55 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs @@ -325,7 +325,7 @@ public CimSessionProxy(CimSessionProxy proxy) DebugHelper.WriteLogEx("protocol = {0}", 1, proxy.Protocol); CreateSetSession(null, proxy.CimSession, null, proxy.OperationOptions, proxy.IsTemporaryCimSession); - this.protocol = proxy.Protocol; + this.Protocol = proxy.Protocol; this.OperationTimeout = proxy.OperationTimeout; this.isDefaultSession = proxy.isDefaultSession; } @@ -463,19 +463,19 @@ private void CreateSetSession( } InitOption(operOptions); - this.protocol = ProtocolType.Wsman; - this.isTemporaryCimSession = temporaryCimSession; + this.Protocol = ProtocolType.Wsman; + this.IsTemporaryCimSession = temporaryCimSession; if (cimSession != null) { - this.session = cimSession; + this.CimSession = cimSession; CimSessionState state = CimSessionBase.GetCimSessionState(); if (state != null) { CimSessionWrapper wrapper = state.QuerySession(cimSession); if (wrapper != null) { - this.protocol = wrapper.GetProtocolType(); + this.Protocol = wrapper.GetProtocolType(); } } } @@ -486,29 +486,29 @@ private void CreateSetSession( if (sessionOptions is DComSessionOptions) { string defaultComputerName = ConstValue.IsDefaultComputerName(computerName) ? ConstValue.NullComputerName : computerName; - this.session = CimSession.Create(defaultComputerName, sessionOptions); - this.protocol = ProtocolType.Dcom; + this.CimSession = CimSession.Create(defaultComputerName, sessionOptions); + this.Protocol = ProtocolType.Dcom; } else { - this.session = CimSession.Create(computerName, sessionOptions); + this.CimSession = CimSession.Create(computerName, sessionOptions); } } else { - this.session = CreateCimSessionByComputerName(computerName); + this.CimSession = CreateCimSessionByComputerName(computerName); } - this.isTemporaryCimSession = true; + this.IsTemporaryCimSession = true; } - if (this.isTemporaryCimSession) + if (this.IsTemporaryCimSession) { - AddCimSessionToTemporaryCache(this.session); + AddCimSessionToTemporaryCache(this.CimSession); } this.invocationContextObject = new InvocationContext(this); - DebugHelper.WriteLog("Protocol {0}, Is temporary session ? {1}", 1, this.protocol, this.isTemporaryCimSession); + DebugHelper.WriteLog("Protocol {0}, Is temporary session ? {1}", 1, this.Protocol, this.IsTemporaryCimSession); } #endregion @@ -522,14 +522,14 @@ public UInt32 OperationTimeout { get { - return (UInt32)this.options.Timeout.TotalSeconds; + return (UInt32)this.OperationOptions.Timeout.TotalSeconds; } set { DebugHelper.WriteLogEx("OperationTimeout {0},", 0, value); - this.options.Timeout = TimeSpan.FromSeconds((double)value); + this.OperationOptions.Timeout = TimeSpan.FromSeconds((double)value); } } @@ -540,14 +540,14 @@ public Uri ResourceUri { get { - return this.options.ResourceUri; + return this.OperationOptions.ResourceUri; } set { DebugHelper.WriteLogEx("ResourceUri {0},", 0, value); - this.options.ResourceUri = value; + this.OperationOptions.ResourceUri = value; } } @@ -559,13 +559,13 @@ public bool EnableMethodResultStreaming { get { - return this.options.EnableMethodResultStreaming; + return this.OperationOptions.EnableMethodResultStreaming; } set { DebugHelper.WriteLogEx("EnableMethodResultStreaming {0}", 0, value); - this.options.EnableMethodResultStreaming = value; + this.OperationOptions.EnableMethodResultStreaming = value; } } @@ -580,7 +580,7 @@ public bool EnablePromptUser DebugHelper.WriteLogEx("EnablePromptUser {0}", 0, value); if (value) { - this.options.PromptUser = this.PromptUser; + this.OperationOptions.PromptUser = this.PromptUser; } } } @@ -594,15 +594,15 @@ private void EnablePSSemantics() // this.options.PromptUserForceFlag... // this.options.WriteErrorMode - this.options.WriteErrorMode = CimCallbackMode.Inquire; + this.OperationOptions.WriteErrorMode = CimCallbackMode.Inquire; // !!!NOTES: Does not subscribe to PromptUser for CimCmdlets now // since cmdlet does not provider an approach // to let user select how to handle prompt message // this can be enabled later if needed. - this.options.WriteError = this.WriteError; - this.options.WriteMessage = this.WriteMessage; - this.options.WriteProgress = this.WriteProgress; + this.OperationOptions.WriteError = this.WriteError; + this.OperationOptions.WriteMessage = this.WriteMessage; + this.OperationOptions.WriteProgress = this.WriteProgress; } /// @@ -610,7 +610,7 @@ private void EnablePSSemantics() /// public SwitchParameter KeyOnly { - set { this.options.KeysOnly = value.IsPresent; } + set { this.OperationOptions.KeysOnly = value.IsPresent; } } /// @@ -622,11 +622,11 @@ public SwitchParameter Shallow { if (value.IsPresent) { - this.options.Flags = CimOperationFlags.PolymorphismShallow; + this.OperationOptions.Flags = CimOperationFlags.PolymorphismShallow; } else { - this.options.Flags = CimOperationFlags.None; + this.OperationOptions.Flags = CimOperationFlags.None; } } } @@ -640,11 +640,11 @@ private void InitOption(CimOperationOptions operOptions) if (operOptions != null) { - this.options = new CimOperationOptions(operOptions); + this.OperationOptions = new CimOperationOptions(operOptions); } - else if (this.options == null) + else if (this.OperationOptions == null) { - this.options = new CimOperationOptions(); + this.OperationOptions = new CimOperationOptions(); } this.EnableMethodResultStreaming = true; @@ -665,10 +665,10 @@ public CimSession Detach() DebugHelper.WriteLogEx(); // Remove the CimSession from cache but don't dispose it - RemoveCimSessionFromTemporaryCache(this.session, false); - CimSession sessionToReturn = this.session; - this.session = null; - this.isTemporaryCimSession = false; + RemoveCimSessionFromTemporaryCache(this.CimSession, false); + CimSession sessionToReturn = this.CimSession; + this.CimSession = null; + this.IsTemporaryCimSession = false; return sessionToReturn; } @@ -707,7 +707,7 @@ private void RemoveOperation(IObservable operation) this.operation = null; } - if (this.session != null && this.ContextObject == null) + if (this.CimSession != null && this.ContextObject == null) { DebugHelper.WriteLog("Dispose this proxy object @ RemoveOperation"); this.Dispose(); @@ -734,7 +734,7 @@ protected void FireNewActionEvent(CimBaseAction action) EventHandler temp = this.OnNewCmdletAction; if (temp != null) { - temp(this.session, actionArgs); + temp(this.CimSession, actionArgs); } else { @@ -759,7 +759,7 @@ private void FireOperationCreatedEvent( OperationEventArgs args = new( cancelOperation, operation, false); - this.OnOperationCreated?.Invoke(this.session, args); + this.OnOperationCreated?.Invoke(this.CimSession, args); this.PostOperationCreateEvent(args); } @@ -779,7 +779,7 @@ private void FireOperationDeletedEvent( OperationEventArgs args = new( null, operation, success); PreOperationDeleteEvent(args); - this.OnOperationDeleted?.Invoke(this.session, args); + this.OnOperationDeleted?.Invoke(this.CimSession, args); this.PostOperationDeleteEvent(args); this.RemoveOperation(operation); @@ -1065,15 +1065,15 @@ private object PostProcessCimInstance(object resultObject) public void CreateInstanceAsync(string namespaceName, CimInstance instance) { Debug.Assert(instance != null, "Caller should verify that instance != NULL."); - DebugHelper.WriteLogEx("EnableMethodResultStreaming = {0}", 0, this.options.EnableMethodResultStreaming); + DebugHelper.WriteLogEx("EnableMethodResultStreaming = {0}", 0, this.OperationOptions.EnableMethodResultStreaming); this.CheckAvailability(); - this.targetCimInstance = instance; + this.TargetCimInstance = instance; this.operationName = CimCmdletStrings.CimOperationNameCreateInstance; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); this.operationParameters.Add(@"instance", instance); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - CimAsyncResult asyncResult = this.session.CreateInstanceAsync(namespaceName, instance, this.options); + CimAsyncResult asyncResult = this.CimSession.CreateInstanceAsync(namespaceName, instance, this.OperationOptions); ConsumeCimInstanceAsync(asyncResult, new CimResultContext(instance)); } @@ -1087,13 +1087,13 @@ public void DeleteInstanceAsync(string namespaceName, CimInstance instance) Debug.Assert(instance != null, "Caller should verify that instance != NULL."); DebugHelper.WriteLogEx("namespace = {0}; classname = {1};", 0, namespaceName, instance.CimSystemProperties.ClassName); this.CheckAvailability(); - this.targetCimInstance = instance; + this.TargetCimInstance = instance; this.operationName = CimCmdletStrings.CimOperationNameDeleteInstance; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); this.operationParameters.Add(@"instance", instance); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - CimAsyncStatus asyncResult = this.session.DeleteInstanceAsync(namespaceName, instance, this.options); + CimAsyncStatus asyncResult = this.CimSession.DeleteInstanceAsync(namespaceName, instance, this.OperationOptions); ConsumeObjectAsync(asyncResult, new CimResultContext(instance)); } @@ -1105,15 +1105,15 @@ public void DeleteInstanceAsync(string namespaceName, CimInstance instance) public void GetInstanceAsync(string namespaceName, CimInstance instance) { Debug.Assert(instance != null, "Caller should verify that instance != NULL."); - DebugHelper.WriteLogEx("namespace = {0}; classname = {1}; keyonly = {2}", 0, namespaceName, instance.CimSystemProperties.ClassName, this.options.KeysOnly); + DebugHelper.WriteLogEx("namespace = {0}; classname = {1}; keyonly = {2}", 0, namespaceName, instance.CimSystemProperties.ClassName, this.OperationOptions.KeysOnly); this.CheckAvailability(); - this.targetCimInstance = instance; + this.TargetCimInstance = instance; this.operationName = CimCmdletStrings.CimOperationNameGetInstance; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); this.operationParameters.Add(@"instance", instance); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - CimAsyncResult asyncResult = this.session.GetInstanceAsync(namespaceName, instance, this.options); + CimAsyncResult asyncResult = this.CimSession.GetInstanceAsync(namespaceName, instance, this.OperationOptions); ConsumeCimInstanceAsync(asyncResult, new CimResultContext(instance)); } @@ -1127,13 +1127,13 @@ public void ModifyInstanceAsync(string namespaceName, CimInstance instance) Debug.Assert(instance != null, "Caller should verify that instance != NULL."); DebugHelper.WriteLogEx("namespace = {0}; classname = {1}", 0, namespaceName, instance.CimSystemProperties.ClassName); this.CheckAvailability(); - this.targetCimInstance = instance; + this.TargetCimInstance = instance; this.operationName = CimCmdletStrings.CimOperationNameModifyInstance; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); this.operationParameters.Add(@"instance", instance); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - CimAsyncResult asyncResult = this.session.ModifyInstanceAsync(namespaceName, instance, this.options); + CimAsyncResult asyncResult = this.CimSession.ModifyInstanceAsync(namespaceName, instance, this.OperationOptions); ConsumeObjectAsync(asyncResult, new CimResultContext(instance)); } @@ -1158,7 +1158,7 @@ public void EnumerateAssociatedInstancesAsync( Debug.Assert(sourceInstance != null, "Caller should verify that sourceInstance != NULL."); DebugHelper.WriteLogEx("Instance class {0}, association class {1}", 0, sourceInstance.CimSystemProperties.ClassName, associationClassName); this.CheckAvailability(); - this.targetCimInstance = sourceInstance; + this.TargetCimInstance = sourceInstance; this.operationName = CimCmdletStrings.CimOperationNameEnumerateAssociatedInstances; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); @@ -1168,7 +1168,7 @@ public void EnumerateAssociatedInstancesAsync( this.operationParameters.Add(@"sourceRole", sourceRole); this.operationParameters.Add(@"resultRole", resultRole); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - CimAsyncMultipleResults asyncResult = this.session.EnumerateAssociatedInstancesAsync(namespaceName, sourceInstance, associationClassName, resultClassName, sourceRole, resultRole, this.options); + CimAsyncMultipleResults asyncResult = this.CimSession.EnumerateAssociatedInstancesAsync(namespaceName, sourceInstance, associationClassName, resultClassName, sourceRole, resultRole, this.OperationOptions); ConsumeCimInstanceAsync(asyncResult, new CimResultContext(sourceInstance)); } @@ -1179,15 +1179,15 @@ public void EnumerateAssociatedInstancesAsync( /// public void EnumerateInstancesAsync(string namespaceName, string className) { - DebugHelper.WriteLogEx("KeyOnly {0}", 0, this.options.KeysOnly); + DebugHelper.WriteLogEx("KeyOnly {0}", 0, this.OperationOptions.KeysOnly); this.CheckAvailability(); - this.targetCimInstance = null; + this.TargetCimInstance = null; this.operationName = CimCmdletStrings.CimOperationNameEnumerateInstances; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); this.operationParameters.Add(@"className", className); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - CimAsyncMultipleResults asyncResult = this.session.EnumerateInstancesAsync(namespaceName, className, this.options); + CimAsyncMultipleResults asyncResult = this.CimSession.EnumerateInstancesAsync(namespaceName, className, this.OperationOptions); string errorSource = string.Format(CultureInfo.CurrentUICulture, "{0}:{1}", namespaceName, className); ConsumeCimInstanceAsync(asyncResult, new CimResultContext(errorSource)); } @@ -1224,16 +1224,16 @@ public void QueryInstancesAsync( string queryDialect, string queryExpression) { - DebugHelper.WriteLogEx("KeyOnly = {0}", 0, this.options.KeysOnly); + DebugHelper.WriteLogEx("KeyOnly = {0}", 0, this.OperationOptions.KeysOnly); this.CheckAvailability(); - this.targetCimInstance = null; + this.TargetCimInstance = null; this.operationName = CimCmdletStrings.CimOperationNameQueryInstances; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); this.operationParameters.Add(@"queryDialect", queryDialect); this.operationParameters.Add(@"queryExpression", queryExpression); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - CimAsyncMultipleResults asyncResult = this.session.QueryInstancesAsync(namespaceName, queryDialect, queryExpression, this.options); + CimAsyncMultipleResults asyncResult = this.CimSession.QueryInstancesAsync(namespaceName, queryDialect, queryExpression, this.OperationOptions); ConsumeCimInstanceAsync(asyncResult, null); } @@ -1246,12 +1246,12 @@ public void EnumerateClassesAsync(string namespaceName) { DebugHelper.WriteLogEx("namespace {0}", 0, namespaceName); this.CheckAvailability(); - this.targetCimInstance = null; + this.TargetCimInstance = null; this.operationName = CimCmdletStrings.CimOperationNameEnumerateClasses; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - CimAsyncMultipleResults asyncResult = this.session.EnumerateClassesAsync(namespaceName, null, this.options); + CimAsyncMultipleResults asyncResult = this.CimSession.EnumerateClassesAsync(namespaceName, null, this.OperationOptions); ConsumeCimClassAsync(asyncResult, null); } @@ -1263,13 +1263,13 @@ public void EnumerateClassesAsync(string namespaceName) public void EnumerateClassesAsync(string namespaceName, string className) { this.CheckAvailability(); - this.targetCimInstance = null; + this.TargetCimInstance = null; this.operationName = CimCmdletStrings.CimOperationNameEnumerateClasses; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); this.operationParameters.Add(@"className", className); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - CimAsyncMultipleResults asyncResult = this.session.EnumerateClassesAsync(namespaceName, className, this.options); + CimAsyncMultipleResults asyncResult = this.CimSession.EnumerateClassesAsync(namespaceName, className, this.OperationOptions); string errorSource = string.Format(CultureInfo.CurrentUICulture, "{0}:{1}", namespaceName, className); ConsumeCimClassAsync(asyncResult, new CimResultContext(errorSource)); } @@ -1283,13 +1283,13 @@ public void GetClassAsync(string namespaceName, string className) { DebugHelper.WriteLogEx("namespace = {0}, className = {1}", 0, namespaceName, className); this.CheckAvailability(); - this.targetCimInstance = null; + this.TargetCimInstance = null; this.operationName = CimCmdletStrings.CimOperationNameGetClass; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); this.operationParameters.Add(@"className", className); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - CimAsyncResult asyncResult = this.session.GetClassAsync(namespaceName, className, this.options); + CimAsyncResult asyncResult = this.CimSession.GetClassAsync(namespaceName, className, this.OperationOptions); string errorSource = string.Format(CultureInfo.CurrentUICulture, "{0}:{1}", namespaceName, className); ConsumeCimClassAsync(asyncResult, new CimResultContext(errorSource)); } @@ -1308,16 +1308,16 @@ public void InvokeMethodAsync( CimMethodParametersCollection methodParameters) { Debug.Assert(instance != null, "Caller should verify that instance != NULL."); - DebugHelper.WriteLogEx("EnableMethodResultStreaming = {0}", 0, this.options.EnableMethodResultStreaming); + DebugHelper.WriteLogEx("EnableMethodResultStreaming = {0}", 0, this.OperationOptions.EnableMethodResultStreaming); this.CheckAvailability(); - this.targetCimInstance = instance; + this.TargetCimInstance = instance; this.operationName = CimCmdletStrings.CimOperationNameInvokeMethod; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); this.operationParameters.Add(@"instance", instance); this.operationParameters.Add(@"methodName", methodName); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - CimAsyncMultipleResults asyncResult = this.session.InvokeMethodAsync(namespaceName, instance, methodName, methodParameters, this.options); + CimAsyncMultipleResults asyncResult = this.CimSession.InvokeMethodAsync(namespaceName, instance, methodName, methodParameters, this.OperationOptions); ConsumeCimInvokeMethodResultAsync(asyncResult, instance.CimSystemProperties.ClassName, methodName, new CimResultContext(instance)); } @@ -1334,16 +1334,16 @@ public void InvokeMethodAsync( string methodName, CimMethodParametersCollection methodParameters) { - DebugHelper.WriteLogEx("EnableMethodResultStreaming = {0}", 0, this.options.EnableMethodResultStreaming); + DebugHelper.WriteLogEx("EnableMethodResultStreaming = {0}", 0, this.OperationOptions.EnableMethodResultStreaming); this.CheckAvailability(); - this.targetCimInstance = null; + this.TargetCimInstance = null; this.operationName = CimCmdletStrings.CimOperationNameInvokeMethod; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); this.operationParameters.Add(@"className", className); this.operationParameters.Add(@"methodName", methodName); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - CimAsyncMultipleResults asyncResult = this.session.InvokeMethodAsync(namespaceName, className, methodName, methodParameters, this.options); + CimAsyncMultipleResults asyncResult = this.CimSession.InvokeMethodAsync(namespaceName, className, methodName, methodParameters, this.OperationOptions); string errorSource = string.Format(CultureInfo.CurrentUICulture, "{0}:{1}", namespaceName, className); ConsumeCimInvokeMethodResultAsync(asyncResult, className, methodName, new CimResultContext(errorSource)); } @@ -1363,7 +1363,7 @@ public void SubscribeAsync( { DebugHelper.WriteLogEx("QueryDialect = '{0}'; queryExpression = '{1}'", 0, queryDialect, queryExpression); this.CheckAvailability(); - this.targetCimInstance = null; + this.TargetCimInstance = null; this.operationName = CimCmdletStrings.CimOperationNameSubscribeIndication; this.operationParameters.Clear(); this.operationParameters.Add(@"namespaceName", namespaceName); @@ -1371,8 +1371,8 @@ public void SubscribeAsync( this.operationParameters.Add(@"queryExpression", queryExpression); this.WriteOperationStartMessage(this.operationName, this.operationParameters); - this.options.Flags |= CimOperationFlags.ReportOperationStarted; - CimAsyncMultipleResults asyncResult = this.session.SubscribeAsync(namespaceName, queryDialect, queryExpression, this.options); + this.OperationOptions.Flags |= CimOperationFlags.ReportOperationStarted; + CimAsyncMultipleResults asyncResult = this.CimSession.SubscribeAsync(namespaceName, queryDialect, queryExpression, this.OperationOptions); ConsumeCimSubscriptionResultAsync(asyncResult, null); } @@ -1385,8 +1385,8 @@ public void TestConnectionAsync() { DebugHelper.WriteLogEx("Start test connection", 0); this.CheckAvailability(); - this.targetCimInstance = null; - CimAsyncResult asyncResult = this.session.TestConnectionAsync(); + this.TargetCimInstance = null; + CimAsyncResult asyncResult = this.CimSession.TestConnectionAsync(); // ignore the test connection result objects ConsumeCimInstanceAsync(asyncResult, true, null); } @@ -1451,42 +1451,15 @@ protected virtual void PostOperationDeleteEvent(OperationEventArgs args) /// The session will be closed while disposing this proxy object /// if it is created by constuctor. /// - internal CimSession CimSession - { - get - { - return this.session; - } - } - - private CimSession session; + internal CimSession CimSession { get; private set; } /// /// The current CimInstance object, against which issued /// current operation, it could be null. /// - internal CimInstance TargetCimInstance - { - get - { - return this.targetCimInstance; - } - } + internal CimInstance TargetCimInstance { get; private set; } = null; - private CimInstance targetCimInstance = null; - - /// - /// Flag controls whether session object should be closed or not. - /// - private bool isTemporaryCimSession; - - internal bool IsTemporaryCimSession - { - get - { - return isTemporaryCimSession; - } - } + internal bool IsTemporaryCimSession { get; private set; } /// /// The CimOperationOptions object, which specifies the options @@ -1496,15 +1469,7 @@ internal bool IsTemporaryCimSession /// The setting MUST be set before start new operation on the /// this proxy object. /// - internal CimOperationOptions OperationOptions - { - get - { - return this.options; - } - } - - private CimOperationOptions options; + internal CimOperationOptions OperationOptions { get; private set; } /// /// All operations completed. @@ -1584,33 +1549,12 @@ private IDisposable CancelOperation /// Current protocol name /// DCOM or WSMAN. /// - internal ProtocolType Protocol - { - get - { - return protocol; - } - } - - private ProtocolType protocol; + internal ProtocolType Protocol { get; private set; } /// /// Cross operation context object. /// - internal XOperationContextBase ContextObject - { - get - { - return this.contextObject; - } - - set - { - this.contextObject = value; - } - } - - private XOperationContextBase contextObject; + internal XOperationContextBase ContextObject { get; set; } /// /// Invocation context object. @@ -1621,20 +1565,7 @@ internal XOperationContextBase ContextObject /// A preprocess object to pre-processing the result object, /// for example, adding PSTypeName, etc. /// - internal IObjectPreProcess ObjectPreProcess - { - get - { - return this.objectPreprocess; - } - - set - { - this.objectPreprocess = value; - } - } - - private IObjectPreProcess objectPreprocess; + internal IObjectPreProcess ObjectPreProcess { get; set; } /// /// is true if this was @@ -1684,10 +1615,10 @@ protected virtual void Dispose(bool disposing) // Dispose managed resources. this.DisposeCancelOperation(); - if (this.options != null) + if (this.OperationOptions != null) { - this.options.Dispose(); - this.options = null; + this.OperationOptions.Dispose(); + this.OperationOptions = null; } DisposeTemporaryCimSession(); @@ -1710,12 +1641,12 @@ public bool IsDisposed /// private void DisposeTemporaryCimSession() { - if (this.isTemporaryCimSession && this.session != null) + if (this.IsTemporaryCimSession && this.CimSession != null) { // remove the cimsession from temporary cache - RemoveCimSessionFromTemporaryCache(this.session); - this.isTemporaryCimSession = false; - this.session = null; + RemoveCimSessionFromTemporaryCache(this.CimSession); + this.IsTemporaryCimSession = false; + this.CimSession = null; } } #endregion @@ -1751,11 +1682,11 @@ protected void ConsumeCimInstanceAsync( CimResultObserver observer; if (ignoreResultObjects) { - observer = new IgnoreResultObserver(this.session, asyncResult); + observer = new IgnoreResultObserver(this.CimSession, asyncResult); } else { - observer = new CimResultObserver(this.session, asyncResult, cimResultContext); + observer = new CimResultObserver(this.CimSession, asyncResult, cimResultContext); } observer.OnNewResult += this.ResultEventHandler; @@ -1776,7 +1707,7 @@ protected void ConsumeObjectAsync(IObservable asyncResult, CimResultContext cimResultContext) { CimResultObserver observer = new( - this.session, asyncResult, cimResultContext); + this.CimSession, asyncResult, cimResultContext); observer.OnNewResult += this.ResultEventHandler; this.operationID = Interlocked.Increment(ref gOperationCounter); @@ -1797,7 +1728,7 @@ protected void ConsumeCimClassAsync(IObservable asyncResult, CimResultContext cimResultContext) { CimResultObserver observer = new( - this.session, asyncResult, cimResultContext); + this.CimSession, asyncResult, cimResultContext); observer.OnNewResult += this.ResultEventHandler; this.operationID = Interlocked.Increment(ref gOperationCounter); @@ -1818,7 +1749,7 @@ protected void ConsumeCimSubscriptionResultAsync( CimResultContext cimResultContext) { CimSubscriptionResultObserver observer = new( - this.session, asyncResult, cimResultContext); + this.CimSession, asyncResult, cimResultContext); observer.OnNewResult += this.ResultEventHandler; this.operationID = Interlocked.Increment(ref gOperationCounter); this.AddOperation(asyncResult); @@ -1841,7 +1772,7 @@ protected void ConsumeCimInvokeMethodResultAsync( string methodName, CimResultContext cimResultContext) { - CimMethodResultObserver observer = new(this.session, asyncResult, cimResultContext) + CimMethodResultObserver observer = new(this.CimSession, asyncResult, cimResultContext) { ClassName = className, MethodName = methodName @@ -1872,7 +1803,7 @@ private void CheckAvailability() } } - DebugHelper.WriteLog("KeyOnly {0},", 1, this.options.KeysOnly); + DebugHelper.WriteLog("KeyOnly {0},", 1, this.OperationOptions.KeysOnly); } /// @@ -1882,9 +1813,9 @@ private void CheckAvailability() /// private void AssertSession() { - if (this.IsDisposed || (this.session == null)) + if (this.IsDisposed || (this.CimSession == null)) { - DebugHelper.WriteLogEx("Invalid CimSessionProxy object, disposed? {0}; session object {1}", 1, this.IsDisposed, this.session); + DebugHelper.WriteLogEx("Invalid CimSessionProxy object, disposed? {0}; session object {1}", 1, this.IsDisposed, this.CimSession); throw new ObjectDisposedException(this.ToString()); } } @@ -1903,7 +1834,7 @@ private CimSession CreateCimSessionByComputerName(string computerName) if (option is DComSessionOptions) { DebugHelper.WriteLog("Create dcom cimSession"); - this.protocol = ProtocolType.Dcom; + this.Protocol = ProtocolType.Dcom; return CimSession.Create(ConstValue.NullComputerName, option); } else @@ -2176,7 +2107,7 @@ internal class CimSessionProxyNewCimInstance : CimSessionProxy public CimSessionProxyNewCimInstance(string computerName, CimNewCimInstance operation) : base(computerName) { - this.newCimInstance = operation; + this.NewCimInstanceOperation = operation; } /// @@ -2189,7 +2120,7 @@ public CimSessionProxyNewCimInstance(string computerName, CimNewCimInstance oper public CimSessionProxyNewCimInstance(CimSession session, CimNewCimInstance operation) : base(session) { - this.newCimInstance = operation; + this.NewCimInstanceOperation = operation; } #endregion @@ -2223,15 +2154,8 @@ protected override bool PreNewActionEvent(CmdletActionEventArgs args) #region private members - private readonly CimNewCimInstance newCimInstance = null; - internal CimNewCimInstance NewCimInstanceOperation - { - get - { - return this.newCimInstance; - } - } + internal CimNewCimInstance NewCimInstanceOperation { get; } = null; #endregion } diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSetCimInstance.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSetCimInstance.cs index 0a8c49dfb50..1ad72e46c79 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSetCimInstance.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSetCimInstance.cs @@ -33,50 +33,26 @@ internal CimSetCimInstanceContext(string theNamespace, bool passThru) { this.proxy = theProxy; - this.property = theProperty; + this.Property = theProperty; this.nameSpace = theNamespace; - this.parameterSetName = theParameterSetName; - this.passThru = passThru; + this.ParameterSetName = theParameterSetName; + this.PassThru = passThru; } /// /// property value /// - internal IDictionary Property - { - get - { - return this.property; - } - } - - private readonly IDictionary property; + internal IDictionary Property { get; } /// /// parameter set name /// - internal string ParameterSetName - { - get - { - return this.parameterSetName; - } - } - - private readonly string parameterSetName; + internal string ParameterSetName { get; } /// /// PassThru value /// - internal bool PassThru - { - get - { - return this.passThru; - } - } - - private readonly bool passThru; + internal bool PassThru { get; } } /// diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteError.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteError.cs index 0f64aad70c9..cf922aea143 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteError.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteError.cs @@ -322,8 +322,8 @@ internal sealed class CimWriteError : CimSyncAction /// public CimWriteError(CimInstance error, InvocationContext context) { - this.error = error; - this.invocationContext = context; + this.Error = error; + this.CimInvocationContext = context; } /// @@ -332,9 +332,9 @@ public CimWriteError(CimInstance error, InvocationContext context) /// public CimWriteError(Exception exception, InvocationContext context, CimResultContext cimResultContext) { - this.exception = exception; - this.invocationContext = context; - this.cimResultContext = cimResultContext; + this.Exception = exception; + this.CimInvocationContext = context; + this.ResultContext = cimResultContext; } /// @@ -348,10 +348,10 @@ public override void Execute(CmdletOperationBase cmdlet) Debug.Assert(cmdlet != null, "Caller should verify that cmdlet != null"); try { - Exception errorException = (error != null) ? new CimException(error) : this.Exception; + Exception errorException = (Error != null) ? new CimException(Error) : this.Exception; // PS engine takes care of handling error action - cmdlet.WriteError(ErrorToErrorRecord.ErrorRecordFromAnyException(this.invocationContext, errorException, this.cimResultContext)); + cmdlet.WriteError(ErrorToErrorRecord.ErrorRecordFromAnyException(this.CimInvocationContext, errorException, this.ResultContext)); // if user wants to continue, we will get here this.responseType = CimResponseType.Yes; @@ -375,59 +375,19 @@ public override void Execute(CmdletOperationBase cmdlet) /// Error instance /// /// - private readonly CimInstance error; - internal CimInstance Error - { - get - { - return error; - } - } + internal CimInstance Error { get; } /// /// /// Exception object /// /// - internal Exception Exception - { - get - { - return exception; - } - } - - private readonly Exception exception; + internal Exception Exception { get; } - /// - /// - /// object that contains - /// the information while issuing the current operation - /// - /// - private readonly InvocationContext invocationContext; + internal InvocationContext CimInvocationContext { get; } - internal InvocationContext CimInvocationContext - { - get - { - return invocationContext; - } - } - - /// - /// - /// - private readonly CimResultContext cimResultContext; - - internal CimResultContext ResultContext - { - get - { - return cimResultContext; - } - } + internal CimResultContext ResultContext { get; } #endregion } diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteMessage.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteMessage.cs index 9a556b68c5e..0b64f9b56a1 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteMessage.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteMessage.cs @@ -22,25 +22,13 @@ internal sealed class CimWriteMessage : CimBaseAction /// /// Channel id. /// - private readonly UInt32 channel; - - /// - /// Message to write to the channel. - /// - private readonly string message; #endregion #region Properties - internal UInt32 Channel - { - get { return channel; } - } + internal UInt32 Channel { get; } - internal string Message - { - get { return message; } - } + internal string Message { get; } #endregion @@ -50,8 +38,8 @@ internal string Message public CimWriteMessage(UInt32 channel, string message) { - this.channel = channel; - this.message = message; + this.Channel = channel; + this.Message = message; } /// @@ -64,16 +52,16 @@ public override void Execute(CmdletOperationBase cmdlet) { ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet"); - switch ((CimWriteMessageChannel)channel) + switch ((CimWriteMessageChannel)Channel) { case CimWriteMessageChannel.Verbose: - cmdlet.WriteVerbose(message); + cmdlet.WriteVerbose(Message); break; case CimWriteMessageChannel.Warning: - cmdlet.WriteWarning(message); + cmdlet.WriteWarning(Message); break; case CimWriteMessageChannel.Debug: - cmdlet.WriteDebug(message); + cmdlet.WriteDebug(Message); break; default: break; diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs index 94b82e47c29..927967608b3 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs @@ -43,20 +43,20 @@ public CimWriteProgress( UInt32 thePercentageCompleted, UInt32 theSecondsRemaining) { - this.activity = theActivity; + this.Activity = theActivity; this.activityID = theActivityID; - this.currentOperation = theCurrentOperation; + this.CurrentOperation = theCurrentOperation; if (string.IsNullOrEmpty(theStatusDescription)) { - this.statusDescription = CimCmdletStrings.DefaultStatusDescription; + this.StatusDescription = CimCmdletStrings.DefaultStatusDescription; } else { - this.statusDescription = theStatusDescription; + this.StatusDescription = theStatusDescription; } this.percentageCompleted = thePercentageCompleted; - this.secondsRemaining = theSecondsRemaining; + this.SecondsRemaining = theSecondsRemaining; } /// @@ -70,19 +70,19 @@ public override void Execute(CmdletOperationBase cmdlet) DebugHelper.WriteLog( "...Activity {0}: id={1}, remain seconds ={2}, percentage completed = {3}", 4, - this.activity, + this.Activity, this.activityID, - this.secondsRemaining, + this.SecondsRemaining, this.percentageCompleted); ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet"); ProgressRecord record = new( this.activityID, - this.activity, - this.statusDescription); - record.Activity = this.activity; + this.Activity, + this.StatusDescription); + record.Activity = this.Activity; record.ParentActivityId = 0; - record.SecondsRemaining = (int)this.secondsRemaining; + record.SecondsRemaining = (int)this.SecondsRemaining; record.PercentComplete = (int)this.percentageCompleted; cmdlet.WriteProgress(record); } @@ -92,62 +92,34 @@ public override void Execute(CmdletOperationBase cmdlet) /// /// Activity of the given activity. /// - private readonly string activity; /// /// Activity identifier of the given activity. /// private readonly int activityID; - /// - /// Current operation text of the given activity. - /// - private readonly string currentOperation; - - /// - /// Status description of the given activity. - /// - private readonly string statusDescription; - /// /// Percentage completed of the given activity. /// private readonly UInt32 percentageCompleted; - /// - /// How many seconds remained for the given activity. - /// - private readonly UInt32 secondsRemaining; - - internal string Activity - { - get { return activity; } - } + internal string Activity { get; } internal int ActivityID { get { return activityID; } } - internal string CurrentOperation - { - get { return currentOperation; } - } + internal string CurrentOperation { get; } - internal string StatusDescription - { - get { return statusDescription; } - } + internal string StatusDescription { get; } internal UInt32 PercentageCompleted { get { return percentageCompleted; } } - internal UInt32 SecondsRemaining - { - get { return secondsRemaining; } - } + internal UInt32 SecondsRemaining { get; } #endregion } diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteResultObject.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteResultObject.cs index 492819c6535..95bf7432291 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteResultObject.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteResultObject.cs @@ -19,7 +19,7 @@ internal sealed class CimWriteResultObject : CimBaseAction /// public CimWriteResultObject(object result, XOperationContextBase theContext) { - this.result = result; + this.Result = result; this.Context = theContext; } @@ -32,22 +32,14 @@ public CimWriteResultObject(object result, XOperationContextBase theContext) public override void Execute(CmdletOperationBase cmdlet) { ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet"); - cmdlet.WriteObject(result, this.Context); + cmdlet.WriteObject(Result, this.Context); } #region members /// /// Result object. /// - internal object Result - { - get - { - return result; - } - } - - private readonly object result; + internal object Result { get; } #endregion } } diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimAssociatedInstanceCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimAssociatedInstanceCommand.cs index a8a69e187a0..ace8d9ef563 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimAssociatedInstanceCommand.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimAssociatedInstanceCommand.cs @@ -53,14 +53,7 @@ public GetCimAssociatedInstanceCommand() [Parameter( Position = 1, ValueFromPipelineByPropertyName = true)] - public string Association - { - get { return association; } - - set { association = value; } - } - - private string association; + public string Association { get; set; } /// /// The following is the definition of the input parameter "ResultClassName". @@ -68,14 +61,7 @@ public string Association /// the given instance. /// [Parameter] - public string ResultClassName - { - get { return resultClassName; } - - set { resultClassName = value; } - } - - private string resultClassName; + public string ResultClassName { get; set; } /// /// @@ -90,11 +76,11 @@ public string ResultClassName [Alias(CimBaseCommand.AliasCimInstance)] public CimInstance InputObject { - get { return cimInstance; } + get { return CimInstance; } set { - cimInstance = value; + CimInstance = value; base.SetParameter(value, nameCimInstance); } } @@ -102,12 +88,7 @@ public CimInstance InputObject /// /// Property for internal usage purpose. /// - internal CimInstance CimInstance - { - get { return cimInstance; } - } - - private CimInstance cimInstance; + internal CimInstance CimInstance { get; private set; } /// /// The following is the definition of the input parameter "Namespace". @@ -115,14 +96,7 @@ internal CimInstance CimInstance /// is registered. /// [Parameter(ValueFromPipelineByPropertyName = true)] - public string Namespace - { - get { return nameSpace; } - - set { nameSpace = value; } - } - - private string nameSpace; + public string Namespace { get; set; } /// /// The following is the definition of the input parameter "OperationTimeoutSec". @@ -133,14 +107,7 @@ public string Namespace /// [Alias(AliasOT)] [Parameter(ValueFromPipelineByPropertyName = true)] - public UInt32 OperationTimeoutSec - { - get { return operationTimeout; } - - set { operationTimeout = value; } - } - - private UInt32 operationTimeout; + public UInt32 OperationTimeoutSec { get; set; } /// /// @@ -220,14 +187,7 @@ public Microsoft.Management.Infrastructure.CimSession[] CimSession /// /// [Parameter] - public SwitchParameter KeyOnly - { - get { return keyOnly; } - - set { keyOnly = value; } - } - - private SwitchParameter keyOnly; + public SwitchParameter KeyOnly { get; set; } #endregion diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimClassCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimClassCommand.cs index 30290a1f7ba..c80596ed7a1 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimClassCommand.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimClassCommand.cs @@ -54,14 +54,7 @@ public GetCimClassCommand() [Parameter( Position = 0, ValueFromPipelineByPropertyName = true)] - public string ClassName - { - get { return className; } - - set { className = value; } - } - - private string className; + public string ClassName { get; set; } /// /// @@ -77,14 +70,7 @@ public string ClassName [Parameter( Position = 1, ValueFromPipelineByPropertyName = true)] - public string Namespace - { - get { return nameSpace; } - - set { nameSpace = value; } - } - - private string nameSpace; + public string Namespace { get; set; } /// /// The following is the definition of the input parameter "OperationTimeoutSec". @@ -93,14 +79,7 @@ public string Namespace /// [Alias(AliasOT)] [Parameter(ValueFromPipelineByPropertyName = true)] - public UInt32 OperationTimeoutSec - { - get { return operationTimeout; } - - set { operationTimeout = value; } - } - - private UInt32 operationTimeout; + public UInt32 OperationTimeoutSec { get; set; } /// /// The following is the definition of the input parameter "Session". @@ -158,14 +137,7 @@ public string[] ComputerName /// /// [Parameter(ValueFromPipelineByPropertyName = true)] - public string MethodName - { - get { return methodName; } - - set { methodName = value; } - } - - private string methodName; + public string MethodName { get; set; } /// /// @@ -175,14 +147,7 @@ public string MethodName /// /// [Parameter(ValueFromPipelineByPropertyName = true)] - public string PropertyName - { - get { return propertyName; } - - set { propertyName = value; } - } - - private string propertyName; + public string PropertyName { get; set; } /// /// @@ -192,14 +157,7 @@ public string PropertyName /// /// [Parameter(ValueFromPipelineByPropertyName = true)] - public string QualifierName - { - get { return qualifierName; } - - set { qualifierName = value; } - } - - private string qualifierName; + public string QualifierName { get; set; } #endregion diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimInstanceCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimInstanceCommand.cs index 0ed548da052..d22f8cdc693 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimInstanceCommand.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/GetCimInstanceCommand.cs @@ -241,14 +241,7 @@ public string Namespace /// [Alias(AliasOT)] [Parameter] - public UInt32 OperationTimeoutSec - { - get { return operationTimeout; } - - set { operationTimeout = value; } - } - - private UInt32 operationTimeout; + public UInt32 OperationTimeoutSec { get; set; } /// /// The following is the definition of the input parameter "InputObject". @@ -276,11 +269,11 @@ public UInt32 OperationTimeoutSec [Alias(CimBaseCommand.AliasCimInstance)] public CimInstance InputObject { - get { return cimInstance; } + get { return CimInstance; } set { - cimInstance = value; + CimInstance = value; base.SetParameter(value, nameCimInstance); } } @@ -288,12 +281,7 @@ public CimInstance InputObject /// /// Property for internal usage purpose. /// - internal CimInstance CimInstance - { - get { return cimInstance; } - } - - private CimInstance cimInstance; + internal CimInstance CimInstance { get; private set; } /// /// The following is the definition of the input parameter "Query". @@ -421,23 +409,18 @@ public string Filter [Alias("SelectProperties")] public string[] Property { - get { return property; } + get { return SelectProperties; } set { - property = value; + SelectProperties = value; base.SetParameter(value, nameSelectProperties); } } /// /// Property for internal usage. /// - internal string[] SelectProperties - { - get { return property; } - } - - private string[] property; + internal string[] SelectProperties { get; private set; } #endregion @@ -519,7 +502,7 @@ private void CheckArgument() case CimBaseCommand.ClassNameSessionSet: // validate the classname & property this.className = ValidationHelper.ValidateArgumentIsValidName(nameClassName, this.className); - this.property = ValidationHelper.ValidateArgumentIsValidName(nameSelectProperties, this.property); + this.SelectProperties = ValidationHelper.ValidateArgumentIsValidName(nameSelectProperties, this.SelectProperties); break; default: break; diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/InvokeCimMethodCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/InvokeCimMethodCommand.cs index 9e7c35d11b3..2c245b8d2b2 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/InvokeCimMethodCommand.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/InvokeCimMethodCommand.cs @@ -182,11 +182,11 @@ public string QueryDialect [Alias(CimBaseCommand.AliasCimInstance)] public CimInstance InputObject { - get { return cimInstance; } + get { return CimInstance; } set { - cimInstance = value; + CimInstance = value; base.SetParameter(value, nameCimInstance); } } @@ -194,12 +194,7 @@ public CimInstance InputObject /// /// Property for internal usage purpose. /// - internal CimInstance CimInstance - { - get { return cimInstance; } - } - - private CimInstance cimInstance; + internal CimInstance CimInstance { get; private set; } /// /// The following is the definition of the input parameter "ComputerName". @@ -287,14 +282,7 @@ public CimSession[] CimSession /// [Parameter(Position = 1, ValueFromPipelineByPropertyName = true)] [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] - public IDictionary Arguments - { - get { return arguments; } - - set { arguments = value; } - } - - private IDictionary arguments; + public IDictionary Arguments { get; set; } /// /// The following is the definition of the input parameter "MethodName". @@ -355,14 +343,7 @@ public string Namespace /// [Alias(AliasOT)] [Parameter] - public UInt32 OperationTimeoutSec - { - get { return operationTimeout; } - - set { operationTimeout = value; } - } - - private UInt32 operationTimeout; + public UInt32 OperationTimeoutSec { get; set; } #endregion diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimInstanceCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimInstanceCommand.cs index 7ceb91a5559..d524f6b5102 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimInstanceCommand.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimInstanceCommand.cs @@ -169,14 +169,7 @@ public CimClass CimClass ValueFromPipelineByPropertyName = true)] [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] [Alias("Arguments")] - public IDictionary Property - { - get { return property; } - - set { property = value; } - } - - private IDictionary property; + public IDictionary Property { get; set; } /// /// The following is the definition of the input parameter "Namespace". @@ -215,14 +208,7 @@ public string Namespace /// [Alias(AliasOT)] [Parameter] - public UInt32 OperationTimeoutSec - { - get { return operationTimeout; } - - set { operationTimeout = value; } - } - - private UInt32 operationTimeout; + public UInt32 OperationTimeoutSec { get; set; } /// /// diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionCommand.cs index 5d25ec5b0dc..d0431ccb860 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionCommand.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionCommand.cs @@ -52,14 +52,7 @@ public PasswordAuthenticationMechanism Authentication /// [Parameter(Position = 1, ParameterSetName = CredentialParameterSet)] [Credential()] - public PSCredential Credential - { - get { return credential; } - - set { credential = value; } - } - - private PSCredential credential; + public PSCredential Credential { get; set; } /// /// The following is the definition of the input parameter "CertificateThumbprint". @@ -67,14 +60,7 @@ public PSCredential Credential /// [Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = CertificateParameterSet)] - public string CertificateThumbprint - { - get { return certificatethumbprint; } - - set { certificatethumbprint = value; } - } - - private string certificatethumbprint; + public string CertificateThumbprint { get; set; } /// /// The following is the definition of the input parameter "ComputerName". @@ -87,14 +73,7 @@ public string CertificateThumbprint ValueFromPipelineByPropertyName = true)] [ValidateNotNullOrEmpty] [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] - public string[] ComputerName - { - get { return computername; } - - set { computername = value; } - } - - private string[] computername; + public string[] ComputerName { get; set; } /// /// @@ -108,14 +87,7 @@ public string[] ComputerName /// /// [Parameter(ValueFromPipelineByPropertyName = true)] - public string Name - { - get { return name; } - - set { name = value; } - } - - private string name; + public string Name { get; set; } /// /// @@ -150,17 +122,7 @@ public UInt32 OperationTimeoutSec /// /// [Parameter(ValueFromPipelineByPropertyName = true)] - public SwitchParameter SkipTestConnection - { - get { return skipTestConnection; } - - set - { - skipTestConnection = value; - } - } - - private SwitchParameter skipTestConnection; + public SwitchParameter SkipTestConnection { get; set; } /// /// The following is the definition of the input parameter "Port". @@ -196,14 +158,7 @@ public UInt32 Port /// object is passed, then connection is made using WsMan. /// [Parameter(ValueFromPipelineByPropertyName = true)] - public Microsoft.Management.Infrastructure.Options.CimSessionOptions SessionOption - { - get { return sessionOption; } - - set { sessionOption = value; } - } - - private Microsoft.Management.Infrastructure.Options.CimSessionOptions sessionOption; + public Microsoft.Management.Infrastructure.Options.CimSessionOptions SessionOption { get; set; } #endregion @@ -256,11 +211,11 @@ internal void BuildSessionOptions(out CimSessionOptions outputOptions, out CimCr // clone the sessionOption object if (this.SessionOption is WSManSessionOptions) { - options = new WSManSessionOptions(this.sessionOption as WSManSessionOptions); + options = new WSManSessionOptions(this.SessionOption as WSManSessionOptions); } else { - options = new DComSessionOptions(this.sessionOption as DComSessionOptions); + options = new DComSessionOptions(this.SessionOption as DComSessionOptions); } } @@ -319,7 +274,7 @@ internal void BuildSessionOptions(out CimSessionOptions outputOptions, out CimCr } } - if (this.authenticationSet || (this.credential != null)) + if (this.authenticationSet || (this.Credential != null)) { PasswordAuthenticationMechanism authentication = this.authenticationSet ? this.Authentication : PasswordAuthenticationMechanism.Default; if (this.authenticationSet) diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionOptionCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionOptionCommand.cs index ed80787e06f..063b477e2e7 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionOptionCommand.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/NewCimSessionOptionCommand.cs @@ -416,28 +416,14 @@ public ProtocolType Protocol /// Specifies the UI Culture to use. i.e. en-us, ar-sa. /// [Parameter(ValueFromPipelineByPropertyName = true)] - public CultureInfo UICulture - { - get { return uiculture; } - - set { uiculture = value; } - } - - private CultureInfo uiculture; + public CultureInfo UICulture { get; set; } /// /// The following is the definition of the input parameter "Culture". /// Specifies the culture to use. i.e. en-us, ar-sa. /// [Parameter(ValueFromPipelineByPropertyName = true)] - public CultureInfo Culture - { - get { return culture; } - - set { culture = value; } - } - - private CultureInfo culture; + public CultureInfo Culture { get; set; } #endregion diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs index 758296f7d56..159a75ed3ef 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/RegisterCimIndicationCommand.cs @@ -35,14 +35,7 @@ public class RegisterCimIndicationCommand : ObjectEventRegistrationBase /// /// [Parameter] - public string Namespace - { - get { return nameSpace; } - - set { nameSpace = value; } - } - - private string nameSpace; + public string Namespace { get; set; } /// /// The following is the definition of the input parameter "ClassName". @@ -122,14 +115,7 @@ public string QueryDialect /// [Alias(CimBaseCommand.AliasOT)] [Parameter] - public UInt32 OperationTimeoutSec - { - get { return operationTimeout; } - - set { operationTimeout = value; } - } - - private UInt32 operationTimeout; + public UInt32 OperationTimeoutSec { get; set; } /// /// The following is the definition of the input parameter "Session". diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/RemoveCimInstanceCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/RemoveCimInstanceCommand.cs index 2e258c3bf3f..113a31ba93f 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/RemoveCimInstanceCommand.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/RemoveCimInstanceCommand.cs @@ -142,14 +142,7 @@ public string Namespace /// [Alias(AliasOT)] [Parameter] - public UInt32 OperationTimeoutSec - { - get { return operationTimeout; } - - set { operationTimeout = value; } - } - - private UInt32 operationTimeout; + public UInt32 OperationTimeoutSec { get; set; } /// /// The following is the definition of the input parameter "InputObject". @@ -168,11 +161,11 @@ public UInt32 OperationTimeoutSec [Alias(CimBaseCommand.AliasCimInstance)] public CimInstance InputObject { - get { return cimInstance; } + get { return CimInstance; } set { - cimInstance = value; + CimInstance = value; base.SetParameter(value, nameCimInstance); } } @@ -180,12 +173,7 @@ public CimInstance InputObject /// /// Property for internal usage purpose. /// - internal CimInstance CimInstance - { - get { return cimInstance; } - } - - private CimInstance cimInstance; + internal CimInstance CimInstance { get; private set; } /// /// The following is the definition of the input parameter "Query". diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/SetCimInstanceCommand.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/SetCimInstanceCommand.cs index d5d6e831944..3e22eb9c6a5 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/SetCimInstanceCommand.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/SetCimInstanceCommand.cs @@ -139,14 +139,7 @@ public string Namespace /// [Alias(AliasOT)] [Parameter] - public UInt32 OperationTimeoutSec - { - get { return operationTimeout; } - - set { operationTimeout = value; } - } - - private UInt32 operationTimeout; + public UInt32 OperationTimeoutSec { get; set; } /// /// The following is the definition of the input parameter "InputObject". @@ -165,11 +158,11 @@ public UInt32 OperationTimeoutSec [Alias(CimBaseCommand.AliasCimInstance)] public CimInstance InputObject { - get { return cimInstance; } + get { return CimInstance; } set { - cimInstance = value; + CimInstance = value; base.SetParameter(value, nameCimInstance); } } @@ -177,12 +170,7 @@ public CimInstance InputObject /// /// Property for internal usage purpose. /// - internal CimInstance CimInstance - { - get { return cimInstance; } - } - - private CimInstance cimInstance; + internal CimInstance CimInstance { get; private set; } /// /// The following is the definition of the input parameter "Query". @@ -277,20 +265,7 @@ public IDictionary Property /// [Parameter] [ValidateNotNull] - public SwitchParameter PassThru - { - get - { - return this.passThru; - } - - set - { - this.passThru = value; - } - } - - private SwitchParameter passThru; + public SwitchParameter PassThru { get; set; } #endregion diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/Utils.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/Utils.cs index 4042f79f130..bab5c092894 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/Utils.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/Utils.cs @@ -138,31 +138,14 @@ internal static class DebugHelper /// /// Flag used to control generating log message into file. /// - private static bool generateLog = true; - - internal static bool GenerateLog - { - get { return generateLog; } - - set { generateLog = value; } - } + internal static bool GenerateLog { get; set; } = true; /// /// Whether the log been initialized. /// private static bool logInitialized = false; - /// - /// Flag used to control generating message into powershell. - /// - private static bool generateVerboseMessage = true; - - internal static bool GenerateVerboseMessage - { - get { return generateVerboseMessage; } - - set { generateVerboseMessage = value; } - } + internal static bool GenerateVerboseMessage { get; set; } = true; /// /// Flag used to control generating message into powershell. @@ -337,7 +320,7 @@ private static void WriteLogInternal(string message, int indent, int depth) } } - if (generateLog) + if (GenerateLog) { if (indent < 0) { From f6e5d19a63ab63f88e1307ebb5f2c7c45582f15a Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Mon, 23 Nov 2020 17:40:06 +0000 Subject: [PATCH 2/3] Fix SA1507 --- .../CimSessionProxy.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs index 45c04c37e55..6ec54a551f3 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs @@ -2154,7 +2154,6 @@ protected override bool PreNewActionEvent(CmdletActionEventArgs args) #region private members - internal CimNewCimInstance NewCimInstanceOperation { get; } = null; #endregion From 9b0609e0c5e6c2a457adf2a8c078e17e6226fab4 Mon Sep 17 00:00:00 2001 From: xtqqczze Date: Tue, 24 Nov 2020 08:55:07 +0000 Subject: [PATCH 3/3] Fixes * Address @iSazonov review. * Convert some missed cases --- .../CimWriteProgress.cs | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs index 927967608b3..bda41668b80 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimWriteProgress.cs @@ -44,7 +44,7 @@ public CimWriteProgress( UInt32 theSecondsRemaining) { this.Activity = theActivity; - this.activityID = theActivityID; + this.ActivityID = theActivityID; this.CurrentOperation = theCurrentOperation; if (string.IsNullOrEmpty(theStatusDescription)) { @@ -55,7 +55,7 @@ public CimWriteProgress( this.StatusDescription = theStatusDescription; } - this.percentageCompleted = thePercentageCompleted; + this.PercentageCompleted = thePercentageCompleted; this.SecondsRemaining = theSecondsRemaining; } @@ -71,54 +71,52 @@ public override void Execute(CmdletOperationBase cmdlet) "...Activity {0}: id={1}, remain seconds ={2}, percentage completed = {3}", 4, this.Activity, - this.activityID, + this.ActivityID, this.SecondsRemaining, - this.percentageCompleted); + this.PercentageCompleted); ValidationHelper.ValidateNoNullArgument(cmdlet, "cmdlet"); ProgressRecord record = new( - this.activityID, + this.ActivityID, this.Activity, this.StatusDescription); record.Activity = this.Activity; record.ParentActivityId = 0; record.SecondsRemaining = (int)this.SecondsRemaining; - record.PercentComplete = (int)this.percentageCompleted; + record.PercentComplete = (int)this.PercentageCompleted; cmdlet.WriteProgress(record); } #region members /// - /// Activity of the given activity. + /// Gets the activity of the given activity. /// + internal string Activity { get; } /// - /// Activity identifier of the given activity. + /// Gets the activity identifier of the given activity. /// - private readonly int activityID; + internal int ActivityID { get; } /// - /// Percentage completed of the given activity. + /// Gets the current operation text of the given activity. /// - private readonly UInt32 percentageCompleted; - - internal string Activity { get; } - - internal int ActivityID - { - get { return activityID; } - } - internal string CurrentOperation { get; } + /// + /// Gets the status description of the given activity. + /// internal string StatusDescription { get; } - internal UInt32 PercentageCompleted - { - get { return percentageCompleted; } - } + /// + /// Gets the percentage completed of the given activity. + /// + internal UInt32 PercentageCompleted { get; } + /// + /// Gets the number of seconds remaining for the given activity. + /// internal UInt32 SecondsRemaining { get; } #endregion