public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ApplicationGroupResourceIdParameterSet)
            {
                ResourceIdentifier getParamAppGroup = new ResourceIdentifier(ResourceId);

                ResourceGroupName = getParamAppGroup.ResourceGroupName;

                if (getParamAppGroup.ResourceType.ToLower() == NamespaceURL.ToLower())
                {
                    NamespaceName = getParamAppGroup.ResourceName;
                }

                else if (getParamAppGroup.ResourceType.ToLower() == ApplicationGroupURL.ToLower())
                {
                    string[] resourceNames = getParamAppGroup.ParentResource.Split(new[] { '/' });
                    NamespaceName = resourceNames[1];
                    Name          = getParamAppGroup.ResourceName;
                }
                else
                {
                    throw new Exception("Invalid Resource Id");
                }
            }

            try
            {
                if (Name == null)
                {
                    if (ShouldProcess(target: NamespaceName, action: string.Format(Resources.ListApplicationGroup, NamespaceName, ResourceGroupName)))
                    {
                        WriteObject(Client.ListApplicationGroup(ResourceGroupName, NamespaceName));
                    }
                }
                else
                {
                    if (ShouldProcess(target: Name, action: string.Format(Resources.GetApplicationGroup, Name, NamespaceName, ResourceGroupName)))
                    {
                        WriteObject(Client.GetApplicationGroup(ResourceGroupName, NamespaceName, Name));
                    }
                }
            }
            catch (Management.EventHub.Models.ErrorResponseException ex)
            {
                WriteError(Eventhub.EventHubsClient.WriteErrorforBadrequest(ex));
            }
        }
Пример #2
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ApplicationGroupResourceIdParameterSet || ParameterSetName == ApplicationGroupInputObjectParameterSet)
            {
                if (InputObject != null)
                {
                    ResourceId = InputObject.Id;
                }

                ResourceIdentifier getParamApplicationGroup = new ResourceIdentifier(ResourceId);

                if (getParamApplicationGroup.ResourceType.ToLower().Equals(ApplicationGroupURL.ToLower()))
                {
                    ResourceGroupName = getParamApplicationGroup.ResourceGroupName;
                    string[] resourceNames = getParamApplicationGroup.ParentResource.Split(new[] { '/' });
                    NamespaceName = resourceNames[1];
                    Name          = getParamApplicationGroup.ResourceName;
                }

                else
                {
                    throw new Exception("Invalid Resource Id");
                }
            }

            if (ShouldProcess(target: Name, action: string.Format(Resources.RemoveApplicationGroup, Name, NamespaceName, ResourceGroupName)))
            {
                try
                {
                    Client.DeleteApplicationGroup(resourceGroupName: ResourceGroupName,
                                                  namespaceName: NamespaceName,
                                                  appGroupName: Name);

                    if (PassThru)
                    {
                        WriteObject(true);
                    }
                }

                catch (Management.EventHub.Models.ErrorResponseException ex)
                {
                    WriteError(Eventhub.EventHubsClient.WriteErrorforBadrequest(ex));
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ApplicationGroupResourceIdParameterSet || ParameterSetName == ApplicationGroupInputObjectParameterSet)
            {
                if (InputObject != null)
                {
                    ResourceId = InputObject.Id;
                }

                ResourceIdentifier getParamApplicationGroup = new ResourceIdentifier(ResourceId);

                if (getParamApplicationGroup.ResourceType.ToLower().Equals(ApplicationGroupURL.ToLower()))
                {
                    ResourceGroupName = getParamApplicationGroup.ResourceGroupName;
                    string[] resourceNames = getParamApplicationGroup.ParentResource.Split(new[] { '/' });
                    NamespaceName = resourceNames[1];
                    Name          = getParamApplicationGroup.ResourceName;
                }

                else
                {
                    throw new Exception("Invalid Resource Id");
                }
            }


            if (ShouldProcess(target: Name, action: string.Format(Resources.UpdateApplicationGroup, Name, NamespaceName, ResourceGroupName)))
            {
                try
                {
                    if (ParameterSetName == ApplicationGroupPropertiesParameterSet || ParameterSetName == ApplicationGroupResourceIdParameterSet)
                    {
                        bool?isEnabled = null;

                        //This is done because isPresent does not really indicate if SwitchParameter
                        //is explicitly set to false or not present at all
                        if (this.IsParameterBound(c => c.IsEnabled) == true)
                        {
                            isEnabled = IsEnabled.IsPresent;
                        }

                        WriteObject(Client.UpdateApplicationGroup(resourceGroupName: ResourceGroupName,
                                                                  namespaceName: NamespaceName,
                                                                  appGroupName: Name,
                                                                  isEnabled: isEnabled,
                                                                  throttlingPolicy: ThrottlingPolicyConfig));
                    }
                    else if (ParameterSetName == ApplicationGroupInputObjectParameterSet)
                    {
                        //When InputObject is given as a parameter, the assumption is that the consumer has given the entire desired state
                        //Hence we reconstruct a new app group object
                        //That is why a create call and not update call.
                        WriteObject(Client.CreateApplicationGroup(resourceGroupName: ResourceGroupName,
                                                                  namespaceName: NamespaceName,
                                                                  appGroupName: Name,
                                                                  clientAppGroupIdentifier: InputObject.ClientAppGroupIdentifier,
                                                                  isEnabled: InputObject.IsEnabled,
                                                                  throttlingPolicy: InputObject.ThrottlingPolicyConfig));
                    }
                }

                catch (Management.EventHub.Models.ErrorResponseException ex)
                {
                    WriteError(Eventhub.EventHubsClient.WriteErrorforBadrequest(ex));
                }
            }
        }