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); }
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); } }