Fix IDE0032: UseAutoProperty part 3 (#14443)
https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0032
This commit is contained in:
parent
bc080921bf
commit
1ab2c0c2bd
|
@ -27,127 +27,43 @@ namespace Microsoft.PowerShell.Commands.GetCounter
|
|||
UInt64 timeStamp100nSec,
|
||||
UInt32 status)
|
||||
{
|
||||
_path = path;
|
||||
_instanceName = instanceName;
|
||||
_cookedValue = cookedValue;
|
||||
_rawValue = rawValue;
|
||||
_secondValue = secondValue;
|
||||
_multiCount = multiCount;
|
||||
_counterType = counterType;
|
||||
_defaultScale = defaultScale;
|
||||
_timeBase = timeBase;
|
||||
_timeStamp = timeStamp;
|
||||
_timeStamp100nSec = timeStamp100nSec;
|
||||
_status = status;
|
||||
Path = path;
|
||||
InstanceName = instanceName;
|
||||
CookedValue = cookedValue;
|
||||
RawValue = rawValue;
|
||||
SecondValue = secondValue;
|
||||
MultipleCount = multiCount;
|
||||
CounterType = counterType;
|
||||
DefaultScale = defaultScale;
|
||||
TimeBase = timeBase;
|
||||
Timestamp = timeStamp;
|
||||
Timestamp100NSec = timeStamp100nSec;
|
||||
Status = status;
|
||||
}
|
||||
|
||||
public string Path
|
||||
{
|
||||
get { return _path; }
|
||||
public string Path { get; set; } = string.Empty;
|
||||
|
||||
set { _path = value; }
|
||||
}
|
||||
public string InstanceName { get; set; } = string.Empty;
|
||||
|
||||
private string _path = string.Empty;
|
||||
public double CookedValue { get; set; }
|
||||
|
||||
public string InstanceName
|
||||
{
|
||||
get { return _instanceName; }
|
||||
public UInt64 RawValue { get; set; }
|
||||
|
||||
set { _instanceName = value; }
|
||||
}
|
||||
public UInt64 SecondValue { get; set; }
|
||||
|
||||
private string _instanceName = string.Empty;
|
||||
public uint MultipleCount { get; set; }
|
||||
|
||||
public double CookedValue
|
||||
{
|
||||
get { return _cookedValue; }
|
||||
public PerformanceCounterType CounterType { get; set; }
|
||||
|
||||
set { _cookedValue = value; }
|
||||
}
|
||||
public DateTime Timestamp { get; set; } = DateTime.MinValue;
|
||||
|
||||
private double _cookedValue = 0;
|
||||
public UInt64 Timestamp100NSec { get; set; }
|
||||
|
||||
public UInt64 RawValue
|
||||
{
|
||||
get { return _rawValue; }
|
||||
public UInt32 Status { get; set; }
|
||||
|
||||
set { _rawValue = value; }
|
||||
}
|
||||
public UInt32 DefaultScale { get; set; }
|
||||
|
||||
private UInt64 _rawValue = 0;
|
||||
|
||||
public UInt64 SecondValue
|
||||
{
|
||||
get { return _secondValue; }
|
||||
|
||||
set { _secondValue = value; }
|
||||
}
|
||||
|
||||
private UInt64 _secondValue = 0;
|
||||
|
||||
public uint MultipleCount
|
||||
{
|
||||
get { return _multiCount; }
|
||||
|
||||
set { _multiCount = value; }
|
||||
}
|
||||
|
||||
private uint _multiCount = 0;
|
||||
|
||||
public PerformanceCounterType CounterType
|
||||
{
|
||||
get { return _counterType; }
|
||||
|
||||
set { _counterType = value; }
|
||||
}
|
||||
|
||||
private PerformanceCounterType _counterType = 0;
|
||||
|
||||
public DateTime Timestamp
|
||||
{
|
||||
get { return _timeStamp; }
|
||||
|
||||
set { _timeStamp = value; }
|
||||
}
|
||||
|
||||
private DateTime _timeStamp = DateTime.MinValue;
|
||||
|
||||
public UInt64 Timestamp100NSec
|
||||
{
|
||||
get { return _timeStamp100nSec; }
|
||||
|
||||
set { _timeStamp100nSec = value; }
|
||||
}
|
||||
|
||||
private UInt64 _timeStamp100nSec = 0;
|
||||
|
||||
public UInt32 Status
|
||||
{
|
||||
get { return _status; }
|
||||
|
||||
set { _status = value; }
|
||||
}
|
||||
|
||||
private UInt32 _status = 0;
|
||||
|
||||
public UInt32 DefaultScale
|
||||
{
|
||||
get { return _defaultScale; }
|
||||
|
||||
set { _defaultScale = value; }
|
||||
}
|
||||
|
||||
private UInt32 _defaultScale = 0;
|
||||
|
||||
public UInt64 TimeBase
|
||||
{
|
||||
get { return _timeBase; }
|
||||
|
||||
set { _timeBase = value; }
|
||||
}
|
||||
|
||||
private UInt64 _timeBase = 0;
|
||||
public UInt64 TimeBase { get; set; }
|
||||
}
|
||||
|
||||
public class PerformanceCounterSampleSet
|
||||
|
@ -161,31 +77,17 @@ namespace Microsoft.PowerShell.Commands.GetCounter
|
|||
PerformanceCounterSample[] counterSamples,
|
||||
bool firstSet) : this()
|
||||
{
|
||||
_timeStamp = timeStamp;
|
||||
_counterSamples = counterSamples;
|
||||
Timestamp = timeStamp;
|
||||
CounterSamples = counterSamples;
|
||||
}
|
||||
|
||||
public DateTime Timestamp
|
||||
{
|
||||
get { return _timeStamp; }
|
||||
|
||||
set { _timeStamp = value; }
|
||||
}
|
||||
|
||||
private DateTime _timeStamp = DateTime.MinValue;
|
||||
public DateTime Timestamp { get; set; } = DateTime.MinValue;
|
||||
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays",
|
||||
Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSample.CounterSamples",
|
||||
Justification = "A string[] is required here because that is the type Powershell supports")]
|
||||
public PerformanceCounterSample[] CounterSamples
|
||||
{
|
||||
get { return _counterSamples; }
|
||||
|
||||
set { _counterSamples = value; }
|
||||
}
|
||||
|
||||
private PerformanceCounterSample[] _counterSamples = null;
|
||||
public PerformanceCounterSample[] CounterSamples { get; set; }
|
||||
|
||||
private readonly ResourceManager _resourceMgr = null;
|
||||
}
|
||||
|
|
|
@ -16,74 +16,34 @@ namespace Microsoft.PowerShell.Commands.GetCounter
|
|||
string setHelp,
|
||||
ref Dictionary<string, string[]> counterInstanceMapping)
|
||||
{
|
||||
_counterSetName = setName;
|
||||
CounterSetName = setName;
|
||||
if (machineName == null || machineName.Length == 0)
|
||||
{
|
||||
machineName = ".";
|
||||
}
|
||||
else
|
||||
{
|
||||
_machineName = machineName;
|
||||
if (!_machineName.StartsWith(@"\\", StringComparison.OrdinalIgnoreCase))
|
||||
MachineName = machineName;
|
||||
if (!MachineName.StartsWith(@"\\", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_machineName = @"\\" + _machineName;
|
||||
MachineName = @"\\" + MachineName;
|
||||
}
|
||||
}
|
||||
|
||||
_counterSetType = categoryType;
|
||||
_description = setHelp;
|
||||
_counterInstanceMapping = counterInstanceMapping;
|
||||
CounterSetType = categoryType;
|
||||
Description = setHelp;
|
||||
CounterInstanceMapping = counterInstanceMapping;
|
||||
}
|
||||
|
||||
public string CounterSetName
|
||||
{
|
||||
get
|
||||
{
|
||||
return _counterSetName;
|
||||
}
|
||||
}
|
||||
public string CounterSetName { get; } = string.Empty;
|
||||
|
||||
private readonly string _counterSetName = string.Empty;
|
||||
public string MachineName { get; } = ".";
|
||||
|
||||
public string MachineName
|
||||
{
|
||||
get
|
||||
{
|
||||
return _machineName;
|
||||
}
|
||||
}
|
||||
public PerformanceCounterCategoryType CounterSetType { get; }
|
||||
|
||||
private readonly string _machineName = ".";
|
||||
public string Description { get; } = string.Empty;
|
||||
|
||||
public PerformanceCounterCategoryType CounterSetType
|
||||
{
|
||||
get
|
||||
{
|
||||
return _counterSetType;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly PerformanceCounterCategoryType _counterSetType;
|
||||
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return _description;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly string _description = string.Empty;
|
||||
|
||||
internal Dictionary<string, string[]> CounterInstanceMapping
|
||||
{
|
||||
get
|
||||
{
|
||||
return _counterInstanceMapping;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, string[]> _counterInstanceMapping;
|
||||
internal Dictionary<string, string[]> CounterInstanceMapping { get; }
|
||||
|
||||
public StringCollection Paths
|
||||
{
|
||||
|
@ -95,15 +55,15 @@ namespace Microsoft.PowerShell.Commands.GetCounter
|
|||
string path;
|
||||
if (CounterInstanceMapping[counterName].Length != 0)
|
||||
{
|
||||
path = (_machineName == ".") ?
|
||||
("\\" + _counterSetName + "(*)\\" + counterName) :
|
||||
(_machineName + "\\" + _counterSetName + "(*)\\" + counterName);
|
||||
path = (MachineName == ".") ?
|
||||
("\\" + CounterSetName + "(*)\\" + counterName) :
|
||||
(MachineName + "\\" + CounterSetName + "(*)\\" + counterName);
|
||||
}
|
||||
else
|
||||
{
|
||||
path = (_machineName == ".") ?
|
||||
("\\" + _counterSetName + "\\" + counterName) :
|
||||
(_machineName + "\\" + _counterSetName + "\\" + counterName);
|
||||
path = (MachineName == ".") ?
|
||||
("\\" + CounterSetName + "\\" + counterName) :
|
||||
(MachineName + "\\" + CounterSetName + "\\" + counterName);
|
||||
}
|
||||
|
||||
retColl.Add(path);
|
||||
|
@ -122,9 +82,9 @@ namespace Microsoft.PowerShell.Commands.GetCounter
|
|||
{
|
||||
foreach (string instanceName in CounterInstanceMapping[counterName])
|
||||
{
|
||||
string path = (_machineName == ".") ?
|
||||
("\\" + _counterSetName + "(" + instanceName + ")\\" + counterName) :
|
||||
(_machineName + "\\" + _counterSetName + "(" + instanceName + ")\\" + counterName);
|
||||
string path = (MachineName == ".") ?
|
||||
("\\" + CounterSetName + "(" + instanceName + ")\\" + counterName) :
|
||||
(MachineName + "\\" + CounterSetName + "(" + instanceName + ")\\" + counterName);
|
||||
retColl.Add(path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,15 +37,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.GetCounterCommand.ListSet",
|
||||
Justification = "A string[] is required here because that is the type Powershell supports")]
|
||||
|
||||
public string[] ListSet
|
||||
{
|
||||
get { return _listSet; }
|
||||
|
||||
set { _listSet = value; }
|
||||
}
|
||||
|
||||
private string[] _listSet = { "*" };
|
||||
public string[] ListSet { get; set; } = { "*" };
|
||||
|
||||
//
|
||||
// Counter parameter
|
||||
|
@ -93,14 +85,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
ValueFromPipelineByPropertyName = false,
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
[ValidateRange((int)1, int.MaxValue)]
|
||||
public int SampleInterval
|
||||
{
|
||||
get { return _sampleInterval; }
|
||||
|
||||
set { _sampleInterval = value; }
|
||||
}
|
||||
|
||||
private int _sampleInterval = 1;
|
||||
public int SampleInterval { get; set; } = 1;
|
||||
|
||||
//
|
||||
// MaxSamples parameter
|
||||
|
@ -155,14 +140,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.GetCounterCommand.ComputerName",
|
||||
Justification = "A string[] is required here because that is the type Powershell supports")]
|
||||
public string[] ComputerName
|
||||
{
|
||||
get { return _computerName; }
|
||||
|
||||
set { _computerName = value; }
|
||||
}
|
||||
|
||||
private string[] _computerName = Array.Empty<string>();
|
||||
public string[] ComputerName { get; set; } = Array.Empty<string>();
|
||||
|
||||
private ResourceManager _resourceMgr = null;
|
||||
|
||||
|
@ -288,12 +266,12 @@ namespace Microsoft.PowerShell.Commands
|
|||
//
|
||||
private void ProcessListSet()
|
||||
{
|
||||
if (_computerName.Length == 0)
|
||||
if (ComputerName.Length == 0)
|
||||
{
|
||||
ProcessListSetPerMachine(null);
|
||||
}
|
||||
else
|
||||
foreach (string machine in _computerName)
|
||||
foreach (string machine in ComputerName)
|
||||
{
|
||||
ProcessListSetPerMachine(machine);
|
||||
}
|
||||
|
@ -322,7 +300,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
|
||||
_cultureAndSpecialCharacterMap.TryGetValue(culture.Name, out characterReplacementList);
|
||||
|
||||
foreach (string pattern in _listSet)
|
||||
foreach (string pattern in ListSet)
|
||||
{
|
||||
bool bMatched = false;
|
||||
string normalizedPattern = pattern;
|
||||
|
@ -550,7 +528,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
break;
|
||||
}
|
||||
|
||||
bool cancelled = _cancelEventArrived.WaitOne((int)_sampleInterval * 1000, true);
|
||||
bool cancelled = _cancelEventArrived.WaitOne((int)SampleInterval * 1000, true);
|
||||
if (cancelled)
|
||||
{
|
||||
break;
|
||||
|
@ -587,7 +565,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
{
|
||||
List<string> retColl = new();
|
||||
|
||||
if (_computerName.Length == 0)
|
||||
if (ComputerName.Length == 0)
|
||||
{
|
||||
retColl.AddRange(_accumulatedCounters);
|
||||
return retColl;
|
||||
|
@ -601,7 +579,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
foreach (string machine in _computerName)
|
||||
foreach (string machine in ComputerName)
|
||||
{
|
||||
if (machine.StartsWith("\\\\", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
|
|
|
@ -42,15 +42,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.GetEvent.ListLog",
|
||||
Justification = "A string[] is required here because that is the type Powershell supports")]
|
||||
|
||||
public string[] ListLog
|
||||
{
|
||||
get { return _listLog; }
|
||||
|
||||
set { _listLog = value; }
|
||||
}
|
||||
|
||||
private string[] _listLog = { "*" };
|
||||
public string[] ListLog { get; set; } = { "*" };
|
||||
|
||||
/// <summary>
|
||||
/// GetLog parameter.
|
||||
|
@ -66,14 +58,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.GetEvent.LogName",
|
||||
Justification = "A string[] is required here because that is the type Powershell supports")]
|
||||
public string[] LogName
|
||||
{
|
||||
get { return _logName; }
|
||||
|
||||
set { _logName = value; }
|
||||
}
|
||||
|
||||
private string[] _logName = { "*" };
|
||||
public string[] LogName { get; set; } = { "*" };
|
||||
|
||||
/// <summary>
|
||||
/// ListProvider parameter.
|
||||
|
@ -87,20 +72,11 @@ namespace Microsoft.PowerShell.Commands
|
|||
HelpMessageBaseName = "GetEventResources",
|
||||
HelpMessageResourceId = "ListProviderParamHelp")]
|
||||
[AllowEmptyCollection]
|
||||
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays",
|
||||
Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.GetEvent.ListProvider",
|
||||
Justification = "A string[] is required here because that is the type Powershell supports")]
|
||||
|
||||
public string[] ListProvider
|
||||
{
|
||||
get { return _listProvider; }
|
||||
|
||||
set { _listProvider = value; }
|
||||
}
|
||||
|
||||
private string[] _listProvider = { "*" };
|
||||
public string[] ListProvider { get; set; } = { "*" };
|
||||
|
||||
/// <summary>
|
||||
/// ProviderName parameter.
|
||||
|
@ -112,20 +88,11 @@ namespace Microsoft.PowerShell.Commands
|
|||
ValueFromPipelineByPropertyName = true,
|
||||
HelpMessageBaseName = "GetEventResources",
|
||||
HelpMessageResourceId = "GetProviderParamHelp")]
|
||||
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays",
|
||||
Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.GetEvent.ProviderName",
|
||||
Justification = "A string[] is required here because that is the type Powershell supports")]
|
||||
|
||||
public string[] ProviderName
|
||||
{
|
||||
get { return _providerName; }
|
||||
|
||||
set { _providerName = value; }
|
||||
}
|
||||
|
||||
private string[] _providerName;
|
||||
public string[] ProviderName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Path parameter.
|
||||
|
@ -137,20 +104,12 @@ namespace Microsoft.PowerShell.Commands
|
|||
ValueFromPipelineByPropertyName = true,
|
||||
HelpMessageBaseName = "GetEventResources",
|
||||
HelpMessageResourceId = "PathParamHelp")]
|
||||
|
||||
[Alias("PSPath")]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays",
|
||||
Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.GetEvent.Path",
|
||||
Justification = "A string[] is required here because that is the type Powershell supports")]
|
||||
public string[] Path
|
||||
{
|
||||
get { return _path; }
|
||||
|
||||
set { _path = value; }
|
||||
}
|
||||
|
||||
private string[] _path;
|
||||
public string[] Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MaxEvents parameter.
|
||||
|
@ -186,14 +145,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
HelpMessageBaseName = "GetEventResources",
|
||||
HelpMessageResourceId = "MaxEventsParamHelp")]
|
||||
[ValidateRange((Int64)1, Int64.MaxValue)]
|
||||
public Int64 MaxEvents
|
||||
{
|
||||
get { return _maxEvents; }
|
||||
|
||||
set { _maxEvents = value; }
|
||||
}
|
||||
|
||||
private Int64 _maxEvents = -1;
|
||||
public Int64 MaxEvents { get; set; } = -1;
|
||||
|
||||
/// <summary>
|
||||
/// ComputerName parameter.
|
||||
|
@ -222,17 +174,9 @@ namespace Microsoft.PowerShell.Commands
|
|||
ParameterSetName = "XmlQuerySet",
|
||||
HelpMessageBaseName = "GetEventResources",
|
||||
HelpMessageResourceId = "ComputerNameParamHelp")]
|
||||
|
||||
[ValidateNotNull]
|
||||
[Alias("Cn")]
|
||||
public string ComputerName
|
||||
{
|
||||
get { return _computerName; }
|
||||
|
||||
set { _computerName = value; }
|
||||
}
|
||||
|
||||
private string _computerName = string.Empty;
|
||||
public string ComputerName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Credential parameter.
|
||||
|
@ -245,14 +189,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
[Parameter(ParameterSetName = "XmlQuerySet")]
|
||||
[Parameter(ParameterSetName = "FileSet")]
|
||||
[Credential]
|
||||
public PSCredential Credential
|
||||
{
|
||||
get { return _credential; }
|
||||
|
||||
set { _credential = value; }
|
||||
}
|
||||
|
||||
private PSCredential _credential = PSCredential.Empty;
|
||||
public PSCredential Credential { get; set; } = PSCredential.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// FilterXPath parameter.
|
||||
|
@ -273,14 +210,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
ValueFromPipelineByPropertyName = false,
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
[ValidateNotNull]
|
||||
public string FilterXPath
|
||||
{
|
||||
get { return _filter; }
|
||||
|
||||
set { _filter = value; }
|
||||
}
|
||||
|
||||
private string _filter = "*";
|
||||
public string FilterXPath { get; set; } = "*";
|
||||
|
||||
/// <summary>
|
||||
/// FilterXml parameter.
|
||||
|
@ -292,20 +222,11 @@ namespace Microsoft.PowerShell.Commands
|
|||
ValueFromPipelineByPropertyName = false,
|
||||
ParameterSetName = "XmlQuerySet",
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
|
||||
[SuppressMessage("Microsoft.Design", "CA1059:MembersShouldNotExposeCertainConcreteTypes",
|
||||
Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.GetEvent.FilterXml",
|
||||
Justification = "An XmlDocument is required here because that is the type Powershell supports")]
|
||||
|
||||
public XmlDocument FilterXml
|
||||
{
|
||||
get { return _xmlQuery; }
|
||||
|
||||
set { _xmlQuery = value; }
|
||||
}
|
||||
|
||||
private XmlDocument _xmlQuery = null;
|
||||
public XmlDocument FilterXml { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// FilterHashtable parameter.
|
||||
|
@ -317,20 +238,11 @@ namespace Microsoft.PowerShell.Commands
|
|||
ValueFromPipelineByPropertyName = false,
|
||||
ParameterSetName = "HashQuerySet",
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays",
|
||||
Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.GetEvent.FilterHashtable",
|
||||
Justification = "A string[] is required here because that is the type Powershell supports")]
|
||||
|
||||
public Hashtable[] FilterHashtable
|
||||
{
|
||||
get { return _selector; }
|
||||
|
||||
set { _selector = value; }
|
||||
}
|
||||
|
||||
private Hashtable[] _selector;
|
||||
public Hashtable[] FilterHashtable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Force switch.
|
||||
|
@ -338,16 +250,8 @@ namespace Microsoft.PowerShell.Commands
|
|||
[Parameter(ParameterSetName = "ListLogSet")]
|
||||
[Parameter(ParameterSetName = "GetProviderSet")]
|
||||
[Parameter(ParameterSetName = "GetLogSet")]
|
||||
|
||||
[Parameter(ParameterSetName = "HashQuerySet")]
|
||||
public SwitchParameter Force
|
||||
{
|
||||
get { return _force; }
|
||||
|
||||
set { _force = value; }
|
||||
}
|
||||
|
||||
private SwitchParameter _force;
|
||||
public SwitchParameter Force { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Oldest switch.
|
||||
|
@ -355,7 +259,6 @@ namespace Microsoft.PowerShell.Commands
|
|||
[Parameter(ParameterSetName = "FileSet")]
|
||||
[Parameter(ParameterSetName = "GetProviderSet")]
|
||||
[Parameter(ParameterSetName = "GetLogSet")]
|
||||
|
||||
[Parameter(ParameterSetName = "HashQuerySet")]
|
||||
[Parameter(ParameterSetName = "XmlQuerySet")]
|
||||
public SwitchParameter Oldest
|
||||
|
@ -501,7 +404,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
//
|
||||
private void AccumulatePipelineLogNames()
|
||||
{
|
||||
_accumulatedLogNames.AddRange(_logName);
|
||||
_accumulatedLogNames.AddRange(LogName);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -510,7 +413,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
//
|
||||
private void AccumulatePipelineProviderNames()
|
||||
{
|
||||
_accumulatedProviderNames.AddRange(_logName);
|
||||
_accumulatedProviderNames.AddRange(LogName);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -519,7 +422,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
//
|
||||
private void AccumulatePipelineFileNames()
|
||||
{
|
||||
_accumulatedFileNames.AddRange(_logName);
|
||||
_accumulatedFileNames.AddRange(LogName);
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -544,7 +447,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
logQuery = new EventLogQuery(_logNamesMatchingWildcard[0], PathType.LogName, _filter);
|
||||
logQuery = new EventLogQuery(_logNamesMatchingWildcard[0], PathType.LogName, FilterXPath);
|
||||
}
|
||||
|
||||
logQuery.Session = eventLogSession;
|
||||
|
@ -561,7 +464,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
{
|
||||
using (EventLogSession eventLogSession = CreateSession())
|
||||
{
|
||||
FindProvidersByLogForWildcardPatterns(eventLogSession, _providerName);
|
||||
FindProvidersByLogForWildcardPatterns(eventLogSession, ProviderName);
|
||||
|
||||
if (_providersByLogMap.Count == 0)
|
||||
{
|
||||
|
@ -604,7 +507,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
{
|
||||
using (EventLogSession eventLogSession = CreateSession())
|
||||
{
|
||||
foreach (string logPattern in _listLog)
|
||||
foreach (string logPattern in ListLog)
|
||||
{
|
||||
bool bMatchFound = false;
|
||||
WildcardPattern wildLogPattern = new(logPattern, WildcardOptions.IgnoreCase);
|
||||
|
@ -660,7 +563,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
if (!bMatchFound)
|
||||
{
|
||||
string msg = _resourceMgr.GetString("NoMatchingLogsFound");
|
||||
Exception exc = new(string.Format(CultureInfo.InvariantCulture, msg, _computerName, logPattern));
|
||||
Exception exc = new(string.Format(CultureInfo.InvariantCulture, msg, ComputerName, logPattern));
|
||||
WriteError(new ErrorRecord(exc, "NoMatchingLogsFound", ErrorCategory.ObjectNotFound, null));
|
||||
}
|
||||
}
|
||||
|
@ -674,7 +577,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
{
|
||||
using (EventLogSession eventLogSession = CreateSession())
|
||||
{
|
||||
foreach (string provPattern in _listProvider)
|
||||
foreach (string provPattern in ListProvider)
|
||||
{
|
||||
bool bMatchFound = false;
|
||||
WildcardPattern wildProvPattern = new(provPattern, WildcardOptions.IgnoreCase);
|
||||
|
@ -707,7 +610,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
if (!bMatchFound)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("NoMatchingProvidersFound"),
|
||||
_computerName, provPattern);
|
||||
ComputerName, provPattern);
|
||||
Exception exc = new(msg);
|
||||
WriteError(new ErrorRecord(exc, "NoMatchingProvidersFound", ErrorCategory.ObjectNotFound, null));
|
||||
}
|
||||
|
@ -727,7 +630,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
//
|
||||
// Do minimal parsing of xmlQuery to determine if any direct channels or ETL files are in it.
|
||||
//
|
||||
XmlElement root = _xmlQuery.DocumentElement;
|
||||
XmlElement root = FilterXml.DocumentElement;
|
||||
XmlNodeList queryNodes = root.SelectNodes("//Query//Select");
|
||||
foreach (XmlNode queryNode in queryNodes)
|
||||
{
|
||||
|
@ -749,7 +652,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
}
|
||||
}
|
||||
|
||||
EventLogQuery logQuery = new(null, PathType.LogName, _xmlQuery.InnerXml);
|
||||
EventLogQuery logQuery = new(null, PathType.LogName, FilterXml.InnerXml);
|
||||
logQuery.Session = eventLogSession;
|
||||
logQuery.ReverseDirection = !_oldest;
|
||||
|
||||
|
@ -768,9 +671,9 @@ namespace Microsoft.PowerShell.Commands
|
|||
// At this point, _path array contains paths that might have wildcards,
|
||||
// environment variables or PS drives. Let's resolve those.
|
||||
//
|
||||
for (int i = 0; i < _path.Length; i++)
|
||||
for (int i = 0; i < Path.Length; i++)
|
||||
{
|
||||
StringCollection resolvedPaths = ValidateAndResolveFilePath(_path[i]);
|
||||
StringCollection resolvedPaths = ValidateAndResolveFilePath(Path[i]);
|
||||
foreach (string resolvedPath in resolvedPaths)
|
||||
{
|
||||
_resolvedPaths.Add(resolvedPath);
|
||||
|
@ -791,7 +694,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
logQuery = new EventLogQuery(_resolvedPaths[0], PathType.FilePath, _filter);
|
||||
logQuery = new EventLogQuery(_resolvedPaths[0], PathType.FilePath, FilterXPath);
|
||||
}
|
||||
|
||||
logQuery.Session = eventLogSession;
|
||||
|
@ -833,30 +736,30 @@ namespace Microsoft.PowerShell.Commands
|
|||
{
|
||||
EventLogSession eventLogSession = null;
|
||||
|
||||
if (_computerName == string.Empty)
|
||||
if (ComputerName == string.Empty)
|
||||
{
|
||||
// Set _computerName to "localhost" for future error messages,
|
||||
// but do not use it for the connection to avoid RPC overhead.
|
||||
_computerName = "localhost";
|
||||
ComputerName = "localhost";
|
||||
|
||||
if (_credential == PSCredential.Empty)
|
||||
if (Credential == PSCredential.Empty)
|
||||
{
|
||||
return new EventLogSession();
|
||||
}
|
||||
}
|
||||
else if (_credential == PSCredential.Empty)
|
||||
else if (Credential == PSCredential.Empty)
|
||||
{
|
||||
return new EventLogSession(_computerName);
|
||||
return new EventLogSession(ComputerName);
|
||||
}
|
||||
|
||||
// If we are here, either both computer name and credential were passed initially,
|
||||
// or credential only - we will use it with "localhost"
|
||||
|
||||
NetworkCredential netCred = (NetworkCredential)_credential;
|
||||
eventLogSession = new EventLogSession(_computerName,
|
||||
NetworkCredential netCred = (NetworkCredential)Credential;
|
||||
eventLogSession = new EventLogSession(ComputerName,
|
||||
netCred.Domain,
|
||||
netCred.UserName,
|
||||
_credential.Password,
|
||||
Credential.Password,
|
||||
SessionAuthentication.Default
|
||||
);
|
||||
//
|
||||
|
@ -894,7 +797,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
break;
|
||||
}
|
||||
|
||||
if (_maxEvents != -1 && numEvents >= _maxEvents)
|
||||
if (MaxEvents != -1 && numEvents >= MaxEvents)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
@ -974,7 +877,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
uint queryId = 0;
|
||||
foreach (string log in _logNamesMatchingWildcard)
|
||||
{
|
||||
result.AppendFormat(CultureInfo.InvariantCulture, queryTemplate, new object[] { queryId++, log, _filter });
|
||||
result.AppendFormat(CultureInfo.InvariantCulture, queryTemplate, new object[] { queryId++, log, FilterXPath });
|
||||
}
|
||||
|
||||
result.Append(queryListClose);
|
||||
|
@ -989,7 +892,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
foreach (string filePath in _resolvedPaths)
|
||||
{
|
||||
string properFilePath = filePrefix + filePath;
|
||||
result.AppendFormat(CultureInfo.InvariantCulture, queryTemplate, new object[] { queryId++, properFilePath, _filter });
|
||||
result.AppendFormat(CultureInfo.InvariantCulture, queryTemplate, new object[] { queryId++, properFilePath, FilterXPath });
|
||||
}
|
||||
|
||||
result.Append(queryListClose);
|
||||
|
@ -1111,7 +1014,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
|
||||
uint queryId = 0;
|
||||
|
||||
foreach (Hashtable hash in _selector)
|
||||
foreach (Hashtable hash in FilterHashtable)
|
||||
{
|
||||
string xpathString = string.Empty;
|
||||
string xpathStringSuppress = string.Empty;
|
||||
|
@ -1674,7 +1577,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
catch (EventLogNotFoundException)
|
||||
{
|
||||
string msg = _resourceMgr.GetString("NoMatchingLogsFound");
|
||||
Exception exc = new(string.Format(CultureInfo.InvariantCulture, msg, _computerName, logName));
|
||||
Exception exc = new(string.Format(CultureInfo.InvariantCulture, msg, ComputerName, logName));
|
||||
WriteError(new ErrorRecord(exc, "NoMatchingLogsFound", ErrorCategory.ObjectNotFound, logName));
|
||||
return false;
|
||||
}
|
||||
|
@ -1833,7 +1736,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
//
|
||||
private void CheckHashTablesForNullValues()
|
||||
{
|
||||
foreach (Hashtable hash in _selector)
|
||||
foreach (Hashtable hash in FilterHashtable)
|
||||
{
|
||||
foreach (string key in hash.Keys)
|
||||
{
|
||||
|
@ -1875,13 +1778,13 @@ namespace Microsoft.PowerShell.Commands
|
|||
{
|
||||
if (providers.Count == 0)
|
||||
{
|
||||
return _filter;
|
||||
return FilterXPath;
|
||||
}
|
||||
|
||||
string ret = _filter;
|
||||
string ret = FilterXPath;
|
||||
string predicate = BuildProvidersPredicate(providers);
|
||||
|
||||
if (_filter.Equals("*", StringComparison.OrdinalIgnoreCase))
|
||||
if (FilterXPath.Equals("*", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
ret += "[" + predicate + "]";
|
||||
}
|
||||
|
@ -1890,7 +1793,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
//
|
||||
// Extend the XPath provided in the _filter
|
||||
//
|
||||
int lastPredClose = _filter.LastIndexOf(']');
|
||||
int lastPredClose = FilterXPath.LastIndexOf(']');
|
||||
if (lastPredClose == -1)
|
||||
{
|
||||
ret += "[" + predicate + "]";
|
||||
|
@ -2113,7 +2016,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
if (!bMatched)
|
||||
{
|
||||
string msg = _resourceMgr.GetString("NoMatchingLogsFound");
|
||||
Exception exc = new(string.Format(CultureInfo.InvariantCulture, msg, _computerName, logPattern));
|
||||
Exception exc = new(string.Format(CultureInfo.InvariantCulture, msg, ComputerName, logPattern));
|
||||
WriteError(new ErrorRecord(exc, "NoMatchingLogsFound", ErrorCategory.ObjectNotFound, logPattern));
|
||||
}
|
||||
}
|
||||
|
@ -2150,7 +2053,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
if (!bMatched)
|
||||
{
|
||||
string msg = _resourceMgr.GetString("NoMatchingProvidersFound");
|
||||
Exception exc = new(string.Format(CultureInfo.InvariantCulture, msg, _computerName, provPattern));
|
||||
Exception exc = new(string.Format(CultureInfo.InvariantCulture, msg, ComputerName, provPattern));
|
||||
WriteError(new ErrorRecord(exc, "NoMatchingProvidersFound", ErrorCategory.ObjectNotFound, provPattern));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,20 +36,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
Position = 0,
|
||||
Mandatory = true,
|
||||
ParameterSetName = ParameterAttribute.AllParameterSets)]
|
||||
public string ProviderName
|
||||
{
|
||||
get
|
||||
{
|
||||
return _providerName;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_providerName = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string _providerName;
|
||||
public string ProviderName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id (EventId defined in manifest file)
|
||||
|
@ -109,20 +96,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays",
|
||||
Target = "Microsoft.PowerShell.Commands",
|
||||
Justification = "A string[] is required here because that is the type Powershell supports")]
|
||||
public object[] Payload
|
||||
{
|
||||
get
|
||||
{
|
||||
return _payload;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_payload = value;
|
||||
}
|
||||
}
|
||||
|
||||
private object[] _payload;
|
||||
public object[] Payload { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// BeginProcessing.
|
||||
|
@ -137,7 +111,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
|
||||
private void LoadProvider()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_providerName))
|
||||
if (string.IsNullOrEmpty(ProviderName))
|
||||
{
|
||||
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("ProviderNotSpecified")), "ProviderName");
|
||||
}
|
||||
|
@ -146,7 +120,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
{
|
||||
foreach (string providerName in session.GetProviderNames())
|
||||
{
|
||||
if (string.Equals(providerName, _providerName, StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(providerName, ProviderName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -165,7 +139,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
|
||||
if (_providerMetadata == null)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("NoProviderFound"), _providerName);
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("NoProviderFound"), ProviderName);
|
||||
throw new ArgumentException(msg);
|
||||
}
|
||||
}
|
||||
|
@ -188,7 +162,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
string msg = string.Format(CultureInfo.InvariantCulture,
|
||||
_resourceMgr.GetString("IncorrectEventId"),
|
||||
_id,
|
||||
_providerName);
|
||||
ProviderName);
|
||||
throw new EventWriteException(msg);
|
||||
}
|
||||
|
||||
|
@ -216,7 +190,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
_resourceMgr.GetString("IncorrectEventVersion"),
|
||||
_version,
|
||||
_id,
|
||||
_providerName);
|
||||
ProviderName);
|
||||
|
||||
throw new EventWriteException(msg);
|
||||
}
|
||||
|
@ -226,7 +200,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
string msg = string.Format(CultureInfo.InvariantCulture,
|
||||
_resourceMgr.GetString("VersionNotSpecified"),
|
||||
_id,
|
||||
_providerName);
|
||||
ProviderName);
|
||||
|
||||
throw new EventWriteException(msg);
|
||||
}
|
||||
|
@ -269,8 +243,8 @@ namespace Microsoft.PowerShell.Commands
|
|||
}
|
||||
}
|
||||
|
||||
if ((_payload == null && definedParameterCount != 0)
|
||||
|| ((_payload != null) && _payload.Length != definedParameterCount))
|
||||
if ((Payload == null && definedParameterCount != 0)
|
||||
|| ((Payload != null) && Payload.Length != definedParameterCount))
|
||||
{
|
||||
string warning = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("PayloadMismatch"), _id, emd.Template);
|
||||
WriteWarning(warning);
|
||||
|
@ -317,17 +291,17 @@ namespace Microsoft.PowerShell.Commands
|
|||
{
|
||||
EventDescriptor ed = _eventDescriptor.Value;
|
||||
|
||||
if (_payload != null && _payload.Length > 0)
|
||||
if (Payload != null && Payload.Length > 0)
|
||||
{
|
||||
for (int i = 0; i < _payload.Length; i++)
|
||||
for (int i = 0; i < Payload.Length; i++)
|
||||
{
|
||||
if (_payload[i] == null)
|
||||
if (Payload[i] == null)
|
||||
{
|
||||
_payload[i] = string.Empty;
|
||||
Payload[i] = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
provider.WriteEvent(in ed, _payload);
|
||||
provider.WriteEvent(in ed, Payload);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue