为SSIS编写自定义任务项(Task)之高级篇
2009-09-19 00:00:00 来源:WEB开发网4. 为任务项实现Execute方法
/// <summary>
/// 这个方法真正执行操作
/// </summary>
/// <param name="connections"></param>
/// <param name="variableDispenser"></param>
/// <param name="componentEvents"></param>
/// <param name="log"></param>
/// <param name="transaction"></param>
/// <returns></returns>
public override DTSExecResult Execute(Connections connections,
VariableDispenser variableDispenser,
IDTSComponentEvents componentEvents,
IDTSLogging log, object transaction)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(source);
XmlNamespaceManager xnm = new XmlNamespaceManager(doc.NameTable);
if (!string.IsNullOrEmpty(defs))
{
string[] def = defs.Split('n');
foreach (var item in def)
{
xnm.AddNamespace(item.Split(',')[0].Trim(), item.Split(',')[1].Trim());
}
}
XmlNode result = doc.SelectSingleNode(xpath, xnm);
File.WriteAllText(target, result.OuterXml);
return DTSExecResult.Success;
}
catch(Exception ex) {
componentEvents.FireError(0, "MyXMLTask", ex.Message, string.Empty, 0);
return DTSExecResult.Failure;
}
}
更多精彩
赞助商链接