public override void ExecuteCmdlet()
        {
            string capacityName      = Name;
            string resourceGroupName = ResourceGroupName;

            if (!string.IsNullOrEmpty(ResourceId))
            {
                PowerBIUtils.GetResourceGroupNameAndCapacityName(ResourceId, out resourceGroupName, out capacityName);
            }
            else if (InputObject != null)
            {
                PowerBIUtils.GetResourceGroupNameAndCapacityName(InputObject.Id, out resourceGroupName, out capacityName);
            }

            if (string.IsNullOrEmpty(capacityName))
            {
                WriteExceptionError(new PSArgumentNullException("Name", "Name of capacity not specified"));
            }

            if (ShouldProcess(capacityName, Resources.RemovingPowerBIEmbeddedCapacity))
            {
                PSPowerBIEmbeddedCapacity capacity = null;
                if (!PowerBIClient.TestCapacity(resourceGroupName, capacityName, out capacity))
                {
                    throw new InvalidOperationException(string.Format(Properties.Resources.CapacityDoesNotExist, capacityName));
                }

                PowerBIClient.DeleteCapacity(resourceGroupName, capacityName);

                if (PassThru.IsPresent)
                {
                    WriteObject(capacity);
                }
            }
        }
Esempio n. 2
0
        public override void ExecuteCmdlet()
        {
            string capacityName      = Name;
            string resourceGroupName = ResourceGroupName;

            if (!string.IsNullOrEmpty(ResourceId))
            {
                PowerBIUtils.GetResourceGroupNameAndCapacityName(ResourceId, out resourceGroupName, out capacityName);
            }
            else if (InputObject != null)
            {
                PowerBIUtils.GetResourceGroupNameAndCapacityName(InputObject.Id, out resourceGroupName, out capacityName);
            }

            if (ShouldProcess(capacityName, Resources.SuspendingPowerBIEmbeddedCapacity))
            {
                PSPowerBIEmbeddedCapacity capacity = null;
                if (!PowerBIClient.TestCapacity(resourceGroupName, capacityName, out capacity))
                {
                    throw new InvalidOperationException(string.Format(Properties.Resources.CapacityDoesNotExist, capacityName));
                }

                PowerBIClient.SuspendCapacity(resourceGroupName, capacityName);

                if (PassThru.IsPresent)
                {
                    // Update the capacity current state
                    if (!PowerBIClient.TestCapacity(resourceGroupName, capacityName, out capacity))
                    {
                        throw new InvalidOperationException(string.Format(Properties.Resources.CapacityDoesNotExist, capacityName));
                    }
                    WriteObject(capacity);
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            string capacityName      = Name;
            string resourceGroupName = ResourceGroupName;

            if (!string.IsNullOrEmpty(ResourceId))
            {
                PowerBIUtils.GetResourceGroupNameAndCapacityName(ResourceId, out resourceGroupName, out capacityName);
            }
            else if (InputObject != null)
            {
                PowerBIUtils.GetResourceGroupNameAndCapacityName(InputObject.Id, out resourceGroupName, out capacityName);
            }

            if (string.IsNullOrEmpty(capacityName))
            {
                WriteExceptionError(new PSArgumentNullException("Name", "Name of capacity not specified"));
            }

            if (ShouldProcess(capacityName, Resources.UpdatingPowerBIEmbeddedCapacity))
            {
                PSPowerBIEmbeddedCapacity currentCapacity = null;
                if (!PowerBIClient.TestCapacity(resourceGroupName, capacityName, out currentCapacity))
                {
                    throw new InvalidOperationException(string.Format(Properties.Resources.CapacityDoesNotExist, capacityName));
                }

                var availableSkus = PowerBIClient.ListSkusForExisting(resourceGroupName, capacityName);
                if (Sku != null && !availableSkus.Value.Any(v => v.Sku.Name == Sku))
                {
                    throw new InvalidOperationException(string.Format(Resources.InvalidSku, Sku, String.Join(",", availableSkus.Value.Select(v => v.Sku.Name))));
                }

                var location = currentCapacity.Location;
                if (Tag == null && currentCapacity.Tag != null)
                {
                    Tag = TagsConversionHelper.CreateTagHashtable(currentCapacity.Tag);
                }

                PSPowerBIEmbeddedCapacity updateCapacity = PowerBIClient.CreateOrUpdateCapacity(resourceGroupName, capacityName, location, Sku, Tag, Administrator, currentCapacity);

                if (PassThru.IsPresent)
                {
                    WriteObject(updateCapacity);
                }
            }
        }
Esempio n. 4
0
        public override void ExecuteCmdlet()
        {
            PSPowerBIEmbeddedCapacity capacity = null;

            WriteObject(PowerBIClient.TestCapacity(string.Empty, Name, out capacity));
        }