Exemplo n.º 1
0
        public void Initialize(Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData100 dtsComponentMetadata, IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
            this.metaData        = dtsComponentMetadata;

            this.connectionService = (IDtsConnectionService)serviceProvider.GetService(typeof(IDtsConnectionService));
        }
Exemplo n.º 2
0
        public static IDTSOutput FindComponentOutput(MainPipe mainPipe, string path)
        {
            if (mainPipe == null)
            {
                throw new ArgumentNullException("mainPipe");
            }

            var pathParts = new List <string>(path.Split(new[] { "." }, StringSplitOptions.None));

            if (pathParts.Count != 2 || !pathParts[1].StartsWith("Outputs", StringComparison.Ordinal))
            {
                throw new ArgumentException("Path was not a valid SSIS reference path.", "path");
            }

            IDTSComponentMetaData component = FindComponent(mainPipe, pathParts[0]);
            string outputName = GetSubStringBetween(pathParts[1], "[", "]");

            foreach (IDTSOutput output in component.OutputCollection)
            {
                if (output.Name.Equals(outputName, StringComparison.Ordinal))
                {
                    return(output);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
 // Creates Source Component (Output Collection)
 internal void CreateSourceComponent()
 {
     // Creates mainpipe for the executable component
     _objMainPipe = ((TaskHost)_objPackage.Executables.Add(_strDataFlowTaskMoniker)).InnerObject as MainPipe;
     // Adds a component from the MainPipe to the Source Metadata
     _objIDTSSRCMetaData = _objMainPipe.ComponentMetaDataCollection.New();
     // Sets the source component class id
     _objIDTSSRCMetaData.ComponentClassID = _strSourceDFComponentID;
     // Sets the locale property
     _objIDTSSRCMetaData.LocaleID = -1;
     // Instantiates the Wrapper, adding Source Metadata
     _objSourceWrapper = _objIDTSSRCMetaData.Instantiate();
     // Provides default properties
     _objSourceWrapper.ProvideComponentProperties();
     // Sets RAWFile Component Property
     _objSourceWrapper.SetComponentProperty("AccessMode", 0);
     _objSourceWrapper.SetComponentProperty("FileName", strRAWFileName);
     _objSourceWrapper.SetComponentProperty("FileNameVariable", null);
     // Sets the connection
     _objSourceWrapper.AcquireConnections(null);
     // Reinitializes the Source Metadata
     _objSourceWrapper.ReinitializeMetaData();
     // Fetch ColumnNames for the Metadata
     if (_strRAWColNames.Length == 0 && _strRAWColNames.ToString() == string.Empty)
     {
         foreach (IDTSOutputColumn100 idtsOutPutColumn in _objIDTSSRCMetaData.OutputCollection[0].OutputColumnCollection)
         {
             _strRAWColNames.Append(idtsOutPutColumn + ",");
         }
     }
     // Releases the Wrapper connection
     _objSourceWrapper.ReleaseConnections();
 }
Exemplo n.º 4
0
        public CRMDestinationAdapterUIForm(Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData100 metaData, IDtsConnectionService connectionService)
            : this()
        {
            this.metaData          = metaData;
            this.connectionService = connectionService;

            this.designTimeInstance = metaData.Instantiate();
        }
Exemplo n.º 5
0
 public RabbitMQSourceUIForm(Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData100 metaData, IServiceProvider serviceProvider)
     : this()
 {
     this.metaData           = metaData;
     this.serviceProvider    = serviceProvider;
     this.connectionService  = (IDtsConnectionService)serviceProvider.GetService(typeof(IDtsConnectionService));
     this.designTimeInstance = metaData.Instantiate();
 }
Exemplo n.º 6
0
 public RabbitMQSourceUIForm(Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData100 metaData, IServiceProvider serviceProvider)
     : this()
 {
     this.metaData = metaData;
       this.serviceProvider = serviceProvider;
       this.connectionService = (IDtsConnectionService)serviceProvider.GetService(typeof(IDtsConnectionService));
       this.designTimeInstance = metaData.Instantiate();
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes the DataFlowUI Instance
 /// </summary>
 /// <param name="dtsComponentMetadata">IDTSComponentMetaData of the DataFlow component</param>
 /// <param name="serviceProvider">IService provider tobe asosciated with the DataFlowUI</param>
 public virtual void Initialize(IDTSComponentMetaData dtsComponentMetadata, IServiceProvider serviceProvider)
 {
     this.componentMetadata = dtsComponentMetadata;
     this.serviceProvider   = serviceProvider;
     if (this.designTimeComponent == null)
     {
         this.designTimeComponent = this.componentMetadata.Instantiate();
     }
 }
Exemplo n.º 8
0
 public MappingsUIForm(Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData100 metaData, IDtsConnectionService connectionService, int Operation, Item EntityItem, Mapping Mapping)
     : this()
 {
     this.metaData          = metaData;
     this.connectionService = connectionService;
     this.operation         = Operation;
     this.entityItem        = EntityItem;
     this.mapping           = Mapping;
 }
        void IDtsComponentUI.Initialize(Microsoft.SqlServer.Dts.Pipeline.Wrapper.IDTSComponentMetaData100 dtsComponentMetadata, IServiceProvider serviceProvider)
        {
            this.componentMetadata = dtsComponentMetadata;
            this.serviceProvider   = serviceProvider;
            Debug.Assert(this.serviceProvider != null);

            this.errorCollector = this.serviceProvider.GetService(typeof(IErrorCollectionService)) as IErrorCollectionService;
            Debug.Assert(this.errorCollector != null);

            if (this.errorCollector == null)
            {
                throw new InvalidOperationException("Not all editing services available");
            }
        }
        public override void Initialize(IDTSComponentMetaData dtsComponentMetadata, IServiceProvider serviceProvider)
        {
            base.Initialize(dtsComponentMetadata, serviceProvider);
            _inputColumns = new List <ConvertMetadataInputColumn>();



            IDTSVirtualInput vInput = GetVirtualInput(0); //Get virtualInput for the RegExExtractionTransformation

            if (vInput != null)
            {
                foreach (IDTSVirtualInputColumn vcol in vInput.VirtualInputColumnCollection)
                {
                    if (RegExExtractionTransformation.SupportedDataTypes.Contains(vcol.DataType))
                    {
                        ConvertMetadataInputColumn iCol = new ConvertMetadataInputColumn(vcol);
                        _inputColumns.Add(iCol);
                    }
                }
            }



            //Sort the columns by name
            _inputColumns.Sort((a, b) => a.Name.CompareTo(b.Name));

            //Check if the column names repeats and in that cas set the DisplayName to include also UpstreamComponentname
            for (int i = 0; i < _inputColumns.Count; i++)
            {
                if (i >= 0 && i < _inputColumns.Count - 1 && _inputColumns[i].Name == _inputColumns[i + 1].Name)
                {
                    _inputColumns[i].DisplayName = string.Format("{0}.{1}", _inputColumns[i].UpstreamComponentName, _inputColumns[i].Name);
                }
                else if (i > 0 && i < _inputColumns.Count && _inputColumns[i].Name == _inputColumns[i - 1].Name)
                {
                    _inputColumns[i].DisplayName = string.Format("{0}.{1}", _inputColumns[i].UpstreamComponentName, _inputColumns[i].Name);
                }
            }

            //add the "Not Specified" column (LineageID = 0)
            _inputColumns.Insert(0, ConvertMetadataInputColumn.NotSpecifiedInputColumn);
        }
Exemplo n.º 11
0
        private static void HookupRawSource(MainPipe pipeline, MainPipe pipelineToReference, IDTSInputXX input, IDTSComponentMetaDataXX componentNextInPath, string sRawFilePath)
        {
            IDTSComponentMetaDataXX rawSourceComponent = pipeline.ComponentMetaDataCollection.New();
            rawSourceComponent.ComponentClassID = "DTSAdapter.RawSource";
            CManagedComponentWrapper inst = rawSourceComponent.Instantiate();
            inst.ProvideComponentProperties();
            inst.SetComponentProperty("FileName", sRawFilePath);
            try
            {
                inst.AcquireConnections(null);
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to locate raw file at the following path which means that the previous test iteration did not run. Is the data flow task disabled?\r\n\r\n" + sRawFilePath, ex);
            }
            inst.ReinitializeMetaData();
            inst.ReleaseConnections();

            IDTSPathXX pathToReference = GetPathForInput(input, pipelineToReference.PathCollection);
            if (pathToReference == null) throw new Exception("Couldn't find path for input " + input.ID);

            if (pathToReference.StartPoint.IsSorted)
            {
                rawSourceComponent.OutputCollection[0].IsSorted = true;
            }

            Dictionary<string, List<IDTSVirtualInputColumnXX>> dictVirtualColumns = new Dictionary<string, List<IDTSVirtualInputColumnXX>>();
            IDTSVirtualInputColumnCollectionXX colCollection = pathToReference.EndPoint.GetVirtualInput().VirtualInputColumnCollection;
            foreach (IDTSVirtualInputColumnXX sourceColToReference in colCollection)
            {
                string sColName = sourceColToReference.Name;
                if (dictVirtualColumns.ContainsKey(sColName))
                {
                    dictVirtualColumns[sColName].Add(sourceColToReference);
                }
                else
                {
                    List<IDTSVirtualInputColumnXX> list = new List<IDTSVirtualInputColumnXX>();
                    list.Add(sourceColToReference);
                    dictVirtualColumns.Add(sColName, list);
                }
            }

            Dictionary<int, int> lineageIdReplacements = new Dictionary<int, int>();
            foreach (IDTSOutputColumnXX outputCol in rawSourceComponent.OutputCollection[0].OutputColumnCollection)
            {
                string sColName = outputCol.Name;
                if (dictVirtualColumns.ContainsKey(sColName))
                {
                    foreach (IDTSVirtualInputColumnXX sourceColToReference in dictVirtualColumns[sColName])
                    {
                        if (!lineageIdReplacements.ContainsKey(sourceColToReference.LineageID))
                        {
                            lineageIdReplacements.Add(sourceColToReference.LineageID, outputCol.LineageID);
                            if (sourceColToReference.SortKeyPosition != 0)
                                outputCol.SortKeyPosition = sourceColToReference.SortKeyPosition;
                        }
                    }
                }
                //foreach (IDTSVirtualInputColumnXX sourceColToReference in colCollection)
                //{
                //    if (sourceColToReference.Name == outputCol.Name && !lineageIdReplacements.ContainsKey(sourceColToReference.LineageID))
                //    {
                //        lineageIdReplacements.Add(sourceColToReference.LineageID, outputCol.LineageID);
                //        if (sourceColToReference.SortKeyPosition != 0)
                //            outputCol.SortKeyPosition = sourceColToReference.SortKeyPosition;
                //    }
                //}
            }

            if (!ContainsID(pipeline, input.ID))
            {
                //look for an unattached input and use it instead
                //it's hopefully a fair assumption that if deleting the path to an input resulted in the input automatically being deleted, then there's nothing special about that input and any other can be used.
                //this is the case with the Union All transform for which this is a workaround
                bool bFoundAlt = false;
                foreach (IDTSInputXX inputAlt in componentNextInPath.InputCollection)
                {
                    if (!inputAlt.IsAttached)
                    {
                        input = inputAlt;
                        bFoundAlt = true;
                        break;
                    }
                }

                if (!bFoundAlt)
                {
                    //create a new input
                    string sNewInputName = "BIDS_Helper_Input_" + input.ID;
                    input = componentNextInPath.InputCollection.New();
                    input.Name = sNewInputName;
                }
            }

            LineageIdReplacer.ReplaceLineageIDs(pipeline, lineageIdReplacements);

            IDTSPathXX path = pipeline.PathCollection.New();
            path.AttachPathAndPropagateNotifications(rawSourceComponent.OutputCollection[0], input);

            rawSourceComponent.Name = RAW_SOURCE_COMPONENT_NAME_PREFIX + pathToReference.StartPoint.ID.ToString();
        }
        public override void Initialize(IDTSComponentMetaData dtsComponentMetadata, IServiceProvider serviceProvider)
        {
            base.Initialize(dtsComponentMetadata, serviceProvider);
            _inputColumns      = new List <ConvertMetadataInputColumn>();
            _lookupColumns     = new List <ConvertMetadataInputColumn>();
            _inputDateColumns  = new List <ConvertMetadataInputColumn>();
            _lookupDateColumns = new List <ConvertMetadataInputColumn>();

            //Load InputColumns
            if (ComponentMetadata != null && ComponentMetadata.InputCollection.Count > 0)
            {
                IDTSVirtualInput vInput = GetVirtualInput(0); //Get virtualInput for the Data Input
                if (vInput != null)
                {
                    foreach (IDTSVirtualInputColumn vcol in vInput.VirtualInputColumnCollection)
                    {
                        if (CheckColumnForInputValidity(vcol))
                        {
                            ConvertMetadataInputColumn iCol = new ConvertMetadataInputColumn(vcol);
                            _inputColumns.Add(iCol);
                        }
                    }
                }

                //Sort the columns by name
                _inputColumns.Sort((a, b) => a.Name.CompareTo(b.Name));

                //Check if teh column names repeats and in that cas set the DisplayName tto include also UpstreamComponentname
                for (int i = 0; i < _inputColumns.Count; i++)
                {
                    if (i >= 0 && i < _inputColumns.Count - 1 && _inputColumns[i].Name == _inputColumns[i + 1].Name)
                    {
                        _inputColumns[i].DisplayName = string.Format("{0}.{1}", _inputColumns[i].UpstreamComponentName, _inputColumns[i].Name);
                    }
                    else if (i > 0 && i < _inputColumns.Count && _inputColumns[i].Name == _inputColumns[i - 1].Name)
                    {
                        _inputColumns[i].DisplayName = string.Format("{0}.{1}", _inputColumns[i].UpstreamComponentName, _inputColumns[i].Name);
                    }
                }

                //add the "Not Specified" column (LineageID = 0)
                _inputColumns.Insert(0, ConvertMetadataInputColumn.NotSpecifiedInputColumn);
            }

            //Load LookupColumns
            if (ComponentMetadata != null && ComponentMetadata.InputCollection.Count > 1)
            {
                IDTSVirtualInput vInput = GetVirtualInput(1); //Get virtualInput for the Data Input
                if (vInput != null)
                {
                    foreach (IDTSVirtualInputColumn vcol in vInput.VirtualInputColumnCollection)
                    {
                        if (CheckColumnForInputValidity(vcol))
                        {
                            ConvertMetadataInputColumn iCol = new ConvertMetadataInputColumn(vcol);
                            _lookupColumns.Add(iCol);
                        }
                    }
                }

                //Sort the columns by name
                _lookupColumns.Sort((a, b) => a.Name.CompareTo(b.Name));

                //Check if teh column names repeats and in that cas set the DisplayName tto include also UpstreamComponentname
                for (int i = 0; i < _lookupColumns.Count; i++)
                {
                    if (i >= 0 && i < _lookupColumns.Count - 1 && _lookupColumns[i].Name == _lookupColumns[i + 1].Name)
                    {
                        _lookupColumns[i].DisplayName = string.Format("{0}.{1}", _lookupColumns[i].UpstreamComponentName, _lookupColumns[i].Name);
                    }
                    else if (i > 0 && i < _lookupColumns.Count && _lookupColumns[i].Name == _lookupColumns[i - 1].Name)
                    {
                        _lookupColumns[i].DisplayName = string.Format("{0}.{1}", _lookupColumns[i].UpstreamComponentName, _lookupColumns[i].Name);
                    }
                }

                //add the "Not Specified" column (LineageID = 0)
                _lookupColumns.Insert(0, ConvertMetadataInputColumn.NotSpecifiedInputColumn);
            }
        }
Exemplo n.º 13
0
        private void ReplaceUpstreamDestinationOutputsWithRawFileSource(MainPipe pipeline, MainPipe pipelineToReference, IDTSComponentMetaDataXX downstreamComponent)
        {
            List<int> destErrorOutputsComponents = new List<int>();
            foreach (IDTSComponentMetaDataXX component in GetUpstreamComponents(downstreamComponent, pipeline.PathCollection))
            {
                if ((component.ObjectType & DTSObjectType.OT_DESTINATIONADAPTER) == DTSObjectType.OT_DESTINATIONADAPTER)
                {
                    foreach (IDTSOutputXX errorOutput in component.OutputCollection)
                    {
                        if (errorOutput.IsAttached && !HasUnsupportedRawFileColumnDataTypes(pipelineToReference.ComponentMetaDataCollection.FindObjectByID(component.ID)))
                        {
                            destErrorOutputsComponents.Add(component.ID);
                        }
                    }
                }
            }

            foreach (int iComponentID in destErrorOutputsComponents)
            {
                int iPath = 0;
                while (iPath < pipeline.PathCollection.Count)
                {
                    IDTSPathXX path = pipeline.PathCollection[iPath];
                    if (path.StartPoint.Component.ID == iComponentID && ContainsID(pipelineToReference.PathCollection, path.ID))
                    {
                        IDTSPathXX pathToReference = pipelineToReference.PathCollection.FindObjectByID(path.ID);
                        string sRawFilePath = GetRawFilePathForOutput(path.StartPoint);
                        IDTSInputXX input = path.EndPoint;
                        IDTSOutputXX output = path.StartPoint;
                        if (output.IsErrorOut && output.IsAttached)
                        {
                            IDTSComponentMetaDataXX componentNextInPath = input.Component;
                            RemovePath(path, pipeline.PathCollection, true);
                            HookupRawSource(pipeline, pipelineToReference, input, componentNextInPath, sRawFilePath);
                        }
                        else
                        {
                            RemovePath(path, pipeline.PathCollection, true);
                        }
                    }
                    else if (path.EndPoint.Component.ID == iComponentID)
                    {
                        RemovePath(path, pipeline.PathCollection, true);
                    }
                    else
                    {
                        iPath++;
                    }
                }
                pipeline.ComponentMetaDataCollection.RemoveObjectByID(iComponentID);
            }
        }
Exemplo n.º 14
0
 internal void SetComponentProperties(Pipe.IDTSComponentMetaData100 Component)
 {
     Component.RuntimeConnectionCollection[0].ConnectionManagerID = ConnectionManager.SSISObject.ID;
     Component.RuntimeConnectionCollection[0].ConnectionManager   = SSIS.DtsConvert.GetExtendedInterface(ConnectionManager.SSISObject);
 }
Exemplo n.º 15
0
        // Creates Destination Component (Input Collection)
        internal void CreateDestinationReaderComponent()
        {
            // 1. DataReader String: the class name of the DataReader destination.
            // 2. FailOnTimeout Boolean:Indicates wheather to fail when a ReadTimeout occurs. The default value is False.
            // 3. ReadeTimeout Integer: The number of milliseconds before a timeout occurs. The default value of this property is 30000 (30 seconds).

            // Adds a component from MainPipe to the Destination Recordset Metadata
            _objIDTSDSTReaderMetaData = _objMainPipe.ComponentMetaDataCollection.New();
            // Sets the Destination recordset component name
            _objIDTSDSTReaderMetaData.Name = "Test";
            // Sets the Destination recordset component class id
            _objIDTSDSTReaderMetaData.ComponentClassID = _strDestinationDFReaderComponentID;

            IDTSCustomProperty100 _property = _objIDTSDSTReaderMetaData.CustomPropertyCollection.New();

            _property.Name  = "DataReader";
            _property.Value = new object();

            _property       = _objIDTSDSTReaderMetaData.CustomPropertyCollection.New();
            _property.Name  = "FailOnTimeout";
            _property.Value = false;

            _property       = _objIDTSDSTReaderMetaData.CustomPropertyCollection.New();
            _property.Name  = "ReadTimeout";
            _property.Value = 30000;

            // Instantiates the Wrapper adding Destination Recordset Metadata
            _objDestinationReaderWrapper = _objIDTSDSTReaderMetaData.Instantiate();
            // Provides default properties
            _objDestinationReaderWrapper.ProvideComponentProperties();
            // Sets the connection
            _objDestinationReaderWrapper.AcquireConnections(null);
            // Reinitializes the Destination Metadata
            _objDestinationReaderWrapper.ReinitializeMetaData();
            // Releases the Wrapper connection
            _objDestinationReaderWrapper.ReleaseConnections();
            // Creates the IDTSPath from the MainPipe
            _objIDTSPath = _objMainPipe.PathCollection.New();


            _objIDTSPath.AttachPathAndPropagateNotifications(_objIDTSSRCMetaData.OutputCollection[0], _objIDTSDSTReaderMetaData.InputCollection[0]);
            _objIDTSInput = _objIDTSDSTReaderMetaData.InputCollection[0];
            //Gets the Virtual Input Column Collection from the Destination Input Collection
            _objIDTSVirtualInput = _objIDTSInput.GetVirtualInput();

            _iDestInputID = Convert.ToInt32(_objIDTSInput.ID);
            // Splits the RAW Column Names into an array of strings
            if (strRAWColNames != null && strRAWColNames.Equals(string.Empty) == false && strRAWColNames != "")
            {
                if (strRAWColNames.EndsWith(","))
                {
                    _iIndex   = strRAWColNames.LastIndexOf(_delim);
                    _strIndex = strRAWColNames.Remove(_iIndex);
                }
                _strFilterArray = _strIndex.Split(_delim);
            }
            // Sets Usagetype According to FilterArray
            foreach (IDTSVirtualInputColumn100 objIDTSVirtualInputColumn in _objIDTSVirtualInput.VirtualInputColumnCollection)
            {
                if (_strFilterArray == null)
                {
                    // When FilterArray string is null
                    _objDestinationReaderWrapper.SetUsageType(_iDestInputID, _objIDTSVirtualInput, objIDTSVirtualInputColumn.LineageID, DTSUsageType.UT_READONLY);
                }
                else
                {
                    if (FilterField(objIDTSVirtualInputColumn.Name, _strFilterArray) == false)
                    {
                        // When FilterArray string is not null
                        _objDestinationReaderWrapper.SetUsageType(_iDestInputID, _objIDTSVirtualInput, objIDTSVirtualInputColumn.LineageID, DTSUsageType.UT_READONLY);
                    }
                }
            }
            // Sets the connection
            _objDestinationReaderWrapper.AcquireConnections(null);
            // Reinitializes the Destination Metadata
            _objDestinationReaderWrapper.ReinitializeMetaData();
            // Releases the Wrapper connection
            _objDestinationReaderWrapper.ReleaseConnections();
        }
Exemplo n.º 16
0
 private static bool HasUnsupportedRawFileColumnDataTypes(IDTSComponentMetaDataXX component)
 {
     foreach (IDTSInputXX input in component.InputCollection)
     {
         if (input.IsAttached)
         {
             foreach (IDTSInputColumnXX col in input.InputColumnCollection)
             {
                 if (col.DataType == Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType.DT_IMAGE || col.DataType == Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType.DT_NTEXT || col.DataType == Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType.DT_TEXT)
                 {
                     return true;
                 }
             }
         }
     }
     foreach (IDTSOutputXX output in component.OutputCollection)
     {
         if (output.IsAttached)
         {
             foreach (IDTSOutputColumnXX col in output.OutputColumnCollection)
             {
                 if (col.DataType == Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType.DT_IMAGE || col.DataType == Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType.DT_NTEXT || col.DataType == Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType.DT_TEXT)
                 {
                     return true;
                 }
             }
         }
     }
     return false;
 }
Exemplo n.º 17
0
        private static void DeleteAllNonUpstreamComponents(MainPipe pipeline, IDTSComponentMetaDataXX component)
        {
            List<int> upstreamComponentIDs = new List<int>();
            upstreamComponentIDs.Add(component.ID);
            foreach (IDTSComponentMetaDataXX upstream in GetUpstreamComponents(component, pipeline.PathCollection))
            {
                upstreamComponentIDs.Add(upstream.ID);
            }

            //delete all paths not upstream
            int iPath = 0;
            while (iPath < pipeline.PathCollection.Count)
            {
                IDTSPathXX path = pipeline.PathCollection[iPath];
                if (!upstreamComponentIDs.Contains(path.StartPoint.Component.ID) || !upstreamComponentIDs.Contains(path.EndPoint.Component.ID))
                {
                    RemovePath(path, pipeline.PathCollection, false);
                }
                else
                {
                    iPath++;
                }
            }

            //remove all non-upstream components
            int iComponent = 0;
            while (iComponent < pipeline.ComponentMetaDataCollection.Count)
            {
                IDTSComponentMetaDataXX componentToRemove = pipeline.ComponentMetaDataCollection[iComponent];
                if (!upstreamComponentIDs.Contains(componentToRemove.ID))
                {
                    pipeline.ComponentMetaDataCollection.RemoveObjectByID(componentToRemove.ID);
                }
                else
                {
                    iComponent++;
                }
            }
        }
        private void ScanIntegrationServicesExecutableForPropertiesWithNonDefaultValue(DtsObject o, string FriendlyPath)
        {
            if (o == null)
            {
                return;
            }

            if (packageDefault == null)
            {
                packageDefault = new Package();
            }

            DtsObject defaultObject;

            if (o is Package)
            {
                defaultObject = packageDefault;
            }
            else if (o is IDTSName)
            {
                if (dictCachedDtsObjects.ContainsKey(((IDTSName)o).CreationName))
                {
                    defaultObject = dictCachedDtsObjects[((IDTSName)o).CreationName];
                }
                else if (o is DtsEventHandler)
                {
                    defaultObject = (DtsObject)packageDefault.EventHandlers.Add(((IDTSName)o).CreationName);
                    dictCachedDtsObjects.Add(((IDTSName)o).CreationName, defaultObject);
                }
                else if (o is ConnectionManager)
                {
                    defaultObject = (DtsObject)packageDefault.Connections.Add(((IDTSName)o).CreationName);
                    dictCachedDtsObjects.Add(((IDTSName)o).CreationName, defaultObject);
                }
                else
                {
                    defaultObject = packageDefault.Executables.Add(((IDTSName)o).CreationName);
                    dictCachedDtsObjects.Add(((IDTSName)o).CreationName, defaultObject);
                }
            }
            else
            {
                throw new Exception("Object " + o.GetType().FullName + " does not implement IDTSName.");
            }

            PropertyInfo[] properties = o.GetType().GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance);
            foreach (PropertyInfo prop in properties)
            {
                if (!prop.CanWrite || !prop.CanRead)
                {
                    continue;
                }

                //SSIS objects don't have a DefaultValueAttribute, which is wy we have to create a new control flow object (defaultObject) above and compare properties from this object to that object

                object[] attrs = prop.GetCustomAttributes(typeof(System.ComponentModel.BrowsableAttribute), true);
                System.ComponentModel.BrowsableAttribute browsableAttr = (System.ComponentModel.BrowsableAttribute)(attrs.Length > 0 ? attrs[0] : null);
                if (browsableAttr != null && !browsableAttr.Browsable)
                {
                    continue;                                                    //don't show attributes marked not browsable
                }
                attrs = prop.GetCustomAttributes(typeof(System.ComponentModel.ReadOnlyAttribute), true);
                System.ComponentModel.ReadOnlyAttribute readOnlyAttr = (System.ComponentModel.ReadOnlyAttribute)(attrs.Length > 0 ? attrs[0] : null);
                if (readOnlyAttr != null && readOnlyAttr.IsReadOnly)
                {
                    continue;                                                  //don't show attributes marked read only
                }
                if (prop.PropertyType.Namespace != "System" && !prop.PropertyType.IsPrimitive && !prop.PropertyType.IsValueType && !prop.PropertyType.IsEnum)
                {
                    continue;
                }
                if (prop.PropertyType == typeof(DateTime))
                {
                    continue;
                }
                if (prop.PropertyType == typeof(string))
                {
                    continue;
                }
                if (prop.Name == "VersionBuild")
                {
                    continue;
                }
                if (prop.Name == "VersionMajor")
                {
                    continue;
                }
                if (prop.Name == "VersionMinor")
                {
                    continue;
                }
                if (prop.Name == "PackageType")
                {
                    continue;
                }

                object value        = prop.GetValue(o, null);
                object defaultValue = prop.GetValue(defaultObject, null);
                if (defaultValue != null && !defaultValue.Equals(value))
                {
                    string sValue = (value == null ? string.Empty : value.ToString());
                    this.listNonDefaultProperties.Add(new NonDefaultProperty(this.DatabaseName, FriendlyPath, prop.Name, defaultValue.ToString(), sValue));
                }
            }

            if (o is IDTSObjectHost)
            {
                IDTSObjectHost host = (IDTSObjectHost)o;
                if (host.InnerObject is Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipe)
                {
                    properties = typeof(Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipe).GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance);
                }
                else if (host.InnerObject is IDTSConnectionManagerDatabaseParametersXX)
                {
                    properties = typeof(IDTSConnectionManagerDatabaseParametersXX).GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance);
                }
                else //probably won't turn up any properties because reflection on a COM object Type doesn't work
                {
                    properties = host.InnerObject.GetType().GetProperties(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance);
                }

                foreach (PropertyInfo prop in properties)
                {
                    if (!prop.CanWrite || !prop.CanRead)
                    {
                        continue;
                    }

                    object[] attrs = prop.GetCustomAttributes(typeof(System.ComponentModel.BrowsableAttribute), true);
                    System.ComponentModel.BrowsableAttribute browsableAttr = (System.ComponentModel.BrowsableAttribute)(attrs.Length > 0 ? attrs[0] : null);
                    if (browsableAttr != null && !browsableAttr.Browsable)
                    {
                        continue;                                                    //don't show attributes marked not browsable
                    }
                    attrs = prop.GetCustomAttributes(typeof(System.ComponentModel.ReadOnlyAttribute), true);
                    System.ComponentModel.ReadOnlyAttribute readOnlyAttr = (System.ComponentModel.ReadOnlyAttribute)(attrs.Length > 0 ? attrs[0] : null);
                    if (readOnlyAttr != null && readOnlyAttr.IsReadOnly)
                    {
                        continue;                                                  //don't show attributes marked read only
                    }
                    if (prop.PropertyType.Namespace != "System" && !prop.PropertyType.IsPrimitive && !prop.PropertyType.IsValueType && !prop.PropertyType.IsEnum)
                    {
                        continue;
                    }
                    if (prop.PropertyType == typeof(DateTime))
                    {
                        continue;
                    }
                    if (prop.PropertyType == typeof(string))
                    {
                        continue;
                    }
                    if (prop.Name == "VersionBuild")
                    {
                        continue;
                    }
                    if (prop.Name == "VersionMajor")
                    {
                        continue;
                    }
                    if (prop.Name == "VersionMinor")
                    {
                        continue;
                    }
                    if (prop.Name == "PackageType")
                    {
                        continue;
                    }
                    if (prop.Name.StartsWith("IDTS"))
                    {
                        continue;
                    }

                    object value;
                    object defaultValue;
                    if (host.InnerObject is Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipe)
                    {
                        try
                        {
                            value = host.InnerObject.GetType().InvokeMember(prop.Name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance, null, host.InnerObject, null);
                        }
                        catch
                        {
                            continue;
                        }
                        try
                        {
                            defaultValue = ((IDTSObjectHost)defaultObject).InnerObject.GetType().InvokeMember(prop.Name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance, null, ((IDTSObjectHost)defaultObject).InnerObject, null);
                        }
                        catch
                        {
                            defaultValue = null;
                        }
                    }
                    else
                    {
                        value        = prop.GetValue(host.InnerObject, null);
                        defaultValue = prop.GetValue(((IDTSObjectHost)defaultObject).InnerObject, null);
                    }
                    if (defaultValue != null && !defaultValue.Equals(value))
                    {
                        string sValue = (value == null ? string.Empty : value.ToString());
                        this.listNonDefaultProperties.Add(new NonDefaultProperty(this.DatabaseName, FriendlyPath, prop.Name, defaultValue.ToString(), sValue));
                    }
                }

                //scan data flow transforms
                if (host.InnerObject is Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipe)
                {
                    Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipe pipe        = (Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipe)host.InnerObject;
                    Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipe defaultPipe = (Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipe)((IDTSObjectHost)defaultObject).InnerObject;
                    foreach (IDTSComponentMetaDataXX transform in pipe.ComponentMetaDataCollection)
                    {
                        IDTSComponentMetaDataXX defaultTransform = defaultPipe.ComponentMetaDataCollection.New();
                        defaultTransform.ComponentClassID = transform.ComponentClassID;
                        CManagedComponentWrapper defaultInst = defaultTransform.Instantiate();
                        try
                        {
                            defaultInst.ProvideComponentProperties();
                        }
                        catch
                        {
                            continue; //if there's a corrupt package (or if you don't have the component installed on your laptop?) then this might fail... so just move on
                        }

                        if (!transform.ValidateExternalMetadata) //this property isn't in the CustomPropertyCollection, so we have to check it manually
                        {
                            this.listNonDefaultProperties.Add(new NonDefaultProperty(this.DatabaseName, FriendlyPath + "\\" + transform.Name, "ValidateExternalMetadata", "True", "False"));
                        }
                        foreach (IDTSOutputXX output in transform.OutputCollection) //check for error row dispositions
                        {
                            if (output.ErrorRowDisposition == DTSRowDisposition.RD_IgnoreFailure)
                            {
                                this.listNonDefaultProperties.Add(new NonDefaultProperty(this.DatabaseName, FriendlyPath + "\\" + transform.Name + "\\" + output.Name, "ErrorRowDisposition", "FailComponent", "IgnoreFailure"));
                            }
                            if (output.TruncationRowDisposition == DTSRowDisposition.RD_IgnoreFailure)
                            {
                                this.listNonDefaultProperties.Add(new NonDefaultProperty(this.DatabaseName, FriendlyPath + "\\" + transform.Name + "\\" + output.Name, "TruncationRowDisposition", "FailComponent", "IgnoreFailure"));
                            }
                        }

                        Microsoft.DataTransformationServices.Design.PipelinePropertiesWrapper propWrapper = new Microsoft.DataTransformationServices.Design.PipelinePropertiesWrapper(transform, transform, 0);

                        foreach (IDTSCustomPropertyXX prop in transform.CustomPropertyCollection)
                        {
                            System.ComponentModel.PropertyDescriptor propDesc = (System.ComponentModel.PropertyDescriptor)propWrapper.GetType().InvokeMember("CreateCustomPropertyPropertyDescriptor", BindingFlags.DeclaredOnly | BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance, null, propWrapper, new object[] { prop });
                            if (propDesc == null)
                            {
                                continue;
                            }
                            if (propDesc.IsReadOnly)
                            {
                                continue;
                            }
                            if (!propDesc.IsBrowsable)
                            {
                                continue;
                            }
                            if (prop.Value is string)
                            {
                                continue;
                            }
                            if (prop.Value is DateTime)
                            {
                                continue;
                            }
                            IDTSCustomPropertyXX defaultProp;
                            try
                            {
                                defaultProp = defaultTransform.CustomPropertyCollection[prop.Name];
                            }
                            catch
                            {
                                if (prop.Name == "PreCompile" && bool.Equals(prop.Value, false)) //this property doesn't show up in the new script component we created to determine defaults, so we have to check it manually
                                {
                                    this.listNonDefaultProperties.Add(new NonDefaultProperty(this.DatabaseName, FriendlyPath + "\\" + transform.Name, prop.Name, "True", "False"));
                                }
                                continue;
                            }

                            System.ComponentModel.ITypeDescriptorContext context = new PipelinePropertyContext(transform, propDesc);
                            string sValue        = propDesc.Converter.ConvertToString(context, prop.Value);        //gets nice text descriptions for enums on component properties
                            string sDefaultValue = propDesc.Converter.ConvertToString(context, defaultProp.Value); //gets nice text descriptions for enums on component properties
                            if (sValue == sDefaultValue)
                            {
                                continue;
                            }

                            this.listNonDefaultProperties.Add(new NonDefaultProperty(this.DatabaseName, FriendlyPath + "\\" + transform.Name, prop.Name, sDefaultValue, sValue));
                        }

                        defaultPipe.ComponentMetaDataCollection.RemoveObjectByID(defaultTransform.ID);
                    }
                }
            }
        }
Exemplo n.º 19
0
 private static IDTSComponentMetaDataXX[] GetUpstreamComponents(IDTSComponentMetaDataXX component, IDTSPathCollectionXX paths)
 {
     List<IDTSComponentMetaDataXX> componentsToReturn = new List<IDTSComponentMetaDataXX>();
     
     foreach (IDTSPathXX upstream in paths)
     {
         if (upstream.EndPoint.Component.ID == component.ID)
         {
             if (!componentsToReturn.Contains(upstream.StartPoint.Component))
             {
                 componentsToReturn.Add(upstream.StartPoint.Component);
                 componentsToReturn.AddRange(GetUpstreamComponents(upstream.StartPoint.Component, paths));
             }
         }
     }
     return componentsToReturn.ToArray();
 }