c# - 在 Azure Logic Apps 中转换 XML,将 C# 程序集 (.DLL) 文件上传到 Azure 集成帐户并在 XSLT(地图)中使用它
问题描述
在 Log Apps 中,我有一个 Source.xml 文件,需要使用 XSLT 将其转换为另一个 destination.xml。在 XSLT 中,我需要使用 C# 代码实现一些自定义逻辑,这些代码将上传到 Azure 集成帐户“程序集部分”
我创建了一个带有 StrongName 的 C# 程序集文件,但需要了解如何从 XSLT 调用 C# 程序集的方法。
如果有人可以通过一个非常基本的示例分享一个工作示例代码,将不胜感激。
解决方案
我找到了一个示例供您参考:
c#代码如下所示:
using System;
namespace ExtAssembly
{
public static class CalcFunctions
{
public static Int64 Add(Int64 a, Int64 b)
{
return a + b;
}
public static Int64 Subtract(Int64 a, Int64 b)
{
return a - b;
}
public static Int64 Multiply(Int64 a, Int64 b)
{
return a * b;
}
public static Double Divide(Int64 a, Int64 b)
{
return a / b;
}
}
}
我们可以在 xslt 中使用 c# 代码,如下所示:
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform Jump " xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl userCSharp" version="1.0" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp Jump ">
<xsl:output omit-xml-declaration="yes" media-type="application/text" method="text" version="1.0" />
<xsl:param name="MethodName" />
<xsl:param name="Parameters" />
<xsl:template match="/">
<xsl:value-of select ="userCSharp:Invoke($MethodName, substring-before(substring-after($Parameters, '('), ')'))" />
</xsl:template>
<msxsl:script language="C#" implements-prefix="userCSharp">
<msxsl:assembly name="ExtAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" />
<msxsl:using namespace="System.Reflection" />
<msxsl:using namespace="System.Text.RegularExpressions" />
<msxsl:using namespace="ExtAssembly" />
<![CDATA[
public object Invoke(string methodName, string methodParameters)
{
MatchCollection matches = new Regex("((?<=\")[^\"]*(?=\"(,|$)+)|(?<=,|^)[^,\"]*(?=,|$))").Matches(methodParameters);
ParameterInfo[] pars = typeof(CalcFunctions).GetMethod(methodName).GetParameters();
object[] methodPars = new object[pars.Length];
for (int i = 0; i < pars.Length; i++)
{
methodPars[i] = Convert.ChangeType(matches[i].Value, pars[i].ParameterType);
}
return typeof(CalcFunctions).GetMethod(methodName).Invoke(null, methodPars);
}
]]>
</msxsl:script>
</xsl:stylesheet>
之后,我们可以在我们的逻辑应用程序中调用它(在“Transform xml”操作中提供“MethodName”和“Parameters”)。
有关详细信息,您可以参考此示例。
希望对您的问题有所帮助。
推荐阅读
- android - 使用 Hilt 依赖注入时无法创建 ViewModel 实例
- javascript - OpenSeadragon 缩放问题
- android - 打开我的 react-native app 时出现此错误。有什么建议么?
- python - 通过使用子字典中键的值对包含子字典的字典进行排序
- python - 将 Pybind 与 Bazel 一起使用但设置 Python 路径?
- ethereum - 如何计算固体百分比
- python-3.x - sympy dsolve 在参数数量上返回 valueerror
- intellij-idea - InteliJ IDEA 中的 Thymeleaf 支持
- sql - 左连接语句没有“客户”列
- java - OkHttp 获取所有 cookie