Beispiel #1
0
        private SearchExpressionNode LoadNodeData(SearchExpressionNode node, IDictionary info)
        {
            if (SJSON.TryGetValue(info, ExpressionField.name, out var name))
            {
                node.name = Convert.ToString(name);
            }

            if (SJSON.TryGetValue(info, ExpressionField.value, out var value))
            {
                node.value = value;
            }

            if (node.type == ExpressionType.Expression)
            {
                var nestedExpression = new SearchExpression(m_SearchOptions);

                if (node.value is string expressionPath && File.Exists(expressionPath))
                {
                    nestedExpression.Load(expressionPath);
                }
                else if (SJSON.TryGetValue(info, ExpressionField.source, out var source) && source is IDictionary sourceData)
                {
                    nestedExpression.Load(sourceData);
                }

                if (nestedExpression.m_EvalNode != null && nestedExpression.m_EvalNode.source != null)
                {
                    node.source = nestedExpression.m_EvalNode.source;
                }
            }
        private SearchExpressionNode LoadNodeData(SearchExpressionNode node, IDictionary info)
        {
            if (SJSON.TryGetValue(info, ExpressionField.name, out var name))
            {
                node.name = Convert.ToString(name);
            }

            if (SJSON.TryGetValue(info, ExpressionField.value, out var value))
            {
                node.value = value;
            }

            if (SJSON.TryGetValue(info, ExpressionField.source, out var source))
            {
                if (source is IDictionary nestedSource)
                {
                    node.source = ParseNode(nestedSource);
                }
                else if (node.type == ExpressionType.Provider)
                {
                    node.value = (string)source;
                }
                else if (m_Nodes.TryGetValue((string)source, out var sourceNode))
                {
                    node.source = sourceNode;
                }
                else
                {
                    throw new ExpressionException($"Expression node {node.id} has an invalid source {source}");
                }
            }

            if (SJSON.TryGetValue(info, ExpressionField.position, out var _obj) && _obj is object[] position && position.Length == 2)
            {
                node.position = new Vector2((float)(double)position[0], (float)(double)position[1]);
            }

            if (SJSON.TryGetValue(info, ExpressionField.variables, out var variablesData))
            {
                var variables = (IDictionary)variablesData;
                foreach (var v in variables)
                {
                    var varName     = (string)((DictionaryEntry)v).Key;
                    var valueSource = ((DictionaryEntry)v).Value;
                    if (valueSource == null)
                    {
                        node.AddVariable(varName);
                    }
                    else if (valueSource is IDictionary nestedSource)
                    {
                        node.AddVariable(varName, ParseNode(nestedSource));
                    }
                    else if (valueSource is string && m_Nodes.TryGetValue((string)valueSource, out var sourceNode))
                    {
                        node.AddVariable(varName, sourceNode);
                    }
                    else
                    {
                        throw new ExpressionException(node, $"Expression node {node.id} has an invalid variable {varName} with source {valueSource}");
                    }
                }
            }

            if (SJSON.TryGetValue(info, ExpressionField.properties, out var propertiesData))
            {
                var properties = (IDictionary)propertiesData;
                foreach (var v in properties)
                {
                    var propertyName  = (string)((DictionaryEntry)v).Key;
                    var propertyValue = ((DictionaryEntry)v).Value;
                    node.SetProperty(propertyName, propertyValue);
                }
            }

            return(node);
        }