Hey ladies and gents, got a puzzling problem I'm encountering. I'm building a custom component for SSIS that accepts an unlimited number of inputs. I decided one way to keep things clean was to make sure that there was exactly one unattached input at a time. Validate() checks to see how many unattached inputs there are and returns VS_NEEDSNEWMETADATA if the amount is not equal to one. ReinitializeMetaData() then cleans up the InputCollection. I've attached the code below for both overridden functions (you can see that I've used message boxes to help verify the code is actually doing what it is expected to do).
I've verified that both functions work correctly, but the problem is that ReinitializeMetaData is not getting automatically called when Validate() returns VS_NEEDSNEWMETADATA. Instead, the little red error symbol appears with rollover text saying "Validation errors occurred", and if I click on the component, a window pops up saying "The component is not in a valid state. Do you want the component to fix itself automatically." Why isn't ReinitializeMetaData automatically running, and how can I fix it. All help greatly appreciated!
public override DTSValidationStatus Validate()
{
///
If there is an input column that no longer exists in the Virtual input collection,
/// return needs new meta data. The designer will then call ReinitalizeMetadata which will clean up the input collection.
if (ComponentMetaData.AreInputColumnsValid == false)
return DTSValidationStatus.VS_NEEDSNEWMETADATA;
/// The component should only have one unattached input at a time. If there are none, ReinitializeMetaData will create one.
/// If there is more than one, ReinitializeMetaData will remove all extras.
int unattachedInputCount = 0;
foreach (IDTSInput100 input in ComponentMetaData.InputCollection)
{
if (input.IsAttached == false)
unattachedInputCount++;
}
MessageBox.Show("You have " + unattachedInputCount.ToString() + " unattached inputs.");
if (unattachedInputCount!=1)
return DTSValidationStatus.VS_NEEDSNEWMETADATA;
DTSValidationStatus status = base.Validate();
return status;
}
public override void ReinitializeMetaData()
{
base.ReinitializeMetaData();
this.ComponentMetaData.RemoveInvalidInputColumns();
/// If there is more than one unattached input, removes all except one.
IDTSInputCollection100 inputCollection = ComponentMetaData.InputCollection;
int unattachedInputCount = 0;
foreach (IDTSInput100 input in inputCollection)
{
if (input.IsAttached == false)
{
unattachedInputCount++;
if (unattachedInputCount > 1)
inputCollection.RemoveObjectByID(input.ID);
}
}
/// If there are no unattached inputs, adds a new one.
if (unattachedInputCount == 0)
inputCollection.New();
/// Identifies remaining unattached inputs to verify the above has worked.
unattachedInputCount = 0;
foreach (IDTSInput100 input in ComponentMetaData.InputCollection)
{
if (!input.IsAttached)
unattachedInputCount++;
}
MessageBox.Show("You now have " + unattachedInputCount.ToString() + " unattached inputs.");
}
}