Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -317,7 +316,7 @@ private void ProcessListSet()
//
private void ProcessListSetPerMachine(string machine)
{
StringCollection counterSets = new StringCollection();
List<string> counterSets = new List<string>();
uint res = _pdhHelper.EnumObjects(machine, ref counterSets);
if (res != 0)
{
Expand All @@ -330,7 +329,7 @@ private void ProcessListSetPerMachine(string machine)

CultureInfo culture = GetCurrentCulture();
List<Tuple<char, char>> characterReplacementList = null;
StringCollection validPaths = new StringCollection();
List<string> validPaths = new List<string>();

_cultureAndSpecialCharacterMap.TryGetValue(culture.Name, out characterReplacementList);

Expand All @@ -356,8 +355,8 @@ private void ProcessListSetPerMachine(string machine)
continue;
}

StringCollection counterSetCounters = new StringCollection();
StringCollection counterSetInstances = new StringCollection();
List<string> counterSetCounters = new List<string>();
List<string> counterSetInstances = new List<string>();

res = _pdhHelper.EnumObjectItems(machine, counterSet, ref counterSetCounters, ref counterSetInstances);
if (res == PdhResults.PDH_ACCESS_DENIED)
Expand Down Expand Up @@ -444,7 +443,7 @@ private void ProcessGetCounter()
_cultureAndSpecialCharacterMap.TryGetValue(culture.Name, out characterReplacementList);
}

StringCollection allExpandedPaths = new StringCollection();
List<string> allExpandedPaths = new List<string>();
foreach (string path in paths)
{
string localizedPath = path;
Expand All @@ -468,7 +467,7 @@ private void ProcessGetCounter()
}
}

StringCollection expandedPaths;
List<string> expandedPaths;
res = _pdhHelper.ExpandWildCardPath(localizedPath, out expandedPaths);
if (res != 0)
{
Expand Down
27 changes: 13 additions & 14 deletions src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Eventing.Reader;
using System.Globalization;
Expand Down Expand Up @@ -396,10 +395,10 @@ public SwitchParameter Oldest
// Other private members and constants
//
private ResourceManager _resourceMgr = null;
private Dictionary<string, StringCollection> _providersByLogMap = new Dictionary<string, StringCollection>();
private Dictionary<string, List<string>> _providersByLogMap = new Dictionary<string, List<string>>();

private StringCollection _logNamesMatchingWildcard = null;
private StringCollection _resolvedPaths = new StringCollection();
private List<string> _logNamesMatchingWildcard = null;
private List<string> _resolvedPaths = new List<string>();

private List<string> _accumulatedLogNames = new List<string>();
private List<string> _accumulatedProviderNames = new List<string>();
Expand Down Expand Up @@ -771,7 +770,7 @@ private void ProcessFile()
//
for (int i = 0; i < _path.Length; i++)
{
StringCollection resolvedPaths = ValidateAndResolveFilePath(_path[i]);
List<string> resolvedPaths = ValidateAndResolveFilePath(_path[i]);
foreach (string resolvedPath in resolvedPaths)
{
_resolvedPaths.Add(resolvedPath);
Expand Down Expand Up @@ -1169,7 +1168,7 @@ private string BuildStructuredQueryFromHashTable(EventLogSession eventLogSession
{
foreach (object elt in (Array)hash[hashkey_path_lc])
{
StringCollection resolvedPaths = ValidateAndResolveFilePath(elt.ToString());
List<string> resolvedPaths = ValidateAndResolveFilePath(elt.ToString());
foreach (string resolvedPath in resolvedPaths)
{
queriedLogsQueryMap.Add(filePrefix + resolvedPath.ToLowerInvariant(),
Expand All @@ -1181,7 +1180,7 @@ private string BuildStructuredQueryFromHashTable(EventLogSession eventLogSession
}
else
{
StringCollection resolvedPaths = ValidateAndResolveFilePath(hash[hashkey_path_lc].ToString());
List<string> resolvedPaths = ValidateAndResolveFilePath(hash[hashkey_path_lc].ToString());
foreach (string resolvedPath in resolvedPaths)
{
queriedLogsQueryMap.Add(filePrefix + resolvedPath.ToLowerInvariant(),
Expand Down Expand Up @@ -1752,9 +1751,9 @@ private bool StringToDateTime(string dtString, ref DateTime dt)
// Writes non-terminating errors for invalid paths
// and returns an empty collection.
//
private StringCollection ValidateAndResolveFilePath(string path)
private List<string> ValidateAndResolveFilePath(string path)
{
StringCollection retColl = new StringCollection();
List<string> retColl = new List<string>();

Collection<PathInfo> resolvedPathSubset = null;
try
Expand Down Expand Up @@ -1872,7 +1871,7 @@ private void CheckHashTablesForNullValues()
// and will may produce garbage if the _filterXPath expression provided by the user is invalid.
// However, we are relying on the EventLog XPath parser to reject the garbage later on.
//
private string AddProviderPredicatesToFilter(StringCollection providers)
private string AddProviderPredicatesToFilter(List<string> providers)
{
if (providers.Count == 0)
{
Expand Down Expand Up @@ -1910,7 +1909,7 @@ private string AddProviderPredicatesToFilter(StringCollection providers)
// "System/Provider[@Name='a' or @Name='b']"
// for all provider names specified in the "providers" argument.
//
private string BuildProvidersPredicate(StringCollection providers)
private string BuildProvidersPredicate(List<string> providers)
{
if (providers.Count == 0)
{
Expand Down Expand Up @@ -2012,7 +2011,7 @@ private void AddLogsForProviderToInternalMap(EventLogSession eventLogSession, st

WriteVerbose(string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("ProviderLogLink"), providerName, logLink.LogName));

StringCollection provColl = new StringCollection();
List<string> provColl = new List<string>();
provColl.Add(providerName.ToLowerInvariant());

_providersByLogMap.Add(logLink.LogName.ToLowerInvariant(), provColl);
Expand All @@ -2022,7 +2021,7 @@ private void AddLogsForProviderToInternalMap(EventLogSession eventLogSession, st
//
// Log is there: add provider, if needed
//
StringCollection coll = _providersByLogMap[logLink.LogName.ToLowerInvariant()];
List<string> coll = _providersByLogMap[logLink.LogName.ToLowerInvariant()];

if (!coll.Contains(providerName.ToLowerInvariant()))
{
Expand Down Expand Up @@ -2054,7 +2053,7 @@ private void FindLogNamesMatchingWildcards(EventLogSession eventLogSession, IEnu
{
if (_logNamesMatchingWildcard == null)
{
_logNamesMatchingWildcard = new StringCollection();
_logNamesMatchingWildcard = new List<string>();
}
else
{
Expand Down
35 changes: 17 additions & 18 deletions src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -426,12 +425,12 @@ public void Dispose()
private Dictionary<string, CounterHandleNInstance> _consumerPathToHandleAndInstanceMap = new Dictionary<string, CounterHandleNInstance>();

/// <summary>
/// A helper reading in a Unicode string with embedded NULLs and splitting it into a StringCollection.
/// A helper reading in a Unicode string with embedded NULLs and splitting it into a List.
/// </summary>
/// <param name="strNative"></param>
/// <param name="strSize"></param>
/// <param name="strColl"></param>
private void ReadPdhMultiString(ref IntPtr strNative, Int32 strSize, ref StringCollection strColl)
private void ReadPdhMultiString(ref IntPtr strNative, Int32 strSize, ref List<string> strColl)
{
Debug.Assert(strSize >= 2);
int offset = 0;
Expand Down Expand Up @@ -534,7 +533,7 @@ public uint ConnectToDataSource(string dataSourceName)
return res;
}

public uint ConnectToDataSource(StringCollection blgFileNames)
public uint ConnectToDataSource(List<string> blgFileNames)
{
if (blgFileNames.Count == 1)
{
Expand Down Expand Up @@ -609,7 +608,7 @@ public uint SetQueryTimeRange(DateTime startTime, DateTime endTime)
return PdhSetQueryTimeRange(_hQuery, ref pTimeInfo);
}

public uint EnumBlgFilesMachines(ref StringCollection machineNames)
public uint EnumBlgFilesMachines(ref List<string> machineNames)
{
IntPtr MachineListTcharSizePtr = new IntPtr(0);
uint res = PdhHelper.PdhEnumMachinesH(_hDataSource, IntPtr.Zero, ref MachineListTcharSizePtr);
Expand Down Expand Up @@ -637,7 +636,7 @@ public uint EnumBlgFilesMachines(ref StringCollection machineNames)
return res;
}

public uint EnumObjects(string machineName, ref StringCollection objectNames)
public uint EnumObjects(string machineName, ref List<string> objectNames)
{
IntPtr pBufferSize = new IntPtr(0);
uint res = PdhEnumObjectsH(_hDataSource, machineName, IntPtr.Zero, ref pBufferSize, PerfDetail.PERF_DETAIL_WIZARD, false);
Expand Down Expand Up @@ -665,7 +664,7 @@ public uint EnumObjects(string machineName, ref StringCollection objectNames)
return res;
}

public uint EnumObjectItems(string machineName, string objectName, ref StringCollection counterNames, ref StringCollection instanceNames)
public uint EnumObjectItems(string machineName, string objectName, ref List<string> counterNames, ref List<string> instanceNames)
{
IntPtr pCounterBufferSize = new IntPtr(0);
IntPtr pInstanceBufferSize = new IntPtr(0);
Expand Down Expand Up @@ -745,11 +744,11 @@ public uint EnumObjectItems(string machineName, string objectName, ref StringCol
return res;
}

public uint GetValidPathsFromFiles(ref StringCollection validPaths)
public uint GetValidPathsFromFiles(ref List<string> validPaths)
{
Debug.Assert(_hDataSource != null && !_hDataSource.IsInvalid, "Call ConnectToDataSource before GetValidPathsFromFiles");

StringCollection machineNames = new StringCollection();
List<string> machineNames = new List<string>();
uint res = this.EnumBlgFilesMachines(ref machineNames);
if (res != 0)
{
Expand All @@ -758,7 +757,7 @@ public uint GetValidPathsFromFiles(ref StringCollection validPaths)

foreach (string machine in machineNames)
{
StringCollection counterSets = new StringCollection();
List<string> counterSets = new List<string>();
res = this.EnumObjects(machine, ref counterSets);
if (res != 0)
{
Expand All @@ -769,8 +768,8 @@ public uint GetValidPathsFromFiles(ref StringCollection validPaths)
{
// Console.WriteLine("Counter set " + counterSet);

StringCollection counterSetCounters = new StringCollection();
StringCollection counterSetInstances = new StringCollection();
List<string> counterSetCounters = new List<string>();
List<string> counterSetInstances = new List<string>();

res = this.EnumObjectItems(machine, counterSet, ref counterSetCounters, ref counterSetInstances);
if (res != 0)
Expand Down Expand Up @@ -1056,9 +1055,9 @@ public uint LookupPerfNameByIndex(string machineName, uint index, out string loc

public uint GetValidPaths(string machineName,
string objectName,
ref StringCollection counters,
ref StringCollection instances,
ref StringCollection validPaths)
ref List<string> counters,
ref List<string> instances,
ref List<string> validPaths)
{
uint res = 0;

Expand Down Expand Up @@ -1097,7 +1096,7 @@ public uint GetValidPaths(string machineName,
return res;
}

public uint AddCounters(ref StringCollection validPaths, bool bFlushOldCounters)
public uint AddCounters(ref List<string> validPaths, bool bFlushOldCounters)
{
Debug.Assert(_hQuery != null && !_hQuery.IsInvalid);

Expand Down Expand Up @@ -1281,9 +1280,9 @@ public uint ReadNextSet(out PerformanceCounterSampleSet nextSet, bool bSkipReadi
return res;
}

public uint ExpandWildCardPath(string path, out StringCollection expandedPaths)
public uint ExpandWildCardPath(string path, out List<string> expandedPaths)
{
expandedPaths = new StringCollection();
expandedPaths = new List<string>();
IntPtr pcchPathListLength = new IntPtr(0);

uint res = PdhExpandWildCardPathH(_hDataSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Management.Automation;
using System.Management.Automation.Internal;

Expand Down Expand Up @@ -184,7 +184,7 @@ public string[] LiteralPath
/// </summary>
protected override void ProcessRecord()
{
StringCollection pathsToParse = new StringCollection();
List<string> pathsToParse = new List<string>();

if (Resolve)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Management.Automation;
using System.Management.Automation.Internal;

Expand Down Expand Up @@ -1117,33 +1116,42 @@ private void InternalInitialize(ListViewEntry lve)

internal static string[] GetProperties(ListViewEntry lve)
{
StringCollection props = new StringCollection();
foreach (ListViewField lvf in lve.listViewFieldList)
int count = lve.listViewFieldList.Count;

if (count == 0)
{
props.Add(lvf.label ?? lvf.propertyName);
return null;
}

if (props.Count == 0)
return null;
string[] retVal = new string[props.Count];
props.CopyTo(retVal, 0);
return retVal;
string[] props = new string[count];

for (int i = 0; i < count; ++i)
{
ListViewField lvf = lve.listViewFieldList[i];
props[i] = lvf.label ?? lvf.propertyName;
}

return props;
}

internal static string[] GetValues(ListViewEntry lve)
{
StringCollection vals = new StringCollection();
int count = lve.listViewFieldList.Count;

foreach (ListViewField lvf in lve.listViewFieldList)
if (count == 0)
{
vals.Add(lvf.formatPropertyField.propertyValue);
return null;
}

if (vals.Count == 0)
return null;
string[] retVal = new string[vals.Count];
vals.CopyTo(retVal, 0);
return retVal;
string[] vals = new string[count];

for (int i = 0; i < count; ++i)
{
ListViewField lvf = lve.listViewFieldList[i];
vals[i] = lvf.formatPropertyField.propertyValue;
}

return vals;
}

/// <summary>
Expand Down
Loading