Exemple #1
0
    private NetUIElementBase ImportNonContainer(List <ElementValue> nonLists)
    {
        NetUIElementBase firstTouchedElement = null;

        foreach (var elementValue in nonLists)
        {
            if (CachedElements.ContainsKey(elementValue.Id))
            {
                var element = this[elementValue.Id];
                element.BinaryValue = elementValue.Value;

                if (firstTouchedElement == null)
                {
                    firstTouchedElement = element;
                }
            }
            else
            {
                Logger.LogWarning(
                    $"'{name}' wonky value import: can't find '{elementValue.Id}'.\n Expected: {string.Join("/", CachedElements.Keys)}",
                    Category.NetUI);
            }
        }

        return(firstTouchedElement);
    }
Exemple #2
0
    private bool ImportContainer(ElementValue[] values, List <ElementValue> nonLists)
    {
        bool shouldRescan = false;

        foreach (var elementValue in values)
        {
            var element = this[elementValue.Id];

            if (CachedElements.ContainsKey(elementValue.Id) &&
                (element is NetUIDynamicList || element is NetPageSwitcher))
            {
                var listContentsChanged = element.ValueObject != elementValue.Value;
                if (!listContentsChanged)
                {
                    continue;
                }

                element.BinaryValue = elementValue.Value;
                shouldRescan        = true;
            }
            else
            {
                nonLists.Add(elementValue);
            }
        }

        return(shouldRescan);
    }
Exemple #3
0
    public NetUIElement ImportValues(ElementValue[] values)
    {
        var  nonLists     = new List <ElementValue>();
        bool shouldRescan = false;

        //set DynamicList values first (so that corresponding subelements would get created)
        for (var i = 0; i < values.Length; i++)
        {
            var elementId = values[i].Id;
            if (CachedElements.ContainsKey(elementId) &&
                (this[elementId] is NetUIDynamicList || this[elementId] is NetPageSwitcher))
            {
                bool listContentsChanged = this[elementId].Value != values[i].Value;
                if (listContentsChanged)
                {
                    this[elementId].Value = values[i].Value;
                    shouldRescan          = true;
                }
            }
            else
            {
                nonLists.Add(values[i]);
            }
        }

        //rescan elements in case of dynamic list changes
        if (shouldRescan)
        {
            RescanElements();
        }

        NetUIElement firstTouchedElement = null;

        //set the rest of the values
        for (var i = 0; i < nonLists.Count; i++)
        {
            var elementId = nonLists[i].Id;
            if (CachedElements.ContainsKey(elementId))
            {
                var element = this[elementId];
                element.Value = nonLists[i].Value;

                if (firstTouchedElement == null)
                {
                    firstTouchedElement = element;
                }
            }
            else
            {
                Logger.LogWarning($"'{name}' wonky value import: can't find '{elementId}'.\n Expected: {string.Join("/",CachedElements.Keys)}", Category.NetUI);
            }
        }
        return(firstTouchedElement);
    }
Exemple #4
0
    private void InitElements(bool serverFirstTime = false)
    {
        // Init and add new elements to cache
        var elements = Elements;

        foreach (var element in elements)
        {
            if (serverFirstTime && element is NetPageSwitcher switcher && switcher.StartInitialized == false)
            {
                // First time we make sure all pages are enabled in order to be scanned
                switcher.Init();
                InitElements(true);
                return;
            }

            if (CachedElements.ContainsKey(element.name))
            {
                continue;
            }
            element.Init();

            if (CachedElements.ContainsKey(element.name))
            {
                // 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) == false)
            {
                toRemove.Add(pair.Key);
            }
        }

        // Remove obsolete elements from cache
        foreach (var removed in toRemove)
        {
            CachedElements.Remove(removed);
        }
    }
        public Element Get(string name, string category, string culture)
        {
            string dictionaryKey = GetElementDictionaryKey(name, category, culture);

            Element element = null;

            if (CachedElements.ContainsKey(dictionaryKey))
            {
                element = CachedElements[dictionaryKey];
            }

            if (element == null && this.InnerElementRepository != null)
            {
                element = this.InnerElementRepository.Get(name, category, culture);

                if (element != null)
                {
                    CachedElements.Add(dictionaryKey, element);
                }
            }

            return(element);
        }
Exemple #6
0
 public NetUIElement this[string elementId] => CachedElements.ContainsKey(elementId) ? CachedElements[elementId] : null;