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); }
public virtual async Task <WishList> Process(CommerceContext commerceContext, string wishListId, WishListLineComponent line) { WishList result = null; using (CommandActivity.Start(commerceContext, this)) { var context = commerceContext.GetPipelineContextOptions(); var findEntityArgument = new FindEntityArgument(typeof(WishList), wishListId); var wishList = await _getPipeline.Run(findEntityArgument, context) as WishList; if (wishList == null) { await context.CommerceContext.AddMessage(commerceContext.GetPolicy <KnownResultCodes>().ValidationError, "EntityNotFound", new object[] { wishListId }, string.Format("Entity {0} was not found.", wishListId)); return(null); } if (wishList.Lines.FirstOrDefault <WishListLineComponent>(c => c.Id == line.Id) == null) { await context.CommerceContext.AddMessage(commerceContext.GetPolicy <KnownResultCodes>().ValidationError, "WishListLineNotFound", new object[] { line.Id }, string.Format("WishList line {0} was not found", line.Id)); return(wishList); } result = await _pipeline.Run(new WishListLineArgument(wishList, line), context); return(result); } }
public virtual async Task <WishList> Process(CommerceContext commerceContext, string wishListId, WishListLineComponent line) { using (CommandActivity.Start(commerceContext, this)) { var context = commerceContext.GetPipelineContextOptions(); var findEntityArgument = new FindEntityArgument(typeof(WishList), wishListId, true); var wishList = await _getPipeline.Run(findEntityArgument, context) as WishList; if (wishList == null) { await context.CommerceContext.AddMessage(commerceContext.GetPolicy <KnownResultCodes>().ValidationError, "EntityNotFound", new object[] { wishListId }, string.Format("Entity {0} was not found.", wishListId)); return(null); } if (!wishList.IsPersisted) { wishList.Id = wishListId; wishList.Name = wishListId; wishList.ShopName = commerceContext.CurrentShopName(); } var result = await _addToWishListPipeline.Run(new WishListLineArgument(wishList, line), context); await _persistEntityPipeline.Run(new PersistEntityArgument(result), context); return(result); } }
/// <summary> /// Processes the specified commerce context. /// </summary> /// <param name="commerceContext">The commerce context.</param> /// <returns>User site terms</returns> public virtual async Task <IEnumerable <Customer> > Process(CommerceContext commerceContext) { using (CommandActivity.Start(commerceContext, this)) { var sqlContext = ConnectionHelper.GetProfilesSqlContext(commerceContext); var rows = await sqlContext.GetAllProfiles(); var migratedCustomers = new List <Customer>(); foreach (DataRow row in rows) { try { var contextOptions = commerceContext.GetPipelineContextOptions(); var csCustomer = await this._migrateCustomerPipeline.Run(row, contextOptions); if (csCustomer != null) { migratedCustomers.Add(csCustomer); } } catch (Exception ex) { await commerceContext.AddMessage( commerceContext.GetPolicy <KnownResultCodes>().Error, "EntityNotFound", new object[] { row["u_user_id"] as string, ex }, $"Customer {row["u_user_id"] as string} was not migrated."); } } return(migratedCustomers); } }
/// <summary> /// Processes the specified commerce context. /// </summary> /// <param name="commerceContext">The commerce context.</param> /// <param name="name">The name.</param> /// <returns></returns> public virtual async Task <FulfillmentFeeBook> Process(CommerceContext commerceContext, string name = "") { using (var activity = CommandActivity.Start(commerceContext, this)) { var FulfillmentFeeBookName = commerceContext.GetPolicy <GlobalPolicy>().GetFulfillmentFeeBookName(name, commerceContext); var cachePolicy = commerceContext.GetPolicy <FulfillmentFeeCachePolicy>(); var cacheKey = string.Format("{0}{1}", commerceContext.CurrentLanguage(), FulfillmentFeeBookName); ICache cache = null; FulfillmentFeeBook FulfillmentFeeBook = null; if (cachePolicy.AllowCaching) { var environmentCacheArgument = new EnvironmentCacheArgument { CacheName = cachePolicy.CacheName }; cache = await _cachePipeline.Run(environmentCacheArgument, commerceContext.GetPipelineContextOptions()); FulfillmentFeeBook = await cache.Get(cacheKey) as FulfillmentFeeBook; } if (FulfillmentFeeBook == null) { FulfillmentFeeBook = await this.GetFulfillmentFeeBook(commerceContext, FulfillmentFeeBookName); if (cachePolicy.AllowCaching && cache != null) { await cache.Set(cacheKey, new Cachable <FulfillmentFeeBook>(FulfillmentFeeBook, 1L), cachePolicy.GetCacheEntryOptions()); } } return(FulfillmentFeeBook); } }
public virtual async Task <List <BreadcrumbModel> > Process(string id, CommerceContext commerceContext) { List <BreadcrumbModel> entityView; using (CommandActivity.Start(commerceContext, this)) { entityView = await _pipeline.Run(id, commerceContext.GetPipelineContextOptions()); } return(entityView); }
public async Task <bool> Process(CommerceContext commerceContext, Promotion promotion, List <Policy> policies = null) { using (CommandActivity.Start(commerceContext, this)) { var createdPromotion = promotion; commerceContext.GetMessages().Add(new CommandMessage { Code = "Information", CommerceTermKey = "PromotionBeingApproved", Text = "Promotion Being Approved!" }); var requestApprovalResponse = await this._commerceCommander.Command <SetApprovalStatusCommand>() .Process(commerceContext.GetPipelineContextOptions().CommerceContext, createdPromotion, commerceContext.GetPolicy <ApprovalStatusPolicy>().ReadyForApproval, "Generated"); if (!requestApprovalResponse) { commerceContext.Logger.LogWarning($"DoActionGeneratePromotionBook.ApprovalRequestDenied: PromotionId={createdPromotion.Id}"); } createdPromotion = await this._commerceCommander.GetEntity <Promotion>(commerceContext, $"{createdPromotion.Id}"); var approvalResponse = await this._commerceCommander.Command <SetApprovalStatusCommand>() .Process(commerceContext.GetPipelineContextOptions().CommerceContext, createdPromotion, commerceContext.GetPolicy <ApprovalStatusPolicy>().Approved, "Generated"); if (!approvalResponse) { commerceContext.Logger.LogWarning($"DoActionGeneratePromotionBook.ApprovalRequestDenied: PromotionId={createdPromotion.Id}"); } else { commerceContext.GetMessages().Add(new CommandMessage { Code = "Information", CommerceTermKey = "PromotionApproved", Text = "Promotion Approved!" }); } createdPromotion = await this._commerceCommander.GetEntity <Promotion>(commerceContext, $"{createdPromotion.Id}"); await this._commerceCommander.PersistEntity(commerceContext, createdPromotion); return(true); } }
public virtual async Task <WishList> Process(CommerceContext commerceContext, WishList wishList, WishListLineComponent line) { WishList result = null; using (CommandActivity.Start(commerceContext, this)) { var context = commerceContext.GetPipelineContextOptions(); result = await _pipeline.Run(new WishListLineArgument(wishList, line), context); } return(result); }
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); }
public async Task <CommerceCommand> Process(CommerceContext commerceContext, string fromUsername, string toUsername) { using (CommandActivity.Start(commerceContext, this)) { var contextOptions = commerceContext.GetPipelineContextOptions(); var argument = new RenameCustomerArgument(fromUsername, toUsername); var result = await Commander.Pipeline <IRenameCustomerPipeline>().Run(argument, contextOptions).ConfigureAwait(false); return(this); } }
/// <summary> /// The process of the command /// </summary> /// <param name="commerceContext"> /// The commerce context /// </param> /// <param name="parameter"> /// The parameter for the command /// </param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <string> Process(CommerceContext commerceContext) { using (var activity = CommandActivity.Start(commerceContext, this)) { string retVal = string.Empty; var context = commerceContext.GetPipelineContextOptions(); ImportSellableItemPipelineArgument pArg = new ImportSellableItemPipelineArgument("ProductImport.xml"); retVal = await this._pipeline.Run(pArg, context); return(retVal); } }
public virtual async Task <Cart> Process(CommerceContext commerceContext, string wishlistId, CartLineComponent line) { RemoveWishListLineCommand removeCartLineCommand = this; Activity activity; Cart result = (Cart)null; activity = CommandActivity.Start(commerceContext, (CommerceCommand)removeCartLineCommand); try { CommercePipelineExecutionContextOptions context = commerceContext.GetPipelineContextOptions(); FindEntityArgument findEntityArgument = new FindEntityArgument(typeof(Cart), wishlistId, false); Cart cart = await removeCartLineCommand._getPipeline.Run(findEntityArgument, (IPipelineExecutionContextOptions)context).ConfigureAwait(false) as Cart; if (cart == null) { string str = await context.CommerceContext.AddMessage(commerceContext.GetPolicy <KnownResultCodes>().ValidationError, "EntityNotFound", new object[1] { (object)wishlistId }, string.Format("Entity {0} was not found.", (object)wishlistId)); return(null); } if (cart.Lines.FirstOrDefault <CartLineComponent>((Func <CartLineComponent, bool>)(c => c.Id == line.Id)) == null) { string str = await context.CommerceContext.AddMessage(commerceContext.GetPolicy <KnownResultCodes>().ValidationError, "CartLineNotFound", new object[1] { (object)line.Id }, string.Format("Wishlist line {0} was not found", (object)line.Id)); return(cart); } await removeCartLineCommand.PerformTransaction(commerceContext, (Func <Task>)(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(); } } }
/// <summary> /// Clones the commerce context. /// </summary> /// <param name="commerceContext">The commerce context.</param> /// <returns>Clone pipeline execution context</returns> protected virtual CommercePipelineExecutionContext CloneCommerceContext(CommerceContext commerceContext) { Condition.Requires(commerceContext, nameof(commerceContext)).IsNotNull(); var commerceContextClone = new CommerceContext(commerceContext.Logger, commerceContext.TelemetryClient, commerceContext.LocalizableMessagePipeline) { Environment = commerceContext.Environment, GlobalEnvironment = commerceContext.GlobalEnvironment, Headers = commerceContext.Headers }; var commerceOptionsClone = commerceContextClone.GetPipelineContextOptions(); return(new CommercePipelineExecutionContext(commerceOptionsClone, commerceContext.Logger)); }
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); }
/// <summary> /// The process of the command /// </summary> /// <param name="commerceContext"> /// The commerce context /// </param> /// <param name="cartId"></param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <Cart> Process(CommerceContext commerceContext, string cartId) { using (var activity = CommandActivity.Start(commerceContext, this)) { var arg = new ResolveCartArgument(commerceContext.CurrentShopName(), cartId, commerceContext.CurrentShopperId()); var cart = await _getCartPipeline.Run(arg, commerceContext.GetPipelineContextOptions()); var cartComponent = cart.GetComponent <TestSimulationComponent>(); cartComponent.Status = true; var persistEntityArgument = await this._persistEntityPipeline.Run(new PersistEntityArgument(cart), commerceContext.GetPipelineContextOptions()); return(cart); } }
/// <summary> /// Processes the specified commerce context. /// </summary> /// <param name="commerceContext">The commerce context.</param> /// <returns> /// Number of migrated customers /// </returns> public virtual async Task <int> Process(CommerceContext commerceContext) { using (CommandActivity.Start(commerceContext, this)) { var context = commerceContext.GetPipelineContextOptions(); var listName = CommerceEntity.ListName <Customer>(); var result = await this.Command <GetListMetadataCommand>().Process(commerceContext, listName); if (result == null) { await commerceContext.AddMessage( commerceContext.GetPolicy <KnownResultCodes>().Error, "EntityNotFound", new object[] { listName }, $"There is no customers in the list {listName}."); return(0); } if (result.Count == 0) { await context.CommerceContext.AddMessage( context.CommerceContext.GetPolicy <KnownResultCodes>().Error, "EntityNotFound", new object[] { listName }, $"There is no customers in the list {listName}."); return(0); } int customersCount = 0; int skip = 0; int take = 20; while (customersCount < result.Count) { customersCount += await this.UpgradeCustomersInList(context, listName, skip, take); skip += take; } return(customersCount); } }
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 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); } }
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); }
public virtual async Task <WishList> Process(CommerceContext commerceContext, string wishListId, bool secureResult = true) { using (CommandActivity.Start(commerceContext, this)) { var context = commerceContext.GetPipelineContextOptions(); var resolveWishListArgument = new ResolveWishListArgument(commerceContext.CurrentShopName(), wishListId, commerceContext.CurrentShopperId()); var objects = commerceContext.GetObjects <WishList>(); if (objects.Any(p => p.Id == wishListId)) { commerceContext.Logger.LogTrace(string.Format("GetWishListCommand.AlreadyLoaded: WishListId={0}", wishListId), Array.Empty <object>()); return(objects.FirstOrDefault(p => p.Id == wishListId)); } commerceContext.Logger.LogTrace(string.Format("GetWishListCommand.LoadingWishList: WishListId={0}", wishListId), Array.Empty <object>()); var wishList = await _pipeline.Run(resolveWishListArgument, context); commerceContext.Logger.LogTrace(string.Format("GetWishListCommand.WishListLoaded: WishListId={0}", wishListId), Array.Empty <object>()); return(wishList); } }
public async Task <CommerceCommand> Process(CommerceContext commerceContext, List <MembershipPriceModel> model) { var policy = commerceContext.GetPolicy <TransactionsPolicy>(); policy.TransactionTimeOut = 10800000; // 3 * 3600 * 1000 = 3 hours in millis ImportMembershipPricesArgument result = null; using (CommandActivity.Start(commerceContext, this)) { var options = commerceContext.GetPipelineContextOptions(); var context = ImportHelpers.OptimizeContextForImport(new CommercePipelineExecutionContext(options, commerceContext.Logger)); var importMembershipPricesPolicy = commerceContext.GetPolicy <ImportMembershipPricesPolicy>(); await PerformTransaction( commerceContext, async() => { result = await importMembershipPricesPipeline.Run(new ImportMembershipPricesArgument(importMembershipPricesPolicy.PriceBookName, model, importMembershipPricesPolicy.CurrencySetId), commerceContext.GetPipelineContextOptions()) .ConfigureAwait(false); }).ConfigureAwait(false); } return(this); }
public virtual async Task <Order> Process(CommerceContext commerceContext, OfflineStoreOrderArgument arg) { CreateOfflineOrderCommand createOrderCommand = this; Order result = (Order)null; Order order; using (CommandActivity.Start(commerceContext, (CommerceCommand)createOrderCommand)) { Func <Task> func = await createOrderCommand.PerformTransaction(commerceContext, (Func <Task>)(async() => { Order order2 = await createOrderCommand._createOfflineOrderPipeline.Run(arg, commerceContext.GetPipelineContextOptions()); result = order2; })); order = result; } return(order); }
public async Task <bool> Process(CommerceContext commerceContext) { using (CommandActivity.Start(commerceContext, this)) { var customerTotals = new Dictionary <string, OrdersTotals>(); try { var orderTotals = await this._commerceCommander.GetEntity <OrdersTotals>(commerceContext, "Orders_Totals", true); if (!orderTotals.IsPersisted) { orderTotals.Id = "Orders_Totals"; } orderTotals.LastRunStarted = DateTimeOffset.UtcNow; orderTotals.LastRunEnded = DateTimeOffset.MinValue; orderTotals.MonitorCycle++; var batchSize = 300; var arg = new FindEntitiesInListArgument(typeof(CommerceEntity), "Orders", System.Convert.ToInt32(orderTotals.LastSkip), batchSize); var ordersBatch = await this._commerceCommander.Pipeline <FindEntitiesInListPipeline>().Run(arg, commerceContext.GetPipelineContextOptions()); while (ordersBatch.List.Items.Count > 0) { var returnedOrders = ordersBatch.List.Items.OfType <Order>(); foreach (var order in returnedOrders) { orderTotals.Totals.GrandTotal.Amount = orderTotals.Totals.GrandTotal.Amount + order.Totals.GrandTotal.Amount; orderTotals.Totals.SubTotal.Amount = orderTotals.Totals.SubTotal.Amount + order.Totals.SubTotal.Amount; orderTotals.Totals.PaymentsTotal.Amount = orderTotals.Totals.PaymentsTotal.Amount + order.Totals.PaymentsTotal.Amount; orderTotals.Totals.AdjustmentsTotal.Amount = orderTotals.Totals.AdjustmentsTotal.Amount + order.Totals.AdjustmentsTotal.Amount; foreach (var adjustment in order.Adjustments) { var adjustmentType = orderTotals.Adjustments.FirstOrDefault(p => p.Name == adjustment.AdjustmentType); if (adjustmentType == null) { adjustmentType = new TotalsAdjustmentsModel { Name = adjustment.AdjustmentType }; orderTotals.Adjustments.Add(adjustmentType); } adjustmentType.Adjustment.Amount = adjustmentType.Adjustment.Amount + adjustment.Adjustment.Amount; } if (order.HasComponent <ContactComponent>()) { OrdersTotals orderTotalsByCust = null; var orderContactComponent = order.GetComponent <ContactComponent>(); var customerTotalsId = $"Order_Totals_ByCust_{orderContactComponent.CustomerId.Replace("Entity-Customer-", "")}"; if (customerTotals.ContainsKey(customerTotalsId)) { orderTotalsByCust = customerTotals[customerTotalsId]; } else { orderTotalsByCust = await this._commerceCommander .GetEntity <OrdersTotals>(commerceContext, customerTotalsId, true); } if (!orderTotalsByCust.IsPersisted) { orderTotalsByCust.Id = customerTotalsId; } else { if (orderTotalsByCust.OrderCount == 0 || orderTotalsByCust.MonitorCycle != orderTotals.MonitorCycle) { orderTotalsByCust.Totals.GrandTotal.Amount = 0; orderTotalsByCust.Totals.SubTotal.Amount = 0; orderTotalsByCust.Totals.PaymentsTotal.Amount = 0; orderTotalsByCust.Totals.AdjustmentsTotal.Amount = 0; orderTotalsByCust.MonitorCycle = orderTotals.MonitorCycle; orderTotalsByCust.Adjustments.Clear(); } } orderTotalsByCust.OrderCount++; orderTotalsByCust.LastSkip = orderTotalsByCust.LastSkip + batchSize; orderTotalsByCust.Totals.GrandTotal.Amount = orderTotalsByCust.Totals.GrandTotal.Amount + order.Totals.GrandTotal.Amount; orderTotalsByCust.Totals.SubTotal.Amount = orderTotalsByCust.Totals.SubTotal.Amount + order.Totals.SubTotal.Amount; orderTotalsByCust.Totals.PaymentsTotal.Amount = orderTotalsByCust.Totals.PaymentsTotal.Amount + order.Totals.PaymentsTotal.Amount; orderTotalsByCust.Totals.AdjustmentsTotal.Amount = orderTotalsByCust.Totals.AdjustmentsTotal.Amount + order.Totals.AdjustmentsTotal.Amount; foreach (var adjustment in order.Adjustments) { var adjustmentType = orderTotalsByCust.Adjustments.FirstOrDefault(p => p.Name == adjustment.AdjustmentType); if (adjustmentType == null) { adjustmentType = new TotalsAdjustmentsModel { Name = adjustment.AdjustmentType }; orderTotalsByCust.Adjustments.Add(adjustmentType); } adjustmentType.Adjustment.Amount = adjustmentType.Adjustment.Amount + adjustment.Adjustment.Amount; } } orderTotals.OrderCount++; } orderTotals.LastSkip = orderTotals.LastSkip + batchSize; orderTotals.History.Add(new HistoryEntryModel { Name = "MonitorTotals.BatchCompleted", EventMessage = $"Completed batch: {orderTotals.LastSkip}" }); orderTotals.LastRunEnded = DateTimeOffset.UtcNow; orderTotals.LastSkip = (orderTotals.LastSkip - batchSize) + returnedOrders.Count(); await this._commerceCommander.PersistEntity(commerceContext, orderTotals); foreach (var orderCustomerTotal in customerTotals) { await this._commerceCommander.PersistEntity(commerceContext, orderCustomerTotal.Value); } customerTotals.Clear(); await Task.Delay(100); arg = new FindEntitiesInListArgument(typeof(CommerceEntity), "Orders", System.Convert.ToInt32(orderTotals.LastSkip), batchSize); ordersBatch = await this._commerceCommander.Pipeline <FindEntitiesInListPipeline>().Run(arg, commerceContext.GetPipelineContextOptions()); } } catch (Exception ex) { commerceContext.Logger.LogError($"ChildViewEnvironments.Exception: Message={ex.Message}"); } return(true); } }
/// <summary> /// Processes the specified commerce context. /// </summary> /// <param name="commerceContext">The commerce context.</param> /// <param name="sourceEnvironmentName">Name of the source environment.</param> /// <param name="newEnvironmentName">New name of the environment.</param> /// <param name="newArtifactStoreId">The new artifact store identifier.</param> /// <returns> /// User site terms /// </returns> public virtual async Task <bool> Process(CommerceContext commerceContext, string sourceEnvironmentName, string newEnvironmentName, Guid newArtifactStoreId) { using (CommandActivity.Start(commerceContext, this)) { var migrationSqlPolicy = commerceContext.GetPolicy <MigrationSqlPolicy>(); if (migrationSqlPolicy == null) { await commerceContext.AddMessage( commerceContext.GetPolicy <KnownResultCodes>().Error, "InvalidOrMissingPropertyValue", new object[] { "MigrationSqlPolicy" }, $"{this.GetType()}. Missing MigrationSqlPolicy"); return(false); } if (string.IsNullOrEmpty(migrationSqlPolicy.SourceStoreSqlPolicy.Server)) { await commerceContext.AddMessage( commerceContext.GetPolicy <KnownResultCodes>().Error, "InvalidOrMissingPropertyValue", new object[] { "MigrationSqlPolicy" }, $"{this.GetType()}. Empty server name in the MigrationSqlPolicy"); return(false); } var migrationPolicy = commerceContext.GetPolicy <MigrationPolicy>(); if (migrationPolicy == null) { await commerceContext.AddMessage( commerceContext.GetPolicy <KnownResultCodes>().Error, "InvalidOrMissingPropertyValue", new object[] { "MigrationPolicy" }, $"{this.GetType()}. Missing MigrationPolicy"); return(false); } Guid id; if (!Guid.TryParse(migrationSqlPolicy.ArtifactStoreId, out id)) { await commerceContext.AddMessage( commerceContext.GetPolicy <KnownResultCodes>().Error, "InvalidOrMissingPropertyValue", new object[] { "MigrationSqlPolicy.ArtifactStoreId" }, "MigrationSqlPolicy. Invalid ArtifactStoreId"); return(false); } var context = commerceContext.GetPipelineContextOptions(); var findArg = new FindEntityArgument(typeof(CommerceEnvironment), $"{CommerceEntity.IdPrefix<CommerceEnvironment>()}{newEnvironmentName}"); var findResult = await this._findEntityPipeline.Run(findArg, context); var newEnvironment = findResult as CommerceEnvironment; if (newEnvironment != null) { await commerceContext.AddMessage( commerceContext.GetPolicy <KnownResultCodes>().Error, "InvalidOrMissingPropertyValue", new object[] { newEnvironmentName }, $"Environment {newEnvironmentName} already exists."); return(false); } findArg = new FindEntityArgument(typeof(CommerceEnvironment), $"{CommerceEntity.IdPrefix<CommerceEnvironment>()}{migrationPolicy.DefaultEnvironmentName}"); findResult = await this._findEntityPipeline.Run(findArg, context); var sourceEnvironment = findResult as CommerceEnvironment; if (sourceEnvironment == null) { await commerceContext.AddMessage( commerceContext.GetPolicy <KnownResultCodes>().Error, "EntityNotFound", new object[] { migrationPolicy.DefaultEnvironmentName }, $"Entity {migrationPolicy.DefaultEnvironmentName} was not found."); return(false); } if (sourceEnvironment.HasPolicy <EntityShardingPolicy>()) { commerceContext.AddUniqueObjectByType(sourceEnvironment.GetPolicy <EntityShardingPolicy>()); sourceEnvironment.RemovePolicy(typeof(EntityShardingPolicy)); } // set sql policies var sqlPoliciesCollection = new List <KeyValuePair <string, EntityStoreSqlPolicy> > { new KeyValuePair <string, EntityStoreSqlPolicy>("SourceGlobal", migrationSqlPolicy.SourceStoreSqlPolicy) }; // Get sql Policy set var ps = await this._findEntityPipeline.Run(new FindEntityArgument(typeof(PolicySet), $"{CommerceEntity.IdPrefix<PolicySet>()}{migrationPolicy.SqlPolicySetName}"), context); if (ps == null) { context.CommerceContext.Logger.LogError($"PolicySet {migrationPolicy.SqlPolicySetName} was not found."); } else { sqlPoliciesCollection.Add(new KeyValuePair <string, EntityStoreSqlPolicy>("DestinationShared", ps.GetPolicy <EntityStoreSqlPolicy>())); } commerceContext.AddUniqueObjectByType(sqlPoliciesCollection); sourceEnvironment.Name = sourceEnvironmentName; sourceEnvironment.ArtifactStoreId = id; sourceEnvironment.Id = $"{CommerceEntity.IdPrefix<CommerceEnvironment>()}{sourceEnvironmentName}"; sourceEnvironment.SetPolicy(migrationSqlPolicy.SourceStoreSqlPolicy); var migrateEnvironmentArgument = new MigrateEnvironmentArgument(sourceEnvironment, newArtifactStoreId, newEnvironmentName); var result = await this._migrateEnvironmentPipeline.Run(migrateEnvironmentArgument, context); return(result); } }
public virtual async Task <PriceCard> Process(CommerceContext commerceContext, string cardFriendlyId, string snapshotId, string priceTierId) { PriceCard result = null; using (CommandActivity.Start(commerceContext, this)) { PriceCard priceCard = await GetPriceCard(commerceContext, cardFriendlyId) .ConfigureAwait(false); if (priceCard == null) { return(null); } PriceSnapshotComponent priceSnapshot = await GetPriceSnapshot(commerceContext, priceCard, snapshotId) .ConfigureAwait(false); if (priceSnapshot == null) { return(null); } var priceTier = await GetCustomPriceTier(commerceContext, priceCard, priceSnapshot, priceTierId) .ConfigureAwait(false); if (priceTier == null) { return(null); } await PerformTransaction(commerceContext, async() => result = await _removeCustomPriceTierPipeline.Run(new PriceCardSnapshotCustomTierArgument(priceCard, priceSnapshot, priceTier), commerceContext.GetPipelineContextOptions()).ConfigureAwait(false)) .ConfigureAwait(false); return(result); } }
public async Task <IEnumerable <SellableItem> > Process(CommerceContext commerceContext, IEnumerable <SellableItem> items) { using (CommandActivity.Start(commerceContext, this)) { var returnedItems = new List <SellableItem>(); foreach (var item in items) { var findEntityArgument = new FindEntityArgument(typeof(SellableItem), item.Id, false); // No bulk API exists in core platform, under the hood it's reading one at a time. // I've layed out the import in this manner so you can test how long each piece takes // An option you have is to do a select directly against the DB, for all items in this batch // to see if you need to make this call. var commerceEntity = await Pipeline <IFindEntityPipeline>().Run(findEntityArgument, commerceContext.GetPipelineContextOptions()) as SellableItem; if (commerceEntity != null) { returnedItems.Add(commerceEntity); } } return(returnedItems); } }
public async Task <List <InventorySet> > Process(CommerceContext commerceContext, List <CreateStoreInventorySetArgument> inputArgumentList, List <string> productsToAssociate, string catalogName) { CreateStoreInventoryCommand createStoreInventoryCommand = this; //InventorySet result = (InventorySet)null; List <InventorySet> sets = new List <InventorySet>(); using (CommandActivity.Start(commerceContext, (CommerceCommand)createStoreInventoryCommand)) { await createStoreInventoryCommand.PerformTransaction(commerceContext, (Func <Task>)(async() => { CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.GetPipelineContextOptions(); foreach (CreateStoreInventorySetArgument arg in inputArgumentList) { InventorySet inventorySet2 = await this._createStoreInventorySetPipeline.Run(arg, pipelineContextOptions); if (inventorySet2 != null) { sets.Add(inventorySet2); } else { // find the entity set id and add - for further processng in associate sets.Add(new InventorySet() { Id = CommerceEntity.IdPrefix <InventorySet>() + arg.Name }); } } })); } // Update all products if no input passed if (productsToAssociate.Count == 0) { var products = await this._getProductsToUpdateInventoryPipeline.Run(catalogName, commerceContext.GetPipelineContextOptions()); productsToAssociate = products; if (productsToAssociate == null) { return(null); } } // Once Done.. then assign inventory to products in the sets // Associate Sellable Item to Inventory Set foreach (var product in productsToAssociate) { using (CommandActivity.Start(commerceContext, (CommerceCommand)createStoreInventoryCommand)) { CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.GetPipelineContextOptions(); var productIds = product.Split('|'); string variantId = null; var productId = product.Split('|').FirstOrDefault(); if (productIds.Count() > 1) { variantId = product.Split('|').Skip(1).FirstOrDefault(); } SellableItemInventorySetsArgument args = new SellableItemInventorySetsArgument() { InventorySetIds = sets.Select(x => x.Id).ToList(), SellableItemId = productId, VariationId = variantId }; bool result = await this._associateStoreInventoryToSellableItem.Run(args, pipelineContextOptions); } } return(sets); }
public virtual async Task <PriceCard> Process(CommerceContext commerceContext, PriceCard priceCard, PriceSnapshotComponent priceSnapshot, CustomPriceTier priceTier) { PriceCard result = null; using (CommandActivity.Start(commerceContext, this)) { await PerformTransaction(commerceContext, async() => { result = await _removeCustomPriceTierPipeline.Run(new PriceCardSnapshotCustomTierArgument(priceCard, priceSnapshot, priceTier), commerceContext.GetPipelineContextOptions()) .ConfigureAwait(false); }).ConfigureAwait(false); } return(result); }
public virtual async Task <PriceCard> Process(CommerceContext commerceContext, PriceCard priceCard, PriceSnapshotComponent priceSnapshot, IEnumerable <CustomPriceTier> priceTiers) { PriceCard result = null; using (CommandActivity.Start(commerceContext, this)) { var snapshot = await GetPriceSnapshot(commerceContext, priceCard, priceSnapshot.Id).ConfigureAwait(false); if (snapshot == null) { return(null); } await PerformTransaction(commerceContext, async() => { foreach (CustomPriceTier priceTier in priceTiers) { result = await _removeCustomPriceTierPipeline.Run(new PriceCardSnapshotCustomTierArgument(priceCard, priceSnapshot, priceTier), commerceContext.GetPipelineContextOptions()) .ConfigureAwait(false); if (commerceContext.HasErrors()) { break; } } }).ConfigureAwait(false); return(result); } }