2026-01-26 14:51:28 +09:00

86 lines
2.9 KiB
C#

/*
* Copyright (c) 2025 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using Hermes;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VisionCommon {
internal class RecipeUpdater_01_02 : Updater {
private const string KEY_LOW_VERSION = nameof(UnitRecipe.UnitName);
private const string KEY_HIGH_VERSION = "UnitName_02";
public RecipeUpdater_01_02()
: base(nameof(RecipeUpdater_01_02), 0.1, 0.2) {
}
protected override int Upgrade(JToken machineToken) {
_logger.FuncI();
string KEY_UPDATE_ITEM = KEY_LOW_VERSION;
var removeTokenList = new List<JToken>();
try {
foreach (JToken recipe in RecipeUpdaterUtil.GetUnitRecipes(machineToken)) {
foreach (JToken item in recipe) {
if (RecipeUpdaterUtil.KeyEquals(item, KEY_UPDATE_ITEM)) {
removeTokenList.Add(item);
}
}
}
foreach (var token in removeTokenList) {
JToken oldItem = token.Parent.SelectToken(KEY_UPDATE_ITEM);
if (oldItem != null) {
string oldValue = oldItem.Value<string>();
token.AddBeforeSelf(new JProperty(KEY_HIGH_VERSION, JToken.FromObject(KEY_HIGH_VERSION)));
token.Remove();
}
}
}
catch (Exception e) {
_logger.E(e.Message);
return E1.GENERIC;
}
return E1.OK;
}
protected override int Downgrade(JToken machineToken) {
_logger.FuncI();
string KEY_UPDATE_ITEM = KEY_HIGH_VERSION;
var removeTokenList = new List<JToken>();
try {
foreach (JToken recipe in RecipeUpdaterUtil.GetUnitRecipes(machineToken)) {
foreach (JToken item in recipe) {
if (RecipeUpdaterUtil.KeyEquals(item, KEY_UPDATE_ITEM)) {
removeTokenList.Add(item);
}
}
}
foreach (var token in removeTokenList) {
JToken oldItem = token.Parent.SelectToken(KEY_UPDATE_ITEM);
if (oldItem != null) {
string oldValue = oldItem.Value<string>();
token.AddBeforeSelf(new JProperty(KEY_LOW_VERSION, JToken.FromObject(KEY_LOW_VERSION)));
token.Remove();
}
}
}
catch (Exception e) {
_logger.E(e.Message);
return E1.GENERIC;
}
return E1.OK;
}
}
}