private void SetMaxVarLength(IList<SingleValue> eqVars, IList<SingleValue> eqConstants) { int maxVarLen = 0; foreach (var item in eqVars) { if (item?.Name?.Length > maxVarLen) { maxVarLen = item.Name.Length; } } foreach (var item in eqConstants) { if (item?.Name?.Length > maxVarLen) { maxVarLen = item.Name.Length; } } _maxVarLength = maxVarLen; OnPropertyChanged("MaxVarLength"); MaxVarLengthChanged?.Invoke(this, null); }
private void SetMaxUOMLength() { try { int maxUOMLength = 0; foreach (var item in EqCalcVariables) { if (item?.UomSymbol?.Length > maxUOMLength) { maxUOMLength = item.UomSymbol.Length; } } _maxUOMLength = maxUOMLength; OnPropertyChanged("MaxUomLength"); MaxVarLengthChanged?.Invoke(this, null); } catch (Exception ex) { Logging.LogException(ex); throw; } }
// ------------------------------ private void SetEqCalcVarInfos() { if (EquationCalc == null) { return; //Might just be a temporary syntax error, so we don't want to lose all our variable definitions } IList <SingleValue> eqVars = EquationCalc?.FindAllVariables() ?? (new List <SingleValue>()); // ------------- int maxVarLen = 0; foreach (var item in eqVars) { if (item?.Name?.Length > maxVarLen) { maxVarLen = item.Name.Length; } } MaxVarLength = maxVarLen; MaxVarLengthChanged?.Invoke(this, null); // ------------- IList <VmEqCalcVarInfo> toRemove = new List <VmEqCalcVarInfo>(); // ------------ Remove the hacks for (int i = EqCalcVarInfos.Count - 1; i >= 0; i--) { VmEqCalcVarInfo ei = EqCalcVarInfos[i]; if (ei.Name == null) { EqCalcVarInfos.Remove(ei); } } foreach (var ei in EqCalcVarInfos) { if (ei.Name == null) { EqCalcVarInfos.Remove(ei); } } foreach (var ei in EqCalcVarInfos) { toRemove.Add(ei); } // ------------ Add new items and note those still needed for (int i = 0; i < eqVars.Count; i++) { var sv = eqVars[i]; sv.ClearAllVarVals(); bool bFound = false; foreach (var ei in toRemove) { if (ei.Name.Equals(sv.Name)) { bFound = true; toRemove.Remove(ei); //still needed break; } } if (!bFound) { EqCalcVarInfos.Add(new VmEqCalcVarInfo(this, sv)); } } // ------------ Remove any no longer needed foreach (var ei in toRemove) { EqCalcVarInfos.Remove(ei); } }