如何根据生成的代码编译BIMLScript?

问题描述 投票:1回答:1

我正在使用BIML创建一个ScriptComponenteSource,其中有一个ScriptComponentProject.该项目包含以下内容(取自Varigence样本)。

<ScriptProjects>
    <ScriptComponentProject Name="SC_AD-Accounts" TargetFrameworkVersion="NetFX461">
        <AssemblyReferences>
            <AssemblyReference AssemblyPath="System" />
            <AssemblyReference AssemblyPath="System.Data" />
            <AssemblyReference AssemblyPath="System.Windows.Forms" />
            <AssemblyReference AssemblyPath="System.Xml" />
            <AssemblyReference AssemblyPath="Microsoft.SqlServer.TxScript" />
            <AssemblyReference AssemblyPath="Microsoft.SqlServer.DTSRuntimeWrap" />
            <AssemblyReference AssemblyPath="Microsoft.SqlServer.DTSPipelineWrap" />
            <AssemblyReference AssemblyPath="Microsoft.SqlServer.PipelineHost" />
            <AssemblyReference AssemblyPath="System.DirectoryServices" />
        </AssemblyReferences>

        <OutputBuffers>
            <OutputBuffer Name="Output0">
                <Columns>
                    <Column Name="UUId" DataType="String" Length="255" />
                    <Column Name="Surname" DataType="String" Length="255" />
                    <Column Name="GivenName" DataType="String" Length="255" />
                    <Column Name="EmailAddress" DataType="String" Length="255" />
                    <Column Name="UPN" DataType="String" Length="255" />
                </Columns>
            </OutputBuffer>
        </OutputBuffers>

        <Files>
            <File Path="main.cs"><![CDATA[
using System;
using System.Data;
using System.DirectoryServices;
using Microsoft.SqlServer.Dts.Pipeline;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public partial class ScriptMain : UserComponent
{
    public override void CreateNewOutputRows()
    {
        /*
          Add rows by calling the AddRow method on the member variable named "<Output Name>Buffer".
          For example, call MyOutputBuffer.AddRow() if your output was named "MyOutput".
        */

        var searchBaseNames = new [] {
            "OU=UserP,OU=User,DC=MyDC",
            "OU=UserPS,OU=User,DC=MyDC",
            "OU=UserPSC,OU=User,DC=MyDC"
        };

        var propertiesToLoad = new [] {
            "sn",
            "givenName",
            "mail",
            "userPrincipalName",
            "objectGuid",
            "serialNumber"
        };

        foreach (var searchBaseName in searchBaseNames) {
            var searchBaseEntry = new DirectoryEntry("LDAP://" + searchBaseName);

            var directorySearcher = new DirectorySearcher(searchBaseEntry, "(objectClass=user)", propertiesToLoad, SearchScope.Subtree) {
                PageSize = 2500
            };

            foreach (SearchResult searchResult in directorySearcher.FindAll()) {
                var surname = searchResult.Properties["sn"][0] as string;
                var givenName = searchResult.Properties["givenName"][0] as string;
                var email = searchResult.Properties["mail"][0] as string;
                var upn = searchResult.Properties["userPrincipalName"][0] as string;

                string uuid = null;

                if(searchResult.Properties.Contains("serialNumber"))
                {
                    uuid = searchResult.Properties["serialNumber"][0] as string;
                    if(!string.IsNullOrEmpty(uuid))
                        uuid = uuid;
                }

                if(string.IsNullOrEmpty(uuid))
                {
                    var objectGuidBytes = searchResult.Properties["objectGuid"][0] as byte[];
                    var objectGuid = new Guid(objectGuidBytes);

                    uuid = objectGuid.ToString();
                }

                if(string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(givenName) || 
                   string.IsNullOrEmpty(upn) || string.IsNullOrEmpty(email))
                {
                    continue;
                }

                Output0Buffer.AddRow();
                Output0Buffer.Surname = surname;
                Output0Buffer.GivenName = givenName;
                Output0Buffer.UPN = upn;
                Output0Buffer.EmailAddress = email;
            }
        }
    }
}
            ]]></File>
        </Files>
    </ScriptComponentProject>
</ScriptProjects>

由于BIML-expansion不知道Output0Buffer和overriden方法(它们将被自动创建),这将无法编译。

有没有办法解决这个母鸡蛋的问题?

ssis biml
1个回答
2
投票

我在博客上写过。https:/billfellows.blogspot.com201510biml-script-component-source.html。

你需要为输出缓冲区指定IsSynchronous属性为false。否则,它将把该组件视为同步变换。

<OutputBuffer Name="Output0" IsSynchronous="false">

好我在评论我的代码

        <OutputBuffers>
            <!--    
            Define what your buffer is called and what it looks like
            Must set IsSynchronous as false. Otherwise it is a transformation
            (one row enters, one row leaves) and not a source.
            -->
            <OutputBuffer Name="DemoOutput" IsSynchronous="false">
                <Columns>
                    <Column Name="SourceColumn" DataType="String" Length="50" /> 
                </Columns>                    
            </OutputBuffer>                                 
        </OutputBuffers>
© www.soinside.com 2019 - 2024. All rights reserved.