/// <summary>
        /// Upgrades customers in list.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="listName">Name of the list.</param>
        /// <param name="skip">The skip.</param>
        /// <param name="take">The take.</param>
        /// <returns>Number of migrated customers</returns>
        protected virtual async Task <int> UpgradeCustomersInList(CommercePipelineExecutionContextOptions context, string listName, int skip, int take)
        {
            var findResult = await this._findEntitiesInListPipeline.Run(new FindEntitiesInListArgument(typeof(Customer), listName, skip, take) { LoadEntities = true }, context).ConfigureAwait(false);

            if (findResult?.List?.Items == null || !findResult.List.Items.Any())
            {
                return(0);
            }

            foreach (var item in findResult.List.Items)
            {
                var customer = (Customer)item;
                if (!string.IsNullOrEmpty(customer.UserName))
                {
                    continue;
                }

                var cloneContext = this.CloneCommerceContext(context.CommerceContext);
                await this._upgradeCustomerPipeline.Run(customer, cloneContext).ConfigureAwait(false);

                MergeMessages(context.CommerceContext, cloneContext.CommerceContext);
            }

            return(findResult.List.Items.Count);
        }
Esempio n. 2
0
        protected override async Task <MinionRunResultsModel> Execute()
        {
            int itemsProcessed = 0;

            var orders = await GetListItems <Order>(Policy.ListToWatch, Policy.ItemsPerBatch).ConfigureAwait(false);

            foreach (Order order in orders)
            {
                CommerceContext commerceContext = new CommerceContext(Logger, MinionContext.TelemetryClient, (IGetLocalizableMessagePipeline)null)
                {
                    Environment = Environment
                };

                CommercePipelineExecutionContextOptions executionContextOptions = new CommercePipelineExecutionContextOptions(commerceContext);

                await MinionPipeline.Run(order, executionContextOptions);

                itemsProcessed++;
            }

            return(new MinionRunResultsModel
            {
                DidRun = true,
                ItemsProcessed = itemsProcessed
            });
        }
Esempio n. 3
0
        public override async Task <MinionRunResultsModel> Run()
        {
            MinionRunResultsModel result = new MinionRunResultsModel();

            Logger.LogTrace($"{this.Name}: Invoked.");
            string      listName  = Policy.ListToWatch;
            Task <long> itemCount = GetListCount(listName);

            //TODO correct handling of <cref='MinionResultArgument.HasMoreItems'>HasMoreItems</cref>

            IEnumerable <CommerceEntity> entities = await GetListItems <CommerceEntity>(listName, Policy.ItemsPerBatch);

            foreach (Customer customer in entities.OfType <Customer>())
            {
                var executionContext = new CommercePipelineExecutionContextOptions(
                    new CommerceContext(MinionContext.Logger, MinionContext.TelemetryClient)
                {
                    Environment = this.Environment
                });
                var issueCouponArgument = new IssueCouponArgument {
                    Customer = customer
                };
                var pipelineResult = await this.MinionPipeline.Run(issueCouponArgument, executionContext);

                // TODO Appropriate handling of pipeline status. Look at other minions.
                result.ItemsProcessed++;
            }

            return(result);
        }
        public override async Task <MinionRunResultsModel> Run()
        {
            long listCount = await GetListCount(Policy.ListToWatch);

            if (listCount > 0L)
            {
                var jobInstanceList = (await this.GetListItems <JobInstance>(this.Policy.ListToWatch, this.Policy.ItemsPerBatch)).ToList();
                foreach (var jobInstance in jobInstanceList)
                {
                    if (jobInstance.ScheduleDateTime < DateTime.Now)
                    {
                        this.Logger.LogInformation($"Starting job {jobInstance.Job.Name}");
                        jobInstance.StartDateTime = DateTime.Now;
                        var jobsSchedulerArgument = new JobSchedulerArgument(jobInstance);
                        var commerceContext       = new CommerceContext(this.Logger, this.MinionContext.TelemetryClient)
                        {
                            Environment = this.Environment
                        };
                        CommercePipelineExecutionContextOptions executionContextOptions = new CommercePipelineExecutionContextOptions(commerceContext);
                        var job = await JobSchedulerPipeline.Run(jobsSchedulerArgument, executionContextOptions);
                    }
                }
            }
            return(new MinionRunResultsModel());
        }
        protected override async Task <MinionRunResultsModel> Execute()
        {
            MinionRunResultsModel runResults = new MinionRunResultsModel();
            /*Gets all the ReleasedOrders and executes export order*/
            long listCount = await GetListCount(Policy.ListToWatch).ConfigureAwait(false);

            this.Logger.LogInformation(string.Format(CultureInfo.InvariantCulture, "{0}-Review List {1}: Count:{2}", Name, Policy.ListsToWatch, listCount));
            foreach (var listItems in (await GetListItems <XC.Order>(Policy.ListToWatch, Convert.ToInt32(listCount)).ConfigureAwait(false)))
            {
                this.Logger.LogDebug(string.Format(CultureInfo.InvariantCulture, "{0}-Reviewing Pending Order: {1}", listItems.Name, listItems.Id), Array.Empty <object>());

                var minionPipeline       = ExportOrderPipeline;
                var ordersMinionArgument = new ExportOrderArgument(listItems.Id);
                using (var commerceContext = new CommerceContext(Logger, MinionContext.TelemetryClient, null))
                {
                    commerceContext.Environment = this.Environment;

                    CommercePipelineExecutionContextOptions executionContextOptions = new CommercePipelineExecutionContextOptions(commerceContext, null, null, null, null, null);

                    var order = await minionPipeline.Run(ordersMinionArgument, executionContextOptions).ConfigureAwait(false);
                }
            }

            return(runResults);
        }
Esempio n. 6
0
        protected override async Task <MinionRunResultsModel> Execute()
        {
            MinionRunResultsModel runResults = new MinionRunResultsModel();
            /* Pull from an appropriate list and execute an appropriate pipeline. */

            /*Gets list of Items from ReleasedOrders and executes export order to file block*/
            long listCount = await this.GetListCount(this.Policy.ListToWatch).ConfigureAwait(false);

            this.Logger.LogInformation(string.Format("{0}-Review List {1}: Count:{2}", Name, Policy.ListToWatch, listCount));
            foreach (var commerceEnty in (await this.GetListItems <XC.Order>(Policy.ListToWatch, Convert.ToInt32(listCount)).ConfigureAwait(false)))
            {
                this.Logger.LogDebug(string.Format("{0}-Reviewing Pending Order: {1}", commerceEnty.Name, commerceEnty.Id), Array.Empty <object>());

                var minionPipeline       = ExportOrderPipeline;
                var ordersMinionArgument = new ExportOrderArgument(commerceEnty.Id);
                using (var commerceContext = new CommerceContext(this.Logger, this.MinionContext.TelemetryClient, null))
                {
                    commerceContext.Environment = this.Environment;
                    CommercePipelineExecutionContextOptions executionContextOptions = new CommercePipelineExecutionContextOptions(commerceContext, null, null, null, null, null);
                    var order = await minionPipeline.Run(ordersMinionArgument, executionContextOptions).ConfigureAwait(false);
                }
            }

            return(runResults);
        }
        public override async Task <MinionRunResultsModel> Run()
        {
            MinionRunResultsModel result = new MinionRunResultsModel();

            Logger.LogTrace($"{this.Name}: Invoked.");
            string      listName  = Policy.ListToWatch;
            Task <long> itemCount = GetListCount(listName);

            //TODO correct handling of <cref='MinionResultArgument.HasMoreItems'>HasMoreItems</cref>

            IEnumerable <CommerceEntity> entities = await GetListItems <CommerceEntity>(listName, Policy.ItemsPerBatch);

            foreach (Customer customer in entities.OfType <Customer>())
            {
                await this.CommerceCommand.PerformTransaction(MinionContext, async() =>
                {
                    var executionContext = new CommercePipelineExecutionContextOptions(
                        new CommerceContext(MinionContext.Logger, MinionContext.TelemetryClient, (IGetLocalizableMessagePipeline)null)
                    {
                        Environment = this.Environment
                    });
                    var pipelineResult = await this.MinionPipeline.Run(customer, executionContext);

                    //TODO Think about error handling here. What happens if the transaction times out?
                });

                result.ItemsProcessed++;
            }

            return(result);
        }
        protected override async Task <MinionRunResultsModel> Execute()
        {
            MinionRunResultsModel runResults = new MinionRunResultsModel();

            /* STUDENT: Complete the body of this method. You need to pull from an appropriate list
             * and then execute an appropriate pipeline. */
            long listCount = await GetListCount(Policy.ListToWatch).ConfigureAwait(false);

            this.Logger.LogInformation(string.Format("{0}-Review List {1}: Count:{2}", (object)this.Name, (object)this.Policy.ListToWatch, (object)listCount));
            // var  entitleMentList = await this.GetListIds<XC.Order>(this.Policy.ListToWatch, Convert.ToInt32(listCount)).ConfigureAwait(false);

            foreach (var commerceEnty in (await this.GetListItems <XC.Order>(Policy.ListToWatch, Convert.ToInt32(listCount)).ConfigureAwait(false)))
            {
                this.Logger.LogDebug(string.Format("{0}-Reviewing Pending Order: {1}", commerceEnty.Name, commerceEnty.Id), Array.Empty <object>());

                var minionPipeline       = ExportOrderPipeline;
                var ordersMinionArgument = new ExportOrderArgument(commerceEnty.Id);
                using (var commerceContext = new CommerceContext(this.Logger, this.MinionContext.TelemetryClient, (IGetLocalizableMessagePipeline)null))
                {
                    commerceContext.Environment = this.Environment;
                    CommercePipelineExecutionContextOptions executionContextOptions = new CommercePipelineExecutionContextOptions(commerceContext, null, null, null, null, null);
                    var order = await minionPipeline.Run(ordersMinionArgument, executionContextOptions).ConfigureAwait(false);
                }
            }

            return(runResults);
        }
        public async Task <IEnumerable <PolicySnapshotModel> > Process(CommerceContext commerceContext)
        {
            IEnumerable <PolicySnapshotModel> policies;

            using (CommandActivity.Start(commerceContext, this))
            {
                CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.GetPipelineContextOptions();
                policies = await this.getPoliciesPipeline.Run(string.Empty, (IPipelineExecutionContextOptions)pipelineContextOptions);
            }
            return(policies);
        }
Esempio n. 10
0
        protected virtual async Task Log(ImportEntityCommand command)
        {
            var commercePipelineExecutionContextOptions = new CommercePipelineExecutionContextOptions(
                new CommerceContext(CommerceContext.Logger, CommerceContext.TelemetryClient)
            {
                Environment = CommerceContext.Environment
            });

            await ServiceProvider.GetService <ILogEntityImportResultPipeline>()
            .Run(new LogEntityImportResultArgument(command), commercePipelineExecutionContextOptions)
            .ConfigureAwait(false);
        }
        public virtual async Task <Cart> Process(CommerceContext commerceContext, string wishlistId, CartLineComponent line)
        {
            RemoveWishListLineCommand removeCartLineCommand = this;
            Activity activity;


            Cart result = null;

            activity = CommandActivity.Start(commerceContext, removeCartLineCommand);

            try
            {
                CommercePipelineExecutionContextOptions context = commerceContext.PipelineContextOptions;
                FindEntityArgument findEntityArgument           = new FindEntityArgument(typeof(Cart), wishlistId, false);
                Cart cart = await removeCartLineCommand._getPipeline.Run(findEntityArgument, context).ConfigureAwait(false) as Cart;

                if (cart == null)
                {
                    string str = await context.CommerceContext.AddMessage(commerceContext.GetPolicy <KnownResultCodes>().ValidationError, "EntityNotFound", new object[1]
                    {
                        wishlistId
                    }, string.Format("Entity {0} was not found.", wishlistId)).ConfigureAwait(false);

                    return(null);
                }
                if (cart.Lines.FirstOrDefault((c => c.Id == line.Id)) == null)
                {
                    string str = await context.CommerceContext.AddMessage(commerceContext.GetPolicy <KnownResultCodes>().ValidationError, "CartLineNotFound", new object[1]
                    {
                        line.Id
                    }, string.Format("Wishlist line {0} was not found", line.Id)).ConfigureAwait(false);

                    return(cart);
                }

                await removeCartLineCommand.PerformTransaction(commerceContext, async() =>
                {
                    var cartResult = await this._pipeline.Run(new CartLineArgument(cart, line), (IPipelineExecutionContextOptions)context).ConfigureAwait(false);

                    result = cartResult;
                });

                return(result);
            }
            finally
            {
                if (activity != null)
                {
                    activity.Dispose();
                }
            }
        }
Esempio n. 12
0
        public override async Task <MinionRunResultsModel> Run()
        {
            this.Logger.LogInformation("ImportMinion running");

            var commerceContext = new CommerceContext(this.Logger, this.MinionContext.TelemetryClient, null);

            commerceContext.Environment = this.Environment;

            CommercePipelineExecutionContextOptions executionContextOptions = new CommercePipelineExecutionContextOptions(commerceContext, null, null, null, null, null);

            MinionRunResultsModel res = await this.MinionPipeline.Run(new MinionRunResultsModel(), executionContextOptions);

            return(new MinionRunResultsModel());
        }
Esempio n. 13
0
        public virtual async Task <CommerceEntity> Process(
            CommerceContext commerceContext,
            string itemId,
            bool filterVariations)
        {
            using (CommandActivity.Start(commerceContext, this))
            {
                CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.GetPipelineContextOptions();

                if (itemId.Contains("|"))
                {
                    itemId = itemId.Replace("|", ",");
                }

                if (!string.IsNullOrEmpty(itemId))
                {
                    if (itemId.Split(',').Length == 3)
                    {
                        var             strArray        = itemId.Split(',');
                        ProductArgument productArgument = new ProductArgument(strArray[0], strArray[1])
                        {
                            VariantId = strArray[2]
                        };

                        var sellableItem = await _pipeline.Run(productArgument, pipelineContextOptions).ConfigureAwait(false);

                        var catalog = await _findEntityPipeline.Run(new FindEntityArgument(typeof(Catalog), CommerceEntity.IdPrefix <Catalog>() + productArgument.CatalogName), pipelineContextOptions).ConfigureAwait(false) as Catalog;

                        if (catalog != null && sellableItem != null && sellableItem.HasPolicy <PriceCardPolicy>())
                        {
                            var    priceCardName = sellableItem.GetPolicy <PriceCardPolicy>();
                            string entityId      = $"{CommerceEntity.IdPrefix<PriceCard>()}{catalog.PriceBookName}-{priceCardName.PriceCardName}";


                            CommerceEntity commerceEntity = await _findEntityPipeline.Run(new FindEntityArgument(typeof(PriceCard), entityId), pipelineContextOptions).ConfigureAwait(false);

                            return(commerceEntity);
                        }
                    }
                }

                string str = await pipelineContextOptions.CommerceContext.AddMessage(commerceContext.GetPolicy <KnownResultCodes>().Error, "ItemIdIncorrectFormat", new object[]
                {
                    itemId
                }, "Expecting a CatalogId and a ProductId in the ItemId: " + itemId);

                return(null);
            }
        }
        public async Task <List <NearestStoreLocation> > Process(CommerceContext commerceContext, GetNearestStoreDetailsByLocationArgument inputArgumentList)
        {
            GetNearestStoreDetailsByLocationCommand getNearestStoreDetailsByLocationCommand = this;
            CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.GetPipelineContextOptions();

            //InventorySet result = (InventorySet)null;
            List <NearestStoreLocation> sets = new List <NearestStoreLocation>();

            using (CommandActivity.Start(commerceContext, (CommerceCommand)getNearestStoreDetailsByLocationCommand))
            {
                sets = await getNearestStoreDetailsByLocationCommand._getNearestStoreDetailsByLocationPipeline.Run(inputArgumentList, pipelineContextOptions);
            }

            return(sets);
        }
Esempio n. 15
0
        public virtual async Task <Cart> Process(CommerceContext commerceContext, string wishlistId, CartLineComponent line)
        {
            AddWishListLineItemCommand addCartLineCommand = this;
            Cart result = null;

            using (CommandActivity.Start(commerceContext, addCartLineCommand))
            {
                await addCartLineCommand.PerformTransaction(commerceContext, async() =>
                {
                    FindEntityArgument findEntityArgument           = new FindEntityArgument(typeof(Cart), wishlistId, true);
                    CommercePipelineExecutionContextOptions context = commerceContext.GetPipelineContextOptions();

                    Cart cart = await _getPipeline.Run(findEntityArgument, commerceContext.GetPipelineContextOptions()).ConfigureAwait(false) as Cart;
                    if (cart == null)
                    {
                        string str = await context.CommerceContext.AddMessage(commerceContext.GetPolicy <KnownResultCodes>().ValidationError, "EntityNotFound", new object[1]
                        {
                            wishlistId
                        }, $"Entity {wishlistId} was not found.");
                    }
                    else
                    {
                        if (!cart.IsPersisted)
                        {
                            cart.Id       = wishlistId;
                            cart.Name     = wishlistId;
                            cart.ShopName = commerceContext.CurrentShopName();
                            cart.SetComponent(new ListMembershipsComponent()
                            {
                                Memberships = new List <string>
                                {
                                    CommerceEntity.ListName <Cart>()
                                }
                            });

                            cart.SetComponent(new CartTypeComponent {
                                CartType = CartTypeEnum.Wishlist.ToString()
                            });
                        }


                        result = await _addWishListLineItemPipeline.Run(new CartLineArgument(cart, line), context);
                    }
                });
            }

            return(result);
        }
        protected virtual async Task <Order> GetLoyaltyOrder(CommerceContext context, string orderId)
        {
            if (string.IsNullOrEmpty(orderId))
            {
                return(null);
            }

            var options = new CommercePipelineExecutionContextOptions(context);

            var loyaltyOrder = await _getLoyaltyOrderPipeline.Run(orderId, options);

            if (loyaltyOrder == null)
            {
                context.Logger.LogDebug($"Order {orderId} was not found.");
            }

            return(loyaltyOrder);
        }
Esempio n. 17
0
        public virtual async Task <IEnumerable <ComposerTemplate> > Process(CommerceContext commerceContext, string[] templateIds)
        {
            GetComposerTemplatesCommand getComposerTemplatesCommand = this;

            IEnumerable <ComposerTemplate> composerTemplates            = Enumerable.Empty <ComposerTemplate>();
            GetComposerTemplatesArgument   getComposerTemplatesArgument = new GetComposerTemplatesArgument(templateIds);

            using (CommandActivity.Start(commerceContext, getComposerTemplatesCommand))
            {
                await getComposerTemplatesCommand.PerformTransaction(commerceContext, async() =>
                {
                    CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.PipelineContextOptions;
                    composerTemplates = await this._getComposerTemplatesPipeline.Run(getComposerTemplatesArgument, pipelineContextOptions).ConfigureAwait(false);
                }).ConfigureAwait(false);

                return(composerTemplates);
            }
        }
        public virtual async Task <bool> Process(CommerceContext commerceContext, string orderId)
        {
            // Run the pipeline
            using (CommandActivity.Start(commerceContext, this))
            {
                bool result = false;

                await PerformTransaction(commerceContext, (async() =>
                {
                    var requestPaymentArgument = new RequestPaymentArgument(orderId);

                    CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.GetPipelineContextOptions();

                    result = await requestPaymentPipeline.Run(requestPaymentArgument, pipelineContextOptions).ConfigureAwait(false);
                }));

                return(result);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Process UpdateCartLineGiftBoxCommand commerce command.
        /// </summary>
        /// <param name="commerceContext">Commerce context.</param>
        /// <param name="cartId">Cart Id.</param>
        /// <param name="cartLineId">Cart line Id.</param>
        /// <param name="isGiftBox">Cart line gift box boolean attribute.</param>
        /// <returns></returns>
        public async Task <Cart> Process(CommerceContext commerceContext, string cartId, string cartLineId, bool isGiftBox)
        {
            try
            {
                Cart cartResult = null;

                using (CommandActivity.Start(commerceContext, this))
                {
                    // find Cart entity
                    var findCartArgument = new FindEntityArgument(typeof(Cart), cartId, false);
                    var pipelineContext  = new CommercePipelineExecutionContextOptions(commerceContext);
                    cartResult = await _findEntityPipeline.Run(findCartArgument, pipelineContext) as Cart;

                    var validationErrorCode = commerceContext.GetPolicy <KnownResultCodes>().ValidationError;

                    if (cartResult == null)
                    {
                        await pipelineContext.CommerceContext.AddMessage(validationErrorCode,
                                                                         "EntityNotFound",
                                                                         new object[] { cartId },
                                                                         $"Cart {cartId} was not found.");
                    }
                    else if (!cartResult.Lines.Any(l => l.Id == cartLineId))
                    {
                        await pipelineContext.CommerceContext.AddMessage(validationErrorCode,
                                                                         "CartLineNotFound",
                                                                         new object[] { cartLineId },
                                                                         $"Cart line {cartLineId} was not found.");
                    }
                    else
                    {
                        var arg = new CartLineGiftBoxArgument(cartResult, cartLineId, isGiftBox);
                        cartResult = await _updateCartLineGiftBoxPipeline.Run(arg, pipelineContext);
                    }

                    return(cartResult);
                }
            }
            catch (Exception ex)
            {
                return(await Task.FromException <Cart>(ex));
            }
        }
Esempio n. 20
0
        protected override async Task <MinionRunResultsModel> Execute()
        {
            Condition.Requires(waitingForPaymentOrdersMinionPipeline).IsNotNull($"Not able to resolve the pipeline: IPaymentResultsMinionPipeline");

            int totalProcessedItem = 0;

            foreach (var listName in Policy.ListsToWatch)
            {
                var argument = await this.GetListIds <Order>(listName, Policy.ItemsPerBatch);

                var list = argument.List;
                do
                {
                    foreach (var entityId in argument.EntityReferences.Select(x => x.EntityId))
                    {
                        var options = new CommercePipelineExecutionContextOptions(MinionContext);
                        var result  = await waitingForPaymentOrdersMinionPipeline.RunAsync(new WaitingForPaymentOrdersMinionArgument()
                        {
                            EntityId = entityId
                        }, options);

                        if (result)
                        {
                            totalProcessedItem++;
                        }
                        else
                        {
                            //TODO: Log error
                        }
                    }

                    argument = await this.GetListIds <Order>(listName, Policy.ItemsPerBatch, list.CurrentPage *Policy.ItemsPerBatch);

                    list = argument.List;
                } while (list.CurrentPage < list.PageCount);
            }

            return(new MinionRunResultsModel()
            {
                DidRun = true,
                ItemsProcessed = totalProcessedItem
            });
        }
Esempio n. 21
0
        public override async Task <MinionRunResultsModel> Run()
        {
            MinionRunResultsModel result = new MinionRunResultsModel();

            Logger.LogTrace($"{this.Name}: Invoked.");


            var executionContext = new CommercePipelineExecutionContextOptions(
                new CommerceContext(
                    MinionContext.Logger,
                    MinionContext.TelemetryClient,
                    (IGetLocalizableMessagePipeline)null)
            {
                Environment = this.Environment
            });
            var pipelineResult = await this.MinionPipeline.Run(new CreateCouponsArgument(), executionContext);

            return(result);
        }
        public virtual async Task <bool> Process(CommerceContext commerceContext, Dictionary <string, string> parameters)
        {
            // Run the pipeline
            using (CommandActivity.Start(commerceContext, this))
            {
                bool result = false;

                await PerformTransaction(commerceContext, (async() =>
                {
                    var handleResponseArgument = new HandleResponseArgument(parameters);

                    CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.GetPipelineContextOptions();

                    result = await handleResponsePipeline.Run(handleResponseArgument, pipelineContextOptions).ConfigureAwait(false);
                }));

                return(result);
            }
        }
        public async Task <CommerceCommand> Process(
            CommerceContext commerceContext,
            IFormFile importFile,
            string mode,
            int errorThreshold,
            bool publishEntities = true)
        {
            CommerceCommand commerceCommand;

            using (CommandActivity.Start(commerceContext, (CommerceCommand)this))
            {
                CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.PipelineContextOptions;
                ImportPriceBooksArgument priceBooksArgument = new ImportPriceBooksArgument(importFile, mode)
                {
                    ErrorThreshold = errorThreshold
                };

                if (publishEntities)
                {
                    commerceContext.Environment.SetPolicy(new AutoApprovePolicy());
                }

                ImportResult importResult = await ImportPriceBooksPipeline.Run(priceBooksArgument, pipelineContextOptions);

                if (importResult != null)
                {
                    this.Messages.AddRange((IEnumerable <CommandMessage>)importResult.Errors);
                    this.ResponseCode = importResult.ResultCode;
                }
                else
                {
                    this.ResponseCode = commerceContext.GetPolicy <KnownResultCodes>().Error;
                }

                if (publishEntities)
                {
                    commerceContext.Environment.RemovePolicy(typeof(AutoApprovePolicy));
                }

                commerceCommand = (CommerceCommand)this;
            }
            return(commerceCommand);
        }
        public virtual async Task <Customer> Process(
            CommerceContext commerceContext,
            string customerId,
            MembershipSubscriptionComponent membershipSubscription)
        {
            Customer result = null;
            Customer customer;

            using (CommandActivity.Start(commerceContext, this))
            {
                await PerformTransaction(commerceContext, async() =>
                {
                    CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.GetPipelineContextOptions();
                    result = await _pipeline.Run(new CustomerMembershipSubscriptioArgument(customerId, membershipSubscription), pipelineContextOptions);
                });

                customer = result;
            }
            return(customer);
        }
        protected virtual async Task <ProductCompare> GetProductCompareComponent(CommerceContext context, string cartId)
        {
            if (string.IsNullOrEmpty(cartId))
            {
                return(null);
            }

            //add a prefix to the cart id so it won't parse into a guid
            cartId += "xxx";
            var entityId = cartId.StartsWith(CommerceEntity.IdPrefix <ProductCompare>(), StringComparison.OrdinalIgnoreCase) ? cartId : cartId.ToEntityId <ProductCompare>();
            var options  = new CommercePipelineExecutionContextOptions(context);
            var productCompareComponent = await _getProductComparePipeline.Run(entityId, options);

            if (productCompareComponent == null)
            {
                context.Logger.LogDebug($"Entity {entityId} was not found.");
            }

            return(productCompareComponent);
        }
Esempio n. 26
0
        /// <summary>
        /// Gets the Fulfillment fee book.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        protected virtual async Task <FulfillmentFeeBook> GetFulfillmentFeeBook(CommerceContext context, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            var entityPrefix = CommerceEntity.IdPrefix <FulfillmentFeeBook>();
            var entityId     = name.StartsWith(entityPrefix, StringComparison.OrdinalIgnoreCase) ? name : string.Format("{0}{1}", entityPrefix, name);

            var arg     = new FindEntityArgument(typeof(FulfillmentFeeBook), entityId, false);
            var options = new CommercePipelineExecutionContextOptions(context, null, null, null, null, null);

            var FulfillmentFeeBook = await this._findEntityPipeline.Run(arg, options) as FulfillmentFeeBook;

            if (FulfillmentFeeBook == null)
            {
                context.Logger.LogDebug(string.Format("Entity {0} was not found.", name));
            }

            return(FulfillmentFeeBook);
        }
        public virtual async Task <RunMinionNowCommand> Process(CommerceContext commerceContext, string minionFullName, string environmentName, IList <Policy> policies)
        {
            RunMinionNowCommand runMinionNowCommand = this;

            using (CommandActivity.Start(commerceContext, (CommerceCommand)runMinionNowCommand))
            {
                if (policies == null)
                {
                    policies = (IList <Policy>) new List <Policy>();
                }
                CommerceEnvironment commerceEnvironment = await this._getEnvironment.Process(commerceContext, environmentName) ?? commerceContext.Environment;

                CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.PipelineContextOptions;
                pipelineContextOptions.CommerceContext.Environment = commerceEnvironment;
                IRunMinionPipeline runMinionPipeline = this._runMinionPipeline;
                RunMinionArgument  runMinionArgument = new RunMinionArgument(minionFullName);
                runMinionArgument.Policies = policies;
                CommercePipelineExecutionContextOptions executionContextOptions = pipelineContextOptions;
                int num = await runMinionPipeline.Run(runMinionArgument, (IPipelineExecutionContextOptions)executionContextOptions) ? 1 : 0;
            }
            return(runMinionNowCommand);
        }
        public override async Task <MinionRunResultsModel> Run()
        {
            MinionRunResultsModel runResults = new MinionRunResultsModel();
            long listCount = await this.GetListCount(this.Policy.ListToWatch);

            this.Logger.LogInformation(string.Format("{0}-Review List {1}: Count:{2}", (object)this.Name, (object)this.Policy.ListToWatch, (object)listCount));
            foreach (string id in (await this.GetListIds <Order>(this.Policy.ListToWatch, Convert.ToInt32(listCount))).IdList)
            {
                this.Logger.LogDebug(string.Format("{0}-Reviewing Pending Order: {1}", (object)this.Name, (object)id), Array.Empty <object>());

                var minionPipeline       = MinionPipeline;
                var ordersMinionArgument = new ExportOrdersMinionArgument(id);
                var commerceContext      = new CommerceContext(this.Logger, this.MinionContext.TelemetryClient, (IGetLocalizableMessagePipeline)null);
                commerceContext.Environment = this.Environment;

                CommercePipelineExecutionContextOptions executionContextOptions = new CommercePipelineExecutionContextOptions(commerceContext, null, null, null, null, null);

                var order = await minionPipeline.Run(ordersMinionArgument, executionContextOptions);
            }

            return(runResults);
        }
Esempio n. 29
0
        protected override async Task <MinionRunResultsModel> Execute()
        {
            this.Logger.LogInformation("ImportProduct minion started");
            MinionRunResultsModel runResults = new MinionRunResultsModel();

            var commerceContext = new CommerceContext(this.Logger, this.MinionContext.TelemetryClient, (IGetLocalizableMessagePipeline)null);

            commerceContext.Environment = this.Environment;
            CommercePipelineExecutionContextOptions executionContextOptions = new CommercePipelineExecutionContextOptions(commerceContext, null, null, null, null, null);

            try
            {
                runResults = await _iImportProuctsMinionPipeline.Run(runResults, executionContextOptions);
            }
            finally
            {
                runResults.HasMoreItems = false;
                runResults.DidRun       = true;
            }

            this.Logger.LogInformation("ImportProduct minion completed");
            return(runResults);
        }
Esempio n. 30
0
        public override async Task <MinionRunResultsModel> Run()
        {
            MinionRunResultsModel runResults = new MinionRunResultsModel();

            var customers = (await this.GetListItems <Customer>("Customers", 20, 0));

            if (customers != null && customers.Any())
            {
                foreach (var customer in customers)
                {
                    this.Logger.LogDebug(string.Format("{0}-Reviewing Customer: {1}", (object)this.Name, (object)customer.Id), Array.Empty <object>());

                    var reconcilePointsArgument = new ReconcilePointsArgument(customer.Id);

                    var commerceContext = new CommerceContext(this.Logger, this.MinionContext.TelemetryClient, (IGetLocalizableMessagePipeline)null);
                    commerceContext.Environment = this.Environment;

                    var executionContextOptions = new CommercePipelineExecutionContextOptions(commerceContext, null, null, null, null, null);

                    var order = await this.ReconcilePointsMinionPipeline.Run(reconcilePointsArgument, executionContextOptions);
                }
            }
            return(runResults);
        }