コード例 #1
0
        /// <summary>
        /// Edits an ip address list.
        /// </summary>
        /// <param name="editPortList">The ip address list details.</param>
        /// <returns>The response details.</returns>
        public async Task <ResponseType> EditPortList(editPortList editPortList)
        {
            if (editPortList.portSpecified && (editPortList.port == null || editPortList.port.Length == 0))
            {
                editPortList.port = new EditPortListPort[] { null };
            }

            if (editPortList.childPortListIdSpecified && (editPortList.childPortListId == null || editPortList.childPortListId.Length == 0))
            {
                editPortList.childPortListId = new string[] { null };
            }

            if (!string.IsNullOrWhiteSpace(editPortList.description))
            {
                editPortList.descriptionSpecified = true;
            }

            return(await _api.PostAsync <editPortList, ResponseType>(
                       ApiUris.EditPortList(_api.OrganizationId),
                       editPortList));
        }
コード例 #2
0
        /// <summary>
        ///     The process record method.
        /// </summary>
        protected override void ProcessRecord()
        {
            ResponseType response = null;

            base.ProcessRecord();
            try
            {
                if (PortList != null)
                {
                    Id = Guid.Parse(PortList.id);
                }

                var port = Port != null
                    ? Port.Select(x => new EditPortListPort
                {
                    begin          = x.Begin ?? 0,
                    end            = x.End ?? 0,
                    beginSpecified = x.Begin.HasValue,
                    endSpecified   = x.End.HasValue,
                }).ToArray()
                    : null;

                if (ChildPortList != null && ChildPortList.Length > 0)
                {
                    ChildPortListId = ChildPortList.Select(x => x.id).ToArray();
                }

                var portList = new editPortList
                {
                    id                       = Id.ToString(),
                    description              = Description,
                    descriptionSpecified     = _descriptionSpecified,
                    port                     = port,
                    portSpecified            = _portSpecified,
                    childPortListId          = ChildPortListId,
                    childPortListIdSpecified = _childPortListIdSpecified,
                };

                response = Connection.ApiClient.Networking.FirewallRule.EditPortList(portList).Result;
            }
            catch (AggregateException ae)
            {
                ae.Handle(
                    e =>
                {
                    if (e is ComputeApiException)
                    {
                        WriteError(new ErrorRecord(e, "-2", ErrorCategory.InvalidOperation, Connection));
                    }
                    else
                    {
                        // if (e is HttpRequestException)
                        ThrowTerminatingError(new ErrorRecord(e, "-1", ErrorCategory.ConnectionError, Connection));
                    }

                    return(true);
                });
            }

            WriteObject(response);
        }