我已经为我的SSIS包创建了一个自定义组件,并且希望它尝试自动链接一些变量。目前,我正在通过UI Properties-> Misc-> Expressions->(选择属性名称和表达式以链接到它们)手动链接它们,如下所示:
我目前正在努力处理以下代码:
public override void InitializeTask(Connections connections, VariableDispenser variableDispenser, IDTSInfoEvents events, IDTSLogging log, EventInfos eventInfos, LogEntryInfos logEntryInfos, ObjectReferenceTracker refTracker)
{
base.InitializeTask(connections, variableDispenser, events, log, eventInfos, logEntryInfos, refTracker);
using (Package pkg = ... /*not sure how to get 'this' package*/)
{
// Iterate through executables to try to find this TaskHost.
foreach (Executable pExec in pkg.Executables)
{
TaskHost aTaskHost = (TaskHost)pExec;
if (aTaskHost.InnerObject.GetType() == this.GetType())
{
// Iterate over variables, to try to match some task's properties.
foreach (Variable myVar in pkg.Variables)
{
if (aTaskHost.Properties.Contains("PackageName") &&
Regex.IsMatch(myVar.QualifiedName, "PackageName", RegexOptions.IgnoreCase))
{
aTaskHost.SetExpression("PackageName", myVar.Expression);
}
}
break;
}
}
}
}
我一直在努力降低表达水平。我的其他一些变量可能会发生变化,因此,我想链接到.Expression,而不是链接.Value。
但是,我不确定如何获取当前程序包,或者即使我知道如何,也可以确保一切正常链接。因此,我想知道是否有人在初始化时以编程方式将系统变量链接到自定义组件的属性表达式。
我看到,没有办法通过UI属性完成此操作。但是,如果通过SSIS UI连接,则可以正常工作。下面的代码段是我采用的方法。希望它可以帮助其他希望弄乱自定义组件的人。
因此,如果您具有以下SSIS UI类:
class PackageStatusSSISUI : Microsoft.SqlServer.Dts.Runtime.Design.IDtsTaskUI
{
private TaskHost _taskHost;
private IServiceProvider _serviceProvider;
public System.Windows.Forms.ContainerControl GetView()
{
PackageStatusForm editor = new PackageStatusForm(this._taskHost, this._serviceProvider);
return editor;
}
public void Initialize(TaskHost taskHost, IServiceProvider serviceProvider)
{
this._taskHost = taskHost;
this._serviceProvider = serviceProvider;
}
}
然后,如果要连接到Windows窗体,则可以访问任务主机变量并设置表达式:
public partial class PackageStatusForm : Form
{
public PackageStatusForm(TaskHost taskHost, IServiceProvider serviceprovider)
{
this.TaskHost = taskHost;
this.ServiceProvider = serviceprovider;
InitializeComponent();
if (this.TaskHost != null && this.TaskHost.Variables != null)
{
// Goes though each variable, to display the shortcut
foreach (Variable var in taskHost.Variables)
{
variableList.Items.Add(var.QualifiedName);
}
// Can set labels to variable name, text boxes to allow the expressions, etc
foreach (LabelTextDisplay ppt in this.flowLayoutPanel1.Controls)
{
this.TaskHost.SetExpression(ppt.PropertyName, ppt.ExpressionValue);
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句