次のカスタム タスクを Cruise Control .net 用に作成しましたが、カスタム タスクをプロジェクト構成に追加する方法についてのリファレンスが 1 つも見つかりません。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;
}
}