簡體   English   中英

比較邏輯應用中的兩個版本

[英]Compare two versions in logic apps

我有兩個版本字符串,我需要像 .NET Version類型那樣比較它們(知道主要版本、次要版本,而不僅僅是字符串)以查看哪個更新。 我的問題是:如何檢查邏輯應用程序中哪個版本字符串較新?

有沒有比字符串操作的“蠻力”方法更好的方法?

major = split(variables('CurrentImageVer', '.'))[0]
minor = split(variables('CurrentImageVer', '.'))[1]

等等...

我同意@Skin,因為版本本身是字符串類型,這可以通過字符串操作來完成。 以下是從我這邊復制后對我有用的東西。

出於演示目的,我在數組變量中使用了以下 2 個版本。

[
  "1.2.31",
  "1.2.30"
]
  • 首先,我試圖從數組中拆分兩個版本。

    在此處輸入圖像描述

  • 然后我使用條件連接器檢查版本 1 是否大於另一個。

    在此處輸入圖像描述在此處輸入圖像描述

結果:

在此處輸入圖像描述

下面是我的邏輯應用程序的完整 JSON。

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@variables('Latest Version')",
                "runAfter": {
                    "Until": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Flag": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Flag",
                            "type": "integer",
                            "value": 0
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Versions",
                            "type": "array",
                            "value": [
                                "1.2.31",
                                "1.2.30"
                            ]
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "Latest_Version": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Latest Version",
                            "type": "string",
                            "value": "Latest Not Found"
                        }
                    ]
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "InitializeVariable"
            },
            "Split_Version1": {
                "inputs": "@split(variables('Versions')[0],'.')",
                "runAfter": {
                    "Latest_Version": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Split_Version2": {
                "inputs": "@split(variables('Versions')[1],'.')",
                "runAfter": {
                    "Flag": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Until": {
                "actions": {
                    "Condition": {
                        "actions": {
                            "Set_variable_2": {
                                "inputs": {
                                    "name": "Latest Version",
                                    "value": "@{variables('Versions')[0]} is the latest version"
                                },
                                "runAfter": {},
                                "type": "SetVariable"
                            }
                        },
                        "else": {
                            "actions": {
                                "Condition_2": {
                                    "actions": {
                                        "Set_variable": {
                                            "inputs": {
                                                "name": "Latest Version",
                                                "value": "@{variables('Versions')[1]} is the latest version"
                                            },
                                            "runAfter": {},
                                            "type": "SetVariable"
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "less": [
                                                    "@outputs('Split_Version1')[variables('Flag')]",
                                                    "@outputs('Split_Version2')[variables('Flag')]"
                                                ]
                                            },
                                            {
                                                "equals": [
                                                    "@variables('Latest Version')",
                                                    "Latest Not Found"
                                                ]
                                            }
                                        ]
                                    },
                                    "runAfter": {},
                                    "type": "If"
                                }
                            }
                        },
                        "expression": {
                            "and": [
                                {
                                    "greater": [
                                        "@outputs('Split_Version1')[variables('Flag')]",
                                        "@outputs('Split_Version2')[variables('Flag')]"
                                    ]
                                },
                                {
                                    "equals": [
                                        "@variables('Latest Version')",
                                        "Latest Not Found"
                                    ]
                                }
                            ]
                        },
                        "runAfter": {},
                        "type": "If"
                    },
                    "Increment_variable": {
                        "inputs": {
                            "name": "Flag",
                            "value": 1
                        },
                        "runAfter": {
                            "Condition": [
                                "Succeeded"
                            ]
                        },
                        "type": "IncrementVariable"
                    }
                },
                "expression": "@equals(variables('Flag'), length(outputs('Split_Version1')))",
                "limit": {
                    "count": 60,
                    "timeout": "PT1H"
                },
                "runAfter": {
                    "Split_Version1": [
                        "Succeeded"
                    ],
                    "Split_Version2": [
                        "Succeeded"
                    ]
                },
                "type": "Until"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM