public static List <UIControl> ParseRawLines(List <string> lines, SectionAddress addr, out List <LogInfo> errorLogs) { // Select Code sections and compile errorLogs = new List <LogInfo>(); List <UIControl> uiCtrls = new List <UIControl>(); for (int i = 0; i < lines.Count; i++) { try { UIControl uiCtrl = ParseUIControl(lines, addr, ref i); if (uiCtrl != null) { // Check if interface control's key is duplicated if (uiCtrls.Count(x => x.Key.Equals(uiCtrl.Key, StringComparison.OrdinalIgnoreCase)) == 0) { uiCtrls.Add(ParseUIControl(lines, addr, ref i)); } else { errorLogs.Add(new LogInfo(LogState.Error, $"Interface key [{uiCtrl.Key}] is duplicated ({uiCtrl.RawLine})")); } } } catch (InvalidUIControlException e) { errorLogs.Add(new LogInfo(LogState.Error, $"{Logger.LogExceptionMessage(e)} ({e.UICtrl.RawLine})")); } catch (InvalidCommandException e) { errorLogs.Add(new LogInfo(LogState.Error, $"{Logger.LogExceptionMessage(e)} ({e.RawLine})")); } catch (Exception e) { errorLogs.Add(new LogInfo(LogState.Error, e)); } } return(uiCtrls.Where(x => x.Type != UIControlType.None).ToList()); }
private static bool RestoreInterface(ref Script sc, InterfaceSectionBackup backup) { (string ifaceSectionName, List <UIControl> uiCtrls, _) = sc.GetInterfaceControls(); if (!ifaceSectionName.Equals(backup.SectionName, StringComparison.OrdinalIgnoreCase)) { return(false); } List <UIControl> bakCtrls = backup.ValueCtrls; List <UIControl> newCtrls = new List <UIControl>(uiCtrls.Count); foreach (UIControl uiCtrl in uiCtrls) { // Get old uiCtrl, equaility identified by Key and Type. UIControl bakCtrl = bakCtrls.FirstOrDefault(bak => bak.Key.Equals(uiCtrl.Key, StringComparison.OrdinalIgnoreCase) && bak.Type == uiCtrl.Type); if (bakCtrl == null) { continue; } // Get old value string bakValue = bakCtrl.GetValue(false); Debug.Assert(bakValue != null, "Internal Logic Error at FileUpdater.RestoreInterface"); // Add to newCtrls only if apply was successful if (uiCtrl.SetValue(bakValue, false, out _)) { newCtrls.Add(uiCtrl); } } // Write to file UIControl.Update(newCtrls); sc = sc.Project.RefreshScript(sc); return(true); }
public static bool KeyEquals(UIControl x, UIControl y) { return(x.Key.Equals(y.Key, StringComparison.OrdinalIgnoreCase)); }
public const double PointToDeviceIndependentPixel = 96f / 72f; // Point - 72DPI, Device Independent Pixel - 96DPI #endregion #region KeyEquals public bool KeyEquals(UIControl y) { return(KeyEquals(this, y)); }