static private GetPackage ( IDbExecutor dbExecutor, string id, string version ) : |
||
dbExecutor | IDbExecutor | |
id | string | |
version | string | |
return |
public override void ExecuteCommand() { using (var sqlConnection = new SqlConnection(ConnectionString.ConnectionString)) using (var dbExecutor = new SqlExecutor(sqlConnection)) { sqlConnection.Open(); var package = Util.GetPackage( dbExecutor, PackageId, PackageVersion); if (package == null) { Log.Error("Package version does not exist: '{0}.{1}'", PackageId, PackageVersion); return; } Log.Info( "Deleting package data for '{0}.{1}'", package.Id, package.Version); if (!WhatIf) { dbExecutor.Execute( "DELETE pa FROM PackageAuthors pa JOIN Packages p ON p.[Key] = pa.PackageKey WHERE p.[Key] = @key", new { key = package.Key }); dbExecutor.Execute( "DELETE pd FROM PackageDependencies pd JOIN Packages p ON p.[Key] = pd.PackageKey WHERE p.[Key] = @key", new { key = package.Key }); dbExecutor.Execute( "DELETE ps FROM PackageStatistics ps JOIN Packages p ON p.[Key] = ps.PackageKey WHERE p.[Key] = @key", new { key = package.Key }); dbExecutor.Execute( "DELETE pf FROM PackageFrameworks pf JOIN Packages p ON p.[Key] = pf.Package_Key WHERE p.[Key] = @key", new { key = package.Key }); dbExecutor.Execute( "DELETE p FROM Packages p JOIN PackageRegistrations pr ON pr.[Key] = p.PackageRegistrationKey WHERE p.[Key] = @key", new { key = package.Key }); } new DeletePackageFileTask { StorageAccount = StorageAccount, PackageId = package.Id, PackageVersion = package.Version, PackageHash = package.Hash, WhatIf = WhatIf }.ExecuteCommand(); } }
public override void ExecuteCommand() { using (var sqlConnection = new SqlConnection(ConnectionString.ConnectionString)) using (var dbExecutor = new SqlExecutor(sqlConnection)) { sqlConnection.Open(); var package = Util.GetPackage( dbExecutor, PackageId, PackageVersion); if (package == null) { Log.Info("Package '{0}.{1}' does not exist; exiting."); return; } new BackupPackageFileTask { StorageAccount = StorageAccount, PackageId = package.Id, PackageVersion = package.Version, PackageHash = package.Hash }.ExecuteCommand(); var hash = Util.GenerateHash(ReplacementFile.AsSeekableStream()); Log.Info("Updating hash for package '{0}.{1}' to '{2}'", package.Id, package.Version, hash); dbExecutor.Execute( "UPDATE Packages SET Hash = @hash WHERE [Key] = @key", new { @key = package.Key, hash }); Log.Info("Uploading replacement file for package '{0}.{1}'", package.Id, package.Version); ReplacementFile.Position = 0; new UploadPackageTask { StorageAccount = StorageAccount, PackageId = package.Id, PackageVersion = package.Version, PackageFile = ReplacementFile }.ExecuteCommand(); } }
public override void ExecuteCommand() { using (var sqlConnection = new SqlConnection(ConnectionString.ConnectionString)) using (var dbExecutor = new SqlExecutor(sqlConnection)) { sqlConnection.Open(); var package = Util.GetPackage( dbExecutor, PackageId, PackageVersion); // Multiple queries? Yes. Do I care? No. var packageRecord = new DataTable(); using (SqlCommand cmd = sqlConnection.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM Packages WHERE [Key] = @key"; cmd.Parameters.AddWithValue("@key", package.Key); var result = cmd.ExecuteReader(); packageRecord.Load(result); } var registrationRecord = new DataTable(); using (SqlCommand cmd = sqlConnection.CreateCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = "SELECT * FROM PackageRegistrations WHERE [ID] = @id"; cmd.Parameters.AddWithValue("@id", package.Id); var result = cmd.ExecuteReader(); registrationRecord.Load(result); } // Write a delete audit record var auditRecord = new PackageAuditRecord( package, packageRecord, registrationRecord, PackageAuditAction.Deleted, Reason, AuditEnvironment.GetCurrent()); string recordName = Util.GetPackageAuditBlobName(package.Id, package.Version, PackageAuditAction.Deleted); if (WhatIf) { var record = Util.RenderAuditRecord(auditRecord); Log.Info("Would Write Audit Record to " + recordName); Log.Info(record); } else { Log.Info("Writing Audit Record"); Util.SaveAuditRecord(BackupStorage, recordName, auditRecord); Log.Info("Successfully wrote audit record to: auditing/" + recordName); } if (package == null) { Log.Error("Package version does not exist: '{0}.{1}'", PackageId, PackageVersion); return; } if (!AuditOnly) { Log.Info( "Deleting package data for '{0}.{1}'", package.Id, package.Version); if (!WhatIf && !AuditOnly) { dbExecutor.Execute( "DELETE pa FROM PackageAuthors pa JOIN Packages p ON p.[Key] = pa.PackageKey WHERE p.[Key] = @key", new { key = package.Key }); dbExecutor.Execute( "DELETE pd FROM PackageDependencies pd JOIN Packages p ON p.[Key] = pd.PackageKey WHERE p.[Key] = @key", new { key = package.Key }); dbExecutor.Execute( "DELETE ps FROM PackageStatistics ps JOIN Packages p ON p.[Key] = ps.PackageKey WHERE p.[Key] = @key", new { key = package.Key }); dbExecutor.Execute( "DELETE pf FROM PackageFrameworks pf JOIN Packages p ON p.[Key] = pf.Package_Key WHERE p.[Key] = @key", new { key = package.Key }); dbExecutor.Execute( "DELETE p FROM Packages p JOIN PackageRegistrations pr ON pr.[Key] = p.PackageRegistrationKey WHERE p.[Key] = @key", new { key = package.Key }); } new DeletePackageFileTask { BackupStorage = BackupStorage, StorageAccount = StorageAccount, PackageId = package.Id, PackageVersion = package.Version, PackageHash = package.Hash, WhatIf = WhatIf }.ExecuteCommand(); } else { Log.Info("Only wrote audit record. Package was NOT deleted."); } } }