Пример #1
0
        /// <summary>
        ///     The process record method.
        /// </summary>
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            try
            {
                var option = new CustomerImageExportHistoryOptions
                {
                    ImageExportId    = ImageExportId,
                    ImageId          = ImageId,
                    DatacenterId     = DatacenterId,
                    ImageName        = ImageName,
                    OvfPackagePrefix = OvfPackagePrefix,
                    StartTime        = StartTime,
                    EndTime          = EndTime,
                    UserName         = UserName
                };


                IEnumerable <HistoricalImageExportType> resultlist = Connection.ApiClient.ServerManagement.ServerImage.GetCustomerImagesExportHistory(option, PageableRequest).Result.items;
                if (resultlist != null && resultlist.Any())
                {
                    switch (resultlist.Count())
                    {
                    case 0:
                        WriteError(
                            new ErrorRecord(
                                new ItemNotFoundException(
                                    "This command cannot find a matching object with the given parameters."
                                    ), "ItemNotFoundException", ErrorCategory.ObjectNotFound, resultlist));
                        break;

                    default:
                        WriteObject(resultlist, true);
                        break;
                    }
                }
            }
            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);
                });
            }
        }
        /// <summary>
        /// Get the customer images export history.
        /// </summary>
        /// <param name="filteringOptions">Filtering options</param>
        /// <param name="pagingOptions">Paging options</param>
        /// <returns>Customer Image with Exports in progress status</returns>
        public async Task <PagedResponse <HistoricalImageExportType> > GetCustomerImagesExportHistory(CustomerImageExportHistoryOptions filteringOptions = null, IPageableRequest pagingOptions = null)
        {
            var response = await _apiClient.GetAsync <historicalImageExports>(
                ApiUris.GetCustomerImageExportHistory(_apiClient.OrganizationId),
                pagingOptions,
                filteringOptions);

            return(new PagedResponse <HistoricalImageExportType>
            {
                items = response.historicalImageExport,
                totalCount = response.totalCountSpecified ? response.totalCount : (int?)null,
                pageCount = response.pageCountSpecified ? response.pageCount : (int?)null,
                pageNumber = response.pageNumberSpecified ? response.pageNumber : (int?)null,
                pageSize = response.pageSizeSpecified ? response.pageSize : (int?)null
            });
        }