示例#1
0
        public Executable AddTask <T>(EntityTypeConfiguration <T> map, ConnectionManager manager) where T : class
        {
            FileInfo fileInfo            = new FileInfo(manager.ConnectionString);
            string   fileName            = fileInfo.Name.Substring(0, fileInfo.Name.Length - 4);
            string   dataFlowName        = $"Data Flow from {fileName} to {map.GetTableName()} in the {map.GetSchemaName()} Schema";
            string   dataFlowDescription = $"This data flow task will transfer the records from {manager.ConnectionString} to the {map.GetFullTableName()}";

            Executable executable = CensusPackageExecutables.Contains(dataFlowName)
                                        ? CensusPackageExecutables[dataFlowName]
                                        : CensusPackageExecutables.Add("STOCK:PipelineTask");
            TaskHost task = executable as TaskHost;

            if (task == null)
            {
                throw new ArgumentException("Failed to retrieve executable as TaskHost!");
            }

            task.Name        = dataFlowName;
            task.Description = dataFlowDescription;

            MainPipe dataFlow = task.InnerObject as MainPipe;

            if (dataFlow == null)
            {
                throw new ArgumentException("Unable to retrieve task as a MainPipe!");
            }

            dataFlow.ComponentMetaDataCollection.RemoveAll();
            dataFlow.Events = DtsConvert.GetExtendedInterface(new SSISComponentEventHandler());

            #region Source
            IDTSComponentMetaData100 source = dataFlow.ComponentMetaDataCollection.New();
            source.Name             = $"{FlatFileSourceComponentInfo.Name} reference to {fileName}";
            source.Description      = $"This component will read all of the records located in {fileInfo.FullName}";
            source.ContactInfo      = "Anthony Hart | [email protected]";
            source.ComponentClassID = FlatFileSourceComponentInfo.CreationName;

            CManagedComponentWrapper sourceWrapper = source.Instantiate();
            sourceWrapper.ProvideComponentProperties();

            source.RuntimeConnectionCollection[0].ConnectionManager   = DtsConvert.GetExtendedInterface(manager);
            source.RuntimeConnectionCollection[0].ConnectionManagerID = manager.ID;

            source.RuntimeConnectionCollection[0].Name        = "FlatFileConnection";
            source.RuntimeConnectionCollection[0].Description = manager.Description;

            sourceWrapper.SetComponentProperty("RetainNulls", true);

            sourceWrapper.AcquireConnections(null);
            sourceWrapper.ReinitializeMetaData();
            sourceWrapper.ReleaseConnections();
            #endregion Source

            #region Destination
            IDTSComponentMetaData100 destination = dataFlow.ComponentMetaDataCollection.New();
            destination.Name             = $"{ADONETDestinationComponentInfo.Name} reference to {map.GetTableName()} in the {map.GetSchemaName()} Schema";
            destination.Description      = $"This component will import all of the records that were read from the {FlatFileSourceComponentInfo.Name} component into the {map.GetFullTableName()} table";
            destination.ContactInfo      = "Anthony Hart | [email protected]";
            destination.ComponentClassID = ADONETDestinationComponentInfo.CreationName;

            CManagedComponentWrapper destinationWrapper = destination.Instantiate();
            destinationWrapper.ProvideComponentProperties();

            destination.RuntimeConnectionCollection[0].ConnectionManager   = DtsConvert.GetExtendedInterface(DefaultConnection);
            destination.RuntimeConnectionCollection[0].ConnectionManagerID = DefaultConnection.ID;
            destination.RuntimeConnectionCollection[0].Name        = "IDbConnection";
            destination.RuntimeConnectionCollection[0].Description = DefaultConnection.Description;

            destinationWrapper.SetComponentProperty("CommandTimeout", 600);
            destinationWrapper.SetComponentProperty("TableOrViewName", map.GetFullTableName());

            destinationWrapper.AcquireConnections(null);
            destinationWrapper.ReinitializeMetaData();
            destinationWrapper.ReleaseConnections();
            #endregion Destination

            #region Pathing
            IDTSPath100 path = dataFlow.PathCollection.New();
            path.AttachPathAndPropagateNotifications(source.OutputCollection[0], destination.InputCollection[0]);
            #endregion

            #region Column Mapping
            IDTSInput100        input        = destination.InputCollection[0];
            IDTSVirtualInput100 virtualInput = input.GetVirtualInput();

            foreach (IDTSVirtualInputColumn100 vColumn in virtualInput.VirtualInputColumnCollection)
            {
                IDTSInputColumn100 vCol = destinationWrapper.SetUsageType(input.ID, virtualInput, vColumn.LineageID, vColumn.Name == "TERMINATOR" ? DTSUsageType.UT_IGNORED : DTSUsageType.UT_READWRITE);
                if (vCol != null)
                {
                    destinationWrapper.MapInputColumn(input.ID, vCol.ID, input.ExternalMetadataColumnCollection[vCol.Name].ID);
                }
            }
            #endregion Column Mapping

            return(executable);
        }
示例#2
0
 public static string GetFullTableName <T>(this EntityTypeConfiguration <T> map) where T : class
 {
     return($"{map.GetSchemaName()}.{map.GetTableName()}");
 }