Azure 逻辑应用程序无法使用 ASP.Net SDK 以编程方式构建和/或条件

Azure Logic Apps can't programmatically build And / Or Condition using ASP.Net SDK

我正在逻辑应用程序中以编程方式构建条件。如果用户选择 Or,我使用 Or 条件。如果用户选择 And,我使用 And 条件。

我可以让 Or 自己工作。我也可以让 And 自己工作。

public class Expression
        {
            public Or[] or { get; set; }
        }


public class Expression
        {
            public And[] and { get; set; }
        }

当我尝试使用下面的表达式 class 时,我收到“条件有 2 个顶级属性。只允许 1 个。”错误。

public class Expression
    {
        public Or[] or { get; set; }
        public And[] and { get; set; }
    }

如果我将 one 设置为 null,则会出现错误。如果我将 one 设置为一个空数组,则会出现错误。

更新 1

这是 Azure 中的逻辑应用程序代码视图。

"expression": {
                "and": 
                 [
                    {
                      "contains": [
                          "@outputs('Compose_3')",
                          "foo"
                     ]
                    },
                    {
                       "contains": [
                           "@outputs('Compose_3')",
                           "bar"
                     ]
                    }
                  ]
                },

有谁知道如何让它工作?我在这里错过了一些简单的东西吗?任何帮助深表感谢。提前致谢!

Logic App 具有默认的 AND / OR 和其他 条件运算符 。如果要添加自定义条件,可以使用 Azure 函数。在 Azure Function 中,您可以实现您的自定义需求,这是实现您的逻辑思想的正确环境。

你可以在逻辑应用程序中包含 Azure Functions 来执行你的任务。参考 here

或者我们还有另一种选择来实现自定义要求,即 Logic App Custom Connector. Please have a look here

我终于搞定了。序列化 JSON 时,使用“IgnoreNullValues = true”。当您在 Expression 对象中设置 And 或 Or 值时,这将忽略出现的 null 值。 ReplaceFirst 只是在第一次出现时向单词“schema”添加一个“$”。

var options = new JsonSerializerOptions { WriteIndented = true, IgnoreNullValues = true};
            string jsonString = ReplaceFirst(JsonSerializer.Serialize(myApp, options), "schema", "$schema").Replace("_else", "else").Replace("_foreach", "foreach");

string ReplaceFirst(string text, string search, string replace)
        {
            int pos = text.IndexOf(search);
            if (pos < 0)
            {
                return text;
            }
            return text.Substring(0, pos) + replace + text.Substring(pos + search.Length);
        }