/// <summary> /// Sets XmlColumn properties for Output Column /// </summary> /// <param name="xmlColumn">Output Column to set XmlColumn Properties</param> internal static void SetXmlColumnProperties(IDTSOutputColumn xmlColumn, SetPropertyType propType, bool setDataType) { List <int> IdsToRemove = new List <int>(); foreach (IDTSCustomProperty prop in xmlColumn.CustomPropertyCollection) { if ( (prop.Name == Resources.XmlSaveOptionPropertyName && (propType & SetPropertyType.XmlSaveOptions) == SetPropertyType.XmlSaveOptions) || (prop.Name == Resources.XmlSerializeLineageName && (propType & SetPropertyType.XmlSerializeLineage) == SetPropertyType.XmlSerializeLineage) || (prop.Name == Resources.XmlSerializeDataTypeName && (propType & SetPropertyType.XmlSerializeDataType) == SetPropertyType.XmlSerializeDataType) || (prop.Name == Resources.XmlInputColumnsPropertyname && (propType & SetPropertyType.XmlInputColumns) == SetPropertyType.XmlInputColumns) || (prop.Name == Resources.XmlSourceIdPropertyName && (propType & SetPropertyType.XMlSourceID) == SetPropertyType.XMlSourceID) || (prop.Name == Resources.XmlSourceNamePropertyName && (propType & SetPropertyType.XmlSourceName) == SetPropertyType.XmlSourceName) ) { IdsToRemove.Add(prop.ID); } } foreach (int id in IdsToRemove) { xmlColumn.CustomPropertyCollection.RemoveObjectByID(id); } //Add Save Options if ((propType & SetPropertyType.XmlSaveOptions) == SetPropertyType.XmlSaveOptions) { IDTSCustomProperty xmlSaveOption = xmlColumn.CustomPropertyCollection.New(); xmlSaveOption.Description = Resources.XmlSaveOptionsDescriptions; xmlSaveOption.Name = Resources.XmlSaveOptionPropertyName; xmlSaveOption.ContainsID = false; xmlSaveOption.EncryptionRequired = false; xmlSaveOption.ExpressionType = DTSCustomPropertyExpressionType.CPET_NONE; xmlSaveOption.TypeConverter = typeof(SaveOptions).AssemblyQualifiedName; xmlSaveOption.Value = SaveOptions.None; } //Lineage & Colun IDs information if ((propType & SetPropertyType.XmlSerializeLineage) == SetPropertyType.XmlSerializeLineage) { IDTSCustomProperty lineage = xmlColumn.CustomPropertyCollection.New(); lineage.Description = Resources.XmlSerializeLineageDescription; lineage.Name = Resources.XmlSerializeLineageName; lineage.ContainsID = false; lineage.EncryptionRequired = false; lineage.ExpressionType = DTSCustomPropertyExpressionType.CPET_NONE; lineage.TypeConverter = typeof(bool).AssemblyQualifiedName; lineage.Value = false; } //Data Type Information if ((propType & SetPropertyType.XmlSerializeDataType) == SetPropertyType.XmlSerializeDataType) { IDTSCustomProperty storeDataType = xmlColumn.CustomPropertyCollection.New(); storeDataType.Description = Resources.XmlStoreDataTypeDescription; storeDataType.Name = Resources.XmlSerializeDataTypeName; storeDataType.ContainsID = false; storeDataType.EncryptionRequired = false; storeDataType.ExpressionType = DTSCustomPropertyExpressionType.CPET_NONE; storeDataType.TypeConverter = typeof(bool).AssemblyQualifiedName; storeDataType.Value = false; } if ((propType & SetPropertyType.XmlInputColumns) == SetPropertyType.XmlInputColumns) { IDTSCustomProperty storeDataType = xmlColumn.CustomPropertyCollection.New(); storeDataType.Name = Resources.XmlInputColumnsPropertyname; storeDataType.Description = "Specifies the columns to be used to build Xml"; storeDataType.ContainsID = true; storeDataType.EncryptionRequired = false; storeDataType.ExpressionType = DTSCustomPropertyExpressionType.CPET_NONE; storeDataType.Value = string.Empty; } if ((propType & SetPropertyType.XMlSourceID) == SetPropertyType.XMlSourceID) { IDTSCustomProperty storeDataType = xmlColumn.CustomPropertyCollection.New(); storeDataType.Name = Resources.XmlSourceIdPropertyName; storeDataType.Description = "Specifies optional descriptive ID of the culumns source"; storeDataType.ContainsID = false; storeDataType.EncryptionRequired = false; storeDataType.ExpressionType = DTSCustomPropertyExpressionType.CPET_NONE; storeDataType.Value = string.Empty; } if ((propType & SetPropertyType.XmlSourceName) == SetPropertyType.XmlSourceName) { IDTSCustomProperty storeDataType = xmlColumn.CustomPropertyCollection.New(); storeDataType.Name = Resources.XmlSourceNamePropertyName; storeDataType.Description = "Specifies optional descriptive Name of the columns source"; storeDataType.ContainsID = false; storeDataType.EncryptionRequired = false; storeDataType.ExpressionType = DTSCustomPropertyExpressionType.CPET_NONE; storeDataType.Value = string.Empty; } //Column Data Type if (setDataType) { xmlColumn.SetDataTypeProperties(DataType.DT_NTEXT, 0, 0, 0, 0); } }
/// <summary> /// Upgrades the component from earlier versions /// </summary> /// <param name="pipelineVersion"></param> public override void PerformUpgrade(int pipelineVersion) { DtsPipelineComponentAttribute componentAttribute = (DtsPipelineComponentAttribute)Attribute.GetCustomAttribute(this.GetType(), typeof(DtsPipelineComponentAttribute), false); int currentVersion = componentAttribute.CurrentVersion; // Get the attributes for the SSIS Package int metadataVersion = ComponentMetaData.Version; if (currentVersion < ComponentMetaData.Version) { throw new Exception(Properties.Resources.ErrorWrongRuntimeVersion); } else if (currentVersion > ComponentMetaData.Version) { IDTSInput input = ComponentMetaData.InputCollection[0]; List <int> propsToRemove = new List <int>(); List <KeyValuePair <int, int> > colLienagesSort = new List <KeyValuePair <int, int> >(input.InputColumnCollection.Count); string sourceID = string.Empty; string sourceName = string.Empty; try { IDTSCustomProperty prop = ComponentMetaData.CustomPropertyCollection[Resources.ColumnsToXmlSourceNameProperty]; if (prop != null) { sourceName = prop.Value.ToString(); ComponentMetaData.CustomPropertyCollection.RemoveObjectByID(prop.ID); } } catch { } try { IDTSCustomProperty prop = ComponentMetaData.CustomPropertyCollection[Resources.ColumnsToXmlSourceIDProperty]; if (prop != null) { sourceID = prop.Value.ToString(); ComponentMetaData.CustomPropertyCollection.RemoveObjectByID(prop.ID); } } catch { } foreach (IDTSInputColumn col in input.InputColumnCollection) { int sortOrder = int.MaxValue; IDTSCustomProperty prop = null; propsToRemove = new List <int>(); foreach (IDTSCustomProperty p in col.CustomPropertyCollection) { if (p.Name == Resources.InputSortOrderPropertyName) { sortOrder = (int)p.Value; propsToRemove.Add(p.ID); break; } } colLienagesSort.Add(new KeyValuePair <int, int>(col.LineageID, sortOrder)); foreach (int id in propsToRemove) { col.CustomPropertyCollection.RemoveObjectByID(id); } } colLienagesSort.Sort((a, b) => a.Value.CompareTo(b.Value)); IDTSOutput output = ComponentMetaData.OutputCollection[0]; foreach (IDTSOutputColumn col in output.OutputColumnCollection) { SetPropertyType setProp = SetPropertyType.All; bool additionalPropertyExists = false; bool setDataType = !(col.DataType == DataType.DT_NTEXT || (col.DataType == DataType.DT_WSTR && col.Length <= 4000)); foreach (IDTSCustomProperty prop in col.CustomPropertyCollection) { if (prop.Name == Resources.XmlSaveOptionPropertyName) { setProp ^= SetPropertyType.XmlSaveOptions; } else if (prop.Name == Resources.XmlSerializeLineageName) { setProp ^= SetPropertyType.XmlSerializeLineage; } else if (prop.Name == Resources.XmlSerializeDataTypeName) { setProp ^= SetPropertyType.XmlSerializeDataType; } else if (prop.Name == Resources.XmlInputColumnsPropertyname) { setProp ^= SetPropertyType.XmlInputColumns; } else if (prop.Name == Resources.XmlSourceIdPropertyName) { setProp ^= SetPropertyType.XMlSourceID; } else if (prop.Name == Resources.XmlSourceNamePropertyName) { setProp ^= SetPropertyType.XmlSourceName; } else { additionalPropertyExists = true; } } if (setProp != SetPropertyType.None || additionalPropertyExists || setDataType) { SetXmlColumnProperties(col, setProp, setDataType); } if ((setProp & SetPropertyType.XmlInputColumns) == SetPropertyType.XmlInputColumns && colLienagesSort.Count > 0) { string lineages = InputColumns.BuildInputLineagesString(colLienagesSort.ConvertAll <int>(kvp => kvp.Key)); col.CustomPropertyCollection[Resources.XmlInputColumnsPropertyname].Value = lineages; } if ((setProp & SetPropertyType.XMlSourceID) == SetPropertyType.XMlSourceID) { col.CustomPropertyCollection[Resources.XmlSourceIdPropertyName].Value = sourceID; } if ((setProp & SetPropertyType.XmlSourceName) == SetPropertyType.XmlSourceName) { col.CustomPropertyCollection[Resources.XmlSourceNamePropertyName].Value = sourceName; } } ComponentMetaData.Version = currentVersion; } }