Exemplo n.º 1
0
        public object GetValueByQuery(GetValueQuery query)
        {
            object result = null;

            foreach (var item in this.stack)
            {
                result = GetValueFromStackItem(item, query);
                if (result != null)
                {
                    return(result);
                }
            }

            // Get Value from KScript variables...
            if (hasvalidchar(query))
            {
                var jsresult = GetValueFromKScript(query);
                if (jsresult != null)
                {
                    var type = jsresult.GetType();
                    if (!type.Name.Contains("Func"))
                    {
                        return(jsresult);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        private bool hasvalidchar(GetValueQuery query)
        {
            string checkkey = null;

            if (query.IsMember)
            {
                checkkey = query.MemberName;
            }
            else
            {
                checkkey = query.Key;
            }

            if (!string.IsNullOrEmpty(checkkey))
            {
                for (int i = 0; i < checkkey.Length; i++)
                {
                    var currentchar = checkkey[i];
                    if (!Lib.Helper.CharHelper.isAlphanumeric(currentchar) && currentchar != '_')
                    {
                        return(false);
                    }
                }
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        internal object GetValueFromJsEngine(GetValueQuery query, Jint.Engine engine)
        {
            if (engine == null)
            {
                return(null);
            }

            if (query.IsMember)
            {
                var jsvalue = engine.GetValue(query.MemberName);
                if (jsvalue != null && jsvalue.Type != Jint.Runtime.Types.Undefined)
                {
                    return(jsvalue.ToObject());
                }
            }
            else
            {
                var value = engine.GetValue(query.Key);

                if (value != null && value.Type != Jint.Runtime.Types.Undefined)
                {
                    string[] subs = query.SubProperty.Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                    object rightvalue = value;

                    foreach (var sub in subs)
                    {
                        rightvalue = getMember(rightvalue, sub);
                        if (rightvalue == null)
                        {
                            break;
                        }
                    }

                    if (rightvalue != null)
                    {
                        if (rightvalue is Jint.Native.JsValue)
                        {
                            var jsvalue = rightvalue as Jint.Native.JsValue;
                            if (jsvalue != null && jsvalue.Type != Jint.Runtime.Types.Undefined)
                            {
                                return(jsvalue.ToObject());
                            }
                        }
                        else
                        {
                            return(rightvalue);
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 4
0
        public object GetValueByQuery(GetValueQuery query)
        {
            object result = null;

            foreach (var item in this.stack)
            {
                result = GetValueFromStackItem(item, query);
                if (result != null)
                {
                    return(result);
                }
            }

            // Get Value from KScript variables...
            if (hasvalidchar(query))
            {
                return(GetValueFromKScript(query));
            }
            return(null);
        }
Exemplo n.º 5
0
        internal object GetValueFromKScript(GetValueQuery query)
        {
            var item = this.renderContext.GetItem <Jint.Engine>();

            if (item == null)
            {
                var debugger = this.renderContext.GetItem <Jint.Engine>("__kooboodebugger");
                var result   = GetValueFromJsEngine(query, debugger);

                if (result != null)
                {
                    return(result);
                }
            }
            else
            {
                var result = GetValueFromJsEngine(query, item);

                if (result != null)
                {
                    return(result);
                }
                else
                {
                    var debugger = this.renderContext.GetItem <Jint.Engine>("__kooboodebugger");
                    result = GetValueFromJsEngine(query, debugger);

                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 6
0
        public object GetValue(string FullPropertyName)
        {
            var query = new GetValueQuery(FullPropertyName);

            return(GetValueByQuery(query));
        }
Exemplo n.º 7
0
        internal object GetValueFromStackItem(IDictionary StackItem, GetValueQuery query)
        {
            object result;

            result = _getDictValueCaseInsensitive(StackItem, query.FullPropertyName);
            if (result != null)
            {
                return(result);
            }

            if (query.IsMember)
            {
                foreach (var item in StackItem.Values)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    if (item is DataMethodResult)
                    {
                        var methodresult = item as DataMethodResult;
                        var objectvalue  = methodresult.Value;

                        if (objectvalue != null)
                        {
                            result = getMember(objectvalue, query.MemberName);
                            if (result != null)
                            {
                                return(result);
                            }
                        }
                    }
                    else
                    {
                        if (item is IDictionary)
                        {
                            var idic = item as IDictionary;
                            result = _getDictValueCaseInsensitive(idic, query.MemberName);
                            if (result != null)
                            {
                                return(result);
                            }
                        }
                        else
                        {
                            var type = item.GetType();

                            if (!type.IsValueType || !type.IsPrimitive)
                            {
                                result = getMember(item, query.MemberName);
                                if (result != null)
                                {
                                    return(result);
                                }
                            }
                        }
                    }
                }
            }

            else
            {
                result = _getDictValueCaseInsensitive(StackItem, query.Key);

                if (result != null)
                {
                    return(getObjectProperty(result, query.SubProperty));
                }

                // by object type...
                string objectType = query.Key.ToLower();

                foreach (var item in StackItem.Values)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    if (item is DataMethodResult)
                    {
                        result = GetValueFromMethodResultByObjectType(item as DataMethodResult, query.Key, query.SubProperty);
                        if (result != null)
                        {
                            return(result);
                        }
                    }
                    else if (item.GetType().IsClass)
                    {
                        var type = item.GetType();
                        if (type.Name.ToLower() == objectType)
                        {
                            if (!string.IsNullOrEmpty(query.SubProperty))
                            {
                                result = getMember(item, query.SubProperty);
                                if (result != null)
                                {
                                    return(result);
                                }
                            }
                            else
                            {
                                return(item);
                            }
                        }
                    }
                }
            }

            return(null);
        }