/// <Content contentref="System.Management.Automation.PathIntrinsics.GetUnresolvedProviderPathFromPSPath" /> public string GetUnresolvedProviderPathFromPSPath(string path) { using (PSTransactionManager.GetEngineProtectionScope()) { return(SessionState.Path.GetUnresolvedProviderPathFromPSPath(path)); } } // GetUnresolvedProviderPathFromPSPath
/// <summary> /// Gives the provider an opportunity to validate the drive /// that is being added. It also allows the provider to modify parts /// of the PSDriveInfo object. This may be done for performance or /// reliability reasons or to provide extra data to all calls using /// the Drive. /// </summary> /// <param name="drive"> /// The proposed new drive. /// </param> /// <returns> /// The new drive that is to be added to the MSH namespace. This /// can either be the same <paramref name="drive"/> object that /// was passed in or a modified version of it. /// /// The default implementation returns the drive that was passed. /// </returns> /// <remarks> /// This method gives the provider an opportunity to associate /// provider specific data with a drive. This is done by deriving /// a new class from <see cref="System.Management.Automation.PSDriveInfo"/> /// and adding any properties, methods, or fields that are necessary. /// When this method gets called, the override should create an instance /// of the derived PSDriveInfo using the passed in PSDriveInfo. The derived /// PSDriveInfo should then be returned. Each subsequent call into the provider /// that uses this drive will have access to the derived PSDriveInfo via the /// PSDriveInfo property provided by the base class. /// /// Any failures should be sent to the <see cref="System.Management.Automation.Provider.CmdletProvider.WriteError(ErrorRecord)"/> /// method and null should be returned. /// </remarks> protected virtual PSDriveInfo NewDrive(PSDriveInfo drive) { using (PSTransactionManager.GetEngineProtectionScope()) { return(drive); } }
/// <summary> /// Gives the provider an opportunity to attach additional parameters to /// the New-PSDrive cmdlet. /// </summary> /// <returns> /// Overrides of this method should return an object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class or a /// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>. /// /// The default implementation returns null. (no additional parameters) /// </returns> protected virtual object NewDriveDynamicParameters() { using (PSTransactionManager.GetEngineProtectionScope()) { return(null); } }
/// <summary> /// Gives the provider an opportunity to attach additional parameters to /// the rename-item 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="newName"> /// The name to which the item should be renamed. This name should always be /// relative to the parent container. /// </param> /// /// <returns> /// Overrides of this method should return an object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class or a /// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>. /// /// The default implementation returns null. (no additional parameters) /// </returns> protected virtual object RenameItemDynamicParameters(string path, string newName) { using (PSTransactionManager.GetEngineProtectionScope()) { return(null); } } // RenameItemDynamicParameters
/// <summary> /// Gives the provider the ability to map drives after initialization. /// </summary> /// <returns> /// A collection of the drives the provider wants to be added to the session upon initialization. /// /// The default implementation returns an empty <see cref="System.Management.Automation.PSDriveInfo"/> collection. /// </returns> /// <remarks> /// After the Start method is called on a provider, the InitializeDefaultDrives /// method is called. This is an opportunity for the provider to /// mount drives that are important to it. For instance, the Active Directory /// provider might mount a drive for the defaultNamingContext if the /// machine is joined to a domain. /// /// All providers should mount a root drive to help the user with discoverability. /// This root drive might contain a listing of a set of locations that would be /// interesting as roots for other mounted drives. For instance, the Active /// Directory provider my create a drive that lists the naming contexts found /// in the namingContext attributes on the RootDSE. This will help users /// discover interesting mount points for other drives. /// </remarks> protected virtual Collection <PSDriveInfo> InitializeDefaultDrives() { using (PSTransactionManager.GetEngineProtectionScope()) { return(new Collection <PSDriveInfo>()); } }
/// <summary> /// Expand a provider path that contains wildcards to a list of provider /// paths that the path represents.Only called for providers that declare /// the ExpandWildcards capability. /// </summary> /// <param name="path"> /// The path to expand. Expansion must be consistent with the wildcarding /// rules of PowerShell's WildcardPattern class. /// </param> /// <returns> /// A list of provider paths that this path expands to. They must all exist. /// </returns> protected virtual string[] ExpandPath(string path) { using (PSTransactionManager.GetEngineProtectionScope()) { return(new string[] { path }); } }
/// <summary> /// Gives the provider an opportunity to attach additional parameters to /// the get-childitem -name 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> /// /// <returns> /// Overrides of this method should return an object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class or a /// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>. /// /// The default implementation returns null. (no additional parameters) /// </returns> protected virtual object GetChildNamesDynamicParameters(string path) { using (PSTransactionManager.GetEngineProtectionScope()) { return(null); } } // GetChildNamesDynamicParameters
/// <summary> /// Gives the provider an opportunity to attach additional parameters to /// the clear-item 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> /// <returns> /// Overrides of this method should return an object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class or a /// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>. /// /// The default implementation returns null. (no additional parameters) /// </returns> protected virtual object ClearItemDynamicParameters(string path) { using (PSTransactionManager.GetEngineProtectionScope()) { return(null); } }
/// <summary> /// Gives the provider an opportunity to attach additional parameters to /// the invoke-item 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> /// <returns> /// Overrides of this method should return an object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class or a /// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>. /// /// The default implementation returns null. (no additional parameters) /// </returns> protected virtual object InvokeDefaultActionDynamicParameters(string path) { using (PSTransactionManager.GetEngineProtectionScope()) { return(null); } }
/// <summary> /// Gives the provider an opportunity to attach additional parameters to /// the get-childitem 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="recurse"> /// True if all children in a subtree should be retrieved, false if only a single /// level of children should be retrieved. This parameter should only be true for /// the NavigationCmdletProvider derived class. /// </param> /// <returns> /// Overrides of this method should return an object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class or a /// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>. /// /// The default implementation returns null. (no additional parameters) /// </returns> protected virtual object GetChildItemsDynamicParameters(string path, bool recurse) { using (PSTransactionManager.GetEngineProtectionScope()) { return(null); } }
} // GetVariableValue /// <Content contentref="System.Management.Automation.VariableIntrinsics.GetValue" /> public object GetVariableValue(string name, object defaultValue) { using (PSTransactionManager.GetEngineProtectionScope()) { return(this.SessionState.PSVariable.GetValue(name, defaultValue)); } } // GetVariableValue
} // GetUnresolvedProviderPathFromPSPath /// <Content contentref="System.Management.Automation.PathIntrinsics.GetResolvedProviderPathFromPSPath" /> public Collection <string> GetResolvedProviderPathFromPSPath(string path, out ProviderInfo provider) { using (PSTransactionManager.GetEngineProtectionScope()) { return(SessionState.Path.GetResolvedProviderPathFromPSPath(path, out provider)); } } // GetResolvedProviderPathFromPSPath
} // NewDriveDynamicParameters /// <summary> /// Gives the provider an opportunity to clean up any provider specific data /// for the drive that is going to be removed. /// </summary> /// /// <param name="drive"> /// The Drive object the represents the mounted drive. /// </param> /// /// <returns> /// If the drive can be removed it should return the drive that was passed /// in. If the drive cannot be removed, null should be returned or an exception /// should be thrown. /// /// The default implementation returns the drive that was passed. /// </returns> /// /// <remarks> /// A provider should override this method to free any resources that may be associated with /// the drive being removed. /// </remarks> protected virtual PSDriveInfo RemoveDrive(PSDriveInfo drive) { using (PSTransactionManager.GetEngineProtectionScope()) { return(drive); } // TraceMethod } // RemoveDrive
protected virtual object NewItemDynamicParameters( string path, string itemTypeName, object newItemValue) { using (PSTransactionManager.GetEngineProtectionScope()) return((object)null); }
protected virtual object CopyItemDynamicParameters( string path, string destination, bool recurse) { using (PSTransactionManager.GetEngineProtectionScope()) return((object)null); }
protected virtual string GetParentPath(string path, string root) { string str3; using (PSTransactionManager.GetEngineProtectionScope()) { string str = null; if (string.IsNullOrEmpty(path)) { throw PSTraceSource.NewArgumentException("path"); } if ((root == null) && (base.PSDriveInfo != null)) { root = base.PSDriveInfo.Root; } if (OSHelper.IsWindows) { path = path.Replace('/', '\\'); } path = path.TrimEnd(new char[] { (OSHelper.IsUnix ? '/' : '\\') }); string strB = string.Empty; if (root != null) { if (OSHelper.IsUnix) { strB = root; } else { strB = root.Replace('/', '\\'); } } if (string.Compare(path, strB, StringComparison.OrdinalIgnoreCase) == 0) { str = string.Empty; } else { int length = path.LastIndexOf((OSHelper.IsUnix ? '/' : '\\')); switch (length) { case -1: goto Label_00A3; case 0: length++; break; } str = path.Substring(0, length); } goto Label_00A9; Label_00A3: str = string.Empty; Label_00A9: str3 = str; } return(str3); }
/// <summary> /// Determines if the item at the specified path has children. /// </summary> /// <param name="path"> /// The path to the item to see if it has children. /// </param> /// <returns> /// True if the item has children, false otherwise. /// </returns> /// <returns> /// Nothing is returned, but all objects should be written to the WriteItemObject method. /// </returns> /// <remarks> /// Providers override this method to give the provider infrastructure the ability to determine /// if a particular provider object has children without having to retrieve all the child items. /// /// For implementers of <see cref="ContainerCmdletProvider"/> classes and those derived from it, /// if a null or empty path is passed, /// the provider should consider any items in the data store to be children /// and return true. /// /// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>. /// </remarks> protected virtual bool HasChildItems(string path) { using (PSTransactionManager.GetEngineProtectionScope()) { throw PSTraceSource.NewNotSupportedException( SessionStateStrings.CmdletProvider_NotSupported); } }
/// <summary> /// Gives the provider an opportunity to attach additional parameters to /// the move-item 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="destination"> /// The path of the destination container. /// </param> /// <returns> /// Overrides of this method should return an object that has properties and fields decorated with /// parsing attributes similar to a cmdlet class or a /// <see cref="System.Management.Automation.RuntimeDefinedParameterDictionary"/>. /// /// The default implementation returns null. (no additional parameters) /// </returns> protected virtual object MoveItemDynamicParameters( string path, string destination) { using (PSTransactionManager.GetEngineProtectionScope()) { return(null); } }
/// <summary> /// Normalizes the path that was passed in and returns the normalized path /// as a relative path to the basePath that was passed. /// </summary> /// <param name="path"> /// A fully qualified provider specific path to an item. The item should exist /// or the provider should write out an error. /// </param> /// <param name="basePath"> /// The path that the return value should be relative to. /// </param> /// <returns> /// A normalized path that is relative to the basePath that was passed. The /// provider should parse the path parameter, normalize the path, and then /// return the normalized path relative to the basePath. /// </returns> /// <remarks> /// This method does not have to be purely syntactical parsing of the path. It /// is encouraged that the provider actually use the path to lookup in its store /// and create a relative path that matches the casing, and standardized path syntax. /// /// Note, the base class implementation uses GetParentPath, GetChildName, and MakePath /// to normalize the path and then make it relative to basePath. All string comparisons /// are done using StringComparison.InvariantCultureIgnoreCase. /// </remarks> protected virtual string NormalizeRelativePath( string path, string basePath) { using (PSTransactionManager.GetEngineProtectionScope()) { return(ContractRelativePath(path, basePath, false, Context)); } }
public bool ShouldProcess( string verboseDescription, string verboseWarning, string caption, out ShouldProcessReason shouldProcessReason) { using (PSTransactionManager.GetEngineProtectionScope()) return(this.Context.ShouldProcess(verboseDescription, verboseWarning, caption, out shouldProcessReason)); }
protected virtual bool ConvertPath( string path, string filter, ref string updatedPath, ref string updatedFilter) { using (PSTransactionManager.GetEngineProtectionScope()) return(false); }
/// <summary> /// Gets the name of the leaf element in the specified path. /// </summary> /// <param name="path"> /// The fully qualified path to the item /// </param> /// <returns> /// The leaf element in the path. /// </returns> /// <remarks> /// This should be implemented as a split on the path separator. The characters /// in the fullPath may not be legal characters in the namespace but may be /// used in globing or regular expression matching. The provider should not error /// unless there are no path separators in the fully qualified path. /// </remarks> protected virtual string GetChildName(string path) { using (PSTransactionManager.GetEngineProtectionScope()) { // Verify the parameters if (String.IsNullOrEmpty(path)) { throw PSTraceSource.NewArgumentException("path"); } // Normalize the path path = NormalizePath(path); // Trim trailing back slashes path = path.TrimEnd(StringLiterals.DefaultPathSeparator); string result = null; int separatorIndex = path.LastIndexOf(StringLiterals.DefaultPathSeparator); // Since there was no path separator return the entire path if (separatorIndex == -1) { result = path; } // If the full path existed, we must semantically evaluate the parent path else if (ItemExists(path, Context)) { string parentPath = GetParentPath(path, null); // No parent, return the entire path if (String.IsNullOrEmpty(parentPath)) { result = path; } // If the parent path ends with the path separator, we can't split // the path based on that else if (parentPath.IndexOf(StringLiterals.DefaultPathSeparator) == (parentPath.Length - 1)) { separatorIndex = path.IndexOf(parentPath, StringComparison.OrdinalIgnoreCase) + parentPath.Length; result = path.Substring(separatorIndex); } else { separatorIndex = path.IndexOf(parentPath, StringComparison.OrdinalIgnoreCase) + parentPath.Length; result = path.Substring(separatorIndex + 1); } } // Otherwise, use lexical parsing else { result = path.Substring(separatorIndex + 1); } return(result); } }
} // ClearItemDynamicParameters /// <summary> /// Invokes the default action on the specified item. /// </summary> /// /// <param name="path"> /// The path to the item to perform the default action on. /// </param> /// /// <returns> /// Nothing. The item that was set should be passed to the WriteItemObject method. /// </returns> /// /// <remarks> /// The default implementation does nothing. /// /// Providers override this method to give the user the ability to invoke provider objects using /// the invoke-item cmdlet. Think of the invocation as a double click in the Windows Shell. This /// method provides a default action based on the path that was passed. /// /// Providers that declare <see cref="System.Management.Automation.Provider.ProviderCapabilities"/> /// of ExpandWildcards, Filter, Include, or Exclude should ensure that the path passed meets those /// requirements by accessing the appropriate property from the base class. /// /// By default overrides of this method should not invoke objects that are generally hidden from /// the user unless the Force property is set to true. An error should be sent to the WriteError method if /// the path represents an item that is hidden from the user and Force is set to false. /// </remarks> protected virtual void InvokeDefaultAction( string path) { using (PSTransactionManager.GetEngineProtectionScope()) { throw PSTraceSource.NewNotSupportedException( SessionStateStrings.CmdletProvider_NotSupported); } }
/// <summary> /// Removes (deletes) the item at the specified path. /// </summary> /// <param name="path"> /// The path to the item to remove. /// </param> /// <param name="recurse"> /// True if all children in a subtree should be removed, false if only a single /// level of children should be removed. This parameter should only be true for /// NavigationCmdletProvider and its derived classes. /// </param> /// <returns> /// Nothing should be returned or written from this method. /// </returns> /// <remarks> /// Providers override this method to allow the user the ability to remove provider objects using /// the remove-item cmdlet. /// /// Providers that declare <see cref="System.Management.Automation.Provider.ProviderCapabilities"/> /// of ExpandWildcards, Filter, Include, or Exclude should ensure that the path passed meets those /// requirements by accessing the appropriate property from the base class. /// /// By default overrides of this method should not remove objects that are generally hidden from /// the user unless the Force property is set to true. For instance, the FileSystem provider should /// not remove a hidden or system file unless the Force property is set to true. /// /// The provider implementation is responsible for preventing infinite recursion when there are /// circular links and the like. An appropriate terminating exception should be thrown if this /// situation occurs. /// /// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>. /// </remarks> protected virtual void RemoveItem( string path, bool recurse) { using (PSTransactionManager.GetEngineProtectionScope()) { throw PSTraceSource.NewNotSupportedException( SessionStateStrings.CmdletProvider_NotSupported); } }
/// <summary> /// Gets names of the children of the specified path. /// </summary> /// <param name="path"> /// The path to the item from which to retrieve the child names. /// </param> /// <param name="returnContainers"> /// Determines if all containers should be returned or only those containers that match the /// filter(s). /// </param> /// <returns> /// Nothing is returned, but all objects should be written to the WriteItemObject method. /// </returns> /// <remarks> /// Providers override this method to give the user access to the provider objects using /// the get-childitem -name cmdlet. /// /// Providers that declare <see cref="System.Management.Automation.Provider.ProviderCapabilities"/> /// of ExpandWildcards, Filter, Include, or Exclude should ensure that the path passed meets those /// requirements by accessing the appropriate property from the base class. The exception to this /// is if <paramref name="returnAllContainers"/> is true, then any child name for a container should /// be returned even if it doesn't match the Filter, Include, or Exclude. /// /// By default overrides of this method should not write the names of objects that are generally hidden from /// the user unless the Force property is set to true. For instance, the FileSystem provider should /// not call WriteItemObject for hidden or system files unless the Force property is set to true. /// /// The provider implementation is responsible for preventing infinite recursion when there are /// circular links and the like. An appropriate terminating exception should be thrown if this /// situation occurs. /// /// The default implementation of this method throws an <see cref="System.Management.Automation.PSNotSupportedException"/>. /// </remarks> protected virtual void GetChildNames( string path, ReturnContainers returnContainers) { using (PSTransactionManager.GetEngineProtectionScope()) { throw PSTraceSource.NewNotSupportedException( SessionStateStrings.CmdletProvider_NotSupported); } }
public void WriteProgress(ProgressRecord progressRecord) { using (PSTransactionManager.GetEngineProtectionScope()) { if (progressRecord == null) { throw CmdletProvider.providerBaseTracer.NewArgumentNullException(nameof(progressRecord)); } this.Context.WriteProgress(progressRecord); } }
public IEnumerable <T> Invoke <T>() { using (PSTransactionManager.GetEngineProtectionScope()) { ArrayList data = this.GetResults(); for (int i = 0; i < data.Count; ++i) { yield return((T)data[i]); } } }
public void WriteDebug(string text) { using (PSTransactionManager.GetEngineProtectionScope()) { if (this.commandRuntime == null) { throw new NotImplementedException(nameof(WriteDebug)); } this.commandRuntime.WriteDebug(text); } }
public void WriteProgress(ProgressRecord progressRecord) { using (PSTransactionManager.GetEngineProtectionScope()) { if (this.commandRuntime == null) { throw new NotImplementedException(nameof(WriteProgress)); } this.commandRuntime.WriteProgress(progressRecord); } }
public void WriteObject(object sendToPipeline, bool enumerateCollection) { using (PSTransactionManager.GetEngineProtectionScope()) { if (this.commandRuntime == null) { throw new NotImplementedException(nameof(WriteObject)); } this.commandRuntime.WriteObject(sendToPipeline, enumerateCollection); } }