BizTalk中的Loopable自定义functoid

时间:2018-03-02 08:20:51

标签: biztalk biztalk-mapper

我有两种类型的自定义functoid。

Custom functoid

第一个:

public class MyClass : BaseFunctoid
{

    public MyClass() : base()
    {
        // Settings for functoid

        this.SetExternalFunctionName(this.GetType().Assembly.FullName, this.GetType().FullName, "MyMethod");
        this.SetMinParams(2);
        this.SetMaxParams(2);

        this.AddInputConnectionType(ConnectionType.Element | ConnectionType.Field);
        this.AddInputConnectionType(ConnectionType.Element | ConnectionType.Field | ConnectionType.FunctoidCount | ConnectionType.FunctoidMath | ConnectionType.FunctoidString);
        this.OutputConnectionType = ConnectionType.Record | ConnectionType.Element | ConnectionType.Field | ConnectionType.FunctoidLooping;

        this.HasSideEffects = false;
    }

    public string[] MyMethod(string arg1, int arg2)
    {
        // do something

        return returnArray;
    }
}

这将创建以下xsl:

<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 userCSharp" version="1.0" xmlns:ns0="urn:mySchema1/1.0.0" xmlns:s0="urn:mySchema2/1.0.0" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp">
    <xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />

    <xsl:template match="/">
        <xsl:apply-templates select="/s0:Root" />
    </xsl:template>

    <xsl:template match="/s0:Root">
        <ns0:DestinationRoot>
            <ns0:sync>
                <xsl:for-each select="s0:RepeatingNode">
                    <xsl:variable name="var:v1" select="position()" />
                    <ns0:statement>
                        <xsl:attribute name="sqlType">
                            <xsl:text>Update</xsl:text>
                        </xsl:attribute>
                        <xsl:attribute name="script">
                            <xsl:value-of select="$var:v1" />
                        </xsl:attribute>
                    </ns0:statement>
                </xsl:for-each>
            </ns0:sync>
        </ns0:DestinationRoot>
    </xsl:template>

    <msxsl:script language="C#" implements-prefix="userCSharp"><![CDATA[

    ]]></msxsl:script>
</xsl:stylesheet>

第二个:

public class MyClass : BaseFunctoid
{

    public MyClass() : base()
    {
        // Settings for functoid

        this.AddScriptTypeSupport(ScriptType.CSharp);
        this.SetScriptBuffer(ScriptType.CSharp, GetCSharpBuffer());
        this.SetMinParams(2);
        this.SetMaxParams(2);

        this.AddInputConnectionType(ConnectionType.Element | ConnectionType.Field);
        this.AddInputConnectionType(ConnectionType.Element | ConnectionType.Field | ConnectionType.FunctoidCount | ConnectionType.FunctoidMath | ConnectionType.FunctoidString);
        this.OutputConnectionType = ConnectionType.Record | ConnectionType.Element | ConnectionType.Field | ConnectionType.FunctoidLooping;

        this.HasSideEffects = false;
    }

    private string GetCSharpBuffer()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("\n");
        sb.Append("public string[] MyMethod(string arg1, int arg2)\n");
        sb.Append("{\n");
        sb.Append("\t// do something\n");
        sb.Append("\treturn returnArray;\n");
        sb.Append("}");

        return sb.ToString();
    }

    public string[] MyMethod(string arg1, int arg2)
    {
        // do something

        return returnArray;
    }
}

创建以下xsl:

<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 userCSharp" version="1.0" xmlns:ns0="urn:mySchema1/1.0.0" xmlns:s0="urn:mySchema2/1.0.0" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />

<xsl:template match="/">
    <xsl:apply-templates select="/s0:Root" />
</xsl:template>

<xsl:template match="/s0:Root">
    <ns0:DestinationRoot>
        <ns0:sync>
            <xsl:for-each select="s0:RepeatingNode">
                <xsl:variable name="var:v1" select="position()" />
                    <ns0:statement>
                        <xsl:attribute name="sqlType">
                            <xsl:text>Update</xsl:text>
                        </xsl:attribute>
                        <xsl:attribute name="script">
                            <xsl:value-of select="$var:v1" />
                        </xsl:attribute>
                    </ns0:statement>
                </xsl:for-each>
            </ns0:sync>
        </ns0:DestinationRoot>
    </xsl:template>
    <msxsl:script language="C#" implements-prefix="userCSharp"><![CDATA[

        public string[] TestMethod(string input, int maxPerItem)
        {
            return returnArray;
        }

    ]]></msxsl:script>
</xsl:stylesheet>

在这两种情况下,都会创建以下XML:

<ns0:DestinationRoot xmlns:ns0="urn:mySchema1/1.0.0">
    <ns0:sync>
        <ns0:statement sqlType="Update" script="1" />
    </ns0:sync>
</ns0:DestinationRoot>

XmlNodeList作为返回类型,我为此列表中的每个节点获取一个项目。但只有柜台才会提高这个数字。代码将不会被执行。

这个functoid的意图是我希望通过某些条件(而不是指定的字符)从输入XML中拆分字段,并且对于每个项目,我需要输出XML中的元素以及此项的值。但是在这个配置中,我只得到一个计数器,并且functoid函数不会被调用。

我有什么办法可以通过循环functoid循环使用functoid并调用functoid的代码。

提前致谢。

0 个答案:

没有答案