public void Retry(int numberOfRetries, TimeSpan timeBetweenRetries, Action <int> action) { var executionCount = 0; bool hasError; do { hasError = false; try { executionCount++; action.Invoke(executionCount); } catch (Exception ex) { hasError = true; AeroContext.Warning($"RetryExecution. Action: Exception, ExecutionCount: {executionCount}, {ex.ToLogString()}"); if (executionCount > numberOfRetries) { //Could be logged by the caller, otherwise it's output as an uncaught exception throw; } System.Threading.Thread.Sleep(timeBetweenRetries); } } while (executionCount <= numberOfRetries && hasError); }
public void Upgrade(string server, string database, string username, string password, string tenantId = null) { var csb = CreateSqlConnectionStringBuilder(server, database, username, password, tenantId); var connectionString = csb.ConnectionString; var usernameAudit = string.IsNullOrWhiteSpace(username) ? "IntegratedAuth" : username; AeroContext.Information($"Server: {csb.DataSource}, Database: {csb.InitialCatalog}, Username: {usernameAudit}"); var useAzureSecurity = false; if (!string.IsNullOrWhiteSpace(tenantId)) { //https://docs.microsoft.com/en-us/azure/key-vault/service-to-service-authentication#running-the-application-using-managed-identity useAzureSecurity = true; Environment.SetEnvironmentVariable("AzureServicesAuthConnectionString", $"RunAs=App;AppId={username};TenantId={tenantId};AppKey={password}"); } var upgrade = DeployChanges.To .SqlDatabase(connectionString, null, useAzureSecurity) .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly()) .LogTo(new CakeDbUpLogger(AeroContext)) .Build(); var result = upgrade.PerformUpgrade(); if (!result.Successful) { throw new Exception("Failed to updated database"); } }
public VersionModel ParseAppVersion(string appVersion) { AeroContext.Information($"VersionService.ParseAppVersion. Action: Start, AppVersion: {appVersion}"); var model = new VersionModel(); var match = new Regex(AppVersionRegEx).Match(appVersion); //Group 0 is the full match, 1-4 are the parts and 5 is the -preview if (!match.Success || match.Groups.Count < 4 || match.Groups.Count > 6) { AeroContext.Error($"VersionService.ParseAppVersion. Action: RegExFail, AppVersion: {appVersion}, GroupCount: {match.Groups?.Count}"); throw new Exception("AppVersion RegEx Failed"); } try { model.AssemblyVersion = new Version( Convert.ToInt32(match.Groups[1].Value), Convert.ToInt32(match.Groups[2].Value), Convert.ToInt32(match.Groups[3].Value), Convert.ToInt32(match.Groups[4].Value) ); } catch (Exception ex) { AeroContext.Error($"VersionService.ParseAppVersion. Action: VersionObjectCreationFailed, AppVersion: {appVersion}, {ex.ToLogString()}"); throw; } //If we have a valid regex and we successfully created a version object then we can just set the Version to the appVersion and it will //work for either 1.2.3.4 or 1.2.3.4-preview model.Version = appVersion; if (match.Groups.Count == 6 && !string.IsNullOrWhiteSpace(match.Groups[5].Value)) { var versionSuffix = $"{match.Groups[5]}.{model.AssemblyVersion.Revision}"; model.NuGetPackageVersion = $"{model.AssemblyVersion.Major}.{model.AssemblyVersion.Minor}.{model.AssemblyVersion.Build}{versionSuffix}"; //model.NuGetFileName = model.NuGetPackageVersion; } else { model.NuGetPackageVersion = $"{model.AssemblyVersion.Major}.{model.AssemblyVersion.Minor}.{model.AssemblyVersion.Build}+{model.AssemblyVersion.Revision}"; //model.NuGetFileName = $"{model.AssemblyVersion.Major}.{model.AssemblyVersion.Minor}.{model.AssemblyVersion.Build}"; } //With the release of one of the following, the fileName changed: .Net 6, VS2022, MSBUild 2022 model.NuGetFileName = appVersion; AeroContext.Information($"VersionService.ParseAppVersion. Action: Stop, AppVersion: {appVersion}, {model.ToLogString()}"); return(model); }
/// <summary> /// Execute a task which must complete in under a specified timeout period /// </summary> /// <param name="aeroContext"></param> /// <param name="action"></param> /// <param name="millisecondsTimeout"></param> /// <remarks> /// This code was adapted from https://devblogs.microsoft.com/pfxteam/crafting-a-task-timeoutafter-method/. It is /// a method of a self-completing action under a given time limit. It is expected that the action will loop /// within itself until its goal state is completed. One example is polling Azure for a particular status value. /// </remarks> public static async Task RetryUntilSuccessOrTimeout(this AeroContext aeroContext, Action action, int millisecondsTimeout) { var task = Task.Run(action); if (task == await Task.WhenAny(task, Task.Delay(millisecondsTimeout))) { await task; } else { throw new TimeoutException(); } }
public VersionModel ParseAppVersion() { //Accept a default value of empty string and then explicitly check so we can provide a better error message var appVersion = AeroContext.Argument(Cake.WellKnown.ArgumentNames.AppVersion, string.Empty); if (string.IsNullOrWhiteSpace(appVersion)) { AeroContext.Error($"VersionService.ParseAppVersion. Action: AppVersionNull, Message: This method requires a context with an argument named {nameof(Cake.WellKnown.ArgumentNames.AppVersion)}"); throw new Exception("AppVersion argument missing"); } return(ParseAppVersion(appVersion)); }
public void ZipDirectory(string sourceDirectoryPath, string destinationFileAndPath, bool deleteExisting = true) { AeroContext.Information($"FileService.ZipDirectory. Action: CreateArchive, Source: {sourceDirectoryPath}, Dest: {destinationFileAndPath}"); var zipFile = new System.IO.FileInfo(destinationFileAndPath); if (zipFile.Exists && deleteExisting) { AeroContext.Information($"FileService.ZipDirectory. Action: DeleteExistingZip, ZipFile: {destinationFileAndPath}"); zipFile.Delete(); } System.IO.Compression.ZipFile.CreateFromDirectory(sourceDirectoryPath, destinationFileAndPath); }
public void AddOrUpdateNuGetSource(string name, DotNetCoreNuGetSourceSettings settings) { var logPrefix = $"{nameof(NuGetService)}.{nameof(AddOrUpdateNuGetSource)}"; if (_dotNet.NuGetHasSource(name, settings)) { AeroContext.Information($"{logPrefix}, Action: UpdatingSource, Name: {name}"); _dotNet.NuGetUpdateSource(name, settings); } else { AeroContext.Information($"{logPrefix}, Action: AddingSource, Name: {name}"); _dotNet.NuGetAddSource(name, settings); } }
public ReservaController(AeroContext context) { _context = context; }
public string XmlPokeString(string sourceXml, string xpath, string value, XmlPokeSettings settings) { return(AeroContext.XmlPokeString(sourceXml, xpath, value, settings)); }
public string XmlPokeString(string sourceXml, string xpath, string value) { return(AeroContext.XmlPokeString(sourceXml, xpath, value)); }
public void XmlPoke(FilePath filePath, string xpath, string value, XmlPokeSettings settings) { AeroContext.XmlPoke(filePath, xpath, value, settings); }
public void XmlPoke(FilePath filePath, string xpath, string value) { AeroContext.XmlPoke(filePath, xpath, value); }
public string XmlPeek(FilePath filePath, string xpath, XmlPeekSettings settings) { return(AeroContext.XmlPeek(filePath, xpath, settings)); }
public void Pack(string projectPath, DotNetCorePackSettings settings) { AeroContext.DotNetCorePack(projectPath, settings); }
public bool NuGetHasSource(string name, DotNetCoreNuGetSourceSettings settings) { return(AeroContext.DotNetCoreNuGetHasSource(name, settings)); }
public DbUpService(AeroContext aeroContext) : base(aeroContext) { }
public VoosController(AeroContext context) { _context = context; }
public FilePath[] ReplaceTextInFiles(string globberPattern, string findText, string replaceText) { return(AeroContext.ReplaceTextInFiles(globberPattern, findText, replaceText)); }
public FilePath[] ReplaceTextInFile(IFile file, string findText, string replaceText) { return(AeroContext.ReplaceTextInFiles(file.Path.FullPath, findText, replaceText)); }
public void Test(string projectPath, DotNetCoreTestSettings settings) { AeroContext.DotNetCoreTest(projectPath, settings); }
public void Publish(string projectPath, DotNetCorePublishSettings settings) { AeroContext.DotNetCorePublish(projectPath, settings); }
public void NuGetUpdateSource(string name, DotNetCoreNuGetSourceSettings settings) { AeroContext.DotNetCoreNuGetUpdateSource(name, settings); }
public string XmlPeek(FilePath filePath, string xpath) { return(AeroContext.XmlPeek(filePath, xpath)); }
public void NuGetPush(string packageName, DotNetCoreNuGetPushSettings settings) { AeroContext.DotNetCoreNuGetPush(packageName, settings); }
public LocalController(AeroContext context) { _context = context; }
public void Build(string projectPath, DotNetCoreBuildSettings settings) { AeroContext.DotNetCoreBuild(projectPath, settings); }