コード例 #1
0
        /// <summary>
        /// The get nat rules.
        /// </summary>
        /// <param name="networkId">
        /// The network id.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        public async Task <IEnumerable <NatRuleType> > GetNatRules(string networkId)
        {
            NatRules natRules =
                await _apiClient.GetAsync <NatRules>(ApiUris.GetNatRules(_apiClient.OrganizationId, networkId));

            return(natRules.NatRule);
        }
        /// <summary>
        ///     Asynchronously perform Cmdlet processing.
        /// </summary>
        /// <param name="cancellationToken">
        ///     A <see cref="CancellationToken"/> that can be used to cancel Cmdlet processing.
        /// </param>
        /// <returns>
        ///     A <see cref="Task"/> representing the asynchronous operation.
        /// </returns>
        protected override async Task ProcessRecordAsync(CancellationToken cancellationToken)
        {
            CloudControlClient client = GetClient();

            switch (ParameterSetName)
            {
            case "By Id":
            {
                NatRule natRule = await client.GetNatRule(Id, cancellationToken);

                if (natRule == null)
                {
                    WriteError(
                        Errors.ResourceNotFoundById <NatRule>(Id)
                        );
                }
                else
                {
                    WriteObject(natRule);
                }

                break;
            }

            case "By network domain":
            {
                Paging paging = GetPagingConfiguration();

                NatRules natRules = await client.ListNatRules(NetworkDomainId, paging, cancellationToken);

                WriteObject(natRules.Items,
                            enumerateCollection: true
                            );

                break;
            }

            default:
            {
                ThrowTerminatingError(
                    Errors.UnrecognizedParameterSet(this)
                    );

                return;
            }
            }
        }