Esempio n. 1
0
        //Validate Inputs  Both InputColumns and ExternalColumns
        private DTSValidationStatus ValidateInputs()
        {
            bool cancel;

            //Component should have a single input
            if (this.ComponentMetaData.InputCollection.Count != 1)
            {
                ErrorSupport.FireErrorWithArgs(HResults.DTS_E_INCORRECTEXACTNUMBEROFINPUTS, out cancel, 1);
                return(DTSValidationStatus.VS_ISCORRUPT);
            }

            //Check input has columns
            var input = ComponentMetaData.InputCollection[INPUT_NAME];

            if (input.ExternalMetadataColumnCollection.Count == 0)
            {
                return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
            }

            //Check input columns are valid
            if (!this.ComponentMetaData.AreInputColumnsValid)
            {
                input.InputColumnCollection.RemoveAll();
                return(DTSValidationStatus.VS_NEEDSNEWMETADATA);
            }

            //Input truncation disposition not supported
            if (input.TruncationRowDisposition != DTSRowDisposition.RD_NotUsed)
            {
                ErrorSupport.FireError(HResults.DTS_E_ADODESTINPUTTRUNDISPNOTSUPPORTED, out cancel);
                return(DTSValidationStatus.VS_ISBROKEN);
            }

            return(DTSValidationStatus.VS_ISVALID);
        }
        //=================================================================================================

        private ManagementObjectCollection ExecWQL(bool bOnlyMetadata)
        {
            if (m_scope == null)
            {
                bool bCancel;
                ErrorSupport.FireError(HResults.DTS_E_CONNECTIONREQUIREDFORMETADATA, out bCancel);
                throw new PipelineComponentHResultException(HResults.DTS_E_CONNECTIONREQUIREDFORMETADATA);
            }

            string wqlQuery = GetWqlString();

            try
            {
                ObjectQuery objectQuery           = new ObjectQuery(wqlQuery);
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(m_scope, objectQuery);
                searcher.Options.PrototypeOnly = bOnlyMetadata;

                ManagementObjectCollection collection = searcher.Get();

                try
                {
                    int count = collection.Count;
                }
                catch (ManagementException e)
                {
                    if (e.ErrorCode == ManagementStatus.InvalidClass ||
                        e.ErrorCode == ManagementStatus.NotFound)
                    {
                        throw new Exception("Invalid WQL query");
                    }
                    else
                    {
                        throw;
                    }
                }

                return(collection);
            }
            catch (Exception e)
            {
                bool bCancel;
                ComponentMetaData.FireError(
                    HResults.DTS_E_ERROROCCURREDWITHFOLLOWINGMESSAGE,
                    ComponentMetaData.Name,
                    "A exception occurred while executing WQL query \"" + wqlQuery + "\". Exception message : " + e.Message,
                    "",
                    0,
                    out bCancel);

                throw new PipelineComponentHResultException(e.Message, HResults.DTS_E_ERROROCCURREDWITHFOLLOWINGMESSAGE);
            }
        }
        //=================================================================================================

        public override void ReinitializeMetaData()
        {
            // baseclass may have some work to do here
            base.ReinitializeMetaData();

            IDTSOutput100 output = ComponentMetaData.OutputCollection[0];

            output.OutputColumnCollection.RemoveAll();
            output.ExternalMetadataColumnCollection.RemoveAll();

            // Execute the WQL query and retrieve metadata
            foreach (PropertyData wmiColumn in GetWmiColumns())
            {
                DataType dtsType;
                int      length;
                int      scale;
                int      precision;
                int      codePage;

                GetWmiColumnProperties(wmiColumn, out dtsType, out length, out scale, out precision, out codePage);

                string Description = (string)GetQualifiers(wmiColumn, "Description", "");

                // create a new column
                IDTSOutputColumn100 outputcolNew = output.OutputColumnCollection.New();

                if (string.IsNullOrEmpty(wmiColumn.Name))
                {
                    bool bCancel;
                    ErrorSupport.FireError(HResults.DTS_E_DATASOURCECOLUMNWITHNONAMEFOUND, out bCancel);
                    throw new PipelineComponentHResultException(HResults.DTS_E_DATASOURCECOLUMNWITHNONAMEFOUND);
                }

                outputcolNew.Name = wmiColumn.Name;
                outputcolNew.SetDataTypeProperties(dtsType, length, precision, scale, codePage);
                outputcolNew.Description = Description;

                CreateExternalMetaDataColumn(output.ExternalMetadataColumnCollection, outputcolNew);
            }

            // Exclusion Group
            output.ExclusionGroup = 0;
            // Synchronous Input
            output.SynchronousInputID = 0;
        }
        public override void AcquireConnections(object transaction)
        {
            if (m_scope != null && m_scope.IsConnected)
            {
                bool bCancel;
                ErrorSupport.FireError(HResults.DTS_E_ALREADYCONNECTED, out bCancel);
                throw new PipelineComponentHResultException(HResults.DTS_E_ALREADYCONNECTED);
            }

            IDTSRuntimeConnection100 conn;

            try
            {
                // get the runtime connection
                conn = ComponentMetaData.RuntimeConnectionCollection[CONNECTION_NAME];
            }
            catch (Exception)
            {
                bool bCancel;
                ErrorSupport.FireErrorWithArgs(HResults.DTS_E_CANNOTTFINDRUNTIMECONNECTIONOBJECT, out bCancel, CONNECTION_NAME);
                throw new PipelineComponentHResultException(HResults.DTS_E_CANNOTTFINDRUNTIMECONNECTIONOBJECT);
            }

            // get the connection manager from the connection
            IDTSConnectionManager100 conn_mgr = conn.ConnectionManager;

            if (conn_mgr == null)
            {
                bool bCancel;
                ErrorSupport.FireErrorWithArgs(HResults.DTS_E_CONNECTIONMANANGERNOTASSIGNED, out bCancel, CONNECTION_NAME);
                throw new PipelineComponentHResultException(HResults.DTS_E_CONNECTIONMANANGERNOTASSIGNED);
            }

            m_scope = (conn_mgr.AcquireConnection(transaction)) as ManagementScope;

            if (m_scope == null)
            {
                bool bCancel;
                ErrorSupport.FireError(HResults.DTS_E_CANNOTACQUIREMANAGEDCONNECTIONFROMCONNECTIONMANAGER, out bCancel);
                throw new PipelineComponentHResultException(HResults.DTS_E_CANNOTACQUIREMANAGEDCONNECTIONFROMCONNECTIONMANAGER);
            }
        }