protected override void ProcessRecord() { if (this.PSProvider == null || this.PSProvider != null && (int)this.PSProvider.Length == 0) { base.WriteObject(base.SessionState.Provider.GetAll(), true); return; } else { string[] pSProvider = this.PSProvider; for (int i = 0; i < (int)pSProvider.Length; i++) { string str = pSProvider[i]; PSSnapinQualifiedName instance = PSSnapinQualifiedName.GetInstance(str); if (instance == null || !WildcardPattern.ContainsWildcardCharacters(instance.ShortName)) { try { Collection <ProviderInfo> providerInfos = base.SessionState.Provider.Get(str); base.WriteObject(providerInfos, true); } catch (ProviderNotFoundException providerNotFoundException1) { ProviderNotFoundException providerNotFoundException = providerNotFoundException1; base.WriteError(new ErrorRecord(providerNotFoundException.ErrorRecord, providerNotFoundException)); } } else { WildcardPattern wildcardPattern = new WildcardPattern(instance.ShortName, WildcardOptions.IgnoreCase); foreach (ProviderInfo all in base.SessionState.Provider.GetAll()) { if (!all.IsMatch(wildcardPattern, instance)) { continue; } base.WriteObject(all); } } } return; } }
/// <summary> /// Search for provider help based on a search target. /// </summary> /// <param name="helpRequest">Help request object.</param> /// <param name="searchOnlyContent"> /// If true, searches for pattern in the help content. Individual /// provider can decide which content to search in. /// /// If false, searches for pattern in the command names. /// </param> /// <returns></returns> internal override IEnumerable <HelpInfo> SearchHelp(HelpRequest helpRequest, bool searchOnlyContent) { int countOfHelpInfoObjectsFound = 0; string target = helpRequest.Target; string pattern = target; // this will be used only when searchOnlyContent == true WildcardPattern wildCardPattern = null; bool decoratedSearch = !WildcardPattern.ContainsWildcardCharacters(target); if (!searchOnlyContent) { if (decoratedSearch) { pattern += "*"; } } else { string searchTarget = helpRequest.Target; if (decoratedSearch) { searchTarget = "*" + helpRequest.Target + "*"; } wildCardPattern = WildcardPattern.Get(searchTarget, WildcardOptions.Compiled | WildcardOptions.IgnoreCase); // search in all providers pattern = "*"; } PSSnapinQualifiedName snapinQualifiedNameForPattern = PSSnapinQualifiedName.GetInstance(pattern); if (snapinQualifiedNameForPattern == null) { yield break; } foreach (ProviderInfo providerInfo in _sessionState.Provider.GetAll()) { if (providerInfo.IsMatch(pattern)) { try { LoadHelpFile(providerInfo); } catch (IOException ioException) { if (!decoratedSearch) { ReportHelpFileError(ioException, providerInfo.Name, providerInfo.HelpFile); } } catch (System.Security.SecurityException securityException) { if (!decoratedSearch) { ReportHelpFileError(securityException, providerInfo.Name, providerInfo.HelpFile); } } catch (XmlException xmlException) { if (!decoratedSearch) { ReportHelpFileError(xmlException, providerInfo.Name, providerInfo.HelpFile); } } HelpInfo helpInfo = GetCache(providerInfo.PSSnapInName + "\\" + providerInfo.Name); if (helpInfo != null) { if (searchOnlyContent) { // ignore help objects that do not have pattern in its help // content. if (!helpInfo.MatchPatternInContent(wildCardPattern)) { continue; } } countOfHelpInfoObjectsFound++; yield return(helpInfo); if (countOfHelpInfoObjectsFound >= helpRequest.MaxResults && helpRequest.MaxResults > 0) { yield break; } } } } }
internal List <PSDriveInfo> GetMatchingDrives(string driveName, string[] providerNames, string scope) { List <PSDriveInfo> pSDriveInfos = new List <PSDriveInfo>(); if (providerNames == null || (int)providerNames.Length == 0) { string[] strArrays = new string[1]; strArrays[0] = "*"; providerNames = strArrays; } string[] strArrays1 = providerNames; for (int i = 0; i < (int)strArrays1.Length; i++) { string str = strArrays1[i]; object[] objArray = new object[1]; objArray[0] = str; CoreCommandBase.tracer.WriteLine("ProviderName: {0}", objArray); bool flag = string.IsNullOrEmpty(str); bool flag1 = WildcardPattern.ContainsWildcardCharacters(str); bool flag2 = string.IsNullOrEmpty(driveName); bool flag3 = WildcardPattern.ContainsWildcardCharacters(driveName); if (!flag && !flag1) { base.SessionState.Provider.Get(str); } if (!flag2 && !flag3) { if (!string.IsNullOrEmpty(scope)) { base.SessionState.Drive.GetAtScope(driveName, scope); } else { base.SessionState.Drive.Get(driveName); } } WildcardPattern wildcardPattern = null; PSSnapinQualifiedName instance = null; if (!flag) { instance = PSSnapinQualifiedName.GetInstance(str); if (instance == null) { goto Label0; } wildcardPattern = new WildcardPattern(instance.ShortName, WildcardOptions.IgnoreCase); } WildcardPattern wildcardPattern1 = null; if (!flag2) { wildcardPattern1 = new WildcardPattern(driveName, WildcardOptions.IgnoreCase); } foreach (PSDriveInfo allAtScope in base.SessionState.Drive.GetAllAtScope(scope)) { bool flag4 = flag2; if (!base.SuppressWildcardExpansion) { if (wildcardPattern1.IsMatch(allAtScope.Name)) { flag4 = true; } } else { if (string.Equals(allAtScope.Name, driveName, StringComparison.OrdinalIgnoreCase)) { flag4 = true; } } if (!flag4 || !flag && !allAtScope.Provider.IsMatch(wildcardPattern, instance)) { continue; } pSDriveInfos.Add(allAtScope); } Label0: continue; } pSDriveInfos.Sort(); return(pSDriveInfos); }