public override Task <EntityView> Run(EntityView arg, CommercePipelineExecutionContext context) { CommerceContext = context; Condition.Requires(arg).IsNotNull($"{Name}: argument cannot be null."); SearchIndexMinionArgument indexMinionArgument = CommerceContext.CommerceContext .GetObjects <SearchIndexMinionArgument>() .FirstOrDefault(); if (string.IsNullOrEmpty(indexMinionArgument?.Policy?.Name)) { return(Task.FromResult(arg)); } var source = GetEntities(indexMinionArgument); if (source == null || !source.Any()) { return(Task.FromResult(arg)); } KnownSearchViewsPolicy searchViewNames = context.GetPolicy <KnownSearchViewsPolicy>(); source.ForEach(si => { EntityView entityView = arg.ChildViews .Cast <EntityView>() .FirstOrDefault(v => v.EntityId.Equals(si.Id, StringComparison.OrdinalIgnoreCase) && v.Name.Equals(searchViewNames.Document, StringComparison.OrdinalIgnoreCase)); if (entityView == null) { entityView = new EntityView { Name = context.GetPolicy <KnownSearchViewsPolicy>().Document, EntityId = si.Id, EntityVersion = si.EntityVersion }; arg.ChildViews.Add(entityView); } BuildProperties(si, entityView); BuildCustomProperties(si, entityView); }); //context.Logger.LogInformation($"Processed {source.Count} {typeof(T)} items."); return(Task.FromResult(arg)); }
public virtual List <T> GetEntities(SearchIndexMinionArgument indexArgument) { return(indexArgument.Entities? .OfType <T>() .ToList()); }