diff --git a/src/Microsoft.WSMan.Management/ConfigProvider.cs b/src/Microsoft.WSMan.Management/ConfigProvider.cs index 237c3eb111f..46547407f29 100644 --- a/src/Microsoft.WSMan.Management/ConfigProvider.cs +++ b/src/Microsoft.WSMan.Management/ConfigProvider.cs @@ -20,7 +20,6 @@ namespace Microsoft.WSMan.Management { - /// /// WsMan Provider. /// @@ -122,27 +121,27 @@ string ICmdletProviderSupportsHelp.GetHelpMaml(string helpItemName, string path) document.Load(reader); } } - catch(XmlException) + catch (XmlException) { return string.Empty; } - catch(PathTooLongException) + catch (PathTooLongException) { return string.Empty; } - catch(IOException) + catch (IOException) { return string.Empty; } - catch(UnauthorizedAccessException) + catch (UnauthorizedAccessException) { return string.Empty; } - catch(NotSupportedException) + catch (NotSupportedException) { return string.Empty; } - catch(SecurityException) + catch (SecurityException) { return string.Empty; } @@ -167,7 +166,7 @@ string ICmdletProviderSupportsHelp.GetHelpMaml(string helpItemName, string path) { result = document.SelectSingleNode(xpathQuery, nsMgr); } - catch(XPathException) + catch (XPathException) { return string.Empty; } @@ -238,7 +237,6 @@ protected override PSDriveInfo RemoveDrive(PSDriveInfo drive) /// protected override string GetChildName(string path) { - string result = string.Empty; int separatorIndex = path.LastIndexOf(WSManStringLiterals.DefaultPathSeparator); string hostname = string.Empty; @@ -254,7 +252,6 @@ protected override string GetChildName(string path) } return GetCorrectCaseOfName(result, hostname, path); - } /// @@ -328,7 +325,6 @@ protected override bool IsValidPath(string path) bool result = false; result = CheckValidContainerOrPath(path); return result; - } /// @@ -393,7 +389,7 @@ protected override bool HasChildItems(string path) string WsManURI = NormalizePath(path, host); - lock(WSManHelper.AutoSession) + lock (WSManHelper.AutoSession) { // Gets the session object from the cache. object sessionobj; @@ -443,7 +439,6 @@ WsMan Config Can be divided in to Four Fixed Regions to Check Whether it has Chi // 3. Plugin and its internal structure Checks else if (WsManURI.Contains(WSManStringLiterals.containerPlugin)) { - strPathCheck = strPathCheck + WSManStringLiterals.containerPlugin; // Check for Plugin path XmlDocument xmlPlugins = FindResourceValue(sessionobj, WsManURI, null); @@ -459,7 +454,6 @@ WsMan Config Can be divided in to Four Fixed Regions to Check Whether it has Chi { return false; } - } strPathCheck = strPathCheck + WSManStringLiterals.DefaultPathSeparator + currentpluginname; @@ -549,7 +543,6 @@ WsMan Config Can be divided in to Four Fixed Regions to Check Whether it has Chi string sSecurity = security.Properties["SecurityDIR"].Value.ToString(); if (path.EndsWith(sSecurity, StringComparison.OrdinalIgnoreCase)) return true; - } } } @@ -582,7 +575,6 @@ WsMan Config Can be divided in to Four Fixed Regions to Check Whether it has Chi [SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode")] protected override void GetItem(string path) { - string childname = string.Empty; if (path.Length == 0 && string.IsNullOrEmpty(childname)) @@ -618,7 +610,7 @@ protected override void GetItem(string path) string host = GetHostName(path); string uri = NormalizePath(path, host); - lock(WSManHelper.AutoSession) + lock (WSManHelper.AutoSession) { // Gets the session object from the cache. object sessionobj; @@ -881,7 +873,6 @@ protected override void GetItem(string path) [SuppressMessage("Microsoft.Maintainability", "CA1505:AvoidUnmaintainableCode")] protected override void SetItem(string path, object value) { - if (value == null) { throw new ArgumentException(helper.GetResourceMsgFromResourcetext("value")); @@ -927,7 +918,7 @@ protected override void SetItem(string path, object value) // If validation is not required, that means Clear-Item cmdlet is called. // Clear-Item is not allowed on RunAsPassword, Admin should call Clear-Item RunAsUser // if he intends to disable RunAs on the Plugin. - if(string.Equals(ChildName, WSManStringLiterals.ConfigRunAsPasswordName, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(ChildName, WSManStringLiterals.ConfigRunAsPasswordName, StringComparison.OrdinalIgnoreCase)) { AssertError(helper.GetResourceMsgFromResourcetext("ClearItemOnRunAsPassword"), false); return; @@ -958,7 +949,7 @@ protected override void SetItem(string path, object value) bool settingPickedUpDynamically = false; - lock(WSManHelper.AutoSession) + lock (WSManHelper.AutoSession) { // Gets the session object from the cache. object sessionobj; @@ -1048,7 +1039,7 @@ protected override void SetItem(string path, object value) if (WSManStringLiterals.ConfigRunAsPasswordName.Equals(ChildName, StringComparison.OrdinalIgnoreCase)) { - if(string.IsNullOrEmpty( + if (string.IsNullOrEmpty( pluginConfiguration.GetOneConfiguration( string.Format( CultureInfo.InvariantCulture, @@ -1072,7 +1063,6 @@ protected override void SetItem(string path, object value) { AssertError(helper.GetResourceMsgFromResourcetext("SetItemNotSupported"), false); return; - } strPathChk = strPathChk + WSManStringLiterals.containerResources + WSManStringLiterals.DefaultPathSeparator; @@ -1294,7 +1284,7 @@ protected override void SetItem(string path, object value) { if (!Force) { - string query=""; + string query = ""; string caption = helper.GetResourceMsgFromResourcetext("SetItemGeneralSecurityCaption"); if (ChildName.Equals("TrustedHosts", StringComparison.OrdinalIgnoreCase)) { @@ -1350,7 +1340,7 @@ protected override void SetItem(string path, object value) } } - foreach(String warnings in warningMessage) + foreach (String warnings in warningMessage) { WriteWarning(warnings); } @@ -1405,7 +1395,6 @@ protected override object SetItemDynamicParameters(string path, object value) /// protected override void GetChildItems(string path, bool recurse) { - GetChildItemsOrNames(path, ProviderMethods.GetChildItems, recurse); } @@ -1416,7 +1405,6 @@ protected override void GetChildItems(string path, bool recurse) /// protected override void GetChildNames(string path, ReturnContainers returnContainers) { - GetChildItemsOrNames(path, ProviderMethods.GetChildNames, false); } #endregion @@ -1430,7 +1418,6 @@ protected override void GetChildNames(string path, ReturnContainers returnContai /// protected override bool IsItemContainer(string path) { - string childname = string.Empty; string strPathCheck = string.Empty; @@ -1461,7 +1448,7 @@ protected override bool IsItemContainer(string path) string host = GetHostName(path); string WsManURI = NormalizePath(path, host); - lock(WSManHelper.AutoSession) + lock (WSManHelper.AutoSession) { // Gets the session object from the cache. object sessionobj; @@ -1522,7 +1509,6 @@ WsMan Config Can be divided in to Four Fixed Regions to Check Whether Item is Co // 3. Plugin and its internal structure Checks else if (WsManURI.Contains(WSManStringLiterals.containerPlugin)) { - strPathCheck = strPathCheck + WSManStringLiterals.containerPlugin; // Check for Plugin path if (path.EndsWith(strPathCheck, StringComparison.OrdinalIgnoreCase)) @@ -1603,7 +1589,6 @@ WsMan Config Can be divided in to Four Fixed Regions to Check Whether Item is Co string sSecurity = security.Properties["SecurityDIR"].Value.ToString(); if (path.EndsWith(sSecurity, StringComparison.OrdinalIgnoreCase)) return true; - } } } @@ -1678,7 +1663,7 @@ protected override void RemoveItem(string path, bool recurse) } } - lock(WSManHelper.AutoSession) + lock (WSManHelper.AutoSession) { // Gets the session object from the cache. object sessionobj; @@ -1848,7 +1833,7 @@ protected override void NewItem(string path, string itemTypeName, object newItem string uri = NormalizePath(path, host); - lock(WSManHelper.AutoSession) + lock (WSManHelper.AutoSession) { Dictionary SessionObjCache = WSManHelper.GetSessionObjCache(); SessionObjCache.TryGetValue(host, out sessionobj); @@ -1982,7 +1967,6 @@ private void NewItemCreateComputerConnection(string Name) if (dynParams.ConnectionURI != null) { parametersetName = "URI"; - } helper.CreateWsManConnection(parametersetName, dynParams.ConnectionURI, dynParams.Port, Name, dynParams.ApplicationName, dynParams.UseSSL, dynParams.Authentication, dynParams.SessionOption, this.Credential, dynParams.CertificateThumbprint); @@ -2046,7 +2030,6 @@ private void NewItemContainerListenerOrCertMapping(object sessionobj, string pat WriteItemObject(GetItemPSObjectWithTypeName(resource.Key.ToString(), WSManStringLiterals.ContainerChildValue, null, (string[])kCache[resource.Key], string.Empty, WsManElementObjectTypes.WSManConfigContainerElement), path + WSManStringLiterals.DefaultPathSeparator + resource.Key.ToString(), true); } } - } /// @@ -2247,12 +2230,10 @@ private void NewItemPluginOrPluginChild(object sessionobj, string path, string h SecurityArray = newSecurity; } } - } if (path.EndsWith(strPathChk + WSManStringLiterals.containerInitParameters, StringComparison.OrdinalIgnoreCase)) { - WSManProviderInitializeParameters niParams = DynamicParameters as WSManProviderInitializeParameters; mshObj.Properties.Add(new PSNoteProperty(niParams.ParamName, niParams.ParamValue)); inputStr = ConstructInitParamsXml(mshObj, null); @@ -2426,7 +2407,6 @@ private void SetItemListenerOrClientCertificate(object sessionObj, string Resour /// private string GetInputStringForCreate(string ResourceURI, Hashtable value, string host) { - string putstr = string.Empty; string nilns = string.Empty; StringBuilder sbvalues = new StringBuilder(); @@ -2528,7 +2508,6 @@ private string GetHostName(string path) Dictionary SessionObjCache = WSManHelper.GetSessionObjCache(); if (!SessionObjCache.ContainsKey(sHostname)) sHostname = null; - } catch (ArgumentNullException e) { @@ -2642,7 +2621,6 @@ private XmlNodeList SearchXml(XmlDocument resourcexmldocument, string searchitem } nodes = resourcexmldocument.SelectNodes(xpathString); - } catch (System.Xml.XPath.XPathException ex) { @@ -2682,7 +2660,7 @@ private void PutResourceValue(object sessionobj, string ResourceURI, Hashtable v { for (int i = 0; i < node.ChildNodes.Count; i++) { - if ( (node.ChildNodes[i].ChildNodes.Count == 0) || node.ChildNodes[i].FirstChild.Name.Equals("#text", StringComparison.OrdinalIgnoreCase)) + if ((node.ChildNodes[i].ChildNodes.Count == 0) || node.ChildNodes[i].FirstChild.Name.Equals("#text", StringComparison.OrdinalIgnoreCase)) { foreach (string key in value.Keys) { @@ -2797,7 +2775,6 @@ private XmlDocument EnumerateResourceValue(object sessionobj, string ResourceURI xmlEnumResources.LoadXml(strXmlValue); this.enumerateMapping.Add(ResourceURI, xmlEnumResources); } - } finally { @@ -2809,7 +2786,6 @@ private XmlDocument EnumerateResourceValue(object sessionobj, string ResourceURI } return xmlEnumResources; - } /// @@ -2832,7 +2808,6 @@ private void DeleteResourceValue(object sessionobj, string ResourceURI, Hashtabl } ((IWSManSession)sessionobj).Delete(ResourceURI, 0); - } } finally @@ -2868,7 +2843,6 @@ private void CreateResourceValue(object sessionobj, string ResourceURI, string r AssertError(((IWSManSession)sessionobj).Error, true); } } - } /// @@ -3202,7 +3176,6 @@ private string SplitAndUpdateStringUsingDelimiter(object sessionobj, string uri, } catch (PSArgumentException) { - } return existingvalue; @@ -3239,7 +3212,7 @@ private PSObject BuildHostLevelPSObjectArrayList(object objSessionObject, string foreach (XmlNode node1 in node.ChildNodes) { // Getting Top Element in - if ( (node1.ChildNodes.Count == 0) || node1.FirstChild.Name.Equals("#text", StringComparison.OrdinalIgnoreCase)) + if ((node1.ChildNodes.Count == 0) || node1.FirstChild.Name.Equals("#text", StringComparison.OrdinalIgnoreCase)) { mshobject.Properties.Add(new PSNoteProperty(node1.LocalName, node1.InnerText)); } @@ -3250,7 +3223,6 @@ private PSObject BuildHostLevelPSObjectArrayList(object objSessionObject, string foreach (string root in WinRmRootConfigs) { mshobject.Properties.Add(new PSNoteProperty(root, WSManStringLiterals.ContainerChildValue)); - } } @@ -3268,7 +3240,7 @@ private PSObject ConvertToPSObject(XmlNode xmlnode) foreach (XmlNode node in xmlnode.ChildNodes) { // If node contains 0 child-nodes, it is empty node, if it's name = "#text" then it's a simple node. - if ( (node.ChildNodes.Count == 0) || node.FirstChild.Name.Equals("#text", StringComparison.OrdinalIgnoreCase)) + if ((node.ChildNodes.Count == 0) || node.FirstChild.Name.Equals("#text", StringComparison.OrdinalIgnoreCase)) { XmlAttribute attrSource = null; foreach (XmlAttribute attr in node.Attributes) @@ -3296,7 +3268,6 @@ private PSObject ConvertToPSObject(XmlNode xmlnode) } return mshObject; - } private string SetXPathString(string uri) @@ -3461,7 +3432,7 @@ private PSObject GetItemValue(string path) AssertError("WinRMServiceError", false); } - lock(WSManHelper.AutoSession) + lock (WSManHelper.AutoSession) { object sessionobj; // gets the sessionobject @@ -3649,25 +3620,25 @@ private string GetCorrectCaseOfName(string ChildName, string hostname, string pa string uri = NormalizePath(path, hostname); - lock(WSManHelper.AutoSession) + lock (WSManHelper.AutoSession) { object sessionobj; SessionObjCache.TryGetValue(hostname, out sessionobj); XmlDocument outxml = FindResourceValue(sessionobj, uri, null); if (outxml != null) { - string currentPluginName = string.Empty; - GetPluginNames(outxml, out objPluginNames, out currentPluginName, path); - if (path.EndsWith(hostname + WSManStringLiterals.DefaultPathSeparator + WSManStringLiterals.containerPlugin + WSManStringLiterals.DefaultPathSeparator + currentPluginName, StringComparison.OrdinalIgnoreCase)) - { - result = currentPluginName; + string currentPluginName = string.Empty; + GetPluginNames(outxml, out objPluginNames, out currentPluginName, path); + if (path.EndsWith(hostname + WSManStringLiterals.DefaultPathSeparator + WSManStringLiterals.containerPlugin + WSManStringLiterals.DefaultPathSeparator + currentPluginName, StringComparison.OrdinalIgnoreCase)) + { + result = currentPluginName; + } } } } } } } - } else { if (ChildName.StartsWith(WSManStringLiterals.containerListener, StringComparison.OrdinalIgnoreCase)) @@ -3787,7 +3758,6 @@ private void GetChildItemOrNamesForListenerOrCertMapping(XmlDocument xmlResource return; } - } /// @@ -3906,7 +3876,6 @@ private bool CheckValidContainerOrPath(string path) if (string.IsNullOrEmpty(host)) { return false; - } // Chks the WinRM Service @@ -3927,7 +3896,7 @@ private bool CheckValidContainerOrPath(string path) return false; } - lock(WSManHelper.AutoSession) + lock (WSManHelper.AutoSession) { object sessionobj = null; Dictionary SessionObjCache = WSManHelper.GetSessionObjCache(); @@ -4029,7 +3998,6 @@ private bool CheckValidContainerOrPath(string path) } } } - } } } @@ -4093,7 +4061,7 @@ private bool ItemExistListenerOrClientCertificate(object sessionobj, string Reso return false; } - Hashtable KeysCache=null, objcache=null; + Hashtable KeysCache = null, objcache = null; if (parentListenerOrCert.Equals(WSManStringLiterals.containerClientCertificate, StringComparison.OrdinalIgnoreCase)) { ProcessCertMappingObjects(outxml, out objcache, out KeysCache); @@ -4131,7 +4099,7 @@ private bool ItemExistListenerOrClientCertificate(object sessionobj, string Reso // Get the object cache from the listener object PSObject obj = (PSObject)objcache[CurrentNode]; - CurrentNode = RemainingPath.Substring(pos+1); + CurrentNode = RemainingPath.Substring(pos + 1); if (CurrentNode.IndexOf(WSManStringLiterals.DefaultPathSeparator) != -1) { // No more directories allowed after listeners objects @@ -4168,7 +4136,6 @@ private void GetChildItemsRecurse(string path, string childname, ProviderMethods { GetChildItemsOrNames(path, ProviderMethods.GetChildItems, recurse); } - } /// @@ -4232,7 +4199,7 @@ private void GetChildItemsOrNames(string path, ProviderMethods methodname, bool } } - lock(WSManHelper.AutoSession) + lock (WSManHelper.AutoSession) { object sessionobj; // gets the sessionobject @@ -4331,9 +4298,8 @@ private void GetChildItemsOrNames(string path, ProviderMethods methodname, bool } return; - } - else if(path.EndsWith(WSManStringLiterals.containerQuotasParameters, StringComparison.OrdinalIgnoreCase)) + else if (path.EndsWith(WSManStringLiterals.containerQuotasParameters, StringComparison.OrdinalIgnoreCase)) { // Get the Quotas element from the config XML. XmlNodeList nodeListForQuotas = CurrentPluginXML.GetElementsByTagName(WSManStringLiterals.containerQuotasParameters); @@ -4515,7 +4481,6 @@ private void GetChildItemsOrNames(string path, ProviderMethods methodname, bool } } } - } } else @@ -4935,7 +4900,6 @@ private ArrayList ProcessPluginResourceLevel(XmlDocument xmldoc, out ArrayList a resourceUri = attributecol[i].Value; strUniqueResourceId = "Resource_" + Convert.ToString(Math.Abs(attributecol[i].Value.GetHashCode()), CultureInfo.InvariantCulture); objResource.Properties.Add(new PSNoteProperty("ResourceDir", strUniqueResourceId)); - } if (attributecol[i].LocalName.Equals("ExactMatch", StringComparison.OrdinalIgnoreCase)) @@ -4988,7 +4952,6 @@ private ArrayList ProcessPluginResourceLevel(XmlDocument xmldoc, out ArrayList a nSecurity = ProcessPluginSecurityLevel(nSecurity, xmlCapabilities, strUniqueResourceId, resourceUri); Resources.Add(objResource); } - } } @@ -5098,7 +5061,6 @@ private ArrayList ProcessPluginSecurityLevel(ArrayList arrSecurity, XmlDocument /// An Configuration XML, ready to send to server. private string ConstructPluginXml(PSObject objinputparam, string ResourceURI, string host, string Operation, ArrayList resources, ArrayList securities, ArrayList initParams) { - StringBuilder sbvalues = new StringBuilder(); sbvalues.Append(" /// Computer dynamic parameters. This is similar to connect-wsman parameters. @@ -5544,7 +5503,6 @@ enum WsManElementObjectTypes /// public class WSManProviderNewItemComputerParameters { - /// /// The following is the definition of the input parameter "OptionSet". /// OptionSet is a hash table and is used to pass a set of switches to the @@ -5688,7 +5646,6 @@ public Uri ConnectionURI } private Uri connectionuri; - } /// @@ -5807,7 +5764,7 @@ public string File [Parameter()] public PSCredential RunAsCredential { - get { return this.runAsCredentials; } + get { return this.runAsCredentials; } set { this.runAsCredentials = value; } } @@ -5866,7 +5823,6 @@ public uint? ProcessIdleTimeoutSec /// public class WSManProviderInitializeParameters { - /// /// Parameter ParamName. /// @@ -5955,7 +5911,7 @@ public string Sddl private string _sddl; } -#region "ClientCertificate Dynamic Parameters" + #region "ClientCertificate Dynamic Parameters" /// /// Client Certificate Dynamic Parameters /// Path - WsMan:\Localhost\ClientCertificate. @@ -6041,12 +5997,11 @@ public bool Enabled } private bool _enabled = true; - } -#endregion + #endregion -#region Listener Dynamic Parameters + #region Listener Dynamic Parameters /// /// Listener Dynamic parameters @@ -6211,17 +6166,16 @@ public bool IsPortSpecified { _IsPortSpecified = value; } - } private bool _IsPortSpecified = false; } -#endregion + #endregion -#endregion + #endregion -#region SetItemDynamicParameters + #region SetItemDynamicParameters /// /// Set-Item Dynamic parameters @@ -6243,11 +6197,11 @@ public SwitchParameter Concatenate private SwitchParameter _concatenate = false; } -#endregion SetItemDynamicParameters + #endregion SetItemDynamicParameters -#endregion + #endregion -#region "String Literals" + #region "String Literals" internal static class WSManStringLiterals { @@ -6311,7 +6265,7 @@ internal static class WSManStringLiterals /// internal const string ContainerChildValue = "Container"; -#region WsMan Containers + #region WsMan Containers /// /// Plugin Container. @@ -6409,9 +6363,9 @@ internal static class WSManStringLiterals /// Possible Values in Plugin Top Security XML internal static readonly string[] NewItemSecurityParams = new string[] { "Uri", "Sddl", "ExactMatch" }; -#endregion WsMan Containers + #endregion WsMan Containers -#region WSMAN Config Names + #region WSMAN Config Names /// /// Name of the configuration which represents RunAs Password. /// @@ -6467,7 +6421,7 @@ internal static class WSManStringLiterals /// internal const string HiddenSuffixForSourceOfValue = "___Source"; -#endregion + #endregion /// /// This is used to start the service. return a bool value. if false we throw error. @@ -6502,12 +6456,11 @@ function Start-WSManServiceD15A7957836142a18627D7E1D342DD82 }} $_ | Start-WSManServiceD15A7957836142a18627D7E1D342DD82 -force $args[0] -captionForStart $args[1] -queryForStart $args[2] "; - } -#endregion "String Literals" + #endregion "String Literals" -#region "WsMan Output Objects" + #region "WsMan Output Objects" /// /// Base Output object. @@ -6532,7 +6485,6 @@ public string Name get { return _name; } set { _name = value; } - } private string _name; @@ -6584,7 +6536,6 @@ public object SourceOfValue get { return _SourceOfValue; } set { _SourceOfValue = value; } - } private object _SourceOfValue; @@ -6597,7 +6548,6 @@ public object Value get { return _value; } set { _value = value; } - } private object _value; @@ -6623,13 +6573,11 @@ public string[] Keys get { return _keys; } set { _keys = value; } - } private string[] _keys; } -#endregion "WsMan Output Objects" - + #endregion "WsMan Output Objects" } diff --git a/src/Microsoft.WSMan.Management/CredSSP.cs b/src/Microsoft.WSMan.Management/CredSSP.cs index 765a21a74d6..99318d96a4a 100644 --- a/src/Microsoft.WSMan.Management/CredSSP.cs +++ b/src/Microsoft.WSMan.Management/CredSSP.cs @@ -255,7 +255,6 @@ private void DeleteDelegateSettings(string applicationname, RegistryKey rootKey, bool otherkeys = false; try { - string Registry_Path_Credentials_Delegation = Registry_Path + @"\CredentialsDelegation"; RegistryKey Allow_Fresh_Credential_Key = rootKey.OpenSubKey(Registry_Path_Credentials_Delegation + @"\" + helper.Key_Allow_Fresh_Credentials, true); if (Allow_Fresh_Credential_Key != null) @@ -642,7 +641,6 @@ private void UpdateCurrentUserRegistrySettings() { string key = GPOpath + "\\" + keyname + "\\" + @"Software\Policies\Microsoft\Windows"; UpdateGPORegistrySettings(applicationname, this.delegatecomputer, Registry.CurrentUser, key); - } } // saving gpo settings @@ -703,7 +701,6 @@ private void UpdateGPORegistrySettings(string applicationname, string[] delegate ErrorRecord er = new ErrorRecord(ex, "ArgumentException", ErrorCategory.InvalidOperation, null); WriteError(er); } - } #region IDisposable Members @@ -812,7 +809,7 @@ private string GetDelegateSettings(string applicationname) WriteError(er); } - return result; + return result; } #endregion private @@ -929,7 +926,6 @@ protected override void BeginProcessing() } #endregion IDisposable Members - } #endregion diff --git a/src/Microsoft.WSMan.Management/CurrentConfigurations.cs b/src/Microsoft.WSMan.Management/CurrentConfigurations.cs index 86470c879c8..41427678150 100644 --- a/src/Microsoft.WSMan.Management/CurrentConfigurations.cs +++ b/src/Microsoft.WSMan.Management/CurrentConfigurations.cs @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; +using System.Globalization; +using System.Xml; + namespace Microsoft.WSMan.Management { - using System; - using System.Globalization; - using System.Xml; - /// /// Class that queries the server and gets current configurations. /// Also provides a generic way to update the configurations. diff --git a/src/Microsoft.WSMan.Management/Interop.cs b/src/Microsoft.WSMan.Management/Interop.cs index 239c59bef8a..25e2d9e81a3 100644 --- a/src/Microsoft.WSMan.Management/Interop.cs +++ b/src/Microsoft.WSMan.Management/Interop.cs @@ -19,7 +19,6 @@ namespace Microsoft.WSMan.Management { - #region "public Api" #region WsManEnumFlags @@ -162,7 +161,7 @@ public enum AuthenticationMechanism /// [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Credssp")] Credssp = 0x80, - } + } #endregion AuthenticationMechanism @@ -331,7 +330,6 @@ string CertificateThumbprint [DispId(1)] set; } - } /// IWSManConnectionOptions interface. @@ -694,9 +692,9 @@ string Error [DispId(29)] int EnumerationFlagAssociatedInstance(); } -#endregion IWsManEx + #endregion IWsManEx -#region IWsManResourceLocator + #region IWsManResourceLocator /// IWSManResourceLocator interface. [SuppressMessage("Microsoft.Design", "CA1040:AvoidEmptyInterfaces")] @@ -737,7 +735,6 @@ public interface IWSManResourceLocator [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings")] string ResourceUri { - // IDL: HRESULT resourceUri (BSTR value); [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "resource")] [SuppressMessage("Microsoft.Design", "CA1056:UriPropertiesShouldNotBeStrings")] @@ -751,7 +748,6 @@ string ResourceUri [DispId(1)] [return: MarshalAs(UnmanagedType.BStr)] get; - } /// AddSelector method of IWSManResourceLocator interface. Add selector to resource locator @@ -857,11 +853,10 @@ string Error [return: MarshalAs(UnmanagedType.BStr)] get; } - } -#endregion IWsManResourceLocator + #endregion IWsManResourceLocator -#region IWSManSession + #region IWSManSession /// IWSManSession interface. [Guid("FC84FC58-1286-40C4-9DA0-C8EF6EC241E0")] [ComImport] @@ -1005,9 +1000,9 @@ int Timeout } } -#endregion IWSManSession + #endregion IWSManSession -#region IWSManResourceLocatorInternal + #region IWSManResourceLocatorInternal /// IWSManResourceLocatorInternal interface. [Guid("EFFAEAD7-7EC8-4716-B9BE-F2E7E9FB4ADB")] [ComImport] @@ -1124,7 +1119,7 @@ void GetMachineName( uint GetPropertySheetPages(out IntPtr hPages); } -#endregion IGroupPolicyObject + #endregion IGroupPolicyObject /// GpoNativeApi public sealed class GpoNativeApi @@ -1140,8 +1135,7 @@ internal static extern System.IntPtr EnterCriticalPolicySection( internal static extern bool LeaveCriticalPolicySection( [In] System.IntPtr hSection); } -#endregion - + #endregion } #pragma warning restore 1591 diff --git a/src/Microsoft.WSMan.Management/InvokeWSManAction.cs b/src/Microsoft.WSMan.Management/InvokeWSManAction.cs index 67d2cc8efed..3722382813d 100644 --- a/src/Microsoft.WSMan.Management/InvokeWSManAction.cs +++ b/src/Microsoft.WSMan.Management/InvokeWSManAction.cs @@ -78,7 +78,6 @@ public string ComputerName { computername = "localhost"; } - } } @@ -261,7 +260,6 @@ protected override void BeginProcessing() // create the connection string connectionStr = helper.CreateConnectionString(connectionuri, port, computername, applicationname); - } /// @@ -269,7 +267,6 @@ protected override void BeginProcessing() /// protected override void ProcessRecord() { - try { // create the resourcelocator object @@ -285,7 +282,6 @@ protected override void ProcessRecord() XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(resultXml); WriteObject(xmldoc.DocumentElement); - } finally { @@ -301,9 +297,7 @@ protected override void ProcessRecord() if (m_session != null) Dispose(m_session); - } - } #region IDisposable Members @@ -339,7 +333,5 @@ protected override void EndProcessing() // WSManHelper helper = new WSManHelper(); helper.CleanUp(); } - - } } diff --git a/src/Microsoft.WSMan.Management/NewWSManSession.cs b/src/Microsoft.WSMan.Management/NewWSManSession.cs index c0266497503..a2d3bfe6cfc 100644 --- a/src/Microsoft.WSMan.Management/NewWSManSession.cs +++ b/src/Microsoft.WSMan.Management/NewWSManSession.cs @@ -277,7 +277,6 @@ protected override void BeginProcessing() } WriteObject(objSessionOption); - } } } diff --git a/src/Microsoft.WSMan.Management/PingWSMan.cs b/src/Microsoft.WSMan.Management/PingWSMan.cs index 8f14c8ec99c..6781e940c15 100644 --- a/src/Microsoft.WSMan.Management/PingWSMan.cs +++ b/src/Microsoft.WSMan.Management/PingWSMan.cs @@ -16,7 +16,6 @@ namespace Microsoft.WSMan.Management { - #region Test-WSMAN /// @@ -138,7 +137,6 @@ public string ApplicationName /// protected override void ProcessRecord() { - WSManHelper helper = new WSManHelper(this); IWSManEx wsmanObject = (IWSManEx)new WSManClass(); string connectionStr = string.Empty; @@ -152,7 +150,7 @@ protected override void ProcessRecord() xmldoc.LoadXml(m_SessionObj.Identify(0)); WriteObject(xmldoc.DocumentElement); } - catch(Exception) + catch (Exception) { try { @@ -165,8 +163,8 @@ protected override void ProcessRecord() this.WriteError(er); } } - catch(Exception) - {} + catch (Exception) + { } } finally { @@ -199,7 +197,6 @@ protected override void ProcessRecord() } #endregion IDisposable Members - } #endregion } diff --git a/src/Microsoft.WSMan.Management/Set-QuickConfig.cs b/src/Microsoft.WSMan.Management/Set-QuickConfig.cs index 5525599f83b..b9950f48baf 100644 --- a/src/Microsoft.WSMan.Management/Set-QuickConfig.cs +++ b/src/Microsoft.WSMan.Management/Set-QuickConfig.cs @@ -191,7 +191,7 @@ private void QuickConfigRemoting(bool serviceonly) } string resultAction = resultopxml.SelectSingleNode(xpathText, nsmgr).InnerText; - if ( source != null && source.Equals("GPO")) + if (source != null && source.Equals("GPO")) { string Info_Msg = WSManResourceLoader.GetResourceString("L_QuickConfig_RemotingDisabledbyGP_00_ErrorMessage"); Info_Msg += " " + resultAction; @@ -260,7 +260,6 @@ private void QuickConfigRemoting(bool serviceonly) if (m_SessionObj != null) Dispose(m_SessionObj); - } } #endregion private @@ -289,7 +288,6 @@ private void QuickConfigRemoting(bool serviceonly) } #endregion IDisposable Members - } #endregion Set-WsManQuickConfig } diff --git a/src/Microsoft.WSMan.Management/WSManConnections.cs b/src/Microsoft.WSMan.Management/WSManConnections.cs index a0f5e931c26..98c7196831d 100644 --- a/src/Microsoft.WSMan.Management/WSManConnections.cs +++ b/src/Microsoft.WSMan.Management/WSManConnections.cs @@ -116,7 +116,6 @@ internal void ValidateSpecifiedAuthentication() [Cmdlet(VerbsCommunications.Connect, "WSMan", DefaultParameterSetName = "ComputerName", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=141437")] public class ConnectWSManCommand : AuthenticatingWSManCommand { - #region Parameters /// @@ -253,7 +252,6 @@ public SwitchParameter UseSSL /// protected override void BeginProcessing() { - WSManHelper helper = new WSManHelper(this); if (connectionuri != null) { @@ -283,7 +281,6 @@ protected override void BeginProcessing() helper.CreateWsManConnection(ParameterSetName, connectionuri, port, computername, applicationname, usessl.IsPresent, Authentication, sessionoption, Credential, CertificateThumbprint); } - } #endregion @@ -311,7 +308,6 @@ public string ComputerName set { - computername = value; if ((string.IsNullOrEmpty(computername)) || (computername.Equals(".", StringComparison.OrdinalIgnoreCase))) { @@ -343,7 +339,6 @@ public string ComputerName { session = null; this.Dispose(); - } #endregion IDisposable Members @@ -379,7 +374,6 @@ protected override void BeginProcessing() helper.AssertError(helper.GetResourceMsgFromResourcetext("InvalidComputerName"), false, computername); } } - } #endregion Disconnect-WSMAN } diff --git a/src/Microsoft.WSMan.Management/WSManInstance.cs b/src/Microsoft.WSMan.Management/WSManInstance.cs index 5ab3e64b160..329db732d9f 100644 --- a/src/Microsoft.WSMan.Management/WSManInstance.cs +++ b/src/Microsoft.WSMan.Management/WSManInstance.cs @@ -305,7 +305,7 @@ public string ReturnType } } - private string returntype="object"; + private string returntype = "object"; /// /// The following is the definition of the input parameter "SelectorSet". @@ -402,16 +402,16 @@ private string GetFilter() string name; string value; string[] Split = filter.Trim().Split(new char[] { '=', ';' }); - if ((Split.Length)%2 != 0) + if ((Split.Length) % 2 != 0) { // mismatched property name/value pair return null; } filter = ""; - for (int i = 0; i" + value + ""; } @@ -435,11 +435,11 @@ private void ReturnEnumeration(IWSManEx wsmanObject, IWSManResourceLocator wsman } else if (returntype.Equals("epr", StringComparison.OrdinalIgnoreCase)) { - flags = wsmanObject.EnumerationFlagReturnEPR(); + flags = wsmanObject.EnumerationFlagReturnEPR(); } else { - flags = wsmanObject.EnumerationFlagReturnObjectAndEPR(); + flags = wsmanObject.EnumerationFlagReturnObjectAndEPR(); } } @@ -458,7 +458,6 @@ private void ReturnEnumeration(IWSManEx wsmanObject, IWSManResourceLocator wsman if (dialect != null && filter != null) { - if (dialect.ToString().Equals(helper.ALIAS_WQL, StringComparison.OrdinalIgnoreCase) || dialect.ToString().Equals(helper.URI_WQL_DIALECT, StringComparison.OrdinalIgnoreCase)) { fragment = helper.URI_WQL_DIALECT; @@ -466,36 +465,36 @@ private void ReturnEnumeration(IWSManEx wsmanObject, IWSManResourceLocator wsman } else if (dialect.ToString().Equals(helper.ALIAS_ASSOCIATION, StringComparison.OrdinalIgnoreCase) || dialect.ToString().Equals(helper.URI_ASSOCIATION_DIALECT, StringComparison.OrdinalIgnoreCase)) { - if (associations) - { - flags |= wsmanObject.EnumerationFlagAssociationInstance(); - } - else - { - flags |= wsmanObject.EnumerationFlagAssociatedInstance(); - } - - fragment = helper.URI_ASSOCIATION_DIALECT; - dialect = new Uri(fragment); + if (associations) + { + flags |= wsmanObject.EnumerationFlagAssociationInstance(); + } + else + { + flags |= wsmanObject.EnumerationFlagAssociatedInstance(); + } + + fragment = helper.URI_ASSOCIATION_DIALECT; + dialect = new Uri(fragment); } else if (dialect.ToString().Equals(helper.ALIAS_SELECTOR, StringComparison.OrdinalIgnoreCase) || dialect.ToString().Equals(helper.URI_SELECTOR_DIALECT, StringComparison.OrdinalIgnoreCase)) { - filter = GetFilter(); - fragment = helper.URI_SELECTOR_DIALECT; - dialect = new Uri(fragment); + filter = GetFilter(); + fragment = helper.URI_SELECTOR_DIALECT; + dialect = new Uri(fragment); } obj = (IWSManEnumerator)wsmanSession.Enumerate(wsmanResourceLocator, filter, dialect.ToString(), flags); } else if (filter != null) { - fragment = helper.URI_WQL_DIALECT; - dialect = new Uri(fragment); - obj = (IWSManEnumerator)wsmanSession.Enumerate(wsmanResourceLocator, filter, dialect.ToString(), flags); + fragment = helper.URI_WQL_DIALECT; + dialect = new Uri(fragment); + obj = (IWSManEnumerator)wsmanSession.Enumerate(wsmanResourceLocator, filter, dialect.ToString(), flags); } else { - obj = (IWSManEnumerator)wsmanSession.Enumerate(wsmanResourceLocator, filter, null, flags); + obj = (IWSManEnumerator)wsmanSession.Enumerate(wsmanResourceLocator, filter, null, flags); } while (!obj.AtEndOfStream) { @@ -536,7 +535,6 @@ protected override void ProcessRecord() { helper.AssertError(helper.GetResourceMsgFromResourcetext("NotProperURI"), false, connectionuri); } - } try @@ -551,7 +549,7 @@ protected override void ProcessRecord() { xmldoc.LoadXml(m_session.Get(m_resource, 0)); } - catch(XmlException ex) + catch (XmlException ex) { helper.AssertError(ex.Message, false, computername); } @@ -576,7 +574,6 @@ protected override void ProcessRecord() helper.AssertError(ex.Message, false, computername); } } - } finally { @@ -625,10 +622,8 @@ protected override void ProcessRecord() /// protected override void EndProcessing() { - helper.CleanUp(); } - } #endregion @@ -644,7 +639,6 @@ protected override void EndProcessing() [Cmdlet(VerbsCommon.Set, "WSManInstance", DefaultParameterSetName = "ComputerName", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=141458")] public class SetWSManInstanceCommand : AuthenticatingWSManCommand, IDisposable { - #region Parameters /// /// The following is the definition of the input parameter "ApplicationName". @@ -883,7 +877,7 @@ public Hashtable ValueSet #endregion - private WSManHelper helper ; + private WSManHelper helper; /// /// ProcessRecord method. /// @@ -921,7 +915,6 @@ protected override void ProcessRecord() { helper.AssertError(helper.GetResourceMsgFromResourcetext("NotProperURI"), false, connectionuri); } - } IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, fragment, dialect, m_wsmanObject, resourceuri); @@ -934,7 +927,7 @@ protected override void ProcessRecord() { xmldoc.LoadXml(m_session.Put(m_resource, input, 0)); } - catch(XmlException ex) + catch (XmlException ex) { helper.AssertError(ex.Message, false, computername); } @@ -952,7 +945,6 @@ protected override void ProcessRecord() } else WriteObject(xmldoc.DocumentElement); - } finally { @@ -1003,7 +995,6 @@ protected override void EndProcessing() { helper.CleanUp(); } - } #endregion @@ -1020,7 +1011,6 @@ protected override void EndProcessing() [Cmdlet(VerbsCommon.Remove, "WSManInstance", DefaultParameterSetName = "ComputerName", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=141453")] public class RemoveWSManInstanceCommand : AuthenticatingWSManCommand, IDisposable { - #region Parameters /// /// The following is the definition of the input parameter "ApplicationName". @@ -1219,7 +1209,6 @@ protected override void ProcessRecord() { helper.AssertError(helper.GetResourceMsgFromResourcetext("NotProperURI"), false, connectionuri); } - } IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, null, null, m_wsmanObject, resourceuri); @@ -1233,7 +1222,6 @@ protected override void ProcessRecord() { helper.AssertError(ex.Message, false, computername); } - } finally { @@ -1249,9 +1237,7 @@ protected override void ProcessRecord() if (m_session != null) Dispose(m_session); - } - } #region IDisposable Members @@ -1278,7 +1264,6 @@ protected override void ProcessRecord() } #endregion IDisposable Members - } #endregion @@ -1497,7 +1482,7 @@ public Hashtable ValueSet /// protected override void BeginProcessing() { - helper = new WSManHelper(this ); + helper = new WSManHelper(this); helper.WSManOp = "new"; connectionStr = helper.CreateConnectionString(connectionuri, port, computername, applicationname); if (connectionuri != null) @@ -1513,9 +1498,7 @@ protected override void BeginProcessing() { helper.AssertError(helper.GetResourceMsgFromResourcetext("NotProperURI"), false, connectionuri); } - } - } /// @@ -1560,7 +1543,6 @@ protected override void ProcessRecord() Dispose(m_session); } } - } #region IDisposable Members @@ -1594,7 +1576,6 @@ protected override void ProcessRecord() protected override void EndProcessing() { helper.CleanUp(); - } } diff --git a/src/Microsoft.WSMan.Management/WsManHelper.cs b/src/Microsoft.WSMan.Management/WsManHelper.cs index ce871b4f612..c5dc9c15e8a 100644 --- a/src/Microsoft.WSMan.Management/WsManHelper.cs +++ b/src/Microsoft.WSMan.Management/WsManHelper.cs @@ -123,7 +123,7 @@ internal static void ReleaseSessions() // Somehow the object was a null reference. Ignore the error } - sessionobj=null; + sessionobj = null; } Sessions.SessionObjCache.Clear(); @@ -230,7 +230,6 @@ internal void AddtoDictionary(string key, object value) Sessions.SessionObjCache.Add(key, value); } } - } internal object RemoveFromDictionary(string computer) @@ -338,7 +337,6 @@ internal string ReadFile(string path) string strOut = null; try { - _fs = new FileStream(path, FileMode.Open, FileAccess.Read); // create stream Reader _sr = new StreamReader(_fs); @@ -348,7 +346,6 @@ internal string ReadFile(string path) { ErrorRecord er = new ErrorRecord(e, "ArgumentNullException", ErrorCategory.InvalidArgument, null); cmdletname.ThrowTerminatingError(er); - } catch (UnauthorizedAccessException e) { @@ -374,7 +371,7 @@ internal string ReadFile(string path) { if (_sr != null) { - // _sr.Close(); + // _sr.Close(); _sr.Dispose(); } @@ -390,7 +387,6 @@ internal string ReadFile(string path) internal string ProcessInput(IWSManEx wsman, string filepath, string operation, string root, Hashtable valueset, IWSManResourceLocator resourceUri, IWSManSession sessionObj) { - string resultString = null; // if file path is given @@ -493,7 +489,6 @@ internal string ProcessInput(IWSManEx wsman, string filepath, string operation, node.InnerText = entry.Value.ToString(); } } - } } @@ -554,12 +549,10 @@ internal string CreateConnectionString(Uri ConnUri, int port, string computernam } return ConnectionString; - } internal IWSManResourceLocator InitializeResourceLocator(Hashtable optionset, Hashtable selectorset, string fragment, Uri dialect, IWSManEx wsmanObj, Uri resourceuri) { - string resource = null; if (resourceuri != null) { @@ -694,7 +687,6 @@ internal IWSManSession CreateSessionObject(IWSManEx wsmanObject, AuthenticationM { sessionFlags = sessionFlags | (int)WSManSessionFlags.WSManFlagUseClientCertificate; } - } IWSManConnectionOptionsEx2 connObject = (IWSManConnectionOptionsEx2)wsmanObject.CreateConnectionOptions(); @@ -707,7 +699,7 @@ internal IWSManSession CreateSessionObject(IWSManEx wsmanObject, AuthenticationM nwCredential = credential.GetNetworkCredential(); if (string.IsNullOrEmpty(nwCredential.Domain)) { - if ( authentication.Equals(AuthenticationMechanism.Digest) || authentication.Equals(AuthenticationMechanism.Basic) ) + if (authentication.Equals(AuthenticationMechanism.Digest) || authentication.Equals(AuthenticationMechanism.Basic)) { connObject.UserName = nwCredential.UserName; } @@ -738,7 +730,6 @@ internal IWSManSession CreateSessionObject(IWSManEx wsmanObject, AuthenticationM if (sessionoption != null) { - if (sessionoption.ProxyAuthentication != 0) { int ProxyAccessflags = 0; @@ -788,7 +779,6 @@ internal IWSManSession CreateSessionObject(IWSManEx wsmanObject, AuthenticationM { connObject.SetProxy((int)sessionoption.ProxyAccessType, (int)sessionoption.ProxyAuthentication, null, null); } - } if (sessionoption.SkipCACheck) @@ -859,7 +849,6 @@ internal IWSManSession CreateSessionObject(IWSManEx wsmanObject, AuthenticationM internal void CleanUp() { - if (_sr != null) { _sr.Dispose(); @@ -871,7 +860,6 @@ internal void CleanUp() _fs.Dispose(); _fs = null; } - } internal string GetFilterString(Hashtable seletorset) @@ -993,7 +981,6 @@ internal void CreateWsManConnection(string ParameterSetName, Uri connectionuri, { AssertError(m_wsmanObject.Error, true, computername); } - } } @@ -1122,10 +1109,8 @@ internal static void LoadResourceData() } catch (IOException e) { - throw (e); } - } /// @@ -1154,6 +1139,5 @@ internal static string GetResourceString(string Key) /// /// private static Dictionary ResourceValueCache = new Dictionary(); - } }