public override void RunBuild(FilePath solution) { if (!BuildsOnCurrentPlatform) { CakeContext.Information("Solution is not configured to build on this platform: {0}", SolutionPath); return; } CakeContext.MSBuild(solution, c => { c.Configuration = Configuration; c.MSBuildPlatform = MSBuildPlatform; if (!string.IsNullOrEmpty(Platform)) { c.Properties["Platform"] = new[] { Platform } } ; if (Targets != null && Targets.Any()) { foreach (var t in Targets) { c.Targets.Add(t); } } if (Properties != null && Properties.Any()) { foreach (var kvp in Properties) { c.Properties.Add(kvp.Key, kvp.Value); } } }); }
public FakeCakeContext() { var fileSystem = new FileSystem(); Log = new FakeLog(); var runtime = new CakeRuntime(); var platform = new FakePlatform(PlatformFamily.Windows); var environment = new CakeEnvironment(platform, runtime, Log); var globber = new Globber(fileSystem, environment); var args = Substitute.For <ICakeArguments>(); var registry = new WindowsRegistry(); var dataService = Substitute.For <ICakeDataService>(); var toolRepository = new ToolRepository(environment); var toolResolutionStrategy = new ToolResolutionStrategy(fileSystem, environment, globber, new FakeConfiguration()); var tools = new ToolLocator(environment, toolRepository, toolResolutionStrategy); var processRunner = new ProcessRunner(fileSystem, environment, Log, tools, new FakeConfiguration()); Context = new CakeContext(fileSystem, environment, globber, Log, args, processRunner, registry, tools, dataService); WorkingDirectory = new DirectoryPath( System.IO.Path.GetFullPath(AppContext.BaseDirectory)); Context.Environment.WorkingDirectory = WorkingDirectory; }
public GlobbingExtensionsTests(CakeFixture fixture) { fixture.FileSystem.AddFile(new FakeFile("", "c:/a.txt")); fixture.FileSystem.AddFile(new FakeFile("", "c:/a/c.txt")); fixture.FileSystem.AddFile(new FakeFile("", "c:/c/a.txt")); context = fixture.Context; }
public virtual void BuildSolution() { if (!BuildsOnCurrentPlatform) { CakeContext.Information("Solution is not configured to build on this platform: {0}", SolutionPath); return; } if (PreBuildAction != null) { PreBuildAction(); } if (RestoreComponents) { CakeContext.RestoreComponents(SolutionPath, new XamarinComponentRestoreSettings()); } CakeContext.NuGetRestore(SolutionPath, new NuGetRestoreSettings { Source = BuildSpec.NuGetSources.Select(s => s.Url).ToList() }); RunBuild(SolutionPath); if (PostBuildAction != null) { PostBuildAction(); } }
public UnityRunnerFixture() { ProjectPath = new DirectoryPath("C:/Project"); Platform = Substitute.For <UnityPlatform>(); DefaultToolPathExist = true; ProjectPathExist = true; Process = new FakeProcess(); ProcessRunner = Substitute.For <IProcessRunner>(); ProcessRunner.Start(Arg.Any <FilePath>(), Arg.Any <ProcessSettings>()).Returns(Process); Environment = new FakeEnvironment(PlatformFamily.Windows) { WorkingDirectory = "/Working" }; Environment.SetSpecialPath(SpecialPath.ProgramFilesX86, "C:/Program Files (x86)"); FileSystem = new FakeFileSystem(Environment); var globber = new Globber(FileSystem, Environment); Tools = new ToolLocator(Environment, new ToolRepository(Environment), new ToolResolutionStrategy(FileSystem, Environment, globber, new FakeConfiguration())); Context = new CakeContext(FileSystem, Environment, globber, new FakeLog(), Substitute.For <ICakeArguments>(), ProcessRunner, Substitute.For <IRegistry>(), Tools, Substitute.For <ICakeDataService>()); }
public GlobbingExtensionsTests(CakeFixture fixture) { fixture.FileSystem.CreateFakeFile("", fixture.Context.Environment.WorkingDirectory + "/a.txt"); fixture.FileSystem.CreateFakeFile("", fixture.Context.Environment.WorkingDirectory + "/a/c.txt"); fixture.FileSystem.CreateFakeFile("", fixture.Context.Environment.WorkingDirectory + "/c/a.txt"); context = fixture.Context; }
public static ICakeContext GetFakeContext() { var testDir = Environment.GetEnvironmentVariable("CAKEPLASTIC_TESTDIR"); var fileSystem = new FileSystem(); var environment = new FakeEnvironment(PlatformFamily.Windows); var log = new FakeLog(); var globber = new Globber(fileSystem, environment); var context = new CakeContext ( fileSystem: fileSystem, environment: environment, globber: globber, log: log, arguments: new FakeCakeArguments(), processRunner: new ProcessRunner(environment, log), registry: new WindowsRegistry(), tools: new ToolLocator(environment, new ToolRepository(environment), new ToolResolutionStrategy(fileSystem, environment, globber, new CakeConfigurationProvider(fileSystem, environment).CreateConfiguration(testDir, new Dictionary <string, string>()))), data: new FakeDataService() ); context.Environment.WorkingDirectory = testDir; return(context); }
private void UpdateCsProjFile(FilePath filePath, string version) { if (!CakeContext.XmlPeek(filePath, "/Project/@Sdk").StartsWith("Microsoft.NET.Sdk")) { return; } const string semver = @"^(\d+\.\d+\.\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$"; var regex = new Regex(semver); var match = regex.Match(version); if (match.Success) { version = string.IsNullOrWhiteSpace(match.Groups[3].Value) ? match.Groups[1].Value : $"{match.Groups[1]}.{match.Groups[3]}"; } else { //We either have Major.Minor.Build.Rev or yyMMdd.Rev from VSTS build //When we have yyMMdd.Rev, then we change it to yy.MM.dd.Rev var segments = version.Split('.'); if (segments.Length == 2) { version = $"{segments[0].Substring(0, 2)}.{segments[0].Substring(2, 2)}.{segments[0].Substring(4, 2)}.{segments[1]}"; } } CakeContext.Information($"Update csproj for version. Version: {version}, File: {filePath}"); CakeContext.XmlPoke(filePath, "/Project/PropertyGroup/AssemblyVersion", version); CakeContext.XmlPoke(filePath, "/Project/PropertyGroup/FileVersion", version); CakeContext.XmlPoke(filePath, "/Project/PropertyGroup/Version", version); }
public EndpointCreatorFixture(IEnumerable <Model.Endpoint> endpoints) { Endpoints = endpoints; Environment = new FakeEnvironment(PlatformFamily.Windows) { WorkingDirectory = "/Working" }; FileSystem = new FakeFileSystem(Environment); Globber = Substitute.For <IGlobber>(); Log = new FakeLog(); Arguments = Substitute.For <ICakeArguments>(); ProcessRunner = Substitute.For <IProcessRunner>(); Registry = Substitute.For <IRegistry>(); Tools = Substitute.For <IToolLocator>(); Context = new CakeContext(FileSystem, Environment, Globber, Log, Arguments, ProcessRunner, Registry, Tools, Substitute.For <ICakeDataService>(), Substitute.For <Core.Configuration.ICakeConfiguration>()); }
public virtual void RunBuild(FilePath solution) { CakeContext.DotNetBuild(solution, c => { c.Configuration = Configuration; if (!string.IsNullOrEmpty(Platform)) { c.Properties ["Platform"] = new [] { Platform } } ; if (Targets != null && Targets.Any()) { foreach (var t in Targets) { c.Targets.Add(t); } } if (Properties != null && Properties.Any()) { foreach (var kvp in Properties) { c.Properties.Add(kvp.Key, kvp.Value); } } }); }
protected BaseController() { hasher = new HashingManager(); encrypter = new Encrypter(); db = new CakeContext(); ViewData = new Dictionary <string, object>(); }
public GlobbingExtensionsTests() { fileSystem = new FakeFileSystem("c:/a.txt", "c:/a/c.txt", "c:/c/a.txt"); environment = new FakeCakeEnvironment(); globber = new Globber(fileSystem, environment); context = new CakeContext(fileSystem, environment, globber, new NullLog(), A.Dummy <ICakeArguments>(), A.Dummy <IProcessRunner>(), A.Dummy <IRegistry>(), A.Dummy <IToolLocator>()); }
public static void Seed(CakeContext context) { context.Database.Migrate(); if (!context.Cakes.Any()) { context.Cakes.AddRange(GetPreConfigureCakes()); context.SaveChanges(); } }
public virtual void CopyOutput() { if (OutputFiles == null) { return; } if (!BuildsOnCurrentPlatform) { return; } foreach (var fileCopy in OutputFiles) { FilePath targetFileName; var targetDir = fileCopy.ToDirectory ?? OutputDirectory; CakeContext.CreateDirectory(targetDir); if (fileCopy.NewFileName != null) { targetFileName = targetDir.CombineWithFilePath(fileCopy.NewFileName); } else { targetFileName = targetDir.CombineWithFilePath(fileCopy.FromFile.GetFilename()); } var srcAbs = CakeContext.MakeAbsolute(fileCopy.FromFile); var destAbs = CakeContext.MakeAbsolute(targetFileName); var sourceTime = System.IO.File.GetLastAccessTime(srcAbs.ToString()); var destTime = System.IO.File.GetLastAccessTime(destAbs.ToString()); CakeContext.Information("Target Dir: Exists? {0}, {1}", CakeContext.DirectoryExists(targetDir), targetDir); CakeContext.Information("Copy From: Exists? {0}, Dir Exists? {1}, Modified: {2}, {3}", CakeContext.FileExists(srcAbs), CakeContext.DirectoryExists(srcAbs.GetDirectory()), sourceTime, srcAbs); CakeContext.Information("Copy To: Exists? {0}, Dir Exists? {1}, Modified: {2}, {3}", CakeContext.FileExists(destAbs), CakeContext.DirectoryExists(destAbs.GetDirectory()), destTime, destAbs); if (sourceTime > destTime || !CakeContext.FileExists(destAbs)) { CakeContext.Information("Copying File: {0} to {1}", srcAbs, targetDir); CakeContext.CopyFileToDirectory(srcAbs, targetDir); } } }
public override void RunBuild(FilePath solution) { if (!BuildsOnCurrentPlatform) { CakeContext.Information("Solution is not configured to build on this platform: {0}", SolutionPath); return; } //if (CakeContext.IsRunningOnUnix ()) { // CakeContext.MDToolBuild (solution, c => { // c.Configuration = Configuration; // }); //} else { base.RunBuild(solution); //} }
public void Run() { CakeContext context = new CakeContext(); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var mainApplication = new ByTheCakeApp(); var appRouteConfig = new AppRouteConfig(); mainApplication.Configure(appRouteConfig); var webServer = new WebServer(1337, appRouteConfig); webServer.Run(); }
/// <summary> /// Goes thru CsProj files and if they have a AssemblyVersion attribute, updates it /// </summary> /// <remarks>Keeping version as a parameter instead of looking for the version argument as this is /// something that could be pulled out into a NuGet package at some point</remarks> public void UpdateFiles(string version, string projectPath, params string[] excludeProjectsNamed) { //We'll keep this around for dealing with Azure Functions as I think that has to be Full Framework //var assemblyInfoFiles = context.GetFiles($"{context.ProjectsPath}/**/properties/AssemblyInfo.cs"); var csprojFiles = CakeContext.GetFiles($"{projectPath}/**/*.csproj"); var excludeProjectsNamedLower = excludeProjectsNamed.Select(x => x.ToLowerInvariant()).ToArray(); foreach (var f in csprojFiles) { if (!excludeProjectsNamedLower.Contains(f.GetFilenameWithoutExtension().FullPath.ToLowerInvariant())) { UpdateCsProjFile(f, version); } } }
public CakeFixture() { var env = FakeEnvironment.CreateUnixEnvironment(); FileSystem = new FakeFileSystem(env); var globber = new Globber(FileSystem, env); var log = new NullLog(); var reg = new WindowsRegistry(); var config = new CakeConfiguration(new Dictionary <string, string>()); var strategy = new ToolResolutionStrategy(FileSystem, env, globber, config, log); var toolLocator = new ToolLocator(env, new ToolRepository(env), strategy); var cakeDataService = new FakeDataService(); var runner = new ProcessRunner(FileSystem, env, log, toolLocator, config); var args = new FakeArguments(); Context = new CakeContext(FileSystem, env, globber, log, args, runner, reg, toolLocator, cakeDataService, config); }
public static IScriptHost GetScriptHost() { var console = new CakeConsole(); ICakeLog log = new CakeBuildLog(console); IFileSystem fileSystem = new FileSystem(); ICakeDataService data = new BridgeDataService(); ICakeEnvironment environment = new CakeEnvironment( new CakePlatform(), new CakeRuntime(), log ); IGlobber globber = new Globber(fileSystem, environment); ICakeArguments arguments = new BridgeArguments(); ICakeConfiguration configuration = new BridgeConfiguration(); IToolLocator tools = new ToolLocator( environment, new ToolRepository(environment), new ToolResolutionStrategy( fileSystem, environment, globber, configuration ) ); ICakeContext context = new CakeContext( fileSystem, environment, globber, log, arguments, new ProcessRunner(fileSystem, environment, log, tools, configuration), new WindowsRegistry(), tools, data, configuration ); return(new BridgeScriptHost( new CakeEngine(data, log), context, new DefaultExecutionStrategy(log), new CakeReportPrinter(console, context), arguments )); }
public ToolFixtureResult Execute(Action <CakeContext> action) { var context = new CakeContext( FileSystem, Environment, Globber, Log, Substitute.For <ICakeArguments>(), ProcessRunner, Substitute.For <IRegistry>(), Tools, Substitute.For <ICakeDataService>() ); action(context); return(ProcessRunner.Results.LastOrDefault()); }
public FakeCakeContext() { WorkingDirectory = new DirectoryPath( System.IO.Path.GetFullPath( System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../"))); var environment = FakeEnvironment.CreateUnixEnvironment(false); var fileSystem = new FakeFileSystem(environment); var globber = new Globber(fileSystem, environment); _log = new FakeLog(); var args = new FakeCakeArguments(); var processRunner = new ProcessRunner(environment, _log); var registry = new WindowsRegistry(); CakeContext = new CakeContext( fileSystem, environment, globber, _log, args, processRunner, registry, new ToolLocator( environment, new ToolRepository(environment), new ToolResolutionStrategy( fileSystem, environment, globber, new FakeConfiguration() ) ) ); CakeContext.Environment.WorkingDirectory = WorkingDirectory; }
/// <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; }
public static void RequiredClass(CakeContext arg) { }
public static void OptionalClass(CakeContext arg = null) { }
/// <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); }
public OrderRepository(CakeContext context) { this.context = context; }
public CakeRepository(CakeContext context) { this.context = context; }
/// <summary> /// Runs the application. /// </summary> /// <param name="args">Arguments.</param> /// <param name="appRoot">Application root folder</param> /// <returns>The result of the run.</returns> public async Task <RunResult> RunAsync(IEnumerable <string> args, string appRoot = null) { var console = new CakeConsole(); var logger = new SafeCakeLog(console); ICakeDataService dataService = new CodeCakeDataService(); var engine = new CakeEngine(dataService, logger); ICakePlatform platform = new CakePlatform(); ICakeRuntime runtime = new CakeRuntime(); IFileSystem fileSystem = new FileSystem(); MutableCakeEnvironment environment = new MutableCakeEnvironment(platform, runtime, appRoot); console.SupportAnsiEscapeCodes = AnsiDetector.SupportsAnsi(environment); IGlobber globber = new Globber(fileSystem, environment); 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, logger); IToolLocator locator = new ToolLocator(environment, toolRepo, toolStrategy); IToolLocator toolLocator = new ToolLocator(environment, toolRepo, toolStrategy); IProcessRunner processRunner = new ProcessRunner(fileSystem, environment, logger, toolLocator, configuration); logger.SetVerbosity(options.Verbosity); ICakeArguments arguments = new CakeArguments(options.Arguments); var context = new CakeContext( fileSystem, environment, globber, logger, arguments, processRunner, windowsRegistry, locator, dataService, configuration); CodeCakeBuildTypeDescriptor choosenBuild; if (!AvailableBuilds.TryGetValue(options.Script, out choosenBuild)) { logger.Error("Build script '{0}' not found.", options.Script); return(new RunResult(-1, context.InteractiveMode())); } // Set the working directory: the solution directory. logger.Information($"Working in Solution directory: '{_solutionDirectory}'."); environment.WorkingDirectory = new DirectoryPath(_solutionDirectory); try { SetEnvironmentVariablesFromCodeCakeBuilderKeyVault(logger, context); // Instantiates the script object. CodeCakeHost._injectedActualHost = new BuildScriptHost(engine, context); CodeCakeHost c = (CodeCakeHost)Activator.CreateInstance(choosenBuild.Type); var target = context.Arguments.GetArgument("target") ?? "Default"; var execSettings = new ExecutionSettings().SetTarget(target); var exclusiveTargetOptional = context.Arguments.HasArgument("exclusiveOptional"); var exclusiveTarget = exclusiveTargetOptional | context.Arguments.HasArgument("exclusive"); var strategy = new CodeCakeExecutionStrategy(logger, exclusiveTarget ? target : null); if (exclusiveTargetOptional && !engine.Tasks.Any(t => t.Name == target)) { logger.Warning($"No task '{target}' defined. Since -exclusiveOptional is specified, nothing is done."); return(new RunResult(0, context.InteractiveMode())); } var report = await engine.RunTargetAsync(context, strategy, execSettings); 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(new RunResult(-2, context.InteractiveMode())); 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(new RunResult(-3, context.InteractiveMode())); } catch (AggregateException ex) { logger.Error("Error occurred: '{0}'.", ex.Message); foreach (var e in ex.InnerExceptions) { logger.Error(" -> '{0}'.", e.Message); } return(new RunResult(-4, context.InteractiveMode())); } catch (Exception ex) { logger.Error("Error occurred: '{0}'.", ex.Message); return(new RunResult(-5, context.InteractiveMode())); } return(new RunResult(0, context.InteractiveMode())); }
public CakeController() { this.dbContext = new CakeContext(); }
private static void SetEnvironmentVariablesFromCodeCakeBuilderKeyVault(SafeCakeLog logger, CakeContext context) { string filePath = "CodeCakeBuilder/CodeCakeBuilderKeyVault.txt"; if (System.IO.File.Exists(filePath)) { logger.Information("Reading environment variables from CodeCakeBuilderKeyVault.txt file."); string key = context.InteractiveEnvironmentVariable("CODECAKEBUILDER_SECRET_KEY", setCache: true); try { if (key != null) { var envVars = KeyVault.DecryptValues(System.IO.File.ReadAllText(filePath), key); foreach (var e in envVars) { if (Environment.GetEnvironmentVariable(e.Key) == null) { logger.Information($"Environment variable '{e.Key}' set from key vault."); Environment.SetEnvironmentVariable(e.Key, e.Value); } else { logger.Information($"Environment variable '{e.Key}' is already defined. Value from Key Vault is ignored."); } } } else { logger.Warning($"Environment variable CODECAKEBUILDER_SECRET_KEY is not set. Cannot open the Key Vault."); } } catch (Exception ex) { logger.Warning($"Error while reading key vault values: {ex.Message}."); } } else { logger.Information("No CodeCakeBuilder/CodeCakeBuilderKeyVault.txt file found."); } }
public HomeController(CakeContext context) { db = context; }