using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace WeldingCommon.Utils { public class ChangeChecker { private static Dictionary mapping = new Dictionary(); public static bool IsChangedBool(string Resource, bool value, bool defaultVal = false) { if (mapping.ContainsKey(Resource) == false) { mapping[Resource] = defaultVal; return false; } if (mapping[Resource] == value) { return false; } mapping[Resource] = value; return true; } public static bool IsChangedBoolMonitoring(string Resource, bool value, bool MonitoringValue, bool defaultVal = false) { if (mapping.ContainsKey(Resource) == false) { mapping[Resource] = defaultVal; return false; } if (mapping[Resource] == value) { return false; } mapping[Resource] = value; if(mapping[Resource] == MonitoringValue) return true; return false; } private static Dictionary mappingInt = new Dictionary(); public static bool IsChangedInt(string Resource, int value, int defaultVal = 0) { if (mappingInt.ContainsKey(Resource) == false) { mappingInt[Resource] = defaultVal; return false; } if (mappingInt[Resource] == value) { return false; } mappingInt[Resource] = value; return true; } public static bool IsChangedInt(string Resource, int value, out int prevalue, int defaultVal = 0) { if (mappingInt.ContainsKey(Resource) == false) { mappingInt[Resource] = defaultVal; prevalue = mappingInt[Resource]; return false; } if (mappingInt[Resource] == value) { prevalue = value; return false; } prevalue = mappingInt[Resource]; mappingInt[Resource] = value; return true; } } }