Exemplo n.º 1
0
    private void InitElements()
    {
        var elements = Elements;

        //Init and add new elements to cache
        for (var i = 0; i < elements.Count; i++)
        {
            NetUIElement element = elements[i];
            if (!CachedElements.ContainsValue(element))
            {
                element.Init();
                CachedElements.Add(element.name, element);
            }
        }

        var toRemove = new List <string>();

        //Mark non-existent elements for removal
        foreach (var pair in CachedElements)
        {
            if (!elements.Contains(pair.Value))
            {
                toRemove.Add(pair.Key);
            }
        }
        //Remove obsolete elements from cache
        for (var i = 0; i < toRemove.Count; i++)
        {
            CachedElements.Remove(toRemove[i]);
        }
    }
Exemplo n.º 2
0
    private void InitElements(bool serverFirstTime = false)
    {
        var elements = Elements;

        //Init and add new elements to cache
        foreach (NetUIElement element in elements)
        {
            if (serverFirstTime && element is NetPageSwitcher switcher && !switcher.StartInitialized)
            {             //First time we make sure all pages are enabled in order to be scanned
                switcher.Init();
                InitElements(true);
                return;
            }

            if (!CachedElements.ContainsValue(element))
            {
                element.Init();

                if (CachedElements.ContainsValue(element))
                {
                    //Someone called InitElements in Init()
                    Logger.LogError($"'{name}': rescan during '{element}' Init(), aborting initial scan", Category.NetUI);
                    return;
                }

                CachedElements.Add(element.name, element);
            }
        }

        var toRemove = new List <string>();

        //Mark non-existent elements for removal
        foreach (var pair in CachedElements)
        {
            if (!elements.Contains(pair.Value))
            {
                toRemove.Add(pair.Key);
            }
        }

        //Remove obsolete elements from cache
        for (var i = 0; i < toRemove.Count; i++)
        {
            CachedElements.Remove(toRemove[i]);
        }
    }