我爲Cruise Control .net創建了以下自定義任務,但找不到如何將自定義任務添加到項目配置的單個引用。有沒有人有如何在cc.net中添加對自定義任務的引用的有用示例?在CC.net配置中使用自定義任務
(下面是我的新任務)
public class RestoreDb : TaskBase
{
#region Parameters
[Required]
public string ServerName { get; set; }
[Required]
public string DbName { get; set; }
public string BackupFileName { get; set; }
#endregion
protected override bool Execute(ThoughtWorks.CruiseControl.Core.IIntegrationResult result)
{
bool returnResult = false;
try
{
SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder();
connectionStringBuilder.IntegratedSecurity = true;
connectionStringBuilder.DataSource = ServerName;
SqlConnection connection = new SqlConnection(connectionStringBuilder.ToString());
connection.Open();
Server server = new Server(new ServerConnection(connection));
if (server.Databases[DbName] != null)
{
Log.Info("Dropping existing " + DbName + " on " + ServerName);
server.Databases[DbName].Drop();
}
else
{
Log.Info(DbName + " on " + ServerName + " doesn't exist.");
}
Log.Info("Restoring " + DbName + " on " + ServerName);
Database newDb = new Database(server, DbName);
Restore rs = new Restore();
rs.NoRecovery = false;
FileInfo fi = new FileInfo(server.Settings.BackupDirectory + "\\" + BackupFileName);
rs.Devices.AddDevice(fi.FullName, DeviceType.File);
rs.Database = DbName;
rs.Action = RestoreActionType.Database;
rs.ReplaceDatabase = true;
DataTable fileContents = rs.ReadFileList(server);
string originalDbName = fileContents.Rows[0][0].ToString();
string originalLogFileName = fileContents.Rows[1][0].ToString();
rs.RelocateFiles.Add(new RelocateFile(originalDbName,
string.Format(@"C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\{0}.mdf", DbName)));
rs.RelocateFiles.Add(new RelocateFile(originalLogFileName,
string.Format(@"C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\{0}_1.ldf", DbName)));
rs.SqlRestore(server);
Log.Info("Restoring done.");
returnResult = true; // success!
}
catch (Exception ex)
{
Log.Error(ex);
returnResult = false;
}
return returnResult;
}
}
這真的不是你發佈的問題的答案 – 2014-10-16 14:49:33