Microsoft.Azure.Commands.Resources.GetAzureProviderOperationCommand.GetNonWildcardPrefix C# (CSharp) Method

GetNonWildcardPrefix() private static method

Extracts the portion of the actionstring before the first wildcard character (*)
private static GetNonWildcardPrefix ( string actionString ) : string
actionString string
return string
        private static string GetNonWildcardPrefix(string actionString)
        {
            int index = actionString.IndexOf(WildCardCharacter);
            return index >= 0 ? actionString.Substring(0, index) : actionString;
        }
    }

Usage Example

        /// <summary>
        /// Get a list of Provider operations in the case that the Actionstring input contains a wildcard
        /// </summary>
        private List <PSResourceProviderOperation> ProcessProviderOperationsWithWildCard(string actionString)
        {
            // Filter the list of all operation names to what matches the wildcard
            WildcardPattern wildcard = new WildcardPattern(actionString, WildcardOptions.IgnoreCase | WildcardOptions.Compiled);

            List <ProviderOperationsMetadata> providers = new List <ProviderOperationsMetadata>();

            string nonWildCardPrefix = GetAzureProviderOperationCommand.GetNonWildcardPrefix(actionString);

            if (string.IsNullOrWhiteSpace(nonWildCardPrefix))
            {
                // 'Get-AzureRmProviderOperation *' or 'Get-AzureRmProviderOperation */virtualmachines/*'
                // get operations for all providers
                providers.AddRange(this.ResourcesClient.ListProviderOperationsMetadata());
            }
            else
            {
                // Some string exists before the wild card character - potentially the full name of the provider.
                string providerFullName = GetAzureProviderOperationCommand.GetResourceProviderFullName(nonWildCardPrefix);
                if (!string.IsNullOrWhiteSpace(providerFullName))
                {
                    // we have the full name of the provider. 'Get-AzureRmProviderOperation Microsoft.Sql/servers/*'
                    // only query for that provider
                    providers.Add(this.ResourcesClient.GetProviderOperationsMetadata(providerFullName));
                }
                else
                {
                    // We have only a partial name of the provider, say Microsoft.*/* or Microsoft.*/*/read.
                    // query for all providers and then do prefix match on the operations
                    providers.AddRange(this.ResourcesClient.ListProviderOperationsMetadata());
                }
            }

            return(providers.SelectMany(p => GetPSOperationsFromProviderOperationsMetadata(p)).Where(operation => wildcard.IsMatch(operation.Operation)).ToList());
        }
All Usage Examples Of Microsoft.Azure.Commands.Resources.GetAzureProviderOperationCommand::GetNonWildcardPrefix