/// <summary> /// Runs the specified target. /// </summary> /// <param name="target">The target to run.</param> /// <returns>The resulting report.</returns> public override async Task <CakeReport> RunTargetAsync(string target) { var strategy = new DefaultExecutionStrategy(_log); var report = await Engine.RunTargetAsync(Context, strategy, target).ConfigureAwait(false); if (report != null && !report.IsEmpty) { _reportPrinter.Write(report); } return(report); }
/// <summary> /// Runs the specified target. /// </summary> /// <param name="target">The target to run.</param> /// <returns>The resulting report.</returns> public override CakeReport RunTarget(string target) { var strategy = new DefaultExecutionStrategy(_log); var report = Engine.RunTarget(Context, strategy, target); if (report != null && !report.IsEmpty) { _reportPrinter.Write(report); } return(report); }
private void Execute_doesnt_retry(Action<IDbExecutionStrategy, Func<int>> execute) { var executionStrategy = new DefaultExecutionStrategy(); var executionCount = 0; Assert.Throws<TimeoutException>( () => execute(executionStrategy, () => { executionCount++; throw new TimeoutException(); })); Assert.Equal(1, executionCount); }
private void ExecuteAsync_doesnt_retry(Func<IDbExecutionStrategy, Func<Task<int>>, Task> executeAsync) { var executionStrategy = new DefaultExecutionStrategy(); var executionCount = 0; Assert.Throws<TimeoutException>( () => ExceptionHelpers.UnwrapAggregateExceptions( () => executeAsync(executionStrategy, () => { executionCount++; throw new TimeoutException(); }).Wait())); Assert.Equal(1, executionCount); }
public CakeEngineFixture() { FileSystem = Substitute.For <IFileSystem>(); Environment = Substitute.For <ICakeEnvironment>(); Log = new FakeLog(); Globber = Substitute.For <IGlobber>(); Arguments = Substitute.For <ICakeArguments>(); ProcessRunner = Substitute.For <IProcessRunner>(); ExecutionStrategy = new DefaultExecutionStrategy(Log); DataService = Substitute.For <ICakeDataService>(); Context = Substitute.For <ICakeContext>(); Context.Arguments.Returns(Arguments); Context.Environment.Returns(Environment); Context.FileSystem.Returns(FileSystem); Context.Globber.Returns(Globber); Context.Log.Returns(Log); Context.ProcessRunner.Returns(ProcessRunner); }
private IDbExecutionStrategy LoadExecutionStrategy() { int?countRanTransactions = (int?)CallContext.LogicalGetData(CallContextKey); IDbExecutionStrategy result; if (countRanTransactions > 0) { if (defaultExecutionStrategy == null) { defaultExecutionStrategy = new DefaultExecutionStrategy(); } result = defaultExecutionStrategy; } else { if (azureExecutionStrategy == null) { azureExecutionStrategy = new SqlAzureExecutionStrategy(3, TimeSpan.FromSeconds(30)); } result = azureExecutionStrategy; } return(result); }
/// <summary> /// Runs the application. /// </summary> /// <param name="args">Arguments.</param> /// <returns>0 on success.</returns> public int Run( string[] args ) { var console = new CakeConsole(); var logger = new SafeCakeLog( console ); var engine = new CakeEngine( logger ); ICakePlatform platform = new CakePlatform(); ICakeRuntime runtime = new CakeRuntime(); IFileSystem fileSystem = new FileSystem(); MutableCakeEnvironment environment = new MutableCakeEnvironment( platform, runtime ); IGlobber globber = new Globber( fileSystem, environment ); environment.Initialize( globber ); IProcessRunner processRunner = new ProcessRunner( environment, logger ); IRegistry windowsRegistry = new WindowsRegistry(); // Parse options. var argumentParser = new ArgumentParser( logger, fileSystem ); CakeOptions options = argumentParser.Parse( args ); Debug.Assert( options != null ); CakeConfigurationProvider configProvider = new CakeConfigurationProvider( fileSystem, environment ); ICakeConfiguration configuration = configProvider.CreateConfiguration( environment.ApplicationRoot, options.Arguments ); IToolRepository toolRepo = new ToolRepository( environment ); IToolResolutionStrategy toolStrategy = new ToolResolutionStrategy( fileSystem, environment, globber, configuration ); IToolLocator locator = new ToolLocator( environment, toolRepo, toolStrategy ); IToolLocator toolLocator = new ToolLocator( environment, toolRepo, toolStrategy ); logger.SetVerbosity( options.Verbosity ); CodeCakeBuildTypeDescriptor choosenBuild; if( !AvailableBuilds.TryGetValue( options.Script, out choosenBuild ) ) { logger.Error( "Build script '{0}' not found.", options.Script ); return -1; } ICakeArguments arguments = new CakeArguments(options.Arguments); var context = new CakeContext( fileSystem, environment, globber, logger, arguments, processRunner, windowsRegistry, locator ); // Copy the arguments from the options. // Set the working directory: the solution directory. environment.WorkingDirectory = new DirectoryPath( _solutionDirectory ); // Adds additional paths from chosen build. foreach( var p in choosenBuild.AdditionnalPatternPaths ) { environment.AddPath( p ); } logger.Information( "Path(s) added: " + string.Join( ", ", environment.EnvironmentAddedPaths ) ); logger.Information( "Dynamic pattern path(s) added: " + string.Join( ", ", environment.EnvironmentDynamicPaths ) ); try { // Instanciates the script object. CodeCakeHost._injectedActualHost = new BuildScriptHost( engine, context ); CodeCakeHost c = (CodeCakeHost)Activator.CreateInstance( choosenBuild.Type ); var strategy = new DefaultExecutionStrategy( logger ); var report = engine.RunTarget( context, strategy, context.Arguments.GetArgument( "target" ) ?? "Default" ); if( report != null && !report.IsEmpty ) { var printerReport = new CakeReportPrinter( console ); printerReport.Write( report ); } } catch( CakeTerminateException ex ) { switch( ex.Option ) { case CakeTerminationOption.Error: logger.Error( "Termination with Error: '{0}'.", ex.Message ); return -1; case CakeTerminationOption.Warning: logger.Warning( "Termination with Warning: '{0}'.", ex.Message ); break; default: Debug.Assert( ex.Option == CakeTerminationOption.Success ); logger.Information( "Termination with Success: '{0}'.", ex.Message ); break; } } catch( TargetInvocationException ex ) { logger.Error( "Error occurred: '{0}'.", ex.InnerException?.Message ?? ex.Message ); return -1; } catch( Exception ex ) { logger.Error( "Error occurred: '{0}'.", ex.Message ); return -1; } return 0; }
/// <summary> /// Runs the application. /// </summary> /// <param name="args">Arguments.</param> /// <param name="appRoot">Application root folder</param> /// <returns>0 on success.</returns> public int Run(string[] args, string appRoot = null) { var console = new CakeConsole(); var logger = new SafeCakeLog(console); var engine = new CakeEngine(logger); ICakePlatform platform = new CakePlatform(); ICakeRuntime runtime = new CakeRuntime(); IFileSystem fileSystem = new FileSystem(); MutableCakeEnvironment environment = new MutableCakeEnvironment(platform, runtime, appRoot); IGlobber globber = new Globber(fileSystem, environment); environment.Initialize(globber); IProcessRunner processRunner = new ProcessRunner(environment, logger); IRegistry windowsRegistry = new WindowsRegistry(); // Parse options. var argumentParser = new ArgumentParser(logger, fileSystem); CakeOptions options = argumentParser.Parse(args); Debug.Assert(options != null); CakeConfigurationProvider configProvider = new CakeConfigurationProvider(fileSystem, environment); ICakeConfiguration configuration = configProvider.CreateConfiguration(environment.ApplicationRoot, options.Arguments); IToolRepository toolRepo = new ToolRepository(environment); IToolResolutionStrategy toolStrategy = new ToolResolutionStrategy(fileSystem, environment, globber, configuration); IToolLocator locator = new ToolLocator(environment, toolRepo, toolStrategy); IToolLocator toolLocator = new ToolLocator(environment, toolRepo, toolStrategy); logger.SetVerbosity(options.Verbosity); CodeCakeBuildTypeDescriptor choosenBuild; if (!AvailableBuilds.TryGetValue(options.Script, out choosenBuild)) { logger.Error("Build script '{0}' not found.", options.Script); return(-1); } ICakeArguments arguments = new CakeArguments(options.Arguments); var context = new CakeContext(fileSystem, environment, globber, logger, arguments, processRunner, windowsRegistry, locator); // Copy the arguments from the options. // Set the working directory: the solution directory. environment.WorkingDirectory = new DirectoryPath(_solutionDirectory); // Adds additional paths from chosen build. foreach (var p in choosenBuild.AdditionnalPatternPaths) { environment.AddPath(p); } logger.Information("Path(s) added: " + string.Join(", ", environment.EnvironmentAddedPaths)); logger.Information("Dynamic pattern path(s) added: " + string.Join(", ", environment.EnvironmentDynamicPaths)); try { // Instanciates the script object. CodeCakeHost._injectedActualHost = new BuildScriptHost(engine, context); CodeCakeHost c = (CodeCakeHost)Activator.CreateInstance(choosenBuild.Type); var strategy = new DefaultExecutionStrategy(logger); var report = engine.RunTargetAsync(context, strategy, context.Arguments.GetArgument("target") ?? "Default").GetAwaiter().GetResult(); if (report != null && !report.IsEmpty) { var printerReport = new CakeReportPrinter(console); printerReport.Write(report); } } catch (CakeTerminateException ex) { switch (ex.Option) { case CakeTerminationOption.Error: logger.Error("Termination with Error: '{0}'.", ex.Message); return(-1); case CakeTerminationOption.Warning: logger.Warning("Termination with Warning: '{0}'.", ex.Message); break; default: Debug.Assert(ex.Option == CakeTerminationOption.Success); logger.Information("Termination with Success: '{0}'.", ex.Message); break; } } catch (TargetInvocationException ex) { logger.Error("Error occurred: '{0}'.", ex.InnerException?.Message ?? ex.Message); return(-1); } catch (Exception ex) { logger.Error("Error occurred: '{0}'.", ex.Message); return(-1); } return(0); }
static ContextDbConfiguration() { ExecutionStrategy = new DefaultExecutionStrategy(); }