I’m putting together a custom control flow SSIS task for the first time in C#. On my task UI editor I have a property grid and in one of the options I would like to be able to populate a drop down list of any task variables available as well as give the user the option of creating a new one. I’ve been researching for a few days and I have found some good examples on the forum but I’m a little lost now. My code as follows compiles and the editor displays a drop down list but its blank. After stepping through it, it appears to be down to this line:
taskHostProperty = context.Instance.GetType().GetProperty("TransferTask", typeof(TaskHost));The "TransferTask" being the name of my control flow task. I'm wondering if this is correct?
My full code for this is below.
//Property Grid Property
[Category("General"),
Description("Specifies the local Path for this task"),
Browsable(true),
ReadOnly(false),
DesignOnly(false),
TypeConverter(typeof(VariableConverter)),
DisplayName("Local Path")]
public string LocalPath
{
get
{
return this.stLocalPath;
}
set
{
dtsVariableService = serviceProvider.GetService(typeof(IDtsVariableService)) as IDtsVariableService;
dtsVariableService.PromptAndCreateVariable(parentWindow, dtsContainer,"Local Path","User",typeof(string));
this.stLocalPath = value;
}
}
//Variable Converter
internal class VariableConverter : TypeConverter
{
StandardValuesCollection svc = new StandardValuesCollection(new ArrayList());
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
TaskHost taskHost = null;
PropertyInfo taskHostProperty = null;
List<string> values = new List<string>();
values.Add(NEW_VARIABLE);
if (context == null)
{
return svc;
}
if (context.Instance == null)
{
return svc;
}
taskHostProperty = context.Instance.GetType().GetProperty("TransferTask", typeof(TaskHost));
if (taskHostProperty == null)
{
return svc;
}
taskHost = taskHostProperty.GetValue(context.Instance, null) as TaskHost;
foreach(Variable v in taskHost.Variables)
{
if (!v.SystemVariable && v.DataType == TypeCode.String)
{
values.Add(v.QualifiedName);
}
}
values.Sort();
return new StandardValuesCollection(values);
}
In the end I gave up trying to add the variables to a property grid and just created my own form. I used the following code to populate a combobox and after allowing the user to add a new SSIS variable. I refreshed the datasource. I would still like to know how to do this properly but I just didnt have the time to sit and work it out.
I used the following to first get the SSIS variables I needed, I’m able to add a new SSIS variable and I’m able to select the newly created one. I’m sure there is a better way of doing this but this works for now.
And I used the following to allow the user to add a new SSIS variable or select an existing SSIS variable and to refresh the SSIS variable combobox.