/********************************************************************++ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ using System.Collections.ObjectModel; using System.Management.Automation.Provider; using Dbg = System.Management.Automation; #pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings #pragma warning disable 56500 namespace System.Management.Automation { /// /// Holds the state of a Monad Shell session /// internal sealed partial class SessionStateInternal { #region IDynamicPropertyCmdletProvider accessors #region NewProperty /// /// Creates a new property on the specified item /// /// /// /// The path(s) to the item(s) on which the new property should be created. /// /// /// /// The name of the property that should be created. /// /// /// /// The type of the property that should be created. /// /// /// /// The new value of the property that should be created. /// /// /// /// Passed on to providers to force operations. /// /// /// /// If true, globbing is not done on paths. /// /// /// /// A property table containing the properties and their values. /// /// /// /// If is null. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// internal Collection NewProperty( string[] paths, string property, string type, object value, bool force, bool literalPath) { if (paths == null) { throw PSTraceSource.NewArgumentNullException("paths"); } if (property == null) { throw PSTraceSource.NewArgumentNullException("property"); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); context.Force = force; context.SuppressWildcardExpansion = literalPath; NewProperty(paths, property, type, value, context); context.ThrowFirstErrorOrDoNothing(); Collection results = context.GetAccumulatedObjects(); return results; } // NewProperty /// /// Creates a new property on the specified item /// /// /// /// The path(s) to the item(s) on which the new property should be created. /// /// /// /// The name of the property that should be created. /// /// /// /// The type of the property that should be created. /// /// /// /// The new value of the property that should be created. /// /// /// /// The context which the core command is running. /// /// /// /// Nothing. The property should be passed to the context as a PSObject. /// /// /// /// If is null. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// /// /// If does not contain glob characters and /// could not be found. /// /// internal void NewProperty( string[] paths, string property, string type, object value, CmdletProviderContext context) { if (paths == null) { throw PSTraceSource.NewArgumentNullException("paths"); } if (property == null) { throw PSTraceSource.NewArgumentNullException("property"); } ProviderInfo provider = null; CmdletProvider providerInstance = null; foreach (string path in paths) { if (path == null) { throw PSTraceSource.NewArgumentNullException("paths"); } Collection providerPaths = Globber.GetGlobbedProviderPathsFromMonadPath( path, false, context, out provider, out providerInstance); foreach (string providerPath in providerPaths) { NewProperty(providerInstance, providerPath, property, type, value, context); } } } // NewProperty /// /// Creates a new property on the item at the specified path. /// /// /// /// The provider instance to use. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The name of the property to create. /// /// /// /// The type of the property to create. /// /// /// /// The value of the property to create. /// /// /// /// The context which the core command is running. /// /// /// /// If the does not support this operation. /// /// /// /// If the pipeline is being stopped while executing the command. /// /// /// /// If the provider threw an exception. /// /// private void NewProperty( CmdletProvider providerInstance, string path, string property, string type, object value, CmdletProviderContext context) { // All parameters should have been validated by caller Dbg.Diagnostics.Assert( providerInstance != null, "Caller should validate providerInstance before calling this method"); Dbg.Diagnostics.Assert( path != null, "Caller should validate path before calling this method"); Dbg.Diagnostics.Assert( property != null, "Caller should validate path before calling this method"); Dbg.Diagnostics.Assert( context != null, "Caller should validate context before calling this method"); try { providerInstance.NewProperty(path, property, type, value, context); } catch (NotSupportedException) { throw; } catch (LoopFlowException) { throw; } catch (PipelineStoppedException) { throw; } catch (ActionPreferenceStopException) { throw; } catch (Exception e) // Catch-all OK, 3rd party callout. { CommandProcessorBase.CheckForSevereException(e); throw NewProviderInvocationException( "NewPropertyProviderException", SessionStateStrings.NewPropertyProviderException, providerInstance.ProviderInfo, path, e); } } // NewProperty /// /// Gets the dynamic parameters for the new-itemproperty cmdlet. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The name of the property that should be created. /// /// /// /// The type of the property that should be created. /// /// /// /// The new value of the property that should be created. /// /// /// /// The context which the core command is running. /// /// /// /// An object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// /// /// If does not contain glob characters and /// could not be found. /// /// internal object NewPropertyDynamicParameters( string path, string propertyName, string type, object value, CmdletProviderContext context) { if (path == null) { return null; } ProviderInfo provider = null; CmdletProvider providerInstance = null; CmdletProviderContext newContext = new CmdletProviderContext(context); newContext.SetFilters( new Collection(), new Collection(), null); Collection providerPaths = Globber.GetGlobbedProviderPathsFromMonadPath( path, true, newContext, out provider, out providerInstance); if (providerPaths.Count > 0) { // Get the dynamic parameters for the first resolved path return NewPropertyDynamicParameters(providerInstance, providerPaths[0], propertyName, type, value, newContext); } return null; } // NewPropertyDynamicParameters /// /// Gets the dynamic parameters for the new-itemproperty cmdlet. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The name of the property to create. /// /// /// /// The type of the property to create. /// /// /// /// The value of the property. /// /// /// /// The instance of the provider to use. /// /// /// /// The context which the core command is running. /// /// /// /// An object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class. /// /// /// /// If the does not support this operation. /// /// /// /// If the pipeline is being stopped while executing the command. /// /// /// /// If the provider threw an exception. /// /// private object NewPropertyDynamicParameters( CmdletProvider providerInstance, string path, string propertyName, string type, object value, CmdletProviderContext context) { // All parameters should have been validated by caller Dbg.Diagnostics.Assert( providerInstance != null, "Caller should validate providerInstance before calling this method"); Dbg.Diagnostics.Assert( path != null, "Caller should validate path before calling this method"); Dbg.Diagnostics.Assert( context != null, "Caller should validate context before calling this method"); object result = null; try { result = providerInstance.NewPropertyDynamicParameters(path, propertyName, type, value, context); } catch (NotSupportedException) { throw; } catch (LoopFlowException) { throw; } catch (PipelineStoppedException) { throw; } catch (ActionPreferenceStopException) { throw; } catch (Exception e) // Catch-all OK, 3rd party callout. { CommandProcessorBase.CheckForSevereException(e); throw NewProviderInvocationException( "NewPropertyDynamicParametersProviderException", SessionStateStrings.NewPropertyDynamicParametersProviderException, providerInstance.ProviderInfo, path, e); } return result; } // NewPropertyDynamicParameters #endregion NewProperty #region RemoveProperty /// /// Removes the specified property from the specified item. /// /// /// /// The path(s) to the item(s) to remove the property from. /// /// /// /// The name of the property to remove /// /// /// /// Passed on to providers to force operations. /// /// /// /// If true, globbing is not done on paths. /// /// /// /// If or is null. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// internal void RemoveProperty(string[] paths, string property, bool force, bool literalPath) { if (paths == null) { throw PSTraceSource.NewArgumentNullException("paths"); } if (property == null) { throw PSTraceSource.NewArgumentNullException("property"); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); context.Force = force; context.SuppressWildcardExpansion = literalPath; RemoveProperty(paths, property, context); context.ThrowFirstErrorOrDoNothing(); } // RemoveProperty /// /// Removes the specified properties from the specified item. /// /// /// /// The path(s) to the item(s) to remove the properties from. /// /// /// /// The name of the property to remove /// /// /// /// The context which the core command is running. /// /// /// /// If or is null. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// /// /// If does not contain glob characters and /// could not be found. /// /// internal void RemoveProperty( string[] paths, string property, CmdletProviderContext context) { if (paths == null) { throw PSTraceSource.NewArgumentNullException("paths"); } if (property == null) { throw PSTraceSource.NewArgumentNullException("property"); } foreach (string path in paths) { if (path == null) { throw PSTraceSource.NewArgumentNullException("paths"); } ProviderInfo provider = null; CmdletProvider providerInstance = null; Collection providerPaths = Globber.GetGlobbedProviderPathsFromMonadPath( path, false, context, out provider, out providerInstance); foreach (string providerPath in providerPaths) { RemoveProperty(providerInstance, providerPath, property, context); } } } // RemoveProperty /// /// Removes the property from the item at the specified path. /// /// /// /// The provider instance to use. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The name of the property to remove. /// /// /// /// The context which the core command is running. /// /// /// /// If the does not support this operation. /// /// /// /// If the pipeline is being stopped while executing the command. /// /// /// /// If the provider threw an exception. /// /// private void RemoveProperty( CmdletProvider providerInstance, string path, string property, CmdletProviderContext context) { // All parameters should have been validated by caller Dbg.Diagnostics.Assert( providerInstance != null, "Caller should validate providerInstance before calling this method"); Dbg.Diagnostics.Assert( path != null, "Caller should validate path before calling this method"); Dbg.Diagnostics.Assert( property != null, "Caller should validate property before calling this method"); Dbg.Diagnostics.Assert( context != null, "Caller should validate context before calling this method"); try { providerInstance.RemoveProperty(path, property, context); } catch (NotSupportedException) { throw; } catch (LoopFlowException) { throw; } catch (PipelineStoppedException) { throw; } catch (ActionPreferenceStopException) { throw; } catch (Exception e) // Catch-all OK, 3rd party callout. { CommandProcessorBase.CheckForSevereException(e); throw NewProviderInvocationException( "RemovePropertyProviderException", SessionStateStrings.RemovePropertyProviderException, providerInstance.ProviderInfo, path, e); } } // RemoveProperty /// /// Gets the dynamic parameters for the remove-itemproperty cmdlet. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The name of the property that should be created. /// /// /// /// The context which the core command is running. /// /// /// /// An object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// /// /// If does not contain glob characters and /// could not be found. /// /// internal object RemovePropertyDynamicParameters( string path, string propertyName, CmdletProviderContext context) { if (path == null) { return null; } ProviderInfo provider = null; CmdletProvider providerInstance = null; CmdletProviderContext newContext = new CmdletProviderContext(context); newContext.SetFilters( new Collection(), new Collection(), null); Collection providerPaths = Globber.GetGlobbedProviderPathsFromMonadPath( path, true, newContext, out provider, out providerInstance); if (providerPaths.Count > 0) { // Get the dynamic parameters for the first resolved path return RemovePropertyDynamicParameters(providerInstance, providerPaths[0], propertyName, newContext); } return null; } // RemovePropertyDynamicParameters /// /// Gets the dynamic parameters for the remove-itemproperty cmdlet. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The name of the property to remove. /// /// /// /// The instance of the provider to use. /// /// /// /// The context which the core command is running. /// /// /// /// An object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class. /// /// /// /// If the does not support this operation. /// /// /// /// If the pipeline is being stopped while executing the command. /// /// /// /// If the provider threw an exception. /// /// private object RemovePropertyDynamicParameters( CmdletProvider providerInstance, string path, string propertyName, CmdletProviderContext context) { // All parameters should have been validated by caller Dbg.Diagnostics.Assert( providerInstance != null, "Caller should validate providerInstance before calling this method"); Dbg.Diagnostics.Assert( path != null, "Caller should validate path before calling this method"); Dbg.Diagnostics.Assert( context != null, "Caller should validate context before calling this method"); object result = null; try { result = providerInstance.RemovePropertyDynamicParameters(path, propertyName, context); } catch (NotSupportedException) { throw; } catch (LoopFlowException) { throw; } catch (PipelineStoppedException) { throw; } catch (ActionPreferenceStopException) { throw; } catch (Exception e) // Catch-all OK, 3rd party callout. { CommandProcessorBase.CheckForSevereException(e); throw NewProviderInvocationException( "RemovePropertyDynamicParametersProviderException", SessionStateStrings.RemovePropertyDynamicParametersProviderException, providerInstance.ProviderInfo, path, e); } return result; } // RemovePropertyDynamicParameters #endregion RemoveProperty #region CopyProperty /// /// Copies the specified property on the specified item to the specified property /// on the destination item. The source and destination items can be the same item. /// /// /// /// The path(s) to the item(s) to copy the property from. /// /// /// /// The name of the property to be copied. /// /// /// /// The path to the item to copy the property to. /// /// /// /// The name of the property to copy the property to. /// /// /// /// Passed on to providers to force operations. /// /// /// /// If true, globbing is not done on paths. /// /// /// /// If , , /// , or /// is null. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// internal Collection CopyProperty( string[] sourcePaths, string sourceProperty, string destinationPath, string destinationProperty, bool force, bool literalPath) { if (sourcePaths == null) { throw PSTraceSource.NewArgumentNullException("sourcePaths"); } if (sourceProperty == null) { throw PSTraceSource.NewArgumentNullException("sourceProperty"); } if (destinationPath == null) { throw PSTraceSource.NewArgumentNullException("destinationPath"); } if (destinationProperty == null) { throw PSTraceSource.NewArgumentNullException("destinationProperty"); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); context.Force = force; context.SuppressWildcardExpansion = literalPath; CopyProperty(sourcePaths, sourceProperty, destinationPath, destinationProperty, context); context.ThrowFirstErrorOrDoNothing(); Collection results = context.GetAccumulatedObjects(); return results; } // CopyProperty /// /// Copies the specified property on the specified item to the specified property /// on the destination item. The source and destination items can be the same item. /// /// /// /// The path(s) to the item(s) to copy the property from. /// /// /// /// The name of the property to be copied. /// /// /// /// The path to the item to copy the property to. /// /// /// /// The name of the property to copy the property to. /// /// /// /// The context which the core command is running. /// /// /// /// If , , /// , or /// is null. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// /// /// If does not contain glob characters and /// could not be found. /// /// internal void CopyProperty( string[] sourcePaths, string sourceProperty, string destinationPath, string destinationProperty, CmdletProviderContext context) { if (sourcePaths == null) { throw PSTraceSource.NewArgumentNullException("sourcePaths"); } if (sourceProperty == null) { throw PSTraceSource.NewArgumentNullException("sourceProperty"); } if (destinationPath == null) { throw PSTraceSource.NewArgumentNullException("destinationPath"); } if (destinationProperty == null) { throw PSTraceSource.NewArgumentNullException("destinationProperty"); } foreach (string sourcePath in sourcePaths) { if (sourcePath == null) { throw PSTraceSource.NewArgumentNullException("sourcePaths"); } ProviderInfo provider = null; CmdletProvider providerInstance = null; Collection providerPaths = Globber.GetGlobbedProviderPathsFromMonadPath( sourcePath, false, context, out provider, out providerInstance); if (providerPaths.Count > 0) { // Save off the original filters Collection includeFilters = context.Include; Collection excludeFilters = context.Exclude; string filterString = context.Filter; // now modify the filters so that the destination isn't filtered context.SetFilters( new Collection(), new Collection(), null); Collection providerDestinationPaths = Globber.GetGlobbedProviderPathsFromMonadPath( destinationPath, false, context, out provider, out providerInstance); // Now reapply the filters context.SetFilters( includeFilters, excludeFilters, filterString); foreach (string providerPath in providerPaths) { foreach (string providerDestinationPath in providerDestinationPaths) { CopyProperty(providerInstance, providerPath, sourceProperty, providerDestinationPath, destinationProperty, context); } } } } } // CopyProperty /// /// Copies the property /// /// /// /// The instance of the provider to use. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The name of the property to be copied. /// /// /// /// The path to the item to copy the property to. /// /// /// /// The name of the property to copy the property to. /// /// /// /// The context which the core command is running. /// /// /// /// If the does not support this operation. /// /// /// /// If the pipeline is being stopped while executing the command. /// /// /// /// If the provider threw an exception. /// /// private void CopyProperty( CmdletProvider providerInstance, string sourcePath, string sourceProperty, string destinationPath, string destinationProperty, CmdletProviderContext context) { // All parameters should have been validated by caller Dbg.Diagnostics.Assert( providerInstance != null, "Caller should validate providerInstance before calling this method"); Dbg.Diagnostics.Assert( sourcePath != null, "Caller should validate sourcePath before calling this method"); Dbg.Diagnostics.Assert( sourceProperty != null, "Caller should validate sourceProperty before calling this method"); Dbg.Diagnostics.Assert( destinationPath != null, "Caller should validate destinationPath before calling this method"); Dbg.Diagnostics.Assert( destinationProperty != null, "Caller should validate destinationProperty before calling this method"); Dbg.Diagnostics.Assert( context != null, "Caller should validate context before calling this method"); try { providerInstance.CopyProperty(sourcePath, sourceProperty, destinationPath, destinationProperty, context); } catch (NotSupportedException) { throw; } catch (LoopFlowException) { throw; } catch (PipelineStoppedException) { throw; } catch (ActionPreferenceStopException) { throw; } catch (Exception e) // Catch-all OK, 3rd party callout. { CommandProcessorBase.CheckForSevereException(e); throw NewProviderInvocationException( "CopyPropertyProviderException", SessionStateStrings.CopyPropertyProviderException, providerInstance.ProviderInfo, sourcePath, e); } } // CopyProperty /// /// Gets the dynamic parameters for the copy-itemproperty cmdlet. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The name of the property to be copied. /// /// /// /// The path to the item to copy the property to. /// /// /// /// The name of the property to copy the property to. /// /// /// /// The context which the core command is running. /// /// /// /// An object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// /// /// If does not contain glob characters and /// could not be found. /// /// internal object CopyPropertyDynamicParameters( string path, string sourceProperty, string destinationPath, string destinationProperty, CmdletProviderContext context) { if (path == null) { return null; } ProviderInfo provider = null; CmdletProvider providerInstance = null; CmdletProviderContext newContext = new CmdletProviderContext(context); newContext.SetFilters( new Collection(), new Collection(), null); Collection providerPaths = Globber.GetGlobbedProviderPathsFromMonadPath( path, true, newContext, out provider, out providerInstance); if (providerPaths.Count > 0) { // Get the dynamic parameters for the first resolved path return CopyPropertyDynamicParameters( providerInstance, providerPaths[0], sourceProperty, destinationPath, destinationProperty, newContext); } return null; } // CopyPropertyDynamicParameters /// /// Gets the dynamic parameters for the copy-itemproperty cmdlet. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The instance of the provider to use. /// /// /// /// The name of the property to copy. /// /// /// /// The path to the item to copy the property to. /// /// /// /// The name of the property to copy the property to on the destination item. /// /// /// /// The context which the core command is running. /// /// /// /// An object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class. /// /// /// /// If the does not support this operation. /// /// /// /// If the pipeline is being stopped while executing the command. /// /// /// /// If the provider threw an exception. /// /// private object CopyPropertyDynamicParameters( CmdletProvider providerInstance, string path, string sourceProperty, string destinationPath, string destinationProperty, CmdletProviderContext context) { // All parameters should have been validated by caller Dbg.Diagnostics.Assert( providerInstance != null, "Caller should validate providerInstance before calling this method"); Dbg.Diagnostics.Assert( path != null, "Caller should validate path before calling this method"); Dbg.Diagnostics.Assert( context != null, "Caller should validate context before calling this method"); object result = null; try { result = providerInstance.CopyPropertyDynamicParameters( path, sourceProperty, destinationPath, destinationProperty, context); } catch (NotSupportedException) { throw; } catch (LoopFlowException) { throw; } catch (PipelineStoppedException) { throw; } catch (ActionPreferenceStopException) { throw; } catch (Exception e) // Catch-all OK, 3rd party callout. { CommandProcessorBase.CheckForSevereException(e); throw NewProviderInvocationException( "CopyPropertyDynamicParametersProviderException", SessionStateStrings.CopyPropertyDynamicParametersProviderException, providerInstance.ProviderInfo, path, e); } return result; } // CopyPropertyDynamicParameters #endregion CopyProperty #region MoveProperty /// /// Moves the specified property on the specified item to the specified property /// on the destination item. The source and destination items can be the same item. /// /// /// /// The path(s) to the item(s) to move the property from. /// /// /// /// The name of the property to be moved. /// /// /// /// The path to the item to move the property to. /// /// /// /// The name of the property to move the property to. /// /// /// /// Passed on to providers to force operations. /// /// /// /// If true, globbing is not done on paths. /// /// /// /// If , , /// , or /// is null. /// /// /// /// If resolves to more than one item. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// internal Collection MoveProperty( string[] sourcePaths, string sourceProperty, string destinationPath, string destinationProperty, bool force, bool literalPath) { if (sourcePaths == null) { throw PSTraceSource.NewArgumentNullException("sourcePaths"); } if (sourceProperty == null) { throw PSTraceSource.NewArgumentNullException("sourceProperty"); } if (destinationPath == null) { throw PSTraceSource.NewArgumentNullException("destinationPath"); } if (destinationProperty == null) { throw PSTraceSource.NewArgumentNullException("destinationProperty"); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); context.Force = force; context.SuppressWildcardExpansion = literalPath; MoveProperty(sourcePaths, sourceProperty, destinationPath, destinationProperty, context); context.ThrowFirstErrorOrDoNothing(); Collection results = context.GetAccumulatedObjects(); return results; } // MoveProperty /// /// Moves the specified property on the specified item to the specified property /// on the destination item. The source and destination items can be the same item. /// /// /// /// The path(s) to the item(s) to move the property from. /// /// /// /// The name of the property to be moved. /// /// /// /// The path to the item to move the property to. /// /// /// /// The name of the property to move the property to. /// /// /// /// The context which the core command is running. /// /// /// /// If , , /// , or /// is null. /// /// /// /// If resolves to more than one item. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// /// /// If does not contain glob characters and /// could not be found. /// /// internal void MoveProperty( string[] sourcePaths, string sourceProperty, string destinationPath, string destinationProperty, CmdletProviderContext context) { if (sourcePaths == null) { throw PSTraceSource.NewArgumentNullException("sourcePaths"); } if (sourceProperty == null) { throw PSTraceSource.NewArgumentNullException("sourceProperty"); } if (destinationPath == null) { throw PSTraceSource.NewArgumentNullException("destinationPath"); } if (destinationProperty == null) { throw PSTraceSource.NewArgumentNullException("destinationProperty"); } ProviderInfo provider = null; CmdletProvider providerInstance = null; // We shouldn't be filtering the destination path CmdletProviderContext destinationContext = new CmdletProviderContext(context); destinationContext.SetFilters( new Collection(), new Collection(), null); Collection destinationProviderPaths = Globber.GetGlobbedProviderPathsFromMonadPath( destinationPath, false, destinationContext, out provider, out providerInstance); if (destinationProviderPaths.Count > 1) { ArgumentException argException = PSTraceSource.NewArgumentException( "destinationPath", SessionStateStrings.MovePropertyDestinationResolveToSingle); context.WriteError(new ErrorRecord(argException, argException.GetType().FullName, ErrorCategory.InvalidArgument, destinationProviderPaths)); } else { foreach (string sourcePath in sourcePaths) { if (sourcePath == null) { throw PSTraceSource.NewArgumentNullException("sourcePaths"); } Collection providerPaths = Globber.GetGlobbedProviderPathsFromMonadPath( sourcePath, false, context, out provider, out providerInstance); foreach (string providerPath in providerPaths) { MoveProperty(providerInstance, providerPath, sourceProperty, destinationProviderPaths[0], destinationProperty, context); } } } } // MoveProperty /// /// Moves the property from one item to another /// /// /// /// The provider instance to use. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The property to be moved. /// /// /// /// The path of the item to move the property to. /// /// /// /// The name of the property to move the property to. /// /// /// /// The context which the core command is running. /// /// /// /// If the does not support this operation. /// /// /// /// If the pipeline is being stopped while executing the command. /// /// /// /// If the provider threw an exception. /// /// private void MoveProperty( CmdletProvider providerInstance, string sourcePath, string sourceProperty, string destinationPath, string destinationProperty, CmdletProviderContext context) { // All parameters should have been validated by caller Dbg.Diagnostics.Assert( providerInstance != null, "Caller should validate providerInstance before calling this method"); Dbg.Diagnostics.Assert( sourcePath != null, "Caller should validate sourcePath before calling this method"); Dbg.Diagnostics.Assert( sourceProperty != null, "Caller should validate sourceProperty before calling this method"); Dbg.Diagnostics.Assert( destinationPath != null, "Caller should validate destinationPath before calling this method"); Dbg.Diagnostics.Assert( destinationProperty != null, "Caller should validate destinationProperty before calling this method"); Dbg.Diagnostics.Assert( context != null, "Caller should validate context before calling this method"); try { providerInstance.MoveProperty(sourcePath, sourceProperty, destinationPath, destinationProperty, context); } catch (NotSupportedException) { throw; } catch (LoopFlowException) { throw; } catch (PipelineStoppedException) { throw; } catch (ActionPreferenceStopException) { throw; } catch (Exception e) // Catch-all OK, 3rd party callout. { CommandProcessorBase.CheckForSevereException(e); throw NewProviderInvocationException( "MovePropertyProviderException", SessionStateStrings.MovePropertyProviderException, providerInstance.ProviderInfo, sourcePath, e); } } // MoveProperty /// /// Gets the dynamic parameters for the move-itemproperty cmdlet. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The name of the property to be moved. /// /// /// /// The path to the item to move the property to. /// /// /// /// The name of the property to move the property to. /// /// /// /// The context which the core command is running. /// /// /// /// An object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// /// /// If does not contain glob characters and /// could not be found. /// /// internal object MovePropertyDynamicParameters( string path, string sourceProperty, string destinationPath, string destinationProperty, CmdletProviderContext context) { if (path == null) { return null; } ProviderInfo provider = null; CmdletProvider providerInstance = null; CmdletProviderContext newContext = new CmdletProviderContext(context); newContext.SetFilters( new Collection(), new Collection(), null); Collection providerPaths = Globber.GetGlobbedProviderPathsFromMonadPath( path, true, newContext, out provider, out providerInstance); if (providerPaths.Count > 0) { // Get the dynamic parameters for the first resolved path return MovePropertyDynamicParameters( providerInstance, providerPaths[0], sourceProperty, destinationPath, destinationProperty, newContext); } return null; } // MovePropertyDynamicParameters /// /// Gets the dynamic parameters for the move-itemproperty cmdlet. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The name of the property to move. /// /// /// /// The path to the item to move the property to. /// /// /// /// The name of the property on the destination item to move the property to. /// /// /// /// The instance of the provider to use. /// /// /// /// The context which the core command is running. /// /// /// /// An object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class. /// /// /// /// If the does not support this operation. /// /// /// /// If the pipeline is being stopped while executing the command. /// /// /// /// If the provider threw an exception. /// /// private object MovePropertyDynamicParameters( CmdletProvider providerInstance, string path, string sourceProperty, string destinationPath, string destinationProperty, CmdletProviderContext context) { // All parameters should have been validated by caller Dbg.Diagnostics.Assert( providerInstance != null, "Caller should validate providerInstance before calling this method"); Dbg.Diagnostics.Assert( path != null, "Caller should validate path before calling this method"); Dbg.Diagnostics.Assert( context != null, "Caller should validate context before calling this method"); object result = null; try { result = providerInstance.MovePropertyDynamicParameters( path, sourceProperty, destinationPath, destinationProperty, context); } catch (NotSupportedException) { throw; } catch (LoopFlowException) { throw; } catch (PipelineStoppedException) { throw; } catch (ActionPreferenceStopException) { throw; } catch (Exception e) // Catch-all OK, 3rd party callout. { CommandProcessorBase.CheckForSevereException(e); throw NewProviderInvocationException( "MovePropertyDynamicParametersProviderException", SessionStateStrings.MovePropertyDynamicParametersProviderException, providerInstance.ProviderInfo, path, e); } return result; } // MovePropertyDynamicParameters #endregion MoveProperty #region RenameProperty /// /// Renames the specified property on the specified item to the specified property. /// /// /// /// The path(s) to the item(s) to rename the property on. /// /// /// /// The name of the property to be renamed. /// /// /// /// The name of the property to rename the property to. /// /// /// /// Passed on to providers to force operations. /// /// /// /// If true, globbing is not done on paths. /// /// /// /// If , , /// or is null. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// internal Collection RenameProperty( string[] sourcePaths, string sourceProperty, string destinationProperty, bool force, bool literalPath) { if (sourcePaths == null) { throw PSTraceSource.NewArgumentNullException("sourcePaths"); } if (sourceProperty == null) { throw PSTraceSource.NewArgumentNullException("sourceProperty"); } if (destinationProperty == null) { throw PSTraceSource.NewArgumentNullException("destinationProperty"); } CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext); context.Force = force; context.SuppressWildcardExpansion = literalPath; RenameProperty(sourcePaths, sourceProperty, destinationProperty, context); context.ThrowFirstErrorOrDoNothing(); Collection results = context.GetAccumulatedObjects(); return results; } // RenameProperty /// /// Renames the specified property on the specified item to the specified property. /// /// /// /// The path(s) to the item(s) to rename the property on. /// /// /// /// The name of the property to be renamed. /// /// /// /// The name of the property to rename the property to. /// /// /// /// The context which the core command is running. /// /// /// /// If , , /// or is null. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// /// /// If does not contain glob characters and /// could not be found. /// /// internal void RenameProperty( string[] paths, string sourceProperty, string destinationProperty, CmdletProviderContext context) { if (paths == null) { throw PSTraceSource.NewArgumentNullException("paths"); } if (sourceProperty == null) { throw PSTraceSource.NewArgumentNullException("sourceProperty"); } if (destinationProperty == null) { throw PSTraceSource.NewArgumentNullException("destinationProperty"); } foreach (string path in paths) { if (path == null) { throw PSTraceSource.NewArgumentNullException("paths"); } ProviderInfo provider = null; CmdletProvider providerInstance = null; Collection providerPaths = Globber.GetGlobbedProviderPathsFromMonadPath( path, false, context, out provider, out providerInstance); foreach (string providerPath in providerPaths) { RenameProperty(providerInstance, providerPath, sourceProperty, destinationProperty, context); } } } // RenameProperty /// /// Renames the property of the item at the specified path. /// /// /// /// The provider instance to use. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The name of the property to rename. /// /// /// /// The new name of the property. /// /// /// /// The context which the core command is running. /// /// /// /// If the does not support this operation. /// /// /// /// If the pipeline is being stopped while executing the command. /// /// /// /// If the provider threw an exception. /// /// private void RenameProperty( CmdletProvider providerInstance, string sourcePath, string sourceProperty, string destinationProperty, CmdletProviderContext context) { // All parameters should have been validated by caller Dbg.Diagnostics.Assert( providerInstance != null, "Caller should validate providerInstance before calling this method"); Dbg.Diagnostics.Assert( sourcePath != null, "Caller should validate sourcePath before calling this method"); Dbg.Diagnostics.Assert( sourceProperty != null, "Caller should validate sourceProperty before calling this method"); Dbg.Diagnostics.Assert( destinationProperty != null, "Caller should validate destinationProperty before calling this method"); Dbg.Diagnostics.Assert( context != null, "Caller should validate context before calling this method"); try { providerInstance.RenameProperty(sourcePath, sourceProperty, destinationProperty, context); } catch (NotSupportedException) { throw; } catch (LoopFlowException) { throw; } catch (PipelineStoppedException) { throw; } catch (ActionPreferenceStopException) { throw; } catch (Exception e) // Catch-all OK, 3rd party callout. { CommandProcessorBase.CheckForSevereException(e); throw NewProviderInvocationException( "RenamePropertyProviderException", SessionStateStrings.RenamePropertyProviderException, providerInstance.ProviderInfo, sourcePath, e); } } // RenameProperty /// /// Gets the dynamic parameters for the rename-itemproperty cmdlet. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The name of the property to be renamed. /// /// /// /// The name of the property to rename the property to. /// /// /// /// The context which the core command is running. /// /// /// /// An object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class. /// /// /// /// If the refers to a provider that could not be found. /// /// /// /// If the refers to a drive that could not be found. /// /// /// /// If the provider that the refers to does /// not support this operation. /// /// /// /// If the provider threw an exception. /// /// /// /// If does not contain glob characters and /// could not be found. /// /// internal object RenamePropertyDynamicParameters( string path, string sourceProperty, string destinationProperty, CmdletProviderContext context) { if (path == null) { return null; } ProviderInfo provider = null; CmdletProvider providerInstance = null; CmdletProviderContext newContext = new CmdletProviderContext(context); newContext.SetFilters( new Collection(), new Collection(), null); Collection providerPaths = Globber.GetGlobbedProviderPathsFromMonadPath( path, true, newContext, out provider, out providerInstance); if (providerPaths.Count > 0) { // Get the dynamic parameters for the first resolved path return RenamePropertyDynamicParameters( providerInstance, providerPaths[0], sourceProperty, destinationProperty, newContext); } return null; } // RenamePropertyDynamicParameters /// /// Gets the dynamic parameters for the rename-itemproperty cmdlet. /// /// /// /// The path to the item if it was specified on the command line. /// /// /// /// The instance of the provider to use. /// /// /// /// The name of the property to rename. /// /// /// /// The new name for the property. /// /// /// /// The context which the core command is running. /// /// /// /// An object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class. /// /// /// /// If the does not support this operation. /// /// /// /// If the pipeline is being stopped while executing the command. /// /// /// /// If the provider threw an exception. /// /// private object RenamePropertyDynamicParameters( CmdletProvider providerInstance, string path, string sourceProperty, string destinationProperty, CmdletProviderContext context) { // All parameters should have been validated by caller Dbg.Diagnostics.Assert( providerInstance != null, "Caller should validate providerInstance before calling this method"); Dbg.Diagnostics.Assert( path != null, "Caller should validate path before calling this method"); Dbg.Diagnostics.Assert( context != null, "Caller should validate context before calling this method"); object result = null; try { result = providerInstance.RenamePropertyDynamicParameters( path, sourceProperty, destinationProperty, context); } catch (NotSupportedException) { throw; } catch (LoopFlowException) { throw; } catch (PipelineStoppedException) { throw; } catch (ActionPreferenceStopException) { throw; } catch (Exception e) // Catch-all OK, 3rd party callout. { CommandProcessorBase.CheckForSevereException(e); throw NewProviderInvocationException( "RenamePropertyDynamicParametersProviderException", SessionStateStrings.RenamePropertyDynamicParametersProviderException, providerInstance.ProviderInfo, path, e); } return result; } // RenamePropertyDynamicParameters #endregion RenameProperty #endregion IDynamicPropertyCmdletProvider accessors } // SessionStateInternal class } #pragma warning restore 56500