Example #1
0
        private void frmMasterIndex_Load(object sender, EventArgs e)
        {
            using (var op_load_frm_masterindex = Timekeeper.StartSyncron("op_load_frm_masterindex", null, CustomActivity.OperationType.RequestOperation, null))
            {
                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_populate_entries", op_load_frm_masterindex))
                {
                    ConcurrentBag <ListItem> lstItemsForLoading = new ConcurrentBag <ListItem>();
                    ConcurrentBag <ListItem> lstFileNamesWithItemsForLoading = new ConcurrentBag <ListItem>();
                    Parallel.ForEach(_lstFileNames, strFileName =>
                    {
                        XPathNavigator xmlBaseNode = XmlManager.Load(strFileName).GetFastNavigator().SelectSingleNode("/chummer");
                        if (xmlBaseNode != null)
                        {
                            bool blnLoopFileNameHasItems = false;
                            foreach (XPathNavigator xmlItemNode in xmlBaseNode.Select(".//*[source and page]"))
                            {
                                blnLoopFileNameHasItems = true;
                                string strName          = xmlItemNode.SelectSingleNode("name")?.Value;
                                string strDisplayName   = xmlItemNode.SelectSingleNode("translate")?.Value
                                                          ?? strName
                                                          ?? xmlItemNode.SelectSingleNode("id")?.Value
                                                          ?? LanguageManager.GetString("String_Unknown");
                                string strSource      = xmlItemNode.SelectSingleNode("source")?.Value;
                                string strPage        = xmlItemNode.SelectSingleNode("page")?.Value;
                                string strDisplayPage = xmlItemNode.SelectSingleNode("altpage")?.Value
                                                        ?? strPage;
                                string strEnglishNameOnPage = xmlItemNode.SelectSingleNode("nameonpage")?.Value
                                                              ?? strName;
                                string strTranslatedNameOnPage = xmlItemNode.SelectSingleNode("altnameonpage")?.Value
                                                                 ?? strDisplayName;
                                string strNotes = xmlItemNode.SelectSingleNode("altnotes")?.Value
                                                  ?? xmlItemNode.SelectSingleNode("notes")?.Value;
                                MasterIndexEntry objEntry = new MasterIndexEntry(
                                    strDisplayName,
                                    strFileName,
                                    new SourceString(strSource, strPage, GlobalOptions.DefaultLanguage),
                                    new SourceString(strSource, strDisplayPage, GlobalOptions.Language),
                                    strEnglishNameOnPage,
                                    strTranslatedNameOnPage);
                                lstItemsForLoading.Add(new ListItem(objEntry, strDisplayName));
                                if (!string.IsNullOrEmpty(strNotes))
                                {
                                    _dicCachedNotes.TryAdd(objEntry, strNotes);
                                }
                            }

                            if (blnLoopFileNameHasItems)
                            {
                                lstFileNamesWithItemsForLoading.Add(new ListItem(strFileName, strFileName));
                            }
                        }
                    });

                    foreach (ListItem objItem in lstItemsForLoading)
                    {
                        MasterIndexEntry objEntry        = (MasterIndexEntry)objItem.Value;
                        ListItem         objExistingItem = _lstItems.FirstOrDefault(x =>
                                                                                    ((MasterIndexEntry)x.Value).DisplayName.Equals(objEntry.DisplayName, StringComparison.OrdinalIgnoreCase) &&
                                                                                    ((MasterIndexEntry)x.Value).DisplaySource == objEntry.DisplaySource);
                        if (objExistingItem.Value == null)
                        {
                            _lstItems.Add(objItem); // Not using AddRange because of potential memory issues
                        }
                        else
                        {
                            ((MasterIndexEntry)objExistingItem.Value).FileNames.UnionWith(objEntry.FileNames);
                        }
                    }
                    _lstFileNamesWithItems.AddRange(lstFileNamesWithItemsForLoading);
                }

                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_sort_entries", op_load_frm_masterindex))
                {
                    _lstItems.Sort(CompareListItems.CompareNames);
                    _lstFileNamesWithItems.Sort(CompareListItems.CompareNames);
                }

                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_populate_controls", op_load_frm_masterindex))
                {
                    _lstFileNamesWithItems.Insert(0, new ListItem(string.Empty, LanguageManager.GetString("String_All")));

                    cboFile.BeginUpdate();
                    cboFile.ValueMember   = nameof(ListItem.Value);
                    cboFile.DisplayMember = nameof(ListItem.Name);
                    cboFile.DataSource    = _lstFileNamesWithItems;
                    cboFile.SelectedIndex = 0;
                    cboFile.EndUpdate();

                    lstItems.BeginUpdate();
                    lstItems.ValueMember   = nameof(ListItem.Value);
                    lstItems.DisplayMember = nameof(ListItem.Name);
                    lstItems.DataSource    = _lstItems;
                    lstItems.SelectedIndex = -1;
                    lstItems.EndUpdate();

                    _blnSkipRefresh = false;
                }
            }
        }
Example #2
0
        private async void frmMasterIndex_Load(object sender, EventArgs e)
        {
            using (var op_load_frm_masterindex = Timekeeper.StartSyncron("op_load_frm_masterindex", null, CustomActivity.OperationType.RequestOperation, null))
            {
                HashSet <string> setValidCodes = new HashSet <string>();
                foreach (XPathNavigator xmlBookNode in (await XmlManager.LoadXPathAsync("books.xml")).Select("/chummer/books/book/code"))
                {
                    setValidCodes.Add(xmlBookNode.Value);
                }

                string strSourceFilter = setValidCodes.Count > 0
                    ? new StringBuilder("(")
                                         .AppendJoin(" or ", setValidCodes.Select(x => "source = \'" + x + "\'"))
                                         .Append(')').ToString()
                    : "source";

                ConcurrentBag <ListItem> lstItemsForLoading = new ConcurrentBag <ListItem>();
                ConcurrentBag <ListItem> lstFileNamesWithItemsForLoading = new ConcurrentBag <ListItem>();
                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_load_entries", op_load_frm_masterindex))
                {
                    // Prevents locking the UI thread while still benefitting from static scheduling of Parallel.ForEach
                    await Task.Run(() =>
                    {
                        Parallel.ForEach(_lstFileNames, strFileName =>
                        {
                            XPathNavigator xmlBaseNode = XmlManager.LoadXPath(strFileName);
                            xmlBaseNode = xmlBaseNode.SelectSingleNode("/chummer");
                            if (xmlBaseNode == null)
                            {
                                return;
                            }
                            bool blnLoopFileNameHasItems = false;
                            foreach (XPathNavigator xmlItemNode in xmlBaseNode.Select(".//*[page and " +
                                                                                      strSourceFilter + ']'))
                            {
                                blnLoopFileNameHasItems = true;
                                string strName          = xmlItemNode.SelectSingleNode("name")?.Value;
                                string strDisplayName   = xmlItemNode.SelectSingleNode("translate")?.Value
                                                          ?? strName
                                                          ?? xmlItemNode.SelectSingleNode("id")?.Value
                                                          ?? LanguageManager.GetString("String_Unknown");
                                string strSource      = xmlItemNode.SelectSingleNode("source")?.Value;
                                string strPage        = xmlItemNode.SelectSingleNode("page")?.Value;
                                string strDisplayPage = xmlItemNode.SelectSingleNode("altpage")?.Value
                                                        ?? strPage;
                                string strEnglishNameOnPage = xmlItemNode.SelectSingleNode("nameonpage")?.Value
                                                              ?? strName;
                                string strTranslatedNameOnPage =
                                    xmlItemNode.SelectSingleNode("altnameonpage")?.Value
                                    ?? strDisplayName;
                                string strNotes = xmlItemNode.SelectSingleNode("altnotes")?.Value
                                                  ?? xmlItemNode.SelectSingleNode("notes")?.Value;
                                MasterIndexEntry objEntry = new MasterIndexEntry(
                                    strDisplayName,
                                    strFileName,
                                    new SourceString(strSource, strPage, GlobalOptions.DefaultLanguage,
                                                     GlobalOptions.InvariantCultureInfo),
                                    new SourceString(strSource, strDisplayPage, GlobalOptions.Language,
                                                     GlobalOptions.CultureInfo),
                                    strEnglishNameOnPage,
                                    strTranslatedNameOnPage);
                                lstItemsForLoading.Add(new ListItem(objEntry, strDisplayName));
                                if (!string.IsNullOrEmpty(strNotes))
                                {
                                    _dicCachedNotes.TryAdd(objEntry, strNotes);
                                }
                            }

                            if (blnLoopFileNameHasItems)
                            {
                                lstFileNamesWithItemsForLoading.Add(new ListItem(strFileName, strFileName));
                            }
                        });
                    });
                }

                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_populate_entries", op_load_frm_masterindex))
                {
                    string strSpace  = LanguageManager.GetString("String_Space");
                    string strFormat = "{0}" + strSpace + "[{1}]";
                    Dictionary <string, List <ListItem> > dicHelper = new Dictionary <string, List <ListItem> >(lstItemsForLoading.Count);
                    foreach (ListItem objItem in lstItemsForLoading)
                    {
                        MasterIndexEntry objEntry = (MasterIndexEntry)objItem.Value;
                        string           strKey   = objEntry.DisplayName.ToUpperInvariant();
                        if (dicHelper.TryGetValue(strKey, out List <ListItem> lstExistingItems))
                        {
                            ListItem objExistingItem = lstExistingItems.FirstOrDefault(x =>
                                                                                       objEntry.DisplaySource.Equals(((MasterIndexEntry)x.Value).DisplaySource));
                            if (objExistingItem.Value != null)
                            {
                                ((MasterIndexEntry)objExistingItem.Value).FileNames.UnionWith(objEntry.FileNames);
                            }
                            else
                            {
                                List <ListItem> lstItemsNeedingNameChanges = lstExistingItems.Where(x => !objEntry.FileNames.IsSubsetOf(((MasterIndexEntry)x.Value).FileNames)).ToList();
                                if (lstItemsNeedingNameChanges.Count == 0)
                                {
                                    _lstItems.Add(objItem); // Not using AddRange because of potential memory issues
                                    lstExistingItems.Add(objItem);
                                }
                                else
                                {
                                    ListItem objItemToAdd = new ListItem(objItem.Value, string.Format(GlobalOptions.CultureInfo,
                                                                                                      strFormat, objItem.Name, string.Join(',' + strSpace, objEntry.FileNames)));
                                    _lstItems.Add(objItemToAdd); // Not using AddRange because of potential memory issues
                                    lstExistingItems.Add(objItemToAdd);

                                    foreach (ListItem objToRename in lstItemsNeedingNameChanges)
                                    {
                                        _lstItems.Remove(objToRename);
                                        lstExistingItems.Remove(objToRename);

                                        MasterIndexEntry objExistingEntry = (MasterIndexEntry)objToRename.Value;
                                        objItemToAdd = new ListItem(objToRename.Value, string.Format(GlobalOptions.CultureInfo,
                                                                                                     strFormat, objExistingEntry.DisplayName, string.Join(',' + strSpace, objExistingEntry.FileNames)));
                                        _lstItems.Add(objItemToAdd); // Not using AddRange because of potential memory issues
                                        lstExistingItems.Add(objItemToAdd);
                                    }
                                }
                            }
                        }
                        else
                        {
                            _lstItems.Add(objItem); // Not using AddRange because of potential memory issues
                            dicHelper.Add(strKey, new List <ListItem>(objItem.Yield()));
                        }
                    }
                    _lstFileNamesWithItems.AddRange(lstFileNamesWithItemsForLoading);
                }

                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_sort_entries", op_load_frm_masterindex))
                {
                    _lstItems.Sort(CompareListItems.CompareNames);
                    _lstFileNamesWithItems.Sort(CompareListItems.CompareNames);
                }

                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_populate_controls", op_load_frm_masterindex))
                {
                    _lstFileNamesWithItems.Insert(0, new ListItem(string.Empty, LanguageManager.GetString("String_All")));

                    cboFile.BeginUpdate();
                    cboFile.PopulateWithListItems(_lstFileNamesWithItems);
                    try
                    {
                        cboFile.SelectedIndex = 0;
                    }
                    // For some reason, some unit tests will fire this exception even when _lstFileNamesWithItems is explicitly checked for having enough items
                    catch (ArgumentOutOfRangeException)
                    {
                        cboFile.SelectedIndex = -1;
                    }
                    cboFile.EndUpdate();

                    lstItems.BeginUpdate();
                    lstItems.PopulateWithListItems(_lstItems);
                    lstItems.SelectedIndex = -1;
                    lstItems.EndUpdate();

                    _blnSkipRefresh = false;
                }
            }
        }
Example #3
0
        private async ValueTask LoadContent()
        {
            using (CustomActivity opLoadMasterindex = Timekeeper.StartSyncron("op_load_frm_masterindex", null,
                                                                              CustomActivity.OperationType.RequestOperation, null))
            {
                _dicCachedNotes.Clear();
                foreach (MasterIndexEntry objExistingEntry in _lstItems.Select(x => x.Value))
                {
                    objExistingEntry.Dispose();
                }
                _lstItems.Clear();
                _lstFileNamesWithItems.Clear();
                string strSourceFilter;
                using (new FetchSafelyFromPool <HashSet <string> >(Utils.StringHashSetPool,
                                                                   out HashSet <string> setValidCodes))
                {
                    foreach (XPathNavigator xmlBookNode in (await XmlManager.LoadXPathAsync(
                                                                "books.xml", _objSelectedSetting.EnabledCustomDataDirectoryPaths))
                             .SelectAndCacheExpression("/chummer/books/book/code"))
                    {
                        setValidCodes.Add(xmlBookNode.Value);
                    }

                    setValidCodes.IntersectWith(_objSelectedSetting.Books);

                    strSourceFilter = setValidCodes.Count > 0
                        ? '(' + string.Join(" or ", setValidCodes.Select(x => "source = " + x.CleanXPath())) + ')'
                        : "source";
                }

                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_load_andpopulate_entries",
                                                   opLoadMasterindex))
                {
                    ConcurrentBag <ListItem> lstItemsForLoading = new ConcurrentBag <ListItem>();
                    using (_ = Timekeeper.StartSyncron("load_frm_masterindex_load_entries", opLoadMasterindex))
                    {
                        ConcurrentBag <ListItem> lstFileNamesWithItemsForLoading = new ConcurrentBag <ListItem>();
                        // Prevents locking the UI thread while still benefitting from static scheduling of Parallel.ForEach
                        await Task.WhenAll(_astrFileNames.Select(strFileName => Task.Run(async() =>
                        {
                            XPathNavigator xmlBaseNode
                                = await XmlManager.LoadXPathAsync(strFileName,
                                                                  _objSelectedSetting.EnabledCustomDataDirectoryPaths);
                            xmlBaseNode = xmlBaseNode.SelectSingleNodeAndCacheExpression("/chummer");
                            if (xmlBaseNode == null)
                            {
                                return;
                            }
                            bool blnLoopFileNameHasItems = false;
                            foreach (XPathNavigator xmlItemNode in xmlBaseNode.SelectAndCacheExpression(
                                         ".//*[page and " +
                                         strSourceFilter + ']'))
                            {
                                blnLoopFileNameHasItems = true;
                                string strName          = xmlItemNode.SelectSingleNodeAndCacheExpression("name")?.Value;
                                string strDisplayName
                                    = xmlItemNode.SelectSingleNodeAndCacheExpression("translate")?.Value
                                      ?? strName
                                      ?? xmlItemNode.SelectSingleNodeAndCacheExpression("id")?.Value
                                      ?? await LanguageManager.GetStringAsync("String_Unknown");
                                string strSource      = xmlItemNode.SelectSingleNodeAndCacheExpression("source")?.Value;
                                string strPage        = xmlItemNode.SelectSingleNodeAndCacheExpression("page")?.Value;
                                string strDisplayPage = xmlItemNode.SelectSingleNodeAndCacheExpression("altpage")?.Value
                                                        ?? strPage;
                                string strEnglishNameOnPage
                                    = xmlItemNode.SelectSingleNodeAndCacheExpression("nameonpage")?.Value
                                      ?? strName;
                                string strTranslatedNameOnPage =
                                    xmlItemNode.SelectSingleNodeAndCacheExpression("altnameonpage")?.Value
                                    ?? strDisplayName;
                                string strNotes = xmlItemNode.SelectSingleNodeAndCacheExpression("altnotes")?.Value
                                                  ?? xmlItemNode.SelectSingleNodeAndCacheExpression("notes")?.Value;
                                MasterIndexEntry objEntry = new MasterIndexEntry(
                                    strDisplayName,
                                    strFileName,
                                    new SourceString(strSource, strPage, GlobalSettings.DefaultLanguage,
                                                     GlobalSettings.InvariantCultureInfo),
                                    new SourceString(strSource, strDisplayPage, GlobalSettings.Language,
                                                     GlobalSettings.CultureInfo),
                                    strEnglishNameOnPage,
                                    strTranslatedNameOnPage);
                                lstItemsForLoading.Add(new ListItem(objEntry, strDisplayName));
                                if (!string.IsNullOrEmpty(strNotes))
                                {
                                    _dicCachedNotes.TryAdd(objEntry, strNotes);
                                }
                            }

                            if (blnLoopFileNameHasItems)
                            {
                                lstFileNamesWithItemsForLoading.Add(new ListItem(strFileName, strFileName));
                            }
                        })));

                        _lstFileNamesWithItems.AddRange(lstFileNamesWithItemsForLoading);
                    }

                    using (_ = Timekeeper.StartSyncron("load_frm_masterindex_populate_entries", opLoadMasterindex))
                    {
                        string strSpace = await LanguageManager.GetStringAsync("String_Space");

                        string strFormat = "{0}" + strSpace + "[{1}]";
                        Dictionary <string, List <ListItem> > dicHelper
                            = new Dictionary <string, List <ListItem> >(lstItemsForLoading.Count);
                        try
                        {
                            foreach (ListItem objItem in lstItemsForLoading)
                            {
                                if (!(objItem.Value is MasterIndexEntry objEntry))
                                {
                                    continue;
                                }
                                string strKey = objEntry.DisplayName.ToUpperInvariant();
                                if (dicHelper.TryGetValue(strKey, out List <ListItem> lstExistingItems))
                                {
                                    ListItem objExistingItem = lstExistingItems.Find(
                                        x => x.Value is MasterIndexEntry y &&
                                        objEntry.DisplaySource.Equals(y.DisplaySource));
                                    if (objExistingItem.Value is MasterIndexEntry objLoopEntry)
                                    {
                                        objLoopEntry.FileNames.UnionWith(objEntry.FileNames);
                                        objEntry.Dispose();
                                    }
                                    else
                                    {
                                        using (new FetchSafelyFromPool <List <ListItem> >(
                                                   Utils.ListItemListPool, out List <ListItem> lstItemsNeedingNameChanges))
                                        {
                                            lstItemsNeedingNameChanges.AddRange(lstExistingItems.FindAll(
                                                                                    x => x.Value is MasterIndexEntry y &&
                                                                                    !objEntry.FileNames.IsSubsetOf(y.FileNames)));
                                            if (lstItemsNeedingNameChanges.Count == 0)
                                            {
                                                _lstItems.Add(
                                                    objItem); // Not using AddRange because of potential memory issues
                                                lstExistingItems.Add(objItem);
                                            }
                                            else
                                            {
                                                ListItem objItemToAdd = new ListItem(
                                                    objItem.Value, string.Format(GlobalSettings.CultureInfo,
                                                                                 strFormat, objItem.Name,
                                                                                 string.Join(
                                                                                     ',' + strSpace, objEntry.FileNames)));
                                                _lstItems.Add(
                                                    objItemToAdd); // Not using AddRange because of potential memory issues
                                                lstExistingItems.Add(objItemToAdd);

                                                foreach (ListItem objToRename in lstItemsNeedingNameChanges)
                                                {
                                                    _lstItems.Remove(objToRename);
                                                    lstExistingItems.Remove(objToRename);

                                                    if (!(objToRename.Value is MasterIndexEntry objExistingEntry))
                                                    {
                                                        continue;
                                                    }
                                                    objItemToAdd = new ListItem(objToRename.Value, string.Format(
                                                                                    GlobalSettings.CultureInfo,
                                                                                    strFormat, objExistingEntry.DisplayName,
                                                                                    string.Join(
                                                                                        ',' + strSpace,
                                                                                        objExistingEntry.FileNames)));
                                                    _lstItems.Add(
                                                        objItemToAdd); // Not using AddRange because of potential memory issues
                                                    lstExistingItems.Add(objItemToAdd);
                                                }
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    _lstItems.Add(objItem); // Not using AddRange because of potential memory issues
                                    List <ListItem> lstHelperItems = Utils.ListItemListPool.Get();
                                    lstHelperItems.Add(objItem);
                                    dicHelper.Add(strKey, lstHelperItems);
                                }
                            }
                        }
                        finally
                        {
                            foreach (List <ListItem> lstHelperItems in dicHelper.Values)
                            {
                                Utils.ListItemListPool.Return(lstHelperItems);
                            }
                        }
                    }
                }

                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_sort_entries", opLoadMasterindex))
                {
                    _lstItems.Sort(CompareListItems.CompareNames);
                    _lstFileNamesWithItems.Sort(CompareListItems.CompareNames);
                }

                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_populate_controls", opLoadMasterindex))
                {
                    _lstFileNamesWithItems.Insert(0, new ListItem(string.Empty, await LanguageManager.GetStringAsync("String_All")));

                    int intOldSelectedIndex = cboFile.SelectedIndex;

                    cboFile.BeginUpdate();
                    cboFile.PopulateWithListItems(_lstFileNamesWithItems);
                    try
                    {
                        cboFile.SelectedIndex = Math.Max(intOldSelectedIndex, 0);
                    }
                    // For some reason, some unit tests will fire this exception even when _lstFileNamesWithItems is explicitly checked for having enough items
                    catch (ArgumentOutOfRangeException)
                    {
                        cboFile.SelectedIndex = -1;
                    }
                    cboFile.EndUpdate();

                    lstItems.BeginUpdate();
                    lstItems.PopulateWithListItems(_lstItems);
                    lstItems.SelectedIndex = -1;
                    lstItems.EndUpdate();

                    _blnSkipRefresh = false;
                }
            }
        }
        private void frmMasterIndex_Load(object sender, EventArgs e)
        {
            using (var op_load_frm_masterindex = Timekeeper.StartSyncron("op_load_frm_masterindex", null, CustomActivity.OperationType.RequestOperation, null))
            {
                HashSet <string> setValidCodes = new HashSet <string>();
                XmlNodeList      lstBookNodes  = XmlManager.Load("books.xml").SelectNodes("/chummer/books/book/code");
                if (lstBookNodes?.Count > 0)
                {
                    foreach (XmlNode xmlBookNode in lstBookNodes)
                    {
                        setValidCodes.Add(xmlBookNode.InnerText);
                    }
                }

                string strSourceFilter = setValidCodes.Count > 0
                    ? new StringBuilder("(")
                                         .AppendJoin(" or ", setValidCodes.Select(x => "source = \'" + x + "\'"))
                                         .Append(')').ToString()
                    : "source";

                ConcurrentBag <ListItem> lstItemsForLoading = new ConcurrentBag <ListItem>();
                ConcurrentBag <ListItem> lstFileNamesWithItemsForLoading = new ConcurrentBag <ListItem>();
                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_load_entries", op_load_frm_masterindex))
                {
                    Parallel.ForEach(_lstFileNames, strFileName =>
                    {
                        XPathNavigator xmlBaseNode = XmlManager.Load(strFileName).GetFastNavigator().SelectSingleNode("/chummer");
                        if (xmlBaseNode != null)
                        {
                            bool blnLoopFileNameHasItems = false;
                            foreach (XPathNavigator xmlItemNode in xmlBaseNode.Select(".//*[page and " + strSourceFilter + ']'))
                            {
                                blnLoopFileNameHasItems = true;
                                string strName          = xmlItemNode.SelectSingleNode("name")?.Value;
                                string strDisplayName   = xmlItemNode.SelectSingleNode("translate")?.Value
                                                          ?? strName
                                                          ?? xmlItemNode.SelectSingleNode("id")?.Value
                                                          ?? LanguageManager.GetString("String_Unknown");
                                string strSource      = xmlItemNode.SelectSingleNode("source")?.Value;
                                string strPage        = xmlItemNode.SelectSingleNode("page")?.Value;
                                string strDisplayPage = xmlItemNode.SelectSingleNode("altpage")?.Value
                                                        ?? strPage;
                                string strEnglishNameOnPage = xmlItemNode.SelectSingleNode("nameonpage")?.Value
                                                              ?? strName;
                                string strTranslatedNameOnPage = xmlItemNode.SelectSingleNode("altnameonpage")?.Value
                                                                 ?? strDisplayName;
                                string strNotes = xmlItemNode.SelectSingleNode("altnotes")?.Value
                                                  ?? xmlItemNode.SelectSingleNode("notes")?.Value;
                                MasterIndexEntry objEntry = new MasterIndexEntry(
                                    strDisplayName,
                                    strFileName,
                                    new SourceString(strSource, strPage, GlobalOptions.DefaultLanguage, GlobalOptions.InvariantCultureInfo),
                                    new SourceString(strSource, strDisplayPage, GlobalOptions.Language, GlobalOptions.CultureInfo),
                                    strEnglishNameOnPage,
                                    strTranslatedNameOnPage);
                                lstItemsForLoading.Add(new ListItem(objEntry, strDisplayName));
                                if (!string.IsNullOrEmpty(strNotes))
                                {
                                    _dicCachedNotes.TryAdd(objEntry, strNotes);
                                }
                            }

                            if (blnLoopFileNameHasItems)
                            {
                                lstFileNamesWithItemsForLoading.Add(new ListItem(strFileName, strFileName));
                            }
                        }
                    });
                }

                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_populate_entries", op_load_frm_masterindex))
                {
                    string strSpace = LanguageManager.GetString("String_Space");
                    Dictionary <string, List <ListItem> > dicHelper = new Dictionary <string, List <ListItem> >(lstItemsForLoading.Count);
                    foreach (ListItem objItem in lstItemsForLoading)
                    {
                        MasterIndexEntry objEntry = (MasterIndexEntry)objItem.Value;
                        string           strKey   = objEntry.DisplayName.ToUpperInvariant();
                        if (dicHelper.TryGetValue(strKey, out List <ListItem> lstExistingItems))
                        {
                            ListItem objExistingItem = lstExistingItems.FirstOrDefault(x =>
                                                                                       objEntry.DisplaySource.Equals(((MasterIndexEntry)x.Value).DisplaySource));
                            if (objExistingItem.Value != null)
                            {
                                ((MasterIndexEntry)objExistingItem.Value).FileNames.UnionWith(objEntry.FileNames);
                            }
                            else
                            {
                                List <ListItem> lstItemsNeedingNameChanges = lstExistingItems.Where(x => !objEntry.FileNames.IsSubsetOf(((MasterIndexEntry)x.Value).FileNames)).ToList();
                                if (lstItemsNeedingNameChanges.Count == 0)
                                {
                                    _lstItems.Add(objItem); // Not using AddRange because of potential memory issues
                                    lstExistingItems.Add(objItem);
                                }
                                else
                                {
                                    ListItem objItemToAdd = new ListItem(objItem.Value,
                                                                         new StringBuilder(objItem.Name)
                                                                         .Append(strSpace).Append('[').AppendJoin(',' + strSpace, objEntry.FileNames).Append(']').ToString());
                                    _lstItems.Add(objItemToAdd); // Not using AddRange because of potential memory issues
                                    lstExistingItems.Add(objItemToAdd);

                                    foreach (ListItem objToRename in lstItemsNeedingNameChanges)
                                    {
                                        _lstItems.Remove(objToRename);
                                        lstExistingItems.Remove(objToRename);

                                        MasterIndexEntry objExistingEntry = (MasterIndexEntry)objToRename.Value;
                                        objItemToAdd = new ListItem(objToRename.Value,
                                                                    new StringBuilder(objExistingEntry.DisplayName)
                                                                    .Append(strSpace).Append('[').AppendJoin(',' + strSpace, objExistingEntry.FileNames).Append(']').ToString());
                                        _lstItems.Add(objItemToAdd); // Not using AddRange because of potential memory issues
                                        lstExistingItems.Add(objItemToAdd);
                                    }
                                }
                            }
                        }
                        else
                        {
                            _lstItems.Add(objItem); // Not using AddRange because of potential memory issues
                            dicHelper.Add(strKey, new List <ListItem>(objItem.Yield()));
                        }
                    }
                    _lstFileNamesWithItems.AddRange(lstFileNamesWithItemsForLoading);
                }

                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_sort_entries", op_load_frm_masterindex))
                {
                    _lstItems.Sort(CompareListItems.CompareNames);
                    _lstFileNamesWithItems.Sort(CompareListItems.CompareNames);
                }

                using (_ = Timekeeper.StartSyncron("load_frm_masterindex_populate_controls", op_load_frm_masterindex))
                {
                    _lstFileNamesWithItems.Insert(0, new ListItem(string.Empty, LanguageManager.GetString("String_All")));

                    cboFile.BeginUpdate();
                    cboFile.ValueMember   = nameof(ListItem.Value);
                    cboFile.DisplayMember = nameof(ListItem.Name);
                    cboFile.DataSource    = _lstFileNamesWithItems;
                    cboFile.SelectedIndex = 0;
                    cboFile.EndUpdate();

                    lstItems.BeginUpdate();
                    lstItems.ValueMember   = nameof(ListItem.Value);
                    lstItems.DisplayMember = nameof(ListItem.Name);
                    lstItems.DataSource    = _lstItems;
                    lstItems.SelectedIndex = -1;
                    lstItems.EndUpdate();

                    _blnSkipRefresh = false;
                }
            }
        }