예제 #1
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            IProductCollectionByCountry operations = Partner.Products.ByCountry(string.IsNullOrEmpty(CountryCode) ? PartnerSession.Instance.Context.CountryCode : CountryCode);

            if (ParameterSetName == ByProductIdParameterSetName)
            {
                WriteObject(new PSProduct(operations.ById(ProductId).GetAsync().ConfigureAwait(false).GetAwaiter().GetResult()));
            }
            else if (ParameterSetName == ByReservationScopeParameterSetName)
            {
                WriteObject(
                    new PSProduct(
                        operations.ById(ProductId).ByReservationScope(ReservationScope).GetAsync().ConfigureAwait(false).GetAwaiter().GetResult()));
            }
            else if (ParameterSetName == ByTargetViewParameterSetName)
            {
                if (string.IsNullOrEmpty(Segment))
                {
                    WriteObject(
                        operations.ByTargetView(Catalog).GetAsync().ConfigureAwait(false).GetAwaiter().GetResult()
                        .Items.Select(p => new PSProduct(p)), true);
                }
                else
                {
                    WriteObject(
                        operations.ByTargetView(Catalog).ByTargetSegment(Segment).GetAsync().ConfigureAwait(false).GetAwaiter().GetResult()
                        .Items.Select(p => new PSProduct(p)), true);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Scheduler.RunTask(async() =>
            {
                IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync(CorrelationId, CancellationToken).ConfigureAwait(false);
                IProductCollectionByCountry operations = partner.Products.ByCountry(string.IsNullOrEmpty(CountryCode) ? PartnerSession.Instance.Context.CountryCode : CountryCode);

                if (ParameterSetName == ByProductIdParameterSetName)
                {
                    WriteObject(new PSProduct(await operations.ById(ProductId).GetAsync(CancellationToken).ConfigureAwait(false)));
                }
                else if (ParameterSetName == ByReservationScopeParameterSetName)
                {
                    WriteObject(
                        new PSProduct(
                            await operations.ById(ProductId).ByReservationScope(ReservationScope).GetAsync(CancellationToken).ConfigureAwait(false)));
                }
                else if (ParameterSetName == ByTargetViewParameterSetName)
                {
                    ResourceCollection <Product> products;

                    if (string.IsNullOrEmpty(Segment))
                    {
                        products = await operations.ByTargetView(Catalog).GetAsync(CancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        products = await operations.ByTargetView(Catalog).ByTargetSegment(Segment).GetAsync(CancellationToken).ConfigureAwait(false);
                    }

                    WriteObject(products.Items.Select(p => new PSProduct(p)), true);
                }
            }, true);
        }