Esempio n. 1
0
        public async Task <ExecutionResult> ExecuteAsync(IScriptHandle script, CancellationToken cancellationToken)
        {
            if (script == null)
            {
                throw new ArgumentNullException(nameof(script));
            }

            var compiledAssembly = await _assemblyProvider.CompileCodeAsync(script, cancellationToken);

            var entryPoint = compiledAssembly
                             .Types
                             .SingleOrDefault(t => typeof(IScriptEntryPoint).IsAssignableFrom(t));

            if (entryPoint == null)
            {
                return(new ExecutionResult(ExecutionResultStatus.Warnings, "No entry point found!"));
            }

            if (CanSkipService(entryPoint))
            {
                return(new ExecutionResult(ExecutionResultStatus.Skipped));
            }
            OnBeforeExecution(entryPoint);

            var service = (IScriptEntryPoint)GetService(entryPoint);

            try
            {
                await service.ExecuteAsync(cancellationToken);
            }
            catch (AggregateException exception)
            {
                return(new ExecutionResult(ExecutionResultStatus.Errors, exception
                                           .InnerExceptions
                                           .Select(t => t.Message)));
            }

            return(new ExecutionResult(ExecutionResultStatus.Success));
        }