コード例 #1
0
        public override void ExecuteCmdlet()
        {
            if (ShouldProcess(Name, Resources.CreateNewPowerBIEmbeddedCapacity))
            {
                try
                {
                    if (PowerBIClient.GetCapacity(ResourceGroupName, Name) != null)
                    {
                        throw new CloudException(string.Format(Resources.PowerBIEmbeddedCapacityExists, Name));
                    }
                }
                catch (CloudException ex)
                {
                    if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) && ex.Body.Code == "ResourceNotFound" ||
                        ex.Message.Contains("ResourceNotFound"))
                    {
                        // capacity does not exists so go ahead and create one
                    }
                    else if (ex.Body != null && !string.IsNullOrEmpty(ex.Body.Code) &&
                             ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                    {
                        // resource group not found, let create throw error don't throw from here
                    }
                    else
                    {
                        // all other exceptions should be thrown
                        throw;
                    }
                }

                var createdCapacity = PowerBIClient.CreateOrUpdateCapacity(ResourceGroupName, Name, Location, Sku, Tag, Administrator, null);
                WriteObject(createdCapacity);
            }
        }
コード例 #2
0
        public override void ExecuteCmdlet()
        {
            string resourceGroupName = ResourceGroupName;
            string capacityName      = Name;

            if (!string.IsNullOrEmpty(ResourceId))
            {
                PowerBIUtils.GetResourceGroupNameAndCapacityName(ResourceId, out resourceGroupName, out capacityName);
            }

            if (!string.IsNullOrEmpty(capacityName))
            {
                // Get for single capacity
                var capacity = PowerBIClient.GetCapacity(resourceGroupName, capacityName);
                WriteObject(capacity);
            }
            else
            {
                // List all capacities in given resource group if avaliable otherwise all capacities in the subscription
                var list = PowerBIClient.ListCapacities(resourceGroupName);
                WriteObject(list, true);
            }
        }