private void SetRegistryDetials(PSContainerRegistry registry)
 {
     if (!string.IsNullOrEmpty(registry.ResourceGroupName) && !string.IsNullOrEmpty(registry.Name))
     {
         registry.Usages = RegistryClient.ListRegistryUsage(registry.ResourceGroupName, registry.Name)?.Value;
     }
 }
        private void ShowRegistry()
        {
            var registry   = RegistryClient.GetRegistry(ResourceGroupName, Name);
            var psRegistry = new PSContainerRegistry(registry);

            if (IncludeDetail)
            {
                SetRegistryDetials(psRegistry);
            }
            WriteObject(psRegistry);
        }
        public IList <PSContainerRegistry> ListAllRegistries(string resourceGroupName)
        {
            List <PSContainerRegistry> list = new List <PSContainerRegistry>();

            var registries = ListRegistries(resourceGroupName);

            foreach (Registry registry in registries)
            {
                list.Add(new PSContainerRegistry(registry));
            }

            while (!string.IsNullOrEmpty(registries.NextPageLink))
            {
                registries = ListRegistriesUsingNextLink(resourceGroupName, registries.NextPageLink);
                foreach (Registry registry in registries)
                {
                    var psRegistry = new PSContainerRegistry(registry);
                    list.Add(psRegistry);
                }
            }
            return(list);
        }
        public string GetStorageAccountResourceGroup(string storageAccountName)
        {
            var filterExpression = $"ResourceType eq 'Microsoft.Storage/storageAccounts' AND name eq '{storageAccountName}'";
            var odataQuery       = new ODataQuery <GenericResourceFilter>()
            {
                Filter = filterExpression
            };
            var result = ResourceManagementClient.Resources.List(odataQuery);

            var resource = result.FirstOrDefault();

            while (resource == null && result.NextPageLink != null)
            {
                result   = ResourceManagementClient.Resources.ListNext(result.NextPageLink);
                resource = result.FirstOrDefault();
            }

            if (resource == null)
            {
                throw new InvalidOperationException($"Storage account {storageAccountName} doesn't exist.");
            }

            return(PSContainerRegistry.ParseResourceGroupFromId(resource.Id));
        }