mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
commit
9742b64170
953 files changed
+71191
-65001
No files matched your search
@@ -1,9 +1,9 @@
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
|
||||
[assembly:AssemblyFileVersionAttribute("3.0.0.0")]
|
||||
[assembly:AssemblyVersion("3.0.0.0")]
|
||||
[assembly: AssemblyFileVersionAttribute("3.0.0.0")]
|
||||
[assembly: AssemblyVersion("3.0.0.0")]
|
||||
|
||||
[assembly:AssemblyCulture("")]
|
||||
[assembly:NeutralResourcesLanguage("en-US")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: NeutralResourcesLanguage("en-US")]
|
||||
|
||||
@@ -8,7 +8,6 @@ using System.Reflection;
|
||||
|
||||
namespace Microsoft.PowerShell.Commands.Diagnostics.Common
|
||||
{
|
||||
|
||||
internal static class CommonUtilities
|
||||
{
|
||||
#if !CORECLR
|
||||
@@ -16,27 +15,27 @@ namespace Microsoft.PowerShell.Commands.Diagnostics.Common
|
||||
// StringArrayToString helper converts a string array into a comma-separated string.
|
||||
// Note this has only limited use, individual strings cannot have commas.
|
||||
//
|
||||
public static string StringArrayToString (IEnumerable input)
|
||||
public static string StringArrayToString(IEnumerable input)
|
||||
{
|
||||
string ret = "";
|
||||
foreach (string element in input)
|
||||
{
|
||||
ret += element + ", ";
|
||||
{
|
||||
ret += element + ", ";
|
||||
}
|
||||
|
||||
ret = ret.TrimEnd();
|
||||
ret = ret.TrimEnd(',');
|
||||
ret = ret.TrimEnd(',');
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
const uint FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
|
||||
const uint FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
|
||||
const uint FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
|
||||
const uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
|
||||
const uint FORMAT_MESSAGE_FROM_HMODULE = 0x00000800;
|
||||
|
||||
|
||||
private const uint FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
|
||||
private const uint FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
|
||||
private const uint FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
|
||||
private const uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002;
|
||||
private const uint FORMAT_MESSAGE_FROM_HMODULE = 0x00000800;
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
private static extern uint FormatMessage(uint dwFlags, IntPtr lpSource,
|
||||
uint dwMessageId, uint dwLanguageId,
|
||||
@@ -58,15 +57,15 @@ namespace Microsoft.PowerShell.Commands.Diagnostics.Common
|
||||
[DllImport("kernel32.dll", EntryPoint = "GetUserDefaultLangID", CallingConvention = CallingConvention.Winapi, SetLastError = true)]
|
||||
private static extern ushort GetUserDefaultLangID();
|
||||
|
||||
|
||||
|
||||
public static uint FormatMessageFromModule(uint lastError, string moduleName, out String msg)
|
||||
{
|
||||
Debug.Assert (!string.IsNullOrEmpty(moduleName));
|
||||
Debug.Assert(!string.IsNullOrEmpty(moduleName));
|
||||
|
||||
uint formatError = 0;
|
||||
msg = String.Empty;
|
||||
IntPtr moduleHandle = IntPtr.Zero;
|
||||
|
||||
|
||||
moduleHandle = LoadLibraryEx(moduleName, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE);
|
||||
if (moduleHandle == IntPtr.Zero)
|
||||
{
|
||||
|
||||
@@ -6,55 +6,50 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
|
||||
|
||||
namespace Microsoft.PowerShell.Commands.GetCounter
|
||||
{
|
||||
|
||||
|
||||
public class CounterFileInfo
|
||||
{
|
||||
internal CounterFileInfo(DateTime oldestRecord,
|
||||
DateTime newestRecord,
|
||||
UInt32 sampleCount)
|
||||
public class CounterFileInfo
|
||||
{
|
||||
|
||||
_oldestRecord = oldestRecord;
|
||||
_newestRecord = newestRecord;
|
||||
_sampleCount = sampleCount;
|
||||
}
|
||||
|
||||
internal CounterFileInfo(){}
|
||||
|
||||
public DateTime OldestRecord
|
||||
{
|
||||
get
|
||||
internal CounterFileInfo(DateTime oldestRecord,
|
||||
DateTime newestRecord,
|
||||
UInt32 sampleCount)
|
||||
{
|
||||
return _oldestRecord;
|
||||
}
|
||||
}
|
||||
private DateTime _oldestRecord = DateTime.MinValue;
|
||||
|
||||
public DateTime NewestRecord
|
||||
{
|
||||
get
|
||||
{
|
||||
return _newestRecord;
|
||||
_oldestRecord = oldestRecord;
|
||||
_newestRecord = newestRecord;
|
||||
_sampleCount = sampleCount;
|
||||
}
|
||||
}
|
||||
private DateTime _newestRecord = DateTime.MaxValue;
|
||||
|
||||
public UInt32 SampleCount
|
||||
{
|
||||
get
|
||||
|
||||
internal CounterFileInfo() { }
|
||||
|
||||
public DateTime OldestRecord
|
||||
{
|
||||
return _sampleCount;
|
||||
get
|
||||
{
|
||||
return _oldestRecord;
|
||||
}
|
||||
}
|
||||
private DateTime _oldestRecord = DateTime.MinValue;
|
||||
|
||||
public DateTime NewestRecord
|
||||
{
|
||||
get
|
||||
{
|
||||
return _newestRecord;
|
||||
}
|
||||
}
|
||||
private DateTime _newestRecord = DateTime.MaxValue;
|
||||
|
||||
public UInt32 SampleCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return _sampleCount;
|
||||
}
|
||||
}
|
||||
private UInt32 _sampleCount = 0;
|
||||
}
|
||||
private UInt32 _sampleCount = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,23 +6,22 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
using System.Resources;
|
||||
using Microsoft.Powershell.Commands.GetCounter.PdhNative;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
|
||||
|
||||
namespace Microsoft.PowerShell.Commands.GetCounter
|
||||
{
|
||||
|
||||
public class PerformanceCounterSample
|
||||
{
|
||||
internal PerformanceCounterSample()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
internal PerformanceCounterSample(string path,
|
||||
string instanceName,
|
||||
double cookedValue,
|
||||
@@ -36,109 +35,106 @@ 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;
|
||||
_multiCount = multiCount;
|
||||
_counterType = counterType;
|
||||
_defaultScale = defaultScale;
|
||||
_timeBase = timeBase;
|
||||
_timeStamp = timeStamp;
|
||||
_timeStamp100nSec = timeStamp100nSec;
|
||||
_status = status;
|
||||
}
|
||||
|
||||
|
||||
public string Path
|
||||
{
|
||||
get {return _path;}
|
||||
set {_path = value;}
|
||||
get { return _path; }
|
||||
set { _path = value; }
|
||||
}
|
||||
private string _path = "";
|
||||
|
||||
|
||||
public string InstanceName
|
||||
{
|
||||
get {return _instanceName;}
|
||||
set {_instanceName = value;}
|
||||
get { return _instanceName; }
|
||||
set { _instanceName = value; }
|
||||
}
|
||||
private string _instanceName = "";
|
||||
|
||||
|
||||
public double CookedValue
|
||||
{
|
||||
get {return _cookedValue;}
|
||||
set {_cookedValue = value;}
|
||||
get { return _cookedValue; }
|
||||
set { _cookedValue = value; }
|
||||
}
|
||||
private double _cookedValue = 0;
|
||||
|
||||
public UInt64 RawValue
|
||||
{
|
||||
get {return _rawValue;}
|
||||
set {_rawValue = value;}
|
||||
get { return _rawValue; }
|
||||
set { _rawValue = value; }
|
||||
}
|
||||
private UInt64 _rawValue = 0;
|
||||
|
||||
public UInt64 SecondValue
|
||||
{
|
||||
get {return _secondValue;}
|
||||
set {_secondValue = value;}
|
||||
get { return _secondValue; }
|
||||
set { _secondValue = value; }
|
||||
}
|
||||
private UInt64 _secondValue = 0;
|
||||
|
||||
|
||||
public uint MultipleCount
|
||||
{
|
||||
get {return _multiCount;}
|
||||
set {_multiCount = value;}
|
||||
get { return _multiCount; }
|
||||
set { _multiCount = value; }
|
||||
}
|
||||
private uint _multiCount = 0;
|
||||
|
||||
public PerformanceCounterType CounterType
|
||||
{
|
||||
get {return _counterType;}
|
||||
set {_counterType = value;}
|
||||
get { return _counterType; }
|
||||
set { _counterType = value; }
|
||||
}
|
||||
private PerformanceCounterType _counterType = 0;
|
||||
|
||||
public DateTime Timestamp
|
||||
{
|
||||
get {return _timeStamp;}
|
||||
set {_timeStamp = value;}
|
||||
get { return _timeStamp; }
|
||||
set { _timeStamp = value; }
|
||||
}
|
||||
private DateTime _timeStamp = DateTime.MinValue;
|
||||
|
||||
|
||||
|
||||
public UInt64 Timestamp100NSec
|
||||
{
|
||||
get {return _timeStamp100nSec;}
|
||||
set {_timeStamp100nSec = value;}
|
||||
get { return _timeStamp100nSec; }
|
||||
set { _timeStamp100nSec = value; }
|
||||
}
|
||||
private UInt64 _timeStamp100nSec = 0;
|
||||
|
||||
public UInt32 Status
|
||||
{
|
||||
get {return _status;}
|
||||
set {_status = value;}
|
||||
get { return _status; }
|
||||
set { _status = value; }
|
||||
}
|
||||
private UInt32 _status = 0;
|
||||
|
||||
public UInt32 DefaultScale
|
||||
{
|
||||
get {return _defaultScale;}
|
||||
set {_defaultScale = value;}
|
||||
get { return _defaultScale; }
|
||||
set { _defaultScale = value; }
|
||||
}
|
||||
private UInt32 _defaultScale = 0;
|
||||
|
||||
public UInt64 TimeBase
|
||||
{
|
||||
get {return _timeBase;}
|
||||
set {_timeBase = value;}
|
||||
get { return _timeBase; }
|
||||
set { _timeBase = value; }
|
||||
}
|
||||
private UInt64 _timeBase = 0;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class PerformanceCounterSampleSet
|
||||
@@ -148,33 +144,32 @@ namespace Microsoft.PowerShell.Commands.GetCounter
|
||||
_resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager();
|
||||
}
|
||||
|
||||
internal PerformanceCounterSampleSet (DateTime timeStamp,
|
||||
internal PerformanceCounterSampleSet(DateTime timeStamp,
|
||||
PerformanceCounterSample[] counterSamples,
|
||||
bool firstSet) : this()
|
||||
{
|
||||
_timeStamp = timeStamp;
|
||||
_counterSamples = counterSamples;
|
||||
_counterSamples = counterSamples;
|
||||
}
|
||||
|
||||
public DateTime Timestamp
|
||||
{
|
||||
get {return _timeStamp;}
|
||||
set {_timeStamp = value;}
|
||||
get { return _timeStamp; }
|
||||
set { _timeStamp = value; }
|
||||
}
|
||||
private DateTime _timeStamp = 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")]
|
||||
Justification = "A string[] is required here because that is the type Powershell supports")]
|
||||
public PerformanceCounterSample[] CounterSamples
|
||||
{
|
||||
get {return _counterSamples;}
|
||||
set {_counterSamples = value;}
|
||||
get { return _counterSamples; }
|
||||
set { _counterSamples = value; }
|
||||
}
|
||||
private PerformanceCounterSample[] _counterSamples = null;
|
||||
|
||||
private ResourceManager _resourceMgr = null;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,130 +6,127 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
|
||||
|
||||
namespace Microsoft.PowerShell.Commands.GetCounter
|
||||
{
|
||||
|
||||
public class CounterSet
|
||||
{
|
||||
internal CounterSet(string setName,
|
||||
string machineName,
|
||||
PerformanceCounterCategoryType categoryType,
|
||||
string setHelp,
|
||||
ref Dictionary<string, string[]> counterInstanceMapping)
|
||||
public class CounterSet
|
||||
{
|
||||
_counterSetName = setName;
|
||||
if (machineName == null || machineName.Length == 0)
|
||||
internal CounterSet(string setName,
|
||||
string machineName,
|
||||
PerformanceCounterCategoryType categoryType,
|
||||
string setHelp,
|
||||
ref Dictionary<string, string[]> counterInstanceMapping)
|
||||
{
|
||||
machineName = ".";
|
||||
}
|
||||
else
|
||||
{
|
||||
_machineName = machineName;
|
||||
if (!_machineName.StartsWith(@"\\", StringComparison.OrdinalIgnoreCase))
|
||||
_counterSetName = setName;
|
||||
if (machineName == null || machineName.Length == 0)
|
||||
{
|
||||
_machineName = @"\\" + _machineName;
|
||||
machineName = ".";
|
||||
}
|
||||
else
|
||||
{
|
||||
_machineName = machineName;
|
||||
if (!_machineName.StartsWith(@"\\", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_machineName = @"\\" + _machineName;
|
||||
}
|
||||
}
|
||||
_counterSetType = categoryType;
|
||||
_description = setHelp;
|
||||
_counterInstanceMapping = counterInstanceMapping;
|
||||
}
|
||||
|
||||
public string CounterSetName
|
||||
{
|
||||
get
|
||||
{
|
||||
return _counterSetName;
|
||||
}
|
||||
}
|
||||
_counterSetType = categoryType;
|
||||
_description = setHelp;
|
||||
_counterInstanceMapping = counterInstanceMapping;
|
||||
}
|
||||
|
||||
public string CounterSetName
|
||||
{
|
||||
get
|
||||
{
|
||||
return _counterSetName;
|
||||
}
|
||||
}
|
||||
private string _counterSetName = "";
|
||||
private string _counterSetName = "";
|
||||
|
||||
public string MachineName
|
||||
{
|
||||
get
|
||||
public string MachineName
|
||||
{
|
||||
return _machineName;
|
||||
}
|
||||
}
|
||||
private string _machineName = ".";
|
||||
|
||||
public PerformanceCounterCategoryType CounterSetType
|
||||
{
|
||||
get
|
||||
{
|
||||
return _counterSetType;
|
||||
}
|
||||
}
|
||||
private PerformanceCounterCategoryType _counterSetType;
|
||||
|
||||
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return _description;
|
||||
}
|
||||
}
|
||||
private string _description = "";
|
||||
|
||||
internal Dictionary<string, string[]> CounterInstanceMapping
|
||||
{
|
||||
get
|
||||
{
|
||||
return _counterInstanceMapping;
|
||||
}
|
||||
}
|
||||
private Dictionary<string, string[]> _counterInstanceMapping;
|
||||
|
||||
public StringCollection Paths
|
||||
{
|
||||
get
|
||||
{
|
||||
StringCollection retColl = new StringCollection();
|
||||
foreach (string counterName in this.CounterInstanceMapping.Keys)
|
||||
get
|
||||
{
|
||||
string path;
|
||||
if (CounterInstanceMapping[counterName].Length != 0)
|
||||
{
|
||||
path = (_machineName == ".") ?
|
||||
("\\" + _counterSetName + "(*)\\" + counterName) :
|
||||
(_machineName + "\\" + _counterSetName + "(*)\\" + counterName);
|
||||
}
|
||||
else
|
||||
{
|
||||
path = (_machineName == ".") ?
|
||||
("\\" + _counterSetName + "\\" + counterName) :
|
||||
(_machineName + "\\" + _counterSetName + "\\" + counterName);
|
||||
}
|
||||
retColl.Add(path);
|
||||
return _machineName;
|
||||
}
|
||||
|
||||
return retColl;
|
||||
}
|
||||
}
|
||||
private string _machineName = ".";
|
||||
|
||||
public StringCollection PathsWithInstances
|
||||
{
|
||||
get
|
||||
public PerformanceCounterCategoryType CounterSetType
|
||||
{
|
||||
StringCollection retColl = new StringCollection();
|
||||
foreach (string counterName in CounterInstanceMapping.Keys)
|
||||
get
|
||||
{
|
||||
foreach (string instanceName in CounterInstanceMapping[counterName])
|
||||
return _counterSetType;
|
||||
}
|
||||
}
|
||||
private PerformanceCounterCategoryType _counterSetType;
|
||||
|
||||
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return _description;
|
||||
}
|
||||
}
|
||||
private string _description = "";
|
||||
|
||||
internal Dictionary<string, string[]> CounterInstanceMapping
|
||||
{
|
||||
get
|
||||
{
|
||||
return _counterInstanceMapping;
|
||||
}
|
||||
}
|
||||
private Dictionary<string, string[]> _counterInstanceMapping;
|
||||
|
||||
public StringCollection Paths
|
||||
{
|
||||
get
|
||||
{
|
||||
StringCollection retColl = new StringCollection();
|
||||
foreach (string counterName in this.CounterInstanceMapping.Keys)
|
||||
{
|
||||
string path = (_machineName == ".") ?
|
||||
("\\" + _counterSetName + "(" + instanceName + ")\\" + counterName) :
|
||||
(_machineName + "\\" + _counterSetName + "(" + instanceName + ")\\" + counterName);
|
||||
string path;
|
||||
if (CounterInstanceMapping[counterName].Length != 0)
|
||||
{
|
||||
path = (_machineName == ".") ?
|
||||
("\\" + _counterSetName + "(*)\\" + counterName) :
|
||||
(_machineName + "\\" + _counterSetName + "(*)\\" + counterName);
|
||||
}
|
||||
else
|
||||
{
|
||||
path = (_machineName == ".") ?
|
||||
("\\" + _counterSetName + "\\" + counterName) :
|
||||
(_machineName + "\\" + _counterSetName + "\\" + counterName);
|
||||
}
|
||||
retColl.Add(path);
|
||||
}
|
||||
|
||||
return retColl;
|
||||
}
|
||||
}
|
||||
|
||||
public StringCollection PathsWithInstances
|
||||
{
|
||||
get
|
||||
{
|
||||
StringCollection retColl = new StringCollection();
|
||||
foreach (string counterName in CounterInstanceMapping.Keys)
|
||||
{
|
||||
foreach (string instanceName in CounterInstanceMapping[counterName])
|
||||
{
|
||||
string path = (_machineName == ".") ?
|
||||
("\\" + _counterSetName + "(" + instanceName + ")\\" + counterName) :
|
||||
(_machineName + "\\" + _counterSetName + "(" + instanceName + ")\\" + counterName);
|
||||
retColl.Add(path);
|
||||
}
|
||||
}
|
||||
return retColl;
|
||||
}
|
||||
return retColl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ using System.Text;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Net;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using System.Globalization;
|
||||
@@ -30,347 +30,342 @@ using Microsoft.PowerShell.Commands.Diagnostics.Common;
|
||||
|
||||
namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
|
||||
///
|
||||
/// Class that implements the Get-Counter cmdlet.
|
||||
///
|
||||
[Cmdlet("Export", "Counter", DefaultParameterSetName = "ExportCounterSet", HelpUri = "http://go.microsoft.com/fwlink/?LinkID=138337")]
|
||||
public sealed class ExportCounterCommand : PSCmdlet
|
||||
{
|
||||
//
|
||||
// Path parameter
|
||||
//
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
Position = 0,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
[Alias("PSPath")]
|
||||
|
||||
public string Path
|
||||
{
|
||||
get {return _path;}
|
||||
set {_path = value;}
|
||||
}
|
||||
private string _path;
|
||||
private string _resolvedPath;
|
||||
|
||||
|
||||
//
|
||||
// Format parameter.
|
||||
// Valid strings are "blg", "csv", "tsv" (case-insensitive).
|
||||
//
|
||||
[Parameter(
|
||||
Mandatory = false,
|
||||
ValueFromPipeline = false,
|
||||
ValueFromPipelineByPropertyName = false,
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
[ValidateNotNull]
|
||||
public string FileFormat
|
||||
{
|
||||
get {return _format;}
|
||||
set {_format = value;}
|
||||
}
|
||||
private string _format = "BLG";
|
||||
|
||||
|
||||
|
||||
//
|
||||
// MaxSize parameter
|
||||
// Maximum output file size, in megabytes.
|
||||
//
|
||||
[Parameter(
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
public UInt32 MaxSize
|
||||
{
|
||||
get {return _maxSize;}
|
||||
set {_maxSize = value;}
|
||||
}
|
||||
private UInt32 _maxSize = 0;
|
||||
|
||||
|
||||
//
|
||||
// InputObject parameter
|
||||
//
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays",
|
||||
Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.ExportCounterCommand.InputObject",
|
||||
Justification="A PerformanceCounterSampleSet[] is required here because Powershell supports arrays natively.")]
|
||||
public PerformanceCounterSampleSet[] InputObject
|
||||
{
|
||||
get {return _counterSampleSets;}
|
||||
set {_counterSampleSets = value;}
|
||||
}
|
||||
private PerformanceCounterSampleSet[] _counterSampleSets = new PerformanceCounterSampleSet[0];
|
||||
|
||||
|
||||
//
|
||||
// Force switch
|
||||
//
|
||||
[Parameter(
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
public SwitchParameter Force
|
||||
{
|
||||
get {return _force;}
|
||||
set{_force = value;}
|
||||
}
|
||||
private SwitchParameter _force;
|
||||
|
||||
//
|
||||
// Circular switch
|
||||
//
|
||||
[Parameter(
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
public SwitchParameter Circular
|
||||
{
|
||||
get {return _circular;}
|
||||
set{_circular = value;}
|
||||
}
|
||||
private SwitchParameter _circular;
|
||||
|
||||
|
||||
|
||||
private ResourceManager _resourceMgr = null;
|
||||
|
||||
private PdhHelper _pdhHelper = null;
|
||||
|
||||
private bool _stopping = false;
|
||||
|
||||
private bool _queryInitialized = false;
|
||||
|
||||
private PdhLogFileType _outputFormat = PdhLogFileType.PDH_LOG_TYPE_BINARY;
|
||||
|
||||
//
|
||||
// BeginProcessing() is invoked once per pipeline
|
||||
//
|
||||
protected override void BeginProcessing()
|
||||
{
|
||||
|
||||
_resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager();
|
||||
|
||||
//
|
||||
// Determine the OS version: this cmdlet requires Windows 7
|
||||
// because it uses new Pdh functionality.
|
||||
//
|
||||
if (System.Environment.OSVersion.Version.Major < 6 ||
|
||||
(System.Environment.OSVersion.Version.Major == 6 && System.Environment.OSVersion.Version.Minor < 1))
|
||||
{
|
||||
string msg = _resourceMgr.GetString("ExportCtrWin7Required");
|
||||
Exception exc = new Exception(msg);
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "ExportCtrWin7Required", ErrorCategory.NotImplemented, null));
|
||||
}
|
||||
|
||||
_pdhHelper = new PdhHelper(System.Environment.OSVersion.Version.Major < 6);
|
||||
|
||||
//
|
||||
// Validate the Format and CounterSamples arguments
|
||||
//
|
||||
ValidateFormat();
|
||||
|
||||
if (Circular.IsPresent && _maxSize == 0)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterCircularNoMaxSize"));
|
||||
Exception exc = new Exception (msg);
|
||||
WriteError(new ErrorRecord(exc, "CounterCircularNoMaxSize", ErrorCategory.InvalidResult, null));
|
||||
}
|
||||
|
||||
uint res = _pdhHelper.ConnectToDataSource();
|
||||
if (res != 0)
|
||||
{
|
||||
ReportPdhError(res, true);
|
||||
}
|
||||
|
||||
res = _pdhHelper.OpenQuery();
|
||||
if (res != 0)
|
||||
{
|
||||
ReportPdhError(res, true);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// EndProcessing() is invoked once per pipeline
|
||||
//
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
_pdhHelper.Dispose();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Handle Control-C
|
||||
/// Class that implements the Get-Counter cmdlet.
|
||||
///
|
||||
protected override void StopProcessing()
|
||||
[Cmdlet("Export", "Counter", DefaultParameterSetName = "ExportCounterSet", HelpUri = "http://go.microsoft.com/fwlink/?LinkID=138337")]
|
||||
public sealed class ExportCounterCommand : PSCmdlet
|
||||
{
|
||||
_stopping = true;
|
||||
_pdhHelper.Dispose();
|
||||
}
|
||||
//
|
||||
// Path parameter
|
||||
//
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
Position = 0,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
[Alias("PSPath")]
|
||||
|
||||
//
|
||||
// ProcessRecord() override.
|
||||
// This is the main entry point for the cmdlet.
|
||||
// When counter data comes from the pipeline, this gets invoked for each pipelined object.
|
||||
// When it's passed in as an argument, ProcessRecord() is called once for the entire _counterSampleSets array.
|
||||
//
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
Debug.Assert(_counterSampleSets.Length != 0 && _counterSampleSets[0] != null);
|
||||
|
||||
ResolvePath();
|
||||
|
||||
uint res = 0;
|
||||
|
||||
if (!_queryInitialized)
|
||||
public string Path
|
||||
{
|
||||
if (_format.ToLower(CultureInfo.InvariantCulture).Equals("blg"))
|
||||
get { return _path; }
|
||||
set { _path = value; }
|
||||
}
|
||||
private string _path;
|
||||
private string _resolvedPath;
|
||||
|
||||
|
||||
//
|
||||
// Format parameter.
|
||||
// Valid strings are "blg", "csv", "tsv" (case-insensitive).
|
||||
//
|
||||
[Parameter(
|
||||
Mandatory = false,
|
||||
ValueFromPipeline = false,
|
||||
ValueFromPipelineByPropertyName = false,
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
[ValidateNotNull]
|
||||
public string FileFormat
|
||||
{
|
||||
get { return _format; }
|
||||
set { _format = value; }
|
||||
}
|
||||
private string _format = "BLG";
|
||||
|
||||
|
||||
|
||||
//
|
||||
// MaxSize parameter
|
||||
// Maximum output file size, in megabytes.
|
||||
//
|
||||
[Parameter(
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
public UInt32 MaxSize
|
||||
{
|
||||
get { return _maxSize; }
|
||||
set { _maxSize = value; }
|
||||
}
|
||||
private UInt32 _maxSize = 0;
|
||||
|
||||
|
||||
//
|
||||
// InputObject parameter
|
||||
//
|
||||
[Parameter(
|
||||
Mandatory = true,
|
||||
ValueFromPipeline = true,
|
||||
ValueFromPipelineByPropertyName = true,
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays",
|
||||
Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.ExportCounterCommand.InputObject",
|
||||
Justification = "A PerformanceCounterSampleSet[] is required here because Powershell supports arrays natively.")]
|
||||
public PerformanceCounterSampleSet[] InputObject
|
||||
{
|
||||
get { return _counterSampleSets; }
|
||||
set { _counterSampleSets = value; }
|
||||
}
|
||||
private PerformanceCounterSampleSet[] _counterSampleSets = new PerformanceCounterSampleSet[0];
|
||||
|
||||
|
||||
//
|
||||
// Force switch
|
||||
//
|
||||
[Parameter(
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
public SwitchParameter Force
|
||||
{
|
||||
get { return _force; }
|
||||
set { _force = value; }
|
||||
}
|
||||
private SwitchParameter _force;
|
||||
|
||||
//
|
||||
// Circular switch
|
||||
//
|
||||
[Parameter(
|
||||
HelpMessageBaseName = "GetEventResources")]
|
||||
public SwitchParameter Circular
|
||||
{
|
||||
get { return _circular; }
|
||||
set { _circular = value; }
|
||||
}
|
||||
private SwitchParameter _circular;
|
||||
|
||||
|
||||
|
||||
private ResourceManager _resourceMgr = null;
|
||||
|
||||
private PdhHelper _pdhHelper = null;
|
||||
|
||||
private bool _stopping = false;
|
||||
|
||||
private bool _queryInitialized = false;
|
||||
|
||||
private PdhLogFileType _outputFormat = PdhLogFileType.PDH_LOG_TYPE_BINARY;
|
||||
|
||||
//
|
||||
// BeginProcessing() is invoked once per pipeline
|
||||
//
|
||||
protected override void BeginProcessing()
|
||||
{
|
||||
_resourceMgr = Microsoft.PowerShell.Commands.Diagnostics.Common.CommonUtilities.GetResourceManager();
|
||||
|
||||
//
|
||||
// Determine the OS version: this cmdlet requires Windows 7
|
||||
// because it uses new Pdh functionality.
|
||||
//
|
||||
if (System.Environment.OSVersion.Version.Major < 6 ||
|
||||
(System.Environment.OSVersion.Version.Major == 6 && System.Environment.OSVersion.Version.Minor < 1))
|
||||
{
|
||||
res = _pdhHelper.AddRelogCounters(_counterSampleSets[0]);
|
||||
string msg = _resourceMgr.GetString("ExportCtrWin7Required");
|
||||
Exception exc = new Exception(msg);
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "ExportCtrWin7Required", ErrorCategory.NotImplemented, null));
|
||||
}
|
||||
else
|
||||
|
||||
_pdhHelper = new PdhHelper(System.Environment.OSVersion.Version.Major < 6);
|
||||
|
||||
//
|
||||
// Validate the Format and CounterSamples arguments
|
||||
//
|
||||
ValidateFormat();
|
||||
|
||||
if (Circular.IsPresent && _maxSize == 0)
|
||||
{
|
||||
res = _pdhHelper.AddRelogCountersPreservingPaths(_counterSampleSets[0]);
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterCircularNoMaxSize"));
|
||||
Exception exc = new Exception(msg);
|
||||
WriteError(new ErrorRecord(exc, "CounterCircularNoMaxSize", ErrorCategory.InvalidResult, null));
|
||||
}
|
||||
|
||||
uint res = _pdhHelper.ConnectToDataSource();
|
||||
if (res != 0)
|
||||
{
|
||||
ReportPdhError(res, true);
|
||||
}
|
||||
|
||||
res = _pdhHelper.OpenLogForWriting(_resolvedPath, _outputFormat, Force.IsPresent, _maxSize * 1024 * 1024, Circular.IsPresent, null);
|
||||
if (res == PdhResults.PDH_FILE_ALREADY_EXISTS)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterFileExists"), _resolvedPath);
|
||||
Exception exc = new Exception (msg);
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "CounterFileExists", ErrorCategory.InvalidResult, null));
|
||||
}
|
||||
else if (res == PdhResults.PDH_LOG_FILE_CREATE_ERROR)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("FileCreateFailed"), _resolvedPath);
|
||||
Exception exc = new Exception (msg);
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "FileCreateFailed", ErrorCategory.InvalidResult, null));
|
||||
|
||||
}
|
||||
else if (res == PdhResults.PDH_LOG_FILE_OPEN_ERROR)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("FileOpenFailed"), _resolvedPath);
|
||||
Exception exc = new Exception (msg);
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "FileOpenFailed", ErrorCategory.InvalidResult, null));
|
||||
}
|
||||
else if (res != 0)
|
||||
res = _pdhHelper.OpenQuery();
|
||||
if (res != 0)
|
||||
{
|
||||
ReportPdhError(res, true);
|
||||
}
|
||||
}
|
||||
|
||||
_queryInitialized = true;
|
||||
//
|
||||
// EndProcessing() is invoked once per pipeline
|
||||
//
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
_pdhHelper.Dispose();
|
||||
}
|
||||
|
||||
|
||||
foreach (PerformanceCounterSampleSet set in _counterSampleSets)
|
||||
///
|
||||
/// Handle Control-C
|
||||
///
|
||||
protected override void StopProcessing()
|
||||
{
|
||||
_pdhHelper.ResetRelogValues();
|
||||
|
||||
foreach (PerformanceCounterSample sample in set.CounterSamples)
|
||||
_stopping = true;
|
||||
_pdhHelper.Dispose();
|
||||
}
|
||||
|
||||
//
|
||||
// ProcessRecord() override.
|
||||
// This is the main entry point for the cmdlet.
|
||||
// When counter data comes from the pipeline, this gets invoked for each pipelined object.
|
||||
// When it's passed in as an argument, ProcessRecord() is called once for the entire _counterSampleSets array.
|
||||
//
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
Debug.Assert(_counterSampleSets.Length != 0 && _counterSampleSets[0] != null);
|
||||
|
||||
ResolvePath();
|
||||
|
||||
uint res = 0;
|
||||
|
||||
if (!_queryInitialized)
|
||||
{
|
||||
bool bUnknownKey = false;
|
||||
res = _pdhHelper.SetCounterValue(sample, out bUnknownKey);
|
||||
if (bUnknownKey)
|
||||
if (_format.ToLower(CultureInfo.InvariantCulture).Equals("blg"))
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterExportSampleNotInInitialSet"), sample.Path, _resolvedPath);
|
||||
Exception exc = new Exception (msg);
|
||||
WriteError(new ErrorRecord(exc, "CounterExportSampleNotInInitialSet", ErrorCategory.InvalidResult, null));
|
||||
res = _pdhHelper.AddRelogCounters(_counterSampleSets[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
res = _pdhHelper.AddRelogCountersPreservingPaths(_counterSampleSets[0]);
|
||||
}
|
||||
if (res != 0)
|
||||
{
|
||||
ReportPdhError(res, true);
|
||||
}
|
||||
|
||||
res = _pdhHelper.OpenLogForWriting(_resolvedPath, _outputFormat, Force.IsPresent, _maxSize * 1024 * 1024, Circular.IsPresent, null);
|
||||
if (res == PdhResults.PDH_FILE_ALREADY_EXISTS)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterFileExists"), _resolvedPath);
|
||||
Exception exc = new Exception(msg);
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "CounterFileExists", ErrorCategory.InvalidResult, null));
|
||||
}
|
||||
else if (res == PdhResults.PDH_LOG_FILE_CREATE_ERROR)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("FileCreateFailed"), _resolvedPath);
|
||||
Exception exc = new Exception(msg);
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "FileCreateFailed", ErrorCategory.InvalidResult, null));
|
||||
}
|
||||
else if (res == PdhResults.PDH_LOG_FILE_OPEN_ERROR)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("FileOpenFailed"), _resolvedPath);
|
||||
Exception exc = new Exception(msg);
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "FileOpenFailed", ErrorCategory.InvalidResult, null));
|
||||
}
|
||||
else if (res != 0)
|
||||
{
|
||||
ReportPdhError(res, true);
|
||||
}
|
||||
|
||||
}
|
||||
res = _pdhHelper.WriteRelogSample(set.Timestamp);
|
||||
if (res != 0)
|
||||
{
|
||||
ReportPdhError(res, true);
|
||||
_queryInitialized = true;
|
||||
}
|
||||
|
||||
if (_stopping)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateFormat() helper.
|
||||
// Validates Format argument: only "BLG", "TSV" and "CSV" are valid strings (case-insensitive)
|
||||
//
|
||||
private void ValidateFormat()
|
||||
{
|
||||
switch (_format.ToLower(CultureInfo.InvariantCulture))
|
||||
{
|
||||
case "blg":
|
||||
_outputFormat = PdhLogFileType.PDH_LOG_TYPE_BINARY;
|
||||
break;
|
||||
case "csv":
|
||||
_outputFormat = PdhLogFileType.PDH_LOG_TYPE_CSV;
|
||||
break;
|
||||
case "tsv":
|
||||
_outputFormat = PdhLogFileType.PDH_LOG_TYPE_TSV;
|
||||
break;
|
||||
default:
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterInvalidFormat"), _format);
|
||||
Exception exc = new Exception (msg);
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "CounterInvalidFormat", ErrorCategory.InvalidArgument, null));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ResolvePath()
|
||||
{
|
||||
try
|
||||
{
|
||||
Collection<PathInfo> result = null;
|
||||
result = SessionState.Path.GetResolvedPSPathFromPSPath(_path);
|
||||
if (result.Count > 1)
|
||||
foreach (PerformanceCounterSampleSet set in _counterSampleSets)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("ExportDestPathAmbiguous"), _path);
|
||||
Exception exc = new Exception (msg);
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "ExportDestPathAmbiguous", ErrorCategory.InvalidArgument, null));
|
||||
}
|
||||
|
||||
foreach (PathInfo currentPath in result)
|
||||
{
|
||||
_resolvedPath = currentPath.ProviderPath;
|
||||
_pdhHelper.ResetRelogValues();
|
||||
|
||||
foreach (PerformanceCounterSample sample in set.CounterSamples)
|
||||
{
|
||||
bool bUnknownKey = false;
|
||||
res = _pdhHelper.SetCounterValue(sample, out bUnknownKey);
|
||||
if (bUnknownKey)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterExportSampleNotInInitialSet"), sample.Path, _resolvedPath);
|
||||
Exception exc = new Exception(msg);
|
||||
WriteError(new ErrorRecord(exc, "CounterExportSampleNotInInitialSet", ErrorCategory.InvalidResult, null));
|
||||
}
|
||||
else if (res != 0)
|
||||
{
|
||||
ReportPdhError(res, true);
|
||||
}
|
||||
}
|
||||
res = _pdhHelper.WriteRelogSample(set.Timestamp);
|
||||
if (res != 0)
|
||||
{
|
||||
ReportPdhError(res, true);
|
||||
}
|
||||
|
||||
if (_stopping)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ItemNotFoundException pathNotFound)
|
||||
{
|
||||
//
|
||||
// This is an expected condition - we will be creating a new file
|
||||
//
|
||||
_resolvedPath = pathNotFound.ItemName;
|
||||
}
|
||||
}
|
||||
|
||||
private void ReportPdhError(uint res, bool bTerminate)
|
||||
{
|
||||
string msg;
|
||||
uint formatRes = CommonUtilities.FormatMessageFromModule(res, "pdh.dll", out msg);
|
||||
if (formatRes != 0)
|
||||
// ValidateFormat() helper.
|
||||
// Validates Format argument: only "BLG", "TSV" and "CSV" are valid strings (case-insensitive)
|
||||
//
|
||||
private void ValidateFormat()
|
||||
{
|
||||
msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterApiError"), res);
|
||||
switch (_format.ToLower(CultureInfo.InvariantCulture))
|
||||
{
|
||||
case "blg":
|
||||
_outputFormat = PdhLogFileType.PDH_LOG_TYPE_BINARY;
|
||||
break;
|
||||
case "csv":
|
||||
_outputFormat = PdhLogFileType.PDH_LOG_TYPE_CSV;
|
||||
break;
|
||||
case "tsv":
|
||||
_outputFormat = PdhLogFileType.PDH_LOG_TYPE_TSV;
|
||||
break;
|
||||
default:
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterInvalidFormat"), _format);
|
||||
Exception exc = new Exception(msg);
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "CounterInvalidFormat", ErrorCategory.InvalidArgument, null));
|
||||
break;
|
||||
}
|
||||
}
|
||||
Exception exc = new Exception (msg);
|
||||
if (bTerminate)
|
||||
|
||||
private void ResolvePath()
|
||||
{
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "CounterApiError", ErrorCategory.InvalidResult, null));
|
||||
try
|
||||
{
|
||||
Collection<PathInfo> result = null;
|
||||
result = SessionState.Path.GetResolvedPSPathFromPSPath(_path);
|
||||
if (result.Count > 1)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("ExportDestPathAmbiguous"), _path);
|
||||
Exception exc = new Exception(msg);
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "ExportDestPathAmbiguous", ErrorCategory.InvalidArgument, null));
|
||||
}
|
||||
|
||||
foreach (PathInfo currentPath in result)
|
||||
{
|
||||
_resolvedPath = currentPath.ProviderPath;
|
||||
}
|
||||
}
|
||||
catch (ItemNotFoundException pathNotFound)
|
||||
{
|
||||
//
|
||||
// This is an expected condition - we will be creating a new file
|
||||
//
|
||||
_resolvedPath = pathNotFound.ItemName;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
private void ReportPdhError(uint res, bool bTerminate)
|
||||
{
|
||||
WriteError(new ErrorRecord(exc, "CounterApiError", ErrorCategory.InvalidResult, null));
|
||||
string msg;
|
||||
uint formatRes = CommonUtilities.FormatMessageFromModule(res, "pdh.dll", out msg);
|
||||
if (formatRes != 0)
|
||||
{
|
||||
msg = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("CounterApiError"), res);
|
||||
}
|
||||
Exception exc = new Exception(msg);
|
||||
if (bTerminate)
|
||||
{
|
||||
ThrowTerminatingError(new ErrorRecord(exc, "CounterApiError", ErrorCategory.InvalidResult, null));
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteError(new ErrorRecord(exc, "CounterApiError", ErrorCategory.InvalidResult, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -6,106 +6,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Microsoft.PowerShell.Commands
|
||||
|
||||
namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Create the PowerShell snap-in used to register the
|
||||
/// Get-WinEvent cmdlet. Declaring the PSSnapIn class identifies
|
||||
/// this .cs file as a PowerShell snap-in.
|
||||
/// </summary>
|
||||
[RunInstaller(true)]
|
||||
public class GetEventPSSnapIn : PSSnapIn
|
||||
{
|
||||
/// <summary>
|
||||
/// Create an instance of the GetEventPSSnapIn class.
|
||||
/// Create the PowerShell snap-in used to register the
|
||||
/// Get-WinEvent cmdlet. Declaring the PSSnapIn class identifies
|
||||
/// this .cs file as a PowerShell snap-in.
|
||||
/// </summary>
|
||||
public GetEventPSSnapIn()
|
||||
: base()
|
||||
[RunInstaller(true)]
|
||||
public class GetEventPSSnapIn : PSSnapIn
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specify the name of the PowerShell snap-in.
|
||||
/// </summary>
|
||||
public override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Microsoft.Powershell.GetEvent";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specify the vendor of the PowerShell snap-in.
|
||||
/// </summary>
|
||||
public override string Vendor
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Microsoft";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get resource information for vendor. This is a string of format: resourceBaseName,resourceName.
|
||||
/// </summary>
|
||||
public override string VendorResource
|
||||
{
|
||||
get
|
||||
{
|
||||
return "GetEventResources,Vendor";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the description of the PowerShell snap-in.
|
||||
/// </summary>
|
||||
public override string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This PS snap-in contains Get-WinEvent cmdlet used to read Windows event log data and configuration.";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get resource information for description. This is a string of format: resourceBaseName,resourceName.
|
||||
/// </summary>
|
||||
public override string DescriptionResource
|
||||
{
|
||||
get
|
||||
{
|
||||
return "GetEventResources,Description";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get type files to be used for this mshsnapin.
|
||||
/// </summary>
|
||||
public override string[] Types
|
||||
{
|
||||
get
|
||||
/// <summary>
|
||||
/// Create an instance of the GetEventPSSnapIn class.
|
||||
/// </summary>
|
||||
public GetEventPSSnapIn()
|
||||
: base()
|
||||
{
|
||||
return _types;
|
||||
}
|
||||
}
|
||||
private string[] _types = new string[] {"getevent.types.ps1xml"};
|
||||
|
||||
/// <summary>
|
||||
/// Get format files to be used for this mshsnapin.
|
||||
/// </summary>
|
||||
public override string[] Formats
|
||||
{
|
||||
get
|
||||
/// <summary>
|
||||
/// Specify the name of the PowerShell snap-in.
|
||||
/// </summary>
|
||||
public override string Name
|
||||
{
|
||||
return _formats;
|
||||
get
|
||||
{
|
||||
return "Microsoft.Powershell.GetEvent";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string[] _formats = new string[] {"Event.format.ps1xml"};
|
||||
}
|
||||
/// <summary>
|
||||
/// Specify the vendor of the PowerShell snap-in.
|
||||
/// </summary>
|
||||
public override string Vendor
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Microsoft";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get resource information for vendor. This is a string of format: resourceBaseName,resourceName.
|
||||
/// </summary>
|
||||
public override string VendorResource
|
||||
{
|
||||
get
|
||||
{
|
||||
return "GetEventResources,Vendor";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the description of the PowerShell snap-in.
|
||||
/// </summary>
|
||||
public override string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return "This PS snap-in contains Get-WinEvent cmdlet used to read Windows event log data and configuration.";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get resource information for description. This is a string of format: resourceBaseName,resourceName.
|
||||
/// </summary>
|
||||
public override string DescriptionResource
|
||||
{
|
||||
get
|
||||
{
|
||||
return "GetEventResources,Description";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get type files to be used for this mshsnapin.
|
||||
/// </summary>
|
||||
public override string[] Types
|
||||
{
|
||||
get
|
||||
{
|
||||
return _types;
|
||||
}
|
||||
}
|
||||
private string[] _types = new string[] { "getevent.types.ps1xml" };
|
||||
|
||||
/// <summary>
|
||||
/// Get format files to be used for this mshsnapin.
|
||||
/// </summary>
|
||||
public override string[] Formats
|
||||
{
|
||||
get
|
||||
{
|
||||
return _formats;
|
||||
}
|
||||
}
|
||||
|
||||
private string[] _formats = new string[] { "Event.format.ps1xml" };
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -3,7 +3,7 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics.Eventing;
|
||||
@@ -13,7 +13,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
|
||||
|
||||
namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
///
|
||||
@@ -23,8 +23,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Cmdlet(VerbsCommon.New, "WinEvent", HelpUri = "http://go.microsoft.com/fwlink/?LinkID=217469")]
|
||||
public sealed class NewWinEventCommand : PSCmdlet
|
||||
{
|
||||
private ProviderMetadata providerMetadata;
|
||||
private EventDescriptor? eventDescriptor;
|
||||
private ProviderMetadata _providerMetadata;
|
||||
private EventDescriptor? _eventDescriptor;
|
||||
|
||||
private const string TemplateTag = "template";
|
||||
private const string DataTag = "data";
|
||||
@@ -42,14 +42,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return providerName;
|
||||
return _providerName;
|
||||
}
|
||||
set
|
||||
{
|
||||
providerName = value;
|
||||
_providerName = value;
|
||||
}
|
||||
}
|
||||
private string providerName;
|
||||
private string _providerName;
|
||||
|
||||
/// <summary>
|
||||
/// Id (EventId defined in manifest file)
|
||||
@@ -62,16 +62,16 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return id;
|
||||
return _id;
|
||||
}
|
||||
set
|
||||
{
|
||||
id = value;
|
||||
idSpecified = true;
|
||||
_id = value;
|
||||
_idSpecified = true;
|
||||
}
|
||||
}
|
||||
private int id;
|
||||
private bool idSpecified = false;
|
||||
private int _id;
|
||||
private bool _idSpecified = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -84,16 +84,16 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return version;
|
||||
return _version;
|
||||
}
|
||||
set
|
||||
{
|
||||
version = value;
|
||||
versionSpecified = true;
|
||||
_version = value;
|
||||
_versionSpecified = true;
|
||||
}
|
||||
}
|
||||
private byte version;
|
||||
private bool versionSpecified = false;
|
||||
private byte _version;
|
||||
private bool _versionSpecified = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -106,19 +106,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
AllowEmptyCollection,
|
||||
SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays",
|
||||
Target = "Microsoft.PowerShell.Commands",
|
||||
Justification="A string[] is required here because that is the type Powershell supports")]
|
||||
Justification = "A string[] is required here because that is the type Powershell supports")]
|
||||
public object[] Payload
|
||||
{
|
||||
get
|
||||
{
|
||||
return payload;
|
||||
return _payload;
|
||||
}
|
||||
set
|
||||
{
|
||||
payload = value;
|
||||
_payload = value;
|
||||
}
|
||||
}
|
||||
private object[] payload;
|
||||
private object[] _payload;
|
||||
|
||||
/// <summary>
|
||||
/// BeginProcessing
|
||||
@@ -133,20 +133,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private void LoadProvider()
|
||||
{
|
||||
if (string.IsNullOrEmpty(this.providerName))
|
||||
if (string.IsNullOrEmpty(_providerName))
|
||||
{
|
||||
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("ProviderNotSpecified")), "ProviderName");
|
||||
}
|
||||
|
||||
|
||||
using (EventLogSession session = new EventLogSession())
|
||||
{
|
||||
foreach (string providerName in session.GetProviderNames())
|
||||
{
|
||||
if (string.Equals(providerName, this.providerName, StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(providerName, _providerName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
try
|
||||
{
|
||||
this.providerMetadata = new ProviderMetadata(providerName);
|
||||
_providerMetadata = new ProviderMetadata(providerName);
|
||||
}
|
||||
catch (EventLogException exc)
|
||||
{
|
||||
@@ -158,21 +158,21 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
|
||||
if (this.providerMetadata == null)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadEventDescriptor()
|
||||
{
|
||||
if (idSpecified)
|
||||
if (_idSpecified)
|
||||
{
|
||||
List<EventMetadata> matchedEvents = new List<EventMetadata>();
|
||||
foreach (EventMetadata emd in this.providerMetadata.Events)
|
||||
foreach (EventMetadata emd in _providerMetadata.Events)
|
||||
{
|
||||
if (emd.Id == this.id)
|
||||
if (emd.Id == _id)
|
||||
{
|
||||
matchedEvents.Add(emd);
|
||||
}
|
||||
@@ -180,25 +180,25 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (matchedEvents.Count == 0)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture,
|
||||
string msg = string.Format(CultureInfo.InvariantCulture,
|
||||
_resourceMgr.GetString("IncorrectEventId"),
|
||||
this.id,
|
||||
this.providerName);
|
||||
_id,
|
||||
_providerName);
|
||||
throw new EventWriteException(msg);
|
||||
}
|
||||
|
||||
EventMetadata matchedEvent = null;
|
||||
if (!versionSpecified && matchedEvents.Count == 1)
|
||||
if (!_versionSpecified && matchedEvents.Count == 1)
|
||||
{
|
||||
matchedEvent = matchedEvents[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (versionSpecified)
|
||||
if (_versionSpecified)
|
||||
{
|
||||
foreach (EventMetadata emd in matchedEvents)
|
||||
{
|
||||
if (emd.Version == this.version)
|
||||
if (emd.Version == _version)
|
||||
{
|
||||
matchedEvent = emd;
|
||||
break;
|
||||
@@ -206,28 +206,28 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
if (matchedEvent == null)
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture,
|
||||
string msg = string.Format(CultureInfo.InvariantCulture,
|
||||
_resourceMgr.GetString("IncorrectEventVersion"),
|
||||
this.version,
|
||||
this.id,
|
||||
this.providerName);
|
||||
|
||||
_version,
|
||||
_id,
|
||||
_providerName);
|
||||
|
||||
throw new EventWriteException(msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string msg = string.Format(CultureInfo.InvariantCulture,
|
||||
string msg = string.Format(CultureInfo.InvariantCulture,
|
||||
_resourceMgr.GetString("VersionNotSpecified"),
|
||||
this.id,
|
||||
this.providerName);
|
||||
_id,
|
||||
_providerName);
|
||||
|
||||
throw new EventWriteException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
VerifyTemplate(matchedEvent);
|
||||
this.eventDescriptor = CreateEventDescriptor(this.providerMetadata, matchedEvent);
|
||||
_eventDescriptor = CreateEventDescriptor(_providerMetadata, matchedEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -265,10 +265,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
|
||||
if ((this.payload == null && definedParameterCount != 0)
|
||||
|| ((this.payload != null) && this.payload.Length != definedParameterCount))
|
||||
if ((_payload == null && definedParameterCount != 0)
|
||||
|| ((_payload != null) && _payload.Length != definedParameterCount))
|
||||
{
|
||||
string warning = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("PayloadMismatch"), this.id, emd.Template);
|
||||
string warning = string.Format(CultureInfo.InvariantCulture, _resourceMgr.GetString("PayloadMismatch"), _id, emd.Template);
|
||||
WriteWarning(warning);
|
||||
|
||||
return false;
|
||||
@@ -294,11 +294,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
return new EventDescriptor(
|
||||
(int) emd.Id,
|
||||
(int)emd.Id,
|
||||
emd.Version,
|
||||
channel,
|
||||
(byte) emd.Level.Value,
|
||||
(byte) emd.Opcode.Value,
|
||||
(byte)emd.Level.Value,
|
||||
(byte)emd.Opcode.Value,
|
||||
emd.Task.Value,
|
||||
keywords);
|
||||
}
|
||||
@@ -308,21 +308,23 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
using (EventProvider provider = new EventProvider(this.providerMetadata.Id))
|
||||
using (EventProvider provider = new EventProvider(_providerMetadata.Id))
|
||||
{
|
||||
EventDescriptor ed = this.eventDescriptor.Value;
|
||||
EventDescriptor ed = _eventDescriptor.Value;
|
||||
|
||||
if (this.payload != null && this.payload.Length > 0)
|
||||
if (_payload != null && _payload.Length > 0)
|
||||
{
|
||||
for (int i = 0; i < this.payload.Length; i++)
|
||||
for (int i = 0; i < _payload.Length; i++)
|
||||
{
|
||||
if (this.payload[i] == null)
|
||||
if (_payload[i] == null)
|
||||
{
|
||||
this.payload[i] = string.Empty;
|
||||
_payload[i] = string.Empty;
|
||||
}
|
||||
}
|
||||
provider.WriteEvent(ref ed, this.payload);
|
||||
} else {
|
||||
provider.WriteEvent(ref ed, _payload);
|
||||
}
|
||||
else
|
||||
{
|
||||
provider.WriteEvent(ref ed);
|
||||
}
|
||||
}
|
||||
@@ -334,19 +336,21 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
if (this.providerMetadata != null)
|
||||
providerMetadata.Dispose();
|
||||
if (_providerMetadata != null)
|
||||
_providerMetadata.Dispose();
|
||||
|
||||
base.EndProcessing();
|
||||
}
|
||||
}
|
||||
|
||||
internal class EventWriteException : Exception
|
||||
|
||||
internal class EventWriteException : Exception
|
||||
{
|
||||
internal EventWriteException(string msg, Exception innerException)
|
||||
: base (msg, innerException) {}
|
||||
|
||||
: base(msg, innerException)
|
||||
{ }
|
||||
|
||||
internal EventWriteException(string msg)
|
||||
: base (msg) {}
|
||||
: base(msg)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,23 +1,23 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
|
||||
namespace Microsoft.Powershell.Commands.GetCounter.PdhNative
|
||||
{
|
||||
|
||||
internal sealed class PdhSafeDataSourceHandle : SafeHandle
|
||||
{
|
||||
private PdhSafeDataSourceHandle() : base(IntPtr.Zero, true) { }
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return handle == IntPtr.Zero;
|
||||
}
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return handle == IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,19 +35,18 @@ namespace Microsoft.Powershell.Commands.GetCounter.PdhNative
|
||||
{
|
||||
private PdhSafeQueryHandle() : base(IntPtr.Zero, true) { }
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return handle == IntPtr.Zero;
|
||||
}
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return handle == IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
|
||||
return (PdhHelper.PdhCloseQuery(handle) == 0);
|
||||
}
|
||||
}
|
||||
@@ -56,22 +55,21 @@ namespace Microsoft.Powershell.Commands.GetCounter.PdhNative
|
||||
{
|
||||
private PdhSafeLogHandle() : base(IntPtr.Zero, true) { }
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return handle == IntPtr.Zero;
|
||||
}
|
||||
public override bool IsInvalid
|
||||
{
|
||||
get
|
||||
{
|
||||
return handle == IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
|
||||
return (PdhHelper.PdhCloseLog(handle, 0) == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
|
||||
[assembly:AssemblyFileVersionAttribute("3.0.0.0")]
|
||||
[assembly:AssemblyVersion("3.0.0.0")]
|
||||
[assembly: AssemblyFileVersionAttribute("3.0.0.0")]
|
||||
[assembly: AssemblyVersion("3.0.0.0")]
|
||||
|
||||
[assembly:AssemblyCulture("")]
|
||||
[assembly:NeutralResourcesLanguage("en-US")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: NeutralResourcesLanguage("en-US")]
|
||||
+71
-71
@@ -35,7 +35,7 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
private bool disposed;
|
||||
private bool _disposed;
|
||||
|
||||
/// <summary>
|
||||
/// Releases resources associated with this object
|
||||
@@ -51,17 +51,17 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
/// </summary>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
if (!_disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (this.parentJob != null)
|
||||
if (_parentJob != null)
|
||||
{
|
||||
this.parentJob.Dispose();
|
||||
this.parentJob = null;
|
||||
_parentJob.Dispose();
|
||||
_parentJob = null;
|
||||
}
|
||||
}
|
||||
disposed = true;
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,16 +72,16 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
/// <summary>
|
||||
/// Session to operate on
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
protected TSession[] Session
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.session == null)
|
||||
if (_session == null)
|
||||
{
|
||||
this.session = new TSession[] {this.DefaultSession};
|
||||
_session = new TSession[] { this.DefaultSession };
|
||||
}
|
||||
return this.session;
|
||||
return _session;
|
||||
}
|
||||
set
|
||||
{
|
||||
@@ -90,12 +90,12 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
throw new ArgumentNullException("value");
|
||||
}
|
||||
|
||||
this.session = value;
|
||||
this.sessionWasSpecified = true;
|
||||
_session = value;
|
||||
_sessionWasSpecified = true;
|
||||
}
|
||||
}
|
||||
private TSession[] session;
|
||||
private bool sessionWasSpecified;
|
||||
private TSession[] _session;
|
||||
private bool _sessionWasSpecified;
|
||||
|
||||
/// <summary>
|
||||
/// Whether to wrap and emit the whole operation as a background job
|
||||
@@ -103,10 +103,10 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
[Parameter]
|
||||
public SwitchParameter AsJob
|
||||
{
|
||||
get { return this.asJob; }
|
||||
set { this.asJob = value; }
|
||||
get { return _asJob; }
|
||||
set { _asJob = value; }
|
||||
}
|
||||
private bool asJob;
|
||||
private bool _asJob;
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of remote connections that can remain active at any given time.
|
||||
@@ -153,12 +153,12 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
sessionForJob,
|
||||
discardNonPipelineResults,
|
||||
actionAgainstResults == null
|
||||
? (Action<PSObject>) null
|
||||
: delegate(PSObject pso)
|
||||
? (Action<PSObject>)null
|
||||
: delegate (PSObject pso)
|
||||
{
|
||||
var objectInstance =
|
||||
(TObjectInstance)
|
||||
LanguagePrimitives.ConvertTo(pso, typeof (TObjectInstance),
|
||||
LanguagePrimitives.ConvertTo(pso, typeof(TObjectInstance),
|
||||
CultureInfo.InvariantCulture);
|
||||
actionAgainstResults(sessionForJob, objectInstance);
|
||||
});
|
||||
@@ -189,17 +189,17 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
|
||||
private StartableJob DoCreateInstanceMethodInvocationJob(TSession sessionForJob, TObjectInstance objectInstance, MethodInvocationInfo methodInvocationInfo, bool passThru, bool asJob)
|
||||
{
|
||||
StartableJob methodInvocationJob = this.CreateInstanceMethodInvocationJob(sessionForJob, objectInstance, methodInvocationInfo, passThru);
|
||||
StartableJob methodInvocationJob = this.CreateInstanceMethodInvocationJob(sessionForJob, objectInstance, methodInvocationInfo, passThru);
|
||||
|
||||
if (methodInvocationJob != null)
|
||||
{
|
||||
bool discardNonPipelineResults = !asJob;
|
||||
HandleJobOutput(
|
||||
methodInvocationJob,
|
||||
sessionForJob,
|
||||
discardNonPipelineResults,
|
||||
outputAction: null);
|
||||
}
|
||||
if (methodInvocationJob != null)
|
||||
{
|
||||
bool discardNonPipelineResults = !asJob;
|
||||
HandleJobOutput(
|
||||
methodInvocationJob,
|
||||
sessionForJob,
|
||||
discardNonPipelineResults,
|
||||
outputAction: null);
|
||||
}
|
||||
|
||||
return methodInvocationJob;
|
||||
}
|
||||
@@ -242,7 +242,7 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
private void HandleJobOutput(Job job, TSession sessionForJob, bool discardNonPipelineResults, Action<PSObject> outputAction)
|
||||
{
|
||||
Action<PSObject> processOutput =
|
||||
delegate(PSObject pso)
|
||||
delegate (PSObject pso)
|
||||
{
|
||||
if (pso == null)
|
||||
{
|
||||
@@ -256,9 +256,9 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
};
|
||||
|
||||
job.Output.DataAdded +=
|
||||
delegate(object sender, DataAddedEventArgs eventArgs)
|
||||
delegate (object sender, DataAddedEventArgs eventArgs)
|
||||
{
|
||||
var dataCollection = (PSDataCollection<PSObject>) sender;
|
||||
var dataCollection = (PSDataCollection<PSObject>)sender;
|
||||
|
||||
if (discardNonPipelineResults)
|
||||
{
|
||||
@@ -306,7 +306,7 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
private static void DiscardJobOutputs<T>(PSDataCollection<T> psDataCollection)
|
||||
{
|
||||
psDataCollection.DataAdded +=
|
||||
delegate(object sender, DataAddedEventArgs e)
|
||||
delegate (object sender, DataAddedEventArgs e)
|
||||
{
|
||||
var localDataCollection = (PSDataCollection<T>)sender;
|
||||
localDataCollection.Clear();
|
||||
@@ -369,7 +369,7 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
|
||||
#region Implementation of ObjectModelWrapper functionality
|
||||
|
||||
private ThrottlingJob parentJob;
|
||||
private ThrottlingJob _parentJob;
|
||||
|
||||
/// <summary>
|
||||
/// Queries for object instances in the object model.
|
||||
@@ -378,7 +378,7 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
/// <returns>A lazy evaluated collection of object instances</returns>
|
||||
public override void ProcessRecord(QueryBuilder query)
|
||||
{
|
||||
this.parentJob.DisableFlowControlForPendingCmdletActionsQueue();
|
||||
_parentJob.DisableFlowControlForPendingCmdletActionsQueue();
|
||||
foreach (TSession sessionForJob in this.GetSessionsToActAgainst(query))
|
||||
{
|
||||
StartableJob childJob = this.DoCreateQueryJob(sessionForJob, query, actionAgainstResults: null);
|
||||
@@ -386,11 +386,11 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
{
|
||||
if (!this.AsJob.IsPresent)
|
||||
{
|
||||
this.parentJob.AddChildJobAndPotentiallyBlock(this.Cmdlet, childJob, ThrottlingJob.ChildJobFlags.None);
|
||||
_parentJob.AddChildJobAndPotentiallyBlock(this.Cmdlet, childJob, ThrottlingJob.ChildJobFlags.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parentJob.AddChildJobWithoutBlocking(childJob, ThrottlingJob.ChildJobFlags.None);
|
||||
_parentJob.AddChildJobWithoutBlocking(childJob, ThrottlingJob.ChildJobFlags.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -404,9 +404,9 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
/// <param name="passThru"><c>true</c> if successful method invocations should emit downstream the object instance being operated on</param>
|
||||
public override void ProcessRecord(QueryBuilder query, MethodInvocationInfo methodInvocationInfo, bool passThru)
|
||||
{
|
||||
this.parentJob.DisableFlowControlForPendingJobsQueue();
|
||||
_parentJob.DisableFlowControlForPendingJobsQueue();
|
||||
|
||||
ThrottlingJob closureOverParentJob = this.parentJob;
|
||||
ThrottlingJob closureOverParentJob = _parentJob;
|
||||
SwitchParameter closureOverAsJob = this.AsJob;
|
||||
|
||||
foreach (TSession sessionForJob in this.GetSessionsToActAgainst(query))
|
||||
@@ -414,30 +414,30 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
StartableJob queryJob = this.DoCreateQueryJob(
|
||||
sessionForJob,
|
||||
query,
|
||||
delegate(TSession sessionForMethodInvocationJob, TObjectInstance objectInstance)
|
||||
delegate (TSession sessionForMethodInvocationJob, TObjectInstance objectInstance)
|
||||
{
|
||||
StartableJob methodInvocationJob = this.DoCreateInstanceMethodInvocationJob(
|
||||
sessionForMethodInvocationJob,
|
||||
objectInstance,
|
||||
methodInvocationInfo,
|
||||
passThru,
|
||||
closureOverAsJob.IsPresent);
|
||||
StartableJob methodInvocationJob = this.DoCreateInstanceMethodInvocationJob(
|
||||
sessionForMethodInvocationJob,
|
||||
objectInstance,
|
||||
methodInvocationInfo,
|
||||
passThru,
|
||||
closureOverAsJob.IsPresent);
|
||||
|
||||
if (methodInvocationJob != null)
|
||||
{
|
||||
closureOverParentJob.AddChildJobAndPotentiallyBlock(methodInvocationJob, ThrottlingJob.ChildJobFlags.None);
|
||||
}
|
||||
if (methodInvocationJob != null)
|
||||
{
|
||||
closureOverParentJob.AddChildJobAndPotentiallyBlock(methodInvocationJob, ThrottlingJob.ChildJobFlags.None);
|
||||
}
|
||||
});
|
||||
|
||||
if (queryJob != null)
|
||||
{
|
||||
if (!this.AsJob.IsPresent)
|
||||
{
|
||||
this.parentJob.AddChildJobAndPotentiallyBlock(this.Cmdlet, queryJob, ThrottlingJob.ChildJobFlags.CreatesChildJobs);
|
||||
_parentJob.AddChildJobAndPotentiallyBlock(this.Cmdlet, queryJob, ThrottlingJob.ChildJobFlags.CreatesChildJobs);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parentJob.AddChildJobWithoutBlocking(queryJob, ThrottlingJob.ChildJobFlags.CreatesChildJobs);
|
||||
_parentJob.AddChildJobWithoutBlocking(queryJob, ThrottlingJob.ChildJobFlags.CreatesChildJobs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -445,7 +445,7 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
|
||||
private IEnumerable<TSession> GetSessionsToActAgainst(TObjectInstance objectInstance)
|
||||
{
|
||||
if (this.sessionWasSpecified)
|
||||
if (_sessionWasSpecified)
|
||||
{
|
||||
return this.Session;
|
||||
}
|
||||
@@ -453,7 +453,7 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
TSession associatedSession = this.GetSessionOfOriginFromInstance(objectInstance);
|
||||
if (associatedSession != null)
|
||||
{
|
||||
return new[] {associatedSession};
|
||||
return new[] { associatedSession };
|
||||
}
|
||||
|
||||
return new[] { this.GetImpliedSession() };
|
||||
@@ -491,7 +491,7 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
|
||||
private IEnumerable<TSession> GetSessionsToActAgainst(QueryBuilder queryBuilder)
|
||||
{
|
||||
if (this.sessionWasSpecified)
|
||||
if (_sessionWasSpecified)
|
||||
{
|
||||
return this.Session;
|
||||
}
|
||||
@@ -517,7 +517,7 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
|
||||
private IEnumerable<TSession> GetSessionsToActAgainst(MethodInvocationInfo methodInvocationInfo)
|
||||
{
|
||||
if (this.sessionWasSpecified)
|
||||
if (_sessionWasSpecified)
|
||||
{
|
||||
return this.Session;
|
||||
}
|
||||
@@ -547,8 +547,8 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
|
||||
internal PSModuleInfo PSModuleInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
get
|
||||
{
|
||||
var scriptCommandInfo = this.Cmdlet.CommandInfo as IScriptCommandInfo;
|
||||
return scriptCommandInfo.ScriptBlock.Module;
|
||||
}
|
||||
@@ -592,11 +592,11 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
{
|
||||
if (!this.AsJob.IsPresent)
|
||||
{
|
||||
this.parentJob.AddChildJobAndPotentiallyBlock(this.Cmdlet, childJob, ThrottlingJob.ChildJobFlags.None);
|
||||
_parentJob.AddChildJobAndPotentiallyBlock(this.Cmdlet, childJob, ThrottlingJob.ChildJobFlags.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parentJob.AddChildJobWithoutBlocking(childJob, ThrottlingJob.ChildJobFlags.None);
|
||||
_parentJob.AddChildJobWithoutBlocking(childJob, ThrottlingJob.ChildJobFlags.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -617,11 +617,11 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
{
|
||||
if (!this.AsJob.IsPresent)
|
||||
{
|
||||
this.parentJob.AddChildJobAndPotentiallyBlock(this.Cmdlet, childJob, ThrottlingJob.ChildJobFlags.None);
|
||||
_parentJob.AddChildJobAndPotentiallyBlock(this.Cmdlet, childJob, ThrottlingJob.ChildJobFlags.None);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parentJob.AddChildJobWithoutBlocking(childJob, ThrottlingJob.ChildJobFlags.None);
|
||||
_parentJob.AddChildJobWithoutBlocking(childJob, ThrottlingJob.ChildJobFlags.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -654,7 +654,7 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
}
|
||||
}
|
||||
|
||||
this.parentJob = new ThrottlingJob(
|
||||
_parentJob = new ThrottlingJob(
|
||||
command: Job.GetCommandTextFromInvocationInfo(this.Cmdlet.MyInvocation),
|
||||
jobName: this.GenerateParentJobName(),
|
||||
jobTypeName: CIMJobType,
|
||||
@@ -667,17 +667,17 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
/// </summary>
|
||||
public override void EndProcessing()
|
||||
{
|
||||
this.parentJob.EndOfChildJobs();
|
||||
_parentJob.EndOfChildJobs();
|
||||
if (this.AsJob.IsPresent)
|
||||
{
|
||||
this.Cmdlet.WriteObject(this.parentJob);
|
||||
this.Cmdlet.JobRepository.Add(this.parentJob);
|
||||
this.parentJob = null; // this class doesn't own parentJob after it has been emitted to the outside world
|
||||
this.Cmdlet.WriteObject(_parentJob);
|
||||
this.Cmdlet.JobRepository.Add(_parentJob);
|
||||
_parentJob = null; // this class doesn't own parentJob after it has been emitted to the outside world
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parentJob.ForwardAllResultsToCmdlet(this.Cmdlet);
|
||||
this.parentJob.Finished.WaitOne();
|
||||
_parentJob.ForwardAllResultsToCmdlet(this.Cmdlet);
|
||||
_parentJob.Finished.WaitOne();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -686,7 +686,7 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
/// </summary>
|
||||
public override void StopProcessing()
|
||||
{
|
||||
Job jobToStop = this.parentJob;
|
||||
Job jobToStop = _parentJob;
|
||||
if (jobToStop != null)
|
||||
{
|
||||
jobToStop.StopJob();
|
||||
|
||||
+54
-53
@@ -63,7 +63,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
throw new ArgumentNullException("info");
|
||||
}
|
||||
|
||||
this.errorRecord = (ErrorRecord)info.GetValue("errorRecord", typeof (ErrorRecord));
|
||||
_errorRecord = (ErrorRecord)info.GetValue("errorRecord", typeof(ErrorRecord));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -79,14 +79,14 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
|
||||
base.GetObjectData(info, context);
|
||||
info.AddValue("errorRecord", this.errorRecord);
|
||||
info.AddValue("errorRecord", _errorRecord);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
internal static CimJobException CreateFromCimException(
|
||||
string jobDescription,
|
||||
CimJobContext jobContext,
|
||||
string jobDescription,
|
||||
CimJobContext jobContext,
|
||||
CimException cimException)
|
||||
{
|
||||
Dbg.Assert(!string.IsNullOrEmpty(jobDescription), "Caller should verify jobDescription != null");
|
||||
@@ -100,8 +100,8 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
|
||||
internal static CimJobException CreateFromAnyException(
|
||||
string jobDescription,
|
||||
CimJobContext jobContext,
|
||||
string jobDescription,
|
||||
CimJobContext jobContext,
|
||||
Exception inner)
|
||||
{
|
||||
Dbg.Assert(!string.IsNullOrEmpty(jobDescription), "Caller should verify jobDescription != null");
|
||||
@@ -114,13 +114,13 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
return CreateFromCimException(jobDescription, jobContext, cimException);
|
||||
}
|
||||
|
||||
string message = BuildErrorMessage(jobDescription, jobContext, inner.Message);
|
||||
string message = BuildErrorMessage(jobDescription, jobContext, inner.Message);
|
||||
CimJobException cimJobException = new CimJobException(message, inner);
|
||||
var containsErrorRecord = inner as IContainsErrorRecord;
|
||||
if (containsErrorRecord != null)
|
||||
{
|
||||
cimJobException.InitializeErrorRecord(
|
||||
jobContext,
|
||||
jobContext,
|
||||
errorId: "CimJob_" + containsErrorRecord.ErrorRecord.FullyQualifiedErrorId,
|
||||
errorCategory: containsErrorRecord.ErrorRecord.CategoryInfo.Category);
|
||||
}
|
||||
@@ -201,10 +201,10 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
private void InitializeErrorRecordCore(CimJobContext jobContext, Exception exception, string errorId, ErrorCategory errorCategory)
|
||||
{
|
||||
ErrorRecord coreErrorRecord = new ErrorRecord(
|
||||
exception: exception,
|
||||
errorId: errorId,
|
||||
errorCategory: errorCategory,
|
||||
targetObject: jobContext != null ? jobContext.TargetObject : null);
|
||||
exception: exception,
|
||||
errorId: errorId,
|
||||
errorCategory: errorCategory,
|
||||
targetObject: jobContext != null ? jobContext.TargetObject : null);
|
||||
|
||||
if (jobContext != null)
|
||||
{
|
||||
@@ -212,40 +212,40 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
jobContext.Session.ComputerName,
|
||||
Guid.Empty);
|
||||
|
||||
this.errorRecord = new System.Management.Automation.Runspaces.RemotingErrorRecord(
|
||||
_errorRecord = new System.Management.Automation.Runspaces.RemotingErrorRecord(
|
||||
coreErrorRecord,
|
||||
originInfo);
|
||||
|
||||
errorRecord.SetInvocationInfo(jobContext.CmdletInvocationInfo);
|
||||
errorRecord.PreserveInvocationInfoOnce = true;
|
||||
_errorRecord.SetInvocationInfo(jobContext.CmdletInvocationInfo);
|
||||
_errorRecord.PreserveInvocationInfoOnce = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.errorRecord = coreErrorRecord;
|
||||
_errorRecord = coreErrorRecord;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeErrorRecord(CimJobContext jobContext, string errorId, ErrorCategory errorCategory)
|
||||
{
|
||||
InitializeErrorRecordCore(
|
||||
jobContext: jobContext,
|
||||
exception: this,
|
||||
errorId: errorId,
|
||||
jobContext: jobContext,
|
||||
exception: this,
|
||||
errorId: errorId,
|
||||
errorCategory: errorCategory);
|
||||
}
|
||||
|
||||
private void InitializeErrorRecord(CimJobContext jobContext, CimException cimException)
|
||||
{
|
||||
InitializeErrorRecordCore(
|
||||
jobContext: jobContext,
|
||||
exception: cimException,
|
||||
errorId: cimException.MessageId ?? "MiClientApiError_" + cimException.NativeErrorCode,
|
||||
jobContext: jobContext,
|
||||
exception: cimException,
|
||||
errorId: cimException.MessageId ?? "MiClientApiError_" + cimException.NativeErrorCode,
|
||||
errorCategory: ConvertCimExceptionToErrorCategory(cimException));
|
||||
|
||||
if (cimException.ErrorData != null)
|
||||
{
|
||||
errorRecord.CategoryInfo.TargetName = cimException.ErrorSource;
|
||||
errorRecord.CategoryInfo.TargetType = jobContext != null ? jobContext.CmdletizationClassName : null;
|
||||
_errorRecord.CategoryInfo.TargetName = cimException.ErrorSource;
|
||||
_errorRecord.CategoryInfo.TargetType = jobContext != null ? jobContext.CmdletizationClassName : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,57 +273,57 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
case NativeErrorCode.Ok:
|
||||
return ErrorCategory.NotSpecified;
|
||||
case NativeErrorCode.Failed:
|
||||
return ErrorCategory.NotSpecified;;
|
||||
return ErrorCategory.NotSpecified; ;
|
||||
case NativeErrorCode.AccessDenied:
|
||||
return ErrorCategory.PermissionDenied;;
|
||||
return ErrorCategory.PermissionDenied; ;
|
||||
case NativeErrorCode.InvalidNamespace:
|
||||
return ErrorCategory.MetadataError;;
|
||||
return ErrorCategory.MetadataError; ;
|
||||
case NativeErrorCode.InvalidParameter:
|
||||
return ErrorCategory.InvalidArgument;;
|
||||
return ErrorCategory.InvalidArgument; ;
|
||||
case NativeErrorCode.InvalidClass:
|
||||
return ErrorCategory.MetadataError;;
|
||||
return ErrorCategory.MetadataError; ;
|
||||
case NativeErrorCode.NotFound:
|
||||
return ErrorCategory.ObjectNotFound;;
|
||||
return ErrorCategory.ObjectNotFound; ;
|
||||
case NativeErrorCode.NotSupported:
|
||||
return ErrorCategory.NotImplemented;;
|
||||
return ErrorCategory.NotImplemented; ;
|
||||
case NativeErrorCode.ClassHasChildren:
|
||||
return ErrorCategory.MetadataError;;
|
||||
return ErrorCategory.MetadataError; ;
|
||||
case NativeErrorCode.ClassHasInstances:
|
||||
return ErrorCategory.MetadataError;;
|
||||
return ErrorCategory.MetadataError; ;
|
||||
case NativeErrorCode.InvalidSuperClass:
|
||||
return ErrorCategory.MetadataError;;
|
||||
return ErrorCategory.MetadataError; ;
|
||||
case NativeErrorCode.AlreadyExists:
|
||||
return ErrorCategory.ResourceExists;;
|
||||
return ErrorCategory.ResourceExists; ;
|
||||
case NativeErrorCode.NoSuchProperty:
|
||||
return ErrorCategory.MetadataError;;
|
||||
return ErrorCategory.MetadataError; ;
|
||||
case NativeErrorCode.TypeMismatch:
|
||||
return ErrorCategory.InvalidType;;
|
||||
return ErrorCategory.InvalidType; ;
|
||||
case NativeErrorCode.QueryLanguageNotSupported:
|
||||
return ErrorCategory.NotImplemented;;
|
||||
return ErrorCategory.NotImplemented; ;
|
||||
case NativeErrorCode.InvalidQuery:
|
||||
return ErrorCategory.InvalidArgument;;
|
||||
return ErrorCategory.InvalidArgument; ;
|
||||
case NativeErrorCode.MethodNotAvailable:
|
||||
return ErrorCategory.MetadataError;;
|
||||
return ErrorCategory.MetadataError; ;
|
||||
case NativeErrorCode.MethodNotFound:
|
||||
return ErrorCategory.MetadataError;;
|
||||
return ErrorCategory.MetadataError; ;
|
||||
case NativeErrorCode.NamespaceNotEmpty:
|
||||
return ErrorCategory.MetadataError;;
|
||||
return ErrorCategory.MetadataError; ;
|
||||
case NativeErrorCode.InvalidEnumerationContext:
|
||||
return ErrorCategory.MetadataError;;
|
||||
return ErrorCategory.MetadataError; ;
|
||||
case NativeErrorCode.InvalidOperationTimeout:
|
||||
return ErrorCategory.InvalidArgument;;
|
||||
return ErrorCategory.InvalidArgument; ;
|
||||
case NativeErrorCode.PullHasBeenAbandoned:
|
||||
return ErrorCategory.OperationStopped;;
|
||||
return ErrorCategory.OperationStopped; ;
|
||||
case NativeErrorCode.PullCannotBeAbandoned:
|
||||
return ErrorCategory.CloseError;;
|
||||
return ErrorCategory.CloseError; ;
|
||||
case NativeErrorCode.FilteredEnumerationNotSupported:
|
||||
return ErrorCategory.NotImplemented;;
|
||||
return ErrorCategory.NotImplemented; ;
|
||||
case NativeErrorCode.ContinuationOnErrorNotSupported:
|
||||
return ErrorCategory.NotImplemented;;
|
||||
return ErrorCategory.NotImplemented; ;
|
||||
case NativeErrorCode.ServerLimitsExceeded:
|
||||
return ErrorCategory.ResourceBusy;;
|
||||
return ErrorCategory.ResourceBusy; ;
|
||||
case NativeErrorCode.ServerIsShuttingDown:
|
||||
return ErrorCategory.ResourceUnavailable;;
|
||||
return ErrorCategory.ResourceUnavailable; ;
|
||||
default:
|
||||
return ErrorCategory.NotSpecified;
|
||||
}
|
||||
@@ -356,13 +356,14 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// </summary>
|
||||
public ErrorRecord ErrorRecord
|
||||
{
|
||||
get { return this.errorRecord; }
|
||||
get { return _errorRecord; }
|
||||
}
|
||||
private ErrorRecord errorRecord;
|
||||
private ErrorRecord _errorRecord;
|
||||
|
||||
internal bool IsTerminatingError
|
||||
{
|
||||
get {
|
||||
get
|
||||
{
|
||||
var cimException = this.InnerException as CimException;
|
||||
if ((cimException == null) || (cimException.ErrorData == null))
|
||||
{
|
||||
|
||||
+3
-4
@@ -46,7 +46,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
Dbg.Assert(_resultFromCreateInstance != null, "GetInstance should only be called after CreteInstance came back with a keyed instance");
|
||||
IObservable<CimInstance> observable = this.JobContext.Session.GetInstanceAsync(
|
||||
this.JobContext.Namespace,
|
||||
this._resultFromCreateInstance,
|
||||
_resultFromCreateInstance,
|
||||
this.CreateOperationOptions());
|
||||
return observable;
|
||||
}
|
||||
@@ -118,8 +118,8 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
Dbg.Assert(this.DidUserSuppressTheOperation || (_resultFromCreateInstance != null), "OnNext should always be called before OnComplete by CreateInstance");
|
||||
#if DEBUG
|
||||
Dbg.Assert(
|
||||
!this._getInstanceOperationGotStarted || this.DidUserSuppressTheOperation || (this._resultFromGetInstance != null),
|
||||
// <=> (this._getInstanceOperationGotStarted => (this._resultFromGetInstance != null))
|
||||
!_getInstanceOperationGotStarted || this.DidUserSuppressTheOperation || (_resultFromGetInstance != null),
|
||||
// <=> (this._getInstanceOperationGotStarted => (this._resultFromGetInstance != null))
|
||||
"GetInstance should cause OnNext to be called which should set this._resultFromGetInstance to non-null");
|
||||
#endif
|
||||
if (this.IsPassThruObjectNeeded() && (_resultFromGetInstance == null))
|
||||
@@ -141,6 +141,5 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
return _resultFromGetInstance;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -13,17 +13,17 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// </summary>
|
||||
internal class DeleteInstanceJob : MethodInvocationJobBase<object>
|
||||
{
|
||||
private readonly CimInstance objectToDelete;
|
||||
private readonly CimInstance _objectToDelete;
|
||||
|
||||
internal DeleteInstanceJob(CimJobContext jobContext, bool passThru, CimInstance objectToDelete, MethodInvocationInfo methodInvocationInfo)
|
||||
: base(
|
||||
jobContext,
|
||||
passThru,
|
||||
jobContext,
|
||||
passThru,
|
||||
objectToDelete.ToString(),
|
||||
methodInvocationInfo)
|
||||
{
|
||||
Dbg.Assert(objectToDelete != null, "Caller should verify objectToDelete != null");
|
||||
this.objectToDelete = objectToDelete;
|
||||
_objectToDelete = objectToDelete;
|
||||
}
|
||||
|
||||
internal override IObservable<object> GetCimOperation()
|
||||
@@ -35,7 +35,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
IObservable<object> observable = this.JobContext.Session.DeleteInstanceAsync(
|
||||
this.JobContext.Namespace,
|
||||
this.objectToDelete,
|
||||
_objectToDelete,
|
||||
this.CreateOperationOptions());
|
||||
return observable;
|
||||
}
|
||||
@@ -47,14 +47,14 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal override object PassThruObject
|
||||
{
|
||||
get { return this.objectToDelete; }
|
||||
get { return _objectToDelete; }
|
||||
}
|
||||
|
||||
internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
|
||||
{
|
||||
return CimCustomOptionsDictionary.MergeOptions(
|
||||
base.CalculateJobSpecificCustomOptions(),
|
||||
this.objectToDelete);
|
||||
_objectToDelete);
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
-21
@@ -15,25 +15,25 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// </summary>
|
||||
internal class EnumerateAssociatedInstancesJob : QueryJobBase
|
||||
{
|
||||
private readonly CimInstance associatedObject;
|
||||
private readonly string associationName;
|
||||
private readonly string resultRole;
|
||||
private readonly string sourceRole;
|
||||
private readonly CimInstance _associatedObject;
|
||||
private readonly string _associationName;
|
||||
private readonly string _resultRole;
|
||||
private readonly string _sourceRole;
|
||||
|
||||
internal EnumerateAssociatedInstancesJob(CimJobContext jobContext, CimQuery cimQuery, CimInstance associatedObject, string associationName, string resultRole, string sourceRole)
|
||||
: base(jobContext, cimQuery)
|
||||
{
|
||||
this.associatedObject = associatedObject;
|
||||
Dbg.Assert(this.associatedObject != null, "Caller should verify that associatedObject is not null");
|
||||
_associatedObject = associatedObject;
|
||||
Dbg.Assert(_associatedObject != null, "Caller should verify that associatedObject is not null");
|
||||
|
||||
this.associationName = associationName;
|
||||
Dbg.Assert(this.associationName != null, "Caller should verify that associationName is not null");
|
||||
_associationName = associationName;
|
||||
Dbg.Assert(_associationName != null, "Caller should verify that associationName is not null");
|
||||
|
||||
this.resultRole = resultRole;
|
||||
Dbg.Assert(this.resultRole != null, "Caller should verify that resultRole is not null");
|
||||
_resultRole = resultRole;
|
||||
Dbg.Assert(_resultRole != null, "Caller should verify that resultRole is not null");
|
||||
|
||||
this.sourceRole = sourceRole;
|
||||
Dbg.Assert(this.sourceRole != null, "Caller should verify that sourceRole is not null");
|
||||
_sourceRole = sourceRole;
|
||||
Dbg.Assert(_sourceRole != null, "Caller should verify that sourceRole is not null");
|
||||
}
|
||||
|
||||
internal override IObservable<CimInstance> GetCimOperation()
|
||||
@@ -41,11 +41,11 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
this.WriteVerboseStartOfCimOperation();
|
||||
IObservable<CimInstance> observable = this.JobContext.Session.EnumerateAssociatedInstancesAsync(
|
||||
this.JobContext.Namespace,
|
||||
this.associatedObject,
|
||||
this.associationName,
|
||||
_associatedObject,
|
||||
_associationName,
|
||||
this.JobContext.ClassNameOrNullIfResourceUriIsUsed,
|
||||
this.sourceRole,
|
||||
this.resultRole,
|
||||
_sourceRole,
|
||||
_resultRole,
|
||||
this.CreateOperationOptions());
|
||||
|
||||
return observable;
|
||||
@@ -53,20 +53,20 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal override string Description
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
CmdletizationResources.CimJob_AssociationDescription,
|
||||
this.JobContext.CmdletizationClassName,
|
||||
this.JobContext.Session.ComputerName,
|
||||
this.associatedObject.ToString());
|
||||
_associatedObject.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal override string FailSafeDescription
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
@@ -80,12 +80,12 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
return CimCustomOptionsDictionary.MergeOptions(
|
||||
base.CalculateJobSpecificCustomOptions(),
|
||||
this.associatedObject);
|
||||
_associatedObject);
|
||||
}
|
||||
|
||||
internal override void WriteObject(object outputObject)
|
||||
{
|
||||
if (IsShowComputerNameMarkerPresent(this.associatedObject))
|
||||
if (IsShowComputerNameMarkerPresent(_associatedObject))
|
||||
{
|
||||
PSObject pso = PSObject.AsPSObject(outputObject);
|
||||
AddShowComputerNameMarker(pso);
|
||||
|
||||
+2
-2
@@ -82,10 +82,10 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
else if (MethodParameterBindings.Error == (methodParameter.Bindings & MethodParameterBindings.Error))
|
||||
{
|
||||
var gotError = (bool)LanguagePrimitives.ConvertTo(dotNetValue, typeof (bool), CultureInfo.InvariantCulture);
|
||||
var gotError = (bool)LanguagePrimitives.ConvertTo(dotNetValue, typeof(bool), CultureInfo.InvariantCulture);
|
||||
if (gotError)
|
||||
{
|
||||
var errorCodeAsString = (string)LanguagePrimitives.ConvertTo(dotNetValue, typeof (string), CultureInfo.InvariantCulture);
|
||||
var errorCodeAsString = (string)LanguagePrimitives.ConvertTo(dotNetValue, typeof(string), CultureInfo.InvariantCulture);
|
||||
CimJobException cje = CimJobException.CreateFromMethodErrorCode(this.GetDescription(), this.JobContext, this.MethodName, errorCodeAsString);
|
||||
throw cje;
|
||||
}
|
||||
|
||||
+7
-7
@@ -14,17 +14,17 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// </summary>
|
||||
internal class InstanceMethodInvocationJob : ExtrinsicMethodInvocationJob
|
||||
{
|
||||
private readonly CimInstance targetInstance;
|
||||
private readonly CimInstance _targetInstance;
|
||||
|
||||
internal InstanceMethodInvocationJob(CimJobContext jobContext, bool passThru, CimInstance targetInstance, MethodInvocationInfo methodInvocationInfo)
|
||||
: base(
|
||||
jobContext,
|
||||
passThru,
|
||||
jobContext,
|
||||
passThru,
|
||||
targetInstance.ToString(),
|
||||
methodInvocationInfo)
|
||||
{
|
||||
Dbg.Assert(targetInstance != null, "Caller should verify targetInstance != null");
|
||||
this.targetInstance = targetInstance;
|
||||
_targetInstance = targetInstance;
|
||||
}
|
||||
|
||||
internal override IObservable<CimMethodResultBase> GetCimOperation()
|
||||
@@ -41,7 +41,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
IObservable<CimMethodResultBase> observable = this.JobContext.Session.InvokeMethodAsync(
|
||||
this.JobContext.Namespace,
|
||||
this.targetInstance,
|
||||
_targetInstance,
|
||||
this.MethodName,
|
||||
methodParameters,
|
||||
operationOptions);
|
||||
@@ -50,14 +50,14 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal override object PassThruObject
|
||||
{
|
||||
get { return this.targetInstance; }
|
||||
get { return _targetInstance; }
|
||||
}
|
||||
|
||||
internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
|
||||
{
|
||||
return CimCustomOptionsDictionary.MergeOptions(
|
||||
base.CalculateJobSpecificCustomOptions(),
|
||||
this.targetInstance);
|
||||
_targetInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-21
@@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// <summary>
|
||||
/// Job wrapping invocation of an extrinsic CIM method
|
||||
/// </summary>
|
||||
abstract internal class MethodInvocationJobBase<T> : CimChildJobBase<T>
|
||||
abstract internal class MethodInvocationJobBase<T> : CimChildJobBase<T>
|
||||
{
|
||||
internal MethodInvocationJobBase(CimJobContext jobContext, bool passThru, string methodSubject, MethodInvocationInfo methodInvocationInfo)
|
||||
: base(jobContext)
|
||||
@@ -25,9 +25,9 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
Dbg.Assert(methodInvocationInfo != null, "Caller should verify methodInvocationInfo != null");
|
||||
Dbg.Assert(methodSubject != null, "Caller should verify methodSubject != null");
|
||||
|
||||
this._passThru = passThru;
|
||||
this._methodSubject = methodSubject;
|
||||
this._methodInvocationInfo = methodInvocationInfo;
|
||||
_passThru = passThru;
|
||||
_methodSubject = methodSubject;
|
||||
_methodInvocationInfo = methodInvocationInfo;
|
||||
}
|
||||
|
||||
private readonly string _methodSubject;
|
||||
@@ -36,14 +36,14 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal string MethodName
|
||||
{
|
||||
get { return this._methodInvocationInfo.MethodName; }
|
||||
get { return _methodInvocationInfo.MethodName; }
|
||||
}
|
||||
|
||||
private const string CustomOperationOptionPrefix = "cim:operationOption:";
|
||||
|
||||
private IEnumerable<MethodParameter> GetMethodInputParametersCore(Func<MethodParameter, bool> filter)
|
||||
{
|
||||
IEnumerable<MethodParameter> inputParameters = this._methodInvocationInfo.Parameters.Where(filter);
|
||||
IEnumerable<MethodParameter> inputParameters = _methodInvocationInfo.Parameters.Where(filter);
|
||||
|
||||
var result = new List<MethodParameter>();
|
||||
foreach (MethodParameter inputParameter in inputParameters)
|
||||
@@ -52,13 +52,13 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
Type cimType = CimSensitiveValueConverter.GetCimType(inputParameter.ParameterType);
|
||||
CimValueConverter.AssertIntrinsicCimType(cimType);
|
||||
result.Add(new MethodParameter
|
||||
{
|
||||
Name = inputParameter.Name,
|
||||
ParameterType = cimType,
|
||||
Bindings = inputParameter.Bindings,
|
||||
Value = cimValue,
|
||||
IsValuePresent = inputParameter.IsValuePresent
|
||||
});
|
||||
{
|
||||
Name = inputParameter.Name,
|
||||
ParameterType = cimType,
|
||||
Bindings = inputParameter.Bindings,
|
||||
Value = cimValue,
|
||||
IsValuePresent = inputParameter.IsValuePresent
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal IEnumerable<CimInstance> GetCimInstancesFromArguments()
|
||||
{
|
||||
return this._methodInvocationInfo.GetArgumentsOfType<CimInstance>();
|
||||
return _methodInvocationInfo.GetArgumentsOfType<CimInstance>();
|
||||
}
|
||||
|
||||
internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
|
||||
@@ -96,10 +96,10 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal IEnumerable<MethodParameter> GetMethodOutputParameters()
|
||||
{
|
||||
IEnumerable<MethodParameter> allParameters_plus_returnValue = this._methodInvocationInfo.Parameters;
|
||||
if (this._methodInvocationInfo.ReturnValue != null)
|
||||
IEnumerable<MethodParameter> allParameters_plus_returnValue = _methodInvocationInfo.Parameters;
|
||||
if (_methodInvocationInfo.ReturnValue != null)
|
||||
{
|
||||
allParameters_plus_returnValue = allParameters_plus_returnValue.Append(this._methodInvocationInfo.ReturnValue);
|
||||
allParameters_plus_returnValue = allParameters_plus_returnValue.Append(_methodInvocationInfo.ReturnValue);
|
||||
}
|
||||
|
||||
var outParameters = allParameters_plus_returnValue
|
||||
@@ -110,7 +110,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal string MethodSubject
|
||||
{
|
||||
get { return this._methodSubject; }
|
||||
get { return _methodSubject; }
|
||||
}
|
||||
|
||||
internal bool ShouldProcess()
|
||||
@@ -158,7 +158,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal bool IsPassThruObjectNeeded()
|
||||
{
|
||||
return (this._passThru) && (!this.DidUserSuppressTheOperation) && (!this.JobHadErrors);
|
||||
return (_passThru) && (!this.DidUserSuppressTheOperation) && (!this.JobHadErrors);
|
||||
}
|
||||
|
||||
public override void OnCompleted()
|
||||
@@ -187,7 +187,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal override string Description
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
@@ -211,6 +211,5 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -75,7 +75,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
return CimCustomOptionsDictionary.MergeOptions(
|
||||
base.CalculateJobSpecificCustomOptions(),
|
||||
this._originalInstance);
|
||||
_originalInstance);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
|
||||
+2
-2
@@ -14,8 +14,8 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
internal PropertySettingJob(CimJobContext jobContext, bool passThru, CimInstance objectToModify, MethodInvocationInfo methodInvocationInfo)
|
||||
: base(
|
||||
jobContext,
|
||||
passThru,
|
||||
jobContext,
|
||||
passThru,
|
||||
objectToModify.ToString(),
|
||||
methodInvocationInfo)
|
||||
{
|
||||
|
||||
+9
-9
@@ -27,17 +27,17 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
wqlQueryBuilder.Append(this.JobContext.ClassName);
|
||||
wqlQueryBuilder.Append(" ");
|
||||
wqlQueryBuilder.Append(wqlCondition);
|
||||
this._wqlQuery = wqlQueryBuilder.ToString();
|
||||
_wqlQuery = wqlQueryBuilder.ToString();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(wqlCondition))
|
||||
{
|
||||
this._useEnumerateInstances = true;
|
||||
_useEnumerateInstances = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jobContext.CmdletInvocationContext.CmdletDefinitionContext.UseEnumerateInstancesInsteadOfWql)
|
||||
{
|
||||
this._useEnumerateInstances = true;
|
||||
_useEnumerateInstances = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,9 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
internal override IObservable<CimInstance> GetCimOperation()
|
||||
{
|
||||
this.WriteVerboseStartOfCimOperation();
|
||||
|
||||
|
||||
IObservable<CimInstance> observable;
|
||||
if (this._useEnumerateInstances)
|
||||
if (_useEnumerateInstances)
|
||||
{
|
||||
observable = this.JobContext.Session.EnumerateInstancesAsync(
|
||||
this.JobContext.Namespace,
|
||||
@@ -59,7 +59,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
observable = this.JobContext.Session.QueryInstancesAsync(
|
||||
this.JobContext.Namespace,
|
||||
"WQL",
|
||||
this._wqlQuery,
|
||||
_wqlQuery,
|
||||
this.CreateOperationOptions());
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal override string Description
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
return this.FailSafeDescription;
|
||||
}
|
||||
@@ -76,14 +76,14 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal override string FailSafeDescription
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
return string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
CmdletizationResources.CimJob_SafeQueryDescription,
|
||||
this.JobContext.CmdletizationClassName,
|
||||
this.JobContext.Session.ComputerName,
|
||||
this._wqlQuery);
|
||||
_wqlQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -33,7 +33,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._cimQuery.IsMatchingResult(item))
|
||||
if (!_cimQuery.IsMatchingResult(item))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
this.ExceptionSafeWrapper(
|
||||
delegate
|
||||
{
|
||||
foreach (ClientSideQuery.NotFoundError notFoundError in this._cimQuery.GenerateNotFoundErrors())
|
||||
foreach (ClientSideQuery.NotFoundError notFoundError in _cimQuery.GenerateNotFoundErrors())
|
||||
{
|
||||
string errorId = "CmdletizationQuery_NotFound";
|
||||
if (!string.IsNullOrEmpty(notFoundError.PropertyName))
|
||||
@@ -70,7 +70,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
|
||||
{
|
||||
return CimCustomOptionsDictionary.Create(this._cimQuery.queryOptions);
|
||||
return CimCustomOptionsDictionary.Create(_cimQuery.queryOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-20
@@ -22,7 +22,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
#region Getting tracker for a given cmdlet invocation
|
||||
|
||||
private static readonly ConditionalWeakTable<InvocationInfo, TerminatingErrorTracker> InvocationToTracker =
|
||||
private static readonly ConditionalWeakTable<InvocationInfo, TerminatingErrorTracker> s_invocationToTracker =
|
||||
new ConditionalWeakTable<InvocationInfo, TerminatingErrorTracker>();
|
||||
|
||||
private static int GetNumberOfSessions(InvocationInfo invocationInfo)
|
||||
@@ -31,7 +31,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
object cimSessionArgument;
|
||||
if (invocationInfo.BoundParameters.TryGetValue("CimSession", out cimSessionArgument))
|
||||
{
|
||||
IList cimSessionArgumentAsList = (IList) cimSessionArgument;
|
||||
IList cimSessionArgumentAsList = (IList)cimSessionArgument;
|
||||
return cimSessionArgumentAsList.Count;
|
||||
}
|
||||
// else - either CimSession=localhost OR CimSession is based on CimInstance->CimSession affinity
|
||||
@@ -59,7 +59,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
.Distinct()
|
||||
.Count();
|
||||
maxNumberOfSessionsIndicatedByCimInstanceArguments = Math.Max(
|
||||
maxNumberOfSessionsIndicatedByCimInstanceArguments,
|
||||
maxNumberOfSessionsIndicatedByCimInstanceArguments,
|
||||
numberOfSessionsAssociatedWithArgument);
|
||||
}
|
||||
}
|
||||
@@ -68,17 +68,17 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal static TerminatingErrorTracker GetTracker(InvocationInfo invocationInfo, bool isStaticCmdlet)
|
||||
{
|
||||
var tracker = InvocationToTracker.GetValue(
|
||||
var tracker = s_invocationToTracker.GetValue(
|
||||
invocationInfo,
|
||||
_ => new TerminatingErrorTracker(GetNumberOfSessions(invocationInfo)));
|
||||
|
||||
return tracker;
|
||||
}
|
||||
|
||||
|
||||
internal static TerminatingErrorTracker GetTracker(InvocationInfo invocationInfo)
|
||||
{
|
||||
TerminatingErrorTracker tracker;
|
||||
bool foundTracker = InvocationToTracker.TryGetValue(invocationInfo, out tracker);
|
||||
bool foundTracker = s_invocationToTracker.TryGetValue(invocationInfo, out tracker);
|
||||
Dbg.Assert(foundTracker, "The other overload of GetTracker should always be called first");
|
||||
return tracker;
|
||||
}
|
||||
@@ -92,7 +92,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
private TerminatingErrorTracker(int numberOfSessions)
|
||||
{
|
||||
this._numberOfSessions = numberOfSessions;
|
||||
_numberOfSessions = numberOfSessions;
|
||||
}
|
||||
|
||||
#region Tracking session's "connectivity" status
|
||||
@@ -101,13 +101,13 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal void MarkSessionAsConnected(CimSession connectedSession)
|
||||
{
|
||||
this._sessionToIsConnected.TryAdd(connectedSession, true);
|
||||
_sessionToIsConnected.TryAdd(connectedSession, true);
|
||||
}
|
||||
|
||||
internal bool DidSessionAlreadyPassedConnectivityTest(CimSession session)
|
||||
{
|
||||
bool alreadyPassedConnectivityTest = false;
|
||||
if (this._sessionToIsConnected.TryGetValue(session, out alreadyPassedConnectivityTest))
|
||||
if (_sessionToIsConnected.TryGetValue(session, out alreadyPassedConnectivityTest))
|
||||
{
|
||||
return alreadyPassedConnectivityTest;
|
||||
}
|
||||
@@ -115,7 +115,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
|
||||
internal Exception GetExceptionIfBrokenSession(
|
||||
CimSession potentiallyBrokenSession,
|
||||
CimSession potentiallyBrokenSession,
|
||||
bool skipTestConnection,
|
||||
out bool sessionWasAlreadyTerminated)
|
||||
{
|
||||
@@ -167,11 +167,11 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
internal void MarkSessionAsTerminated(CimSession terminatedSession, out bool sessionWasAlreadyTerminated)
|
||||
{
|
||||
bool closureSafeSessionWasAlreadyTerminated = false;
|
||||
this._sessionToIsTerminated.AddOrUpdate(
|
||||
_sessionToIsTerminated.AddOrUpdate(
|
||||
key: terminatedSession,
|
||||
addValue: true,
|
||||
updateValueFactory:
|
||||
delegate(CimSession key, bool isTerminatedValueInDictionary)
|
||||
delegate (CimSession key, bool isTerminatedValueInDictionary)
|
||||
{
|
||||
closureSafeSessionWasAlreadyTerminated = isTerminatedValueInDictionary;
|
||||
return true;
|
||||
@@ -182,7 +182,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal bool IsSessionTerminated(CimSession session)
|
||||
{
|
||||
bool isTerminated = this._sessionToIsTerminated.GetOrAdd(session, false);
|
||||
bool isTerminated = _sessionToIsTerminated.GetOrAdd(session, false);
|
||||
return isTerminated;
|
||||
}
|
||||
|
||||
@@ -196,8 +196,8 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
object lockObject = new object();
|
||||
Func<Cmdlet, bool> action = delegate (Cmdlet cmdlet)
|
||||
{
|
||||
this._numberOfReportedSessionTerminatingErrors++;
|
||||
if (this._numberOfReportedSessionTerminatingErrors >= this._numberOfSessions)
|
||||
_numberOfReportedSessionTerminatingErrors++;
|
||||
if (_numberOfReportedSessionTerminatingErrors >= _numberOfSessions)
|
||||
{
|
||||
cmdlet.ThrowTerminatingError(errorRecord);
|
||||
}
|
||||
@@ -210,11 +210,11 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
};
|
||||
|
||||
return new CmdletMethodInvoker<bool>
|
||||
{
|
||||
Action = action,
|
||||
Finished = manualResetEventSlim, // not really needed here, but required by CmdletMethodInvoker
|
||||
SyncObject = lockObject, // not really needed here, but required by CmdletMethodInvoker
|
||||
};
|
||||
{
|
||||
Action = action,
|
||||
Finished = manualResetEventSlim, // not really needed here, but required by CmdletMethodInvoker
|
||||
SyncObject = lockObject, // not really needed here, but required by CmdletMethodInvoker
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
+105
-105
@@ -27,19 +27,19 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// <summary>
|
||||
/// Base class for all child jobs that wrap CIM operations
|
||||
/// </summary>
|
||||
internal abstract class CimChildJobBase<T> :
|
||||
StartableJob,
|
||||
internal abstract class CimChildJobBase<T> :
|
||||
StartableJob,
|
||||
IObserver<T>
|
||||
{
|
||||
private static long _globalJobNumberCounter;
|
||||
private readonly long _myJobNumber = Interlocked.Increment(ref _globalJobNumberCounter);
|
||||
private static long s_globalJobNumberCounter;
|
||||
private readonly long _myJobNumber = Interlocked.Increment(ref s_globalJobNumberCounter);
|
||||
private const string CIMJobType = "CimJob";
|
||||
|
||||
internal CimJobContext JobContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._jobContext;
|
||||
return _jobContext;
|
||||
}
|
||||
}
|
||||
private readonly CimJobContext _jobContext;
|
||||
@@ -47,18 +47,18 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
internal CimChildJobBase(CimJobContext jobContext)
|
||||
: base(Job.GetCommandTextFromInvocationInfo(jobContext.CmdletInvocationInfo), " " /* temporary name - reset below */)
|
||||
{
|
||||
this._jobContext = jobContext;
|
||||
_jobContext = jobContext;
|
||||
this.PSJobTypeName = CIMJobType;
|
||||
|
||||
this.Name = this.GetType().Name + this._myJobNumber.ToString(CultureInfo.InvariantCulture);
|
||||
this.Name = this.GetType().Name + _myJobNumber.ToString(CultureInfo.InvariantCulture);
|
||||
UsesResultsCollection = true;
|
||||
|
||||
lock (GlobalRandom)
|
||||
lock (s_globalRandom)
|
||||
{
|
||||
this._random = new Random(GlobalRandom.Next());
|
||||
_random = new Random(s_globalRandom.Next());
|
||||
}
|
||||
|
||||
this._jobSpecificCustomOptions = new Lazy<CimCustomOptionsDictionary>(this.CalculateJobSpecificCustomOptions);
|
||||
_jobSpecificCustomOptions = new Lazy<CimCustomOptionsDictionary>(this.CalculateJobSpecificCustomOptions);
|
||||
}
|
||||
|
||||
private CimSensitiveValueConverter _cimSensitiveValueConverter = new CimSensitiveValueConverter();
|
||||
@@ -77,7 +77,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
ERROR_WSMAN_QUOTA_SYSTEM = 0x803381A8,
|
||||
ERROR_WSMAN_QUOTA_MAX_SHELLUSERS = 0x803381AB,
|
||||
ERROR_WSMAN_QUOTA_MAX_SHELLS_PPQ = 0x803381E4,
|
||||
ERROR_WSMAN_QUOTA_MAX_USERS_PPQ = 0x803381E5,
|
||||
ERROR_WSMAN_QUOTA_MAX_USERS_PPQ = 0x803381E5,
|
||||
ERROR_WSMAN_QUOTA_MAX_PLUGINSHELLS_PPQ = 0x803381E6,
|
||||
ERROR_WSMAN_QUOTA_MAX_PLUGINOPERATIONS_PPQ = 0x803381E7,
|
||||
ERROR_WSMAN_QUOTA_MAX_OPERATIONS_USER_PPQ = 0x803381E8,
|
||||
@@ -114,7 +114,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
return false;
|
||||
}
|
||||
|
||||
WsManErrorCode wsManErrorCode = (WsManErrorCode) (UInt32) (errorCodeProperty.Value);
|
||||
WsManErrorCode wsManErrorCode = (WsManErrorCode)(UInt32)(errorCodeProperty.Value);
|
||||
switch (wsManErrorCode) // error codes that should result in sleep-and-retry are based on an email from Ryan
|
||||
{
|
||||
case WsManErrorCode.ERROR_WSMAN_QUOTA_MAX_SHELLS:
|
||||
@@ -161,7 +161,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
});
|
||||
}
|
||||
|
||||
private static readonly Random GlobalRandom = new Random();
|
||||
private static readonly Random s_globalRandom = new Random();
|
||||
private readonly Random _random;
|
||||
private int _sleepAndRetryDelayRangeMs = 1000;
|
||||
private int _sleepAndRetryExtraDelayMs = 0;
|
||||
@@ -173,14 +173,14 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
this.ExceptionSafeWrapper(
|
||||
delegate
|
||||
{
|
||||
lock (this._jobStateLock)
|
||||
lock (_jobStateLock)
|
||||
{
|
||||
if (this._sleepAndRetryTimer != null)
|
||||
if (_sleepAndRetryTimer != null)
|
||||
{
|
||||
this._sleepAndRetryTimer.Dispose();
|
||||
this._sleepAndRetryTimer = null;
|
||||
_sleepAndRetryTimer.Dispose();
|
||||
_sleepAndRetryTimer = null;
|
||||
}
|
||||
if (this._jobWasStopped)
|
||||
if (_jobWasStopped)
|
||||
{
|
||||
this.SetCompletedJobState(JobState.Stopped, null);
|
||||
return;
|
||||
@@ -191,12 +191,12 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
private void SleepAndRetry()
|
||||
{
|
||||
int tmpRandomDelay = _random.Next(0, this._sleepAndRetryDelayRangeMs);
|
||||
int delay = MinRetryDelayMs + this._sleepAndRetryExtraDelayMs + tmpRandomDelay;
|
||||
this._sleepAndRetryExtraDelayMs = _sleepAndRetryDelayRangeMs - tmpRandomDelay;
|
||||
if (this._sleepAndRetryDelayRangeMs < MaxRetryDelayMs)
|
||||
int tmpRandomDelay = _random.Next(0, _sleepAndRetryDelayRangeMs);
|
||||
int delay = MinRetryDelayMs + _sleepAndRetryExtraDelayMs + tmpRandomDelay;
|
||||
_sleepAndRetryExtraDelayMs = _sleepAndRetryDelayRangeMs - tmpRandomDelay;
|
||||
if (_sleepAndRetryDelayRangeMs < MaxRetryDelayMs)
|
||||
{
|
||||
this._sleepAndRetryDelayRangeMs *= 2;
|
||||
_sleepAndRetryDelayRangeMs *= 2;
|
||||
}
|
||||
|
||||
string verboseMessage = string.Format(
|
||||
@@ -207,16 +207,16 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
delay / 1000.0);
|
||||
this.WriteVerbose(verboseMessage);
|
||||
|
||||
lock (this._jobStateLock)
|
||||
lock (_jobStateLock)
|
||||
{
|
||||
if (this._jobWasStopped)
|
||||
if (_jobWasStopped)
|
||||
{
|
||||
this.SetCompletedJobState(JobState.Stopped, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Dbg.Assert(this._sleepAndRetryTimer == null, "There should be only 1 active _sleepAndRetryTimer");
|
||||
this._sleepAndRetryTimer = new Timer(
|
||||
Dbg.Assert(_sleepAndRetryTimer == null, "There should be only 1 active _sleepAndRetryTimer");
|
||||
_sleepAndRetryTimer = new Timer(
|
||||
state: null,
|
||||
dueTime: delay,
|
||||
period: Timeout.Infinite,
|
||||
@@ -230,7 +230,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// </summary>
|
||||
public override string Location
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
// this.JobContext is set in the constructor of CimChildJobBase,
|
||||
// but the constructor of Job wants to access Location property
|
||||
@@ -250,7 +250,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// </summary>
|
||||
public override string StatusMessage
|
||||
{
|
||||
get
|
||||
get
|
||||
{
|
||||
return this.JobStateInfo.State.ToString();
|
||||
}
|
||||
@@ -261,8 +261,8 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// </summary>
|
||||
public override bool HasMoreData
|
||||
{
|
||||
get
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Results.IsOpen || Results.Count > 0);
|
||||
}
|
||||
}
|
||||
@@ -281,15 +281,15 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal override void StartJob()
|
||||
{
|
||||
lock (this._jobStateLock)
|
||||
lock (_jobStateLock)
|
||||
{
|
||||
if (this._jobWasStopped)
|
||||
if (_jobWasStopped)
|
||||
{
|
||||
this.SetCompletedJobState(JobState.Stopped, null);
|
||||
return;
|
||||
}
|
||||
|
||||
Dbg.Assert(!this._alreadyReachedCompletedState, "Job shouldn't reach completed state, before ThrottlingJob has a chance to register for job-completed/failed events");
|
||||
Dbg.Assert(!_alreadyReachedCompletedState, "Job shouldn't reach completed state, before ThrottlingJob has a chance to register for job-completed/failed events");
|
||||
|
||||
TerminatingErrorTracker tracker = TerminatingErrorTracker.GetTracker(this.JobContext.CmdletInvocationInfo);
|
||||
if (tracker.IsSessionTerminated(this.JobContext.Session))
|
||||
@@ -298,16 +298,17 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._jobWasStarted)
|
||||
if (!_jobWasStarted)
|
||||
{
|
||||
this._jobWasStarted = true;
|
||||
_jobWasStarted = true;
|
||||
this.SetJobState(JobState.Running);
|
||||
}
|
||||
}
|
||||
|
||||
// This invocation can block (i.e. by calling Job.ShouldProcess) and wait for pipeline thread to unblock it
|
||||
// Therefore we have to do the invocation outside of the pipeline thread.
|
||||
ThreadPool.QueueUserWorkItem(delegate {
|
||||
ThreadPool.QueueUserWorkItem(delegate
|
||||
{
|
||||
this.ExceptionSafeWrapper(delegate
|
||||
{
|
||||
IObservable<T> observable = this.GetCimOperation();
|
||||
@@ -358,14 +359,14 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
catch (PSInvalidOperationException)
|
||||
{
|
||||
lock (this._jobStateLock)
|
||||
lock (_jobStateLock)
|
||||
{
|
||||
bool everythingIsOk = false;
|
||||
if (this._jobWasStopped)
|
||||
if (_jobWasStopped)
|
||||
{
|
||||
everythingIsOk = true;
|
||||
}
|
||||
if (this._alreadyReachedCompletedState && this._jobHadErrors)
|
||||
if (_alreadyReachedCompletedState && _jobHadErrors)
|
||||
{
|
||||
everythingIsOk = true;
|
||||
}
|
||||
@@ -394,13 +395,13 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
internal CimOperationOptions CreateOperationOptions()
|
||||
{
|
||||
var operationOptions = new CimOperationOptions(mustUnderstand: false)
|
||||
{
|
||||
CancellationToken = this._cancellationTokenSource.Token,
|
||||
WriteProgress = this.WriteProgressCallback,
|
||||
WriteMessage = this.WriteMessageCallback,
|
||||
WriteError = this.WriteErrorCallback,
|
||||
PromptUser = this.PromptUserCallback,
|
||||
};
|
||||
{
|
||||
CancellationToken = _cancellationTokenSource.Token,
|
||||
WriteProgress = this.WriteProgressCallback,
|
||||
WriteMessage = this.WriteMessageCallback,
|
||||
WriteError = this.WriteErrorCallback,
|
||||
PromptUser = this.PromptUserCallback,
|
||||
};
|
||||
|
||||
operationOptions.SetOption("__MI_OPERATIONOPTIONS_IMPROVEDPERF_STREAMING", 1);
|
||||
|
||||
@@ -464,7 +465,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
case MshCommandRuntime.ShouldProcessPossibleOptimization.NoOptimizationPossible:
|
||||
default:
|
||||
operationOptions.PromptUserMode = CimCallbackMode.Inquire;
|
||||
operationOptions.PromptUserMode = CimCallbackMode.Inquire;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -486,31 +487,31 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
if (!string.IsNullOrWhiteSpace(this.GetProviderVersionExpectedByJob()))
|
||||
{
|
||||
CimOperationOptionsHelper.SetCustomOption(
|
||||
operationOptions,
|
||||
"MI_OPERATIONOPTIONS_PROVIDERVERSION",
|
||||
this.GetProviderVersionExpectedByJob(),
|
||||
operationOptions,
|
||||
"MI_OPERATIONOPTIONS_PROVIDERVERSION",
|
||||
this.GetProviderVersionExpectedByJob(),
|
||||
CimSensitiveValueConverter);
|
||||
}
|
||||
|
||||
if (this.JobContext.CmdletizationModuleVersion != null)
|
||||
{
|
||||
CimOperationOptionsHelper.SetCustomOption(
|
||||
operationOptions,
|
||||
"MI_OPERATIONOPTIONS_POWERSHELL_MODULEVERSION",
|
||||
this.JobContext.CmdletizationModuleVersion,
|
||||
operationOptions,
|
||||
"MI_OPERATIONOPTIONS_POWERSHELL_MODULEVERSION",
|
||||
this.JobContext.CmdletizationModuleVersion,
|
||||
CimSensitiveValueConverter);
|
||||
}
|
||||
CimOperationOptionsHelper.SetCustomOption(
|
||||
operationOptions,
|
||||
"MI_OPERATIONOPTIONS_POWERSHELL_CMDLETNAME",
|
||||
this.JobContext.CmdletInvocationInfo.MyCommand.Name,
|
||||
operationOptions,
|
||||
"MI_OPERATIONOPTIONS_POWERSHELL_CMDLETNAME",
|
||||
this.JobContext.CmdletInvocationInfo.MyCommand.Name,
|
||||
CimSensitiveValueConverter);
|
||||
if (!string.IsNullOrWhiteSpace(this.JobContext.Session.ComputerName))
|
||||
{
|
||||
CimOperationOptionsHelper.SetCustomOption(
|
||||
operationOptions,
|
||||
"MI_OPERATIONOPTIONS_POWERSHELL_COMPUTERNAME",
|
||||
this.JobContext.Session.ComputerName,
|
||||
operationOptions,
|
||||
"MI_OPERATIONOPTIONS_POWERSHELL_COMPUTERNAME",
|
||||
this.JobContext.Session.ComputerName,
|
||||
CimSensitiveValueConverter);
|
||||
}
|
||||
|
||||
@@ -542,22 +543,22 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// </summary>
|
||||
public override void StopJob()
|
||||
{
|
||||
lock (this._jobStateLock)
|
||||
lock (_jobStateLock)
|
||||
{
|
||||
if (this._jobWasStopped || this._alreadyReachedCompletedState)
|
||||
if (_jobWasStopped || _alreadyReachedCompletedState)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this._jobWasStopped = true;
|
||||
_jobWasStopped = true;
|
||||
|
||||
if (!_jobWasStarted)
|
||||
{
|
||||
this.SetCompletedJobState(JobState.Stopped, null);
|
||||
}
|
||||
else if (this._sleepAndRetryTimer != null)
|
||||
else if (_sleepAndRetryTimer != null)
|
||||
{
|
||||
this._sleepAndRetryTimer.Dispose();
|
||||
this._sleepAndRetryTimer = null;
|
||||
_sleepAndRetryTimer.Dispose();
|
||||
_sleepAndRetryTimer = null;
|
||||
this.SetCompletedJobState(JobState.Stopped, null);
|
||||
}
|
||||
else
|
||||
@@ -565,7 +566,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
this.SetJobState(JobState.Stopping);
|
||||
}
|
||||
}
|
||||
this._cancellationTokenSource.Cancel();
|
||||
_cancellationTokenSource.Cancel();
|
||||
}
|
||||
|
||||
private readonly object _jobStateLock = new object();
|
||||
@@ -578,9 +579,9 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (this._jobStateLock)
|
||||
lock (_jobStateLock)
|
||||
{
|
||||
return this._jobHadErrors;
|
||||
return _jobHadErrors;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -592,9 +593,9 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
bool sessionWasAlreadyTerminated = false;
|
||||
bool isThisTerminatingError = false;
|
||||
Exception brokenSessionException = null;
|
||||
lock (this._jobStateLock)
|
||||
lock (_jobStateLock)
|
||||
{
|
||||
if (!this._jobWasStopped)
|
||||
if (!_jobWasStopped)
|
||||
{
|
||||
brokenSessionException = terminatingErrorTracker.GetExceptionIfBrokenSession(
|
||||
this.JobContext.Session,
|
||||
@@ -629,9 +630,9 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
bool writeError = !sessionWasAlreadyTerminated;
|
||||
if (writeError)
|
||||
{
|
||||
lock (this._jobStateLock)
|
||||
lock (_jobStateLock)
|
||||
{
|
||||
if (this._jobWasStopped)
|
||||
if (_jobWasStopped)
|
||||
{
|
||||
writeError = false;
|
||||
}
|
||||
@@ -644,7 +645,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
if (writeError)
|
||||
{
|
||||
lock (this._jobStateLock)
|
||||
lock (_jobStateLock)
|
||||
{
|
||||
if (!_alreadyReachedCompletedState)
|
||||
{
|
||||
@@ -661,7 +662,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.SetCompletedJobState(JobState.Failed, errorRecord.Exception);
|
||||
}
|
||||
|
||||
@@ -685,7 +686,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal void SetCompletedJobState(JobState state, Exception reason)
|
||||
{
|
||||
lock (this._jobStateLock)
|
||||
lock (_jobStateLock)
|
||||
{
|
||||
if (_alreadyReachedCompletedState)
|
||||
{
|
||||
@@ -696,14 +697,14 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
if ((state == JobState.Failed) || (reason != null))
|
||||
{
|
||||
this._jobHadErrors = true;
|
||||
_jobHadErrors = true;
|
||||
}
|
||||
|
||||
if (this._jobWasStopped)
|
||||
if (_jobWasStopped)
|
||||
{
|
||||
state = JobState.Stopped;
|
||||
}
|
||||
else if (this._jobHadErrors)
|
||||
else if (_jobHadErrors)
|
||||
{
|
||||
state = JobState.Failed;
|
||||
}
|
||||
@@ -712,22 +713,22 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
this.FinishProgressReporting();
|
||||
this.SetJobState(state, reason);
|
||||
this.CloseAllStreams();
|
||||
this._cancellationTokenSource.Cancel();
|
||||
_cancellationTokenSource.Cancel();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Support for progress reporting
|
||||
|
||||
private readonly ConcurrentDictionary<int, ProgressRecord> _activityIdToLastProgressRecord = new ConcurrentDictionary<int,ProgressRecord>();
|
||||
private readonly ConcurrentDictionary<int, ProgressRecord> _activityIdToLastProgressRecord = new ConcurrentDictionary<int, ProgressRecord>();
|
||||
|
||||
internal override void WriteProgress(ProgressRecord progressRecord)
|
||||
{
|
||||
progressRecord.Activity = this.JobContext.PrependComputerNameToMessage(progressRecord.Activity);
|
||||
|
||||
this._activityIdToLastProgressRecord.AddOrUpdate(
|
||||
progressRecord.ActivityId,
|
||||
progressRecord,
|
||||
_activityIdToLastProgressRecord.AddOrUpdate(
|
||||
progressRecord.ActivityId,
|
||||
progressRecord,
|
||||
(activityId, oldProgressRecord) => progressRecord);
|
||||
|
||||
base.WriteProgress(progressRecord);
|
||||
@@ -735,7 +736,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal void FinishProgressReporting()
|
||||
{
|
||||
foreach (ProgressRecord lastProgressRecord in this._activityIdToLastProgressRecord.Values)
|
||||
foreach (ProgressRecord lastProgressRecord in _activityIdToLastProgressRecord.Values)
|
||||
{
|
||||
if (lastProgressRecord.RecordType != ProgressRecordType.Completed)
|
||||
{
|
||||
@@ -746,7 +747,6 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
this.WriteProgress(newProgressRecord);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -771,7 +771,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
else if (secondsRemaining <= Int32.MaxValue)
|
||||
{
|
||||
signedSecondsRemaining = (Int32) secondsRemaining;
|
||||
signedSecondsRemaining = (Int32)secondsRemaining;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -785,20 +785,20 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
else if (percentageCompleted <= 100)
|
||||
{
|
||||
signedPercentageComplete = (Int32) percentageCompleted;
|
||||
signedPercentageComplete = (Int32)percentageCompleted;
|
||||
}
|
||||
else
|
||||
{
|
||||
signedPercentageComplete = 100;
|
||||
}
|
||||
|
||||
var progressRecord = new ProgressRecord(unchecked((int)(this._myJobNumber % int.MaxValue)), activity, statusDescription)
|
||||
{
|
||||
CurrentOperation = currentOperation,
|
||||
PercentComplete = signedPercentageComplete,
|
||||
SecondsRemaining = signedSecondsRemaining,
|
||||
RecordType = ProgressRecordType.Processing,
|
||||
};
|
||||
var progressRecord = new ProgressRecord(unchecked((int)(_myJobNumber % int.MaxValue)), activity, statusDescription)
|
||||
{
|
||||
CurrentOperation = currentOperation,
|
||||
PercentComplete = signedPercentageComplete,
|
||||
SecondsRemaining = signedSecondsRemaining,
|
||||
RecordType = ProgressRecordType.Processing,
|
||||
};
|
||||
|
||||
this.ExceptionSafeWrapper(
|
||||
delegate
|
||||
@@ -856,9 +856,9 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
private CimResponseType WriteErrorCallback(CimInstance cimError)
|
||||
{
|
||||
lock (this._jobStateLock)
|
||||
lock (_jobStateLock)
|
||||
{
|
||||
this._jobHadErrors = true;
|
||||
_jobHadErrors = true;
|
||||
}
|
||||
|
||||
var cimException = new CimException(cimError);
|
||||
@@ -898,7 +898,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
return ShouldProcess(verboseDescription, null, null);
|
||||
}
|
||||
|
||||
|
||||
internal CimResponseType ShouldProcess(
|
||||
string verboseDescription,
|
||||
string verboseWarning,
|
||||
@@ -949,7 +949,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
Exception exceptionThrownOnCmdletThread = null;
|
||||
CimResponseType result = CimResponseType.No;
|
||||
|
||||
this._userWasPromptedForContinuationOfProcessing = true;
|
||||
_userWasPromptedForContinuationOfProcessing = true;
|
||||
switch (promptType)
|
||||
{
|
||||
case CimPromptType.Critical:
|
||||
@@ -987,7 +987,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
if ((result == CimResponseType.Yes) || (result == CimResponseType.YesToAll))
|
||||
{
|
||||
this._userRespondedYesToAtLeastOneShouldProcess = true;
|
||||
_userRespondedYesToAtLeastOneShouldProcess = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1041,12 +1041,12 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
if (pso == null)
|
||||
{
|
||||
pso = PSObject.AsPSObject(outputObject);
|
||||
pso = PSObject.AsPSObject(outputObject);
|
||||
}
|
||||
AddShowComputerNameMarker(pso);
|
||||
if(cimInstance == null)
|
||||
if (cimInstance == null)
|
||||
{
|
||||
pso.Properties.Add(new PSNoteProperty(RemotingConstants.ComputerNameNoteProperty,this.JobContext.Session.ComputerName));
|
||||
pso.Properties.Add(new PSNoteProperty(RemotingConstants.ComputerNameNoteProperty, this.JobContext.Session.ComputerName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1058,9 +1058,9 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
if (disposing)
|
||||
{
|
||||
bool isCompleted;
|
||||
lock (this._jobStateLock)
|
||||
lock (_jobStateLock)
|
||||
{
|
||||
isCompleted = this._alreadyReachedCompletedState;
|
||||
isCompleted = _alreadyReachedCompletedState;
|
||||
}
|
||||
if (!isCompleted)
|
||||
{
|
||||
|
||||
+23
-23
@@ -13,17 +13,17 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
internal class CimCmdletDefinitionContext
|
||||
{
|
||||
internal CimCmdletDefinitionContext(
|
||||
string cmdletizationClassName,
|
||||
string cmdletizationClassVersion,
|
||||
Version cmdletizationModuleVersion,
|
||||
bool supportsShouldProcess,
|
||||
string cmdletizationClassName,
|
||||
string cmdletizationClassVersion,
|
||||
Version cmdletizationModuleVersion,
|
||||
bool supportsShouldProcess,
|
||||
IDictionary<string, string> privateData)
|
||||
{
|
||||
this.CmdletizationClassName = cmdletizationClassName;
|
||||
this.CmdletizationClassVersion = cmdletizationClassVersion;
|
||||
this.CmdletizationModuleVersion = cmdletizationModuleVersion;
|
||||
this.SupportsShouldProcess = supportsShouldProcess;
|
||||
this._privateData = privateData;
|
||||
_privateData = privateData;
|
||||
}
|
||||
|
||||
public string CmdletizationClassName { get; private set; }
|
||||
@@ -42,15 +42,15 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
bool newValue = false;
|
||||
string queryLanguage;
|
||||
if (this._privateData != null &&
|
||||
this._privateData.TryGetValue(QueryLanguageKey, out queryLanguage) &&
|
||||
if (_privateData != null &&
|
||||
_privateData.TryGetValue(QueryLanguageKey, out queryLanguage) &&
|
||||
queryLanguage.Equals("None", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
newValue = true;
|
||||
}
|
||||
this._useEnumerateInstancesInsteadOfWql = newValue;
|
||||
_useEnumerateInstancesInsteadOfWql = newValue;
|
||||
}
|
||||
return this._useEnumerateInstancesInsteadOfWql.Value;
|
||||
return _useEnumerateInstancesInsteadOfWql.Value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,10 +68,10 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
public int DefaultThrottleLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
get
|
||||
{
|
||||
string defaultThrottleLimitString;
|
||||
if (!this._privateData.TryGetValue("DefaultThrottleLimit", out defaultThrottleLimitString))
|
||||
if (!_privateData.TryGetValue("DefaultThrottleLimit", out defaultThrottleLimitString))
|
||||
{
|
||||
return FallbackDefaultThrottleLimit;
|
||||
}
|
||||
@@ -88,19 +88,19 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
public bool ExposeCimNamespaceParameter
|
||||
{
|
||||
get { return this._privateData.ContainsKey("CimNamespaceParameter"); }
|
||||
get { return _privateData.ContainsKey("CimNamespaceParameter"); }
|
||||
}
|
||||
|
||||
public bool ClientSideWriteVerbose
|
||||
{
|
||||
get { return this._privateData.ContainsKey("ClientSideWriteVerbose"); }
|
||||
get { return _privateData.ContainsKey("ClientSideWriteVerbose"); }
|
||||
}
|
||||
|
||||
public bool ClientSideShouldProcess
|
||||
{
|
||||
get
|
||||
{
|
||||
return this._privateData.ContainsKey("ClientSideShouldProcess");
|
||||
return _privateData.ContainsKey("ClientSideShouldProcess");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,22 +114,22 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
string newResourceUriString;
|
||||
Uri newResourceUri;
|
||||
if (this._privateData != null &&
|
||||
this._privateData.TryGetValue("ResourceUri", out newResourceUriString) &&
|
||||
if (_privateData != null &&
|
||||
_privateData.TryGetValue("ResourceUri", out newResourceUriString) &&
|
||||
Uri.TryCreate(newResourceUriString, UriKind.RelativeOrAbsolute, out newResourceUri))
|
||||
{
|
||||
this._resourceUri = newResourceUri;
|
||||
_resourceUri = newResourceUri;
|
||||
}
|
||||
|
||||
this._resourceUriHasBeenCalculated = true;
|
||||
_resourceUriHasBeenCalculated = true;
|
||||
}
|
||||
return this._resourceUri;
|
||||
return _resourceUri;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SkipTestConnection
|
||||
{
|
||||
get { return this._privateData.ContainsKey("SkipTestConnection"); }
|
||||
get { return _privateData.ContainsKey("SkipTestConnection"); }
|
||||
}
|
||||
|
||||
private CimOperationFlags? _schemaConformanceLevel;
|
||||
@@ -142,8 +142,8 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
CimOperationFlags newSchemaConformanceLevel = 0;
|
||||
|
||||
string schemaConformanceFromCdxml;
|
||||
if (this._privateData != null &&
|
||||
this._privateData.TryGetValue("TypeInformation", out schemaConformanceFromCdxml))
|
||||
if (_privateData != null &&
|
||||
_privateData.TryGetValue("TypeInformation", out schemaConformanceFromCdxml))
|
||||
{
|
||||
if (schemaConformanceFromCdxml.Equals("Basic", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
|
||||
+8
-8
@@ -13,7 +13,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
internal CimCmdletInvocationContext(
|
||||
CimCmdletDefinitionContext cmdletDefinitionContext,
|
||||
Cmdlet cmdlet,
|
||||
Cmdlet cmdlet,
|
||||
string namespaceOverride)
|
||||
{
|
||||
this.CmdletDefinitionContext = cmdletDefinitionContext;
|
||||
@@ -22,7 +22,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
// Cmdlet might have a shorter lifespan than CimCmdletInvocationContext
|
||||
// - we need to extract information out of Cmdlet to extend information's lifespan
|
||||
|
||||
this.CmdletInvocationInfo = cmdlet.MyInvocation;
|
||||
this.CmdletInvocationInfo = cmdlet.MyInvocation;
|
||||
|
||||
var runtime = cmdlet.CommandRuntime as MshCommandRuntime;
|
||||
Dbg.Assert(runtime != null, "CIM cmdlets should only be run from within PS runtime");
|
||||
@@ -30,17 +30,17 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
this.DebugActionPreference = runtime.DebugPreference;
|
||||
WarnAboutUnsupportedActionPreferences(
|
||||
cmdlet,
|
||||
this.DebugActionPreference,
|
||||
"Debug",
|
||||
inquireMessageGetter: () => CmdletizationResources.CimCmdletAdapter_DebugInquire,
|
||||
this.DebugActionPreference,
|
||||
"Debug",
|
||||
inquireMessageGetter: () => CmdletizationResources.CimCmdletAdapter_DebugInquire,
|
||||
stopMessageGetter: () => string.Empty);
|
||||
|
||||
this.WarningActionPreference = runtime.WarningPreference;
|
||||
WarnAboutUnsupportedActionPreferences(
|
||||
cmdlet,
|
||||
this.WarningActionPreference,
|
||||
"WarningAction",
|
||||
inquireMessageGetter: () => CmdletizationResources.CimCmdletAdapter_WarningInquire,
|
||||
this.WarningActionPreference,
|
||||
"WarningAction",
|
||||
inquireMessageGetter: () => CmdletizationResources.CimCmdletAdapter_WarningInquire,
|
||||
stopMessageGetter: () => CmdletizationResources.CimCmdletAdapter_WarningStop);
|
||||
|
||||
this.VerboseActionPreference = runtime.VerbosePreference;
|
||||
|
||||
+10
-11
@@ -44,7 +44,7 @@ namespace Microsoft.PowerShell.Cim
|
||||
|
||||
#if !CORECLR // String.IsInterned Not In CoreCLR
|
||||
Debug.Assert(
|
||||
string.IsInterned(_string) == null,
|
||||
string.IsInterned(_string) == null,
|
||||
"We will overwrite string contents - we can't / shouldn't do this for interned strings.");
|
||||
#endif
|
||||
|
||||
@@ -170,9 +170,9 @@ namespace Microsoft.PowerShell.Cim
|
||||
|
||||
PSObject psObject = PSObject.AsPSObject(dotNetObject);
|
||||
Type dotNetType = psObject.BaseObject.GetType();
|
||||
if (typeof (PSCredential).IsAssignableFrom(dotNetType))
|
||||
if (typeof(PSCredential).IsAssignableFrom(dotNetType))
|
||||
{
|
||||
var credential = (PSCredential) (psObject.BaseObject);
|
||||
var credential = (PSCredential)(psObject.BaseObject);
|
||||
|
||||
string escapedUsername = credential.UserName;
|
||||
escapedUsername = escapedUsername.Replace("\\", "\\\\"); // Esc backslashes
|
||||
@@ -186,9 +186,9 @@ namespace Microsoft.PowerShell.Cim
|
||||
return sensitiveString.Value;
|
||||
}
|
||||
|
||||
if (typeof (SecureString).IsAssignableFrom(dotNetType))
|
||||
if (typeof(SecureString).IsAssignableFrom(dotNetType))
|
||||
{
|
||||
SecureString secureString = (SecureString) psObject.BaseObject;
|
||||
SecureString secureString = (SecureString)psObject.BaseObject;
|
||||
var sensitiveString = new SensitiveString(secureString.Length);
|
||||
lock (_trackedDisposables) { _trackedDisposables.Add(sensitiveString); }
|
||||
sensitiveString.Copy(secureString, 0);
|
||||
@@ -244,7 +244,7 @@ namespace Microsoft.PowerShell.Cim
|
||||
PSObject psObject = PSObject.AsPSObject(dotNetObject);
|
||||
Type dotNetType = psObject.BaseObject.GetType();
|
||||
Dbg.Assert(
|
||||
!(dotNetType.GetTypeInfo().IsGenericType && dotNetType.GetGenericTypeDefinition() == typeof (Nullable<>)),
|
||||
!(dotNetType.GetTypeInfo().IsGenericType && dotNetType.GetGenericTypeDefinition() == typeof(Nullable<>)),
|
||||
"GetType on a boxed object should never return Nullable<T>");
|
||||
|
||||
if (LanguagePrimitives.IsCimIntrinsicScalarType(dotNetType))
|
||||
@@ -394,7 +394,7 @@ namespace Microsoft.PowerShell.Cim
|
||||
return dotNetObject;
|
||||
}
|
||||
|
||||
Func<Func<object>, object> exceptionSafeReturn = delegate(Func<object> innerAction)
|
||||
Func<Func<object>, object> exceptionSafeReturn = delegate (Func<object> innerAction)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -402,7 +402,6 @@ namespace Microsoft.PowerShell.Cim
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
CommandProcessor.CheckForSevereException(e);
|
||||
throw CimValueConverter.GetInvalidCastException(
|
||||
e,
|
||||
@@ -470,7 +469,7 @@ namespace Microsoft.PowerShell.Cim
|
||||
return exceptionSafeReturn(delegate
|
||||
{
|
||||
XmlDocument doc = InternalDeserializer.LoadUnsafeXmlDocument(
|
||||
cimIntrinsicValue,
|
||||
cimIntrinsicValue,
|
||||
true, /* preserve non elements: whitespace, processing instructions, comments, etc. */
|
||||
null); /* default maxCharactersInDocument */
|
||||
return doc;
|
||||
@@ -671,8 +670,8 @@ namespace Microsoft.PowerShell.Cim
|
||||
(type.IsArray && LanguagePrimitives.IsCimIntrinsicScalarType(type.GetElementType())) ||
|
||||
typeof(CimInstance).IsAssignableFrom(type) ||
|
||||
typeof(PSReference).IsAssignableFrom(type) ||
|
||||
type == typeof (CimInstance[]) ||
|
||||
type == typeof (PSReference[]),
|
||||
type == typeof(CimInstance[]) ||
|
||||
type == typeof(PSReference[]),
|
||||
"Caller should verify that type is an intrinsic CIM type");
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
internal CimJobContext(
|
||||
CimCmdletInvocationContext cmdletInvocationContext,
|
||||
CimSession session,
|
||||
CimSession session,
|
||||
object targetObject)
|
||||
{
|
||||
this.CmdletInvocationContext = cmdletInvocationContext;
|
||||
|
||||
+11
-11
@@ -13,7 +13,7 @@ using Dbg = System.Management.Automation.Diagnostics;
|
||||
|
||||
namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
internal class CimCustomOptionsDictionary
|
||||
internal class CimCustomOptionsDictionary
|
||||
{
|
||||
private readonly IDictionary<string, object> _dict;
|
||||
private readonly object _dictModificationLock = new object();
|
||||
@@ -21,18 +21,18 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
private CimCustomOptionsDictionary(IEnumerable<KeyValuePair<string, object>> wrappedDictionary)
|
||||
{
|
||||
// no need to lock _dictModificationLock inside the constructor
|
||||
this._dict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
||||
_dict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var kvp in wrappedDictionary)
|
||||
{
|
||||
this._dict[kvp.Key] = kvp.Value;
|
||||
_dict[kvp.Key] = kvp.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<KeyValuePair<string, object>> GetSnapshot()
|
||||
{
|
||||
lock (this._dictModificationLock)
|
||||
lock (_dictModificationLock)
|
||||
{
|
||||
return this._dict.ToList();
|
||||
return _dict.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
return new CimCustomOptionsDictionary(wrappedDictionary);
|
||||
}
|
||||
|
||||
private static readonly ConditionalWeakTable<CimInstance, CimCustomOptionsDictionary> CimInstanceToCustomOptions = new ConditionalWeakTable<CimInstance, CimCustomOptionsDictionary>();
|
||||
private static readonly ConditionalWeakTable<CimInstance, CimCustomOptionsDictionary> s_cimInstanceToCustomOptions = new ConditionalWeakTable<CimInstance, CimCustomOptionsDictionary>();
|
||||
|
||||
internal static void AssociateCimInstanceWithCustomOptions(CimInstance cimInstance, CimCustomOptionsDictionary newCustomOptions)
|
||||
{
|
||||
@@ -59,7 +59,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
|
||||
bool foundAssociatedOptions = true;
|
||||
CimCustomOptionsDictionary oldCustomOptions = CimInstanceToCustomOptions.GetValue(
|
||||
CimCustomOptionsDictionary oldCustomOptions = s_cimInstanceToCustomOptions.GetValue(
|
||||
cimInstance,
|
||||
delegate
|
||||
{
|
||||
@@ -82,7 +82,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
internal static CimCustomOptionsDictionary MergeOptions(CimCustomOptionsDictionary optionsFromCommandLine, CimInstance instanceRelatedToThisOperation)
|
||||
{
|
||||
CimCustomOptionsDictionary instanceRelatedOptions;
|
||||
if (CimInstanceToCustomOptions.TryGetValue(instanceRelatedToThisOperation, out instanceRelatedOptions) && instanceRelatedOptions != null)
|
||||
if (s_cimInstanceToCustomOptions.TryGetValue(instanceRelatedToThisOperation, out instanceRelatedOptions) && instanceRelatedOptions != null)
|
||||
{
|
||||
IEnumerable<KeyValuePair<string, object>> instanceRelatedOptionsSnapshot = instanceRelatedOptions.GetSnapshot();
|
||||
IEnumerable<KeyValuePair<string, object>> optionsFromCommandLineSnapshot = optionsFromCommandLine.GetSnapshot();
|
||||
@@ -120,7 +120,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
internal static class CimOperationOptionsHelper
|
||||
{
|
||||
internal static void SetCustomOptions(
|
||||
CimOperationOptions operationOptions,
|
||||
CimOperationOptions operationOptions,
|
||||
IEnumerable<KeyValuePair<string, object>> customOptions,
|
||||
CimSensitiveValueConverter cimSensitiveValueConverter)
|
||||
{
|
||||
@@ -134,8 +134,8 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
|
||||
internal static void SetCustomOption(
|
||||
CimOperationOptions operationOptions,
|
||||
string optionName,
|
||||
CimOperationOptions operationOptions,
|
||||
string optionName,
|
||||
object optionValue,
|
||||
CimSensitiveValueConverter cimSensitiveValueConverter)
|
||||
{
|
||||
|
||||
+21
-21
@@ -21,12 +21,12 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// </summary>
|
||||
internal class CimQuery : QueryBuilder, ISessionBoundQueryBuilder<CimSession>
|
||||
{
|
||||
private readonly StringBuilder wqlCondition;
|
||||
private readonly StringBuilder _wqlCondition;
|
||||
|
||||
private CimInstance associatedObject;
|
||||
private string associationName;
|
||||
private string resultRole;
|
||||
private string sourceRole;
|
||||
private CimInstance _associatedObject;
|
||||
private string _associationName;
|
||||
private string _resultRole;
|
||||
private string _sourceRole;
|
||||
|
||||
internal readonly Dictionary<string, object> queryOptions = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal CimQuery()
|
||||
{
|
||||
this.wqlCondition = new StringBuilder();
|
||||
_wqlCondition = new StringBuilder();
|
||||
this.ClientSideQuery = new ClientSideQuery();
|
||||
}
|
||||
|
||||
@@ -42,11 +42,11 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
private void AddWqlCondition(string condition)
|
||||
{
|
||||
this.wqlCondition.Append(this.wqlCondition.Length != 0 ? " AND " : " WHERE ");
|
||||
_wqlCondition.Append(_wqlCondition.Length != 0 ? " AND " : " WHERE ");
|
||||
|
||||
this.wqlCondition.Append('(');
|
||||
this.wqlCondition.Append(condition);
|
||||
this.wqlCondition.Append(')');
|
||||
_wqlCondition.Append('(');
|
||||
_wqlCondition.Append(condition);
|
||||
_wqlCondition.Append(')');
|
||||
}
|
||||
|
||||
private static string ObjectToWqlLiteral(object o)
|
||||
@@ -76,7 +76,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
if (typeCode == TypeCode.DateTime)
|
||||
{
|
||||
var dateTime = (DateTime) LanguagePrimitives.ConvertTo(o, typeof (DateTime), CultureInfo.InvariantCulture);
|
||||
var dateTime = (DateTime)LanguagePrimitives.ConvertTo(o, typeof(DateTime), CultureInfo.InvariantCulture);
|
||||
string result = ClrFacade.ToDmtfDateTime(dateTime);
|
||||
return "'" + result + "'";
|
||||
}
|
||||
@@ -301,10 +301,10 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
public override void FilterByAssociatedInstance(object associatedInstance, string associationName, string sourceRole, string resultRole, BehaviorOnNoMatch behaviorOnNoMatch)
|
||||
{
|
||||
this.ClientSideQuery.FilterByAssociatedInstance(associatedInstance, associationName, sourceRole, resultRole, behaviorOnNoMatch);
|
||||
this.associatedObject = associatedInstance as CimInstance;
|
||||
this.associationName = associationName;
|
||||
this.resultRole = resultRole;
|
||||
this.sourceRole = sourceRole;
|
||||
_associatedObject = associatedInstance as CimInstance;
|
||||
_associationName = associationName;
|
||||
_resultRole = resultRole;
|
||||
_sourceRole = sourceRole;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -332,13 +332,13 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal StartableJob GetQueryJob(CimJobContext jobContext)
|
||||
{
|
||||
if (this.associationName == null)
|
||||
if (_associationName == null)
|
||||
{
|
||||
return new QueryInstancesJob(jobContext, this, this.wqlCondition.ToString());
|
||||
return new QueryInstancesJob(jobContext, this, _wqlCondition.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
return new EnumerateAssociatedInstancesJob(jobContext, this, this.associatedObject, this.associationName, this.resultRole, this.sourceRole);
|
||||
return new EnumerateAssociatedInstancesJob(jobContext, this, _associatedObject, _associationName, _resultRole, _sourceRole);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,9 +357,9 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
CimSession ISessionBoundQueryBuilder<CimSession>.GetTargetSession()
|
||||
{
|
||||
if (this.associatedObject != null)
|
||||
if (_associatedObject != null)
|
||||
{
|
||||
return CimCmdletAdapter.GetSessionOfOriginFromCimInstance(this.associatedObject);
|
||||
return CimCmdletAdapter.GetSessionOfOriginFromCimInstance(_associatedObject);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -370,7 +370,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// <returns>A string that represents the current CIM query</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return this.wqlCondition.ToString();
|
||||
return _wqlCondition.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-21
@@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// <summary>
|
||||
/// CIM-specific ObjectModelWrapper
|
||||
/// </summary>
|
||||
public sealed class CimCmdletAdapter :
|
||||
public sealed class CimCmdletAdapter :
|
||||
SessionBasedCmdletAdapter<CimInstance, CimSession>,
|
||||
IDynamicParameters
|
||||
{
|
||||
@@ -37,7 +37,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
[Parameter]
|
||||
[ValidateNotNullOrEmpty]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
[Alias("Session")]
|
||||
[Alias("Session")]
|
||||
public CimSession[] CimSession
|
||||
{
|
||||
get
|
||||
@@ -58,17 +58,17 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._throttleLimitIsSetExplicitly)
|
||||
if (_throttleLimitIsSetExplicitly)
|
||||
{
|
||||
return base.ThrottleLimit;
|
||||
}
|
||||
|
||||
return this.CmdletDefinitionContext.DefaultThrottleLimit;
|
||||
}
|
||||
set
|
||||
{
|
||||
set
|
||||
{
|
||||
base.ThrottleLimit = value;
|
||||
this._throttleLimitIsSetExplicitly = true;
|
||||
_throttleLimitIsSetExplicitly = true;
|
||||
}
|
||||
}
|
||||
private bool _throttleLimitIsSetExplicitly;
|
||||
@@ -92,7 +92,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
if (_cmdletInvocationContext == null)
|
||||
{
|
||||
this._cmdletInvocationContext = new CimCmdletInvocationContext(
|
||||
_cmdletInvocationContext = new CimCmdletInvocationContext(
|
||||
this.CmdletDefinitionContext,
|
||||
this.Cmdlet,
|
||||
this.GetDynamicNamespace());
|
||||
@@ -108,7 +108,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
if (_cmdletDefinitionContext == null)
|
||||
{
|
||||
this._cmdletDefinitionContext = new CimCmdletDefinitionContext(
|
||||
_cmdletDefinitionContext = new CimCmdletDefinitionContext(
|
||||
this.ClassName,
|
||||
this.ClassVersion,
|
||||
this.ModuleVersion,
|
||||
@@ -129,7 +129,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
#region SessionBasedCmdletAdapter overrides
|
||||
|
||||
private static long _jobNumber;
|
||||
private static long s_jobNumber;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new job name to use for the parent job that handles throttling of the child jobs that actually perform querying and method invocation.
|
||||
@@ -137,7 +137,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
/// <returns>Job name</returns>
|
||||
protected override string GenerateParentJobName()
|
||||
{
|
||||
return "CimJob" + Interlocked.Increment(ref CimCmdletAdapter._jobNumber).ToString(CultureInfo.InvariantCulture);
|
||||
return "CimJob" + Interlocked.Increment(ref CimCmdletAdapter.s_jobNumber).ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -211,7 +211,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
|
||||
CimJobContext jobContext = this.CreateJobContext(session, objectInstance);
|
||||
|
||||
|
||||
Dbg.Assert(objectInstance != null, "Caller should verify objectInstance != null");
|
||||
|
||||
StartableJob result;
|
||||
@@ -228,7 +228,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
result = new ModifyInstanceJob(
|
||||
jobContext,
|
||||
passThru,
|
||||
objectInstance,
|
||||
objectInstance,
|
||||
methodInvocationInfo);
|
||||
}
|
||||
else
|
||||
@@ -240,7 +240,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
methodInvocationInfo);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
private bool IsSupportedSession(CimSession cimSession, TerminatingErrorTracker terminatingErrorTracker)
|
||||
@@ -252,8 +252,8 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
if (cimSession.ComputerName != null && (!cimSession.ComputerName.Equals("localhost", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
PSPropertyInfo protocolProperty = PSObject.AsPSObject(cimSession).Properties["Protocol"];
|
||||
if ((protocolProperty != null) &&
|
||||
(protocolProperty.Value != null) &&
|
||||
if ((protocolProperty != null) &&
|
||||
(protocolProperty.Value != null) &&
|
||||
(protocolProperty.Value.ToString().Equals("DCOM", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
bool sessionWasAlreadyTerminated;
|
||||
@@ -326,19 +326,19 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
methodInvocationInfo);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion SessionBasedCmdletAdapter overrides
|
||||
|
||||
#region Session affinity management
|
||||
|
||||
private static readonly ConditionalWeakTable<CimInstance, CimSession> cimInstanceToSessionOfOrigin = new ConditionalWeakTable<CimInstance, CimSession>();
|
||||
private static readonly ConditionalWeakTable<CimInstance, CimSession> s_cimInstanceToSessionOfOrigin = new ConditionalWeakTable<CimInstance, CimSession>();
|
||||
|
||||
internal static void AssociateSessionOfOriginWithInstance(CimInstance cimInstance, CimSession sessionOfOrigin)
|
||||
{
|
||||
// GetValue adds value to the table, if the key is not present in the table
|
||||
cimInstanceToSessionOfOrigin.GetValue(cimInstance, _ => sessionOfOrigin);
|
||||
s_cimInstanceToSessionOfOrigin.GetValue(cimInstance, _ => sessionOfOrigin);
|
||||
}
|
||||
|
||||
internal static CimSession GetSessionOfOriginFromCimInstance(CimInstance instance)
|
||||
@@ -346,7 +346,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
CimSession result = null;
|
||||
if (instance != null)
|
||||
{
|
||||
cimInstanceToSessionOfOrigin.TryGetValue(instance, out result);
|
||||
s_cimInstanceToSessionOfOrigin.TryGetValue(instance, out result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -392,7 +392,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
namespaceAttributes.Add(new ParameterAttribute());
|
||||
RuntimeDefinedParameter namespaceRuntimeParameter = new RuntimeDefinedParameter(
|
||||
CimNamespaceParameter,
|
||||
typeof (string),
|
||||
typeof(string),
|
||||
namespaceAttributes);
|
||||
_dynamicParameters.Add(CimNamespaceParameter, namespaceRuntimeParameter);
|
||||
}
|
||||
@@ -402,6 +402,5 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
+37
-37
@@ -49,7 +49,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ErrorMessageGenerator =
|
||||
this.ErrorMessageGenerator =
|
||||
(queryDescription, className) => GetErrorMessageForNotFound_ForEquality(this.PropertyName, this.PropertyValue, className);
|
||||
}
|
||||
}
|
||||
@@ -134,7 +134,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
}
|
||||
else
|
||||
{
|
||||
return new[] {new NotFoundError()};
|
||||
return new[] { new NotFoundError() };
|
||||
}
|
||||
|
||||
case BehaviorOnNoMatch.SilentlyContinue:
|
||||
@@ -151,10 +151,10 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
private abstract class CimInstancePropertyBasedFilter : CimInstanceFilterBase
|
||||
{
|
||||
private readonly List<PropertyValueFilter> _propertyValueFilters = new List<PropertyValueFilter>();
|
||||
protected IEnumerable<PropertyValueFilter> PropertyValueFilters { get { return this._propertyValueFilters; } }
|
||||
protected IEnumerable<PropertyValueFilter> PropertyValueFilters { get { return _propertyValueFilters; } }
|
||||
protected void AddPropertyValueFilter(PropertyValueFilter propertyValueFilter)
|
||||
{
|
||||
this._propertyValueFilters.Add(propertyValueFilter);
|
||||
_propertyValueFilters.Add(propertyValueFilter);
|
||||
}
|
||||
|
||||
protected override bool IsMatchCore(CimInstance cimInstance)
|
||||
@@ -183,7 +183,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
foreach (object allowedPropertyValue in allowedPropertyValues)
|
||||
{
|
||||
PropertyValueFilter filter =
|
||||
PropertyValueFilter filter =
|
||||
new PropertyValueRegularFilter(
|
||||
propertyName,
|
||||
allowedPropertyValue,
|
||||
@@ -332,37 +332,37 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
{
|
||||
protected PropertyValueFilter(string propertyName, object expectedPropertyValue, BehaviorOnNoMatch behaviorOnNoMatch)
|
||||
{
|
||||
this.propertyName = propertyName;
|
||||
this._behaviorOnNoMatch = behaviorOnNoMatch;
|
||||
this._originalExpectedPropertyValue = expectedPropertyValue;
|
||||
this._cimTypedExpectedPropertyValue = CimValueConverter.ConvertFromDotNetToCim(expectedPropertyValue);
|
||||
_propertyName = propertyName;
|
||||
_behaviorOnNoMatch = behaviorOnNoMatch;
|
||||
_originalExpectedPropertyValue = expectedPropertyValue;
|
||||
_cimTypedExpectedPropertyValue = CimValueConverter.ConvertFromDotNetToCim(expectedPropertyValue);
|
||||
}
|
||||
|
||||
public BehaviorOnNoMatch BehaviorOnNoMatch
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._behaviorOnNoMatch == BehaviorOnNoMatch.Default)
|
||||
if (_behaviorOnNoMatch == BehaviorOnNoMatch.Default)
|
||||
{
|
||||
this._behaviorOnNoMatch = this.GetDefaultBehaviorWhenNoMatchesFound(this.CimTypedExpectedPropertyValue);
|
||||
_behaviorOnNoMatch = this.GetDefaultBehaviorWhenNoMatchesFound(this.CimTypedExpectedPropertyValue);
|
||||
}
|
||||
return this._behaviorOnNoMatch;
|
||||
return _behaviorOnNoMatch;
|
||||
}
|
||||
}
|
||||
protected abstract BehaviorOnNoMatch GetDefaultBehaviorWhenNoMatchesFound(object cimTypedExpectedPropertyValue);
|
||||
private BehaviorOnNoMatch _behaviorOnNoMatch;
|
||||
|
||||
public string PropertyName { get { return this.propertyName; } }
|
||||
private readonly string propertyName;
|
||||
public string PropertyName { get { return _propertyName; } }
|
||||
private readonly string _propertyName;
|
||||
|
||||
public object CimTypedExpectedPropertyValue { get { return this._cimTypedExpectedPropertyValue; } }
|
||||
public object CimTypedExpectedPropertyValue { get { return _cimTypedExpectedPropertyValue; } }
|
||||
private readonly object _cimTypedExpectedPropertyValue;
|
||||
|
||||
public object OriginalExpectedPropertyValue { get { return this._originalExpectedPropertyValue; } }
|
||||
public object OriginalExpectedPropertyValue { get { return _originalExpectedPropertyValue; } }
|
||||
private readonly object _originalExpectedPropertyValue;
|
||||
|
||||
public bool HadMatch { get { return this.hadMatch; } }
|
||||
private bool hadMatch;
|
||||
public bool HadMatch { get { return _hadMatch; } }
|
||||
private bool _hadMatch;
|
||||
|
||||
public bool IsMatch(CimInstance o)
|
||||
{
|
||||
@@ -371,7 +371,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
return false;
|
||||
}
|
||||
|
||||
CimProperty propertyInfo = o.CimInstanceProperties[propertyName];
|
||||
CimProperty propertyInfo = o.CimInstanceProperties[_propertyName];
|
||||
if (propertyInfo == null)
|
||||
{
|
||||
return false;
|
||||
@@ -380,7 +380,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
if (_cimTypedExpectedPropertyValue == null)
|
||||
{
|
||||
hadMatch = hadMatch || (actualPropertyValue == null);
|
||||
_hadMatch = _hadMatch || (actualPropertyValue == null);
|
||||
return actualPropertyValue == null;
|
||||
}
|
||||
|
||||
@@ -391,7 +391,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
Dbg.Assert(IsSameType(actualPropertyValue, _cimTypedExpectedPropertyValue), "Types of actual vs expected property value should always match");
|
||||
|
||||
bool isMatch = this.IsMatchingValue(actualPropertyValue);
|
||||
hadMatch = hadMatch || isMatch;
|
||||
_hadMatch = _hadMatch || isMatch;
|
||||
return isMatch;
|
||||
}
|
||||
|
||||
@@ -409,7 +409,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
var errorMessage = string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
CmdletizationResources.CimJob_MismatchedTypeOfPropertyReturnedByQuery,
|
||||
propertyName,
|
||||
_propertyName,
|
||||
actualPropertyValue.GetType().FullName,
|
||||
expectedPropertyValue.GetType().FullName);
|
||||
throw CimJobException.CreateWithoutJobContext(
|
||||
@@ -448,12 +448,12 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
public PropertyValueRegularFilter(string propertyName, object expectedPropertyValue, bool wildcardsEnabled, BehaviorOnNoMatch behaviorOnNoMatch)
|
||||
: base(propertyName, expectedPropertyValue, behaviorOnNoMatch)
|
||||
{
|
||||
this._wildcardsEnabled = wildcardsEnabled;
|
||||
_wildcardsEnabled = wildcardsEnabled;
|
||||
}
|
||||
|
||||
protected override BehaviorOnNoMatch GetDefaultBehaviorWhenNoMatchesFound(object cimTypedExpectedPropertyValue)
|
||||
{
|
||||
if (!this._wildcardsEnabled)
|
||||
if (!_wildcardsEnabled)
|
||||
{
|
||||
return BehaviorOnNoMatch.ReportErrors;
|
||||
}
|
||||
@@ -473,7 +473,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal NotFoundError GetGranularNotFoundError()
|
||||
{
|
||||
return new NotFoundError(this.PropertyName, this.OriginalExpectedPropertyValue, this._wildcardsEnabled);
|
||||
return new NotFoundError(this.PropertyName, this.OriginalExpectedPropertyValue, _wildcardsEnabled);
|
||||
}
|
||||
|
||||
protected override bool IsMatchingValue(object actualPropertyValue)
|
||||
@@ -487,7 +487,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
return NonWildcardEqual(this.PropertyName, actualPropertyValue, this.CimTypedExpectedPropertyValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static bool NonWildcardEqual(string propertyName, object actualPropertyValue, object expectedPropertyValue)
|
||||
{
|
||||
// perform .NET-based, case-insensitive equality test for 1) characters and 2) strings
|
||||
@@ -626,7 +626,7 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
lock (_myLock)
|
||||
{
|
||||
_numberOfResultsFromMi++;
|
||||
|
||||
|
||||
if (_filters.All(f => f.IsMatch(result)))
|
||||
{
|
||||
_numberOfMatchingResults++;
|
||||
@@ -641,22 +641,22 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
internal IEnumerable<NotFoundError> GenerateNotFoundErrors()
|
||||
{
|
||||
if (this._filters.Count > 1)
|
||||
if (_filters.Count > 1)
|
||||
{
|
||||
if (this._numberOfMatchingResults > 0)
|
||||
if (_numberOfMatchingResults > 0)
|
||||
{
|
||||
return Enumerable.Empty<NotFoundError>();
|
||||
}
|
||||
|
||||
if (this._filters.All(f => !f.ShouldReportErrorOnNoMatches_IfMultipleFilters()))
|
||||
if (_filters.All(f => !f.ShouldReportErrorOnNoMatches_IfMultipleFilters()))
|
||||
{
|
||||
return Enumerable.Empty<NotFoundError>();
|
||||
}
|
||||
|
||||
return new[] {new NotFoundError()};
|
||||
return new[] { new NotFoundError() };
|
||||
}
|
||||
|
||||
CimInstanceFilterBase filter = this._filters.SingleOrDefault();
|
||||
CimInstanceFilterBase filter = _filters.SingleOrDefault();
|
||||
if (filter != null)
|
||||
{
|
||||
return filter.GetNotFoundErrors_IfThisIsTheOnlyFilter();
|
||||
@@ -671,27 +671,27 @@ namespace Microsoft.PowerShell.Cmdletization.Cim
|
||||
|
||||
public override void FilterByProperty(string propertyName, IEnumerable allowedPropertyValues, bool wildcardsEnabled, BehaviorOnNoMatch behaviorOnNoMatch)
|
||||
{
|
||||
this._filters.Add(new CimInstanceRegularFilter(propertyName, allowedPropertyValues, wildcardsEnabled, behaviorOnNoMatch));
|
||||
_filters.Add(new CimInstanceRegularFilter(propertyName, allowedPropertyValues, wildcardsEnabled, behaviorOnNoMatch));
|
||||
}
|
||||
|
||||
public override void ExcludeByProperty(string propertyName, IEnumerable excludedPropertyValues, bool wildcardsEnabled, BehaviorOnNoMatch behaviorOnNoMatch)
|
||||
{
|
||||
this._filters.Add(new CimInstanceExcludeFilter(propertyName, excludedPropertyValues, wildcardsEnabled, behaviorOnNoMatch));
|
||||
_filters.Add(new CimInstanceExcludeFilter(propertyName, excludedPropertyValues, wildcardsEnabled, behaviorOnNoMatch));
|
||||
}
|
||||
|
||||
public override void FilterByMinPropertyValue(string propertyName, object minPropertyValue, BehaviorOnNoMatch behaviorOnNoMatch)
|
||||
{
|
||||
this._filters.Add(new CimInstanceMinFilter(propertyName, minPropertyValue, behaviorOnNoMatch));
|
||||
_filters.Add(new CimInstanceMinFilter(propertyName, minPropertyValue, behaviorOnNoMatch));
|
||||
}
|
||||
|
||||
public override void FilterByMaxPropertyValue(string propertyName, object maxPropertyValue, BehaviorOnNoMatch behaviorOnNoMatch)
|
||||
{
|
||||
this._filters.Add(new CimInstanceMaxFilter(propertyName, maxPropertyValue, behaviorOnNoMatch));
|
||||
_filters.Add(new CimInstanceMaxFilter(propertyName, maxPropertyValue, behaviorOnNoMatch));
|
||||
}
|
||||
|
||||
public override void FilterByAssociatedInstance(object associatedInstance, string associationName, string sourceRole, string resultRole, BehaviorOnNoMatch behaviorOnNoMatch)
|
||||
{
|
||||
this._filters.Add(new CimInstanceAssociationFilter(behaviorOnNoMatch));
|
||||
_filters.Add(new CimInstanceAssociationFilter(behaviorOnNoMatch));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
+3
-3
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -14,7 +15,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// A command that appends the specified content to the item at the specified path.
|
||||
/// </summary>
|
||||
[Cmdlet (VerbsCommon.Add, "Content", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
[Cmdlet(VerbsCommon.Add, "Content", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113278")]
|
||||
public class AddContentCommand : WriteContentCommandBase
|
||||
{
|
||||
@@ -85,13 +86,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
string action = NavigationResources.AddContentAction;
|
||||
|
||||
string target = StringUtil.Format(NavigationResources.AddContentTarget,path);
|
||||
string target = StringUtil.Format(NavigationResources.AddContentTarget, path);
|
||||
|
||||
return ShouldProcess(target, action);
|
||||
}
|
||||
|
||||
#endregion protected members
|
||||
} // AddContentCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
+4
-4
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -10,7 +11,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// A command that appends the specified content to the item at the specified path.
|
||||
/// </summary>
|
||||
[Cmdlet (VerbsCommon.Clear, "Content", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
[Cmdlet(VerbsCommon.Clear, "Content", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113282")]
|
||||
public class ClearContentCommand : ContentCommandBase
|
||||
{
|
||||
@@ -19,7 +20,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Clears the contents from the item at the specified path.
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
// Default to the CmdletProviderContext that will direct output to
|
||||
// the pipeline.
|
||||
@@ -100,10 +101,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Go ahead an let any exceptions terminate the pipeline.
|
||||
return InvokeProvider.Content.ClearContentDynamicParameters(Path[0], context);
|
||||
}
|
||||
|
||||
|
||||
return InvokeProvider.Content.ClearContentDynamicParameters(".", context);
|
||||
} // GetDynamicParameters
|
||||
} // ClearContentCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
+15
-16
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Management.Automation;
|
||||
@@ -11,7 +12,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// A command to clear the value of a property of an item at a specified path
|
||||
/// </summary>
|
||||
[Cmdlet (VerbsCommon.Clear, "ItemProperty", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
[Cmdlet(VerbsCommon.Clear, "ItemProperty", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113284")]
|
||||
public class ClearItemPropertyCommand : PassThroughItemPropertyCommandBase
|
||||
{
|
||||
@@ -21,7 +22,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Gets or sets the path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(Position = 0, ParameterSetName = "Path",
|
||||
Mandatory = true, ValueFromPipeline=true, ValueFromPipelineByPropertyName = true)]
|
||||
Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||
public string[] Path
|
||||
{
|
||||
get
|
||||
@@ -59,17 +60,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// The properties to clear from the item
|
||||
/// </summary>
|
||||
///
|
||||
[Parameter(Position=1, Mandatory=true, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true)]
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return property;
|
||||
return _property;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
property = value;
|
||||
_property = value;
|
||||
}
|
||||
} // Name
|
||||
|
||||
@@ -91,16 +92,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
internal override object GetDynamicParameters(CmdletProviderContext context)
|
||||
{
|
||||
Collection<string> propertyCollection = new Collection<string>();
|
||||
propertyCollection.Add(property);
|
||||
propertyCollection.Add(_property);
|
||||
|
||||
if (Path != null && Path.Length > 0)
|
||||
{
|
||||
|
||||
// Go ahead and let any exception terminate the pipeline.
|
||||
|
||||
return InvokeProvider.Property.ClearPropertyDynamicParameters(
|
||||
Path[0],
|
||||
propertyCollection,
|
||||
Path[0],
|
||||
propertyCollection,
|
||||
context);
|
||||
}
|
||||
return InvokeProvider.Property.ClearPropertyDynamicParameters(
|
||||
@@ -112,11 +112,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The properties to be cleared.
|
||||
/// </summary>
|
||||
private string property;
|
||||
private string _property;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -125,21 +125,21 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Clears the properties of an item at the specified path
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
CmdletProviderContext currentContext = CmdletProviderContext;
|
||||
currentContext.PassThru = PassThru;
|
||||
|
||||
Collection<string> propertyCollection = new Collection<string>();
|
||||
propertyCollection.Add(property);
|
||||
propertyCollection.Add(_property);
|
||||
|
||||
foreach (string path in Path)
|
||||
{
|
||||
try
|
||||
{
|
||||
InvokeProvider.Property.Clear(
|
||||
path,
|
||||
propertyCollection,
|
||||
path,
|
||||
propertyCollection,
|
||||
currentContext);
|
||||
}
|
||||
catch (PSNotSupportedException notSupported)
|
||||
@@ -176,5 +176,4 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
|
||||
} // ClearItemPropertyCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
+24
-24
@@ -17,20 +17,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Cmdlet(VerbsCommon.Clear, "RecycleBin", SupportsShouldProcess = true, HelpUri = "http://go.microsoft.com/fwlink/?LinkId=524082", ConfirmImpact = ConfirmImpact.High)]
|
||||
public class ClearRecycleBinCommand : PSCmdlet
|
||||
{
|
||||
private string[] drivesList;
|
||||
private DriveInfo[] availableDrives;
|
||||
private bool force;
|
||||
private string[] _drivesList;
|
||||
private DriveInfo[] _availableDrives;
|
||||
private bool _force;
|
||||
|
||||
/// <summary>
|
||||
/// Property that sets DriveLetter parameter.
|
||||
/// </summary>
|
||||
[Parameter(Position = 0, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position = 0, ValueFromPipelineByPropertyName = true)]
|
||||
[ValidateNotNullOrEmpty]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public string[] DriveLetter
|
||||
{
|
||||
get { return drivesList; }
|
||||
set { drivesList = value; }
|
||||
get { return _drivesList; }
|
||||
set { _drivesList = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,11 +41,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return force;
|
||||
return _force;
|
||||
}
|
||||
set
|
||||
{
|
||||
force = value;
|
||||
_force = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void BeginProcessing()
|
||||
{
|
||||
availableDrives = DriveInfo.GetDrives();
|
||||
_availableDrives = DriveInfo.GetDrives();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -64,9 +64,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
// There are two scenarios:
|
||||
// 1) The user provides a list of drives.
|
||||
if (drivesList != null)
|
||||
if (_drivesList != null)
|
||||
{
|
||||
foreach (var drive in drivesList)
|
||||
foreach (var drive in _drivesList)
|
||||
{
|
||||
if (!IsValidPattern(drive))
|
||||
{
|
||||
@@ -82,7 +82,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Get the full path for the drive.
|
||||
string drivePath = GetDrivePath(drive);
|
||||
if (ValidDrivePath(drivePath))
|
||||
{
|
||||
{
|
||||
EmptyRecycleBin(drivePath);
|
||||
}
|
||||
}
|
||||
@@ -102,18 +102,18 @@ namespace Microsoft.PowerShell.Commands
|
||||
private bool ValidDrivePath(string drivePath)
|
||||
{
|
||||
DriveInfo actualDrive = null;
|
||||
if (availableDrives != null)
|
||||
if (_availableDrives != null)
|
||||
{
|
||||
foreach (DriveInfo drive in availableDrives)
|
||||
foreach (DriveInfo drive in _availableDrives)
|
||||
{
|
||||
if (String.Compare(drive.Name, drivePath, StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
actualDrive = drive;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The drive was not found.
|
||||
if (actualDrive == null)
|
||||
{
|
||||
@@ -195,7 +195,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
drivePath);
|
||||
}
|
||||
|
||||
if (force || (ShouldProcess(clearRecycleBinShouldProcessTarget, "Clear-RecycleBin")))
|
||||
if (_force || (ShouldProcess(clearRecycleBinShouldProcessTarget, "Clear-RecycleBin")))
|
||||
{
|
||||
// If driveName is null, then clear the recyclebin for all drives; otherwise, just for the specified drivename.
|
||||
|
||||
@@ -226,7 +226,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
progress.PercentComplete = 100;
|
||||
progress.RecordType = ProgressRecordType.Completed;
|
||||
WriteProgress(progress);
|
||||
|
||||
|
||||
// 0 is for a successful operation
|
||||
// 203 comes up when trying to empty an already emptied recyclebin
|
||||
// 18 comes up when there are no more files in the given recyclebin
|
||||
@@ -239,15 +239,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
|
||||
static class NativeMethod
|
||||
internal static class NativeMethod
|
||||
{
|
||||
// Internal code to SHEmptyRecycleBin
|
||||
internal enum RecycleFlags : uint
|
||||
{
|
||||
SHERB_NOCONFIRMATION = 0x00000001,
|
||||
SHERB_NOPROGRESSUI = 0x00000002,
|
||||
SHERB_NOSOUND = 0x00000004
|
||||
}
|
||||
SHERB_NOPROGRESSUI = 0x00000002,
|
||||
SHERB_NOSOUND = 0x00000004
|
||||
}
|
||||
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
|
||||
internal static extern uint SHEmptyRecycleBin(IntPtr hwnd, string pszRootPath, RecycleFlags dwFlags);
|
||||
}
|
||||
|
||||
+16
-18
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -18,22 +19,22 @@ namespace Microsoft.PowerShell.Commands
|
||||
public class JoinPathCommand : CoreCommandWithCredentialsBase
|
||||
{
|
||||
#region Parameters
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter (Position=0,Mandatory=true, ValueFromPipeline=true, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("PSPath")]
|
||||
public string[] Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
paths = value;
|
||||
_paths = value;
|
||||
} // set
|
||||
} // Path
|
||||
|
||||
@@ -47,12 +48,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return childPath;
|
||||
return _childPath;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
childPath = value;
|
||||
_childPath = value;
|
||||
} // set
|
||||
} // childPath
|
||||
|
||||
@@ -65,33 +66,33 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return resolve;
|
||||
return _resolve;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
resolve = value;
|
||||
_resolve = value;
|
||||
} //set
|
||||
} // Resolve
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The path to resolve
|
||||
/// </summary>
|
||||
private string[] paths;
|
||||
private string[] _paths;
|
||||
|
||||
/// <summary>
|
||||
/// The child part of the path to be joined with the Path paramter
|
||||
/// </summary>
|
||||
private string childPath = String.Empty;
|
||||
private string _childPath = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the path should be resolved after being joined.
|
||||
/// </summary>
|
||||
private bool resolve;
|
||||
private bool _resolve;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -101,10 +102,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Parses the specified path and returns the portion determined by the
|
||||
/// boolean parameters.
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
Dbg.Diagnostics.Assert(
|
||||
paths != null,
|
||||
_paths != null,
|
||||
"Since Path is a mandatory parameter, paths should never be null");
|
||||
|
||||
foreach (string path in Path)
|
||||
@@ -115,7 +116,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
try
|
||||
{
|
||||
joinedPath =
|
||||
joinedPath =
|
||||
SessionState.Path.Combine(path, ChildPath, CmdletProviderContext);
|
||||
}
|
||||
catch (PSNotSupportedException notSupported)
|
||||
@@ -235,9 +236,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
pathNotFound));
|
||||
continue;
|
||||
}
|
||||
|
||||
} // for each path
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -252,6 +251,5 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
|
||||
} // JoinPathCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
internal static class CommandsCommon
|
||||
{
|
||||
#if CORECLR
|
||||
#if CORECLR
|
||||
// AccessViolationException/StackOverflowException Not In CoreCLR.
|
||||
// The CoreCLR team told us to not check for these exceptions because they
|
||||
// usually won't be caught.
|
||||
|
||||
+3
-4
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Provider;
|
||||
@@ -17,18 +18,16 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Commits the current transaction
|
||||
/// </summary>
|
||||
protected override void EndProcessing ()
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
// Commit the transaction
|
||||
if(ShouldProcess(
|
||||
if (ShouldProcess(
|
||||
NavigationResources.TransactionResource,
|
||||
NavigationResources.CommitAction))
|
||||
{
|
||||
this.Context.TransactionManager.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
} // CommitTransactionCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+54
-58
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -17,22 +18,22 @@ namespace Microsoft.PowerShell.Commands
|
||||
public class ContentCommandBase : CoreCommandWithCredentialsBase, IDisposable
|
||||
{
|
||||
#region Parameters
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(Position=0, ParameterSetName = "Path",
|
||||
Mandatory = true, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position = 0, ParameterSetName = "Path",
|
||||
Mandatory = true, ValueFromPipelineByPropertyName = true)]
|
||||
public string[] Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
paths = value;
|
||||
_paths = value;
|
||||
} // set
|
||||
} // Path
|
||||
|
||||
@@ -40,19 +41,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Gets or sets the literal path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(ParameterSetName = "LiteralPath",
|
||||
Mandatory = true, ValueFromPipeline=false, ValueFromPipelineByPropertyName = true)]
|
||||
Mandatory = true, ValueFromPipeline = false, ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("PSPath")]
|
||||
public string[] LiteralPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
base.SuppressWildcardExpansion = true;
|
||||
paths = value;
|
||||
_paths = value;
|
||||
} // set
|
||||
} // LiteralPath
|
||||
|
||||
@@ -72,7 +73,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
base.Filter = value;
|
||||
} // set
|
||||
} // Filter
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the include property
|
||||
/// </summary>
|
||||
@@ -138,11 +139,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The path to the item to ping
|
||||
/// </summary>
|
||||
private string[] paths;
|
||||
private string[] _paths;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -198,30 +199,30 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Use the cached notes if the cache exists and the path is still the same
|
||||
PSNoteProperty note;
|
||||
|
||||
if (currentContentItem != null &&
|
||||
((currentContentItem.PathInfo == pathInfo) ||
|
||||
(
|
||||
if (_currentContentItem != null &&
|
||||
((_currentContentItem.PathInfo == pathInfo) ||
|
||||
(
|
||||
String.Compare(
|
||||
pathInfo.Path,
|
||||
currentContentItem.PathInfo.Path,
|
||||
_currentContentItem.PathInfo.Path,
|
||||
StringComparison.OrdinalIgnoreCase) == 0)
|
||||
)
|
||||
)
|
||||
{
|
||||
result = currentContentItem.AttachNotes(result);
|
||||
result = _currentContentItem.AttachNotes(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Generate a new cache item and cache the notes
|
||||
|
||||
currentContentItem = new ContentPathsCache(pathInfo);
|
||||
_currentContentItem = new ContentPathsCache(pathInfo);
|
||||
|
||||
// Construct a provider qualified path as the Path note
|
||||
string psPath = pathInfo.Path;
|
||||
note = new PSNoteProperty("PSPath", psPath);
|
||||
result.Properties.Add(note, true);
|
||||
tracer.WriteLine("Attaching {0} = {1}", "PSPath", psPath);
|
||||
currentContentItem.PSPath = psPath;
|
||||
_currentContentItem.PSPath = psPath;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -240,7 +241,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
note = new PSNoteProperty("PSParentPath", parentPath);
|
||||
result.Properties.Add(note, true);
|
||||
tracer.WriteLine("Attaching {0} = {1}", "PSParentPath", parentPath);
|
||||
currentContentItem.ParentPath = parentPath;
|
||||
_currentContentItem.ParentPath = parentPath;
|
||||
|
||||
// Get the child name
|
||||
|
||||
@@ -248,7 +249,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
note = new PSNoteProperty("PSChildName", childName);
|
||||
result.Properties.Add(note, true);
|
||||
tracer.WriteLine("Attaching {0} = {1}", "PSChildName", childName);
|
||||
currentContentItem.ChildName = childName;
|
||||
_currentContentItem.ChildName = childName;
|
||||
}
|
||||
catch (NotSupportedException)
|
||||
{
|
||||
@@ -263,7 +264,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
note = new PSNoteProperty("PSDrive", drive);
|
||||
result.Properties.Add(note, true);
|
||||
tracer.WriteLine("Attaching {0} = {1}", "PSDrive", drive);
|
||||
currentContentItem.Drive = drive;
|
||||
_currentContentItem.Drive = drive;
|
||||
}
|
||||
|
||||
// ProviderInfo
|
||||
@@ -272,7 +273,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
note = new PSNoteProperty("PSProvider", provider);
|
||||
result.Properties.Add(note, true);
|
||||
tracer.WriteLine("Attaching {0} = {1}", "PSProvider", provider);
|
||||
currentContentItem.Provider = provider;
|
||||
_currentContentItem.Provider = provider;
|
||||
}
|
||||
|
||||
// Add the ReadCount note
|
||||
@@ -280,14 +281,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
result.Properties.Add(note, true);
|
||||
|
||||
WriteObject(result);
|
||||
|
||||
} // WriteContentObject
|
||||
|
||||
/// <summary>
|
||||
/// A cache of the notes that get added to the content items as they are written
|
||||
/// to the pipeline.
|
||||
/// </summary>
|
||||
private ContentPathsCache currentContentItem;
|
||||
private ContentPathsCache _currentContentItem;
|
||||
|
||||
/// <summary>
|
||||
/// A class that stores a cache of the notes that get attached to content items
|
||||
@@ -306,7 +306,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
///
|
||||
public ContentPathsCache(PathInfo pathInfo)
|
||||
{
|
||||
this.pathInfo = pathInfo;
|
||||
_pathInfo = pathInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -317,10 +317,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return pathInfo;
|
||||
return _pathInfo;
|
||||
}
|
||||
} // PathInfo
|
||||
private PathInfo pathInfo;
|
||||
private PathInfo _pathInfo;
|
||||
|
||||
/// <summary>
|
||||
/// The cached PSPath of the item.
|
||||
@@ -330,15 +330,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return psPath;
|
||||
return _psPath;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
psPath = value;
|
||||
_psPath = value;
|
||||
}
|
||||
} // PSPath
|
||||
private string psPath;
|
||||
private string _psPath;
|
||||
|
||||
/// <summary>
|
||||
/// The cached parent path of the item.
|
||||
@@ -348,15 +348,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return parentPath;
|
||||
return _parentPath;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
parentPath = value;
|
||||
_parentPath = value;
|
||||
}
|
||||
} // ParentPath
|
||||
private string parentPath;
|
||||
private string _parentPath;
|
||||
|
||||
/// <summary>
|
||||
/// The cached drive for the item.
|
||||
@@ -366,15 +366,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return drive;
|
||||
return _drive;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
drive = value;
|
||||
_drive = value;
|
||||
}
|
||||
} // Drive
|
||||
private PSDriveInfo drive;
|
||||
private PSDriveInfo _drive;
|
||||
|
||||
/// <summary>
|
||||
/// The cached provider of the item.
|
||||
@@ -384,15 +384,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return provider;
|
||||
return _provider;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
provider = value;
|
||||
_provider = value;
|
||||
}
|
||||
} // Provider
|
||||
private ProviderInfo provider;
|
||||
private ProviderInfo _provider;
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -403,15 +403,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return childName;
|
||||
return _childName;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
childName = value;
|
||||
_childName = value;
|
||||
}
|
||||
} // ChildName
|
||||
private string childName;
|
||||
private string _childName;
|
||||
|
||||
/// <summary>
|
||||
/// Attaches the cached notes to the specified PSObject.
|
||||
@@ -447,7 +447,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// PSDriveInfo
|
||||
|
||||
if (pathInfo.Drive != null)
|
||||
if (_pathInfo.Drive != null)
|
||||
{
|
||||
note = new PSNoteProperty("PSDrive", Drive);
|
||||
content.Properties.Add(note, true);
|
||||
@@ -473,8 +473,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
internal struct ContentHolder
|
||||
{
|
||||
internal ContentHolder(
|
||||
PathInfo pathInfo,
|
||||
IContentReader reader,
|
||||
PathInfo pathInfo,
|
||||
IContentReader reader,
|
||||
IContentWriter writer)
|
||||
{
|
||||
if (pathInfo == null)
|
||||
@@ -482,9 +482,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
throw PSTraceSource.NewArgumentNullException("pathInfo");
|
||||
}
|
||||
|
||||
this._pathInfo = pathInfo;
|
||||
this._reader = reader;
|
||||
this._writer = writer;
|
||||
_pathInfo = pathInfo;
|
||||
_reader = reader;
|
||||
_writer = writer;
|
||||
} // constructor
|
||||
|
||||
internal PathInfo PathInfo
|
||||
@@ -524,7 +524,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
holder.Writer.Close();
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) // Catch-all OK. 3rd party callout
|
||||
{
|
||||
@@ -596,7 +595,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
providerException));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // CloseContent
|
||||
|
||||
@@ -694,7 +692,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (readers.Count == 1 && readers[0] != null)
|
||||
{
|
||||
ContentHolder holder =
|
||||
ContentHolder holder =
|
||||
new ContentHolder(pathInfo, readers[0], null);
|
||||
|
||||
results.Add(holder);
|
||||
@@ -731,7 +729,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </returns>
|
||||
///
|
||||
internal Collection<PathInfo> ResolvePaths(
|
||||
string[] pathsToResolve,
|
||||
string[] pathsToResolve,
|
||||
bool allowNonexistingPaths,
|
||||
bool allowEmptyResult,
|
||||
CmdletProviderContext currentCommandContext)
|
||||
@@ -747,11 +745,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
// First resolve each of the paths
|
||||
Collection<PathInfo> pathInfos =
|
||||
Collection<PathInfo> pathInfos =
|
||||
SessionState.Path.GetResolvedPSPathFromPSPath(
|
||||
path,
|
||||
path,
|
||||
currentCommandContext);
|
||||
|
||||
if (pathInfos.Count == 0)
|
||||
@@ -803,9 +800,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (pathNotFound)
|
||||
{
|
||||
if (allowNonexistingPaths &&
|
||||
(! filtersHidPath) &&
|
||||
(!filtersHidPath) &&
|
||||
(currentCommandContext.SuppressWildcardExpansion ||
|
||||
(! WildcardPattern.ContainsWildcardCharacters(path))))
|
||||
(!WildcardPattern.ContainsWildcardCharacters(path))))
|
||||
{
|
||||
ProviderInfo provider = null;
|
||||
PSDriveInfo drive = null;
|
||||
@@ -879,5 +876,4 @@ namespace Microsoft.PowerShell.Commands
|
||||
#endregion IDisposable
|
||||
|
||||
} // ContentCommandBase
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
+16
-15
@@ -1,7 +1,8 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using Microsoft.Win32;
|
||||
@@ -100,7 +101,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Locale specific verb action Open string exposed by the control panel item.
|
||||
/// </summary>
|
||||
private static string VerbActionOpenName = null;
|
||||
private static string s_verbActionOpenName = null;
|
||||
|
||||
/// <summary>
|
||||
/// Canonical name of the control panel item used as a refernece to fetch the verb
|
||||
@@ -109,7 +110,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
private const string RegionCanonicalName = "Microsoft.RegionAndLanguage";
|
||||
|
||||
private const string ControlPanelShellFolder = "shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}";
|
||||
private static readonly string[] ControlPanelItemFilterList = new string[] { "Folder Options", "Taskbar and Start Menu" };
|
||||
private static readonly string[] s_controlPanelItemFilterList = new string[] { "Folder Options", "Taskbar and Start Menu" };
|
||||
private const string TestHeadlessServerScript = @"
|
||||
$result = $false
|
||||
$serverManagerModule = Get-Module -ListAvailable | ? {$_.Name -eq 'ServerManager'}
|
||||
@@ -153,7 +154,7 @@ $result
|
||||
if (applyControlPanelItemFilterList)
|
||||
{
|
||||
bool match = false;
|
||||
foreach (string name in ControlPanelItemFilterList)
|
||||
foreach (string name in s_controlPanelItemFilterList)
|
||||
{
|
||||
if (name.Equals(item.Name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
@@ -212,8 +213,8 @@ $result
|
||||
FolderItemVerbs verbs = item.Verbs();
|
||||
foreach (FolderItemVerb verb in verbs)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(verb.Name) &&
|
||||
(verb.Name.Equals(ControlPanelResources.VerbActionOpen, StringComparison.OrdinalIgnoreCase) ||
|
||||
if (!String.IsNullOrEmpty(verb.Name) &&
|
||||
(verb.Name.Equals(ControlPanelResources.VerbActionOpen, StringComparison.OrdinalIgnoreCase) ||
|
||||
CompareVerbActionOpen(verb.Name)))
|
||||
{
|
||||
result = true;
|
||||
@@ -230,8 +231,8 @@ $result
|
||||
/// <param name="verbActionName">Locale spcific verb action exposed by the control panel item.</param>
|
||||
/// <returns>True if the control panel item supports verb action open or else returns false.</returns>
|
||||
private static bool CompareVerbActionOpen(string verbActionName)
|
||||
{
|
||||
if (VerbActionOpenName == null)
|
||||
{
|
||||
if (s_verbActionOpenName == null)
|
||||
{
|
||||
const string allItemFolderPath = ControlPanelShellFolder + "\\0";
|
||||
IShellDispatch4 shell2 = (IShellDispatch4)new Shell();
|
||||
@@ -248,16 +249,16 @@ $result
|
||||
if (canonicalName != null && canonicalName.Equals(RegionCanonicalName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// The 'Region' control panel item always has '&Open' (english or other locale) as the first verb name
|
||||
VerbActionOpenName = item.Verbs().Item(0).Name;
|
||||
s_verbActionOpenName = item.Verbs().Item(0).Name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Dbg.Assert(VerbActionOpenName != null, "The 'Region' control panel item is available on all SKUs and it always "
|
||||
Dbg.Assert(s_verbActionOpenName != null, "The 'Region' control panel item is available on all SKUs and it always "
|
||||
+ "has '&Open' as the first verb item, so VerbActionOpenName should never be null at this point");
|
||||
}
|
||||
|
||||
return VerbActionOpenName.Equals(verbActionName, StringComparison.OrdinalIgnoreCase);
|
||||
return s_verbActionOpenName.Equals(verbActionName, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -316,7 +317,7 @@ $result
|
||||
{
|
||||
string path = category.Path;
|
||||
string catNum = path.Substring(path.LastIndexOf("\\", StringComparison.OrdinalIgnoreCase) + 1);
|
||||
|
||||
|
||||
CategoryMap.Add(catNum, category.Name);
|
||||
}
|
||||
}
|
||||
@@ -341,10 +342,10 @@ $result
|
||||
int[] categories = (int[])item.ExtendedProperty("System.ControlPanel.Category");
|
||||
foreach (int cat in categories)
|
||||
{
|
||||
string catStr = (string)LanguagePrimitives.ConvertTo(cat, typeof (string), CultureInfo.InvariantCulture);
|
||||
string catStr = (string)LanguagePrimitives.ConvertTo(cat, typeof(string), CultureInfo.InvariantCulture);
|
||||
Dbg.Assert(CategoryMap.ContainsKey(catStr), "the category should be contained in _categoryMap");
|
||||
string catName = CategoryMap[catStr];
|
||||
|
||||
|
||||
if (!wildcard.IsMatch(catName))
|
||||
continue;
|
||||
if (itemSet.Contains(path))
|
||||
@@ -690,7 +691,7 @@ $result
|
||||
|
||||
#endregion "Private Methods"
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Show the specified control panel applet
|
||||
/// </summary>
|
||||
|
||||
+11
-12
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Management.Automation;
|
||||
@@ -12,13 +13,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// A command to convert a drive qualifed or provider qualified path to
|
||||
/// a provider internal path.
|
||||
/// </summary>
|
||||
[Cmdlet (VerbsData.Convert, "Path", DefaultParameterSetName = "Path", SupportsTransactions = true,
|
||||
[Cmdlet(VerbsData.Convert, "Path", DefaultParameterSetName = "Path", SupportsTransactions = true,
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113289", RemotingCapability = RemotingCapability.None)]
|
||||
[OutputType(typeof(string))]
|
||||
public class ConvertPathCommand : CoreCommandBase
|
||||
{
|
||||
#region Parameters
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path parameter to the command
|
||||
/// </summary>
|
||||
@@ -28,12 +29,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
paths = value;
|
||||
_paths = value;
|
||||
} // set
|
||||
} // Path
|
||||
|
||||
@@ -41,30 +42,30 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Gets or sets the literal path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(ParameterSetName = "LiteralPath",
|
||||
Mandatory = true, ValueFromPipeline=false, ValueFromPipelineByPropertyName = true)]
|
||||
Mandatory = true, ValueFromPipeline = false, ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("PSPath")]
|
||||
public string[] LiteralPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
base.SuppressWildcardExpansion = true;
|
||||
paths = value;
|
||||
_paths = value;
|
||||
} // set
|
||||
} // LiteralPath
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The path(s) to the item(s) to convert
|
||||
/// </summary>
|
||||
private string[] paths;
|
||||
private string[] _paths;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -74,7 +75,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Converts a drive qualified or provider qualified path to a provider
|
||||
/// internal path.
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
ProviderInfo provider = null;
|
||||
|
||||
@@ -122,13 +123,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
pathNotFound));
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
} // ProcessRecord
|
||||
#endregion Command code
|
||||
|
||||
|
||||
} // ConvertPathCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
+24
-24
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -10,7 +11,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// A command to copy a property on an item.
|
||||
/// </summary>
|
||||
[Cmdlet (VerbsCommon.Copy, "ItemProperty", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
[Cmdlet(VerbsCommon.Copy, "ItemProperty", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113293")]
|
||||
public class CopyItemPropertyCommand : PassThroughItemPropertyCommandBase
|
||||
{
|
||||
@@ -20,7 +21,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Gets or sets the path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(Position = 0, ParameterSetName = "Path",
|
||||
Mandatory = true, ValueFromPipeline=true, ValueFromPipelineByPropertyName = true)]
|
||||
Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||
public string[] Path
|
||||
{
|
||||
get
|
||||
@@ -64,12 +65,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return property;
|
||||
return _property;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
property = value;
|
||||
_property = value;
|
||||
}
|
||||
} // Property
|
||||
|
||||
@@ -77,20 +78,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// The path to the destination item to copy the property to.
|
||||
/// </summary>
|
||||
///
|
||||
[Parameter(Mandatory=true, Position = 1, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true)]
|
||||
public string Destination
|
||||
{
|
||||
get
|
||||
{
|
||||
return destination;
|
||||
return _destination;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
destination = value;
|
||||
_destination = value;
|
||||
}
|
||||
} // Destination
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A virtual method for retrieving the dynamic parameters for a cmdlet. Derived cmdlets
|
||||
/// that require dynamic parameters should override this method and return the
|
||||
@@ -111,33 +112,33 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (Path != null & Path.Length > 0)
|
||||
{
|
||||
return InvokeProvider.Property.CopyPropertyDynamicParameters(
|
||||
Path[0],
|
||||
property,
|
||||
Destination,
|
||||
property,
|
||||
Path[0],
|
||||
_property,
|
||||
Destination,
|
||||
_property,
|
||||
context);
|
||||
}
|
||||
return InvokeProvider.Property.CopyPropertyDynamicParameters(
|
||||
".",
|
||||
property,
|
||||
_property,
|
||||
Destination,
|
||||
property,
|
||||
_property,
|
||||
context);
|
||||
} // GetDynamicParameters
|
||||
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The property to be copied.
|
||||
/// </summary>
|
||||
private string property;
|
||||
private string _property;
|
||||
|
||||
/// <summary>
|
||||
/// The destination path of the item to copy the property to.
|
||||
/// </summary>
|
||||
private string destination;
|
||||
private string _destination;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -146,17 +147,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Copies the property from one item to another
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
foreach (string path in Path)
|
||||
{
|
||||
try
|
||||
{
|
||||
InvokeProvider.Property.Copy(
|
||||
path,
|
||||
property,
|
||||
Destination,
|
||||
property,
|
||||
path,
|
||||
_property,
|
||||
Destination,
|
||||
_property,
|
||||
GetCurrentContext());
|
||||
}
|
||||
catch (PSNotSupportedException notSupported)
|
||||
@@ -197,5 +198,4 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
|
||||
} // CopyItemPropertyCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -87,8 +88,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_after = value;
|
||||
isDateSpecified = true;
|
||||
isFilterSpecified = true;
|
||||
_isDateSpecified = true;
|
||||
_isFilterSpecified = true;
|
||||
}
|
||||
}
|
||||
private DateTime _after;
|
||||
@@ -104,8 +105,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_before = value;
|
||||
isDateSpecified = true;
|
||||
isFilterSpecified = true;
|
||||
_isDateSpecified = true;
|
||||
_isFilterSpecified = true;
|
||||
}
|
||||
}
|
||||
private DateTime _before;
|
||||
@@ -122,7 +123,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_username = value;
|
||||
isFilterSpecified = true;
|
||||
_isFilterSpecified = true;
|
||||
}
|
||||
}
|
||||
private String[] _username;
|
||||
@@ -134,15 +135,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(Position = 1, ParameterSetName = "LogName")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[ValidateRangeAttribute((long)0, long.MaxValue)]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public long[] InstanceId
|
||||
{
|
||||
get { return _instanceIds; }
|
||||
set
|
||||
{
|
||||
_instanceIds = value;
|
||||
isFilterSpecified = true;
|
||||
|
||||
_isFilterSpecified = true;
|
||||
}
|
||||
}
|
||||
private long[] _instanceIds = null;
|
||||
@@ -155,14 +155,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(ParameterSetName = "LogName")]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[ValidateRangeAttribute((int)1, int.MaxValue)]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public int[] Index
|
||||
{
|
||||
get { return _indexes; }
|
||||
set
|
||||
{
|
||||
_indexes = value;
|
||||
isFilterSpecified = true;
|
||||
_isFilterSpecified = true;
|
||||
}
|
||||
}
|
||||
private int[] _indexes = null;
|
||||
@@ -183,7 +183,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_entryTypes = value;
|
||||
isFilterSpecified = true;
|
||||
_isFilterSpecified = true;
|
||||
}
|
||||
}
|
||||
private string[] _entryTypes = null;
|
||||
@@ -202,7 +202,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_sources = value;
|
||||
isFilterSpecified = true;
|
||||
_isFilterSpecified = true;
|
||||
}
|
||||
}
|
||||
private string[] _sources;
|
||||
@@ -222,7 +222,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_message = value;
|
||||
isFilterSpecified = true;
|
||||
_isFilterSpecified = true;
|
||||
}
|
||||
}
|
||||
private string _message;
|
||||
@@ -285,9 +285,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Sets true when Filter is Specified
|
||||
/// </summary>
|
||||
private bool isFilterSpecified = false;
|
||||
private bool isDateSpecified = false;
|
||||
private bool isThrowError = true;
|
||||
private bool _isFilterSpecified = false;
|
||||
private bool _isDateSpecified = false;
|
||||
private bool _isThrowError = true;
|
||||
|
||||
/// <summary>
|
||||
/// Process the specified logs
|
||||
@@ -413,7 +413,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
try
|
||||
{
|
||||
entry = entries[i];
|
||||
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
@@ -450,7 +449,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|| lastindex - entry.Index == 1)))
|
||||
{
|
||||
lastindex = entry.Index;
|
||||
if (isFilterSpecified)
|
||||
if (_isFilterSpecified)
|
||||
{
|
||||
if (!FiltersMatch(entry))
|
||||
continue;
|
||||
@@ -473,7 +472,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
processed++;
|
||||
}
|
||||
}
|
||||
if (!matchesfound && isThrowError)
|
||||
if (!matchesfound && _isThrowError)
|
||||
{
|
||||
Exception Ex = new ArgumentException(StringUtil.Format(EventlogResources.NoEntriesFound, log.Log, ""));
|
||||
WriteError(new ErrorRecord(Ex, "GetEventLogNoEntriesFound", ErrorCategory.ObjectNotFound, null));
|
||||
@@ -518,7 +517,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (WildcardPattern.ContainsWildcardCharacters(source))
|
||||
{
|
||||
isThrowError = false;
|
||||
_isThrowError = false;
|
||||
}
|
||||
WildcardPattern wildcardpattern = WildcardPattern.Get(source, WildcardOptions.IgnoreCase);
|
||||
if (wildcardpattern.IsMatch(entry.Source))
|
||||
@@ -533,7 +532,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (WildcardPattern.ContainsWildcardCharacters(_message))
|
||||
{
|
||||
isThrowError = false;
|
||||
_isThrowError = false;
|
||||
}
|
||||
WildcardPattern wildcardpattern = WildcardPattern.Get(_message, WildcardOptions.IgnoreCase);
|
||||
if (!wildcardpattern.IsMatch(entry.Message))
|
||||
@@ -546,7 +545,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
bool usernamematch = false;
|
||||
foreach (string user in _username)
|
||||
{
|
||||
isThrowError = false;
|
||||
_isThrowError = false;
|
||||
if (entry.UserName != null)
|
||||
{
|
||||
WildcardPattern wildcardpattern = WildcardPattern.Get(user, WildcardOptions.IgnoreCase);
|
||||
@@ -559,25 +558,25 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
if (!usernamematch) return usernamematch;
|
||||
}
|
||||
if (isDateSpecified)
|
||||
if (_isDateSpecified)
|
||||
{
|
||||
isThrowError = false;
|
||||
_isThrowError = false;
|
||||
bool datematch = false;
|
||||
if (!_after.Equals(Initial) && _before.Equals(Initial))
|
||||
if (!_after.Equals(_initial) && _before.Equals(_initial))
|
||||
{
|
||||
if (entry.TimeGenerated > _after)
|
||||
{
|
||||
datematch = true;
|
||||
}
|
||||
}
|
||||
else if (!_before.Equals(Initial) && _after.Equals(Initial))
|
||||
else if (!_before.Equals(_initial) && _after.Equals(_initial))
|
||||
{
|
||||
if (entry.TimeGenerated < _before)
|
||||
{
|
||||
datematch = true;
|
||||
}
|
||||
}
|
||||
else if (!_after.Equals(Initial) && !_before.Equals(Initial))
|
||||
else if (!_after.Equals(_initial) && !_before.Equals(_initial))
|
||||
{
|
||||
if (_after > _before || _after == _before)
|
||||
{
|
||||
@@ -627,7 +626,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
return matchingLogs;
|
||||
}
|
||||
//private string ErrorBase = "EventlogResources";
|
||||
private DateTime Initial = new DateTime();
|
||||
private DateTime _initial = new DateTime();
|
||||
|
||||
#endregion Private
|
||||
}//GetEventLogCommand
|
||||
@@ -733,12 +732,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
WriteError(er);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//beginprocessing
|
||||
|
||||
#endregion Overrides
|
||||
@@ -878,13 +875,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
public string ComputerName
|
||||
{
|
||||
get { return compname; }
|
||||
get { return _compname; }
|
||||
set
|
||||
{
|
||||
compname = value;
|
||||
_compname = value;
|
||||
}
|
||||
}
|
||||
private string compname = ".";
|
||||
private string _compname = ".";
|
||||
|
||||
#endregion Parameters
|
||||
# region private
|
||||
@@ -904,35 +901,32 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void BeginProcessing()
|
||||
{
|
||||
|
||||
string _computerName = string.Empty;
|
||||
if ((compname.Equals("localhost", StringComparison.CurrentCultureIgnoreCase)) || (compname.Equals(".", StringComparison.OrdinalIgnoreCase)))
|
||||
if ((_compname.Equals("localhost", StringComparison.CurrentCultureIgnoreCase)) || (_compname.Equals(".", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
_computerName = "localhost";
|
||||
}
|
||||
else
|
||||
{
|
||||
_computerName = compname;
|
||||
_computerName = _compname;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!(EventLog.SourceExists(_source, compname)))
|
||||
if (!(EventLog.SourceExists(_source, _compname)))
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(StringUtil.Format(EventlogResources.SourceDoesNotExist, null, _computerName, _source)), null, ErrorCategory.InvalidOperation, null);
|
||||
WriteError(er);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(EventLog.Exists(_logName, compname)))
|
||||
if (!(EventLog.Exists(_logName, _compname)))
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(StringUtil.Format(EventlogResources.LogDoesNotExist, _logName, _computerName)), null, ErrorCategory.InvalidOperation, null);
|
||||
WriteError(er);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
EventLog _myevent = new EventLog(_logName, compname, _source);
|
||||
EventLog _myevent = new EventLog(_logName, _compname, _source);
|
||||
_myevent.WriteEntry(_message, _entryType, _eventId, _category, _rawData);
|
||||
}
|
||||
}
|
||||
@@ -944,16 +938,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
WriteNonTerminatingError(ex, "AccessDenied", StringUtil.Format(EventlogResources.AccessDenied, _logName, null, _source), ErrorCategory.PermissionDenied);
|
||||
|
||||
}
|
||||
catch (Win32Exception ex)
|
||||
{
|
||||
WriteNonTerminatingError(ex, "OSWritingError", StringUtil.Format(EventlogResources.OSWritingError, null, null, null), ErrorCategory.WriteError);
|
||||
|
||||
}
|
||||
catch (System.IO.IOException ex)
|
||||
{
|
||||
WriteNonTerminatingError(ex, "PathDoesNotExist", StringUtil.Format(EventlogResources.PathDoesNotExist, null, compname, null), ErrorCategory.InvalidOperation);
|
||||
WriteNonTerminatingError(ex, "PathDoesNotExist", StringUtil.Format(EventlogResources.PathDoesNotExist, null, _compname, null), ErrorCategory.InvalidOperation);
|
||||
}
|
||||
}//beginprocessing
|
||||
|
||||
@@ -1016,11 +1008,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_retention = value;
|
||||
retentionSpecified = true;
|
||||
_retentionSpecified = true;
|
||||
}
|
||||
}
|
||||
private Int32 _retention;
|
||||
bool retentionSpecified = false;
|
||||
private bool _retentionSpecified = false;
|
||||
/// <summary>
|
||||
/// Overflow action to be taken.
|
||||
/// </summary>
|
||||
@@ -1035,11 +1027,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_overflowaction = value;
|
||||
overflowSpecified = true;
|
||||
_overflowSpecified = true;
|
||||
}
|
||||
}
|
||||
private System.Diagnostics.OverflowAction _overflowaction;
|
||||
bool overflowSpecified = false;
|
||||
private bool _overflowSpecified = false;
|
||||
/// <summary>
|
||||
/// Maximum size of this log.
|
||||
/// </summary>
|
||||
@@ -1051,11 +1043,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_maximumKilobytes = value;
|
||||
maxkbSpecified = true;
|
||||
_maxkbSpecified = true;
|
||||
}
|
||||
}
|
||||
private Int64 _maximumKilobytes;
|
||||
bool maxkbSpecified = false;
|
||||
private bool _maxkbSpecified = false;
|
||||
#endregion Parameters
|
||||
|
||||
# region private
|
||||
@@ -1109,7 +1101,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
EventLog newLog = new EventLog(logname, compname);
|
||||
int _minRetention = newLog.MinimumRetentionDays;
|
||||
System.Diagnostics.OverflowAction _newFlowAction = newLog.OverflowAction;
|
||||
if (retentionSpecified && overflowSpecified)
|
||||
if (_retentionSpecified && _overflowSpecified)
|
||||
{
|
||||
if (_overflowaction.CompareTo(System.Diagnostics.OverflowAction.OverwriteOlder) == 0)
|
||||
{
|
||||
@@ -1122,7 +1114,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (retentionSpecified && !overflowSpecified)
|
||||
else if (_retentionSpecified && !_overflowSpecified)
|
||||
{
|
||||
if (_newFlowAction.CompareTo(System.Diagnostics.OverflowAction.OverwriteOlder) == 0)
|
||||
{
|
||||
@@ -1135,11 +1127,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (!retentionSpecified && overflowSpecified)
|
||||
else if (!_retentionSpecified && _overflowSpecified)
|
||||
{
|
||||
newLog.ModifyOverflowPolicy(_overflowaction, _minRetention);
|
||||
}
|
||||
if (maxkbSpecified)
|
||||
if (_maxkbSpecified)
|
||||
{
|
||||
int kiloByte = 1024;
|
||||
_maximumKilobytes = _maximumKilobytes / kiloByte;
|
||||
@@ -1160,7 +1152,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
catch (ArgumentOutOfRangeException ex)
|
||||
{
|
||||
if (!retentionSpecified && !maxkbSpecified)
|
||||
if (!_retentionSpecified && !_maxkbSpecified)
|
||||
{
|
||||
WriteNonTerminatingError(ex, EventlogResources.InvalidArgument, "InvalidArgument", ErrorCategory.InvalidData, null, null);
|
||||
}
|
||||
@@ -1239,7 +1231,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
catch (SystemException ex)
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(ex, "InvalidComputerName", ErrorCategory.InvalidArgument, this._computerName);
|
||||
ErrorRecord er = new ErrorRecord(ex, "InvalidComputerName", ErrorCategory.InvalidArgument, _computerName);
|
||||
WriteError(er);
|
||||
}
|
||||
}
|
||||
@@ -1271,7 +1263,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Cmdlet(VerbsCommon.New, "EventLog", HelpUri = "http://go.microsoft.com/fwlink/?LinkID=135235", RemotingCapability = RemotingCapability.SupportedByCommand)]
|
||||
public class NewEventLogCommand : PSCmdlet
|
||||
{
|
||||
|
||||
# region Parameter
|
||||
/// <summary>
|
||||
/// The following is the definition of the input parameter "CategoryResourceFile".
|
||||
@@ -1443,7 +1434,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
WriteNonTerminatingError(ex, EventlogResources.AccessIsDenied, "AccessIsDenied", ErrorCategory.InvalidOperation, null, null, null, null);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//End BeginProcessing()
|
||||
@@ -1474,13 +1464,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public String[] ComputerName
|
||||
{
|
||||
get { return computername; }
|
||||
get { return _computername; }
|
||||
set
|
||||
{
|
||||
computername = value;
|
||||
_computername = value;
|
||||
}
|
||||
}
|
||||
private string[] computername = { "." };
|
||||
private string[] _computername = { "." };
|
||||
|
||||
/// <summary>
|
||||
/// The following is the definition of the input parameter "LogName".
|
||||
@@ -1494,13 +1484,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public String[] LogName
|
||||
{
|
||||
get { return logname; }
|
||||
get { return _logname; }
|
||||
set
|
||||
{
|
||||
logname = value;
|
||||
_logname = value;
|
||||
}
|
||||
}
|
||||
private String[] logname;
|
||||
private String[] _logname;
|
||||
|
||||
/// <summary>
|
||||
/// The following is the definition of the input parameter "RemoveSource".
|
||||
@@ -1518,13 +1508,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public String[] Source
|
||||
{
|
||||
get { return source; }
|
||||
get { return _source; }
|
||||
set
|
||||
{
|
||||
source = value;
|
||||
_source = value;
|
||||
}
|
||||
}
|
||||
private String[] source;
|
||||
private String[] _source;
|
||||
|
||||
|
||||
|
||||
@@ -1536,7 +1526,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
try
|
||||
{
|
||||
string computer = string.Empty;
|
||||
foreach (string compName in computername)
|
||||
foreach (string compName in _computername)
|
||||
{
|
||||
if ((compName.Equals("localhost", StringComparison.CurrentCultureIgnoreCase)) || (compName.Equals(".", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
@@ -1548,12 +1538,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
if (ParameterSetName.Equals("Default"))
|
||||
{
|
||||
foreach (string log in logname)
|
||||
foreach (string log in _logname)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
if (EventLog.Exists(log, compName))
|
||||
{
|
||||
if (!ShouldProcess(StringUtil.Format(EventlogResources.RemoveEventLogWarning, log, computer)))
|
||||
@@ -1574,16 +1562,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(StringUtil.Format(EventlogResources.PathDoesNotExist, null, computer)), null, ErrorCategory.InvalidOperation, null);
|
||||
WriteError(er);
|
||||
continue;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (string src in source)
|
||||
foreach (string src in _source)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
if (EventLog.SourceExists(src, compName))
|
||||
@@ -1603,12 +1588,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
catch (System.IO.IOException)
|
||||
{
|
||||
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(StringUtil.Format(EventlogResources.PathDoesNotExist, null, computer)), null, ErrorCategory.InvalidOperation, null);
|
||||
WriteError(er);
|
||||
continue;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1618,16 +1600,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
ErrorRecord er = new ErrorRecord(ex, "NewEventlogException", ErrorCategory.SecurityError, null);
|
||||
WriteError(er);
|
||||
|
||||
}
|
||||
}//End BeginProcessing()
|
||||
|
||||
|
||||
|
||||
}//End Class
|
||||
|
||||
#endregion RemoveEventLogCommand
|
||||
|
||||
|
||||
}//Microsoft.PowerShell.Commands
|
||||
|
||||
+26
-27
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -13,7 +14,6 @@ using Dbg = System.Management.Automation;
|
||||
|
||||
namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The get-childitem command class.
|
||||
/// This command lists the contents of a container
|
||||
@@ -57,16 +57,16 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Gets or sets the path for the operation
|
||||
/// </summary>
|
||||
[Parameter(Position = 0, ParameterSetName = childrenSet,
|
||||
ValueFromPipeline=true, ValueFromPipelineByPropertyName = true)]
|
||||
ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||
public string[] Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
}
|
||||
set
|
||||
{
|
||||
paths = value;
|
||||
_paths = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,19 +74,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Gets or sets the literal path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(ParameterSetName = literalChildrenSet,
|
||||
Mandatory = true, ValueFromPipeline=false, ValueFromPipelineByPropertyName = true)]
|
||||
Mandatory = true, ValueFromPipeline = false, ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("PSPath")]
|
||||
public string[] LiteralPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
base.SuppressWildcardExpansion = true;
|
||||
paths = value;
|
||||
_paths = value;
|
||||
} // set
|
||||
} // LiteralPath
|
||||
|
||||
@@ -149,11 +149,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return recurse;
|
||||
return _recurse;
|
||||
}
|
||||
set
|
||||
{
|
||||
recurse = value;
|
||||
_recurse = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,11 +168,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return depth;
|
||||
return _depth;
|
||||
}
|
||||
set
|
||||
{
|
||||
depth = value;
|
||||
_depth = value;
|
||||
this.Recurse = true; // Bug 2391925 - Get-ChildItem -Depth should auto-set -Recurse
|
||||
}
|
||||
}
|
||||
@@ -212,11 +212,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return childNames;
|
||||
return _childNames;
|
||||
}
|
||||
set
|
||||
{
|
||||
childNames = value;
|
||||
_childNames = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,9 +285,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
object result = null;
|
||||
string path = String.Empty;
|
||||
|
||||
if (paths != null && paths.Length > 0)
|
||||
if (_paths != null && _paths.Length > 0)
|
||||
{
|
||||
path = paths[0];
|
||||
path = _paths[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -298,7 +298,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
case childrenSet:
|
||||
case literalChildrenSet:
|
||||
if(Name)
|
||||
if (Name)
|
||||
{
|
||||
result = InvokeProvider.ChildItem.GetChildNamesDynamicParameters(path, context);
|
||||
}
|
||||
@@ -329,12 +329,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// The path for the get-location operation.
|
||||
/// </summary>
|
||||
private string[] paths;
|
||||
private string[] _paths;
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the command should do recursion.
|
||||
/// </summary>
|
||||
private bool recurse;
|
||||
private bool _recurse;
|
||||
|
||||
/// <summary>
|
||||
/// Limits the depth of recursion; used with Recurse parameter;
|
||||
@@ -342,12 +342,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Value '1' will show 1 level deep, etc...;
|
||||
/// Default is uint.MaxValue - it performs full recursion (this parameter has no effect).
|
||||
/// </summary>
|
||||
private uint depth = uint.MaxValue;
|
||||
private uint _depth = uint.MaxValue;
|
||||
|
||||
/// <summary>
|
||||
/// The flag that specifies whether to retrieve the child names or the child items
|
||||
/// </summary>
|
||||
private bool childNames = false;
|
||||
private bool _childNames = false;
|
||||
|
||||
#endregion command data
|
||||
|
||||
@@ -357,17 +357,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// The main execution method for the get-childitem command.
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
CmdletProviderContext currentContext = CmdletProviderContext;
|
||||
|
||||
if (paths == null ||
|
||||
(paths != null && paths.Length == 0))
|
||||
if (_paths == null ||
|
||||
(_paths != null && _paths.Length == 0))
|
||||
{
|
||||
paths = new string[] { String.Empty };
|
||||
_paths = new string[] { String.Empty };
|
||||
}
|
||||
|
||||
foreach (string path in paths)
|
||||
foreach (string path in _paths)
|
||||
{
|
||||
switch (ParameterSetName)
|
||||
{
|
||||
@@ -375,7 +375,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
case literalChildrenSet:
|
||||
try
|
||||
{
|
||||
if(Name)
|
||||
if (Name)
|
||||
{
|
||||
// Get the names of the child items using the static namespace method.
|
||||
// The child names should be written directly to the pipeline using the
|
||||
@@ -499,7 +499,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
private const string targetTreatAsType = "System.Management.Automation.RelationshipTarget";
|
||||
#endif
|
||||
#endregion command code
|
||||
|
||||
} // class GetChildrenCommand
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
+15
-16
@@ -54,15 +54,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
[ValidateNotNullOrEmpty]
|
||||
public TextDataFormat TextFormatType
|
||||
{
|
||||
get { return textFormat; }
|
||||
get { return _textFormat; }
|
||||
set
|
||||
{
|
||||
isTextFormatTypeSet = true;
|
||||
textFormat = value;
|
||||
_isTextFormatTypeSet = true;
|
||||
_textFormat = value;
|
||||
}
|
||||
}
|
||||
private TextDataFormat textFormat = TextDataFormat.UnicodeText;
|
||||
private bool isTextFormatTypeSet = false;
|
||||
private TextDataFormat _textFormat = TextDataFormat.UnicodeText;
|
||||
private bool _isTextFormatTypeSet = false;
|
||||
|
||||
/// <summary>
|
||||
/// Property that sets raw parameter. This will allow clipboard return text or file list as one string.
|
||||
@@ -70,15 +70,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter]
|
||||
public SwitchParameter Raw
|
||||
{
|
||||
get { return raw; }
|
||||
get { return _raw; }
|
||||
set
|
||||
{
|
||||
isRawSet = true;
|
||||
raw = value;
|
||||
_isRawSet = true;
|
||||
_raw = value;
|
||||
}
|
||||
}
|
||||
private bool raw;
|
||||
private bool isRawSet = false;
|
||||
private bool _raw;
|
||||
private bool _isRawSet = false;
|
||||
|
||||
/// <summary>
|
||||
/// This method implements the ProcessRecord method for Get-Clipboard command
|
||||
@@ -86,7 +86,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
protected override void BeginProcessing()
|
||||
{
|
||||
// TextFormatType should only combine with Text.
|
||||
if (Format != ClipboardFormat.Text && isTextFormatTypeSet)
|
||||
if (Format != ClipboardFormat.Text && _isTextFormatTypeSet)
|
||||
{
|
||||
ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(
|
||||
String.Format(CultureInfo.InvariantCulture, ClipboardResources.InvalidTypeCombine)),
|
||||
@@ -94,7 +94,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
// Raw should only combine with Text or FileDropList.
|
||||
if (Format != ClipboardFormat.Text && Format != ClipboardFormat.FileDropList && isRawSet)
|
||||
if (Format != ClipboardFormat.Text && Format != ClipboardFormat.FileDropList && _isRawSet)
|
||||
{
|
||||
ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(
|
||||
String.Format(CultureInfo.InvariantCulture, ClipboardResources.InvalidRawCombine)),
|
||||
@@ -103,7 +103,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (Format == ClipboardFormat.Text)
|
||||
{
|
||||
this.WriteObject(GetClipboardContentAsText(textFormat), true);
|
||||
this.WriteObject(GetClipboardContentAsText(_textFormat), true);
|
||||
}
|
||||
else if (Format == ClipboardFormat.Image)
|
||||
{
|
||||
@@ -111,7 +111,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
else if (Format == ClipboardFormat.FileDropList)
|
||||
{
|
||||
if (raw)
|
||||
if (_raw)
|
||||
{
|
||||
this.WriteObject(Clipboard.GetFileDropList(), true);
|
||||
}
|
||||
@@ -141,7 +141,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// TextFormat default value is Text, by default it is same as Clipboard.GetText()
|
||||
string textContent = Clipboard.GetText(textFormat);
|
||||
if (raw)
|
||||
if (_raw)
|
||||
{
|
||||
result.Add(textContent);
|
||||
}
|
||||
@@ -159,7 +159,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns></returns>
|
||||
private List<PSObject> GetClipboardContentAsFileList()
|
||||
{
|
||||
|
||||
if (!Clipboard.ContainsFileDropList())
|
||||
{
|
||||
return null;
|
||||
|
||||
+711
-710
File diff suppressed because it is too large.
Load diff
+13
-16
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,7 +21,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
public class GetContentCommand : ContentCommandBase
|
||||
{
|
||||
#region Parameters
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The number of content items to retrieve per block.
|
||||
/// By default this value is 1 which means read one block
|
||||
@@ -33,12 +34,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return readCount;
|
||||
return _readCount;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
readCount = value;
|
||||
_readCount = value;
|
||||
}
|
||||
} // ReadCount
|
||||
|
||||
@@ -53,12 +54,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return totalCount;
|
||||
return _totalCount;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
totalCount = value;
|
||||
_totalCount = value;
|
||||
_totalCountSpecified = true;
|
||||
}
|
||||
} // TotalCount
|
||||
@@ -80,7 +81,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
private int _backCount = -1;
|
||||
private bool _tailSpecified = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A virtual method for retrieving the dynamic parameters for a cmdlet. Derived cmdlets
|
||||
/// that require dynamic parameters should override this method and return the
|
||||
@@ -104,20 +105,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
return InvokeProvider.Content.GetContentReaderDynamicParameters(".", context);
|
||||
} // GetDynamicParameters
|
||||
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The number of content items to retrieve per block.
|
||||
/// </summary>
|
||||
private long readCount = 1;
|
||||
private long _readCount = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The number of content items to retrieve.
|
||||
/// </summary>
|
||||
private long totalCount = -1;
|
||||
private long _totalCount = -1;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -126,7 +127,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Gets the content of an item at the specified path
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
// TotalCount and Tail should not be specified at the same time.
|
||||
// Throw out terminating error if this is the case.
|
||||
@@ -211,7 +212,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (TotalCount != 0)
|
||||
{
|
||||
IList results = null;
|
||||
@@ -272,10 +273,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
WriteContentObject(results, countRead, holder.PathInfo, currentContext);
|
||||
}
|
||||
}
|
||||
|
||||
} while (results != null && results.Count > 0 && ((TotalCount < 0) || countRead < TotalCount));
|
||||
}
|
||||
|
||||
} // foreach holder in contentStreams
|
||||
}
|
||||
finally
|
||||
@@ -350,7 +349,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
tailResultQueue.Enqueue(entry);
|
||||
}
|
||||
}
|
||||
|
||||
} while (results != null && results.Count > 0);
|
||||
|
||||
if (tailResultQueue.Count > 0)
|
||||
@@ -445,6 +443,5 @@ namespace Microsoft.PowerShell.Commands
|
||||
#endregion Command code
|
||||
|
||||
} // GetContentCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
+31
-35
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -21,7 +22,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Gets or sets the path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(Position = 0, ParameterSetName = "Path",
|
||||
Mandatory = true, ValueFromPipeline=true, ValueFromPipelineByPropertyName = true)]
|
||||
Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||
public string[] Path
|
||||
{
|
||||
get
|
||||
@@ -39,7 +40,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Gets or sets the literal path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(ParameterSetName = "LiteralPath",
|
||||
Mandatory = true, ValueFromPipeline=false, ValueFromPipelineByPropertyName = true)]
|
||||
Mandatory = true, ValueFromPipeline = false, ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("PSPath")]
|
||||
public string[] LiteralPath
|
||||
{
|
||||
@@ -65,12 +66,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return property;
|
||||
return _property;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
property = value;
|
||||
_property = value;
|
||||
}
|
||||
} // Property
|
||||
|
||||
@@ -94,22 +95,22 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (Path != null && Path.Length > 0)
|
||||
{
|
||||
return InvokeProvider.Property.GetPropertyDynamicParameters(
|
||||
Path[0],
|
||||
SessionStateUtilities.ConvertArrayToCollection<string>(property), context);
|
||||
Path[0],
|
||||
SessionStateUtilities.ConvertArrayToCollection<string>(_property), context);
|
||||
}
|
||||
return InvokeProvider.Property.GetPropertyDynamicParameters(
|
||||
".",
|
||||
SessionStateUtilities.ConvertArrayToCollection<string>(property), context);
|
||||
SessionStateUtilities.ConvertArrayToCollection<string>(_property), context);
|
||||
} // GetDynamicParameters
|
||||
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The properties to be retrieved.
|
||||
/// </summary>
|
||||
private string[] property;
|
||||
private string[] _property;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -118,15 +119,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Gets the properties of an item at the specified path
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
foreach (string path in Path)
|
||||
{
|
||||
foreach (string path in Path)
|
||||
{
|
||||
try
|
||||
{
|
||||
InvokeProvider.Property.Get(
|
||||
path,
|
||||
SessionStateUtilities.ConvertArrayToCollection<string>(property),
|
||||
path,
|
||||
SessionStateUtilities.ConvertArrayToCollection<string>(_property),
|
||||
CmdletProviderContext);
|
||||
}
|
||||
catch (PSNotSupportedException notSupported)
|
||||
@@ -161,13 +162,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
pathNotFound));
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
} // ProcessRecord
|
||||
|
||||
#endregion Command code
|
||||
|
||||
|
||||
} // GetItemPropertyCommand
|
||||
|
||||
/// <summary>
|
||||
@@ -228,12 +226,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return property;
|
||||
return _property;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
property = value;
|
||||
_property = value;
|
||||
}
|
||||
} // Property
|
||||
|
||||
@@ -258,11 +256,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
return InvokeProvider.Property.GetPropertyDynamicParameters(
|
||||
Path[0],
|
||||
SessionStateUtilities.ConvertArrayToCollection<string>(property), context);
|
||||
SessionStateUtilities.ConvertArrayToCollection<string>(_property), context);
|
||||
}
|
||||
return InvokeProvider.Property.GetPropertyDynamicParameters(
|
||||
".",
|
||||
SessionStateUtilities.ConvertArrayToCollection<string>(property), context);
|
||||
SessionStateUtilities.ConvertArrayToCollection<string>(_property), context);
|
||||
} // GetDynamicParameters
|
||||
|
||||
#endregion Parameters
|
||||
@@ -272,7 +270,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// The properties to be retrieved.
|
||||
/// </summary>
|
||||
private string[] property;
|
||||
private string[] _property;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -283,17 +281,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
if (Path == null || Path.Length == 0)
|
||||
{
|
||||
paths = new string[] { "." };
|
||||
}
|
||||
foreach (string path in Path)
|
||||
{
|
||||
if (Path == null || Path.Length == 0)
|
||||
{
|
||||
paths = new string[] { "." };
|
||||
}
|
||||
foreach (string path in Path)
|
||||
{
|
||||
try
|
||||
{
|
||||
Collection<PSObject> itemProperties = InvokeProvider.Property.Get(
|
||||
new string[] { path },
|
||||
SessionStateUtilities.ConvertArrayToCollection<string>(property),
|
||||
SessionStateUtilities.ConvertArrayToCollection<string>(_property),
|
||||
base.SuppressWildcardExpansion);
|
||||
|
||||
if (itemProperties != null)
|
||||
@@ -304,7 +302,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
foreach (string currentPropertyName in this.Name)
|
||||
{
|
||||
if (currentItem.Properties != null &&
|
||||
if (currentItem.Properties != null &&
|
||||
currentItem.Properties[currentPropertyName] != null &&
|
||||
currentItem.Properties[currentPropertyName].Value != null)
|
||||
{
|
||||
@@ -314,7 +312,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (PSNotSupportedException notSupported)
|
||||
{
|
||||
@@ -348,10 +345,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
pathNotFound));
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Command code
|
||||
}
|
||||
}
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
+2
-3
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -17,12 +18,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Creates a new transaction.
|
||||
/// </summary>
|
||||
protected override void EndProcessing ()
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
WriteObject(this.Context.TransactionManager.GetCurrent());
|
||||
}
|
||||
|
||||
} // GetTransactionCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
+135
-141
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Management.Automation;
|
||||
@@ -14,7 +15,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// A command to get WMI Objects
|
||||
/// </summary>
|
||||
[Cmdlet (VerbsCommon.Get, "WmiObject", DefaultParameterSetName = "query",
|
||||
[Cmdlet(VerbsCommon.Get, "WmiObject", DefaultParameterSetName = "query",
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113337", RemotingCapability = RemotingCapability.OwnedByCommand)]
|
||||
public class GetWmiObjectCommand : WmiBaseCmdlet
|
||||
{
|
||||
@@ -26,11 +27,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
[Alias("ClassName")]
|
||||
[Parameter(Position = 0, Mandatory = true, ParameterSetName = "query")]
|
||||
[Parameter(Position =1, ParameterSetName = "list")]
|
||||
[Parameter(Position = 1, ParameterSetName = "list")]
|
||||
public string Class
|
||||
{
|
||||
get { return this.wmiClass; }
|
||||
set { this.wmiClass = value; }
|
||||
get { return _wmiClass; }
|
||||
set { _wmiClass = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// To specify whether to get the results recursively
|
||||
@@ -38,8 +39,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(ParameterSetName = "list")]
|
||||
public SwitchParameter Recurse
|
||||
{
|
||||
get { return this.recurse; }
|
||||
set { this.recurse = value; }
|
||||
get { return _recurse; }
|
||||
set { _recurse = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -48,8 +49,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(Position = 1, ParameterSetName = "query")]
|
||||
public string[] Property
|
||||
{
|
||||
get { return (string[])this.property.Clone(); }
|
||||
set { this.property = value; }
|
||||
get { return (string[])_property.Clone(); }
|
||||
set { _property = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -58,8 +59,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(ParameterSetName = "query")]
|
||||
public string Filter
|
||||
{
|
||||
get { return this.filter; }
|
||||
set { this.filter = value; }
|
||||
get { return _filter; }
|
||||
set { _filter = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -68,19 +69,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter]
|
||||
public SwitchParameter Amended
|
||||
{
|
||||
get { return amended; }
|
||||
set { amended = value; }
|
||||
get { return _amended; }
|
||||
set { _amended = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If Enumerate Deep flag to use. When 'list' parameter is specified 'EnumerateDeep' parameter is ignored.
|
||||
/// </summary>
|
||||
[Parameter(ParameterSetName ="WQLQuery")]
|
||||
[Parameter(ParameterSetName ="query")]
|
||||
[Parameter(ParameterSetName = "WQLQuery")]
|
||||
[Parameter(ParameterSetName = "query")]
|
||||
public SwitchParameter DirectRead
|
||||
{
|
||||
get { return directRead; }
|
||||
set { directRead = value; }
|
||||
get { return _directRead; }
|
||||
set { _directRead = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -89,8 +90,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(ParameterSetName = "list")]
|
||||
public SwitchParameter List
|
||||
{
|
||||
get { return this.list; }
|
||||
set { this.list = value; }
|
||||
get { return _list; }
|
||||
set { _list = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,21 +100,21 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(Mandatory = true, ParameterSetName = "WQLQuery")]
|
||||
public string Query
|
||||
{
|
||||
get { return this.objectQuery; }
|
||||
set { this.objectQuery = value; }
|
||||
get { return _objectQuery; }
|
||||
set { _objectQuery = value; }
|
||||
}
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
private string wmiClass;
|
||||
private string[] property = new string[] {"*"};
|
||||
private string filter;
|
||||
private SwitchParameter amended;
|
||||
private SwitchParameter directRead;
|
||||
private string objectQuery;
|
||||
private SwitchParameter list = false;
|
||||
private SwitchParameter recurse = false;
|
||||
private string _wmiClass;
|
||||
private string[] _property = new string[] { "*" };
|
||||
private string _filter;
|
||||
private SwitchParameter _amended;
|
||||
private SwitchParameter _directRead;
|
||||
private string _objectQuery;
|
||||
private SwitchParameter _list = false;
|
||||
private SwitchParameter _recurse = false;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -125,67 +126,66 @@ namespace Microsoft.PowerShell.Commands
|
||||
internal string GetQueryString()
|
||||
{
|
||||
StringBuilder returnValue = new StringBuilder("select ");
|
||||
returnValue.Append(String.Join(", ", this.property));
|
||||
returnValue.Append(String.Join(", ", _property));
|
||||
returnValue.Append(" from ");
|
||||
returnValue.Append(this.wmiClass);
|
||||
if(!String.IsNullOrEmpty(this.filter))
|
||||
returnValue.Append(_wmiClass);
|
||||
if (!String.IsNullOrEmpty(_filter))
|
||||
{
|
||||
returnValue.Append(" where ");
|
||||
returnValue.Append(this.filter);
|
||||
returnValue.Append(_filter);
|
||||
}
|
||||
return returnValue.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// Uses filter table to convert the class into WMI understandable language.
|
||||
/// Character Description Example Match Comment
|
||||
/// * Matches zero or more characters starting at the specified position A* A,ag,Apple Supported by PowerShell.
|
||||
/// ? Matches any character at the specified position ?n An,in,on (does not match ran) Supported by PowerShell.
|
||||
/// _ Matches any character at the specified position _n An,in,on (does not match ran) Supperted by WMI
|
||||
/// % Matches zero or more characters starting at the specified position A% A,ag,Apple Supperted by WMI
|
||||
/// [] Matches a range of characters [a-l]ook Book,cook,look (does not match took) Supported by WMI and powershell
|
||||
/// [] Matches specified characters [bc]ook Book,cook, (does not match look) Supported by WMI and powershell
|
||||
/// ^ Does not Match specified characters. [^bc]ook Look, took (does not match book, cook) Supported by WMI.
|
||||
/// Character Description Example Match Comment
|
||||
/// * Matches zero or more characters starting at the specified position A* A,ag,Apple Supported by PowerShell.
|
||||
/// ? Matches any character at the specified position ?n An,in,on (does not match ran) Supported by PowerShell.
|
||||
/// _ Matches any character at the specified position _n An,in,on (does not match ran) Supperted by WMI
|
||||
/// % Matches zero or more characters starting at the specified position A% A,ag,Apple Supperted by WMI
|
||||
/// [] Matches a range of characters [a-l]ook Book,cook,look (does not match took) Supported by WMI and powershell
|
||||
/// [] Matches specified characters [bc]ook Book,cook, (does not match look) Supported by WMI and powershell
|
||||
/// ^ Does not Match specified characters. [^bc]ook Look, took (does not match book, cook) Supported by WMI.
|
||||
/// </summary>
|
||||
|
||||
internal string GetFilterClassName()
|
||||
{
|
||||
if(string.IsNullOrEmpty(this.Class))
|
||||
if (string.IsNullOrEmpty(this.Class))
|
||||
return string.Empty;
|
||||
string filterClass = string.Copy(this.Class);
|
||||
filterClass = filterClass.Replace('*','%');
|
||||
filterClass = filterClass.Replace('?','_');
|
||||
filterClass = filterClass.Replace('*', '%');
|
||||
filterClass = filterClass.Replace('?', '_');
|
||||
return filterClass;
|
||||
|
||||
}
|
||||
internal bool IsLocalizedNamespace(string sNamespace)
|
||||
{
|
||||
bool toReturn = false;
|
||||
if( sNamespace.StartsWith("ms_", StringComparison.OrdinalIgnoreCase) )
|
||||
if (sNamespace.StartsWith("ms_", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
toReturn = true;
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
internal bool ValidateClassFormat()
|
||||
internal bool ValidateClassFormat()
|
||||
{
|
||||
string filterClass = this.Class;
|
||||
if( string.IsNullOrEmpty(filterClass) )
|
||||
if (string.IsNullOrEmpty(filterClass))
|
||||
return true;
|
||||
StringBuilder newClassName = new StringBuilder();
|
||||
for (int i = 0; i < filterClass.Length; i ++)
|
||||
for (int i = 0; i < filterClass.Length; i++)
|
||||
{
|
||||
if( Char.IsLetterOrDigit(filterClass[i]) ||
|
||||
filterClass[i].Equals('[') || filterClass[i].Equals(']') ||
|
||||
filterClass[i].Equals('*') || filterClass[i].Equals('?') ||
|
||||
filterClass[i].Equals('-') )
|
||||
if (Char.IsLetterOrDigit(filterClass[i]) ||
|
||||
filterClass[i].Equals('[') || filterClass[i].Equals(']') ||
|
||||
filterClass[i].Equals('*') || filterClass[i].Equals('?') ||
|
||||
filterClass[i].Equals('-'))
|
||||
{
|
||||
newClassName.Append(filterClass[ i ]);
|
||||
newClassName.Append(filterClass[i]);
|
||||
continue;
|
||||
}
|
||||
else if ( filterClass[i].Equals('_') )
|
||||
else if (filterClass[i].Equals('_'))
|
||||
{
|
||||
newClassName.Append('[');
|
||||
newClassName.Append(filterClass[ i ]);
|
||||
newClassName.Append(filterClass[i]);
|
||||
newClassName.Append(']');
|
||||
continue;
|
||||
}
|
||||
@@ -194,22 +194,22 @@ namespace Microsoft.PowerShell.Commands
|
||||
this.Class = newClassName.ToString();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ManagementObjectSearcher object
|
||||
/// </summary>
|
||||
internal ManagementObjectSearcher GetObjectList(ManagementScope scope)
|
||||
{
|
||||
ManagementObjectSearcher searcher =null;
|
||||
StringBuilder queryStringBuilder = new StringBuilder();
|
||||
if(string.IsNullOrEmpty(this.Class) )
|
||||
ManagementObjectSearcher searcher = null;
|
||||
StringBuilder queryStringBuilder = new StringBuilder();
|
||||
if (string.IsNullOrEmpty(this.Class))
|
||||
{
|
||||
queryStringBuilder.Append("select * from meta_class");
|
||||
}
|
||||
else
|
||||
{
|
||||
string filterClass = GetFilterClassName();
|
||||
if( filterClass == null )
|
||||
if (filterClass == null)
|
||||
return searcher;
|
||||
queryStringBuilder.Append("select * from meta_class where __class like '");
|
||||
queryStringBuilder.Append(filterClass);
|
||||
@@ -229,38 +229,37 @@ namespace Microsoft.PowerShell.Commands
|
||||
protected override void BeginProcessing()
|
||||
{
|
||||
ConnectionOptions options = GetConnectionOption();
|
||||
if( this.AsJob )
|
||||
if (this.AsJob)
|
||||
{
|
||||
RunAsJob("Get-WMIObject");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (this.list.IsPresent)
|
||||
if (_list.IsPresent)
|
||||
{
|
||||
if(!this.ValidateClassFormat() )
|
||||
if (!this.ValidateClassFormat())
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
new ArgumentException(
|
||||
String.Format(
|
||||
Thread.CurrentThread.CurrentCulture,
|
||||
"Class", this.Class)),
|
||||
"INVALID_QUERY_IDENTIFIER",
|
||||
ErrorCategory.InvalidArgument,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this,"WmiResources","WmiFilterInvalidClass", this.Class);
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
new ArgumentException(
|
||||
String.Format(
|
||||
Thread.CurrentThread.CurrentCulture,
|
||||
"Class", this.Class)),
|
||||
"INVALID_QUERY_IDENTIFIER",
|
||||
ErrorCategory.InvalidArgument,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiFilterInvalidClass", this.Class);
|
||||
|
||||
WriteError(errorRecord);
|
||||
return;
|
||||
WriteError(errorRecord);
|
||||
return;
|
||||
}
|
||||
foreach (string name in ComputerName)
|
||||
{
|
||||
if( this.Recurse.IsPresent)
|
||||
if (this.Recurse.IsPresent)
|
||||
{
|
||||
Queue namespaceElement = new Queue();
|
||||
namespaceElement.Enqueue(this.Namespace);
|
||||
while(namespaceElement.Count > 0 )
|
||||
while (namespaceElement.Count > 0)
|
||||
{
|
||||
string connectNamespace = (string)namespaceElement.Dequeue();
|
||||
ManagementScope scope = new ManagementScope(WMIHelper.GetScopeString(name, connectNamespace), options);
|
||||
@@ -270,55 +269,54 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
catch (ManagementException e)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
e,
|
||||
"INVALID_NAMESPACE_IDENTIFIER",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this,"WmiResources","WmiNamespaceConnect",connectNamespace, e.Message);
|
||||
WriteError(errorRecord);
|
||||
continue;
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
e,
|
||||
"INVALID_NAMESPACE_IDENTIFIER",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiNamespaceConnect", connectNamespace, e.Message);
|
||||
WriteError(errorRecord);
|
||||
continue;
|
||||
}
|
||||
catch (System.Runtime.InteropServices.COMException e)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
e,
|
||||
"INVALID_NAMESPACE_IDENTIFIER",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this,"WmiResources","WmiNamespaceConnect",connectNamespace, e.Message);
|
||||
WriteError(errorRecord);
|
||||
continue;
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
e,
|
||||
"INVALID_NAMESPACE_IDENTIFIER",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiNamespaceConnect", connectNamespace, e.Message);
|
||||
WriteError(errorRecord);
|
||||
continue;
|
||||
}
|
||||
catch (System.UnauthorizedAccessException e)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
e,
|
||||
"INVALID_NAMESPACE_IDENTIFIER",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this,"WmiResources","WmiNamespaceConnect",connectNamespace, e.Message);
|
||||
WriteError(errorRecord);
|
||||
continue;
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
e,
|
||||
"INVALID_NAMESPACE_IDENTIFIER",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiNamespaceConnect", connectNamespace, e.Message);
|
||||
WriteError(errorRecord);
|
||||
continue;
|
||||
}
|
||||
|
||||
ManagementClass namespaceClass= new ManagementClass(scope, new ManagementPath("__Namespace"), new ObjectGetOptions() );
|
||||
foreach (ManagementBaseObject obj in namespaceClass.GetInstances() )
|
||||
|
||||
ManagementClass namespaceClass = new ManagementClass(scope, new ManagementPath("__Namespace"), new ObjectGetOptions());
|
||||
foreach (ManagementBaseObject obj in namespaceClass.GetInstances())
|
||||
{
|
||||
if( !IsLocalizedNamespace( (string)obj["Name"]) )
|
||||
if (!IsLocalizedNamespace((string)obj["Name"]))
|
||||
{
|
||||
namespaceElement.Enqueue(connectNamespace + "\\" + obj["Name"]);
|
||||
}
|
||||
}
|
||||
|
||||
ManagementObjectSearcher searcher = this.GetObjectList(scope);
|
||||
if( searcher == null )
|
||||
if (searcher == null)
|
||||
continue;
|
||||
foreach (ManagementBaseObject obj in searcher.Get())
|
||||
{
|
||||
WriteObject(obj);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -330,39 +328,39 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
catch (ManagementException e)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
e,
|
||||
"INVALID_NAMESPACE_IDENTIFIER",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this,"WmiResources","WmiNamespaceConnect",this.Namespace, e.Message);
|
||||
WriteError(errorRecord);
|
||||
continue;
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
e,
|
||||
"INVALID_NAMESPACE_IDENTIFIER",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiNamespaceConnect", this.Namespace, e.Message);
|
||||
WriteError(errorRecord);
|
||||
continue;
|
||||
}
|
||||
catch (System.Runtime.InteropServices.COMException e)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
e,
|
||||
"INVALID_NAMESPACE_IDENTIFIER",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this,"WmiResources","WmiNamespaceConnect",this.Namespace, e.Message);
|
||||
WriteError(errorRecord);
|
||||
continue;
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
e,
|
||||
"INVALID_NAMESPACE_IDENTIFIER",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiNamespaceConnect", this.Namespace, e.Message);
|
||||
WriteError(errorRecord);
|
||||
continue;
|
||||
}
|
||||
catch (System.UnauthorizedAccessException e)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
e,
|
||||
"INVALID_NAMESPACE_IDENTIFIER",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this,"WmiResources","WmiNamespaceConnect",this.Namespace, e.Message);
|
||||
WriteError(errorRecord);
|
||||
continue;
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
e,
|
||||
"INVALID_NAMESPACE_IDENTIFIER",
|
||||
ErrorCategory.ObjectNotFound,
|
||||
null);
|
||||
errorRecord.ErrorDetails = new ErrorDetails(this, "WmiResources", "WmiNamespaceConnect", this.Namespace, e.Message);
|
||||
WriteError(errorRecord);
|
||||
continue;
|
||||
}
|
||||
ManagementObjectSearcher searcher = this.GetObjectList(scope);
|
||||
if( searcher == null )
|
||||
if (searcher == null)
|
||||
continue;
|
||||
foreach (ManagementBaseObject obj in searcher.Get())
|
||||
{
|
||||
@@ -371,11 +369,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// When -List is not specified and -Recurse is specified, we need the -Class parameter to compose the right query string
|
||||
if (this.Recurse.IsPresent && string.IsNullOrEmpty(wmiClass))
|
||||
if (this.Recurse.IsPresent && string.IsNullOrEmpty(_wmiClass))
|
||||
{
|
||||
string errormMsg = string.Format(CultureInfo.InvariantCulture, WmiResources.WmiParameterMissing, "-Class");
|
||||
ErrorRecord er = new ErrorRecord(new InvalidOperationException(errormMsg), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
|
||||
@@ -392,8 +389,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
ManagementScope scope = new ManagementScope(WMIHelper.GetScopeString(name, this.Namespace), options);
|
||||
EnumerationOptions enumOptions = new EnumerationOptions();
|
||||
enumOptions.UseAmendedQualifiers = amended;
|
||||
enumOptions.DirectRead = this.directRead;
|
||||
enumOptions.UseAmendedQualifiers = _amended;
|
||||
enumOptions.DirectRead = _directRead;
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query, enumOptions);
|
||||
foreach (ManagementBaseObject obj in searcher.Get())
|
||||
{
|
||||
@@ -450,9 +447,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
System.Management.Automation.Diagnostics.Assert(query.Contains("from"),
|
||||
"Only get called when ErrorCode is InvalidClass, which means the query string contains 'from' and the class name");
|
||||
|
||||
if (wmiClass != null)
|
||||
if (_wmiClass != null)
|
||||
{
|
||||
return wmiClass;
|
||||
return _wmiClass;
|
||||
}
|
||||
|
||||
int fromIndex = query.IndexOf(" from ", StringComparison.OrdinalIgnoreCase);
|
||||
@@ -462,9 +459,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
#endregion Command code
|
||||
|
||||
|
||||
} // GetWmiObjectCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -28,7 +29,6 @@ using Dbg = System.Management.Automation;
|
||||
|
||||
namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
|
||||
#region Get-HotFix
|
||||
|
||||
/// <summary>
|
||||
@@ -44,7 +44,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Specifies the HotFixID. Unique identifier associated with a particular update.
|
||||
/// </summary>
|
||||
[Parameter(Position = 0,ParameterSetName="Default")]
|
||||
[Parameter(Position = 0, ParameterSetName = "Default")]
|
||||
[ValidateNotNullOrEmpty]
|
||||
[Alias("HFID")]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
@@ -111,10 +111,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
#region Overrides
|
||||
|
||||
|
||||
private ManagementObjectSearcher searchProcess;
|
||||
|
||||
private bool inputContainsWildcard = false;
|
||||
private ManagementObjectSearcher _searchProcess;
|
||||
|
||||
private bool _inputContainsWildcard = false;
|
||||
/// <summary>
|
||||
/// Get the List of HotFixes installed on the Local Machine.
|
||||
/// </summary>
|
||||
@@ -145,8 +145,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
QueryString.Append("Select * from Win32_QuickFixEngineering");
|
||||
foundRecord = true;
|
||||
}
|
||||
searchProcess = new ManagementObjectSearcher(scope, new ObjectQuery(QueryString.ToString()));
|
||||
foreach (ManagementObject obj in searchProcess.Get())
|
||||
_searchProcess = new ManagementObjectSearcher(scope, new ObjectQuery(QueryString.ToString()));
|
||||
foreach (ManagementObject obj in _searchProcess.Get())
|
||||
{
|
||||
if (_description != null)
|
||||
{
|
||||
@@ -155,7 +155,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
inputContainsWildcard = true;
|
||||
_inputContainsWildcard = true;
|
||||
}
|
||||
|
||||
// try to translate the SID to a more friendly username
|
||||
@@ -173,7 +173,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
catch (SystemException e) // thrown by SecurityIdentifier.constr
|
||||
{
|
||||
CommandsCommon.CheckForSevereException(this, e);
|
||||
CommandsCommon.CheckForSevereException(this, e);
|
||||
}
|
||||
//catch (ArgumentException) // thrown (indirectly) by SecurityIdentifier.constr (on XP only?)
|
||||
//{ catch not needed - this is already caught as SystemException
|
||||
@@ -189,12 +189,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
WriteObject(obj);
|
||||
foundRecord = true;
|
||||
}
|
||||
if (!foundRecord && !inputContainsWildcard)
|
||||
if (!foundRecord && !_inputContainsWildcard)
|
||||
{
|
||||
Exception Ex = new ArgumentException(StringUtil.Format(HotFixResources.NoEntriesFound, computer));
|
||||
WriteError(new ErrorRecord(Ex, "GetHotFixNoEntriesFound", ErrorCategory.ObjectNotFound, null));
|
||||
}
|
||||
if (searchProcess != null)
|
||||
if (_searchProcess != null)
|
||||
{
|
||||
this.Dispose();
|
||||
}
|
||||
@@ -206,10 +206,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void StopProcessing()
|
||||
{
|
||||
if (searchProcess != null)
|
||||
if (_searchProcess != null)
|
||||
{
|
||||
searchProcess.Dispose();
|
||||
}
|
||||
_searchProcess.Dispose();
|
||||
}
|
||||
}
|
||||
#endregion Overrides
|
||||
|
||||
@@ -228,12 +228,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
if (WildcardPattern.ContainsWildcardCharacters(desc))
|
||||
{
|
||||
inputContainsWildcard = true;
|
||||
_inputContainsWildcard = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
{
|
||||
CommandsCommon.CheckForSevereException(this, e);
|
||||
return false;
|
||||
}
|
||||
@@ -263,16 +263,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (searchProcess != null)
|
||||
if (_searchProcess != null)
|
||||
{
|
||||
searchProcess.Dispose();
|
||||
_searchProcess.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion "IDisposable Members"
|
||||
|
||||
}//end class
|
||||
#endregion
|
||||
|
||||
}//Microsoft.Powershell.commands
|
||||
+57
-56
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Internal;
|
||||
@@ -27,20 +28,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// The WMI Object to use
|
||||
/// </summary>
|
||||
///
|
||||
[Parameter(ValueFromPipeline = true,Mandatory = true,ParameterSetName = "object")]
|
||||
[Parameter(ValueFromPipeline = true, Mandatory = true, ParameterSetName = "object")]
|
||||
public ManagementObject InputObject
|
||||
{
|
||||
get { return this.inputObject; }
|
||||
set { this.inputObject = value; }
|
||||
get { return _inputObject; }
|
||||
set { _inputObject = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The WMI Path to use
|
||||
/// </summary>
|
||||
[Parameter(ParameterSetName = "path",Mandatory = true)]
|
||||
[Parameter(ParameterSetName = "path", Mandatory = true)]
|
||||
public string Path
|
||||
{
|
||||
get { return this.path; }
|
||||
set { this.path = value; }
|
||||
get { return _path; }
|
||||
set { _path = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The WMI class to use
|
||||
@@ -48,19 +49,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(Position = 0, Mandatory = true, ParameterSetName = "class")]
|
||||
public string Class
|
||||
{
|
||||
get { return this.className; }
|
||||
set { this.className = value; }
|
||||
get { return _className; }
|
||||
set { _className = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The WMI Method to execute
|
||||
/// </summary>
|
||||
[Parameter(Position = 1,Mandatory = true)]
|
||||
[Parameter(Position = 1, Mandatory = true)]
|
||||
public string Name
|
||||
{
|
||||
get { return this.methodName; }
|
||||
set { this.methodName = value; }
|
||||
get { return _methodName; }
|
||||
set { _methodName = value; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The parameters to the method specified by MethodName
|
||||
/// </summary>
|
||||
@@ -70,18 +71,18 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Alias("Args")]
|
||||
public object[] ArgumentList
|
||||
{
|
||||
get { return this.argumentList; }
|
||||
set { this.argumentList = value; }
|
||||
get { return _argumentList; }
|
||||
set { _argumentList = value; }
|
||||
}
|
||||
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
private string path = null;
|
||||
private string className = null;
|
||||
private string methodName = null;
|
||||
private ManagementObject inputObject = null;
|
||||
private object[] argumentList = null;
|
||||
private string _path = null;
|
||||
private string _className = null;
|
||||
private string _methodName = null;
|
||||
private ManagementObject _inputObject = null;
|
||||
private object[] _argumentList = null;
|
||||
|
||||
#endregion parameter data
|
||||
#region Command code
|
||||
@@ -90,38 +91,38 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
if( this.AsJob )
|
||||
if (this.AsJob)
|
||||
{
|
||||
RunAsJob("Invoke-WMIMethod");
|
||||
return;
|
||||
}
|
||||
if (inputObject != null)
|
||||
if (_inputObject != null)
|
||||
{
|
||||
object result = null;
|
||||
ManagementBaseObject inputParameters =null ;
|
||||
ManagementBaseObject inputParameters = null;
|
||||
try
|
||||
{
|
||||
inputParameters = inputObject.GetMethodParameters(methodName);
|
||||
if(argumentList != null )
|
||||
inputParameters = _inputObject.GetMethodParameters(_methodName);
|
||||
if (_argumentList != null)
|
||||
{
|
||||
int inParamCount = argumentList.Length;
|
||||
int inParamCount = _argumentList.Length;
|
||||
foreach (PropertyData property in inputParameters.Properties)
|
||||
{
|
||||
if (inParamCount == 0)
|
||||
break;
|
||||
property.Value = argumentList[argumentList.Length - inParamCount];
|
||||
property.Value = _argumentList[_argumentList.Length - inParamCount];
|
||||
inParamCount--;
|
||||
}
|
||||
}
|
||||
if (!ShouldProcess(
|
||||
StringUtil.Format(WmiResources.WmiMethodNameForConfirmation,
|
||||
inputObject["__CLASS"].ToString(),
|
||||
this.Name)
|
||||
))
|
||||
if (!ShouldProcess(
|
||||
StringUtil.Format(WmiResources.WmiMethodNameForConfirmation,
|
||||
_inputObject["__CLASS"].ToString(),
|
||||
this.Name)
|
||||
))
|
||||
{
|
||||
return;
|
||||
}
|
||||
result = inputObject.InvokeMethod(methodName, inputParameters,null);
|
||||
result = _inputObject.InvokeMethod(_methodName, inputParameters, null);
|
||||
}
|
||||
catch (ManagementException e)
|
||||
{
|
||||
@@ -145,14 +146,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
ManagementPath mPath = null;
|
||||
object result = null;
|
||||
ManagementObject mObject = null;
|
||||
if( path != null)
|
||||
if (_path != null)
|
||||
{
|
||||
mPath = new ManagementPath(path);
|
||||
if(String.IsNullOrEmpty(mPath.NamespacePath))
|
||||
mPath = new ManagementPath(_path);
|
||||
if (String.IsNullOrEmpty(mPath.NamespacePath))
|
||||
{
|
||||
mPath.NamespacePath = this.Namespace;
|
||||
}
|
||||
else if( namespaceSpecified )
|
||||
else if (namespaceSpecified)
|
||||
{
|
||||
//ThrowTerminatingError
|
||||
ThrowTerminatingError(new ErrorRecord(
|
||||
@@ -161,8 +162,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
ErrorCategory.InvalidOperation,
|
||||
this.Namespace));
|
||||
}
|
||||
|
||||
if( mPath.Server != "." && serverNameSpecified )
|
||||
|
||||
if (mPath.Server != "." && serverNameSpecified)
|
||||
{
|
||||
//ThrowTerminatingError
|
||||
ThrowTerminatingError(new ErrorRecord(
|
||||
@@ -172,7 +173,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
ComputerName));
|
||||
}
|
||||
//If server name is specified loop through it.
|
||||
if ( !(mPath.Server == "." && serverNameSpecified))
|
||||
if (!(mPath.Server == "." && serverNameSpecified))
|
||||
{
|
||||
string[] serverName = new string[] { mPath.Server };
|
||||
ComputerName = serverName;
|
||||
@@ -183,7 +184,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
result = null;
|
||||
try
|
||||
{
|
||||
if( path != null )
|
||||
if (_path != null)
|
||||
{
|
||||
mPath.Server = name;
|
||||
if (mPath.IsClass)
|
||||
@@ -202,19 +203,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
else
|
||||
{
|
||||
ManagementScope scope = new ManagementScope(WMIHelper.GetScopeString(name, this.Namespace), options);
|
||||
ManagementClass mClass = new ManagementClass(className);
|
||||
ManagementClass mClass = new ManagementClass(_className);
|
||||
mObject = mClass;
|
||||
mObject.Scope = scope;
|
||||
}
|
||||
ManagementBaseObject inputParameters = mObject.GetMethodParameters(methodName);
|
||||
if(argumentList != null )
|
||||
ManagementBaseObject inputParameters = mObject.GetMethodParameters(_methodName);
|
||||
if (_argumentList != null)
|
||||
{
|
||||
int inParamCount = argumentList.Length;
|
||||
int inParamCount = _argumentList.Length;
|
||||
foreach (PropertyData property in inputParameters.Properties)
|
||||
{
|
||||
if (inParamCount == 0)
|
||||
break;
|
||||
object argument = PSObject.Base(argumentList[argumentList.Length - inParamCount]);
|
||||
object argument = PSObject.Base(_argumentList[_argumentList.Length - inParamCount]);
|
||||
if (property.IsArray)
|
||||
{
|
||||
property.Value = MakeBaseObjectArray(argument);
|
||||
@@ -226,15 +227,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
inParamCount--;
|
||||
}
|
||||
}
|
||||
if (!ShouldProcess(
|
||||
StringUtil.Format(WmiResources.WmiMethodNameForConfirmation,
|
||||
mObject["__CLASS"].ToString(),
|
||||
this.Name)
|
||||
))
|
||||
{
|
||||
return;
|
||||
}
|
||||
result = mObject.InvokeMethod(this.methodName, inputParameters,null);
|
||||
if (!ShouldProcess(
|
||||
StringUtil.Format(WmiResources.WmiMethodNameForConfirmation,
|
||||
mObject["__CLASS"].ToString(),
|
||||
this.Name)
|
||||
))
|
||||
{
|
||||
return;
|
||||
}
|
||||
result = mObject.InvokeMethod(_methodName, inputParameters, null);
|
||||
}
|
||||
catch (ManagementException e)
|
||||
{
|
||||
@@ -296,5 +297,5 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
#endregion Command code
|
||||
}//InvokeWMIObject
|
||||
}//InvokeWMIObject
|
||||
}
|
||||
+14
-15
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -10,7 +11,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// A command to move a property on an item to another item
|
||||
/// </summary>
|
||||
[Cmdlet (VerbsCommon.Move, "ItemProperty", SupportsShouldProcess = true, DefaultParameterSetName = "Path", SupportsTransactions = true,
|
||||
[Cmdlet(VerbsCommon.Move, "ItemProperty", SupportsShouldProcess = true, DefaultParameterSetName = "Path", SupportsTransactions = true,
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113351")]
|
||||
public class MoveItemPropertyCommand : PassThroughItemPropertyCommandBase
|
||||
{
|
||||
@@ -19,8 +20,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Gets or sets the path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(Position = 0, ParameterSetName = "Path",
|
||||
Mandatory = true, ValueFromPipeline=true, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position = 0, ParameterSetName = "Path",
|
||||
Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||
public string[] Path
|
||||
{
|
||||
get
|
||||
@@ -64,7 +65,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return property;
|
||||
return _property;
|
||||
} // get
|
||||
|
||||
set
|
||||
@@ -73,7 +74,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
value = new string[0];
|
||||
}
|
||||
property = value;
|
||||
_property = value;
|
||||
}
|
||||
} // Property
|
||||
|
||||
@@ -86,15 +87,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return destination;
|
||||
return _destination;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
destination = value;
|
||||
_destination = value;
|
||||
}
|
||||
} // Destination
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A virtual method for retrieving the dynamic parameters for a cmdlet. Derived cmdlets
|
||||
/// that require dynamic parameters should override this method and return the
|
||||
@@ -129,20 +130,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
propertyName,
|
||||
context);
|
||||
} // GetDynamicParameters
|
||||
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The property to be created.
|
||||
/// </summary>
|
||||
private string[] property = new string[0];
|
||||
private string[] _property = new string[0];
|
||||
|
||||
/// <summary>
|
||||
/// The destination path of the item to copy the property to.
|
||||
/// </summary>
|
||||
private string destination;
|
||||
private string _destination;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -151,7 +152,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Creates the property on the item
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
foreach (string path in Path)
|
||||
{
|
||||
@@ -193,7 +194,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
pathNotFound));
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // ProcessRecord
|
||||
@@ -201,5 +201,4 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
|
||||
} // MoveItemPropertyCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
File diff suppressed because it is too large.
Load diff
+15
-16
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -10,7 +11,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// A command to create a new property on an object.
|
||||
/// </summary>
|
||||
[Cmdlet (VerbsCommon.New, "ItemProperty", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
[Cmdlet(VerbsCommon.New, "ItemProperty", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113354")]
|
||||
public class NewItemPropertyCommand : ItemPropertyCommandBase
|
||||
{
|
||||
@@ -63,12 +64,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return property;
|
||||
return _property;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
property = value;
|
||||
_property = value;
|
||||
}
|
||||
} // Property
|
||||
|
||||
@@ -82,15 +83,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return type;
|
||||
return _type;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
type = value;
|
||||
_type = value;
|
||||
}
|
||||
} // Type
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The value of the property to create on the item.
|
||||
/// </summary>
|
||||
@@ -100,12 +101,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return propertyValue;
|
||||
return _propertyValue;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
propertyValue = value;
|
||||
_propertyValue = value;
|
||||
}
|
||||
} // Value
|
||||
|
||||
@@ -159,25 +160,25 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
return InvokeProvider.Property.NewPropertyDynamicParameters(".", Name, PropertyType, Value, context);
|
||||
} // GetDynamicParameters
|
||||
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The property to be created.
|
||||
/// </summary>
|
||||
private string property;
|
||||
private string _property;
|
||||
|
||||
/// <summary>
|
||||
/// The type of the property to be created.
|
||||
/// </summary>
|
||||
private string type;
|
||||
private string _type;
|
||||
|
||||
/// <summary>
|
||||
/// The value of the property to be created.
|
||||
/// </summary>
|
||||
private object propertyValue;
|
||||
private object _propertyValue;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -186,7 +187,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Creates the property on the item
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
foreach (string path in Path)
|
||||
{
|
||||
@@ -226,12 +227,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
pathNotFound));
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
} // ProcessRecord
|
||||
#endregion Command code
|
||||
|
||||
|
||||
} // NewItemPropertyCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
+51
-53
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
@@ -24,7 +25,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
public class SplitPathCommand : CoreCommandWithCredentialsBase
|
||||
{
|
||||
#region Parameters
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The parameter set name to get the parent path
|
||||
/// </summary>
|
||||
@@ -67,12 +68,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
paths = value;
|
||||
_paths = value;
|
||||
} // set
|
||||
} // Path
|
||||
|
||||
@@ -85,13 +86,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
base.SuppressWildcardExpansion = true;
|
||||
paths = value;
|
||||
_paths = value;
|
||||
} // set
|
||||
} // LiteralPath
|
||||
|
||||
@@ -105,17 +106,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// the MSH path.
|
||||
/// </value>
|
||||
///
|
||||
[Parameter(Position=1, ValueFromPipelineByPropertyName = true, ParameterSetName=qualifierSet, Mandatory=false)]
|
||||
[Parameter(Position = 1, ValueFromPipelineByPropertyName = true, ParameterSetName = qualifierSet, Mandatory = false)]
|
||||
public SwitchParameter Qualifier
|
||||
{
|
||||
get
|
||||
{
|
||||
return qualifier;
|
||||
return _qualifier;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
qualifier = value;
|
||||
_qualifier = value;
|
||||
} //set
|
||||
} // Qualifier
|
||||
|
||||
@@ -129,17 +130,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// the MSH path.
|
||||
/// </value>
|
||||
///
|
||||
[Parameter(ParameterSetName= noQualifierSet, Mandatory=false, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(ParameterSetName = noQualifierSet, Mandatory = false, ValueFromPipelineByPropertyName = true)]
|
||||
public SwitchParameter NoQualifier
|
||||
{
|
||||
get
|
||||
{
|
||||
return noqualifier;
|
||||
return _noqualifier;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
noqualifier = value;
|
||||
_noqualifier = value;
|
||||
} //set
|
||||
} // NoQualifier
|
||||
|
||||
@@ -152,17 +153,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// If true the parent of the path will be returned.
|
||||
/// </value>
|
||||
///
|
||||
[Parameter(ParameterSetName=parentSet, Mandatory=false, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(ParameterSetName = parentSet, Mandatory = false, ValueFromPipelineByPropertyName = true)]
|
||||
public SwitchParameter Parent
|
||||
{
|
||||
get
|
||||
{
|
||||
return parent;
|
||||
return _parent;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
parent = value;
|
||||
_parent = value;
|
||||
} //set
|
||||
} // Parent
|
||||
|
||||
@@ -174,17 +175,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// If true the leaf name of the path will be returned.
|
||||
/// </value>
|
||||
///
|
||||
[Parameter(ParameterSetName=leafSet, Mandatory=false, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(ParameterSetName = leafSet, Mandatory = false, ValueFromPipelineByPropertyName = true)]
|
||||
public SwitchParameter Leaf
|
||||
{
|
||||
get
|
||||
{
|
||||
return leaf;
|
||||
return _leaf;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
leaf = value;
|
||||
_leaf = value;
|
||||
} //set
|
||||
} // Leaf
|
||||
|
||||
@@ -197,12 +198,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return resolve;
|
||||
return _resolve;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
resolve = value;
|
||||
_resolve = value;
|
||||
} //set
|
||||
} // Resolve
|
||||
|
||||
@@ -215,29 +216,29 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return isAbsolute;
|
||||
return _isAbsolute;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
isAbsolute = value;
|
||||
_isAbsolute = value;
|
||||
} //set
|
||||
}
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The path to resolve
|
||||
/// </summary>
|
||||
private string[] paths;
|
||||
private string[] _paths;
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the qualifier of the path should be returned.
|
||||
/// The qualifier is either the drive name or provider name that
|
||||
/// is qualifying the path.
|
||||
/// </summary>
|
||||
private bool qualifier;
|
||||
private bool _qualifier;
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the qualifier of the path should be returned.
|
||||
@@ -246,27 +247,27 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// The qualifier is either the drive name or provider name that
|
||||
/// is qualifying the path.
|
||||
/// </summary>
|
||||
private bool noqualifier;
|
||||
private bool _noqualifier;
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the parent path of the specified path should be returned.
|
||||
/// </summary>
|
||||
private bool parent = true;
|
||||
private bool _parent = true;
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the leaf name of the specified path should be returned.
|
||||
/// </summary>
|
||||
private bool leaf;
|
||||
private bool _leaf;
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the path(s) should be resolved before being parsed.
|
||||
/// </summary>
|
||||
private bool resolve;
|
||||
private bool _resolve;
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the path(s) are absolute paths.
|
||||
/// </summary>
|
||||
private bool isAbsolute;
|
||||
private bool _isAbsolute;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -276,20 +277,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Parses the specified path and returns the portion determined by the
|
||||
/// boolean parameters.
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
StringCollection pathsToParse = new StringCollection();
|
||||
|
||||
if (resolve)
|
||||
if (_resolve)
|
||||
{
|
||||
CmdletProviderContext currentContext = CmdletProviderContext;
|
||||
|
||||
foreach (string path in paths)
|
||||
foreach (string path in _paths)
|
||||
{
|
||||
// resolve the paths and then parse each one.
|
||||
|
||||
Collection<PathInfo> resolvedPaths = null;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
resolvedPaths =
|
||||
@@ -369,7 +370,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
pathNotFound));
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -383,7 +383,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
for (int index = 0; index < pathsToParse.Count; ++index)
|
||||
{
|
||||
string result = null;
|
||||
|
||||
|
||||
switch (ParameterSetName)
|
||||
{
|
||||
case isAbsoluteSet:
|
||||
@@ -394,16 +394,16 @@ namespace Microsoft.PowerShell.Commands
|
||||
WriteObject(isPathAbsolute);
|
||||
continue;
|
||||
|
||||
case qualifierSet :
|
||||
case qualifierSet:
|
||||
int separatorIndex = pathsToParse[index].IndexOf(":", StringComparison.CurrentCulture);
|
||||
|
||||
if (separatorIndex < 0)
|
||||
{
|
||||
FormatException e =
|
||||
new FormatException (
|
||||
FormatException e =
|
||||
new FormatException(
|
||||
StringUtil.Format(NavigationResources.ParsePathFormatError, pathsToParse[index]));
|
||||
WriteError (
|
||||
new ErrorRecord (
|
||||
WriteError(
|
||||
new ErrorRecord(
|
||||
e,
|
||||
"ParsePathFormatError", // RENAME
|
||||
ErrorCategory.InvalidArgument,
|
||||
@@ -419,9 +419,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
// The plus 2 is for the length of the provider separator
|
||||
// which is "::"
|
||||
|
||||
result =
|
||||
result =
|
||||
pathsToParse[index].Substring(
|
||||
0,
|
||||
0,
|
||||
separatorIndex + 2);
|
||||
}
|
||||
else
|
||||
@@ -433,10 +433,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case parentSet :
|
||||
case literalPathSet :
|
||||
bool pathStartsWithRoot =
|
||||
|
||||
case parentSet:
|
||||
case literalPathSet:
|
||||
bool pathStartsWithRoot =
|
||||
pathsToParse[index].StartsWith("\\", StringComparison.CurrentCulture) ||
|
||||
pathsToParse[index].StartsWith("/", StringComparison.CurrentCulture);
|
||||
|
||||
@@ -461,12 +461,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
break;
|
||||
|
||||
case leafSet :
|
||||
case leafSet:
|
||||
try
|
||||
{
|
||||
result =
|
||||
result =
|
||||
SessionState.Path.ParseChildName(
|
||||
pathsToParse[index],
|
||||
pathsToParse[index],
|
||||
CmdletProviderContext,
|
||||
true);
|
||||
}
|
||||
@@ -498,7 +498,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
break;
|
||||
|
||||
case noQualifierSet :
|
||||
case noQualifierSet:
|
||||
result = RemoveQualifier(pathsToParse[index]);
|
||||
break;
|
||||
|
||||
@@ -547,7 +547,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
result = path.Substring(index + 2);
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
string driveName = String.Empty;
|
||||
|
||||
@@ -564,8 +564,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
return result;
|
||||
} // RemoveQualifier
|
||||
|
||||
} // SplitPathCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
+7
-7
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -14,7 +15,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
public class PassThroughContentCommandBase : ContentCommandBase
|
||||
{
|
||||
#region Parameters
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the passthrough parameter to the command
|
||||
/// </summary>
|
||||
@@ -23,12 +24,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return passThrough;
|
||||
return _passThrough;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
passThrough = value;
|
||||
_passThrough = value;
|
||||
} // set
|
||||
} // PassThru
|
||||
|
||||
@@ -40,19 +41,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.DoesProviderSupportShouldProcess (base.Path);
|
||||
return base.DoesProviderSupportShouldProcess(base.Path);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the content returned from the provider should
|
||||
/// be passed through to the pipeline.
|
||||
/// </summary>
|
||||
private bool passThrough;
|
||||
private bool _passThrough;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -77,6 +78,5 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
#endregion protected members
|
||||
} // PassThroughContentCommandBase
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
+7
-8
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -14,7 +15,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
public class PassThroughItemPropertyCommandBase : ItemPropertyCommandBase
|
||||
{
|
||||
#region Parameters
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the passthrough parameter to the command
|
||||
/// </summary>
|
||||
@@ -23,12 +24,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return passThrough;
|
||||
return _passThrough;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
passThrough = value;
|
||||
_passThrough = value;
|
||||
} // set
|
||||
} // PassThru
|
||||
|
||||
@@ -62,12 +63,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the property returned from the provider should
|
||||
/// be passed through to the pipeline.
|
||||
/// </summary>
|
||||
private bool passThrough;
|
||||
private bool _passThrough;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -81,7 +82,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.DoesProviderSupportShouldProcess (base.paths);
|
||||
return base.DoesProviderSupportShouldProcess(base.paths);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,8 +104,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
} // GetCurrentContext
|
||||
|
||||
#endregion protected members
|
||||
|
||||
} // PassThroughItemPropertyCommandBase
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
+22
-23
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -40,18 +41,18 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Gets or sets the path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter (Position = 0, ParameterSetName = "Path",
|
||||
[Parameter(Position = 0, ParameterSetName = "Path",
|
||||
Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||
public string[] Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
paths = value;
|
||||
_paths = value;
|
||||
} // set
|
||||
} // Path
|
||||
|
||||
@@ -59,19 +60,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Gets or sets the literal path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(ParameterSetName = "LiteralPath",
|
||||
Mandatory = true, ValueFromPipeline=false, ValueFromPipelineByPropertyName = true)]
|
||||
Mandatory = true, ValueFromPipeline = false, ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("PSPath")]
|
||||
public string[] LiteralPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
base.SuppressWildcardExpansion = true;
|
||||
paths = value;
|
||||
_paths = value;
|
||||
} // set
|
||||
} // LiteralPath
|
||||
|
||||
@@ -134,12 +135,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return type;
|
||||
return _type;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
type = value;
|
||||
_type = value;
|
||||
} // set
|
||||
} // Type
|
||||
|
||||
@@ -151,15 +152,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return isValid;
|
||||
return _isValid;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
isValid = value;
|
||||
_isValid = value;
|
||||
} // set
|
||||
} // IsValid
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A virtual method for retrieving the dynamic parameters for a cmdlet. Derived cmdlets
|
||||
/// that require dynamic parameters should override this method and return the
|
||||
@@ -196,11 +197,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The path to the item to ping
|
||||
/// </summary>
|
||||
private string[] paths;
|
||||
private string[] _paths;
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -208,12 +209,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// the specified path, a container exists at the specified path, or a
|
||||
/// leaf item exists at the specified path.
|
||||
/// </summary>
|
||||
private TestPathType type = TestPathType.Any;
|
||||
private TestPathType _type = TestPathType.Any;
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the path should be checked for validity.
|
||||
/// </summary>
|
||||
private SwitchParameter isValid = new SwitchParameter();
|
||||
private SwitchParameter _isValid = new SwitchParameter();
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -222,25 +223,25 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Determines if an item at the specified path exists.
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
CmdletProviderContext currentContext = CmdletProviderContext;
|
||||
|
||||
foreach (string path in paths)
|
||||
|
||||
foreach (string path in _paths)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
try
|
||||
{
|
||||
if(IsValid)
|
||||
if (IsValid)
|
||||
{
|
||||
result = SessionState.Path.IsValid (path, currentContext);
|
||||
result = SessionState.Path.IsValid(path, currentContext);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.PathType == TestPathType.Container)
|
||||
{
|
||||
result = InvokeProvider.Item.IsContainer (path, currentContext);
|
||||
result = InvokeProvider.Item.IsContainer(path, currentContext);
|
||||
}
|
||||
else if (this.PathType == TestPathType.Leaf)
|
||||
{
|
||||
@@ -253,7 +254,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
result = InvokeProvider.Item.Exists(path, currentContext);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// Any of the known exceptions means the path does not exist.
|
||||
catch (PSNotSupportedException)
|
||||
@@ -276,6 +276,5 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
|
||||
} // PingPathCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+4
-6
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -13,7 +14,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
public class ItemPropertyCommandBase : CoreCommandWithCredentialsBase
|
||||
{
|
||||
#region Parameters
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the filter parameter
|
||||
/// </summary>
|
||||
@@ -30,7 +31,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
base.Filter = value;
|
||||
} // set
|
||||
} // Filter
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the include property
|
||||
/// </summary>
|
||||
@@ -67,15 +68,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The path to the item
|
||||
/// </summary>
|
||||
internal string[] paths = new string[0];
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
|
||||
} // ItemPropertyCommandBase
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
+35
-34
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -29,10 +30,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Alias("NS")]
|
||||
public string Namespace
|
||||
{
|
||||
get { return this.nameSpace; }
|
||||
set { this.nameSpace = value;}
|
||||
get { return _nameSpace; }
|
||||
set { _nameSpace = value; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The credential to use
|
||||
/// </summary>
|
||||
@@ -40,10 +41,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Credential()]
|
||||
public PSCredential Credential
|
||||
{
|
||||
get { return this.credential; }
|
||||
set { this.credential = value; }
|
||||
get { return _credential; }
|
||||
set { _credential = value; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The ComputerName in which to query
|
||||
/// </summary>
|
||||
@@ -52,19 +53,19 @@ namespace Microsoft.PowerShell.Commands
|
||||
[ValidateNotNullOrEmpty]
|
||||
public string ComputerName
|
||||
{
|
||||
get { return this.computerName; }
|
||||
set { this.computerName = value; }
|
||||
get { return _computerName; }
|
||||
set { _computerName = value; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The WMI class to use
|
||||
/// </summary>
|
||||
[Parameter(Position = 0, Mandatory = true, ParameterSetName = "class")]
|
||||
public string Class
|
||||
{
|
||||
get { return this.className; }
|
||||
set { this.className = value; }
|
||||
get { return _className; }
|
||||
set { _className = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -73,10 +74,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(Position = 0, Mandatory = true, ParameterSetName = "query")]
|
||||
public string Query
|
||||
{
|
||||
get { return this.objectQuery; }
|
||||
set { this.objectQuery = value; }
|
||||
get { return _objectQuery; }
|
||||
set { _objectQuery = value; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Timeout in milliseconds
|
||||
/// </summary>
|
||||
@@ -86,22 +87,22 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return timeOut;
|
||||
return _timeOut;
|
||||
}
|
||||
set
|
||||
{
|
||||
timeOut = value;
|
||||
timeoutSpecified = true;
|
||||
_timeOut = value;
|
||||
_timeoutSpecified = true;
|
||||
}
|
||||
}
|
||||
|
||||
private Int64 timeOut = 0;
|
||||
private bool timeoutSpecified = false;
|
||||
private string objectQuery = null;
|
||||
private string className = null;
|
||||
private string computerName = "localhost";
|
||||
private string nameSpace = "root\\cimv2";
|
||||
private PSCredential credential;
|
||||
|
||||
private Int64 _timeOut = 0;
|
||||
private bool _timeoutSpecified = false;
|
||||
private string _objectQuery = null;
|
||||
private string _className = null;
|
||||
private string _computerName = "localhost";
|
||||
private string _nameSpace = "root\\cimv2";
|
||||
private PSCredential _credential;
|
||||
|
||||
#endregion parameters
|
||||
#region helper functions
|
||||
@@ -128,16 +129,16 @@ namespace Microsoft.PowerShell.Commands
|
||||
protected override Object GetSourceObject()
|
||||
{
|
||||
string wmiQuery = this.Query;
|
||||
if(this.Class != null )
|
||||
if (this.Class != null)
|
||||
{
|
||||
//Validate class format
|
||||
for (int i = 0; i < this.Class.Length; i ++)
|
||||
for (int i = 0; i < this.Class.Length; i++)
|
||||
{
|
||||
if( Char.IsLetterOrDigit(this.Class[i]) || this.Class[i].Equals('_') )
|
||||
if (Char.IsLetterOrDigit(this.Class[i]) || this.Class[i].Equals('_'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
new ArgumentException(
|
||||
String.Format(
|
||||
@@ -170,12 +171,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
conOptions.Password = cred.Password;
|
||||
}
|
||||
|
||||
ManagementScope scope = new ManagementScope(GetScopeString(computerName, this.Namespace), conOptions);
|
||||
ManagementScope scope = new ManagementScope(GetScopeString(_computerName, this.Namespace), conOptions);
|
||||
EventWatcherOptions evtOptions = new EventWatcherOptions();
|
||||
|
||||
if(timeoutSpecified)
|
||||
if (_timeoutSpecified)
|
||||
{
|
||||
evtOptions.Timeout = new TimeSpan(timeOut * 10000);
|
||||
evtOptions.Timeout = new TimeSpan(_timeOut * 10000);
|
||||
}
|
||||
|
||||
ManagementEventWatcher watcher = new ManagementEventWatcher(scope, new EventQuery(wmiQuery), evtOptions);
|
||||
@@ -200,13 +201,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Register for the "Unsubscribed" event so that we can stop the
|
||||
// event watcher.
|
||||
PSEventSubscriber newSubscriber = NewSubscriber;
|
||||
if(newSubscriber != null)
|
||||
if (newSubscriber != null)
|
||||
{
|
||||
newSubscriber.Unsubscribed += new PSEventUnsubscribedEventHandler(newSubscriber_Unsubscribed);
|
||||
}
|
||||
}
|
||||
|
||||
void newSubscriber_Unsubscribed(object sender, PSEventUnsubscribedEventArgs e)
|
||||
private void newSubscriber_Unsubscribed(object sender, PSEventUnsubscribedEventArgs e)
|
||||
{
|
||||
ManagementEventWatcher watcher = sender as ManagementEventWatcher;
|
||||
if (watcher != null)
|
||||
|
||||
+12
-13
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -10,7 +11,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// A command to remove a property from an item.
|
||||
/// </summary>
|
||||
[Cmdlet (VerbsCommon.Remove, "ItemProperty", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
[Cmdlet(VerbsCommon.Remove, "ItemProperty", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113374")]
|
||||
public class RemoveItemPropertyCommand : ItemPropertyCommandBase
|
||||
{
|
||||
@@ -20,7 +21,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Gets or sets the path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(Position = 0, ParameterSetName = "Path",
|
||||
Mandatory = true, ValueFromPipeline=true, ValueFromPipelineByPropertyName = true)]
|
||||
Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||
public string[] Path
|
||||
{
|
||||
get
|
||||
@@ -38,7 +39,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Gets or sets the literal path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(ParameterSetName = "LiteralPath",
|
||||
Mandatory = true, ValueFromPipeline=false, ValueFromPipelineByPropertyName = true)]
|
||||
Mandatory = true, ValueFromPipeline = false, ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("PSPath")]
|
||||
public string[] LiteralPath
|
||||
{
|
||||
@@ -58,24 +59,24 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// The name of the property to create on the item
|
||||
/// </summary>
|
||||
///
|
||||
[Parameter(Mandatory=true, Position = 1, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("PSProperty")]
|
||||
public string[] Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return property;
|
||||
return _property;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
property = new string[0];
|
||||
_property = new string[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
property = value;
|
||||
_property = value;
|
||||
}
|
||||
}
|
||||
} // Property
|
||||
@@ -136,15 +137,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
return InvokeProvider.Property.RemovePropertyDynamicParameters(".", propertyName, context);
|
||||
} // GetDynamicParameters
|
||||
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The property to be created.
|
||||
/// </summary>
|
||||
private string[] property = new string[0];
|
||||
private string[] _property = new string[0];
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -153,7 +154,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Removes the property from the item
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
foreach (string path in Path)
|
||||
{
|
||||
@@ -195,7 +196,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
pathNotFound));
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
} // ProcessRecord
|
||||
@@ -203,5 +203,4 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
|
||||
} // RemoveItemPropertyCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
+25
-24
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Management;
|
||||
using System.Management.Automation;
|
||||
@@ -10,7 +11,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// A command to Remove WMI Object
|
||||
/// </summary>
|
||||
[Cmdlet(VerbsCommon.Remove, "WmiObject", DefaultParameterSetName = "class",SupportsShouldProcess = true,
|
||||
[Cmdlet(VerbsCommon.Remove, "WmiObject", DefaultParameterSetName = "class", SupportsShouldProcess = true,
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113381", RemotingCapability = RemotingCapability.OwnedByCommand)]
|
||||
public class RemoveWmiObject : WmiBaseCmdlet
|
||||
{
|
||||
@@ -22,34 +23,34 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(ValueFromPipeline = true, Mandatory = true, ParameterSetName = "object")]
|
||||
public ManagementObject InputObject
|
||||
{
|
||||
get { return this.inputObject; }
|
||||
set { this.inputObject = value; }
|
||||
get { return _inputObject; }
|
||||
set { _inputObject = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The WMI Path to use
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true,ParameterSetName = "path")]
|
||||
[Parameter(Mandatory = true, ParameterSetName = "path")]
|
||||
public string Path
|
||||
{
|
||||
get { return this.path; }
|
||||
set { this.path = value; }
|
||||
get { return _path; }
|
||||
set { _path = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The WMI class to use
|
||||
/// </summary>
|
||||
[Parameter(Position = 0, Mandatory = true,ParameterSetName = "class")]
|
||||
[Parameter(Position = 0, Mandatory = true, ParameterSetName = "class")]
|
||||
public string Class
|
||||
{
|
||||
get { return this.className; }
|
||||
set { this.className = value; }
|
||||
get { return _className; }
|
||||
set { _className = value; }
|
||||
}
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
private string path = null;
|
||||
private string className = null;
|
||||
private ManagementObject inputObject = null;
|
||||
private string _path = null;
|
||||
private string _className = null;
|
||||
private ManagementObject _inputObject = null;
|
||||
|
||||
#endregion parameter data
|
||||
#region Command code
|
||||
@@ -58,20 +59,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
if( this.AsJob )
|
||||
if (this.AsJob)
|
||||
{
|
||||
RunAsJob("Remove-WMIObject");
|
||||
return;
|
||||
}
|
||||
if (inputObject != null)
|
||||
if (_inputObject != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!ShouldProcess(inputObject["__PATH"].ToString()) )
|
||||
if (!ShouldProcess(_inputObject["__PATH"].ToString()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
inputObject.Delete();
|
||||
_inputObject.Delete();
|
||||
}
|
||||
catch (ManagementException e)
|
||||
{
|
||||
@@ -90,14 +91,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
ConnectionOptions options = GetConnectionOption();
|
||||
ManagementPath mPath = null;
|
||||
ManagementObject mObject = null;
|
||||
if (path != null)
|
||||
if (_path != null)
|
||||
{
|
||||
mPath = new ManagementPath(path);
|
||||
if(String.IsNullOrEmpty(mPath.NamespacePath))
|
||||
mPath = new ManagementPath(_path);
|
||||
if (String.IsNullOrEmpty(mPath.NamespacePath))
|
||||
{
|
||||
mPath.NamespacePath = this.Namespace;
|
||||
}
|
||||
else if( namespaceSpecified )
|
||||
else if (namespaceSpecified)
|
||||
{
|
||||
//ThrowTerminatingError
|
||||
ThrowTerminatingError(new ErrorRecord(
|
||||
@@ -107,7 +108,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
this.Namespace));
|
||||
}
|
||||
|
||||
if( mPath.Server != "." && serverNameSpecified )
|
||||
if (mPath.Server != "." && serverNameSpecified)
|
||||
{
|
||||
//ThrowTerminatingError
|
||||
ThrowTerminatingError(new ErrorRecord(
|
||||
@@ -126,7 +127,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
try
|
||||
{
|
||||
if( path != null )
|
||||
if (_path != null)
|
||||
{
|
||||
mPath.Server = name;
|
||||
if (mPath.IsClass)
|
||||
@@ -145,11 +146,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
else
|
||||
{
|
||||
ManagementScope scope = new ManagementScope(WMIHelper.GetScopeString(name, this.Namespace), options);
|
||||
ManagementClass mClass = new ManagementClass(className);
|
||||
ManagementClass mClass = new ManagementClass(_className);
|
||||
mObject = mClass;
|
||||
mObject.Scope = scope;
|
||||
}
|
||||
if (!ShouldProcess(mObject["__PATH"].ToString()) )
|
||||
if (!ShouldProcess(mObject["__PATH"].ToString()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
+18
-19
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -10,7 +11,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// A command to rename a property of an item at a specified path
|
||||
/// </summary>
|
||||
[Cmdlet (VerbsCommon.Rename, "ItemProperty", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
[Cmdlet(VerbsCommon.Rename, "ItemProperty", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113383")]
|
||||
public class RenameItemPropertyCommand : PassThroughItemPropertyCommandBase
|
||||
{
|
||||
@@ -20,17 +21,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Gets or sets the path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(Position = 0, ParameterSetName = "Path",
|
||||
Mandatory = true, ValueFromPipeline=true, ValueFromPipelineByPropertyName = true)]
|
||||
Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return path;
|
||||
return _path;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
path = value;
|
||||
_path = value;
|
||||
} // set
|
||||
} // Path
|
||||
|
||||
@@ -44,16 +45,16 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return path;
|
||||
return _path;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
base.SuppressWildcardExpansion = true;
|
||||
path = value;
|
||||
_path = value;
|
||||
} // set
|
||||
} // LiteralPath
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The properties to be renamed on the item
|
||||
/// </summary>
|
||||
@@ -64,12 +65,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return property;
|
||||
return _property;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
property = value;
|
||||
_property = value;
|
||||
}
|
||||
} // Property
|
||||
|
||||
@@ -82,12 +83,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return newName;
|
||||
return _newName;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
newName = value;
|
||||
_newName = value;
|
||||
}
|
||||
} // NewName
|
||||
|
||||
@@ -114,7 +115,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
return InvokeProvider.Property.RenamePropertyDynamicParameters(".", Name, NewName, context);
|
||||
} // GetDynamicParameters
|
||||
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
@@ -122,17 +123,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// The path to rename the property on.
|
||||
/// </summary>
|
||||
private string path;
|
||||
private string _path;
|
||||
|
||||
/// <summary>
|
||||
/// The property to be renamed.
|
||||
/// </summary>
|
||||
private string property;
|
||||
private string _property;
|
||||
|
||||
/// <summary>
|
||||
/// The new name of the item.
|
||||
/// </summary>
|
||||
private string newName;
|
||||
private string _newName;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -141,14 +142,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Renames a property on an item.
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
try
|
||||
{
|
||||
CmdletProviderContext currentContext = CmdletProviderContext;
|
||||
currentContext.PassThru = PassThru;
|
||||
|
||||
InvokeProvider.Property.Rename(path, Name, NewName, currentContext);
|
||||
InvokeProvider.Property.Rename(_path, Name, NewName, currentContext);
|
||||
}
|
||||
catch (PSNotSupportedException notSupported)
|
||||
{
|
||||
@@ -178,11 +179,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
pathNotFound.ErrorRecord,
|
||||
pathNotFound));
|
||||
}
|
||||
|
||||
} // ProcessRecord
|
||||
#endregion Command code
|
||||
|
||||
|
||||
} // RenameItemPropertyCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
+15
-15
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -12,12 +13,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// A command to resolve MSH paths containing glob characters to
|
||||
/// MSH paths that match the glob strings.
|
||||
/// </summary>
|
||||
[Cmdlet (VerbsDiagnostic.Resolve, "Path", DefaultParameterSetName = "Path", SupportsTransactions = true,
|
||||
[Cmdlet(VerbsDiagnostic.Resolve, "Path", DefaultParameterSetName = "Path", SupportsTransactions = true,
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113384")]
|
||||
public class ResolvePathCommand : CoreCommandWithCredentialsBase
|
||||
{
|
||||
#region Parameters
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path parameter to the command
|
||||
/// </summary>
|
||||
@@ -27,12 +28,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
paths = value;
|
||||
_paths = value;
|
||||
} // set
|
||||
} // Path
|
||||
|
||||
@@ -46,13 +47,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return paths;
|
||||
return _paths;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
base.SuppressWildcardExpansion = true;
|
||||
paths = value;
|
||||
_paths = value;
|
||||
} // set
|
||||
} // LiteralPath
|
||||
|
||||
@@ -65,25 +66,25 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return relative;
|
||||
return _relative;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
relative = value;
|
||||
_relative = value;
|
||||
} // set
|
||||
} // Relative
|
||||
private SwitchParameter relative;
|
||||
private SwitchParameter _relative;
|
||||
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The path to resolve
|
||||
/// </summary>
|
||||
private string[] paths;
|
||||
private string[] _paths;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -93,7 +94,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Resolves the path containing glob characters to the MSH paths that it
|
||||
/// represents.
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
foreach (string path in Path)
|
||||
{
|
||||
@@ -102,7 +103,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
result = SessionState.Path.GetResolvedPSPathFromPSPath(path, CmdletProviderContext);
|
||||
|
||||
if (relative)
|
||||
if (_relative)
|
||||
{
|
||||
foreach (PathInfo currentPath in result)
|
||||
{
|
||||
@@ -149,7 +150,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!relative)
|
||||
if (!_relative)
|
||||
{
|
||||
WriteObject(result, true);
|
||||
}
|
||||
@@ -159,6 +160,5 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
|
||||
} // ResolvePathCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
+3
-4
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Provider;
|
||||
@@ -17,18 +18,16 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Rolls the current transaction back.
|
||||
/// </summary>
|
||||
protected override void EndProcessing ()
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
// Rollback the transaction
|
||||
if(ShouldProcess(
|
||||
if (ShouldProcess(
|
||||
NavigationResources.TransactionResource,
|
||||
NavigationResources.RollbackAction))
|
||||
{
|
||||
this.Context.TransactionManager.Rollback();
|
||||
}
|
||||
}
|
||||
|
||||
} // RollbackTransactionCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ServiceProcess;
|
||||
@@ -275,15 +276,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return inputObject;
|
||||
return _inputObject;
|
||||
}
|
||||
set
|
||||
{
|
||||
inputObject = value;
|
||||
_inputObject = value;
|
||||
selectionMode = SelectionMode.InputObject;
|
||||
}
|
||||
}
|
||||
private ServiceController[] inputObject = null;
|
||||
private ServiceController[] _inputObject = null;
|
||||
#endregion Parameters
|
||||
|
||||
#region Internal
|
||||
@@ -301,7 +302,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
if (null == allServices)
|
||||
if (null == _allServices)
|
||||
{
|
||||
List<ServiceController> services = new List<ServiceController>();
|
||||
|
||||
@@ -317,12 +318,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
services.AddRange(ServiceController.GetServices());
|
||||
}
|
||||
|
||||
allServices = services.ToArray();
|
||||
_allServices = services.ToArray();
|
||||
}
|
||||
return allServices;
|
||||
return _allServices;
|
||||
}
|
||||
}
|
||||
private ServiceController[] allServices = null;
|
||||
private ServiceController[] _allServices = null;
|
||||
|
||||
private void AddIfValidService(IList<ServiceController> listOfValidServices, string nameOfService, string computerName)
|
||||
{
|
||||
@@ -368,10 +369,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
protected string[] SuppliedComputerName
|
||||
{
|
||||
get { return computerName; }
|
||||
set { computerName = value; }
|
||||
get { return _computerName; }
|
||||
set { _computerName = value; }
|
||||
}
|
||||
private string[] computerName = new string[0];
|
||||
private string[] _computerName = new string[0];
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve the list of all services matching the ServiceName,
|
||||
@@ -392,7 +393,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
default:
|
||||
matchingServices = MatchingServicesByServiceName();
|
||||
break;
|
||||
|
||||
}
|
||||
// 2004/12/16 Note that the services will be sorted
|
||||
// before being stopped. JimTru confirms that this is OK.
|
||||
@@ -657,14 +657,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return dependentservices;
|
||||
return _dependentservices;
|
||||
}
|
||||
set
|
||||
{
|
||||
dependentservices = value;
|
||||
_dependentservices = value;
|
||||
}
|
||||
}
|
||||
private SwitchParameter dependentservices;
|
||||
private SwitchParameter _dependentservices;
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -676,14 +676,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return requiredservices;
|
||||
return _requiredservices;
|
||||
}
|
||||
set
|
||||
{
|
||||
requiredservices = value;
|
||||
_requiredservices = value;
|
||||
}
|
||||
}
|
||||
private SwitchParameter requiredservices;
|
||||
private SwitchParameter _requiredservices;
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
@@ -695,20 +695,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
foreach (ServiceController service in MatchingServices())
|
||||
{
|
||||
if (!dependentservices.IsPresent && !requiredservices.IsPresent)
|
||||
if (!_dependentservices.IsPresent && !_requiredservices.IsPresent)
|
||||
{
|
||||
WriteObject(service);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dependentservices.IsPresent)
|
||||
if (_dependentservices.IsPresent)
|
||||
{
|
||||
foreach (ServiceController dependantserv in service.DependentServices)
|
||||
{
|
||||
WriteObject(dependantserv);
|
||||
}
|
||||
}
|
||||
if (requiredservices.IsPresent)
|
||||
if (_requiredservices.IsPresent)
|
||||
{
|
||||
foreach (ServiceController servdependedon in service.ServicesDependedOn)
|
||||
{
|
||||
@@ -780,14 +780,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return passThru;
|
||||
return _passThru;
|
||||
}
|
||||
set
|
||||
{
|
||||
passThru = value;
|
||||
_passThru = value;
|
||||
}
|
||||
}
|
||||
private SwitchParameter passThru;
|
||||
private SwitchParameter _passThru;
|
||||
#endregion Parameters
|
||||
|
||||
#region Internal
|
||||
@@ -1035,11 +1035,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
RemoveNotStoppedServices(stoppedServices);
|
||||
if((serviceController.Status.Equals(ServiceControllerStatus.Stopped)) || (serviceController.Status.Equals(ServiceControllerStatus.StopPending)))
|
||||
{
|
||||
if ((serviceController.Status.Equals(ServiceControllerStatus.Stopped)) || (serviceController.Status.Equals(ServiceControllerStatus.StopPending)))
|
||||
{
|
||||
stoppedServices.Add(serviceController);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return stoppedServices;
|
||||
}
|
||||
@@ -1087,7 +1087,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns>true iff the service was paused</returns>
|
||||
internal bool DoPauseService(ServiceController serviceController)
|
||||
{
|
||||
|
||||
Exception exception = null;
|
||||
bool serviceNotRunning = false;
|
||||
try
|
||||
@@ -1166,7 +1165,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns>true iff the service was resumed</returns>
|
||||
internal bool DoResumeService(ServiceController serviceController)
|
||||
{
|
||||
|
||||
Exception exception = null;
|
||||
bool serviceNotRunning = false;
|
||||
try
|
||||
@@ -1202,7 +1200,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
"CouldNotResumeServiceNotRunning",
|
||||
ServiceResources.CouldNotResumeServiceNotRunning,
|
||||
ErrorCategory.CloseError);
|
||||
|
||||
}
|
||||
else if (!serviceController.CanPauseAndContinue)
|
||||
{
|
||||
@@ -1263,14 +1260,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return force;
|
||||
return _force;
|
||||
}
|
||||
set
|
||||
{
|
||||
force = value;
|
||||
_force = value;
|
||||
}
|
||||
}
|
||||
private SwitchParameter force;
|
||||
private SwitchParameter _force;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether to wait for a service to reach the stopped state before returning
|
||||
@@ -1280,14 +1277,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return nowait;
|
||||
return _nowait;
|
||||
}
|
||||
set
|
||||
{
|
||||
nowait = value;
|
||||
_nowait = value;
|
||||
}
|
||||
}
|
||||
private SwitchParameter nowait;
|
||||
private SwitchParameter _nowait;
|
||||
|
||||
/// <summary>
|
||||
/// Stop the services.
|
||||
@@ -1436,14 +1433,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return force;
|
||||
return _force;
|
||||
}
|
||||
set
|
||||
{
|
||||
force = value;
|
||||
_force = value;
|
||||
}
|
||||
}
|
||||
private SwitchParameter force;
|
||||
private SwitchParameter _force;
|
||||
|
||||
/// <summary>
|
||||
/// Stop and restart the services.
|
||||
@@ -1509,13 +1506,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public String[] ComputerName
|
||||
{
|
||||
get { return computername; }
|
||||
get { return _computername; }
|
||||
set
|
||||
{
|
||||
computername = value;
|
||||
_computername = value;
|
||||
}
|
||||
}
|
||||
private String[] computername = new string[] { "." };
|
||||
private String[] _computername = new string[] { "." };
|
||||
|
||||
/// <summary>
|
||||
/// service name
|
||||
@@ -1628,13 +1625,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
ParameterSetName = "InputObject")]
|
||||
public new ServiceController InputObject
|
||||
{
|
||||
get { return inputobject; }
|
||||
get { return _inputobject; }
|
||||
set
|
||||
{
|
||||
inputobject = value;
|
||||
_inputobject = value;
|
||||
}
|
||||
}
|
||||
private ServiceController inputobject;
|
||||
private ServiceController _inputobject;
|
||||
|
||||
/// <summary>
|
||||
/// This is not a parameter for this cmdlet.
|
||||
@@ -1680,22 +1677,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
[ArchitectureSensitive]
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
|
||||
ServiceController service = null;
|
||||
string ServiceComputerName = null;
|
||||
foreach (string computer in computername)
|
||||
foreach (string computer in _computername)
|
||||
{
|
||||
bool objServiceShouldBeDisposed = false;
|
||||
try
|
||||
{
|
||||
if (_ParameterSetName.Equals("InputObject", StringComparison.OrdinalIgnoreCase) && inputobject != null)
|
||||
if (_ParameterSetName.Equals("InputObject", StringComparison.OrdinalIgnoreCase) && _inputobject != null)
|
||||
{
|
||||
service = inputobject;
|
||||
service = _inputobject;
|
||||
Name = service.ServiceName;
|
||||
ServiceComputerName = service.MachineName;
|
||||
//computer = service.MachineName;
|
||||
objServiceShouldBeDisposed = false;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1727,7 +1722,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
try // In finally we ensure dispose, if object not pipelined.
|
||||
{
|
||||
|
||||
// confirm the operation first
|
||||
// this is always false if WhatIf is set
|
||||
if (!ShouldProcessServiceOperation(service))
|
||||
@@ -1739,7 +1733,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
NakedWin32Handle hService = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
|
||||
hScManager = NativeMethods.OpenSCManagerW(
|
||||
ServiceComputerName,
|
||||
null,
|
||||
@@ -1867,7 +1860,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
//start service
|
||||
DoStartService(service);
|
||||
}
|
||||
|
||||
}
|
||||
else if (Status.Equals("Stopped", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
@@ -1893,16 +1885,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
//Specify NoWait parameter as always false since we are not adding this switch to this cmdlet
|
||||
DoStopService(service, true, true);
|
||||
}
|
||||
|
||||
}
|
||||
else if (Status.Equals("Paused", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
if (!service.Status.Equals(ServiceControllerStatus.Paused))
|
||||
//pause service
|
||||
DoPauseService(service);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (PassThru.IsPresent)
|
||||
{
|
||||
@@ -1910,7 +1899,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
ServiceController displayservice = new ServiceController(Name, ServiceComputerName);
|
||||
WriteObject(displayservice);
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -1943,7 +1931,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
"CouldNotSetServiceDescription",
|
||||
ServiceResources.CouldNotSetServiceDescription,
|
||||
ErrorCategory.PermissionDenied);
|
||||
|
||||
}
|
||||
}
|
||||
} // finally
|
||||
@@ -2266,9 +2253,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
"CouldNotNewServiceDescription",
|
||||
ServiceResources.CouldNotNewServiceDescription,
|
||||
ErrorCategory.PermissionDenied);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2517,7 +2502,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
public static extern bool QueryInformationJobObject(SafeHandle hJob, int JobObjectInfoClass,
|
||||
ref JOBOBJECT_BASIC_PROCESS_ID_LIST lpJobObjectInfo,
|
||||
int cbJobObjectLength, IntPtr lpReturnLength);
|
||||
|
||||
}
|
||||
#endregion NativeMethods
|
||||
}
|
||||
|
||||
+14
-15
@@ -22,7 +22,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Alias("scb")]
|
||||
public class SetClipboardCommand : PSCmdlet
|
||||
{
|
||||
private List<string> contentList = new List<string>();
|
||||
private List<string> _contentList = new List<string>();
|
||||
private const string ValueParameterSet = "Value";
|
||||
private const string PathParameterSet = "Path";
|
||||
private const string LiteralPathParameterSet = "LiteralPath";
|
||||
@@ -66,22 +66,22 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter]
|
||||
public SwitchParameter AsHtml
|
||||
{
|
||||
get { return asHtml; }
|
||||
get { return _asHtml; }
|
||||
set
|
||||
{
|
||||
isHtmlSet = true;
|
||||
asHtml = value;
|
||||
_isHtmlSet = true;
|
||||
_asHtml = value;
|
||||
}
|
||||
}
|
||||
private bool asHtml;
|
||||
private bool isHtmlSet = false;
|
||||
private bool _asHtml;
|
||||
private bool _isHtmlSet = false;
|
||||
|
||||
/// <summary>
|
||||
/// This method implements the BeginProcessing method for Set-Clipboard command
|
||||
/// </summary>
|
||||
protected override void BeginProcessing()
|
||||
{
|
||||
contentList.Clear();
|
||||
_contentList.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -90,7 +90,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
// Html should only combine with Text content.
|
||||
if (Value == null && isHtmlSet)
|
||||
if (Value == null && _isHtmlSet)
|
||||
{
|
||||
ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(
|
||||
String.Format(CultureInfo.InvariantCulture, ClipboardResources.InvalidHtmlCombine)),
|
||||
@@ -99,15 +99,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (Value != null)
|
||||
{
|
||||
contentList.AddRange(Value);
|
||||
_contentList.AddRange(Value);
|
||||
}
|
||||
else if (Path != null)
|
||||
{
|
||||
contentList.AddRange(Path);
|
||||
_contentList.AddRange(Path);
|
||||
}
|
||||
else if (LiteralPath != null)
|
||||
{
|
||||
contentList.AddRange(LiteralPath);
|
||||
_contentList.AddRange(LiteralPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,15 +118,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (LiteralPath != null)
|
||||
{
|
||||
CopyFilesToClipboard(contentList, Append, true);
|
||||
CopyFilesToClipboard(_contentList, Append, true);
|
||||
}
|
||||
else if (Path != null)
|
||||
{
|
||||
CopyFilesToClipboard(contentList, Append, false);
|
||||
CopyFilesToClipboard(_contentList, Append, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetClipboardContent(contentList, Append, asHtml);
|
||||
SetClipboardContent(_contentList, Append, _asHtml);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,6 +416,5 @@ EndSelection:<<<<<<<<4";
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Internal;
|
||||
@@ -12,7 +13,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// A command to set the content of an item at a specified path
|
||||
/// </summary>
|
||||
[Cmdlet (VerbsCommon.Set, "Content", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
[Cmdlet(VerbsCommon.Set, "Content", DefaultParameterSetName = "Path", SupportsShouldProcess = true, SupportsTransactions = true,
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113392")]
|
||||
public class SetContentCommand : WriteContentCommandBase
|
||||
{
|
||||
@@ -43,7 +44,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
InvokeProvider.Content.Clear(path, context);
|
||||
context.ThrowFirstErrorOrDoNothing(true);
|
||||
|
||||
}
|
||||
catch (PSNotSupportedException)
|
||||
{
|
||||
@@ -72,7 +72,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
//If the item is not found then there is nothing to clear so ignore this exception.
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
} // BeforeOpenStreams
|
||||
|
||||
@@ -98,6 +97,5 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
#endregion protected members
|
||||
} // SetContentCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
+25
-25
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -24,9 +25,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Gets or sets the path parameter to the command
|
||||
/// </summary>
|
||||
[Parameter(Position = 0, ParameterSetName = propertyPSObjectPathSet,
|
||||
[Parameter(Position = 0, ParameterSetName = propertyPSObjectPathSet,
|
||||
Mandatory = true, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position = 0, ParameterSetName = propertyValuePathSet,
|
||||
[Parameter(Position = 0, ParameterSetName = propertyValuePathSet,
|
||||
Mandatory = true, ValueFromPipelineByPropertyName = true)]
|
||||
public string[] Path
|
||||
{
|
||||
@@ -73,24 +74,24 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// This value type is determined by the InvokeProvider.
|
||||
/// </value>
|
||||
///
|
||||
[Parameter(Position=1, ParameterSetName = propertyValuePathSet,
|
||||
Mandatory=true, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position=1, ParameterSetName = propertyValueLiteralPathSet,
|
||||
Mandatory=true, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position = 1, ParameterSetName = propertyValuePathSet,
|
||||
Mandatory = true, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position = 1, ParameterSetName = propertyValueLiteralPathSet,
|
||||
Mandatory = true, ValueFromPipelineByPropertyName = true)]
|
||||
[Alias("PSProperty")]
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return property;
|
||||
return _property;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
property = value;
|
||||
_property = value;
|
||||
}
|
||||
} // Property
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The value of the property to set.
|
||||
@@ -100,21 +101,21 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// This value type is determined by the InvokeProvider.
|
||||
/// </value>
|
||||
///
|
||||
[Parameter(Position=2, ParameterSetName = propertyValuePathSet,
|
||||
Mandatory=true, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position=2, ParameterSetName = propertyValueLiteralPathSet,
|
||||
Mandatory=true, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position = 2, ParameterSetName = propertyValuePathSet,
|
||||
Mandatory = true, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position = 2, ParameterSetName = propertyValueLiteralPathSet,
|
||||
Mandatory = true, ValueFromPipelineByPropertyName = true)]
|
||||
[AllowNull]
|
||||
public object Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return content;
|
||||
return _content;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
content = value;
|
||||
_content = value;
|
||||
}
|
||||
} // Value
|
||||
|
||||
@@ -136,12 +137,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return propertyTable;
|
||||
return _propertyTable;
|
||||
} //get
|
||||
|
||||
set
|
||||
{
|
||||
propertyTable = value;
|
||||
_propertyTable = value;
|
||||
} // set
|
||||
} // PropertyTable
|
||||
#endregion Shell Object set
|
||||
@@ -169,7 +170,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
case propertyValuePathSet:
|
||||
case propertyValueLiteralPathSet:
|
||||
if (! String.IsNullOrEmpty(Name))
|
||||
if (!String.IsNullOrEmpty(Name))
|
||||
{
|
||||
mshObject = new PSObject();
|
||||
mshObject.Properties.Add(new PSNoteProperty(Name, Value));
|
||||
@@ -187,25 +188,25 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
return InvokeProvider.Property.SetPropertyDynamicParameters(".", mshObject, context);
|
||||
} // GetDynamicParameters
|
||||
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The value of the property to be set.
|
||||
/// </summary>
|
||||
private object content;
|
||||
private object _content;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the property to be set.
|
||||
/// </summary>
|
||||
private string property = String.Empty;
|
||||
private string _property = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The properties to be set contained within a PSObject
|
||||
/// </summary>
|
||||
private PSObject propertyTable;
|
||||
private PSObject _propertyTable;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -214,7 +215,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Sets the content of the item at the specified path
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
// Default to the CmdletProviderContext that will direct output to
|
||||
// the pipeline.
|
||||
@@ -287,5 +288,4 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
|
||||
} // SetItemPropertyCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
+27
-26
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Management;
|
||||
@@ -30,8 +31,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(ValueFromPipeline = true, Mandatory = true, ParameterSetName = "object")]
|
||||
public ManagementObject InputObject
|
||||
{
|
||||
get { return this.inputObject; }
|
||||
set { this.inputObject = value; }
|
||||
get { return _inputObject; }
|
||||
set { _inputObject = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The WMI Path to use
|
||||
@@ -39,8 +40,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(ParameterSetName = "path", Mandatory = true)]
|
||||
public string Path
|
||||
{
|
||||
get { return this.path; }
|
||||
set { this.path = value; }
|
||||
get { return _path; }
|
||||
set { _path = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The WMI class to use
|
||||
@@ -48,8 +49,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(Position = 0, Mandatory = true, ParameterSetName = "class")]
|
||||
public string Class
|
||||
{
|
||||
get { return this.className; }
|
||||
set { this.className = value; }
|
||||
get { return _className; }
|
||||
set { _className = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The property name /value pair
|
||||
@@ -61,28 +62,28 @@ namespace Microsoft.PowerShell.Commands
|
||||
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
|
||||
public Hashtable Arguments
|
||||
{
|
||||
get { return this.propertyBag; }
|
||||
set { this.propertyBag = value; }
|
||||
get { return _propertyBag; }
|
||||
set { _propertyBag = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Flag to use
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public PutType PutType
|
||||
public PutType PutType
|
||||
{
|
||||
get { return this.putType; }
|
||||
set { this.putType = value; flagSpecified = true;}
|
||||
get { return _putType; }
|
||||
set { _putType = value; flagSpecified = true; }
|
||||
}
|
||||
|
||||
#endregion Parameters
|
||||
#region parameter data
|
||||
internal bool flagSpecified = false;
|
||||
private string path = null;
|
||||
private string className = null;
|
||||
private ManagementObject inputObject = null;
|
||||
private Hashtable propertyBag = null;
|
||||
private PutType putType = PutType.None;
|
||||
private string _path = null;
|
||||
private string _className = null;
|
||||
private ManagementObject _inputObject = null;
|
||||
private Hashtable _propertyBag = null;
|
||||
private PutType _putType = PutType.None;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -92,12 +93,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
if( this.AsJob )
|
||||
if (this.AsJob)
|
||||
{
|
||||
RunAsJob("Set-WMIInstance");
|
||||
return;
|
||||
}
|
||||
if (inputObject != null)
|
||||
if (_inputObject != null)
|
||||
{
|
||||
object result = null;
|
||||
ManagementObject mObj = null;
|
||||
@@ -105,10 +106,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
PutOptions pOptions = new PutOptions();
|
||||
mObj = SetWmiInstanceGetPipelineObject();
|
||||
pOptions.Type = putType;
|
||||
if( mObj != null)
|
||||
pOptions.Type = _putType;
|
||||
if (mObj != null)
|
||||
{
|
||||
if (!ShouldProcess(mObj.Path.Path.ToString()) )
|
||||
if (!ShouldProcess(mObj.Path.Path.ToString()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -139,7 +140,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
//If Class is specified only CreateOnly flag is supported
|
||||
mPath = this.SetWmiInstanceBuildManagementPath();
|
||||
//If server name is specified loop through it.
|
||||
if( mPath != null)
|
||||
if (mPath != null)
|
||||
{
|
||||
if (!(mPath.Server == "." && serverNameSpecified))
|
||||
{
|
||||
@@ -155,12 +156,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
result = null;
|
||||
try
|
||||
{
|
||||
mObject = this.SetWmiInstanceGetObject(mPath,name);
|
||||
mObject = this.SetWmiInstanceGetObject(mPath, name);
|
||||
PutOptions pOptions = new PutOptions();
|
||||
pOptions.Type = putType;
|
||||
if( mObject != null)
|
||||
pOptions.Type = _putType;
|
||||
if (mObject != null)
|
||||
{
|
||||
if (!ShouldProcess(mObject.Path.Path.ToString()) )
|
||||
if (!ShouldProcess(mObject.Path.Path.ToString()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
+26
-27
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using Dbg = System.Management.Automation;
|
||||
@@ -23,22 +24,22 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int) timeout.TotalMinutes;
|
||||
return (int)_timeout.TotalMinutes;
|
||||
}
|
||||
set
|
||||
{
|
||||
// The transactions constructor treats a timeout of
|
||||
// zero as infinite. So we fudge it to be a bit longer.
|
||||
if(value == 0)
|
||||
timeout = TimeSpan.FromTicks(1);
|
||||
if (value == 0)
|
||||
_timeout = TimeSpan.FromTicks(1);
|
||||
else
|
||||
timeout = TimeSpan.FromMinutes(value);
|
||||
|
||||
timeoutSpecified = true;
|
||||
_timeout = TimeSpan.FromMinutes(value);
|
||||
|
||||
_timeoutSpecified = true;
|
||||
}
|
||||
}
|
||||
bool timeoutSpecified = false;
|
||||
private TimeSpan timeout = TimeSpan.MinValue;
|
||||
private bool _timeoutSpecified = false;
|
||||
private TimeSpan _timeout = TimeSpan.MinValue;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the flag to determine if this transaction can
|
||||
@@ -47,10 +48,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter()]
|
||||
public SwitchParameter Independent
|
||||
{
|
||||
get { return independent; }
|
||||
set { independent = value; }
|
||||
get { return _independent; }
|
||||
set { _independent = value; }
|
||||
}
|
||||
private SwitchParameter independent;
|
||||
private SwitchParameter _independent;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the rollback preference for this transaction.
|
||||
@@ -58,48 +59,46 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter()]
|
||||
public RollbackSeverity RollbackPreference
|
||||
{
|
||||
get { return rollbackPreference; }
|
||||
set { rollbackPreference = value; }
|
||||
get { return _rollbackPreference; }
|
||||
set { _rollbackPreference = value; }
|
||||
}
|
||||
private RollbackSeverity rollbackPreference = RollbackSeverity.Error;
|
||||
|
||||
private RollbackSeverity _rollbackPreference = RollbackSeverity.Error;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new transaction.
|
||||
/// </summary>
|
||||
protected override void EndProcessing ()
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
if(ShouldProcess(
|
||||
if (ShouldProcess(
|
||||
NavigationResources.TransactionResource,
|
||||
NavigationResources.CreateAction))
|
||||
{
|
||||
// Set the default timeout
|
||||
if(! timeoutSpecified)
|
||||
if (!_timeoutSpecified)
|
||||
{
|
||||
// See if we're being invoked directly at the
|
||||
// command line. In that case, set the timeout to infinite.
|
||||
if(MyInvocation.CommandOrigin == CommandOrigin.Runspace)
|
||||
if (MyInvocation.CommandOrigin == CommandOrigin.Runspace)
|
||||
{
|
||||
timeout = TimeSpan.MaxValue;
|
||||
_timeout = TimeSpan.MaxValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
timeout = TimeSpan.FromMinutes(30);
|
||||
_timeout = TimeSpan.FromMinutes(30);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Create the new transaction
|
||||
if(independent)
|
||||
if (_independent)
|
||||
{
|
||||
this.Context.TransactionManager.CreateNew(rollbackPreference, timeout);
|
||||
this.Context.TransactionManager.CreateNew(_rollbackPreference, _timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Context.TransactionManager.CreateOrJoin(rollbackPreference, timeout);
|
||||
this.Context.TransactionManager.CreateOrJoin(_rollbackPreference, _timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // StartTransactionCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
+21
-21
@@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Alias("gtz")]
|
||||
public class GetTimeZoneCommand : PSCmdlet
|
||||
{
|
||||
#region Parameters
|
||||
#region Parameters
|
||||
|
||||
/// <summary>
|
||||
/// A list of the local time zone ids that the cmdlet should look up.
|
||||
@@ -42,7 +42,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public string[] Name { get; set; }
|
||||
|
||||
#endregion Parameters
|
||||
#endregion Parameters
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of the ProcessRecord method for Get-TimeZone
|
||||
@@ -131,18 +131,18 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
[Cmdlet(VerbsCommon.Set, "TimeZone",
|
||||
SupportsShouldProcess = true,
|
||||
DefaultParameterSetName = "Name",
|
||||
DefaultParameterSetName = "Name",
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkId=799469")]
|
||||
[Alias("stz")]
|
||||
public class SetTimeZoneCommand : PSCmdlet
|
||||
{
|
||||
#region string constants
|
||||
#region string constants
|
||||
|
||||
private const string TimeZoneTarget = "Local System";
|
||||
|
||||
#endregion string constants
|
||||
#endregion string constants
|
||||
|
||||
#region Parameters
|
||||
#region Parameters
|
||||
|
||||
/// <summary>
|
||||
/// The name of the local time zone that the system should use.
|
||||
@@ -168,7 +168,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter]
|
||||
public SwitchParameter PassThru { get; set; }
|
||||
|
||||
#endregion Parameters
|
||||
#endregion Parameters
|
||||
|
||||
/// <summary>
|
||||
/// Implementation of the ProcessRecord method for Get-TimeZone
|
||||
@@ -357,7 +357,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
|
||||
#region Helper functions
|
||||
#region Helper functions
|
||||
|
||||
/// <summary>
|
||||
/// True if the current process has access to change the time zone setting.
|
||||
@@ -461,9 +461,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
throw new Win32Exception(error);
|
||||
}
|
||||
|
||||
#endregion Helper functions
|
||||
#endregion Helper functions
|
||||
|
||||
#region Win32 interop helper
|
||||
#region Win32 interop helper
|
||||
|
||||
internal class NativeMethods
|
||||
{
|
||||
@@ -474,7 +474,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
}
|
||||
|
||||
#region Native DLL locations
|
||||
#region Native DLL locations
|
||||
|
||||
#if CORECLR
|
||||
private const string SetDynamicTimeZoneApiDllName = "api-ms-win-core-timezone-l1-1-0.dll";
|
||||
@@ -498,9 +498,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
private const string SendMessageTimeoutApiDllName = "user32.dll";
|
||||
#endif
|
||||
|
||||
#endregion Native DLL locations
|
||||
#endregion Native DLL locations
|
||||
|
||||
#region Win32 SetDynamicTimeZoneInformation imports
|
||||
#region Win32 SetDynamicTimeZoneInformation imports
|
||||
|
||||
/// <summary>
|
||||
/// Used to marshal win32 SystemTime structure to managed code layer
|
||||
@@ -653,9 +653,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
[DllImport(GetTimeZoneInformationForYearApiDllName, SetLastError = true)]
|
||||
public static extern bool GetTimeZoneInformationForYear([In] ushort wYear, [In] ref DYNAMIC_TIME_ZONE_INFORMATION pdtzi, ref TIME_ZONE_INFORMATION ptzi);
|
||||
|
||||
#endregion Win32 SetDynamicTimeZoneInformation imports
|
||||
#endregion Win32 SetDynamicTimeZoneInformation imports
|
||||
|
||||
#region Win32 AdjustTokenPrivilege imports
|
||||
#region Win32 AdjustTokenPrivilege imports
|
||||
|
||||
/// <summary>
|
||||
/// Definition of TOKEN_QUERY constant from Win32 API
|
||||
@@ -765,9 +765,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
public int Attributes;
|
||||
}
|
||||
|
||||
#endregion Win32 AdjustTokenPrivilege imports
|
||||
#endregion Win32 AdjustTokenPrivilege imports
|
||||
|
||||
#region Win32 SendMessage imports
|
||||
#region Win32 SendMessage imports
|
||||
|
||||
/// <summary>
|
||||
/// Definition of WM_SETTINGCHANGE constant from Win32 API
|
||||
@@ -798,10 +798,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
[DllImport(SendMessageTimeoutApiDllName, SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
public static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, string lParam, int fuFlags, int uTimeout, ref int lpdwResult);
|
||||
|
||||
#endregion Win32 SendMessage imports
|
||||
#endregion Win32 SendMessage imports
|
||||
}
|
||||
|
||||
#endregion Win32 interop helper
|
||||
#endregion Win32 interop helper
|
||||
}
|
||||
|
||||
|
||||
@@ -810,14 +810,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
internal static class TimeZoneHelper
|
||||
{
|
||||
#region Error Ids
|
||||
#region Error Ids
|
||||
|
||||
internal const string TimeZoneNotFoundError = "TimeZoneNotFound";
|
||||
internal const string MultipleMatchingTimeZonesError = "MultipleMatchingTimeZones";
|
||||
internal const string InsufficientPermissionsError = "InsufficientPermissions";
|
||||
internal const string SetTimeZoneFailedError = "SetTimeZoneFailed";
|
||||
|
||||
#endregion Error Ids
|
||||
#endregion Error Ids
|
||||
|
||||
/// <summary>
|
||||
/// Clear the cached TimeZoneInfo data. Note that since TimeZoneInfo.ClearCachedData
|
||||
|
||||
+18
-19
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Internal;
|
||||
@@ -24,35 +25,35 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return transactedScript;
|
||||
return _transactedScript;
|
||||
}
|
||||
set
|
||||
{
|
||||
transactedScript = value;
|
||||
_transactedScript = value;
|
||||
}
|
||||
}
|
||||
private ScriptBlock transactedScript;
|
||||
private ScriptBlock _transactedScript;
|
||||
|
||||
/// <summary>
|
||||
/// Commits the current transaction
|
||||
/// </summary>
|
||||
protected override void EndProcessing ()
|
||||
protected override void EndProcessing()
|
||||
{
|
||||
using(CurrentPSTransaction)
|
||||
using (CurrentPSTransaction)
|
||||
{
|
||||
try
|
||||
{
|
||||
var emptyArray = Utils.EmptyArray<object>();
|
||||
transactedScript.InvokeUsingCmdlet(
|
||||
contextCmdlet: this,
|
||||
useLocalScope: false,
|
||||
errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe,
|
||||
dollarUnder: null,
|
||||
input: emptyArray,
|
||||
scriptThis: AutomationNull.Value,
|
||||
args: emptyArray);
|
||||
_transactedScript.InvokeUsingCmdlet(
|
||||
contextCmdlet: this,
|
||||
useLocalScope: false,
|
||||
errorHandlingBehavior: ScriptBlock.ErrorHandlingBehavior.WriteToCurrentErrorPipe,
|
||||
dollarUnder: null,
|
||||
input: emptyArray,
|
||||
scriptThis: AutomationNull.Value,
|
||||
args: emptyArray);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
// Catch-all OK. This is a third-party call-out.
|
||||
CommandProcessorBase.CheckForSevereException(e);
|
||||
@@ -63,9 +64,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
// exceedingly obtuse. We clarify things here.
|
||||
bool isTimeoutException = false;
|
||||
Exception tempException = e;
|
||||
while(tempException != null)
|
||||
while (tempException != null)
|
||||
{
|
||||
if(tempException is System.TimeoutException)
|
||||
if (tempException is System.TimeoutException)
|
||||
{
|
||||
isTimeoutException = true;
|
||||
break;
|
||||
@@ -74,7 +75,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
tempException = tempException.InnerException;
|
||||
}
|
||||
|
||||
if(isTimeoutException)
|
||||
if (isTimeoutException)
|
||||
{
|
||||
errorRecord = new ErrorRecord(
|
||||
new InvalidOperationException(
|
||||
@@ -88,8 +89,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // CommitTransactionCommand
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
+30
-36
@@ -25,12 +25,11 @@ using Dbg = System.Management.Automation;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Resources;
|
||||
using Microsoft.Win32;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
|
||||
namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
|
||||
#region New-WebServiceProxy
|
||||
|
||||
/// <summary>
|
||||
@@ -129,23 +128,23 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Cache for storing URIs.
|
||||
/// </summary>
|
||||
private static Dictionary<Uri, string> UriCache = new Dictionary<Uri, string>();
|
||||
private static Dictionary<Uri, string> s_uriCache = new Dictionary<Uri, string>();
|
||||
|
||||
/// <summary>
|
||||
/// Cache for storing sourcecodehashes.
|
||||
/// </summary>
|
||||
private static Dictionary<int, object> srccodeCache = new Dictionary<int, object>();
|
||||
private static Dictionary<int, object> s_srccodeCache = new Dictionary<int, object>();
|
||||
|
||||
/// <summary>
|
||||
/// holds the hash code of the source generated.
|
||||
/// </summary>
|
||||
private int sourceHash;
|
||||
private int _sourceHash;
|
||||
/// <summary>
|
||||
/// Random class
|
||||
/// </summary>
|
||||
|
||||
private object cachelock = new object();
|
||||
private static Random rnd = new Random();
|
||||
private object _cachelock = new object();
|
||||
private static Random s_rnd = new Random();
|
||||
/// <summary>
|
||||
/// BeginProcessing code
|
||||
/// </summary>
|
||||
@@ -169,16 +168,16 @@ namespace Microsoft.PowerShell.Commands
|
||||
er.ErrorDetails = new ErrorDetails(WebServiceResources.NotSupported);
|
||||
ThrowTerminatingError(er);
|
||||
}
|
||||
|
||||
|
||||
int sourceCache = 0;
|
||||
|
||||
lock (UriCache)
|
||||
lock (s_uriCache)
|
||||
{
|
||||
if (UriCache.ContainsKey(_uri))
|
||||
if (s_uriCache.ContainsKey(_uri))
|
||||
{
|
||||
//if uri is present in the cache
|
||||
string ns;
|
||||
UriCache.TryGetValue(_uri, out ns);
|
||||
s_uriCache.TryGetValue(_uri, out ns);
|
||||
string[] data = ns.Split('|');
|
||||
if (string.IsNullOrEmpty(_namespace))
|
||||
{
|
||||
@@ -230,25 +229,25 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
//disposing the entries in a cache
|
||||
//Adding to Cache
|
||||
lock (UriCache)
|
||||
lock (s_uriCache)
|
||||
{
|
||||
UriCache.Remove(_uri);
|
||||
s_uriCache.Remove(_uri);
|
||||
}
|
||||
if (sourceCache > 0)
|
||||
{
|
||||
lock (cachelock)
|
||||
lock (_cachelock)
|
||||
{
|
||||
srccodeCache.Remove(sourceCache);
|
||||
s_srccodeCache.Remove(sourceCache);
|
||||
}
|
||||
}
|
||||
string key = string.Join("|", new string[] { _namespace, _class, sourceHash.ToString(System.Globalization.CultureInfo.InvariantCulture) });
|
||||
lock (UriCache)
|
||||
string key = string.Join("|", new string[] { _namespace, _class, _sourceHash.ToString(System.Globalization.CultureInfo.InvariantCulture) });
|
||||
lock (s_uriCache)
|
||||
{
|
||||
UriCache.Add(_uri, key);
|
||||
s_uriCache.Add(_uri, key);
|
||||
}
|
||||
lock (cachelock)
|
||||
lock (_cachelock)
|
||||
{
|
||||
srccodeCache.Add(sourceHash, instance);
|
||||
s_srccodeCache.Add(_sourceHash, instance);
|
||||
}
|
||||
|
||||
WriteObject(instance, true);
|
||||
@@ -258,8 +257,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
#region private
|
||||
|
||||
private static ulong sequenceNumber = 1;
|
||||
private static object sequenceNumberLock = new object();
|
||||
private static ulong s_sequenceNumber = 1;
|
||||
private static object s_sequenceNumberLock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Generates a random name
|
||||
@@ -267,7 +266,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns>string </returns>
|
||||
private string GenerateRandomName()
|
||||
{
|
||||
|
||||
string rndname = null;
|
||||
string givenuri = _uri.ToString();
|
||||
for (int i = 0; i < givenuri.Length; i++)
|
||||
@@ -284,9 +282,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
string sequenceString;
|
||||
lock (sequenceNumberLock)
|
||||
lock (s_sequenceNumberLock)
|
||||
{
|
||||
sequenceString = (sequenceNumber++).ToString(CultureInfo.InvariantCulture);
|
||||
sequenceString = (s_sequenceNumber++).ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
if (rndname.Length > 30)
|
||||
@@ -294,7 +292,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
return (sequenceString + rndname.Substring(rndname.Length - 30));
|
||||
}
|
||||
return (sequenceString + rndname);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -380,14 +377,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
WriteError(er);
|
||||
}
|
||||
//generate the hashcode of the CodeCompileUnit
|
||||
sourceHash = codegenerator.ToString().GetHashCode();
|
||||
_sourceHash = codegenerator.ToString().GetHashCode();
|
||||
|
||||
//if the sourcehash matches the hashcode in the cache,the proxy hasnt changed and so
|
||||
// return the instance of th eproxy in the cache
|
||||
if (srccodeCache.ContainsKey(sourceHash))
|
||||
if (s_srccodeCache.ContainsKey(_sourceHash))
|
||||
{
|
||||
object obj;
|
||||
srccodeCache.TryGetValue(sourceHash, out obj);
|
||||
s_srccodeCache.TryGetValue(_sourceHash, out obj);
|
||||
WriteObject(obj, true);
|
||||
return null;
|
||||
}
|
||||
@@ -421,7 +418,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
return results.CompiledAssembly;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -458,22 +454,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
Object[] obj = type.GetCustomAttributes(typeof(WebServiceBindingAttribute), false);
|
||||
if (obj.Length > 0)
|
||||
{
|
||||
proxyType = type;
|
||||
break;
|
||||
}
|
||||
proxyType = type;
|
||||
break;
|
||||
}
|
||||
if (proxyType != null) break;
|
||||
}
|
||||
|
||||
System.Management.Automation.Diagnostics.Assert(
|
||||
proxyType != null,
|
||||
proxyType != null,
|
||||
"Proxy class should always get generated unless there were some errors earlier (in that case we shouldn't get here)");
|
||||
|
||||
return assembly.CreateInstance(proxyType.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}//end class
|
||||
#endregion
|
||||
|
||||
}//Microsoft.Powershell.commands
|
||||
+25
-26
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -17,7 +18,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
public class WriteContentCommandBase : PassThroughContentCommandBase
|
||||
{
|
||||
#region Parameters
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The value of the content to set.
|
||||
/// </summary>
|
||||
@@ -26,30 +27,30 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// This value type is determined by the InvokeProvider.
|
||||
/// </value>
|
||||
///
|
||||
[Parameter (Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Mandatory = true, Position = 1, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
|
||||
[AllowNull]
|
||||
[AllowEmptyCollection]
|
||||
public object[] Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return content;
|
||||
return _content;
|
||||
} // get
|
||||
|
||||
set
|
||||
{
|
||||
content = value;
|
||||
_content = value;
|
||||
}
|
||||
} // Value
|
||||
|
||||
#endregion Parameters
|
||||
|
||||
#region parameter data
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The value of the content to be set.
|
||||
/// </summary>
|
||||
private object[] content;
|
||||
private object[] _content;
|
||||
|
||||
#endregion parameter data
|
||||
|
||||
@@ -60,7 +61,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// parameter was specified on the command line or via the pipeline.
|
||||
/// </summary>
|
||||
///
|
||||
bool pipingPaths;
|
||||
private bool _pipingPaths;
|
||||
|
||||
/// <summary>
|
||||
/// True if the content writers have been open.
|
||||
@@ -68,7 +69,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// to determine if the content writers need to
|
||||
/// be closed each time ProgressRecord is called.
|
||||
/// </summary>
|
||||
bool contentWritersOpen;
|
||||
private bool _contentWritersOpen;
|
||||
|
||||
#endregion private Data
|
||||
|
||||
@@ -82,41 +83,41 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (Path != null && Path.Length > 0)
|
||||
{
|
||||
pipingPaths = false;
|
||||
_pipingPaths = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
pipingPaths = true;
|
||||
_pipingPaths = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Appends the content to the specified item.
|
||||
/// </summary>
|
||||
protected override void ProcessRecord ()
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
CmdletProviderContext currentContext = GetCurrentContext();
|
||||
|
||||
// Initialize the content
|
||||
|
||||
if (content == null)
|
||||
|
||||
if (_content == null)
|
||||
{
|
||||
content = new object[0];
|
||||
_content = new object[0];
|
||||
}
|
||||
|
||||
if (pipingPaths)
|
||||
if (_pipingPaths)
|
||||
{
|
||||
// Make sure to clean up the content writers that are already there
|
||||
|
||||
if (contentStreams != null && contentStreams.Count > 0)
|
||||
{
|
||||
CloseContent(contentStreams, false);
|
||||
contentWritersOpen = false;
|
||||
_contentWritersOpen = false;
|
||||
contentStreams = new List<ContentHolder>();
|
||||
}
|
||||
}
|
||||
|
||||
if (!contentWritersOpen)
|
||||
if (!_contentWritersOpen)
|
||||
{
|
||||
// Since the paths are being pipelined in, we have
|
||||
// to get new content writers for the new paths
|
||||
@@ -129,7 +130,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
SeekContentPosition(contentStreams);
|
||||
}
|
||||
|
||||
contentWritersOpen = true;
|
||||
_contentWritersOpen = true;
|
||||
}
|
||||
|
||||
// Now write the content to the item
|
||||
@@ -142,7 +143,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
IList result = null;
|
||||
try
|
||||
{
|
||||
result = holder.Writer.Write(content);
|
||||
result = holder.Writer.Write(_content);
|
||||
}
|
||||
catch (Exception e) // Catch-all OK. 3rd party callout
|
||||
{
|
||||
@@ -177,14 +178,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
finally
|
||||
{
|
||||
// Need to close all the writers if the paths are being pipelined
|
||||
|
||||
if (pipingPaths)
|
||||
if (_pipingPaths)
|
||||
{
|
||||
CloseContent(contentStreams, false);
|
||||
contentWritersOpen = false;
|
||||
_contentWritersOpen = false;
|
||||
contentStreams = new List<ContentHolder>();
|
||||
}
|
||||
}
|
||||
@@ -355,11 +356,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
|
||||
return (string[]) paths.ToArray(typeof(String));
|
||||
return (string[])paths.ToArray(typeof(String));
|
||||
}
|
||||
|
||||
|
||||
#endregion protected members
|
||||
|
||||
} // WriteContentCommandBase
|
||||
|
||||
} // namespace Microsoft.PowerShell.Commands
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
|
||||
[assembly:AssemblyFileVersionAttribute("3.0.0.0")]
|
||||
[assembly:AssemblyVersion("3.0.0.0")]
|
||||
[assembly: AssemblyFileVersionAttribute("3.0.0.0")]
|
||||
[assembly: AssemblyVersion("3.0.0.0")]
|
||||
|
||||
[assembly:AssemblyCulture("")]
|
||||
[assembly:NeutralResourcesLanguage("en-US")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: NeutralResourcesLanguage("en-US")]
|
||||
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -21,13 +22,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
HelpUri = "http://go.microsoft.com/fwlink/?LinkID=113280", RemotingCapability = RemotingCapability.None)]
|
||||
public class AddMemberCommand : PSCmdlet
|
||||
{
|
||||
private static object notSpecified = new object();
|
||||
private static object s_notSpecified = new object();
|
||||
private static bool HasBeenSpecified(object obj)
|
||||
{
|
||||
return !System.Object.ReferenceEquals(obj, notSpecified);
|
||||
return !System.Object.ReferenceEquals(obj, s_notSpecified);
|
||||
}
|
||||
|
||||
private PSObject inputObject;
|
||||
private PSObject _inputObject;
|
||||
/// <summary>
|
||||
/// The object to add a member to
|
||||
/// </summary>
|
||||
@@ -37,11 +38,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = NotePropertyMultiMemberSet)]
|
||||
public PSObject InputObject
|
||||
{
|
||||
set { inputObject = value; }
|
||||
get { return inputObject; }
|
||||
set { _inputObject = value; }
|
||||
get { return _inputObject; }
|
||||
}
|
||||
|
||||
PSMemberTypes memberType;
|
||||
|
||||
private PSMemberTypes _memberType;
|
||||
/// <summary>
|
||||
/// The member type of to be added
|
||||
/// </summary>
|
||||
@@ -49,22 +50,22 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Alias("Type")]
|
||||
public PSMemberTypes MemberType
|
||||
{
|
||||
set { memberType = value; }
|
||||
get { return memberType; }
|
||||
set { _memberType = value; }
|
||||
get { return _memberType; }
|
||||
}
|
||||
|
||||
string memberName;
|
||||
private string _memberName;
|
||||
/// <summary>
|
||||
/// The name of the new member
|
||||
/// </summary>
|
||||
[Parameter(Mandatory = true, Position = 1, ParameterSetName = "MemberSet")]
|
||||
public string Name
|
||||
{
|
||||
set { memberName = value; }
|
||||
get { return memberName; }
|
||||
set { _memberName = value; }
|
||||
get { return _memberName; }
|
||||
}
|
||||
|
||||
private object value1 = notSpecified;
|
||||
private object _value1 = s_notSpecified;
|
||||
/// <summary>
|
||||
/// First value of the new member. The meaning of this value
|
||||
/// changes according to the member type.
|
||||
@@ -72,11 +73,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(Position = 2, ParameterSetName = "MemberSet")]
|
||||
public object Value
|
||||
{
|
||||
set { value1 = value; }
|
||||
get { return value1; }
|
||||
set { _value1 = value; }
|
||||
get { return _value1; }
|
||||
}
|
||||
|
||||
private object value2 = notSpecified;
|
||||
private object _value2 = s_notSpecified;
|
||||
/// <summary>
|
||||
/// Second value of the new member. The meaning of this value
|
||||
/// changes according to the member type.
|
||||
@@ -84,11 +85,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(Position = 3, ParameterSetName = "MemberSet")]
|
||||
public object SecondValue
|
||||
{
|
||||
set { value2 = value; }
|
||||
get { return value2; }
|
||||
set { _value2 = value; }
|
||||
get { return _value2; }
|
||||
}
|
||||
|
||||
private string typeName;
|
||||
private string _typeName;
|
||||
/// <summary>
|
||||
/// Add new type name to the specified object for TypeNameSet
|
||||
/// </summary>
|
||||
@@ -99,11 +100,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
[ValidateNotNullOrEmpty]
|
||||
public string TypeName
|
||||
{
|
||||
set { typeName = value; }
|
||||
get { return typeName; }
|
||||
set { _typeName = value; }
|
||||
get { return _typeName; }
|
||||
}
|
||||
|
||||
private bool force;
|
||||
private bool _force;
|
||||
/// <summary>
|
||||
/// True if we should overwrite a possibly existing member
|
||||
/// </summary>
|
||||
@@ -112,11 +113,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(ParameterSetName = NotePropertyMultiMemberSet)]
|
||||
public SwitchParameter Force
|
||||
{
|
||||
set { force = value; }
|
||||
get { return force; }
|
||||
set { _force = value; }
|
||||
get { return _force; }
|
||||
}
|
||||
|
||||
private bool passThru /* = false */;
|
||||
private bool _passThru /* = false */;
|
||||
/// <summary>
|
||||
/// Gets or sets the parameter -passThru which states output from
|
||||
/// the command should be placed in the pipeline.
|
||||
@@ -127,8 +128,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(ParameterSetName = NotePropertyMultiMemberSet)]
|
||||
public SwitchParameter PassThru
|
||||
{
|
||||
set { passThru = value; }
|
||||
get { return passThru; }
|
||||
set { _passThru = value; }
|
||||
get { return _passThru; }
|
||||
}
|
||||
|
||||
|
||||
@@ -187,49 +188,49 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private void EnsureValue1AndValue2AreNotBothNull()
|
||||
{
|
||||
if (value1 == null &&
|
||||
(value2 == null || !HasBeenSpecified(value2)))
|
||||
if (_value1 == null &&
|
||||
(_value2 == null || !HasBeenSpecified(_value2)))
|
||||
{
|
||||
ThrowTerminatingError(NewError("Value1AndValue2AreNotBothNull", "Value1AndValue2AreNotBothNull", null, this.memberType));
|
||||
ThrowTerminatingError(NewError("Value1AndValue2AreNotBothNull", "Value1AndValue2AreNotBothNull", null, _memberType));
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureValue1IsNotNull()
|
||||
{
|
||||
if (value1 == null)
|
||||
if (_value1 == null)
|
||||
{
|
||||
ThrowTerminatingError(NewError("Value1ShouldNotBeNull", "Value1ShouldNotBeNull", null, this.memberType));
|
||||
ThrowTerminatingError(NewError("Value1ShouldNotBeNull", "Value1ShouldNotBeNull", null, _memberType));
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureValue2IsNotNull()
|
||||
{
|
||||
if (value2 == null)
|
||||
if (_value2 == null)
|
||||
{
|
||||
ThrowTerminatingError(NewError("Value2ShouldNotBeNull", "Value2ShouldNotBeNull", null, this.memberType));
|
||||
ThrowTerminatingError(NewError("Value2ShouldNotBeNull", "Value2ShouldNotBeNull", null, _memberType));
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureValue1HasBeenSpecified()
|
||||
{
|
||||
if (!HasBeenSpecified(this.value1))
|
||||
if (!HasBeenSpecified(_value1))
|
||||
{
|
||||
Collection<FieldDescription> fdc = new Collection<FieldDescription>();
|
||||
fdc.Add(new FieldDescription("Value"));
|
||||
string prompt = StringUtil.Format(AddMember.Value1Prompt, this.memberType);
|
||||
string prompt = StringUtil.Format(AddMember.Value1Prompt, _memberType);
|
||||
Dictionary<string, PSObject> result = this.Host.UI.Prompt(prompt, null, fdc);
|
||||
if (result != null)
|
||||
{
|
||||
this.value1 = result["Value"].BaseObject;
|
||||
_value1 = result["Value"].BaseObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureValue2HasNotBeenSpecified()
|
||||
{
|
||||
if (HasBeenSpecified(this.value2))
|
||||
if (HasBeenSpecified(_value2))
|
||||
{
|
||||
ThrowTerminatingError(NewError("Value2ShouldNotBeSpecified", "Value2ShouldNotBeSpecified", null, this.memberType));
|
||||
ThrowTerminatingError(NewError("Value2ShouldNotBeSpecified", "Value2ShouldNotBeSpecified", null, _memberType));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,14 +239,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
EnsureValue1HasBeenSpecified();
|
||||
EnsureValue1IsNotNull();
|
||||
|
||||
string value1Str = (string)GetParameterType(value1, typeof(string));
|
||||
if (HasBeenSpecified(this.value2))
|
||||
string value1Str = (string)GetParameterType(_value1, typeof(string));
|
||||
if (HasBeenSpecified(_value2))
|
||||
{
|
||||
EnsureValue2IsNotNull();
|
||||
Type value2Type = (Type)GetParameterType(value2, typeof(Type));
|
||||
return new PSAliasProperty(this.memberName, value1Str, value2Type);
|
||||
Type value2Type = (Type)GetParameterType(_value2, typeof(Type));
|
||||
return new PSAliasProperty(_memberName, value1Str, value2Type);
|
||||
}
|
||||
return new PSAliasProperty(this.memberName, value1Str);
|
||||
return new PSAliasProperty(_memberName, value1Str);
|
||||
}
|
||||
|
||||
private PSMemberInfo GetCodeMethod()
|
||||
@@ -253,8 +254,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
EnsureValue1HasBeenSpecified();
|
||||
EnsureValue1IsNotNull();
|
||||
EnsureValue2HasNotBeenSpecified();
|
||||
MethodInfo value1MethodInfo = (MethodInfo)GetParameterType(value1, typeof(MethodInfo));
|
||||
return new PSCodeMethod(this.memberName, value1MethodInfo);
|
||||
MethodInfo value1MethodInfo = (MethodInfo)GetParameterType(_value1, typeof(MethodInfo));
|
||||
return new PSCodeMethod(_memberName, value1MethodInfo);
|
||||
}
|
||||
|
||||
private PSMemberInfo GetCodeProperty()
|
||||
@@ -263,35 +264,35 @@ namespace Microsoft.PowerShell.Commands
|
||||
EnsureValue1AndValue2AreNotBothNull();
|
||||
|
||||
MethodInfo value1MethodInfo = null;
|
||||
if (HasBeenSpecified(this.value1))
|
||||
if (HasBeenSpecified(_value1))
|
||||
{
|
||||
value1MethodInfo = (MethodInfo)GetParameterType(value1, typeof(MethodInfo));
|
||||
value1MethodInfo = (MethodInfo)GetParameterType(_value1, typeof(MethodInfo));
|
||||
}
|
||||
MethodInfo value2MethodInfo = null;
|
||||
if (HasBeenSpecified(this.value2))
|
||||
if (HasBeenSpecified(_value2))
|
||||
{
|
||||
value2MethodInfo = (MethodInfo)GetParameterType(value2, typeof(MethodInfo));
|
||||
value2MethodInfo = (MethodInfo)GetParameterType(_value2, typeof(MethodInfo));
|
||||
}
|
||||
return new PSCodeProperty(this.memberName, value1MethodInfo, value2MethodInfo);
|
||||
return new PSCodeProperty(_memberName, value1MethodInfo, value2MethodInfo);
|
||||
}
|
||||
|
||||
private PSMemberInfo GetMemberSet()
|
||||
{
|
||||
EnsureValue2HasNotBeenSpecified();
|
||||
if (value1 == null || !HasBeenSpecified(this.value1))
|
||||
if (_value1 == null || !HasBeenSpecified(_value1))
|
||||
{
|
||||
return new PSMemberSet(this.memberName);
|
||||
return new PSMemberSet(_memberName);
|
||||
}
|
||||
Collection<PSMemberInfo> value1Collection =
|
||||
(Collection<PSMemberInfo>)GetParameterType(value1, typeof(Collection<PSMemberInfo>));
|
||||
return new PSMemberSet(this.memberName, value1Collection);
|
||||
Collection<PSMemberInfo> value1Collection =
|
||||
(Collection<PSMemberInfo>)GetParameterType(_value1, typeof(Collection<PSMemberInfo>));
|
||||
return new PSMemberSet(_memberName, value1Collection);
|
||||
}
|
||||
|
||||
private PSMemberInfo GetNoteProperty()
|
||||
{
|
||||
EnsureValue1HasBeenSpecified();
|
||||
EnsureValue2HasNotBeenSpecified();
|
||||
return new PSNoteProperty(this.memberName, this.value1);
|
||||
return new PSNoteProperty(_memberName, _value1);
|
||||
}
|
||||
|
||||
private PSMemberInfo GetPropertySet()
|
||||
@@ -299,19 +300,18 @@ namespace Microsoft.PowerShell.Commands
|
||||
EnsureValue2HasNotBeenSpecified();
|
||||
EnsureValue1HasBeenSpecified();
|
||||
EnsureValue1IsNotNull();
|
||||
Collection<string> value1Collection =
|
||||
(Collection<string>)GetParameterType(value1, typeof(Collection<string>));
|
||||
return new PSPropertySet(this.memberName, value1Collection);
|
||||
Collection<string> value1Collection =
|
||||
(Collection<string>)GetParameterType(_value1, typeof(Collection<string>));
|
||||
return new PSPropertySet(_memberName, value1Collection);
|
||||
}
|
||||
|
||||
private PSMemberInfo GetScriptMethod()
|
||||
{
|
||||
EnsureValue2HasNotBeenSpecified();
|
||||
EnsureValue1HasBeenSpecified();
|
||||
EnsureValue1IsNotNull();
|
||||
ScriptBlock value1ScriptBlock = (ScriptBlock)GetParameterType(value1, typeof(ScriptBlock));
|
||||
return new PSScriptMethod(this.memberName, value1ScriptBlock);
|
||||
|
||||
EnsureValue1IsNotNull();
|
||||
ScriptBlock value1ScriptBlock = (ScriptBlock)GetParameterType(_value1, typeof(ScriptBlock));
|
||||
return new PSScriptMethod(_memberName, value1ScriptBlock);
|
||||
}
|
||||
|
||||
private PSMemberInfo GetScriptProperty()
|
||||
@@ -320,16 +320,16 @@ namespace Microsoft.PowerShell.Commands
|
||||
EnsureValue1AndValue2AreNotBothNull();
|
||||
|
||||
ScriptBlock value1ScriptBlock = null;
|
||||
if (HasBeenSpecified(this.value1))
|
||||
if (HasBeenSpecified(_value1))
|
||||
{
|
||||
value1ScriptBlock = (ScriptBlock)GetParameterType(value1, typeof(ScriptBlock));
|
||||
value1ScriptBlock = (ScriptBlock)GetParameterType(_value1, typeof(ScriptBlock));
|
||||
}
|
||||
ScriptBlock value2ScriptBlock = null;
|
||||
if (HasBeenSpecified(this.value2))
|
||||
if (HasBeenSpecified(_value2))
|
||||
{
|
||||
value2ScriptBlock = (ScriptBlock)GetParameterType(value2, typeof(ScriptBlock));
|
||||
value2ScriptBlock = (ScriptBlock)GetParameterType(_value2, typeof(ScriptBlock));
|
||||
}
|
||||
return new PSScriptProperty(this.memberName, value1ScriptBlock, value2ScriptBlock);
|
||||
return new PSScriptProperty(_memberName, value1ScriptBlock, value2ScriptBlock);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -337,18 +337,18 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
if (this.typeName != null && string.IsNullOrWhiteSpace(this.typeName))
|
||||
if (_typeName != null && string.IsNullOrWhiteSpace(_typeName))
|
||||
{
|
||||
ThrowTerminatingError(NewError("TypeNameShouldNotBeEmpty", "TypeNameShouldNotBeEmpty", this.typeName));
|
||||
ThrowTerminatingError(NewError("TypeNameShouldNotBeEmpty", "TypeNameShouldNotBeEmpty", _typeName));
|
||||
}
|
||||
|
||||
if(ParameterSetName == "TypeNameSet")
|
||||
if (ParameterSetName == "TypeNameSet")
|
||||
{
|
||||
UpdateTypeNames();
|
||||
|
||||
if (this.passThru)
|
||||
if (_passThru)
|
||||
{
|
||||
WriteObject(this.inputObject);
|
||||
WriteObject(_inputObject);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -366,7 +366,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
int memberCountHelper = (int)memberType;
|
||||
int memberCountHelper = (int)_memberType;
|
||||
int memberCount = 0;
|
||||
while (memberCountHelper != 0)
|
||||
{
|
||||
@@ -378,11 +378,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
if (memberCount != 1)
|
||||
{
|
||||
ThrowTerminatingError(NewError("WrongMemberCount", "WrongMemberCount", null, memberType.ToString()));
|
||||
ThrowTerminatingError(NewError("WrongMemberCount", "WrongMemberCount", null, _memberType.ToString()));
|
||||
return;
|
||||
}
|
||||
|
||||
switch (memberType)
|
||||
switch (_memberType)
|
||||
{
|
||||
case PSMemberTypes.AliasProperty:
|
||||
member = GetAliasProperty();
|
||||
@@ -409,11 +409,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
member = GetScriptProperty();
|
||||
break;
|
||||
default:
|
||||
ThrowTerminatingError(NewError("CannotAddMemberType", "CannotAddMemberType", null, memberType.ToString()));
|
||||
ThrowTerminatingError(NewError("CannotAddMemberType", "CannotAddMemberType", null, _memberType.ToString()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (member == null)
|
||||
{
|
||||
return;
|
||||
@@ -421,15 +421,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (!AddMemberToTarget(member))
|
||||
return;
|
||||
|
||||
if(this.typeName != null)
|
||||
|
||||
if (_typeName != null)
|
||||
{
|
||||
UpdateTypeNames();
|
||||
}
|
||||
|
||||
if (this.passThru)
|
||||
|
||||
if (_passThru)
|
||||
{
|
||||
WriteObject(this.inputObject);
|
||||
WriteObject(_inputObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,32 +440,32 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns></returns>
|
||||
private bool AddMemberToTarget(PSMemberInfo member)
|
||||
{
|
||||
PSMemberInfo previousMember = this.inputObject.Members[member.Name];
|
||||
PSMemberInfo previousMember = _inputObject.Members[member.Name];
|
||||
if (previousMember != null)
|
||||
{
|
||||
if (!this.force)
|
||||
if (!_force)
|
||||
{
|
||||
WriteError(NewError("MemberAlreadyExists",
|
||||
"MemberAlreadyExists",
|
||||
this.inputObject, member.Name));
|
||||
_inputObject, member.Name));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (previousMember.IsInstance)
|
||||
{
|
||||
this.inputObject.Members.Remove(member.Name);
|
||||
_inputObject.Members.Remove(member.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteError(NewError("CannotRemoveTypeDataMember",
|
||||
"CannotRemoveTypeDataMember",
|
||||
this.inputObject, member.Name, previousMember.MemberType));
|
||||
_inputObject, member.Name, previousMember.MemberType));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.inputObject.Members.Add(member);
|
||||
_inputObject.Members.Add(member);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -482,7 +482,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
if (string.IsNullOrEmpty(noteName))
|
||||
{
|
||||
WriteError(NewError("NotePropertyNameShouldNotBeNull",
|
||||
WriteError(NewError("NotePropertyNameShouldNotBeNull",
|
||||
"NotePropertyNameShouldNotBeNull", noteName));
|
||||
continue;
|
||||
}
|
||||
@@ -492,13 +492,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (result && this.typeName != null)
|
||||
if (result && _typeName != null)
|
||||
{
|
||||
UpdateTypeNames();
|
||||
}
|
||||
if (result && this.passThru)
|
||||
if (result && _passThru)
|
||||
{
|
||||
WriteObject(this.inputObject);
|
||||
WriteObject(_inputObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -506,9 +506,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
// Respect the type shortcut
|
||||
Type type;
|
||||
string typeNameInUse = this.typeName;
|
||||
if (LanguagePrimitives.TryConvertTo(this.typeName, out type)) { typeNameInUse = type.FullName; }
|
||||
this.inputObject.TypeNames.Insert(0, typeNameInUse);
|
||||
string typeNameInUse = _typeName;
|
||||
if (LanguagePrimitives.TryConvertTo(_typeName, out type)) { typeNameInUse = type.FullName; }
|
||||
_inputObject.TypeNames.Insert(0, typeNameInUse);
|
||||
}
|
||||
|
||||
private ErrorRecord NewError(string errorId, string resourceId, object targetObject, params object[] args)
|
||||
@@ -579,6 +579,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
return inputData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,14 +178,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return typename;
|
||||
return _typename;
|
||||
}
|
||||
set
|
||||
{
|
||||
typename = value;
|
||||
_typename = value;
|
||||
}
|
||||
}
|
||||
private string typename;
|
||||
private string _typename;
|
||||
|
||||
/// <summary>
|
||||
/// The source code of this method / member
|
||||
@@ -248,14 +248,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return usingNamespace;
|
||||
return _usingNamespace;
|
||||
}
|
||||
set
|
||||
{
|
||||
usingNamespace = value;
|
||||
_usingNamespace = value;
|
||||
}
|
||||
}
|
||||
private string[] usingNamespace = Utils.EmptyArray<string>();
|
||||
private string[] _usingNamespace = Utils.EmptyArray<string>();
|
||||
|
||||
|
||||
|
||||
@@ -489,7 +489,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
internal bool referencedAssembliesSpecified = false;
|
||||
internal string[] referencedAssemblies = Utils.EmptyArray<string>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The path to the output assembly
|
||||
/// </summary>
|
||||
@@ -698,7 +698,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
" {{\n" +
|
||||
" {1}\n" +
|
||||
" }}\n";
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -939,7 +938,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
#if CORECLR
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds a new type to the Application Domain.
|
||||
/// This version is based on CodeAnalysis (Roslyn).
|
||||
@@ -948,8 +947,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
[OutputType(typeof(Type))]
|
||||
public sealed class AddTypeCommand : AddTypeCommandBase
|
||||
{
|
||||
private static Dictionary<string, int> sourceCache = new Dictionary<string, int>();
|
||||
|
||||
private static Dictionary<string, int> s_sourceCache = new Dictionary<string, int>();
|
||||
|
||||
/// <summary>
|
||||
/// Generate the type(s)
|
||||
/// </summary>
|
||||
@@ -1025,9 +1024,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
if (sourceCache.ContainsKey(type.FullName))
|
||||
if (s_sourceCache.ContainsKey(type.FullName))
|
||||
{
|
||||
if (sourceCache[type.FullName] != sourceCode.GetHashCode())
|
||||
if (s_sourceCache[type.FullName] != sourceCode.GetHashCode())
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
new Exception(
|
||||
@@ -1042,12 +1041,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
sourceCache[type.FullName] = sourceCode.GetHashCode();
|
||||
s_sourceCache[type.FullName] = sourceCode.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string FrameworkFolder = System.IO.Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.Location);
|
||||
private static string s_frameworkFolder = System.IO.Path.GetDirectoryName(typeof(object).GetTypeInfo().Assembly.Location);
|
||||
|
||||
// there are two different assemblies: framework contract and framework implementation.
|
||||
// Version 1.1.1 of Microsoft.CodeAnalysis doesn't provide a good way to handle contract separetely from implementation.
|
||||
@@ -1056,40 +1055,40 @@ namespace Microsoft.PowerShell.Commands
|
||||
// (i.e. System.Management.Automation), so we need the contract one.
|
||||
// 2) We have to provide implementation assembly explicitly, Roslyn doesn't have a way to figure out implementation by itself.
|
||||
// So we are adding both.
|
||||
private static PortableExecutableReference ObjectImplementationAssemblyReference =
|
||||
private static PortableExecutableReference s_objectImplementationAssemblyReference =
|
||||
MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location);
|
||||
|
||||
private static PortableExecutableReference MscorlibAssemblyReference =
|
||||
MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("mscorlib")).Location);
|
||||
private static PortableExecutableReference s_mscorlibAssemblyReference =
|
||||
MetadataReference.CreateFromFile(Assembly.Load(new AssemblyName("mscorlib")).Location);
|
||||
|
||||
// This assembly should be System.Runtime.dll
|
||||
private static PortableExecutableReference SystemRuntimeAssemblyReference =
|
||||
private static PortableExecutableReference s_systemRuntimeAssemblyReference =
|
||||
MetadataReference.CreateFromFile(ClrFacade.GetAssemblies(typeof(object).FullName).First().Location);
|
||||
|
||||
// SecureString is defined in a separate assembly.
|
||||
// This fact is an implementation detail and should not require the user to specify one more assembly,
|
||||
// if they want to use SecureString in Add-Type -TypeDefinition.
|
||||
// So this assembly should be in the default assemblies list to provide the best experience.
|
||||
private static PortableExecutableReference SecureStringAssemblyReference =
|
||||
private static PortableExecutableReference s_secureStringAssemblyReference =
|
||||
MetadataReference.CreateFromFile(typeof(System.Security.SecureString).GetTypeInfo().Assembly.Location);
|
||||
|
||||
|
||||
// These assemlbies are always automatically added to ReferencedAssemblies.
|
||||
private static PortableExecutableReference[] autoReferencedAssemblies = new PortableExecutableReference[]
|
||||
private static PortableExecutableReference[] s_autoReferencedAssemblies = new PortableExecutableReference[]
|
||||
{
|
||||
MscorlibAssemblyReference,
|
||||
SystemRuntimeAssemblyReference,
|
||||
SecureStringAssemblyReference,
|
||||
ObjectImplementationAssemblyReference
|
||||
s_mscorlibAssemblyReference,
|
||||
s_systemRuntimeAssemblyReference,
|
||||
s_secureStringAssemblyReference,
|
||||
s_objectImplementationAssemblyReference
|
||||
};
|
||||
|
||||
// These assemlbies are used, when ReferencedAssemblies parameter is not specified.
|
||||
private static PortableExecutableReference[] defaultAssemblies = new PortableExecutableReference[]
|
||||
private static PortableExecutableReference[] s_defaultAssemblies = new PortableExecutableReference[]
|
||||
{
|
||||
MscorlibAssemblyReference,
|
||||
SystemRuntimeAssemblyReference,
|
||||
SecureStringAssemblyReference,
|
||||
ObjectImplementationAssemblyReference,
|
||||
s_mscorlibAssemblyReference,
|
||||
s_systemRuntimeAssemblyReference,
|
||||
s_secureStringAssemblyReference,
|
||||
s_objectImplementationAssemblyReference,
|
||||
MetadataReference.CreateFromFile(typeof(PSObject).GetTypeInfo().Assembly.Location)
|
||||
};
|
||||
|
||||
@@ -1126,7 +1125,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
// lookup in framework folders and the current folder
|
||||
string frameworkPossiblePath = System.IO.Path.Combine(FrameworkFolder, referencedAssembly);
|
||||
string frameworkPossiblePath = System.IO.Path.Combine(s_frameworkFolder, referencedAssembly);
|
||||
if (File.Exists(frameworkPossiblePath))
|
||||
{
|
||||
return frameworkPossiblePath;
|
||||
@@ -1227,11 +1226,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
SyntaxTree syntaxTree = CSharpSyntaxTree.ParseText(source, parseOptions);
|
||||
var references = defaultAssemblies;
|
||||
var references = s_defaultAssemblies;
|
||||
if (referencedAssembliesSpecified)
|
||||
{
|
||||
var tempReferences = ReferencedAssemblies.Select(a => MetadataReference.CreateFromFile(ResolveReferencedAssembly(a))).ToList();
|
||||
tempReferences.AddRange(autoReferencedAssemblies);
|
||||
tempReferences.AddRange(s_autoReferencedAssemblies);
|
||||
|
||||
references = tempReferences.ToArray();
|
||||
}
|
||||
@@ -1447,7 +1446,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(ParameterSetName = "FromMember")]
|
||||
[Parameter(ParameterSetName = "FromPath")]
|
||||
[Parameter(ParameterSetName = "FromLiteralPath")]
|
||||
[Alias("CP")]
|
||||
[Alias("CP")]
|
||||
public CompilerParameters CompilerParameters
|
||||
{
|
||||
get
|
||||
@@ -1469,7 +1468,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
base.EndProcessing();
|
||||
|
||||
// Generate an error if they've specified a language AND a CodeDomProvider
|
||||
if(providerSpecified && languageSpecified)
|
||||
if (providerSpecified && languageSpecified)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
new Exception(
|
||||
@@ -1552,11 +1551,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<Type> generatedTypes = new List<Type>();
|
||||
|
||||
// We want to compile from a source representation
|
||||
if(! loadAssembly)
|
||||
if (!loadAssembly)
|
||||
{
|
||||
CompileAssemblyFromSource(generatedTypes);
|
||||
}
|
||||
@@ -1567,7 +1566,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
// Pass the type along if they supplied the PassThru parameter
|
||||
if(PassThru)
|
||||
if (PassThru)
|
||||
{
|
||||
WriteObject(generatedTypes, true);
|
||||
}
|
||||
@@ -1584,12 +1583,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
// Load the source if they want to load from a file
|
||||
if(String.Equals(ParameterSetName, "FromPath", StringComparison.OrdinalIgnoreCase) ||
|
||||
if (String.Equals(ParameterSetName, "FromPath", StringComparison.OrdinalIgnoreCase) ||
|
||||
String.Equals(ParameterSetName, "FromLiteralPath", StringComparison.OrdinalIgnoreCase)
|
||||
)
|
||||
{
|
||||
sourceCode = "";
|
||||
foreach(string file in paths)
|
||||
foreach (string file in paths)
|
||||
{
|
||||
sourceCode += System.IO.File.ReadAllText(file) + "\n";
|
||||
}
|
||||
@@ -1659,14 +1658,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
compilerParameters = new CompilerParameters();
|
||||
|
||||
// Turn off debug information and turn on compiler optimizations by default.
|
||||
// Turn off debug information and turn on compiler optimizations by default.
|
||||
compilerParameters.IncludeDebugInformation = false;
|
||||
if (Language == Language.CSharp || Language == Language.VisualBasic || Language==Language.CSharpVersion2 || Language==Language.CSharpVersion3)
|
||||
if (Language == Language.CSharp || Language == Language.VisualBasic || Language == Language.CSharpVersion2 || Language == Language.CSharpVersion3)
|
||||
{
|
||||
|
||||
compilerParameters.CompilerOptions = "/optimize+";
|
||||
}
|
||||
|
||||
|
||||
compilerParameters.ReferencedAssemblies.AddRange(defaultAssemblies.ToArray());
|
||||
|
||||
foreach (string referencedAssembly in referencedAssemblies)
|
||||
@@ -1709,7 +1707,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
|
||||
compilerParameters.TreatWarningsAsErrors = !((bool) ignoreWarnings);
|
||||
compilerParameters.TreatWarningsAsErrors = !((bool)ignoreWarnings);
|
||||
|
||||
if (String.IsNullOrEmpty(outputAssembly))
|
||||
{
|
||||
@@ -1753,8 +1751,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
compilerResults = provider.CompileAssemblyFromFile(compilerParameters, paths);
|
||||
}
|
||||
// Otherwise, this is code generated. Use the
|
||||
// source code
|
||||
// Otherwise, this is code generated. Use the
|
||||
// source code
|
||||
else
|
||||
{
|
||||
compilerResults = provider.CompileAssemblyFromSource(compilerParameters, sourceCode);
|
||||
@@ -1794,7 +1792,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
HandleCompilerErrors(GetErrors(compilerResults.Errors));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Only return / load the types if they aren't
|
||||
// storing it to disk. PassThru overrides this.
|
||||
if (PassThru || String.IsNullOrEmpty(outputAssembly))
|
||||
@@ -1876,7 +1874,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// Suppress the "defines no public members" for
|
||||
// cmdlets as they are so common
|
||||
if (typeof (System.Management.Automation.Cmdlet).IsAssignableFrom(generatedType))
|
||||
if (typeof(System.Management.Automation.Cmdlet).IsAssignableFrom(generatedType))
|
||||
{
|
||||
foundPublicMember = true;
|
||||
continue;
|
||||
@@ -1934,7 +1932,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
[SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId="System.Reflection.Assembly.LoadFrom")]
|
||||
[SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Reflection.Assembly.LoadFrom")]
|
||||
private void LoadAssemblyFromPathOrName(List<Type> generatedTypes)
|
||||
{
|
||||
// Load the source if they want to load from a file
|
||||
@@ -1942,13 +1940,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
String.Equals(ParameterSetName, "FromLiteralPath", StringComparison.OrdinalIgnoreCase)
|
||||
)
|
||||
{
|
||||
foreach(string path in paths)
|
||||
foreach (string path in paths)
|
||||
{
|
||||
generatedTypes.AddRange(ClrFacade.LoadFrom(path).GetTypes());
|
||||
}
|
||||
}
|
||||
// Load the assembly by name
|
||||
else if(String.Equals(ParameterSetName, "FromAssemblyName", StringComparison.OrdinalIgnoreCase))
|
||||
else if (String.Equals(ParameterSetName, "FromAssemblyName", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
bool caughtError = false;
|
||||
|
||||
@@ -2005,26 +2003,26 @@ namespace Microsoft.PowerShell.Commands
|
||||
// to use it. So here, we do it all through reflection.
|
||||
|
||||
// Go through the constructors
|
||||
foreach(ConstructorInfo constructor in typeof(CSharpCodeProvider).GetConstructors())
|
||||
foreach (ConstructorInfo constructor in typeof(CSharpCodeProvider).GetConstructors())
|
||||
{
|
||||
// Look for the one that takes a single parameter
|
||||
ParameterInfo[] constructorParameters = constructor.GetParameters();
|
||||
if(constructorParameters.Length == 1)
|
||||
if (constructorParameters.Length == 1)
|
||||
{
|
||||
// Ensure this is the one that takes a dictionary
|
||||
Dictionary<string,string> providerParameters = new Dictionary<string,string>();
|
||||
Dictionary<string, string> providerParameters = new Dictionary<string, string>();
|
||||
providerParameters["CompilerVersion"] = "v3.5";
|
||||
|
||||
if(constructorParameters[0].ParameterType.IsAssignableFrom(providerParameters.GetType()))
|
||||
if (constructorParameters[0].ParameterType.IsAssignableFrom(providerParameters.GetType()))
|
||||
{
|
||||
// If so, create the compiler and break
|
||||
csc = (CodeDomProvider) constructor.Invoke(new object[] { providerParameters });
|
||||
csc = (CodeDomProvider)constructor.Invoke(new object[] { providerParameters });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(csc == null)
|
||||
if (csc == null)
|
||||
{
|
||||
throw new NotSupportedException(
|
||||
string.Format(CultureInfo.InvariantCulture, AddTypeStrings.SpecialNetVersionRequired, Language.CSharpVersion3.ToString(), "3.5"));
|
||||
@@ -2068,7 +2066,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// So we'll try from the short name.
|
||||
catch (System.IO.FileNotFoundException) { }
|
||||
|
||||
if(loadedAssembly != null)
|
||||
if (loadedAssembly != null)
|
||||
return loadedAssembly;
|
||||
|
||||
// Next, try an exact match
|
||||
@@ -2087,12 +2085,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
string matchedStrongName = null;
|
||||
|
||||
WildcardPattern pattern = WildcardPattern.Get(assemblyName, WildcardOptions.IgnoreCase);
|
||||
foreach(string strongNameShortcut in StrongNames.Value.Keys)
|
||||
foreach (string strongNameShortcut in StrongNames.Value.Keys)
|
||||
{
|
||||
if (pattern.IsMatch(strongNameShortcut))
|
||||
{
|
||||
// If we've already found a matching type, throw an error.
|
||||
if(matchedStrongName != null)
|
||||
if (matchedStrongName != null)
|
||||
{
|
||||
ErrorRecord errorRecord = new ErrorRecord(
|
||||
new Exception(
|
||||
@@ -2113,7 +2111,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
// Return NULL if we couldn't find one. The caller generates an error here.
|
||||
if(matchedStrongName == null)
|
||||
if (matchedStrongName == null)
|
||||
return null;
|
||||
|
||||
// Otherwise, load the assembly.
|
||||
@@ -2885,6 +2883,5 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
#endif // if !CORECLR
|
||||
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// NoTypeInformation : should the #TYPE line be generated
|
||||
/// </summary>
|
||||
@@ -95,7 +95,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
_noTypeInformation = value;
|
||||
}
|
||||
}
|
||||
bool _noTypeInformation;
|
||||
private bool _noTypeInformation;
|
||||
|
||||
#endregion Command Line Parameters
|
||||
|
||||
@@ -163,11 +163,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_path = value;
|
||||
specifiedPath = true;
|
||||
_specifiedPath = true;
|
||||
}
|
||||
}
|
||||
private string _path;
|
||||
bool specifiedPath = false;
|
||||
private bool _specifiedPath = false;
|
||||
|
||||
/// <summary>
|
||||
/// The literal path of the mandatory file name to write to
|
||||
@@ -185,13 +185,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_path = value;
|
||||
isLiteralPath = true;
|
||||
_isLiteralPath = true;
|
||||
}
|
||||
}
|
||||
bool isLiteralPath = false;
|
||||
private bool _isLiteralPath = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Property that sets force parameter.
|
||||
/// </summary>
|
||||
@@ -218,14 +218,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return noclobber;
|
||||
return _noclobber;
|
||||
}
|
||||
set
|
||||
{
|
||||
noclobber = value;
|
||||
_noclobber = value;
|
||||
}
|
||||
}
|
||||
private bool noclobber;
|
||||
private bool _noclobber;
|
||||
|
||||
/// <summary>
|
||||
/// Encoding optional flag
|
||||
@@ -250,16 +250,16 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public SwitchParameter Append { get; set; }
|
||||
private bool isActuallyAppending; // true if Append=true AND the file written was not empty (or nonexistant) when the cmdlet was invoked
|
||||
private bool _isActuallyAppending; // true if Append=true AND the file written was not empty (or nonexistant) when the cmdlet was invoked
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides
|
||||
|
||||
private bool shouldProcess;
|
||||
private bool _shouldProcess;
|
||||
private IList<string> _propertyNames;
|
||||
private IList<string> _preexistingPropertyNames;
|
||||
private ExportCsvHelper helper;
|
||||
private ExportCsvHelper _helper;
|
||||
|
||||
/// <summary>
|
||||
/// BeginProcessing override
|
||||
@@ -269,22 +269,22 @@ namespace Microsoft.PowerShell.Commands
|
||||
base.BeginProcessing();
|
||||
|
||||
// Validate that they don't provide both Path and LiteralPath, but have provided at least one.
|
||||
if (!(specifiedPath ^ isLiteralPath))
|
||||
if (!(_specifiedPath ^ _isLiteralPath))
|
||||
{
|
||||
InvalidOperationException exception = new InvalidOperationException(CsvCommandStrings.CannotSpecifyPathAndLiteralPath);
|
||||
ErrorRecord errorRecord = new ErrorRecord(exception, "CannotSpecifyPathAndLiteralPath", ErrorCategory.InvalidData, null);
|
||||
this.ThrowTerminatingError(errorRecord);
|
||||
}
|
||||
|
||||
shouldProcess = ShouldProcess(Path);
|
||||
if (!shouldProcess) return;
|
||||
_shouldProcess = ShouldProcess(Path);
|
||||
if (!_shouldProcess) return;
|
||||
|
||||
CreateFileStream();
|
||||
|
||||
helper = new ExportCsvHelper(this, base.Delimiter);
|
||||
|
||||
_helper = new ExportCsvHelper(this, base.Delimiter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Convert the current input object to Csv and write to file/WriteObject
|
||||
/// </summary>
|
||||
@@ -297,30 +297,30 @@ namespace Microsoft.PowerShell.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shouldProcess) return;
|
||||
if (!_shouldProcess) return;
|
||||
//Process first object
|
||||
if (_propertyNames == null)
|
||||
{
|
||||
// figure out the column names (and lock-in their order)
|
||||
_propertyNames = helper.BuildPropertyNames(InputObject, _propertyNames);
|
||||
if (this.isActuallyAppending && _preexistingPropertyNames != null)
|
||||
_propertyNames = _helper.BuildPropertyNames(InputObject, _propertyNames);
|
||||
if (_isActuallyAppending && _preexistingPropertyNames != null)
|
||||
{
|
||||
this.ReconcilePreexistingPropertyNames();
|
||||
}
|
||||
|
||||
// write headers (row1: typename + row2: column names)
|
||||
if (!this.isActuallyAppending)
|
||||
if (!_isActuallyAppending)
|
||||
{
|
||||
if (NoTypeInformation == false)
|
||||
{
|
||||
WriteCsvLine(helper.GetTypeString(InputObject));
|
||||
WriteCsvLine(_helper.GetTypeString(InputObject));
|
||||
}
|
||||
|
||||
WriteCsvLine(helper.ConvertPropertyNamesCSV(_propertyNames));
|
||||
WriteCsvLine(_helper.ConvertPropertyNamesCSV(_propertyNames));
|
||||
}
|
||||
}
|
||||
|
||||
string csv = helper.ConvertPSObjectToCSV(InputObject, _propertyNames);
|
||||
string csv = _helper.ConvertPSObjectToCSV(InputObject, _propertyNames);
|
||||
WriteCsvLine(csv);
|
||||
_sw.Flush();
|
||||
}
|
||||
@@ -350,32 +350,32 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// handle to file whose read-only attribute should be reset when we are done
|
||||
/// </summary>
|
||||
private FileInfo readOnlyFileInfo = null;
|
||||
private FileInfo _readOnlyFileInfo = null;
|
||||
|
||||
private void CreateFileStream()
|
||||
{
|
||||
Dbg.Assert(_path != null, "FileName is mandatory parameter");
|
||||
|
||||
string resolvedFilePath = PathUtils.ResolveFilePath(this.Path, this, isLiteralPath);
|
||||
string resolvedFilePath = PathUtils.ResolveFilePath(this.Path, this, _isLiteralPath);
|
||||
|
||||
bool isCsvFileEmpty = true;
|
||||
|
||||
if (this.Append && File.Exists(resolvedFilePath))
|
||||
{
|
||||
using (StreamReader streamReader = PathUtils.OpenStreamReader(this, this.Path, this._encodingParameter, isLiteralPath))
|
||||
using (StreamReader streamReader = PathUtils.OpenStreamReader(this, this.Path, _encodingParameter, _isLiteralPath))
|
||||
{
|
||||
isCsvFileEmpty = streamReader.Peek() == -1 ? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
// If the csv file is empty then even append is treated as regualr export (i.e., both header & values are added to the CSV file).
|
||||
this.isActuallyAppending = this.Append && File.Exists(resolvedFilePath) && !isCsvFileEmpty;
|
||||
_isActuallyAppending = this.Append && File.Exists(resolvedFilePath) && !isCsvFileEmpty;
|
||||
|
||||
if (this.isActuallyAppending)
|
||||
if (_isActuallyAppending)
|
||||
{
|
||||
Encoding encodingObject;
|
||||
|
||||
using (StreamReader streamReader = PathUtils.OpenStreamReader(this, this.Path, this._encodingParameter, isLiteralPath))
|
||||
using (StreamReader streamReader = PathUtils.OpenStreamReader(this, this.Path, _encodingParameter, _isLiteralPath))
|
||||
{
|
||||
ImportCsvHelper readingHelper = new ImportCsvHelper(
|
||||
this, this.Delimiter, null /* header */, null /* typeName */, streamReader);
|
||||
@@ -392,31 +392,31 @@ namespace Microsoft.PowerShell.Commands
|
||||
false, // defaultEncoding
|
||||
Append,
|
||||
Force,
|
||||
NoClobber,
|
||||
NoClobber,
|
||||
out _fs,
|
||||
out _sw,
|
||||
out readOnlyFileInfo,
|
||||
isLiteralPath);
|
||||
out _readOnlyFileInfo,
|
||||
_isLiteralPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
PathUtils.MasterStreamOpen(
|
||||
this,
|
||||
this.Path,
|
||||
this._encodingParameter ?? "ASCII",
|
||||
_encodingParameter ?? "ASCII",
|
||||
false, // defaultEncoding
|
||||
Append,
|
||||
Force,
|
||||
NoClobber,
|
||||
NoClobber,
|
||||
out _fs,
|
||||
out _sw,
|
||||
out readOnlyFileInfo,
|
||||
isLiteralPath);
|
||||
out _readOnlyFileInfo,
|
||||
_isLiteralPath);
|
||||
}
|
||||
}
|
||||
|
||||
private
|
||||
void
|
||||
private
|
||||
void
|
||||
CleanUp()
|
||||
{
|
||||
if (_fs != null)
|
||||
@@ -430,27 +430,27 @@ namespace Microsoft.PowerShell.Commands
|
||||
_fs.Dispose();
|
||||
_fs = null;
|
||||
// reset the read-only attribute
|
||||
if (null != readOnlyFileInfo)
|
||||
readOnlyFileInfo.Attributes |= FileAttributes.ReadOnly;
|
||||
if (null != _readOnlyFileInfo)
|
||||
_readOnlyFileInfo.Attributes |= FileAttributes.ReadOnly;
|
||||
}
|
||||
if (helper != null)
|
||||
if (_helper != null)
|
||||
{
|
||||
helper.Dispose();
|
||||
_helper.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ReconcilePreexistingPropertyNames()
|
||||
{
|
||||
Dbg.Assert(this.isActuallyAppending, "This method should only get called when appending");
|
||||
Dbg.Assert(_isActuallyAppending, "This method should only get called when appending");
|
||||
Dbg.Assert(_preexistingPropertyNames != null, "This method should only get called when we have successfully read preexisting property names");
|
||||
|
||||
HashSet<string> appendedPropertyNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (string appendedPropertyName in this._propertyNames)
|
||||
foreach (string appendedPropertyName in _propertyNames)
|
||||
{
|
||||
appendedPropertyNames.Add(appendedPropertyName);
|
||||
}
|
||||
|
||||
foreach (string preexistingPropertyName in this._preexistingPropertyNames)
|
||||
foreach (string preexistingPropertyName in _preexistingPropertyNames)
|
||||
{
|
||||
if (!appendedPropertyNames.Contains(preexistingPropertyName))
|
||||
{
|
||||
@@ -488,13 +488,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
_sw.WriteLine(line);
|
||||
}
|
||||
#endregion file
|
||||
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
/// <summary>
|
||||
/// Set to true when object is disposed
|
||||
/// </summary>
|
||||
bool _disposed;
|
||||
private bool _disposed;
|
||||
|
||||
/// <summary>
|
||||
/// public dispose method
|
||||
@@ -510,7 +510,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
|
||||
#endregion IDisposable Members
|
||||
}
|
||||
|
||||
@@ -561,11 +560,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_paths = value;
|
||||
specifiedPath = true;
|
||||
_specifiedPath = true;
|
||||
}
|
||||
}
|
||||
private string[] _paths;
|
||||
bool specifiedPath = false;
|
||||
private bool _specifiedPath = false;
|
||||
|
||||
/// <summary>
|
||||
/// The literal path of the mandatory file name to read from
|
||||
@@ -583,10 +582,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
set
|
||||
{
|
||||
_paths = value;
|
||||
isLiteralPath = true;
|
||||
_isLiteralPath = true;
|
||||
}
|
||||
}
|
||||
bool isLiteralPath = false;
|
||||
private bool _isLiteralPath = false;
|
||||
|
||||
/// <summary>
|
||||
/// Property that sets UseCulture parameter
|
||||
@@ -616,17 +615,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
public string[] Header
|
||||
{
|
||||
get
|
||||
{
|
||||
return _header;
|
||||
{
|
||||
return _header;
|
||||
}
|
||||
set
|
||||
{
|
||||
_header = value;
|
||||
}
|
||||
_header = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string[] _header;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Encoding optional flag
|
||||
/// </summary>
|
||||
@@ -650,7 +649,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// one or more unspecified names
|
||||
/// </summary>
|
||||
private bool _alreadyWarnedUnspecifiedNames = false;
|
||||
|
||||
|
||||
#endregion Command Line Parameters
|
||||
|
||||
#region Override Methods
|
||||
@@ -668,7 +667,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
// Validate that they don't provide both Path and LiteralPath, but have provided at least one.
|
||||
if (!(specifiedPath ^ isLiteralPath))
|
||||
if (!(_specifiedPath ^ _isLiteralPath))
|
||||
{
|
||||
InvalidOperationException exception = new InvalidOperationException(CsvCommandStrings.CannotSpecifyPathAndLiteralPath);
|
||||
ErrorRecord errorRecord = new ErrorRecord(exception, "CannotSpecifyPathAndLiteralPath", ErrorCategory.InvalidData, null);
|
||||
@@ -679,7 +678,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
foreach (string path in _paths)
|
||||
{
|
||||
using (StreamReader streamReader = PathUtils.OpenStreamReader(this, path, this.Encoding, isLiteralPath))
|
||||
using (StreamReader streamReader = PathUtils.OpenStreamReader(this, path, this.Encoding, _isLiteralPath))
|
||||
{
|
||||
ImportCsvHelper helper = new ImportCsvHelper(this, _delimiter, _header, null /* typeName */, streamReader);
|
||||
|
||||
@@ -697,7 +696,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}//if
|
||||
}////ProcessRecord
|
||||
}
|
||||
#endregion Override Methods
|
||||
#endregion Override Methods
|
||||
|
||||
#endregion Import-CSV Command
|
||||
|
||||
@@ -716,7 +715,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Overrides Base InputObject
|
||||
/// </summary>
|
||||
[Parameter(ValueFromPipeline = true, Mandatory = true, ValueFromPipelineByPropertyName = true,Position=0)]
|
||||
[Parameter(ValueFromPipeline = true, Mandatory = true, ValueFromPipelineByPropertyName = true, Position = 0)]
|
||||
public override PSObject InputObject
|
||||
{
|
||||
get
|
||||
@@ -737,12 +736,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Stores Property Names
|
||||
/// </summary>
|
||||
IList<string> _propertyNames;
|
||||
private IList<string> _propertyNames;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
ExportCsvHelper helper;
|
||||
private ExportCsvHelper _helper;
|
||||
|
||||
/// <summary>
|
||||
/// BeginProcessing override
|
||||
@@ -752,10 +751,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
BeginProcessing()
|
||||
{
|
||||
base.BeginProcessing();
|
||||
helper = new ExportCsvHelper(this, base.Delimiter);
|
||||
_helper = new ExportCsvHelper(this, base.Delimiter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Convert the current input object to Csv and write to stream/WriteObject
|
||||
@@ -771,25 +770,23 @@ namespace Microsoft.PowerShell.Commands
|
||||
//Process first object
|
||||
if (_propertyNames == null)
|
||||
{
|
||||
_propertyNames = helper.BuildPropertyNames(InputObject, _propertyNames);
|
||||
_propertyNames = _helper.BuildPropertyNames(InputObject, _propertyNames);
|
||||
if (NoTypeInformation == false)
|
||||
{
|
||||
WriteCsvLine(helper.GetTypeString(InputObject));
|
||||
WriteCsvLine(_helper.GetTypeString(InputObject));
|
||||
}
|
||||
//Write property information
|
||||
string properties = helper.ConvertPropertyNamesCSV(_propertyNames);
|
||||
string properties = _helper.ConvertPropertyNamesCSV(_propertyNames);
|
||||
if (!properties.Equals(""))
|
||||
WriteCsvLine(properties);
|
||||
}
|
||||
|
||||
string csv = helper.ConvertPSObjectToCSV(InputObject, _propertyNames);
|
||||
string csv = _helper.ConvertPSObjectToCSV(InputObject, _propertyNames);
|
||||
//write to the console
|
||||
if(csv != "")
|
||||
if (csv != "")
|
||||
WriteCsvLine(csv);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endregion Overrides
|
||||
|
||||
#region CSV conversion
|
||||
@@ -803,10 +800,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
WriteObject(line);
|
||||
}
|
||||
|
||||
|
||||
#endregion CSV conversion
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endregion ConvertTo-CSV Command
|
||||
@@ -846,7 +840,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
///<summary>
|
||||
///Culture switch for csv conversion
|
||||
///</summary>
|
||||
[Parameter(ParameterSetName = "UseCulture",Mandatory=true)]
|
||||
[Parameter(ParameterSetName = "UseCulture", Mandatory = true)]
|
||||
[ValidateNotNull]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public SwitchParameter UseCulture
|
||||
@@ -865,14 +859,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Input Object which is written in Csv format
|
||||
/// </summary>
|
||||
[Parameter(ValueFromPipeline = true, Mandatory = true, ValueFromPipelineByPropertyName = true,Position=0)]
|
||||
[Parameter(ValueFromPipeline = true, Mandatory = true, ValueFromPipelineByPropertyName = true, Position = 0)]
|
||||
[ValidateNotNull]
|
||||
[ValidateNotNullOrEmpty]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public PSObject[] InputObject
|
||||
{
|
||||
get
|
||||
{
|
||||
{
|
||||
return _object;
|
||||
}
|
||||
set
|
||||
@@ -888,7 +882,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
[Parameter(Mandatory = false)]
|
||||
[ValidateNotNull]
|
||||
[ValidateNotNullOrEmpty]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
|
||||
public string[] Header
|
||||
{
|
||||
get
|
||||
@@ -922,12 +916,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
_delimiter = ImportExportCSVHelper.SetDelimiter(this, ParameterSetName, _delimiter, _useculture);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Convert the current input object to Csv and write to stream/WriteObject
|
||||
/// </summary>
|
||||
protected override
|
||||
void
|
||||
protected override
|
||||
void
|
||||
ProcessRecord()
|
||||
{
|
||||
foreach (PSObject pObject in _object)
|
||||
@@ -958,7 +952,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion Overrides
|
||||
|
||||
private string _typeName;
|
||||
@@ -978,27 +972,27 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
private PSCmdlet _cmdlet ;
|
||||
private PSCmdlet _cmdlet;
|
||||
|
||||
private char Delimiter;
|
||||
private char _delimiter;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="cmdlet"></param>
|
||||
/// <param name="delimiter"></param>
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="cmdlet"></param>
|
||||
/// <param name="delimiter"></param>
|
||||
internal
|
||||
ExportCsvHelper(PSCmdlet cmdlet, char delimiter)
|
||||
{
|
||||
if (cmdlet == null)
|
||||
{
|
||||
{
|
||||
}
|
||||
_cmdlet = cmdlet;
|
||||
Delimiter = delimiter;
|
||||
_delimiter = delimiter;
|
||||
}
|
||||
|
||||
//Name of properties to be written in CSV format
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get the name of properties from source PSObject and
|
||||
@@ -1044,7 +1038,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
else
|
||||
{
|
||||
//changed to delimiter
|
||||
dest.Append(Delimiter);
|
||||
dest.Append(_delimiter);
|
||||
}
|
||||
EscapeAndAppendString(dest, propertyName);
|
||||
}
|
||||
@@ -1059,7 +1053,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns></returns>
|
||||
internal
|
||||
string
|
||||
ConvertPSObjectToCSV(PSObject mshObject, IList<string> propertyNames )
|
||||
ConvertPSObjectToCSV(PSObject mshObject, IList<string> propertyNames)
|
||||
{
|
||||
Dbg.Assert(propertyNames != null, "PropertyName collection can be empty here, but it should not be null");
|
||||
|
||||
@@ -1074,7 +1068,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
dest.Append(Delimiter);
|
||||
dest.Append(_delimiter);
|
||||
}
|
||||
PSPropertyInfo property = mshObject.Properties[propertyName] as PSPropertyInfo;
|
||||
string value = null;
|
||||
@@ -1120,7 +1114,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
internal
|
||||
internal
|
||||
string
|
||||
GetTypeString(PSObject source)
|
||||
{
|
||||
@@ -1174,14 +1168,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
dest.Append(c);
|
||||
}
|
||||
dest.Append('"');
|
||||
|
||||
}
|
||||
#region IDisposable Members
|
||||
|
||||
/// <summary>
|
||||
/// Set to true when object is disposed
|
||||
/// </summary>
|
||||
bool _disposed;
|
||||
private bool _disposed;
|
||||
|
||||
/// <summary>
|
||||
/// public dispose method
|
||||
@@ -1191,16 +1184,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
Dispose()
|
||||
{
|
||||
if (_disposed == false)
|
||||
{
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
_disposed = true;
|
||||
|
||||
}
|
||||
|
||||
#endregion IDisposable Members
|
||||
|
||||
|
||||
#endregion IDisposable Members
|
||||
}
|
||||
|
||||
#endregion ExportHelperConversion
|
||||
@@ -1283,7 +1273,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// This is set to true when end of file is reached
|
||||
/// </summary>
|
||||
private
|
||||
private
|
||||
bool EOF
|
||||
{
|
||||
get
|
||||
@@ -1366,7 +1356,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
Collection<string> values = ParseNextRecord(false);
|
||||
if (values.Count == 0)
|
||||
break;
|
||||
|
||||
|
||||
if (values.Count == 1 && String.IsNullOrEmpty(values[0]))
|
||||
{
|
||||
// skip the blank lines
|
||||
@@ -1467,12 +1457,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
StringBuilder current = new StringBuilder();
|
||||
|
||||
bool seenBeginQuote = false;
|
||||
// int i = 0;
|
||||
// int i = 0;
|
||||
while (!EOF)
|
||||
{
|
||||
//Read the next character
|
||||
char ch = ReadChar();
|
||||
|
||||
|
||||
|
||||
if ((ch == _delimiter))
|
||||
{
|
||||
@@ -1491,7 +1481,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
result.Add(current.ToString());
|
||||
current.Remove(0, current.Length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else if (ch == '"')
|
||||
@@ -1509,7 +1498,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
ReadChar();
|
||||
current.Append('"');
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1640,7 +1628,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
return result;
|
||||
}
|
||||
|
||||
private
|
||||
private
|
||||
bool
|
||||
IsNewLine(char ch)
|
||||
{
|
||||
@@ -1672,7 +1660,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// If this is true, eat the trailing blanks. Note:if there are non
|
||||
/// whitespace characters present, then trailing blanks are not consumed
|
||||
/// </param>
|
||||
private
|
||||
private
|
||||
void
|
||||
ReadTillNextDelimiter(StringBuilder current, ref bool endOfRecord, bool eatTrailingBlanks)
|
||||
{
|
||||
@@ -1726,7 +1714,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
private
|
||||
PSObject
|
||||
BuildMshobject(string type, IList<string> names, Collection<string> values,char delimiter)
|
||||
BuildMshobject(string type, IList<string> names, Collection<string> values, char delimiter)
|
||||
{
|
||||
//string[] namesarray = null;
|
||||
PSObject result = new PSObject();
|
||||
@@ -1737,13 +1725,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
result.TypeNames.Clear();
|
||||
result.TypeNames.Add(type);
|
||||
}
|
||||
for (int i = 0; i <= names.Count-1; i++)
|
||||
for (int i = 0; i <= names.Count - 1; i++)
|
||||
{
|
||||
|
||||
string name = names[i];
|
||||
string value = null;
|
||||
////if name is null and delimiter is '"', continue
|
||||
if (name.Length == 0 && delimiterlocal == '"')
|
||||
if (name.Length == 0 && delimiterlocal == '"')
|
||||
continue;
|
||||
////if name is null and delimiter is not '"', use a default property name 'UnspecifiedName'
|
||||
if (string.IsNullOrEmpty(name))
|
||||
@@ -1781,7 +1768,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
internal const char CSVDelimiter = ',';
|
||||
internal const string CSVTypePrefix = "CSV:";
|
||||
|
||||
internal static char SetDelimiter(PSCmdlet Cmdlet, string ParameterSetName,char Delimiter, bool UseCulture)
|
||||
internal static char SetDelimiter(PSCmdlet Cmdlet, string ParameterSetName, char Delimiter, bool UseCulture)
|
||||
{
|
||||
switch (ParameterSetName)
|
||||
{
|
||||
@@ -1806,7 +1793,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
Delimiter = ImportExportCSVHelper.CSVDelimiter;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
return Delimiter;
|
||||
}
|
||||
@@ -1815,5 +1801,4 @@ namespace Microsoft.PowerShell.Commands
|
||||
#endregion ExportImport Helper
|
||||
|
||||
#endregion CSV conversion
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// Base class for a variety of commandlets that take color parameters
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
|
||||
public
|
||||
class ConsoleColorCmdlet : PSCmdlet
|
||||
{
|
||||
@@ -24,7 +24,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
public ConsoleColorCmdlet()
|
||||
{
|
||||
consoleColorEnumType = typeof(ConsoleColor);
|
||||
_consoleColorEnumType = typeof(ConsoleColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,24 +41,24 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!isFgColorSet)
|
||||
if (!_isFgColorSet)
|
||||
{
|
||||
fgColor = this.Host.UI.RawUI.ForegroundColor;
|
||||
isFgColorSet = true;
|
||||
_fgColor = this.Host.UI.RawUI.ForegroundColor;
|
||||
_isFgColorSet = true;
|
||||
}
|
||||
|
||||
return fgColor;
|
||||
return _fgColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value >= (ConsoleColor) 0 && value <= (ConsoleColor) 15)
|
||||
if (value >= (ConsoleColor)0 && value <= (ConsoleColor)15)
|
||||
{
|
||||
fgColor = value;
|
||||
isFgColorSet = true;
|
||||
_fgColor = value;
|
||||
_isFgColorSet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ThrowTerminatingError(BuildOutOfRangeErrorRecord(value, "SetInvalidForegroundColor"));
|
||||
ThrowTerminatingError(BuildOutOfRangeErrorRecord(value, "SetInvalidForegroundColor"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
///
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
|
||||
|
||||
[Parameter]
|
||||
public
|
||||
ConsoleColor
|
||||
@@ -77,20 +77,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!isBgColorSet)
|
||||
if (!_isBgColorSet)
|
||||
{
|
||||
bgColor = this.Host.UI.RawUI.BackgroundColor;
|
||||
isBgColorSet = true;
|
||||
_bgColor = this.Host.UI.RawUI.BackgroundColor;
|
||||
_isBgColorSet = true;
|
||||
}
|
||||
|
||||
return bgColor;
|
||||
return _bgColor;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value >= (ConsoleColor) 0 && value <= (ConsoleColor) 15)
|
||||
if (value >= (ConsoleColor)0 && value <= (ConsoleColor)15)
|
||||
{
|
||||
bgColor = value;
|
||||
isBgColorSet = true;
|
||||
_bgColor = value;
|
||||
_isBgColorSet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -108,13 +108,13 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
#endregion helper
|
||||
|
||||
private ConsoleColor fgColor;
|
||||
private ConsoleColor bgColor;
|
||||
private ConsoleColor _fgColor;
|
||||
private ConsoleColor _bgColor;
|
||||
|
||||
private bool isFgColorSet = false;
|
||||
private bool isBgColorSet = false;
|
||||
private bool _isFgColorSet = false;
|
||||
private bool _isBgColorSet = false;
|
||||
|
||||
private readonly Type consoleColorEnumType;
|
||||
private readonly Type _consoleColorEnumType;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -70,11 +70,11 @@ namespace Microsoft.PowerShell.Commands
|
||||
string name = s.Substring(0, index);
|
||||
name = name.Trim();
|
||||
|
||||
if(result.ContainsKey(name))
|
||||
if (result.ContainsKey(name))
|
||||
{
|
||||
throw PSTraceSource.NewInvalidOperationException(
|
||||
ConvertFromStringData.DataItemAlreadyDefined,
|
||||
line,
|
||||
line,
|
||||
name);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Microsoft.PowerShell.Commands
|
||||
@@ -12,7 +13,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
internal CSVHelper(char delimiter)
|
||||
{
|
||||
this.delimiter = delimiter;
|
||||
_delimiter = delimiter;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -21,9 +22,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
///
|
||||
internal char Delimiter
|
||||
{
|
||||
get { return delimiter; }
|
||||
get { return _delimiter; }
|
||||
}
|
||||
private char delimiter = ',';
|
||||
private char _delimiter = ',';
|
||||
|
||||
/// <summary>
|
||||
/// Parse a CSV String.
|
||||
@@ -111,8 +112,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
namespace System.Management.Automation
|
||||
{
|
||||
using System;
|
||||
@@ -50,7 +51,7 @@ namespace System.Management.Automation
|
||||
/// depth to be used for serialization. If this value is specified,
|
||||
/// depth from types.xml is not used.
|
||||
/// </param>
|
||||
internal CustomSerialization(XmlWriter writer,bool notypeinformation, int depth)
|
||||
internal CustomSerialization(XmlWriter writer, bool notypeinformation, int depth)
|
||||
{
|
||||
if (writer == null)
|
||||
{
|
||||
@@ -69,14 +70,14 @@ namespace System.Management.Automation
|
||||
/// <summary>
|
||||
/// Default depth of serialization
|
||||
/// </summary>
|
||||
private static int mshDefaultSerializationDepth = 1;
|
||||
private static int s_mshDefaultSerializationDepth = 1;
|
||||
|
||||
/// <summary>
|
||||
/// Default depth of serializaiton
|
||||
/// </summary>
|
||||
public static int MshDefaultSerializationDepth
|
||||
{
|
||||
get { return mshDefaultSerializationDepth; }
|
||||
get { return s_mshDefaultSerializationDepth; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
@@ -96,7 +97,7 @@ namespace System.Management.Automation
|
||||
|
||||
#region public methods
|
||||
|
||||
private bool firstCall = true;
|
||||
private bool _firstCall = true;
|
||||
|
||||
/// <summary>
|
||||
/// Serialzies passed in object
|
||||
@@ -107,9 +108,9 @@ namespace System.Management.Automation
|
||||
internal void Serialize(object source)
|
||||
{
|
||||
//Write the root element tag before writing first object.
|
||||
if (firstCall)
|
||||
if (_firstCall)
|
||||
{
|
||||
firstCall = false;
|
||||
_firstCall = false;
|
||||
Start();
|
||||
}
|
||||
|
||||
@@ -140,7 +141,7 @@ namespace System.Management.Automation
|
||||
_serializer.WriteOneObject(source, null, _depth);
|
||||
_serializer = null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Writes the start of root element
|
||||
/// </summary>
|
||||
@@ -154,9 +155,9 @@ namespace System.Management.Automation
|
||||
/// </summary>
|
||||
internal void Done()
|
||||
{
|
||||
if (firstCall)
|
||||
if (_firstCall)
|
||||
{
|
||||
firstCall = false;
|
||||
_firstCall = false;
|
||||
Start();
|
||||
}
|
||||
_writer.WriteEndElement();
|
||||
@@ -194,12 +195,12 @@ namespace System.Management.Automation
|
||||
/// <summary>
|
||||
/// Xml writer to be used
|
||||
/// </summary>
|
||||
XmlWriter _writer;
|
||||
private XmlWriter _writer;
|
||||
|
||||
/// <summary>
|
||||
/// check first call for every pipeline object to write Object tag else property tag
|
||||
/// </summary>
|
||||
private bool firstcall;
|
||||
private bool _firstcall;
|
||||
|
||||
/// <summary>
|
||||
/// should the type information to be shown
|
||||
@@ -209,7 +210,7 @@ namespace System.Management.Automation
|
||||
/// <summary>
|
||||
/// check object call
|
||||
/// </summary>
|
||||
private bool firstobjectcall = true ;
|
||||
private bool _firstobjectcall = true;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
@@ -229,26 +230,26 @@ namespace System.Management.Automation
|
||||
|
||||
_writer = writer;
|
||||
_notypeinformation = notypeinformation;
|
||||
firstcall = isfirstcallforObject;
|
||||
_firstcall = isfirstcallforObject;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Stopping
|
||||
|
||||
private bool isStopping = false;
|
||||
private bool _isStopping = false;
|
||||
|
||||
/// <summary>
|
||||
/// Called from a separate thread will stop the serialization process
|
||||
/// </summary>
|
||||
internal void Stop()
|
||||
{
|
||||
this.isStopping = true;
|
||||
_isStopping = true;
|
||||
}
|
||||
|
||||
private void CheckIfStopping()
|
||||
{
|
||||
if (this.isStopping)
|
||||
if (_isStopping)
|
||||
{
|
||||
throw PSTraceSource.NewInvalidOperationException(Serialization.Stopping);
|
||||
}
|
||||
@@ -317,7 +318,7 @@ namespace System.Management.Automation
|
||||
/// <returns>
|
||||
/// true if source is handled, else false.
|
||||
/// </returns>
|
||||
private bool HandlePrimitiveKnownType( object source, string property)
|
||||
private bool HandlePrimitiveKnownType(object source, string property)
|
||||
{
|
||||
Dbg.Assert(source != null, "caller should validate the parameter");
|
||||
|
||||
@@ -340,7 +341,7 @@ namespace System.Management.Automation
|
||||
/// <returns>
|
||||
/// true if source is handled, else false.
|
||||
/// </returns>
|
||||
private bool HandlePrimitiveKnownTypePSObject( object source, string property, int depth)
|
||||
private bool HandlePrimitiveKnownTypePSObject(object source, string property, int depth)
|
||||
{
|
||||
Dbg.Assert(source != null, "caller should validate the parameter");
|
||||
|
||||
@@ -444,7 +445,7 @@ namespace System.Management.Automation
|
||||
/// <param name="ct"></param>
|
||||
/// <param name="dictionary"></param>
|
||||
/// <param name="enumerable"></param>
|
||||
void GetKnownContainerTypeInfo(
|
||||
private void GetKnownContainerTypeInfo(
|
||||
object source, out ContainerType ct, out IDictionary dictionary, out IEnumerable enumerable)
|
||||
{
|
||||
Dbg.Assert(source != null, "caller should validate the parameter");
|
||||
@@ -513,7 +514,6 @@ namespace System.Management.Automation
|
||||
ct = ContainerType.Enumerable;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -522,7 +522,7 @@ namespace System.Management.Automation
|
||||
/// <param name="derived"></param>
|
||||
/// <param name="baseType"></param>
|
||||
/// <returns></returns>
|
||||
static bool DerivesFromGenericType(Type derived, Type baseType)
|
||||
private static bool DerivesFromGenericType(Type derived, Type baseType)
|
||||
{
|
||||
Dbg.Assert(derived != null, "caller should validate the parameter");
|
||||
Dbg.Assert(baseType != null, "caller should validate the parameter");
|
||||
@@ -559,7 +559,7 @@ namespace System.Management.Automation
|
||||
/// </param>
|
||||
/// <param name="property"></param>
|
||||
/// <param name="depth"></param>
|
||||
private void WritePrimitiveTypePSObjectWithNotes (
|
||||
private void WritePrimitiveTypePSObjectWithNotes(
|
||||
PSObject source,
|
||||
object primitive,
|
||||
TypeSerializationInfo pktInfo,
|
||||
@@ -576,7 +576,7 @@ namespace System.Management.Automation
|
||||
{
|
||||
WriteOnePrimitiveKnownType(_writer, null, primitive, pktInfo);
|
||||
}
|
||||
|
||||
|
||||
//Serialize instanceMembers
|
||||
PSMemberInfoCollection<PSMemberInfo> instanceMembers = source.InstanceMembers;
|
||||
if (instanceMembers != null)
|
||||
@@ -607,16 +607,15 @@ namespace System.Management.Automation
|
||||
{
|
||||
object baseObject = source.ImmediateBaseObject;
|
||||
foreach (PSPropertyInfo prop in source.Properties)
|
||||
{
|
||||
{
|
||||
WriteOneObject(System.Convert.ChangeType(baseObject, Enum.GetUnderlyingType(baseObject.GetType()), System.Globalization.CultureInfo.InvariantCulture), prop.Name, depth);
|
||||
}
|
||||
|
||||
}
|
||||
else if (isPSObject)
|
||||
{
|
||||
if (firstobjectcall)
|
||||
if (_firstobjectcall)
|
||||
{
|
||||
firstobjectcall = false;
|
||||
_firstobjectcall = false;
|
||||
WritePSObjectProperties(source, depth);
|
||||
}
|
||||
else
|
||||
@@ -628,7 +627,7 @@ namespace System.Management.Automation
|
||||
{
|
||||
WritePSObjectProperties(source, depth);
|
||||
}
|
||||
|
||||
|
||||
_writer.WriteEndElement();
|
||||
}
|
||||
|
||||
@@ -646,7 +645,7 @@ namespace System.Management.Automation
|
||||
bool writeTNH)
|
||||
{
|
||||
Dbg.Assert(mshObject != null, "caller should validate the parameter");
|
||||
|
||||
|
||||
if (property != null)
|
||||
{
|
||||
WriteStartElement(_writer, CustomSerializationStrings.Properties);
|
||||
@@ -654,19 +653,19 @@ namespace System.Management.Automation
|
||||
}
|
||||
else
|
||||
{
|
||||
if (firstcall)
|
||||
if (_firstcall)
|
||||
{
|
||||
WriteStartElement(_writer, CustomSerializationStrings.PSObjectTag);
|
||||
firstcall = false;
|
||||
}
|
||||
_firstcall = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteStartElement(_writer, CustomSerializationStrings.Properties);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Object baseObject = mshObject.BaseObject;
|
||||
if(!_notypeinformation)
|
||||
if (!_notypeinformation)
|
||||
WriteAttribute(_writer, CustomSerializationStrings.TypeAttribute, baseObject.GetType().ToString());
|
||||
}
|
||||
|
||||
@@ -678,7 +677,7 @@ namespace System.Management.Automation
|
||||
/// <param name="source"></param>
|
||||
/// <returns>
|
||||
/// </returns>
|
||||
bool PSObjectHasNotes(PSObject source)
|
||||
private bool PSObjectHasNotes(PSObject source)
|
||||
{
|
||||
if (source.InstanceMembers != null && source.InstanceMembers.Count > 0)
|
||||
{
|
||||
@@ -719,7 +718,7 @@ namespace System.Management.Automation
|
||||
}
|
||||
|
||||
enclosingTagWritten = true;
|
||||
WriteStartElement(_writer, CustomSerializationStrings.Properties);
|
||||
WriteStartElement(_writer, CustomSerializationStrings.Properties);
|
||||
WriteAttribute(_writer, CustomSerializationStrings.NameAttribute, info.Name);
|
||||
if (!_notypeinformation)
|
||||
WriteAttribute(_writer, CustomSerializationStrings.TypeAttribute, info.GetType().ToString());
|
||||
@@ -761,7 +760,7 @@ namespace System.Management.Automation
|
||||
SerializeProperties(specificProperties, CustomSerializationStrings.Properties, depth);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
foreach (PSPropertyInfo prop in source.Properties)
|
||||
{
|
||||
Dbg.Assert(prop != null, "propertyCollection should only have member of type PSProperty");
|
||||
@@ -787,7 +786,6 @@ namespace System.Management.Automation
|
||||
WriteOneObject(value, prop.Name, depth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -848,7 +846,7 @@ namespace System.Management.Automation
|
||||
private void WriteEnumerable(IEnumerable enumerable, int depth)
|
||||
{
|
||||
Dbg.Assert(enumerable != null, "caller should validate the parameter");
|
||||
|
||||
|
||||
IEnumerator enumerator = null;
|
||||
try
|
||||
{
|
||||
@@ -887,7 +885,6 @@ namespace System.Management.Automation
|
||||
WriteOneObject(item, null, depth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -923,7 +920,7 @@ namespace System.Management.Automation
|
||||
|
||||
#region serialize as string
|
||||
|
||||
void HandlePSObjectAsString(PSObject source, string property, int depth)
|
||||
private void HandlePSObjectAsString(PSObject source, string property, int depth)
|
||||
{
|
||||
Dbg.Assert(source != null, "caller should validate the information");
|
||||
|
||||
@@ -940,7 +937,7 @@ namespace System.Management.Automation
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteOnePrimitiveKnownType(_writer, property,source.BaseObject, pktInfo);
|
||||
WriteOnePrimitiveKnownType(_writer, property, source.BaseObject, pktInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -968,7 +965,7 @@ namespace System.Management.Automation
|
||||
/// <returns>
|
||||
/// string value to use for serializing this PSObject.
|
||||
/// </returns>
|
||||
string GetStringFromPSObject(PSObject source)
|
||||
private string GetStringFromPSObject(PSObject source)
|
||||
{
|
||||
Dbg.Assert(source != null, "caller should have validated the information");
|
||||
|
||||
@@ -1014,7 +1011,7 @@ namespace System.Management.Automation
|
||||
/// </summary>
|
||||
/// <param name="source">PSObject to be serialized</param>
|
||||
/// <returns>true if the object needs to be serialized as a string</returns>
|
||||
static bool SerializeAsString(PSObject source)
|
||||
private static bool SerializeAsString(PSObject source)
|
||||
{
|
||||
return source.GetSerializationMethod(null) == SerializationMethod.String;
|
||||
}
|
||||
@@ -1027,7 +1024,7 @@ namespace System.Management.Automation
|
||||
/// <param name="source">PSObject whose serialization depth has to be computed</param>
|
||||
/// <param name="depth">current depth</param>
|
||||
/// <returns></returns>
|
||||
static int GetDepthOfSerialization(PSObject source, int depth)
|
||||
private static int GetDepthOfSerialization(PSObject source, int depth)
|
||||
{
|
||||
if (source == null)
|
||||
return depth;
|
||||
@@ -1051,7 +1048,6 @@ namespace System.Management.Automation
|
||||
/// <param name="property"></param>
|
||||
private void WriteNull(string property)
|
||||
{
|
||||
|
||||
if (property != null)
|
||||
{
|
||||
WriteStartElement(_writer, CustomSerializationStrings.Properties);
|
||||
@@ -1059,10 +1055,10 @@ namespace System.Management.Automation
|
||||
}
|
||||
else
|
||||
{
|
||||
if (firstcall)
|
||||
if (_firstcall)
|
||||
{
|
||||
WriteStartElement(_writer, CustomSerializationStrings.PSObjectTag);
|
||||
firstcall = false;
|
||||
_firstcall = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1076,14 +1072,14 @@ namespace System.Management.Automation
|
||||
#region known type serialization
|
||||
|
||||
private void WritePropertyWithNullValue(
|
||||
XmlWriter writer,PSPropertyInfo source, int depth)
|
||||
XmlWriter writer, PSPropertyInfo source, int depth)
|
||||
{
|
||||
WriteStartElement(writer, CustomSerializationStrings.Properties);
|
||||
WriteAttribute(writer, CustomSerializationStrings.NameAttribute, ((PSPropertyInfo)source).Name.ToString());
|
||||
if (!_notypeinformation)
|
||||
WriteAttribute(writer, CustomSerializationStrings.TypeAttribute, ((PSPropertyInfo)source).TypeNameOfValue.ToString());
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteObjectString(
|
||||
XmlWriter writer, string property, object source, TypeSerializationInfo entry)
|
||||
@@ -1095,10 +1091,10 @@ namespace System.Management.Automation
|
||||
}
|
||||
else
|
||||
{
|
||||
if (firstcall)
|
||||
if (_firstcall)
|
||||
{
|
||||
WriteStartElement(writer, CustomSerializationStrings.PSObjectTag);
|
||||
firstcall = false;
|
||||
_firstcall = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1120,7 +1116,7 @@ namespace System.Management.Automation
|
||||
/// <param name="property">name of property. Pass null for item</param>
|
||||
/// <param name="source">object to be written</param>
|
||||
/// <param name="entry">serialization information about source</param>
|
||||
|
||||
|
||||
private void WriteOnePrimitiveKnownType(
|
||||
XmlWriter writer, string property, object source, TypeSerializationInfo entry)
|
||||
{
|
||||
|
||||
+8
-7
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
namespace System.Management.Automation
|
||||
{
|
||||
/// <summary>
|
||||
@@ -8,14 +9,14 @@ namespace System.Management.Automation
|
||||
/// </summary>
|
||||
internal static class CustomSerializationStrings
|
||||
{
|
||||
#region element tags
|
||||
#region element tags
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Element tag for root node
|
||||
/// </summary>
|
||||
internal const string RootElementTag = "Objects";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Element tag for PSObject
|
||||
/// </summary>
|
||||
@@ -26,8 +27,8 @@ namespace System.Management.Automation
|
||||
/// </summary>
|
||||
internal const string Properties = "Property";
|
||||
|
||||
|
||||
#region attribute tags
|
||||
|
||||
#region attribute tags
|
||||
|
||||
/// <summary>
|
||||
/// String for name attribute
|
||||
@@ -38,7 +39,7 @@ namespace System.Management.Automation
|
||||
/// String for type attribute
|
||||
/// </summary>
|
||||
internal const string TypeAttribute = "Type";
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region known container tags
|
||||
@@ -55,6 +56,6 @@ namespace System.Management.Automation
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+15
-15
@@ -120,15 +120,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
switch (ParameterSetName)
|
||||
{
|
||||
case DebugRunspaceCommand.NameParameterSet:
|
||||
case DebugRunspaceCommand.NameParameterSet:
|
||||
runspaces = GetRunspaceUtils.GetRunspacesByName(new string[] { Name });
|
||||
break;
|
||||
|
||||
case DebugRunspaceCommand.IdParameterSet:
|
||||
case DebugRunspaceCommand.IdParameterSet:
|
||||
runspaces = GetRunspaceUtils.GetRunspacesById(new int[] { Id });
|
||||
break;
|
||||
|
||||
case DebugRunspaceCommand.InstanceIdParameterSet:
|
||||
case DebugRunspaceCommand.InstanceIdParameterSet:
|
||||
runspaces = GetRunspaceUtils.GetRunspacesByInstanceId(new Guid[] { InstanceId });
|
||||
break;
|
||||
}
|
||||
@@ -143,7 +143,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
this)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (runspaces.Count == 1)
|
||||
{
|
||||
_runspace = runspaces[0];
|
||||
@@ -209,7 +209,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Blocking call. Send runspace/command output to host UI while debugging and wait for runspace/command completion.
|
||||
WaitAndReceiveRunspaceOutput();
|
||||
}
|
||||
finally
|
||||
finally
|
||||
{
|
||||
RestoreRunspace(_runspace);
|
||||
}
|
||||
@@ -259,7 +259,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// Make sure host debugger has debugging turned on.
|
||||
_debugger.SetDebugMode(DebugModes.LocalScript | DebugModes.RemoteScript);
|
||||
|
||||
|
||||
// Set up host script debugger to debug the runspace.
|
||||
_debugger.DebugRunspace(_runspace);
|
||||
|
||||
@@ -338,14 +338,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
_runningPowerShell = _runspace.GetCurrentBasePowerShell();
|
||||
if (_runningPowerShell != null)
|
||||
{
|
||||
if (_runningPowerShell.OutputBuffer != null)
|
||||
{
|
||||
_runningPowerShell.OutputBuffer.DataAdding += HandlePowerShellOutputBufferDataAdding;
|
||||
}
|
||||
if (_runningPowerShell.ErrorBuffer != null)
|
||||
{
|
||||
_runningPowerShell.ErrorBuffer.DataAdding += HandlePowerShellErrorBufferDataAdding;
|
||||
}
|
||||
if (_runningPowerShell.OutputBuffer != null)
|
||||
{
|
||||
_runningPowerShell.OutputBuffer.DataAdding += HandlePowerShellOutputBufferDataAdding;
|
||||
}
|
||||
if (_runningPowerShell.ErrorBuffer != null)
|
||||
{
|
||||
_runningPowerShell.ErrorBuffer.DataAdding += HandlePowerShellErrorBufferDataAdding;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -416,7 +416,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
_debugBlockingCollection.Complete();
|
||||
}
|
||||
else if ((e.RunspaceAvailability == RunspaceAvailability.Busy) &&
|
||||
else if ((e.RunspaceAvailability == RunspaceAvailability.Busy) &&
|
||||
((prevAvailability == RunspaceAvailability.Available) || (prevAvailability == RunspaceAvailability.None)))
|
||||
{
|
||||
_newRunningScriptEvent.Set();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
using System.Management.Automation;
|
||||
|
||||
namespace Microsoft.PowerShell.Commands
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Management.Automation;
|
||||
@@ -151,5 +152,4 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -198,7 +198,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
[Parameter(Position = 1, ParameterSetName = CommonRunspaceCommandBase.ProcessNameParameterSet)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Scope = "member",
|
||||
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Scope = "member",
|
||||
Target = "Microsoft.PowerShell.Commands.CommonRunspaceCommandBase.#AppDomainName")]
|
||||
public string[] AppDomainName
|
||||
{
|
||||
@@ -291,7 +291,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
if (!string.IsNullOrEmpty(currentAppDomainName))
|
||||
{
|
||||
if(appDomainNames == null)
|
||||
if (appDomainNames == null)
|
||||
{
|
||||
appDomainNames = new List<string>();
|
||||
}
|
||||
@@ -360,7 +360,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// </summary>
|
||||
protected override void ProcessRecord()
|
||||
{
|
||||
if(this.ParameterSetName.Equals(CommonRunspaceCommandBase.ProcessNameParameterSet))
|
||||
if (this.ParameterSetName.Equals(CommonRunspaceCommandBase.ProcessNameParameterSet))
|
||||
{
|
||||
SetDebugPreferenceHelper(ProcessName, AppDomainName, true, "EnableRunspaceDebugCommandPersistDebugPreferenceFailure");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -52,21 +53,21 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return path;
|
||||
return _path;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
path = ".";
|
||||
_path = ".";
|
||||
}
|
||||
else
|
||||
{
|
||||
path = value;
|
||||
_path = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
private string path = ".";
|
||||
private string _path = ".";
|
||||
|
||||
/// <summary>
|
||||
/// The literal path of the file to export the aliases to.
|
||||
@@ -78,47 +79,47 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return path;
|
||||
return _path;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
path = ".";
|
||||
_path = ".";
|
||||
}
|
||||
else
|
||||
{
|
||||
path = value;
|
||||
isLiteralPath = true;
|
||||
_path = value;
|
||||
_isLiteralPath = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
private bool isLiteralPath = false;
|
||||
private bool _isLiteralPath = false;
|
||||
|
||||
/// <summary>
|
||||
/// The Name parameter for the command
|
||||
/// </summary>
|
||||
///
|
||||
[Parameter (Position = 1, ValueFromPipelineByPropertyName = true)]
|
||||
[Parameter(Position = 1, ValueFromPipelineByPropertyName = true)]
|
||||
public string[] Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return names;
|
||||
return _names;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
names = new string[] { "*" };
|
||||
_names = new string[] { "*" };
|
||||
}
|
||||
else
|
||||
{
|
||||
names = value;
|
||||
_names = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
private string[] names = new string[] { "*" };
|
||||
private string[] _names = new string[] { "*" };
|
||||
|
||||
/// <summary>
|
||||
/// If set to true, the alias that is set is passed to the
|
||||
@@ -130,15 +131,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return passThru;
|
||||
return _passThru;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
passThru = value;
|
||||
_passThru = value;
|
||||
}
|
||||
}
|
||||
private bool passThru;
|
||||
private bool _passThru;
|
||||
|
||||
/// <summary>
|
||||
/// Parameter that determines the format of the file created.
|
||||
@@ -149,14 +150,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return asFormat;
|
||||
return _asFormat;
|
||||
}
|
||||
set
|
||||
{
|
||||
asFormat = value;
|
||||
_asFormat = value;
|
||||
}
|
||||
}
|
||||
private ExportAliasFormat asFormat = ExportAliasFormat.Csv;
|
||||
private ExportAliasFormat _asFormat = ExportAliasFormat.Csv;
|
||||
|
||||
/// <summary>
|
||||
/// Property that sets append parameter.
|
||||
@@ -166,14 +167,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return append;
|
||||
return _append;
|
||||
}
|
||||
set
|
||||
{
|
||||
append = value;
|
||||
_append = value;
|
||||
}
|
||||
}
|
||||
private bool append;
|
||||
private bool _append;
|
||||
|
||||
/// <summary>
|
||||
/// Property that sets force parameter.
|
||||
@@ -183,14 +184,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return force;
|
||||
return _force;
|
||||
}
|
||||
set
|
||||
{
|
||||
force = value;
|
||||
_force = value;
|
||||
}
|
||||
}
|
||||
private bool force;
|
||||
private bool _force;
|
||||
|
||||
/// <summary>
|
||||
/// Property that prevents file overwrite.
|
||||
@@ -201,14 +202,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return noclobber;
|
||||
return _noclobber;
|
||||
}
|
||||
set
|
||||
{
|
||||
noclobber = value;
|
||||
_noclobber = value;
|
||||
}
|
||||
}
|
||||
private bool noclobber;
|
||||
private bool _noclobber;
|
||||
|
||||
/// <summary>
|
||||
/// The description that gets added to the file as a comment
|
||||
@@ -219,14 +220,14 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return description;
|
||||
return _description;
|
||||
}
|
||||
set
|
||||
{
|
||||
description = value;
|
||||
_description = value;
|
||||
}
|
||||
}
|
||||
private string description;
|
||||
private string _description;
|
||||
|
||||
/// <summary>
|
||||
/// The scope parameter for the command determines
|
||||
@@ -238,15 +239,15 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
get
|
||||
{
|
||||
return scope;
|
||||
return _scope;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
scope = value;
|
||||
_scope = value;
|
||||
}
|
||||
}
|
||||
private string scope;
|
||||
private string _scope;
|
||||
#endregion Parameters
|
||||
|
||||
#region Command code
|
||||
@@ -260,20 +261,20 @@ namespace Microsoft.PowerShell.Commands
|
||||
// First get the alias table (from the proper scope if necessary)
|
||||
IDictionary<string, AliasInfo> aliasTable = null;
|
||||
|
||||
if (!String.IsNullOrEmpty(scope))
|
||||
if (!String.IsNullOrEmpty(_scope))
|
||||
{
|
||||
// This can throw PSArgumentException and PSArgumentOutOfRangeException
|
||||
// but just let them go as this is terminal for the pipeline and the
|
||||
// exceptions are already properly adorned with an ErrorRecord.
|
||||
|
||||
aliasTable = SessionState.Internal.GetAliasTableAtScope(scope);
|
||||
aliasTable = SessionState.Internal.GetAliasTableAtScope(_scope);
|
||||
}
|
||||
else
|
||||
{
|
||||
aliasTable = SessionState.Internal.GetAliasTable();
|
||||
}
|
||||
|
||||
foreach (string aliasName in names)
|
||||
foreach (string aliasName in _names)
|
||||
{
|
||||
bool resultFound = false;
|
||||
|
||||
@@ -298,7 +299,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
if (SessionState.IsVisible(origin, tableEntry.Value))
|
||||
{
|
||||
resultFound = true;
|
||||
matchingAliases.Add(tableEntry.Value);
|
||||
_matchingAliases.Add(tableEntry.Value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +343,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// Now write out the aliases
|
||||
|
||||
foreach (AliasInfo alias in matchingAliases)
|
||||
foreach (AliasInfo alias in _matchingAliases)
|
||||
{
|
||||
string line = null;
|
||||
if (this.As == ExportAliasFormat.Csv)
|
||||
@@ -362,7 +363,6 @@ namespace Microsoft.PowerShell.Commands
|
||||
WriteObject(alias);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -377,7 +377,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <summary>
|
||||
/// Holds all the matching aliases for writing to the file
|
||||
/// </summary>
|
||||
private Collection<AliasInfo> matchingAliases = new Collection<AliasInfo>();
|
||||
private Collection<AliasInfo> _matchingAliases = new Collection<AliasInfo>();
|
||||
|
||||
private static string GetAliasLine(AliasInfo alias, string formatString)
|
||||
{
|
||||
@@ -412,17 +412,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
// Now write the description if there is one
|
||||
|
||||
if (description != null)
|
||||
if (_description != null)
|
||||
{
|
||||
// First we need to break up the description on newlines and add a
|
||||
// # for each line.
|
||||
|
||||
description = description.Replace("\n", "\n# ");
|
||||
_description = _description.Replace("\n", "\n# ");
|
||||
|
||||
// Now write out the description
|
||||
writer.WriteLine("#");
|
||||
writer.Write("# ");
|
||||
writer.WriteLine(description);
|
||||
writer.WriteLine(_description);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,7 +464,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
out file,
|
||||
out result,
|
||||
out readOnlyFileInfo,
|
||||
isLiteralPath
|
||||
_isLiteralPath
|
||||
);
|
||||
|
||||
return result;
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
using System;
|
||||
@@ -33,7 +34,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
internal Type GetValueType(PSObject liveObject, out object columnValue)
|
||||
{
|
||||
columnValue = GetValue(liveObject);
|
||||
if(columnValue != null && columnValue is IComparable)
|
||||
if (columnValue != null && columnValue is IComparable)
|
||||
{
|
||||
return columnValue.GetType();
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
using System;
|
||||
@@ -10,17 +11,17 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
internal class ExpressionColumnInfo : ColumnInfo
|
||||
{
|
||||
private MshExpression expression;
|
||||
private MshExpression _expression;
|
||||
|
||||
internal ExpressionColumnInfo(string staleObjectPropertyName, string displayName, MshExpression expression)
|
||||
: base(staleObjectPropertyName, displayName)
|
||||
{
|
||||
this.expression = expression;
|
||||
_expression = expression;
|
||||
}
|
||||
|
||||
internal override Object GetValue(PSObject liveObject)
|
||||
{
|
||||
List<MshExpressionResult> resList = expression.GetValues(liveObject);
|
||||
List<MshExpressionResult> resList = _expression.GetValues(liveObject);
|
||||
|
||||
if (resList.Count == 0)
|
||||
{
|
||||
|
||||
Loaded 100 of 953 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user