public void Run(object sender, ITaskContext context) { if ((context.Data["Mode"] as string).ToLower() == "release") { const string BatTemplate = @"git commit -am ""Auto generated commit for version %v"" git tag -a %v -m ""Auto generated commit for version %v"" git push origin HEAD:master git push --tags origin"; var file = context.Data["WorkingDirectory"] as string; file = context.FileSystem.Path.Combine(file, "push.bat"); var outstr = BatTemplate.Replace("%v", (context.Data["NewVersion"] as Version).ToString()); context.FileSystem.File.WriteAllText(file, outstr); } else if ((context.Data["Mode"] as string).ToLower() == "test") { const string BatTemplate = @"git commit -am ""Auto generated commit for version %v"" git tag -a %v -m ""Auto generated commit for version %v"" git push origin HEAD:test git push --tags origin"; var file = context.Data["WorkingDirectory"] as string; file = context.FileSystem.Path.Combine(file, "push.bat"); var outstr = BatTemplate.Replace("%v", (context.Data["NewVersion"] as Version).ToString()); context.FileSystem.File.WriteAllText(file, outstr); } }
/// <summary> /// Implementation function for the execution. /// </summary> /// <param name="context">Verification context.</param> /// <returns>A task that represents the completion of this execution.</returns> protected override async Task ExecuteInternalAsync(ITaskContext context) { using (var connection = this.connectionFactory.CreateConnection()) { connection.Open(); var command = connection.CreateCommand(); command.CommandText = this.commandText; var asyncCommand = command as DbCommand; if (asyncCommand == null) { // This command doesn't support asynchronous execution // so we will tie up this thread executing normally. // In this instance it is OK because there is no // message pump that we need to return control to. command.ExecuteNonQuery(); } else { await asyncCommand.ExecuteNonQueryAsync(context.CancellationToken); } } }
/// <summary> /// Implementation function for the execution. /// </summary> /// <param name="context">Execution context.</param> /// <returns>A task that represents the completion of this execution.</returns> protected override async Task ExecuteInternalAsync(ITaskContext context) { this.ExecuteWasCalled = true; if (this.ExecuteFunction != null) { await this.ExecuteFunction(context); } }
/// <summary> /// Implementation function for the execution. /// </summary> /// <param name="context">Verification context.</param> /// <returns>A task that represents the completion of this execution.</returns> protected override async Task ExecuteInternalAsync(ITaskContext context) { foreach (var task in this.Tasks) { context.CancellationToken.ThrowIfCancellationRequested(); await task.ExecuteAsync(context); } }
/// <summary> /// Implementation function for the execution. /// </summary> /// <param name="context">Verification context.</param> /// <returns>A task that represents the completion of this execution.</returns> protected override async Task ExecuteInternalAsync(ITaskContext context) { var waits = new List<Task>(); foreach (var task in this.Tasks) { context.CancellationToken.ThrowIfCancellationRequested(); waits.Add(Task.Run(() => task.ExecuteAsync(context), context.CancellationToken)); } await Task.WhenAll(waits); }
/// <summary> /// Initializes a new instance of the <see cref="CsvBulkRepositoryFacts"/> class. /// </summary> public CsvBulkRepositoryFacts() { this.fixture = new Fixture(); this.outputWriter = new StringWriter(CultureInfo.CurrentCulture); this.target = new CsvBulkRepository<FakeEntity>( TestFileName, new CsvConfiguration(), f => this.outputWriter); this.data = this.fixture.CreateMany<FakeEntity>(); this.context = Substitute.For<ITaskContext>(); }
/// <summary> /// Implementation function for the verification. /// </summary> /// <param name="context">Verification context.</param> /// <returns>A task that represents the completion of this verification.</returns> protected override async Task VerifyInternalAsync(ITaskContext context) { await base.VerifyInternalAsync(context); var waits = new List<Task>(); foreach (var task in this.Tasks) { context.CancellationToken.ThrowIfCancellationRequested(); waits.Add(task.VerifyAsync(context)); } await Task.WhenAll(waits); }
public void Run(object sender, ITaskContext context) { Log.Info("Updating changelog from recentchanges"); var workingDirectory = context.Data["WorkingDirectory"] as string; var newVersion = (context.Data["NewVersion"] as Version).ToString(); var mode = (context.Data["Mode"] as string).ToLower(); var changeLogFilename = Path.Combine(workingDirectory, "CHANGELOG.md"); var recentChangesFilename = Path.Combine(workingDirectory, "recentchanges.txt"); Log.InfoFormat("Changelog Filename {0}", changeLogFilename); Log.InfoFormat("Recent Changes Filename {0}", recentChangesFilename); var clLines = File.ReadAllLines(changeLogFilename); var outArr = new List<string>(); if (mode == "release") { outArr.Add("#" + newVersion); } else if (mode == "test") { outArr.Add("#" + newVersion + " - Test"); } var changeLines = File.ReadAllLines(recentChangesFilename); foreach (var l in changeLines) { outArr.Add("+ " + l); } outArr.Add(""); outArr.AddRange(clLines); File.WriteAllLines(changeLogFilename,outArr); if (mode == "release") { using (var file = File.Open(recentChangesFilename, FileMode.Truncate, FileAccess.Write, FileShare.None)) { file.Flush(true); file.Close(); } } }
public static IDictionary<string, string> GetAllVariables(ITaskContext context, bool isSafe = false) { IVariableService ivariableService = (IVariableService)((IServiceManager)context).GetService<IVariableService>(); IDictionary<string, string> dictionary = new Dictionary<string, string>(); if (ivariableService != null) { if (!isSafe) ivariableService.MergeVariables(dictionary); else { ivariableService.MergeSafeVariables(dictionary); } } return dictionary; }
/// <summary> /// Initializes a new instance of the <see cref="SimpleDataflowTaskFacts"/> class. /// </summary> public SimpleDataflowTaskFacts() { this.fixture = new Fixture(); this.source = this.fixture.CreateMany<FakeEntity>(); this.repository = Substitute.For<IBulkRepository<FakeEntity>>(); this.context = Substitute.For<ITaskContext>(); this.repository.BulkCopyAsync( Arg.Do<IEnumerable<FakeEntity>>(a => this.data = a), Arg.Any<ITaskContext>()); this.dataflow = new SimpleDataflowTask<FakeEntity, FakeEntity>( this.source, MappingFunctions.Identity, this.repository); }
public virtual string[] GetUpdateFiles(ITaskContext context) { var list = new List<String>(); list.Add(this.CreateUpdateString(context,"currentversion.txt")); list.Add(this.CreateUpdateString(context,"nuget\\Octgn.Library.nuspec")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.Core\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.DataNew\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.DeckBuilderPluginExample\\DeckBuilderPluginExample.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.Library\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.ProxyGenerator\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.Server\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.Test\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.LobbyServer\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.ReleasePusher\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.StandAloneServer\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.Online.Client\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.Online.Data\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.Online.GameService\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.Online.Library\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.Online.SASManagerService\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.Online.StandAloneServer\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.Online.Test\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Skylabs.Lobby\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Skylabs.LobbyServer\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\o8build\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn.Tools.Proxytest\\Properties\\AssemblyInfo.cs")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn\\CurrentVersion.txt")); if ((context.Data["Mode"] as string).ToLower() == "release") { list.Add(this.CreateUpdateString(context, "deploy\\currentversion.txt")); list.Add(this.CreateUpdateString(context, "installer\\Install.nsi")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn\\CurrentReleaseVersion.txt")); } else if ((context.Data["Mode"] as string).ToLower() == "test") { list.Add(this.CreateUpdateString(context, "deploy\\currentversiontest.txt")); list.Add(this.CreateUpdateString(context, "installer\\InstallTest.nsi")); list.Add(this.CreateUpdateString(context, "octgnFX\\Octgn\\CurrentTestVersion.txt")); } else { throw new InvalidOperationException("Mode must be set to release or test"); } return list.ToArray(); }
public void Run(object sender, ITaskContext context) { context.Log.Info("Reading Data Settings"); var rootPath = context.Data["WorkingDirectory"] as string; var currentVersionFileRelativePath = context.Data["CurrentVersionFileRelativePath"] as string; var fullPath = context.FileSystem.Path.Combine(rootPath, currentVersionFileRelativePath); context.Log.InfoFormat("Reading {0}",fullPath); var versionText = context.FileSystem.File.ReadAllText(fullPath); context.Log.InfoFormat("Formatting {0} into System.Version type.",versionText); var currentVersion = ParseVersion(versionText); context.Log.InfoFormat("Setting CurrentVersion: {0}",currentVersion); context.Data["CurrentVersion"] = currentVersion; }
public void Run(object sender, ITaskContext context) { context.Log.Info("Running"); var filesToIgnore = this.GetIgnoreFiles(context,context.Data["ReplaceVersionIgnoreFile"] as string); var workingDirectory = context.Data["WorkingDirectory"] as string; var currentVersion = (context.Data["CurrentVersion"] as Version).ToString(); var newVersion = (context.Data["NewVersion"] as Version).ToString(); var files = context.FileSystem.Directory .GetFiles(workingDirectory, "*", SearchOption.AllDirectories) .Select(x=>new FileInfoWrapper(new FileInfo(x))); foreach (var f in files ) { this.ProcessFile(context,f,filesToIgnore,currentVersion,newVersion); } }
public void Run(object sender, ITaskContext context) { if ((context.Data["Mode"] as string).ToLower() == "test") { var version = context.Data["CurrentVersion"] as Version; context.Log.InfoFormat("Current version: {0}", version); context.Data["NewVersion"] = new Version( version.Major, version.Minor, version.Build, version.Revision + 1); context.Log.InfoFormat("New Version: {0}", context.Data["NewVersion"] as Version); } else if ((context.Data["Mode"] as string).ToLower() == "release") { var version = context.Data["CurrentVersion"] as Version; context.Log.InfoFormat("Current version: {0}", version); context.Data["NewVersion"] = new Version( version.Major, version.Minor, version.Build + 1, version.Revision); context.Log.InfoFormat("New Version: {0}", context.Data["NewVersion"] as Version); } }
public void Run(object sender, ITaskContext context) { context.Log.Info("Running"); var workingDirectory = context.Data["WorkingDirectory"] as string; var currentVersion = (context.Data["CurrentVersion"] as Version).ToString(); var currentReleaseVersion = (context.Data["CurrentReleaseVersion"] as Version).ToString(); var currentTestVersion = (context.Data["CurrentTestVersion"] as Version).ToString(); var newVersion = (context.Data["NewVersion"] as Version).ToString(); var files = context.FileSystem.Directory .GetFiles(workingDirectory, "*", SearchOption.AllDirectories) .Select(x=>new FileInfoWrapper(new FileInfo(x))) .Where(x=> this.GetUpdateFiles(context).Contains(x.FullName,StringComparer.InvariantCultureIgnoreCase)); foreach (var f in files ) { this.ProcessFile(context, f, currentVersion, currentReleaseVersion, currentTestVersion,newVersion); } }
/// <summary> /// Implementation function for the execution. /// </summary> /// <remarks>This function is not asynchronous.</remarks> /// <param name="context">Verification context.</param> /// <returns>A task that represents the completion of this execution.</returns> protected override Task ExecuteInternalAsync(ITaskContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (context.CancellationToken == null) { throw new ArgumentException("context argument must contain a valid cancellation token", "context"); } this.startInfo.ErrorDialog = false; var process = Process.Start(this.startInfo); process.EnableRaisingEvents = true; // I don't see any harm in polling here since we are already executing // on the thread pool and its a good time to report process. while (!process.WaitForExit(DefaultProcessPollPeriod)) { string message = string.Format( CultureInfo.CurrentCulture, Properties.Resources.ReportProcessProgressFormat, this.startInfo.FileName, process.TotalProcessorTime); context.Log.ReportProgress(this, message, 50); if (context.CancellationToken.IsCancellationRequested) { process.Kill(); context.CancellationToken.ThrowIfCancellationRequested(); } } return TaskBase.Complete; }
public virtual void ProcessFile(ITaskContext context, FileInfoBase file, string currentVersion, string currentReleaseVersion, string currentTestVersion, string newVersion) { var rel = file.FullName.Replace(context.Data["WorkingDirectory"] as string, "").TrimStart('/', '\\'); // Read the whole file. context.Log.InfoFormat("Reading file {0}",file.FullName); var text = context.FileSystem.File.ReadAllText(file.FullName); // Return if the file contents don't contain the version number var mode = (context.Data["Mode"] as string).ToLower(); switch (mode) { case "release": if (!text.Contains(currentVersion) && !text.Contains(currentReleaseVersion)) return; break; case "test": if (!text.Contains(currentVersion) && !text.Contains(currentTestVersion)) return; break; } context.Log.InfoFormat("Replacing version number in file {0}",file.FullName); // Replace all occurrences of the oldVersion with the newVersion text = text.Replace(currentVersion, newVersion); switch (mode) { case "release": text = text.Replace(currentReleaseVersion, newVersion); break; case "test": text = text.Replace(currentTestVersion, newVersion); break; } context.Log.InfoFormat("Writing file {0}",file.FullName); // Write the new file to the file system. context.FileSystem.File.WriteAllText(file.FullName, text); }
public virtual void ProcessFile(ITaskContext context, FileInfoBase file, string[] filesToIgnore, string currentVersion, string newVersion) { // Should we ignore this? if (filesToIgnore.Contains(file.Name)) return; if (file.Extension.ToLower() == ".exe" || file.Extension.ToLower() == "*.dll") return; var rel = file.FullName.Replace(context.Data["WorkingDirectory"] as string, "").TrimStart('/', '\\'); if (rel.StartsWith(".git") || file.FullName.Contains("packages")) return; if ((context.Data["Mode"] as string).ToLower() == "test") if (rel == "deploy\\currentversion.txt") return; // Read the whole file. context.Log.InfoFormat("Reading file {0}",file.FullName); var text = context.FileSystem.File.ReadAllText(file.FullName); // Return if the file contents don't contain the version number if (!text.Contains(currentVersion)) return; context.Log.InfoFormat("Replacing version number in file {0}",file.FullName); // Replace all occurrences of the oldVersion with the newVersion text = text.Replace(currentVersion, newVersion); context.Log.InfoFormat("Writing file {0}",file.FullName); // Write the new file to the file system. context.FileSystem.File.WriteAllText(file.FullName, text); }
public virtual bool ValidateConfiguration(ITaskContext taskContext) { this.TaskContext = taskContext; return(true); }
public QueryDecorator(ITaskContext taskContext) { this.TaskContext = taskContext; }
public virtual bool NeedsConfiguration(ITaskContext taskContext) { this.TaskContext = taskContext; return(false); }
public TaskController(ITaskContext context) { _taskMgr = new TaskManager(context); }
private void SomeMethodName(ITaskContext context) { }
internal virtual string CreateUpdateString(ITaskContext context, string relativePath) { return context.FileSystem.Path.Combine(context.Data["WorkingDirectory"] as string, relativePath); }
/// <summary> /// Executes the task synchronously. /// </summary> /// <remarks>The default implementation just calls <c>ExecuteAsync</c> and waits for the call to complete.</remarks> /// <param name="context">Execution context.</param> public void Execute(ITaskContext context) { if (context == null) { throw new ArgumentNullException("context"); } this.ExecuteAsync(context).Wait(context.CancellationToken); }
public TaskProvider(ITaskContext context) { _context = context; }
protected override void DoExecute(ITaskContext context) { FullPath packagesDir = new FullPath(context.Properties.Get(BuildProps.ProductRootDir, ".")); packagesDir = packagesDir.CombineWith(context.Properties.Get <string> (BuildProps.BuildDir)); FileFullPath destNuspecFile = packagesDir.AddFileName("{0}.nuspec", packageId); context.WriteInfo("Preparing the {0} file", destNuspecFile); ReplaceTokensTask task = new ReplaceTokensTask( nuspecFileName, destNuspecFile.ToString()); task.AddTokenValue("version", context.Properties.Get <Version> (BuildProps.BuildVersion).ToString()); task.Execute(context); // package it context.WriteInfo("Creating a NuGet package file"); string nugetWorkingDir = destNuspecFile.Directory.ToString(); NuGetCmdLineTask nugetTask = new NuGetCmdLineTask("pack", nugetWorkingDir); nugetTask .AddArgument(destNuspecFile.FileName); nugetTask.AddVerbosityArgument(NuGetCmdLineTask.NuGetVerbosity.Detailed); if (BasePath != null) { nugetTask.AddArgument("-BasePath").AddArgument(BasePath); } nugetTask.Execute(context); string nupkgFileName = ConstructNupkgFileName(context); context.WriteInfo("NuGet package file {0} created", nupkgFileName); // do not push new packages from a local build if (context.IsInteractive && !AllowPushOnInteractiveBuild) { return; } if (apiKeyFunc == null) { throw new InvalidOperationException("NuGet API key was not provided"); } string apiKey = apiKeyFunc(context); if (apiKey == null) { context.WriteInfo("API key function returned null, skipping pushing of the NuGet package."); return; } // publish the package file context.WriteInfo("Pushing the NuGet package to the repository"); nugetTask = new NuGetCmdLineTask("push", nugetWorkingDir); nugetTask .AddArgument(nupkgFileName) .AddArgument(apiKey) .AddArgument("-Source").AddArgument(nuGetServerUrl) .AddVerbosityArgument(NuGetCmdLineTask.NuGetVerbosity.Detailed); nugetTask .Execute(context); }
public void Run(object sender, ITaskContext context) { this.GetCurrentVersion(context); this.GetCurrentReleaseVersion(context); this.GetCurrentTestVersion(context); }
protected abstract void ConfigureTargets(ITaskContext context);
public static bool IsRoot <TContext>(ITaskContext <TContext> taskContext) { var isRoot = taskContext.Parent == TaskContext <TContext> .RootTaskContextParent; return(isRoot); }
// // GET: /Task/ public TaskController(ITaskContext taskContext) { _context = taskContext; }
private void TaskDelay200(ITaskContext context) { System.Threading.Thread.Sleep(200); m_testVariable = 82; }
public TasksController(ITaskContext tasksList) { _tasksList = tasksList; }
private void TaskNOP(ITaskContext context) { }
protected internal abstract void LogTaskHelp(ITaskContext context);
/// <summary> /// Helper function to increment and decrement a counter. /// </summary> /// <param name="context">Execution context.</param> /// <returns>A task that represents the completion of this execution.</returns> private async Task TaskCounterFunction(ITaskContext context) { Interlocked.Increment(ref this.executingCount); Interlocked.CompareExchange(ref this.maxExecuting, this.executingCount, this.executingCount - 1); // This Yield function must remain as we need to give other tasks // the chance to start executing, hence the possibility of incorrectly // running in parallel which will be tested for. await Task.Yield(); Interlocked.Decrement(ref this.executingCount); }
public static string GetEnvironmentVariable(this ITaskContext context, string variable) { return(Environment.GetEnvironmentVariable(variable)); }
/// <summary> /// Implementation function for the execution. /// </summary> /// <param name="context">Verification context.</param> /// <returns>A task that represents the completion of this execution.</returns> protected override async Task ExecuteInternalAsync(ITaskContext context) { await this.action(); }
private static void TargetPackage(ITaskContext context) { FullPath packagesDir = new FullPath(context.Properties.Get(BuildProps.ProductRootDir, ".")); packagesDir = packagesDir.CombineWith(context.Properties.Get<string>(BuildProps.BuildDir)); FullPath simplexPackageDir = packagesDir.CombineWith("Detergent"); FileFullPath zipFileName = packagesDir.AddFileName( "Detergent-{0}.zip", context.Properties.Get<Version>(BuildProps.BuildVersion)); StandardPackageDef packageDef = new StandardPackageDef("Detergent", context); VSSolution solution = context.Properties.Get<VSSolution>(BuildProps.Solution); VSProjectWithFileInfo projectInfo = (VSProjectWithFileInfo)solution.FindProjectByName("Detergent"); LocalPath projectOutputPath = projectInfo.GetProjectOutputPath( context.Properties.Get<string>(BuildProps.BuildConfiguration)); FullPath projectTargetDir = projectInfo.ProjectDirectoryPath.CombineWith(projectOutputPath); packageDef.AddFolderSource( "bin", projectTargetDir, false); ICopier copier = new Copier(context); CopyProcessor copyProcessor = new CopyProcessor( context, copier, simplexPackageDir); copyProcessor .AddTransformation("bin", new LocalPath(string.Empty)); IPackageDef copiedPackageDef = copyProcessor.Process(packageDef); Zipper zipper = new Zipper(context); ZipProcessor zipProcessor = new ZipProcessor( context, zipper, zipFileName, simplexPackageDir, null, "bin"); zipProcessor.Process(copiedPackageDef); }
/// <summary> /// Initializes a new instance of the <see cref="SqlBulkRepositoryFacts"/> class. /// </summary> public SqlBulkRepositoryFacts() { this.fixture = new Fixture(); this.bulkCopy = Substitute.For<IBulkCopy>(); this.connectionFactory = Substitute.For<IDbConnectionFactory>(); this.columnMappings = new Dictionary<string, string>() { { "Id", "Id" }, { "Name", "Name" }, { "Created", "Created" } }; this.bulkRepository = new SqlBulkRepository<FakeEntity>( (c, o) => this.bulkCopy, TestTableName, this.connectionFactory, this.columnMappings); this.data = this.fixture.CreateMany<FakeEntity>(); this.context = Substitute.For<ITaskContext>(); }
/// <summary> /// Local git repository information. /// </summary> /// <param name="context"></param> /// <returns></returns> public static Git Git(this ITaskContext context) { return(new Git(context)); }
internal virtual string CreateUpdateString(ITaskContext context, string relativePath) { return(context.FileSystem.Path.Combine(context.Data["WorkingDirectory"] as string, relativePath)); }
protected override void ConfigureTargets(ITaskContext session) { }
public virtual bool CheckPrereqs(ITaskContext taskContext) { this.TaskContext = taskContext; return(true); }
protected abstract TaskOutput Execute(TaskInput input, ITaskContext context);
public virtual bool Configure(ITaskContext taskContext) { this.TaskContext = taskContext; return(true); }
public void SuccesfullTarget(ITaskContext session, string fileName) { File.Create(fileName); }
public override object Execute(List <PersistableObject> objs, ITaskContext context) { return(base.Execute(objs, context)); }
public void FailedTarget(ITaskContext session) { throw new TaskExecutionException("Error message", 5); }
private void TaskAdd17(ITaskContext context) { System.Threading.Thread.Sleep(1); m_testVariable += 17; }
public TaskRepository(ITaskContext taskContext) { _taskContext = taskContext; }
private static void TargetNuGet(ITaskContext context, string nugetId) { FullPath packagesDir = new FullPath(context.Properties.Get(BuildProps.ProductRootDir, ".")); packagesDir = packagesDir.CombineWith(context.Properties.Get<string>(BuildProps.BuildDir)); string sourceNuspecFile = string.Format( CultureInfo.InvariantCulture, @"{0}\{0}.nuspec", nugetId); FileFullPath destNuspecFile = packagesDir.AddFileName("{0}.nuspec", nugetId); context.WriteInfo("Preparing the {0} file", destNuspecFile); ExpandPropertiesTask task = new ExpandPropertiesTask( sourceNuspecFile, destNuspecFile.ToString(), Encoding.UTF8, Encoding.UTF8); task.AddPropertyToExpand("version", context.Properties.Get<Version>(BuildProps.BuildVersion).ToString()); task.Execute(context); // package it context.WriteInfo("Creating a NuGet package file"); RunProgramTask progTask = new RunProgramTask(@"lib\NuGet\NuGet.exe"); progTask.SetWorkingDir(destNuspecFile.Directory.ToString()); progTask .AddArgument("pack") .AddArgument(destNuspecFile.FileName) .AddArgument("-Verbose") .Execute(context); string nupkgFileName = string.Format( CultureInfo.InvariantCulture, "{0}.{1}.nupkg", nugetId, context.Properties.Get<Version>(BuildProps.BuildVersion)); context.WriteInfo("NuGet package file {0} created", nupkgFileName); string apiKeyFileName = "NuGet API key.txt"; if (!File.Exists(apiKeyFileName)) { context.WriteInfo("'NuGet API key.txt' does not exist, cannot publish the package."); return; } string apiKey = File.ReadAllText(apiKeyFileName); // publish the package file context.WriteInfo("Pushing the NuGet package to the repository"); progTask = new RunProgramTask(@"lib\NuGet\NuGet.exe"); progTask.SetWorkingDir(destNuspecFile.Directory.ToString()); progTask .AddArgument("push") .AddArgument(nupkgFileName) .AddArgument(apiKey) .AddArgument("-Source") .AddArgument("http://packages.nuget.org/v1/") .Execute(context); }
protected override TaskOutput Execute(TaskInput input, ITaskContext context) { var channelFilesDictionary = new Dictionary <string, List <TaskFile> >(); foreach (var file in input.Files) { if (file.Params.ContainsKey(_printChannelKey)) { var channal = file.Params[_printChannelKey]; if (!channelFilesDictionary.ContainsKey(channal)) { channelFilesDictionary[channal] = new List <TaskFile>(); } channelFilesDictionary[channal].Add(file); } } var outputFiles = new List <TaskFile>(); foreach (var channelFiles in channelFilesDictionary) { var channel = channelFiles.Key; Logger.Info("Found {0} files for {1} channel", channelFiles.Value.Count, channel); var @params = new Dictionary <string, string>(context.CommonParams); if ([email protected](_printChannelKey)) { @params.Add(_printChannelKey, channel); } var miscDirectoryPath = GetMiscDirectoryPath(context.WorkingDirectory, @params); var filesDirectoryPath = GetFilesDirectoryPath(context.WorkingDirectory, @params); Logger.Info("dpof FILES directory path: {0}", Path.GetFullPath(filesDirectoryPath)); Logger.Info("dpof MISC directory path: {0}", Path.GetFullPath(miscDirectoryPath)); var printFiles = new List <PrintFileInfo>(); foreach (var file in channelFiles.Value) { var sourceFile = new FileInfo(file.Path); var fileName = string.Format("{0}{1}", Path.GetFileNameWithoutExtension(file.Path).Unidecode().Trim(), sourceFile.Extension).Replace(" ", "_"); var newPath = Path.Combine(filesDirectoryPath, fileName); if (File.Exists(newPath)) { Logger.Warn("warning: file exists ({0})", Path.GetFullPath(newPath)); var newName = Path.GetFileNameWithoutExtension(newPath); var fi = new FileInfo(newPath); var dirPath = fi.DirectoryName; var i = 1; while (i < 99) { newName = string.Format("{0}_{1}{2}", newName, i, fi.Extension); var path = Path.Combine(dirPath, newName); if (!File.Exists(path)) { newPath = path; break; } i++; } Logger.Warn("new file path is: {0}", Path.GetFullPath(newPath)); File.Copy(file.Path, newPath, true); } else { File.Copy(sourceFile.FullName, newPath, false); } Logger.Info("file copy: {0} to {1}", Path.GetFullPath(sourceFile.FullName), newPath); printFiles.Add(new PrintFileInfo() { CopyCount = int.Parse(file.Params[_copyCountKey]), FilePath = newPath }); outputFiles.Add(new TaskFile(newPath, file.Params)); } var paperSize = channelFiles.Value.First().Params[_paperSizeKey]; var doc = new NoritsuDpofDocument(miscDirectoryPath, printFiles, paperSize, int.Parse(channel)); var result = doc.GetRenderedFilesPath(); foreach (var filePath in result) { Logger.Info("dpof result file: {0}", Path.GetFullPath(filePath)); outputFiles.Add(new TaskFile(filePath, null)); } } return(new TaskOutput(outputFiles)); }
private static void TargetFetchBuildVersion(ITaskContext context) { Version version = BuildTargets.FetchBuildVersionFromFile(context); context.Properties.Set(BuildProps.BuildVersion, version); context.WriteInfo("The build version will be {0}", version); }
protected override void ConfigureTargets(ITaskContext session) { session.CreateTarget("Test").AddTask(x => x.CompileSolutionTask()); }
/// <summary> /// Implementation function for the execution. /// </summary> /// <param name="context">Verification context.</param> /// <returns>A task that represents the completion of this execution.</returns> protected override Task ExecuteInternalAsync(ITaskContext context) { this.action(); return Task.FromResult<int>(0); }
public void DeployWebApi(ITaskContext context) { DeploymentConfig config = null; var json = File.ReadAllText("DeploymentConfig.json"); config = JsonConvert.DeserializeObject <DeploymentConfig>(json); ValidateDeploymentConfig(config); string connectionString; if (!string.IsNullOrWhiteSpace(config.LiteDbConnectionString)) { connectionString = config.LiteDbConnectionString; } else { var liteDbPassword = GenerateRandomSecureString(15); connectionString = $"FileName=database.db; Password={liteDbPassword}"; } bool createDb = false; var dbFileName = Files.GetFileNameFromConnectionString(connectionString); var isPathRooted = Path.IsPathRooted(dbFileName); if (!config.IsUpdate) { if (config.RecreateDatabase) { createDb = true; } else { if (isPathRooted) { if (!File.Exists(dbFileName)) { createDb = true; } } else { var dbPath = Path.Combine(config.DeploymentPath, dbFileName); if (!File.Exists(dbPath)) { createDb = true; } } } if (createDb) { File.Delete(dbFileName); using (var db = new LiteRepository(connectionString)) { IUserRepository repository = new UserRepository(db); var hashService = new HashService(); repository.AddUser(new User { Username = config.Username, Password = hashService.Hash(config.Password), }); } if (!isPathRooted) { var outputDbFilePath = Path.Combine("FlubuCore.WebApi", dbFileName); context.Tasks().CopyFileTask(dbFileName, outputDbFilePath, true) .Execute(context); } } else { ////Delete old db file if it exists so it doesnt rewrite database at deployed location. var outputDbFilePath = Path.Combine("FlubuCore.WebApi", dbFileName); if (File.Exists(outputDbFilePath)) { File.Delete(outputDbFilePath); } } context.Tasks().UpdateJsonFileTask(@".\FlubuCore.WebApi\appsettings.json") .Update(new KeyValuePair <string, JValue>("FlubuConnectionStrings.LiteDbConnectionString", new JValue(connectionString))).Execute(context); context.Tasks().UpdateJsonFileTask(@".\FlubuCore.WebApi\appsettings.json") .Update(new KeyValuePair <string, JValue>("WebApiSettings.AllowScriptUpload", new JValue(config.AllowScriptUpload))).Execute(context); context.Tasks().UpdateJsonFileTask(@".\FlubuCore.WebApi\appsettings.json") .Update("JwtOptions.SecretKey", GenerateRandomString(30)).Execute(context); context.Tasks().CreateDirectoryTask(config.DeploymentPath + "\\Packages", false).Execute(context); context.Tasks().CreateDirectoryTask(config.DeploymentPath + "\\Scripts", false).Execute(context); } else { ////Delete old db file if it exists so it doesnt rewrite database at deployed location. var outputDbFilePath = Path.Combine("FlubuCore.WebApi", dbFileName); if (File.Exists(outputDbFilePath)) { File.Delete(outputDbFilePath); } if (File.Exists("FlubuCore.WebApi/appsettings.json")) { File.Delete("FlubuCore.WebApi/appsettings.json"); } if (File.Exists("FlubuCore.WebApi/web.config")) { File.Delete("FlubuCore.WebApi/web.config"); } } context.Tasks().CopyDirectoryStructureTask("FlubuCore.Webapi", config.DeploymentPath, true).Execute(context); }
public static FileFullPath OutputDirectory(this ITaskContext context) { return(context.GetRootDirectory().AddFileName(context.Properties.GetOutputDir())); }
/// <summary> /// Implementation function for the verification. /// </summary> /// <param name="context">Verification context.</param> /// <returns>A task that represents the completion of this verification.</returns> protected override async Task VerifyInternalAsync(ITaskContext context) { this.VerifyWasCalled = true; if (this.VerifyFunction != null) { await this.VerifyFunction(context); } }