Remove dead code (#5066)

Code guarded by the following defines is ancient and has never been
used, so removing.
* RELATIONSHIP_SUPPORTED
* SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
* SUPPORTS_CMDLETPROVIDER_FILE
Also removed some unused platform dependent unsafe code.
This commit is contained in:
Jason Shirk
2017-10-09 17:28:10 -07:00
committed by Dongbo Wang
parent 590848cef4
commit 22662c8c56
12 changed files with 0 additions and 2254 deletions
@@ -30,21 +30,6 @@ namespace Microsoft.PowerShell.Commands
private const string childrenSet = "Items";
private const string literalChildrenSet = "LiteralItems";
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
/// <summary>
/// The string declaration for the -relationship parameter set.
/// </summary>
///
/// <remarks>
/// The "relationship" parameter set includes the following parameters:
/// -relationship
/// -property
/// </remarks>
///
private const string relationshipSet = "Relationship";
#endif
#region Command parameters
/// <summary>
@@ -214,51 +199,6 @@ namespace Microsoft.PowerShell.Commands
}
}
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
/// <summary>
/// Gets and sets the value of the Relationship parameter which determines
/// which relationship the targets should be retrieved for.
/// </summary>
///
[Parameter(
Mandatory = true,
ParameterSetName = relationshipSet,
ValueFromPipelineByPropertyName = true)]
public string[] Relationship
{
get
{
return relationships;
}
set
{
relationships = value;
}
}
private string[] relationships = new string[0];
/// <summary>
/// Gets or sets the property parameter which may provide guidance to the relationship
/// provider on which targets to return.
/// </summary>
///
[Parameter(ParameterSetName = relationshipSet, ValueFromPipelineByPropertyName = true)]
public string Property
{
get
{
return property;
}
set
{
property = value;
}
}
private string property = String.Empty;
#endif
/// <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
@@ -302,13 +242,6 @@ namespace Microsoft.PowerShell.Commands
}
break;
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
case relationshipSet:
// No possible dynamic parameters for the relationship set.
break;
#endif
default:
result = InvokeProvider.ChildItem.GetChildItemsDynamicParameters(path, Recurse, context);
break;
@@ -421,63 +354,6 @@ namespace Microsoft.PowerShell.Commands
break;
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
case relationshipSet:
foreach (string relationship in relationships)
{
Collection<string> results = null;
try
{
results =
InvokeProvider.Relationship.GetTargets(
relationship,
path,
property);
}
catch (PSArgumentException argException)
{
WriteError(
new ErrorRecord(
argException.ErrorRecord,
argException));
continue;
}
catch (ProviderNotFoundException providerNotFound)
{
WriteError(
new ErrorRecord(
providerNotFound.ErrorRecord,
providerNotFound));
continue;
}
foreach (string target in results)
{
// Create an PSObject with the result.
// Attach the relationship name as a note,
// and set "System.Management.Automation.RelationshipTarget"
// as the TreatAs.
PSObject result = PSObject.AsPSObject (target);
result.Properties.Add (
new PSNoteProperty (
"Relationship",
relationship));
Collection<string> treatAs = new Collection<string> ();
treatAs.Add (targetTreatAsType);
result.TypeNames = treatAs;
// Now write out the result
WriteObject (result);
}
}
break;
#endif
default:
Dbg.Diagnostics.Assert(
false,
@@ -487,11 +363,6 @@ namespace Microsoft.PowerShell.Commands
}
} // ProcessRecord
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
private const string targetTreatAsType = "System.Management.Automation.RelationshipTarget";
#endif
#endregion command code
} // class GetChildrenCommand
} // namespace Microsoft.PowerShell.Commands
@@ -745,22 +745,9 @@ namespace Microsoft.PowerShell.Commands
/// </summary>
private const string stackSet = "Stack";
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
/// <summary>
/// The string declaration for the Relationship parameter set in this command.
/// </summary>
private const string relationshipSet = "Relationship";
#endif
/// <summary>
/// Gets or sets the path property
/// </summary>
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
[Parameter(Position = 0, ParameterSetName = relationshipSet, ValueFromPipelineByPropertyName = true)]
#endif
[Parameter(Position = 0, ParameterSetName = pathSet,
ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public string Path
@@ -813,68 +800,6 @@ namespace Microsoft.PowerShell.Commands
[Parameter(ParameterSetName = stackSet, ValueFromPipelineByPropertyName = true)]
public string StackName { get; set; }
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
/// <summary>
/// Gets or sets the relationship Parameter which determines which relationship
/// to resolve to a path to set-location to.
/// </summary>
///
[Parameter(Mandatory = true, ParameterSetName = relationshipSet, ValueFromPipelineByPropertyName = true)]
public string Relationship
{
get
{
return relationship;
}
set
{
relationship = value;
}
}
private string relationship = String.Empty;
/// <summary>
/// Gets or sets the Property parameter value
/// </summary>
///
[Parameter(ParameterSetName = relationshipSet, ValueFromPipelineByPropertyName = true)]
public string Property
{
get
{
return property;
}
set
{
property = value;
}
}
private string property = String.Empty;
/// <summary>
/// Gets or sets the Target parameter value
/// </summary>
///
[Parameter (ParameterSetName = relationshipSet, ValueFromPipelineByPropertyName = true)]
public string Target
{
get
{
return target;
}
set
{
target = value;
}
}
private string target = String.Empty;
#endif
#endregion Command parameters
#region Command data
@@ -971,76 +896,6 @@ namespace Microsoft.PowerShell.Commands
break;
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
case relationshipSet:
string relationshipPath = null;
try
{
relationshipPath =
InvokeProvider.Relationship.Resolve(
Relationship,
Path,
Property,
Target);
}
catch (PSArgumentException argException)
{
WriteError(
new ErrorRecord(
argException.ErrorRecord,
argException));
return;
}
try
{
result = SessionState.Path.SetLocation (relationshipPath, CmdletProviderContext);
}
catch (PSNotSupportedException notSupported)
{
WriteError(
new ErrorRecord(
notSupported.ErrorRecord,
notSupported));
return;
}
catch (DriveNotFoundException driveNotFound)
{
WriteError(
new ErrorRecord(
driveNotFound.ErrorRecord,
driveNotFound));
return;
}
catch (ProviderNotFoundException providerNotFound)
{
WriteError(
new ErrorRecord(
providerNotFound.ErrorRecord,
providerNotFound));
return;
}
catch (PSArgumentException argException)
{
WriteError(
new ErrorRecord(
argException.ErrorRecord,
argException));
return;
}
catch (ItemNotFoundException pathNotFound)
{
WriteError(
new ErrorRecord(
pathNotFound.ErrorRecord,
pathNotFound));
return;
}
break;
#endif
default:
Dbg.Diagnostics.Assert(
false,
@@ -1070,18 +925,9 @@ namespace Microsoft.PowerShell.Commands
{
#region Command parameters
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
private const string relationshipSet = "Relationship";
#endif
/// <summary>
/// Gets or sets the path property
/// </summary>
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
[Parameter (Position = 0, ParameterSetName = relationshipSet, ValueFromPipelineByPropertyName = true)]
#endif
[Parameter(Position = 0, ParameterSetName = "Path",
ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public string Path
@@ -1139,10 +985,6 @@ namespace Microsoft.PowerShell.Commands
/// to use for the push. If the parameter is missing or empty the default
/// location stack is used.
/// </summary>
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
[Parameter (ParameterSetName = relationshipSet)]
#endif
[Parameter(ValueFromPipelineByPropertyName = true)]
public string StackName
{
@@ -1156,67 +998,6 @@ namespace Microsoft.PowerShell.Commands
} //set
} // StackName
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
/// <summary>
/// Gets or sets the relationship Parameter which determines which relationship
/// to resolve to a path to set-location to.
/// </summary>
///
[Parameter (Mandatory = true, ParameterSetName = relationshipSet, ValueFromPipelineByPropertyName = true)]
public string Relationship
{
get
{
return relationship;
}
set
{
relationship = value;
}
}
private string relationship = String.Empty;
/// <summary>
/// Gets or sets the Property parameter value
/// </summary>
///
[Parameter (ParameterSetName = relationshipSet, ValueFromPipelineByPropertyName = true)]
public string Property
{
get
{
return property;
}
set
{
property = value;
}
}
private string property = String.Empty;
/// <summary>
/// Gets or sets the Target parameter value
/// </summary>
///
[Parameter (ParameterSetName = relationshipSet, ValueFromPipelineByPropertyName = true)]
public string Target
{
get
{
return target;
}
set
{
target = value;
}
}
private string target = String.Empty;
#endif
#endregion Command parameters
#region Command data
@@ -1251,42 +1032,6 @@ namespace Microsoft.PowerShell.Commands
// working directory stack
SessionState.Path.PushCurrentLocation(_stackName);
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
if (String.Equals(
relationshipSet,
ParameterSetName,
StringComparison.OrdinalIgnoreCase))
{
try
{
Path =
InvokeProvider.Relationship.Resolve(
Relationship,
Path,
Property,
Target);
}
catch (ProviderNotFoundException providerNotFound)
{
WriteError(
new ErrorRecord(
providerNotFound.ErrorRecord,
providerNotFound));
return;
}
catch (PSArgumentException argException)
{
WriteError(
new ErrorRecord(
argException.ErrorRecord,
argException));
return;
}
}
#endif
if (Path != null)
{
try
@@ -50,15 +50,7 @@ namespace System.Management.Automation
ChildItem = new ChildItemCmdletProviderIntrinsics(cmdlet);
Content = new ContentCmdletProviderIntrinsics(cmdlet);
Property = new PropertyCmdletProviderIntrinsics(cmdlet);
#if SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
this.propertyValue = new PropertyValueCmdletProviderIntrinsics(cmdlet);
#endif
SecurityDescriptor = new SecurityDescriptorCmdletProviderIntrinsics(cmdlet);
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
this.relationship = new RelationshipProviderIntrinsics(cmdlet.Context.EngineSessionState);
#endif
} // ProviderIntrinsics internal
/// <summary>
@@ -80,15 +72,7 @@ namespace System.Management.Automation
ChildItem = new ChildItemCmdletProviderIntrinsics(sessionState);
Content = new ContentCmdletProviderIntrinsics(sessionState);
Property = new PropertyCmdletProviderIntrinsics(sessionState);
#if SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
this.propertyValue = new PropertyValueCmdletProviderIntrinsics(sessionState);
#endif
SecurityDescriptor = new SecurityDescriptorCmdletProviderIntrinsics(sessionState);
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
this.relationship = new RelationshipProviderIntrinsics(sessionState);
#endif
} // ProviderIntrinsics internal
#endregion Constructors
@@ -115,47 +99,17 @@ namespace System.Management.Automation
/// </summary>
public PropertyCmdletProviderIntrinsics Property { get; }
#if SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
/// <summary>
/// The object that exposes the verbs for the item propertyvalue for Cmdlet Providers
/// </summary>
///
public PropertyValueCmdletProviderIntrinsics PropertyValue
{
get { return propertyValue; }
}
#endif
/// <summary>
/// Gets the object that exposes the verbs for the SecurityDescriptor noun for Cmdlet Providers
/// </summary>
public SecurityDescriptorCmdletProviderIntrinsics SecurityDescriptor { get; }
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
/// <summary>
/// The object that exposes the verbs for the relationship providers
/// </summary>
///
public RelationshipProviderIntrinsics Relationship
{
get { return relationship; }
}
#endif
#endregion Public members
#region private data
private InternalCommand _cmdlet;
#if SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
private PropertyValueCmdletProviderIntrinsics propertyValue;
#endif
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
private RelationshipProviderIntrinsics relationship = null;
#endif
#endregion private data
} // ProviderIntrinsics
}
@@ -420,9 +420,6 @@ namespace System.Management.Automation
HelpFile = helpFile;
PSSnapIn = psSnapIn;
#if SUPPORTS_CMDLETPROVIDER_FILE
LoadProviderFromPath(path);
#endif
// Create the hidden drive. The name doesn't really
// matter since we are not adding this drive to a scope.
@@ -444,58 +441,6 @@ namespace System.Management.Automation
}
}
#if SUPPORTS_CMDLETPROVIDER_FILE
/// <summary>
/// Loads the provider from the specified path.
/// </summary>
///
/// <param name="path">
/// The path to a .cmdletprovider file to load the provider from.
/// </param>
///
/// <exception cref="ArgumentException">
/// If <paramref name="path"/> is null or empty.
/// </exception>
///
/// <exception cref="FileLoadException">
/// The file specified by <paramref name="path"/> could
/// not be loaded as an XML document.
/// </exception>
///
/// <exception cref="FormatException">
/// If <paramref name="path"/> refers to a file that does
/// not adhere to the appropriate CmdletProvider file format.
/// </exception>
///
private void LoadProviderFromPath(string path)
{
if (String.IsNullOrEmpty(path))
{
throw tracer.NewArgumentException("path");
}
Internal.CmdletProviderFileReader reader =
Internal.CmdletProviderFileReader.CreateCmdletProviderFileReader(path);
// Read the assembly info from the file
assemblyInfo = reader.AssemblyInfo;
// Read the type name from the file
providerImplementationClassName = reader.TypeName;
helpFile = reader.HelpFilePath;
// Read the capabilities from the file
capabilities = reader.Capabilities;
capabilitiesRead = true;
if (String.IsNullOrEmpty(name))
{
name = reader.Name;
}
} // LoadProviderFromPath
#endif
/// <summary>
/// Determines if the passed in name is either the fully-qualified pssnapin name or
/// short name of the provider.
@@ -485,20 +485,6 @@ namespace System.Management.Automation
return SessionStateEntryVisibility.Private;
}
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
/// <summary>
/// Gets the collection of relationship providers
/// </summary>
///
internal RelationshipProviderCollection Relationships
{
get { return relationships; }
}
private RelationshipProviderCollection relationships = null;
#endif
#endregion Private data
/// <summary>
@@ -1436,14 +1436,6 @@ namespace System.Management.Automation
}
}
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
// Make sure the delay-load relationships get updated for the new provider
relationships.ProcessDelayLoadRelationships (provider.Name);
#endif
// Now write out the result
return provider;
@@ -1761,13 +1753,6 @@ namespace System.Management.Automation
RemoveProviderFromCollection(provider);
ProvidersCurrentWorkingDrive.Remove(provider);
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
// Now make sure no relationship reference this provider
relationships.ProcessRelationshipsOnCmdletProviderRemoval (providerName);
#endif
}
}
} // RemoveProvider
@@ -35,12 +35,6 @@ namespace System.Management.Automation
}
_sessionState = sessionState;
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
this.relationship = new RelationshipProviderManagementIntrinsics (sessionState);
#endif
} // SessionState
/// <summary>
@@ -305,28 +299,6 @@ namespace System.Management.Automation
return (commandInfo.Visibility == SessionStateEntryVisibility.Public);
}
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
/// <summary>
/// The state APIs to access relationship providers in session state.
/// </summary>
///
public RelationshipProviderManagementIntrinsics Relationship
{
get
{
using (tracer.TraceProperty())
{
Dbg.Diagnostics.Assert (
relationship != null,
"The only constructor for this class should always set the relationship field");
return relationship;
} // TraceProperty
} // get
} // RelationshipProvider
#endif
#endregion Public methods
#region Internal methods
@@ -349,12 +321,6 @@ namespace System.Management.Automation
private PathIntrinsics _path;
private PSVariableIntrinsics _variable;
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
private RelationshipProviderManagementIntrinsics relationship = null;
#endif
#endregion private data
} // SessionStatePublic
@@ -86,15 +86,6 @@ namespace System.Management.Automation
/// </summary>
internal const string SessionState = "SessionState";
#if RELATIONSHIP_SUPPORTED
// 2004/11/24-JeffJon - Relationships have been removed from the Exchange release
/// <summary>
/// The file extension (including the dot) of the relationship provider description file
/// </summary>
internal const string RelationshipProviderFileExtension = ".relationshipprovider";
#endif
/// <summary>
/// The file extension (including the dot) of an PowerShell script file
/// </summary>
@@ -1,294 +0,0 @@
//
// NOTE: A vast majority of this code was copied from BCL in
// Namespace: System
//
using BCLDebug = System.Diagnostics.Debug;
using System.Runtime.ConstrainedExecution;
namespace Microsoft.PowerShell.Commands.Internal
{
//Only contains static methods. Does not require serialization
[System.Runtime.InteropServices.ComVisible(true)]
internal static class Buffer
{
// This is ported from the optimized CRT assembly in memchr.asm. The JIT generates
// pretty good code here and this ends up being within a couple % of the CRT asm.
// It is however cross platform as the CRT hasn't ported their fast version to 64-bit
// platforms.
//
internal static unsafe int IndexOfByte(byte* src, byte value, int index, int count)
{
BCLDebug.Assert(src != null, "src should not be null");
byte* pByte = src + index;
// Align up the pointer to sizeof(int).
while (((int)pByte & 3) != 0)
{
if (count == 0)
return -1;
else if (*pByte == value)
return (int)(pByte - src);
count--;
pByte++;
}
// Fill comparer with value byte for comparisons
//
// comparer = 0/0/value/value
uint comparer = (((uint)value << 8) + (uint)value);
// comparer = value/value/value/value
comparer = (comparer << 16) + comparer;
// Run through buffer until we hit a 4-byte section which contains
// the byte we're looking for or until we exhaust the buffer.
while (count > 3)
{
// Test the buffer for presence of value. comparer contains the byte
// replicated 4 times.
uint t1 = *(uint*)pByte;
t1 = t1 ^ comparer;
uint t2 = 0x7efefeff + t1;
t1 = t1 ^ 0xffffffff;
t1 = t1 ^ t2;
t1 = t1 & 0x81010100;
// if t1 is zero then these 4-bytes don't contain a match
if (t1 != 0)
{
// We've found a match for value, figure out which position it's in.
int foundIndex = (int)(pByte - src);
if (pByte[0] == value)
return foundIndex;
else if (pByte[1] == value)
return foundIndex + 1;
else if (pByte[2] == value)
return foundIndex + 2;
else if (pByte[3] == value)
return foundIndex + 3;
}
count -= 4;
pByte += 4;
}
// Catch any bytes that might be left at the tail of the buffer
while (count > 0)
{
if (*pByte == value)
return (int)(pByte - src);
count--;
pByte++;
}
// If we don't have a match return -1;
return -1;
}
internal static unsafe void ZeroMemory(byte* src, long len)
{
while (len-- > 0)
*(src + len) = 0;
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static unsafe void memcpy(byte* src, int srcIndex, byte[] dest, int destIndex, int len)
{
BCLDebug.Assert((srcIndex >= 0) && (destIndex >= 0) && (len >= 0), "Index and length must be non-negative!");
BCLDebug.Assert(dest.Length - destIndex >= len, "not enough bytes in dest");
// If dest has 0 elements, the fixed statement will throw an
// IndexOutOfRangeException. Special-case 0-byte copies.
if (len == 0)
return;
fixed (byte* pDest = dest)
{
memcpyimpl(src + srcIndex, pDest + destIndex, len);
}
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static unsafe void memcpy(byte[] src, int srcIndex, byte* pDest, int destIndex, int len)
{
BCLDebug.Assert((srcIndex >= 0) && (destIndex >= 0) && (len >= 0), "Index and length must be non-negative!");
BCLDebug.Assert(src.Length - srcIndex >= len, "not enough bytes in src");
// If dest has 0 elements, the fixed statement will throw an
// IndexOutOfRangeException. Special-case 0-byte copies.
if (len == 0)
return;
fixed (byte* pSrc = src)
{
memcpyimpl(pSrc + srcIndex, pDest + destIndex, len);
}
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static unsafe void memcpy(char* pSrc, int srcIndex, char* pDest, int destIndex, int len)
{
BCLDebug.Assert((srcIndex >= 0) && (destIndex >= 0) && (len >= 0), "Index and length must be non-negative!");
// No boundary check for buffer overruns - dangerous
if (len == 0)
return;
memcpyimpl((byte*)(char*)(pSrc + srcIndex), (byte*)(char*)(pDest + destIndex), len * 2);
}
// Note - using a long instead of an int for the length parameter
// slows this method down by ~18%.
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static unsafe void memcpyimpl(byte* src, byte* dest, int len)
{
BCLDebug.Assert(len >= 0, "Negative length in memcopy!");
// It turns out that on AMD64 it is faster to not be careful of alignment issues.
// On IA64 it is necessary to be careful... Oh well. When we do the IA64 push we
// can work on this implementation.
#if IA64
long dstAlign = 8 - (((long)dest) & 7); // number of bytes to copy before dest is 8-byte aligned
while ((dstAlign > 0) && (len > 0))
{
*dest++ = *src++;
len--;
dstAlign--;
}
long srcAlign = 8 - (((long)src) & 7);
if (len > 0)
{
if (srcAlign != 8)
{
if (4 == srcAlign)
{
while (len >= 4)
{
((int*)dest)[0] = ((int*)src)[0];
dest += 4;
src += 4;
len -= 4;
}
srcAlign = 2; // fall through to 2-byte copies
}
if ((2 == srcAlign) || (6 == srcAlign))
{
while (len >= 2)
{
((short*)dest)[0] = ((short*)src)[0];
dest += 2;
src += 2;
len -= 2;
}
}
while (len-- > 0)
{
*dest++ = *src++;
}
}
else
{
if (len >= 16)
{
do
{
((long*)dest)[0] = ((long*)src)[0];
((long*)dest)[1] = ((long*)src)[1];
dest += 16;
src += 16;
} while ((len -= 16) >= 16);
}
if (len > 0) // protection against negative len and optimization for len==16*N
{
if ((len & 8) != 0)
{
((long*)dest)[0] = ((long*)src)[0];
dest += 8;
src += 8;
}
if ((len & 4) != 0)
{
((int*)dest)[0] = ((int*)src)[0];
dest += 4;
src += 4;
}
if ((len & 2) != 0)
{
((short*)dest)[0] = ((short*)src)[0];
dest += 2;
src += 2;
}
if ((len & 1) != 0)
{
*dest++ = *src++;
}
}
}
}
#else
// AMD64 implementation uses longs instead of ints where possible
//
// <STRIP>This is a faster memcpy implementation, from
// COMString.cpp. For our strings, this beat the processor's
// repeat & move single byte instruction, which memcpy expands into.
// (You read that correctly.)
// This is 3x faster than a simple while loop copying byte by byte,
// for large copies.</STRIP>
if (len >= 16)
{
do
{
#if AMD64
((long*)dest)[0] = ((long*)src)[0];
((long*)dest)[1] = ((long*)src)[1];
#else
((int*)dest)[0] = ((int*)src)[0];
((int*)dest)[1] = ((int*)src)[1];
((int*)dest)[2] = ((int*)src)[2];
((int*)dest)[3] = ((int*)src)[3];
#endif
dest += 16;
src += 16;
} while ((len -= 16) >= 16);
}
if (len > 0) // protection against negative len and optimization for len==16*N
{
if ((len & 8) != 0)
{
#if AMD64
((long*)dest)[0] = ((long*)src)[0];
#else
((int*)dest)[0] = ((int*)src)[0];
((int*)dest)[1] = ((int*)src)[1];
#endif
dest += 8;
src += 8;
}
if ((len & 4) != 0)
{
((int*)dest)[0] = ((int*)src)[0];
dest += 4;
src += 4;
}
if ((len & 2) != 0)
{
((short*)dest)[0] = ((short*)src)[0];
dest += 2;
src += 2;
}
if ((len & 1) != 0)
*dest++ = *src++;
}
#endif // IA64
}
}
}
@@ -495,483 +495,6 @@ namespace System.Management.Automation.Provider
#endregion IPropertyCmdletProvider
#if SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
#region IMultivaluePropertyCmdletProvider
/// <summary>
/// Internal wrapper for the GetPropertyAt protected method. This method will
/// only be called if the provider implements the IPropertyCmdletProvider interface.
/// </summary>
///
/// <param name="path">
/// The path to the item to retrieve property from.
/// </param>
///
/// <param name="propertyName">
/// The property that should be retrieved.
/// </param>
///
/// <param name="index">
/// The index of the value to be retrieved from the property.
/// </param>
///
/// <param name="cmdletProviderContext">
/// The context under which this method is being called.
/// </param>
///
internal void GetPropertyValueAt(
string path,
string propertyName,
object index,
CmdletProviderContext cmdletProviderContext)
{
Context = cmdletProviderContext;
IMultivaluePropertyCmdletProvider propertyProvider =
this as IMultivaluePropertyCmdletProvider;
if (propertyProvider == null)
{
throw
providerBaseTracer.NewNotSupportedException(
"SessionStateStrings",
"IMultivaluePropertyCmdletProvider_NotSupported");
}
// Call interface method
propertyProvider.GetPropertyValueAt(path, propertyName, index);
} // GetPropertyValueAt
/// <summary>
/// Gives the provider a chance to attach additional parameters to
/// the get-propertyvalue -at cmdlet.
/// </summary>
///
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
///
/// <param name="propertyName">
/// The property that should be retrieved.
/// </param>
///
/// <param name="at">
/// The index of the value to be retrieved from the property.
/// </param>
///
/// <param name="cmdletProviderContext">
/// The context under which this method is being called.
/// </param>
///
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
///
internal object GetPropertyValueAtDynamicParameters(
string path,
string propertyName,
object at,
CmdletProviderContext cmdletProviderContext)
{
Context = cmdletProviderContext;
IMultivaluePropertyCmdletProvider propertyProvider = this as IMultivaluePropertyCmdletProvider;
if (propertyProvider == null)
{
return null;
}
return propertyProvider.GetPropertyValueAtDynamicParameters(path, propertyName, at);
} // GetPropertyValueAtDynamicParameters
/// <summary>
/// Sets the specified properties of the item at the specified path at the specified
/// position if the property is a multivalued property.
/// </summary>
///
/// <param name="path">
/// The path to the item to set the properties on.
/// </param>
///
/// <param name="position">
/// The position to place the new value of the property.
/// </param>
///
/// <param name="propertyValue">
/// A PSObject which contains a collection of the name, type, value
/// of the properties to be set.
/// </param>
///
/// <param name="cmdletProviderContext">
/// The context under which this method is being called.
/// </param>
///
/// <returns>
/// Nothing. An instance of PSObject representing the properties that were set
/// should be passed to the WriteObject() method.
/// </returns>
///
internal void SetPropertyValueAt(
string path,
object position,
PSObject propertyValue,
CmdletProviderContext cmdletProviderContext)
{
Context = cmdletProviderContext;
IMultivaluePropertyCmdletProvider propertyProvider =
this as IMultivaluePropertyCmdletProvider;
if (propertyProvider == null)
{
throw
providerBaseTracer.NewNotSupportedException(
"SessionStateStrings",
"IMultivaluePropertyCmdletProvider_NotSupported");
}
// Call interface method
propertyProvider.SetPropertyValueAt(path, position, propertyValue);
} // SetPropertyValueAt
/// <summary>
/// Gives the provider a chance to attach additional parameters to
/// the set-propertyvalue -at cmdlet.
/// </summary>
///
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
///
/// <param name="at">
/// The position to place the new value of the property.
/// </param>
///
/// <param name="propertyValue">
/// A PSObject which contains a collection of the name, type, value
/// of the properties to be added.
/// </param>
///
/// <param name="cmdletProviderContext">
/// The context under which this method is being called.
/// </param>
///
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
///
internal object SetPropertyValueAtDynamicParameters(
string path,
object at,
PSObject propertyValue,
CmdletProviderContext cmdletProviderContext)
{
Context = cmdletProviderContext;
IMultivaluePropertyCmdletProvider propertyProvider = this as IMultivaluePropertyCmdletProvider;
if (propertyProvider == null)
{
return null;
}
return propertyProvider.SetPropertyValueAtDynamicParameters(path, at, propertyValue);
} // SetPropertyValueAtDynamicParameters
/// <summary>
/// Internal wrapper for the ClearPropertyAt protected method. This method will
/// only be called if the provider implements the
/// IMultivaluePropertyCmdletProvider interface.
/// </summary>
///
/// <param name="path">
/// The path to the item from which the property should be cleared.
/// </param>
///
/// <param name="propertyName">
/// The name of the property that should be cleared.
/// </param>
///
/// <param name="at">
/// The position of the value of the property to be cleared.
/// </param>
///
/// <param name="cmdletProviderContext">
/// The context under which this method is being called.
/// </param>
///
/// <remarks>
/// Implement this method when you are providing access to a data store
/// that allows dynamic clearing of properties.
/// </remarks>
///
internal void ClearPropertyValueAt(
string path,
string propertyName,
object at,
CmdletProviderContext cmdletProviderContext)
{
Context = cmdletProviderContext;
IMultivaluePropertyCmdletProvider propertyProvider =
this as IMultivaluePropertyCmdletProvider;
if (propertyProvider == null)
{
throw
providerBaseTracer.NewNotSupportedException(
"SessionStateStrings",
"IMultivaluePropertyCmdletProvider_NotSupported");
}
// Call interface method
propertyProvider.ClearPropertyValueAt(path, propertyName, at);
} // ClearPropertyValueAt
/// <summary>
/// Gives the provider a chance to attach additional parameters to
/// the clear-propertyvalue -at cmdlet.
/// </summary>
///
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
///
/// <param name="propertyName">
/// The name of the property that should be cleared.
/// </param>
///
/// <param name="at">
/// The position of the value of the property to be cleared.
/// </param>
///
/// <param name="cmdletProviderContext">
/// The context under which this method is being called.
/// </param>
///
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
///
internal object ClearPropertyValueAtDynamicParameters(
string path,
string propertyName,
object at,
CmdletProviderContext cmdletProviderContext)
{
Context = cmdletProviderContext;
IMultivaluePropertyCmdletProvider propertyProvider = this as IMultivaluePropertyCmdletProvider;
if (propertyProvider == null)
{
return null;
}
return propertyProvider.ClearPropertyValueAtDynamicParameters(path, propertyName, at);
} // ClearPropertyValueAtDynamicParameters
/// <summary>
/// Internal wrapper for the RemovePropertyValueAt protected method. This method will
/// only be called if the provider implements the
/// IMultivaluePropertyCmdletProvider interface.
/// </summary>
///
/// <param name="path">
/// The path to the item from which the property value should be removed.
/// </param>
///
/// <param name="propertyName">
/// The name of the property that the value should be remove from.
/// </param>
///
/// <param name="at">
/// The position of the value of the property to be removed.
/// </param>
///
/// <param name="cmdletProviderContext">
/// The context under which this method is being called.
/// </param>
///
/// <remarks>
/// Implement this method when you are providing access to a data store
/// that allows dynamic removing of property values.
/// </remarks>
///
internal void RemovePropertyValueAt(
string path,
string propertyName,
object at,
CmdletProviderContext cmdletProviderContext)
{
Context = cmdletProviderContext;
IMultivaluePropertyCmdletProvider propertyProvider =
this as IMultivaluePropertyCmdletProvider;
if (propertyProvider == null)
{
throw
providerBaseTracer.NewNotSupportedException(
"SessionStateStrings",
"IMultivaluePropertyCmdletProvider_NotSupported");
}
// Call interface method
propertyProvider.RemovePropertyValueAt(path, propertyName, at);
} // RemovePropertyValueAt
/// <summary>
/// Gives the provider a chance to attach additional parameters to
/// the remove-propertyvalue -at cmdlet.
/// </summary>
///
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
///
/// <param name="propertyName">
/// The name of the property that the value should be remove from.
/// </param>
///
/// <param name="at">
/// The position of the value of the property to be removed.
/// </param>
///
/// <param name="cmdletProviderContext">
/// The context under which this method is being called.
/// </param>
///
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
///
internal object RemovePropertyValueAtDynamicParameters(
string path,
string propertyName,
object at,
CmdletProviderContext cmdletProviderContext)
{
Context = cmdletProviderContext;
IMultivaluePropertyCmdletProvider propertyProvider = this as IMultivaluePropertyCmdletProvider;
if (propertyProvider == null)
{
return null;
}
return propertyProvider.RemovePropertyValueAtDynamicParameters(path, propertyName, at);
} // RemovePropertyValueAtDynamicParameters
/// <summary>
/// Adds the specified properties of the item at the specified path at the specified
/// position if the property is a multivalued property.
/// </summary>
///
/// <param name="path">
/// The path to the item to add the property to.
/// </param>
///
/// <param name="position">
/// The position to place the new value of the property.
/// </param>
///
/// <param name="propertyValue">
/// A PSObject which contains a collection of the name, type, value
/// of the properties to be added.
/// </param>
///
/// <param name="cmdletProviderContext">
/// The context under which this method is being called.
/// </param>
///
/// <returns>
/// Nothing. An instance of PSObject representing the properties that were set
/// should be passed to the WriteObject() method.
/// </returns>
///
internal void AddPropertyValueAt(
string path,
object position,
PSObject propertyValue,
CmdletProviderContext cmdletProviderContext)
{
Context = cmdletProviderContext;
IMultivaluePropertyCmdletProvider propertyProvider =
this as IMultivaluePropertyCmdletProvider;
if (propertyProvider == null)
{
throw
providerBaseTracer.NewNotSupportedException(
"SessionStateStrings",
"IMultivaluePropertyCmdletProvider_NotSupported");
}
// Call interface method
propertyProvider.AddPropertyValueAt(path, position, propertyValue);
} // AddPropertyValueAt
/// <summary>
/// Gives the provider a chance to attach additional parameters to
/// the add-propertyvalue -at cmdlet.
/// </summary>
///
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
///
/// <param name="at">
/// The position to place the new value of the property.
/// </param>
///
/// <param name="propertyValue">
/// A PSObject which contains a collection of the name, type, value
/// of the properties to be added.
/// </param>
///
/// <param name="cmdletProviderContext">
/// The context under which this method is being called.
/// </param>
///
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
///
internal object AddPropertyValueAtDynamicParameters(
string path,
object at,
PSObject propertyValue,
CmdletProviderContext cmdletProviderContext)
{
Context = cmdletProviderContext;
IMultivaluePropertyCmdletProvider propertyProvider = this as IMultivaluePropertyCmdletProvider;
if (propertyProvider == null)
{
return null;
}
return propertyProvider.AddPropertyValueAtDynamicParameters(path, at, propertyValue);
} // AddPropertyValueAtDynamicParameters
#endregion IMultivaluePropertyCmdletProvider
#endif // SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
#region IDynamicPropertyCmdletProvider
/// <summary>
@@ -2354,58 +1877,6 @@ namespace System.Management.Automation.Provider
Context.WriteObject(result);
} // WriteObject
#if SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
/// <summary>
/// Converts the incoming object to a PSObject and then adds extra
/// data as notes. Then it writes the shell object to the context.
/// </summary>
///
/// <param name="item">
/// The value of the property being written out.
/// </param>
///
/// <param name="path">
/// The path of the item being written out.
/// </param>
///
/// <param name="propertyName">
/// The name of the property the value came from.
/// </param>
///
/// <param name="position">
/// The position in the property they value came from.
/// </param>
///
private void WriteObject(
object item,
string path,
string propertyName,
object position)
{
PSObject result = WrapOutputInPSObject(item, path);
// Now add the property
PSNoteProperty propertyToAdd = new PSNoteProperty("PSProperty", propertyName);
result.Properties.Add(propertyToAdd);
providerBaseTracer.WriteLine("Attaching {0} = {1}", "PSProperty", propertyName);
// Now add the position
propertyToAdd = new PSNoteProperty("MshAt", position);
result.Properties.Add(propertyToAdd);
providerBaseTracer.WriteLine("Attaching {0} = {1}", "MshAt", position);
Diagnostics.Assert (
Context != null,
"The context should always be set");
Context.WriteObject(result);
} // WriteObject
#endif // SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
/// <summary>
/// Converts the incoming object to a PSObject and then adds extra
/// data as notes. Then it writes the shell object to the context.
@@ -2636,50 +2107,6 @@ namespace System.Management.Automation.Provider
}
} // WriteSecurityDescriptorObject
#if SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
/// <summary>
/// Writes a property value object to the output as a PSObject with extra data attached
/// as notes.
/// </summary>
///
/// <param name="item">
/// The value of the property to be written.
/// </param>
///
/// <param name="path">
/// The path of the item being written.
/// </param>
///
/// <param name="propertyName">
/// The properties to be written.
/// </param>
///
/// <param name="position">
/// The position at which the property value was retrieved or written.
/// </param>
///
/// <remarks>
/// If streaming is on and the writeObjectHandler was specified then the object
/// gets written to the writeObjectHandler. If streaming is on and the writeObjectHandler
/// was not specified and the command object was specified, the object gets written to
/// the WriteObject method of the command object.
/// If streaming is off the object gets written to an accumulator collection. The collection
/// of written object can be retrieved using the AccumulatedObjects method.
/// </remarks>
///
public void WritePropertyValueObject(
object item,
string path,
string propertyName,
object position)
{
using(PSTransactionManager.GetEngineProtectionScope())
{
WriteObject(item, path, propertyName, position);
}
} // WritePropertyValueObject
#endif
/// <Content contentref="System.Management.Automation.Cmdlet.WriteError" />
public void WriteError(ErrorRecord errorRecord)
{
@@ -64,9 +64,6 @@ namespace Microsoft.PowerShell.Commands
public sealed partial class RegistryProvider :
NavigationCmdletProvider,
IPropertyCmdletProvider,
#if SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
IMultivaluePropertyCmdletProvider,
#endif
IDynamicPropertyCmdletProvider,
ISecurityDescriptorCmdletProvider
{
@@ -2133,830 +2130,6 @@ namespace Microsoft.PowerShell.Commands
#endregion IPropertyCmdletProvider
#if SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
#region IMultivaluePropertyCmdletProvider
/// <summary>
/// Gets a value of a property from the item specified by the path.
/// </summary>
///
/// <param name="path">
/// The path to the item from which the property value should be retrieved.
/// </param>
///
/// <param name="propertyName">
/// The property to get the value from.
/// </param>
///
/// <param name="at">
/// The position of the property to get.
/// </param>
///
/// <returns>
/// Nothing. A PSObject representing the property and value that was
/// retrieved should be passed to the WriteObject() method.
/// </returns>
///
/// <remarks>
/// Implement this method when you are providing access to a data store
/// that allows multivalued properties.
/// </remarks>
///
public void GetPropertyValueAt(
string path,
string propertyName,
object at)
{
if (path == null)
{
throw tracer.NewArgumentNullException("path");
}
if (!CheckOperationNotAllowedOnHiveContainer(path))
{
return;
}
IRegistryWrapper key = GetRegkeyForPathWriteIfError(path, false);
if (key == null)
{
return;
}
// Convert the at parameter to an int
int index = GetIndexFromAt(at);
if (index == -1)
{
// The key was not found, write out an error.
ArgumentException exception =
new ArgumentException(
RegistryProviderStrings.BadAtParam;
WriteError (new ErrorRecord (exception, exception.GetType().FullName, ErrorCategory.InvalidArgument, path));
return;
}
PSObject propertyResults = new PSObject();
try
{
string valueName = propertyName;
// Need to convert the default value name to "(default)"
if (String.IsNullOrEmpty(valueName))
{
valueName = GetLocalizedDefaultToken();
}
object resultValue = key.GetValue(valueName);
if (resultValue != null)
{
if (resultValue is IList &&
at != null)
{
resultValue = ((IList)resultValue)[index];
}
propertyResults.Properties.Add(new PSNoteProperty(valueName, resultValue));
WritePropertyObject(propertyResults, path);
}
}
catch (System.IO.IOException ioException)
{
// An exception occurred while trying to get the key. Write
// out the error.
WriteError (new ErrorRecord (ioException, ioException.GetType().FullName, ErrorCategory.ReadError, path));
}
catch (System.Security.SecurityException securityException)
{
// An exception occurred while trying to get the key. Write
// out the error.
WriteError (new ErrorRecord (securityException, securityException.GetType().FullName, ErrorCategory.PermissionDenied, path));
}
catch (System.UnauthorizedAccessException unauthorizedAccessException)
{
// An exception occurred while trying to get the key. Write
// out the error.
WriteError (new ErrorRecord (unauthorizedAccessException, unauthorizedAccessException.GetType().FullName, ErrorCategory.PermissionDenied, path));
}
} // GetPropertyValueAt
/// <summary>
/// Sets a property value on the item specified by the path.
/// </summary>
///
/// <param name="path">
/// The path to the item on which the property should be set.
/// </param>
///
/// <param name="at">
/// The position of the property to set.
/// </param>
///
/// <param name="propertyValue">
/// The property to set the value on.
/// </param>
///
/// <returns>
/// Nothing. A PSObject representing the property and value that was
/// set should be passed to the WriteObject() method.
/// </returns>
///
/// <remarks>
/// Implement this method when you are providing access to a data store
/// that allows multivalued properties.
/// </remarks>
///
public void SetPropertyValueAt(
string path,
object at,
PSObject propertyValue)
{
if (path == null)
{
throw tracer.NewArgumentNullException("path");
}
if (!CheckOperationNotAllowedOnHiveContainer(path))
{
return;
}
if (propertyValue == null)
{
throw tracer.NewArgumentNullException("propertyValue");
}
// Convert the at parameter to an int
int index = GetIndexFromAt(at);
if (index == -1)
{
// The key was not found, write out an error.
ArgumentException exception =
new ArgumentException(
RegistryProviderStrings.BadAtParam;
WriteError (new ErrorRecord (exception, exception.GetType().FullName, ErrorCategory.InvalidArgument, path));
return;
}
IRegistryWrapper key = GetRegkeyForPathWriteIfError(path, true);
if (key == null)
{
return;
}
string action =
RegistryProviderStrings.SetPropertyValueAtAction;
string resourceTemplate =
RegistryProviderStrings.SetPropertyValueAtResourceTemplate;
foreach (PSMemberInfo property in propertyValue.Properties)
{
try
{
object newPropertyValue = property.Value;
string resource =
String.Format(
Host.CurrentCulture,
resourceTemplate,
path,
property.Name,
at);
if (ShouldProcess(resource, action))
{
string propertyNameToSet = GetPropertyName(property.Name);
// First get the current value
object currentValue = key.GetValue(propertyNameToSet);
if (currentValue != null &&
currentValue is IList)
{
((IList)currentValue)[index] = newPropertyValue;
}
else
{
currentValue = newPropertyValue;
}
key.SetValue(propertyNameToSet, currentValue);
// Now write out the value by getting the value from the store
object value = key.GetValue(propertyNameToSet);
PSObject result = new PSObject();
result.Properties.Add(new PSNoteProperty(property.Name, newPropertyValue));
WritePropertyObject(result, path);
}
}
catch (System.IO.IOException ioException)
{
// An exception occurred while trying to set the value. Write
// out the error.
WriteError (new ErrorRecord (ioException, ioException.GetType().FullName, ErrorCategory.WriteError, property.Name));
continue;
}
catch (System.Security.SecurityException securityException)
{
// An exception occurred while trying to set the value. Write
// out the error.
WriteError (new ErrorRecord (securityException, securityException.GetType().FullName, ErrorCategory.PermissionDenied, property.Name));
continue;
}
catch (System.UnauthorizedAccessException unauthorizedAccessException)
{
// An exception occurred while trying to get the key. Write
// out the error.
WriteError (new ErrorRecord (unauthorizedAccessException, unauthorizedAccessException.GetType().FullName, ErrorCategory.PermissionDenied, property.Name));
continue;
}
}
} // SetPropertyValueAt
/// <summary>
/// Clears the specified value of a property on the item specified by the path.
/// </summary>
///
/// <param name="path">
/// The path to the item from which the property value should be cleared.
/// </param>
///
/// <param name="propertyName">
/// The property to clear the value from.
/// </param>
///
/// <param name="at">
/// The position of the property to clear.
/// </param>
///
/// <returns>
/// Nothing. A PSObject representing the property and value that was
/// retrieved should be passed to the WriteObject() method.
/// </returns>
///
/// <remarks>
/// Implement this method when you are providing access to a data store
/// that allows multivalued properties.
/// </remarks>
///
public void ClearPropertyValueAt(
string path,
string propertyName,
object at)
{
throw tracer.NewNotImplementedException();
}
/// <summary>
/// Removes the specified value of a property on the item specified by the path.
/// </summary>
///
/// <param name="path">
/// The path to the item from which the property value should be removed.
/// </param>
///
/// <param name="propertyName">
/// The property to remove the value from.
/// </param>
///
/// <param name="at">
/// The position of the property value to remove.
/// </param>
///
/// <returns>
/// Nothing. A PSObject representing the property and value that was
/// removed should be passed to the WriteObject() method.
/// </returns>
///
/// <remarks>
/// Implement this method when you are providing access to a data store
/// that allows multivalued properties.
/// </remarks>
///
public void RemovePropertyValueAt(
string path,
string propertyName,
object at)
{
if (path == null)
{
throw tracer.NewArgumentNullException("path");
}
if (!CheckOperationNotAllowedOnHiveContainer(path))
{
return;
}
// Convert the at parameter to an int
int index = GetIndexFromAt(at);
if (index == -1)
{
// The key was not found, write out an error.
ArgumentException exception =
new ArgumentException(
RegistryProviderStrings.BadAtParam);
WriteError (new ErrorRecord (exception, exception.GetType().FullName, ErrorCategory.InvalidArgument, path));
return;
}
IRegistryWrapper key = GetRegkeyForPathWriteIfError(path, true);
if (key == null)
{
return;
}
string action = RegistryProviderStrings.RemovePropertyValueAtAction;
string resourceTemplate = RegistryProviderStrings.RemovePropertyValueAtResourceTemplate;
string resource =
String.Format(
Host.CurrentCulture,
resourceTemplate,
path,
propertyName,
at);
if (ShouldProcess(resource, action))
{
try
{
string propertyNameToRemove = GetPropertyName(propertyName);
// First get the current value
object currentValue = key.GetValue(propertyNameToRemove);
if (currentValue != null &&
currentValue is string[])
{
ArrayList newValueArrayList = new ArrayList((string[])currentValue);
newValueArrayList.RemoveAt(index);
currentValue = newValueArrayList.ToArray(typeof(string));
}
else if (currentValue != null &&
currentValue is byte[])
{
ArrayList newValueArrayList = new ArrayList((byte[])currentValue);
newValueArrayList.RemoveAt(index);
currentValue = newValueArrayList.ToArray(typeof(byte));
}
else
{
Exception e =
new ArgumentException (
RegistryProviderStrings.PropertyNotMultivalued);
WriteError (new ErrorRecord (
e,
e.GetType().FullName,
ErrorCategory.InvalidOperation,
propertyNameToRemove));
return;
}
key.SetValue(propertyNameToRemove, currentValue);
}
catch (System.IO.IOException ioException)
{
// An exception occurred while trying to set the value. Write
// out the error.
WriteError (new ErrorRecord (ioException, ioException.GetType().FullName, ErrorCategory.WriteError, propertyName));
}
catch (System.Security.SecurityException securityException)
{
// An exception occurred while trying to set the value. Write
// out the error.
WriteError (new ErrorRecord (securityException, securityException.GetType().FullName, ErrorCategory.PermissionDenied, propertyName));
}
catch (System.UnauthorizedAccessException unauthorizedAccessException)
{
// An exception occurred while trying to get the key. Write
// out the error.
WriteError (new ErrorRecord (unauthorizedAccessException, unauthorizedAccessException.GetType().FullName, ErrorCategory.PermissionDenied, propertyName));
}
}
} // RemovePropertyValueAt
/// <summary>
/// Adds a property value on the item specified by the path.
/// </summary>
///
/// <param name="path">
/// The path to the item on which the property should be added.
/// </param>
///
/// <param name="at">
/// The position of the property to add.
/// </param>
///
/// <param name="propertyValue">
/// The property to add the value on.
/// </param>
///
/// <returns>
/// Nothing. A PSObject representing the property and value that was
/// added should be passed to the WriteObject() method.
/// </returns>
///
/// <remarks>
/// Implement this method when you are providing access to a data store
/// that allows multivalued properties.
/// </remarks>
///
public void AddPropertyValueAt(
string path,
object at,
PSObject propertyValue)
{
if (path == null)
{
throw tracer.NewArgumentNullException("path");
}
if (!CheckOperationNotAllowedOnHiveContainer(path))
{
return;
}
if (propertyValue == null)
{
throw tracer.NewArgumentNullException("propertyValue");
}
// Convert the at parameter to an int
int index = GetIndexFromAt(at);
IRegistryWrapper key = GetRegkeyForPathWriteIfError(path, true);
if (key == null)
{
return;
}
string action = RegistryProviderStrings.AddPropertyValueAtAction;
string resourceTemplate = RegistryProviderStrings.AddPropertyValueAtResourceTemplate;
PSMemberInfoCollection properties = null;
try
{
properties = propertyValue.Properties;
}
catch (System.IO.IOException ioException)
{
// An exception occurred while trying to get the key. Write
// out the error.
WriteError (new ErrorRecord (ioException, ioException.GetType().FullName, ErrorCategory.ReadError, path));
return;
}
catch (System.Security.SecurityException securityException)
{
// An exception occurred while trying to get the key. Write
// out the error.
WriteError (new ErrorRecord (securityException, securityException.GetType().FullName, ErrorCategory.PermissionDenied, path));
return;
}
catch (System.UnauthorizedAccessException unauthorizedAccessException)
{
// An exception occurred while trying to get the key. Write
// out the error.
WriteError (new ErrorRecord (unauthorizedAccessException, unauthorizedAccessException.GetType().FullName, ErrorCategory.PermissionDenied, path));
return;
}
foreach (PSMemberInfo property in properties)
{
object newPropertyValue = property.Value;
string resource =
String.Format(
Host.CurrentCulture,
resourceTemplate,
path,
property.Name,
at);
if (ShouldProcess(resource, action))
{
string propertyNameToSet = GetPropertyName(property.Name);
// First get the current value
object currentValue = null;
try
{
currentValue = key.GetValue(propertyNameToSet);
}
catch (System.IO.IOException ioException)
{
// An exception occurred while trying to set the value. Write
// out the error.
WriteError (new ErrorRecord (ioException, ioException.GetType().FullName, ErrorCategory.ReadError, property.Name));
continue;
}
catch (System.Security.SecurityException securityException)
{
// An exception occurred while trying to set the value. Write
// out the error.
WriteError (new ErrorRecord (securityException, securityException.GetType().FullName, ErrorCategory.PermissionDenied, property.Name));
continue;
}
catch (System.UnauthorizedAccessException unauthorizedAccessException)
{
// An exception occurred while trying to get the key. Write
// out the error.
WriteError (new ErrorRecord (unauthorizedAccessException, unauthorizedAccessException.GetType().FullName, ErrorCategory.PermissionDenied, property.Name));
continue;
}
if (currentValue != null &&
currentValue is string[])
{
ArrayList newValueArrayList = new ArrayList((string[])currentValue);
if (index == -1 || index >= newValueArrayList.Count)
{
newValueArrayList.Add(newPropertyValue.ToString());
}
else
{
newValueArrayList.Insert(index, newPropertyValue.ToString());
}
currentValue = newValueArrayList.ToArray(typeof(string));
}
else if (currentValue != null && currentValue is byte[])
{
ArrayList newValueArrayList = new ArrayList((byte[])currentValue);
if (index == -1 || index >= newValueArrayList.Count)
{
newValueArrayList.Add((byte)newPropertyValue);
}
else
{
newValueArrayList.Insert(index, (byte)newPropertyValue);
}
currentValue = newValueArrayList.ToArray(typeof(byte));
}
else
{
Exception e =
new ArgumentException (
RegistryProviderStrings.PropertyNotMultivaluedChange);
WriteError (new ErrorRecord (
e,
e.GetType().FullName,
ErrorCategory.InvalidOperation,
propertyNameToSet));
continue;
}
try
{
key.SetValue(propertyNameToSet, currentValue);
// Now write out the value by getting the value from the store
object value = key.GetValue(propertyNameToSet);
PSObject result = new PSObject();
result.Properties.Add(new PSNoteProperty(property.Name, value));
WritePropertyObject(result, path);
}
catch (System.IO.IOException ioException)
{
// An exception occurred while trying to set the value. Write
// out the error.
WriteError (new ErrorRecord (ioException, ioException.GetType().FullName, ErrorCategory.WriteError, property.Name));
}
catch (System.Security.SecurityException securityException)
{
// An exception occurred while trying to set the value. Write
// out the error.
WriteError (new ErrorRecord (securityException, securityException.GetType().FullName, ErrorCategory.PermissionDenied, property.Name));
}
catch (System.UnauthorizedAccessException unauthorizedAccessException)
{
// An exception occurred while trying to get the key. Write
// out the error.
WriteError (new ErrorRecord (unauthorizedAccessException, unauthorizedAccessException.GetType().FullName, ErrorCategory.PermissionDenied, property.Name));
}
} // if ShouldProcess
}
} // RemovePropertyValueAt
#region Unimplemented methods
/// <summary>
/// Gives the provider a chance to attach additional parameters to the
/// get-propertyvalue cmdlet.
/// </summary>
///
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
///
/// <param name="propertyName">
/// The property to get the value from.
/// </param>
///
/// <param name="at">
/// The position of the property to get.
/// </param>
///
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
///
public object GetPropertyValueAtDynamicParameters(
string path,
string propertyName,
object at)
{
return null;
}
/// <summary>
/// Gives the provider a chance to attach additional parameters to the
/// set-propertyvalue cmdlet.
/// </summary>
///
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
///
/// <param name="at">
/// The position of the property to get.
/// </param>
///
/// <param name="propertyValue">
/// The property to set the value on.
/// </param>
///
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
///
public object SetPropertyValueAtDynamicParameters(
string path,
object at,
PSObject propertyValue)
{
return null;
}
/// <summary>
/// Gives the provider a chance to attach additional parameters to the
/// clear-propertyvalue cmdlet.
/// </summary>
///
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
///
/// <param name="propertyName">
/// The property to clear the value from.
/// </param>
///
/// <param name="at">
/// The position of the property to clear.
/// </param>
///
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
///
public object ClearPropertyValueAtDynamicParameters(
string path,
string propertyName,
object at)
{
return null;
}
/// <summary>
/// Gives the provider a chance to attach additional parameters to the
/// remove-propertyvalue cmdlet.
/// </summary>
///
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
///
/// <param name="propertyName">
/// The property to remove the value from.
/// </param>
///
/// <param name="at">
/// The position of the property to remove.
/// </param>
///
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
///
public object RemovePropertyValueAtDynamicParameters(
string path,
string propertyName,
object at)
{
return null;
}
/// <summary>
/// Gives the provider a chance to attach additional parameters to the
/// add-propertyvalue cmdlet.
/// </summary>
///
/// <param name="path">
/// If the path was specified on the command line, this is the path
/// to the item to get the dynamic parameters for.
/// </param>
///
/// <param name="at">
/// The position of the property to add.
/// </param>
///
/// <param name="propertyValue">
/// The property to add the value on.
/// </param>
///
/// <returns>
/// An object that has properties and fields decorated with
/// parsing attributes similar to a cmdlet class.
/// </returns>
///
public object AddPropertyValueAtDynamicParameters(
string path,
object at,
PSObject propertyValue)
{
return null;
}
#endregion Unimplemented method
#endregion IMultivaluePropertyCmdletProvider
#endif // SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
#region IDynamicPropertyCmdletProvider
/// <summary>
@@ -22,9 +22,6 @@ namespace Microsoft.PowerShell.Commands
public sealed partial class RegistryProvider :
NavigationCmdletProvider,
IPropertyCmdletProvider,
#if SUPPORTS_IMULTIVALUEPROPERTYCMDLETPROVIDER
IMultivaluePropertyCmdletProvider,
#endif
IDynamicPropertyCmdletProvider,
ISecurityDescriptorCmdletProvider
{