private void InitializeRegisters() { WorkerThread.RunOperation(async() => { if (_registers != null) { return; // already initialized } string[] names = await MICommandFactory.DataListRegisterNames(); if (_registers != null) { return; // already initialized } EngineUtils.RegisterNameMap nameMap = EngineUtils.RegisterNameMap.Create(names); List <RegisterDescription> desc = new List <RegisterDescription>(); var registerGroups = new List <RegisterGroup>(); for (int i = 0; i < names.Length; ++i) { if (String.IsNullOrEmpty(names[i])) { continue; // ignore the empty names } RegisterGroup grp = GetGroupForRegister(registerGroups, names[i], nameMap); desc.Add(new RegisterDescription(names[i], grp, i)); } _registerGroups = registerGroups.AsReadOnly(); _registers = desc.AsReadOnly(); }); }
private static RegisterGroup GetGroupForRegister(List <RegisterGroup> registerGroups, string name, EngineUtils.RegisterNameMap nameMap) { string grpName = nameMap.GetGroupName(name); RegisterGroup grp = registerGroups.FirstOrDefault((g) => { return(g.Name == grpName); }); if (grp == null) { grp = new RegisterGroup(grpName); registerGroups.Add(grp); } return(grp); }