Пример #1
0
        /// <summary>
        /// Runs this step asynchronously.
        /// </summary>
        protected async Task <Result <T, IError> > RunAsync(
            IStateMonad stateMonad,
            CancellationToken cancellationToken)
        {
            var methodParameters = await TryGetMethodParameters(stateMonad, cancellationToken);

            if (methodParameters.IsFailure)
            {
                return(methodParameters.ConvertFailure <T>());
            }

            var nuixConnection = await stateMonad.GetOrCreateNuixConnection(this, false);

            if (nuixConnection.IsFailure)
            {
                return(nuixConnection.ConvertFailure <T>().MapError(x => x.WithLocation(this)));
            }

            var runResult = await nuixConnection.Value.RunFunctionAsync(
                stateMonad,
                this,
                RubyScriptStepFactory.RubyFunction,
                methodParameters.Value,
                CasePathParameter,
                cancellationToken
                );

            if (runResult.IsFailure &&
                runResult.Error.GetErrorBuilders()
                .Any(x => x.Data is ErrorData.ExceptionData {
                Exception: ChannelClosedException
            }))
Пример #2
0
        public async Task GetOrCreateNuixConnection_WhenScriptFileDoesNotExist_ReturnsError()
        {
            var fakeExternalProcess = new ExternalProcessMock(
                1,
                ConnectionTestsHelper.GetCreateCaseAction()
                );

            var fileMock =
                Mock.Of <IFile>(f => f.Exists(It.IsAny <string>()) == false);

            IStateMonad state = ConnectionTestsHelper.GetStateMonad(
                TestLoggerFactory.Create(),
                fakeExternalProcess,
                ConsoleAdapter.Instance
                );

            //Remove the script from the file system
            var nuixFileSystem =
                state.ExternalContext.TryGetContext <IFileSystem>(ConnectorInjection.FileSystemKey);

            nuixFileSystem.Value.File.Delete(NuixConnectionHelper.NuixGeneralScriptName);

            var connection = await state.GetOrCreateNuixConnection(null, false);

            Assert.True(connection.IsFailure);

            Assert.Matches(
                $"Could not find.+{NuixConnectionHelper.NuixGeneralScriptName}'",
                connection.Error.AsString
                );
        }
Пример #3
0
        /// <inheritdoc />
        protected override async Task <Result <Unit, IError> > Run(
            IStateMonad stateMonad,
            CancellationToken cancellationToken)
        {
            await Task.CompletedTask;

            var r = await stateMonad.GetOrCreateNuixConnection(this, false);

            if (r.IsFailure)
            {
                return(r.MapError(x => x.WithLocation(this)).ConvertFailure <Unit>());
            }

            return(Unit.Default);
        }
Пример #4
0
        public async Task GetOrCreateNuixConnection_OnStartExternalProcessFailure_ReturnsError()
        {
            var fakeExternalProcess =
                new ExternalProcessMock(1, ConnectionTestsHelper.GetCreateCaseAction())
            {
                ProcessPath = "WrongPath", ValidateArguments = false
            };

            var loggerFactory = TestLoggerFactory.Create();

            IStateMonad state =
                ConnectionTestsHelper.GetStateMonad(
                    fakeExternalProcess,
                    loggerFactory
                    );

            var createConnection = await state.GetOrCreateNuixConnection(null, true);

            createConnection.ShouldBeFailure();

            createConnection.Error.AsString.Should()
            .Be($"External Process Failed: 'Could not start '{Constants.NuixConsoleExe}''");
        }
Пример #5
0
        /// <inheritdoc />
        protected override async Task <Result <StringStream, IError> > Run(
            IStateMonad stateMonad,
            CancellationToken cancellationToken)
        {
            //var isAdmin = IsCurrentProcessAdmin();
            //var isLinux = IsLinux;
            //if(isAdmin &&!isLinux)
            //    return new SingleError("You cannot run arbitrary Nuix Scripts as Administrator", ErrorCode.ExternalProcessError, new StepErrorLocation(this));

            var functionName = await FunctionName.Run(stateMonad, cancellationToken)
                               .Map(x => x.GetStringAsync())
            ;

            if (functionName.IsFailure)
            {
                return(functionName.ConvertFailure <StringStream>());
            }

            var scriptText = await ScriptText.Run(stateMonad, cancellationToken)
                             .Map(x => x.GetStringAsync());

            if (scriptText.IsFailure)
            {
                return(scriptText.ConvertFailure <StringStream>());
            }

            var parameters = await Parameters.Run(stateMonad, cancellationToken);

            if (parameters.IsFailure)
            {
                return(parameters.ConvertFailure <StringStream>());
            }

            var nuixConnection = await stateMonad.GetOrCreateNuixConnection(this, false);

            if (nuixConnection.IsFailure)
            {
                return(nuixConnection.ConvertFailure <StringStream>()
                       .MapError(x => x.WithLocation(this)));
            }

            var rubyFunctionParameters = parameters.Value
                                         .Select(x => new RubyFunctionParameter(ConvertString(x.Name), x.Name, true))
                                         .ToList();

            var parameterDict = parameters.Value
                                .ToDictionary(
                x =>
                new RubyFunctionParameter(ConvertString(x.Name), x.Name, true),
                x => x.BestValue.ObjectValue
                )
                                .Where(x => x.Value != null)
                                .ToDictionary(x => x.Key, x => x.Value !);

            if (EntityStreamParameter != null)
            {
                var streamResult = await EntityStreamParameter.Run(stateMonad, cancellationToken);

                if (streamResult.IsFailure)
                {
                    return(streamResult.ConvertFailure <StringStream>());
                }

                const string streamParameter = "datastream";

                var parameter = new RubyFunctionParameter(
                    ConvertString(streamParameter),
                    streamParameter,
                    true
                    );

                rubyFunctionParameters.Add(parameter);

                parameterDict.Add(parameter, streamResult.Value);
            }

            var function = new RubyFunction <string>(
                ConvertString(functionName.Value),
                scriptText.Value,
                rubyFunctionParameters,
                new Version(5, 0),
                ArraySegment <NuixFeature> .Empty
                );

            var runResult = await nuixConnection.Value.RunFunctionAsync(
                stateMonad,
                this,
                function,
                parameterDict,
                CasePathParameter.IgnoresOpenCase.Instance,
                cancellationToken
                )
                            .Map(x => new StringStream(x));

            if (runResult.IsFailure)
            {
                return(runResult.MapError(x => x.WithLocation(this)).ConvertFailure <StringStream>());
            }

            return(runResult.Value);
        }