public IBulkAction Create(BulkActionContext context)
        {
            IBulkAction result = null;

            switch (context)
            {
            case CategoryChangeBulkActionContext changeCategoryActionContext:
                result = new CategoryChangeBulkAction(changeCategoryActionContext, _catalogService, _categoryListEntryMover, _productListEntryMover);
                break;

            case PropertiesUpdateBulkActionContext updatePropertiesActionContext:
                result = new PropertiesUpdateBulkAction(updatePropertiesActionContext, _itemService, _bulkPropertyUpdateManager);
                break;
            }

            return(result ?? throw new ArgumentException($"Unsupported action type: {context.GetType().Name}"));
        }
        public IBulkAction Create(BulkActionContext context)
        {
            IBulkAction result = null;

            switch (context)
            {
            case CategoryChangeBulkActionContext changeCategoryActionContext:
                result = new CategoryChangeBulkAction(_lazyLazyServiceProvider, changeCategoryActionContext);
                break;

            case PropertiesUpdateBulkActionContext updatePropertiesActionContext:
                result = new PropertiesUpdateBulkAction(_lazyLazyServiceProvider, updatePropertiesActionContext);
                break;
            }

            return(result ?? throw new ArgumentException($"Unsupported action type: {context.GetType().Name}"));
        }
        private async Task ValidateActionAsync(IBulkAction action)
        {
            var validationResult = await action.ValidateAsync();

            var proceed = validationResult.Succeeded;

            ThrowIfCancellationRequested();

            if (proceed)
            {
                _progressContext.Description = "Validation successfully completed.";
            }
            else
            {
                _progressContext.Description = "Validation has been completed with errors.";
                _progressContext.Errors      = validationResult.Errors;
            }
        }
 public BulkController(IBulkAction bulkAction)
 {
     _bulkAction = bulkAction;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Resolves a BulkAction Connector, given a <see cref="ConnectorKey"/>.
        /// </summary>
        public virtual IBulkAction <TState, TInput> ResolveBulkAction(ConnectorKey connectorKey)
        {
            if (connectorKey == null)
            {
                throw new ArgumentNullException(nameof(connectorKey));
            }

            do
            {
                try
                {
                    if (!BulkActions.TryGetValue(connectorKey.Identifier, out var bulkAction))
                    {
                        throw new ConnectorResolutionException($"No BulkAction exists matching connectorKey: \"{connectorKey.Identifier}\".");
                    }

                    return(bulkAction);
                }
                catch (ConnectorResolutionException connectorResolutionException)
                {
                    var connectorType = Type.GetType(connectorKey.Identifier);

                    if (connectorType != null)
                    {
                        lock (SyncRoot)
                        {
                            IBulkAction <TState, TInput> bulkAction = null;

                            var resolutionExceptions = new List <Exception>
                            {
                                connectorResolutionException
                            };

                            for (var i = 0; i <= 1; i++)
                            {
                                try
                                {
                                    bulkAction = (Agent.Configuration as HostConfiguration).Container
                                                 .Resolve <IBulkAction <TState, TInput> >(connectorKey.Identifier);
                                }
                                catch (Exception ex)
                                {
                                    resolutionExceptions.Add(ex);

                                    Agent.Configuration.Register(registrar =>
                                                                 registrar.RegisterConnector(connectorType)
                                                                 .WithConfiguration(new ConnectorConfiguration(connectorKey.Identifier)));
                                }
                            }

                            if (bulkAction == null)
                            {
                                throw new AggregateException(
                                          message: "BulkAction resolution failed even after best attempt re-register.",
                                          innerExceptions: resolutionExceptions);
                            }

                            BulkActions.TryAdd(connectorKey.Identifier, bulkAction);

                            continue;
                        }
                    }

                    throw;
                }
            }while (true);
        }