예제 #1
0
        public static IEnumerable <(string Key, ConnectorSettings Settings)> CreateFromSCLSettings(
            SCLSettings sclSettings)
        {
            var connectorsEntity = sclSettings.Entity.TryGetNestedEntity(SCLSettings.ConnectorsKey);

            if (connectorsEntity.HasNoValue)
            {
                yield break;
            }

            foreach (var property in connectorsEntity.Value)
            {
                if (property.BestValue is EntityValue.NestedEntity nestedEntity)
                {
                    var connectorSettings =
                        EntityConversionHelpers.TryCreateFromEntity <ConnectorSettings>(
                            nestedEntity.Value
                            );

                    if (connectorSettings.IsSuccess)
                    {
                        yield return(new(property.Name, connectorSettings.Value));
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Try to get a list of NuixSettings from a list of Connector Informations
        /// </summary>
        public static Result <NuixSettings, IErrorBuilder> TryGetNuixSettings(
            IEnumerable <ConnectorSettings> connectorSettings)
        {
            var connectorInformation =
                connectorSettings.FirstOrDefault(
                    x => x.Id.EndsWith("Nuix", StringComparison.OrdinalIgnoreCase)
                    );

            if (connectorInformation is null)
            {
                return(ErrorCode.MissingStepSettings.ToErrorBuilder("Nuix"));
            }

            var nuixSettings =
                EntityConversionHelpers.TryCreateFromEntity <NuixSettings>(
                    connectorInformation.Settings
                    );

            return(nuixSettings);
        }
예제 #3
0
        /// <inheritdoc />
        protected override async Task <Result <Array <Entity>, IError> > Run(
            IStateMonad stateMonad,
            CancellationToken cancellationToken)
        {
            var entityStream = await EntityStream.Run(stateMonad, cancellationToken);

            if (entityStream.IsFailure)
            {
                return(entityStream.ConvertFailure <Array <Entity> >());
            }

            var schemaEntity = await Schema.Run(stateMonad, cancellationToken);

            if (schemaEntity.IsFailure)
            {
                return(schemaEntity.ConvertFailure <Array <Entity> >());
            }

            var schema = EntityConversionHelpers.TryCreateFromEntity <Schema>(schemaEntity.Value)
                         .MapError(e => e.WithLocation(this));

            if (schema.IsFailure)
            {
                return(schema.ConvertFailure <Array <Entity> >());
            }

            Maybe <ErrorBehavior> errorBehavior;

            if (ErrorBehavior == null)
            {
                errorBehavior = Maybe <ErrorBehavior> .None;
            }
            else
            {
                var errorBehaviorResult = await ErrorBehavior.Run(stateMonad, cancellationToken);

                if (errorBehaviorResult.IsFailure)
                {
                    return(errorBehaviorResult.ConvertFailure <Array <Entity> >());
                }

                errorBehavior = Maybe <ErrorBehavior> .From(errorBehaviorResult.Value);
            }

            var newStream = entityStream.Value.SelectMany(ApplySchema);

            return(newStream);

            async IAsyncEnumerable <Entity> ApplySchema(Entity entity)
            {
                await ValueTask.CompletedTask;
                var result = schema.Value.ApplyToEntity(entity, this, stateMonad, errorBehavior);

                if (result.IsFailure)
                {
                    throw new ErrorException(result.Error.WithLocation(this));
                }

                if (result.Value.HasValue)
                {
                    yield return(result.Value.Value);
                }
            }
        }