public NdfValueWrapper GetValueFromQuery(string query)
        {
            string rest = string.Empty;
            string next = NdfQueryReader.ParseNextStep(query, out rest);

            long index = -1;

            if (long.TryParse(next, out index)) // can be  a list of map so we need to find a way to use "next" as a key and (even worst, sometimes a long is a key map)
            {
                NdfValueWrapper val = this.InnerList[(int)index].Value;

                switch (val.Type)
                {
                case NdfType.ObjectReference:
                    NdfObjectReference reference = val as NdfObjectReference;
                    return(reference.Instance.GetValueFromQuery(rest));

                case NdfType.MapList:
                    NdfMapList mapList = val as NdfMapList;
                    return(mapList.GetValueFromQuery(rest));

                case NdfType.List:
                    NdfCollection list = val as NdfCollection;
                    return(list.GetValueFromQuery(rest));

                case NdfType.Map:
                    NdfMap map = val as NdfMap;
                    return((map.Value as MapValueHolder).Value);


                default:
                    return(val);
                }
            }
            else
            {
                // do a list from the maps of the inner list
                List <CollectionItemValueHolder> maps = _innerList.FindAll(x => x.Value.Type == NdfType.Map);
                try
                {
                    NdfValueWrapper selectedmap = maps.Find(x => (x.Value as NdfMap).Key.Value.ToString() == next).Value; // wat

                    NdfMap         mapVal    = selectedmap as NdfMap;
                    MapValueHolder valholder = mapVal.Value as MapValueHolder;

                    return(valholder.Value);
                }
                catch { }
            }

            throw (new Exception("Something went wrong with this path: " + query != string.Empty ? query : "empty path"));
        }
Beispiel #2
0
        private string FromItemKey2String(NdfValueWrapper val) // Must change, since all key are not necess stringreferences
        {
            NdfMap map = val as NdfMap;

            switch (map.Key.Value.Type)
            {
            case NdfType.UInt32:
                return(((NdfUInt32)map.Key.Value).ToString());

            case NdfType.TableString:
                return(((NdfString)map.Key.Value).ToString());

            case NdfType.WideString:
                return(((NdfWideString)map.Key.Value).ToString());

            default: return(string.Empty);
            }

            //return ((NdfString)map.Key.Value).Value as NdfStringReference; // Bleh
        }
Beispiel #3
0
        public bool TryGetValueFromQuery(string propertyPath, out NdfValueWrapper value)
        {
            string rest = string.Empty;
            string next = NdfQueryReader.ParseNextStep(propertyPath, out rest);

            if (!string.IsNullOrEmpty(next))
            {
                NdfMap nextMap;
                if (TryGetMap(next, out nextMap))
                {
                    switch (nextMap.Type)
                    {
                    case NdfType.ObjectReference:
                        NdfObjectReference reference = nextMap.Value as NdfObjectReference;
                        return(reference.Instance.TryGetValueFromQuery(rest, out value));

                    case NdfType.MapList:
                        NdfMapList mapList = nextMap.Value as NdfMapList;
                        return(mapList.TryGetValueFromQuery(rest, out value));

                    case NdfType.List:
                        NdfCollection list = nextMap.Value as NdfCollection;
                        return(list.TryGetValueFromQuery(rest, out value));

                    case Types.NdfType.Unknown:
                        break;

                    case Types.NdfType.Unset:
                        break;

                    default:
                        value = nextMap;
                        return(true);
                    }
                }
            }
            value = null;
            return(false);
        }
Beispiel #4
0
        public bool TryGetValueFromQuery(string query, out NdfValueWrapper value)
        {
            NdfValueWrapper val = (this.Value as MapValueHolder).Value;

            switch (val.Type)
            {
            case NdfType.ObjectReference:
                NdfObjectReference reference = val as NdfObjectReference;
                return(reference.Instance.TryGetValueFromQuery(query, out value));

            case NdfType.MapList:
                NdfMapList mapList = val as NdfMapList;
                return(mapList.TryGetValueFromQuery(query, out value));

            case NdfType.List:
                NdfCollection list = val as NdfCollection;
                return(list.TryGetValueFromQuery(query, out value));

            case NdfType.Map:
                NdfMap map = val as NdfMap;
                return(map.TryGetValueFromQuery(query, out value));

            case Types.NdfType.Unknown:
                break;

            case Types.NdfType.Unset:
                break;

            default:
                value = val;
                return(true);
            }


            value = null;
            return(false);
            //throw (new Exception("Something went wrong with this path: " + propertyPath != string.Empty ? propertyPath : "empty path"));
        }
        public bool TryGetValueFromQuery(string query, out NdfValueWrapper value)
        {
            string rest = string.Empty;
            string next = NdfQueryReader.ParseNextStep(query, out rest);

            // verify next is in the from "[ i ]"
            bool isIndex = false;

            string[] parts = next.Split(new string[] { "[", "]" }, StringSplitOptions.None);
            if (parts.Length == 3)
            {
                isIndex = true;
            }

            long index = -1;

            if (isIndex && long.TryParse(parts[1], out index))
            {
                NdfValueWrapper val = null;

                try { val = this.InnerList[(int)index].Value; }
                catch { value = null; return(false); }

                switch (val.Type)
                {
                case NdfType.ObjectReference:
                    NdfObjectReference reference = val as NdfObjectReference;
                    return(reference.Instance.TryGetValueFromQuery(rest, out value));

                case NdfType.MapList:
                    NdfMapList mapList = val as NdfMapList;
                    return(mapList.TryGetValueFromQuery(rest, out value));

                case NdfType.List:
                    NdfCollection list = val as NdfCollection;
                    return(list.TryGetValueFromQuery(rest, out value));

                case NdfType.Map:
                    NdfMap map = val as NdfMap;
                    return(map.TryGetValueFromQuery(rest, out value));

                case Types.NdfType.Unknown:
                    break;

                case Types.NdfType.Unset:
                    break;

                default:
                    value = val;
                    return(true);
                }
            }
            else
            {
                // do a list from the maps of the inner list
                List <CollectionItemValueHolder> maps = _innerList.FindAll(x => x.Value.Type == NdfType.Map);
                try
                {
                    NdfValueWrapper selectedmap = maps.Find(x => (x.Value as NdfMap).Key.Value.ToString() == next).Value; // wat

                    NdfMap         mapVal    = selectedmap as NdfMap;
                    MapValueHolder valholder = mapVal.Value as MapValueHolder;

                    NdfValueWrapper val = valholder.Value;

                    switch (val.Type)
                    {
                    case NdfType.ObjectReference:
                        NdfObjectReference reference = val as NdfObjectReference;
                        return(reference.Instance.TryGetValueFromQuery(rest, out value));

                    case NdfType.MapList:
                        NdfMapList mapList = val as NdfMapList;
                        return(mapList.TryGetValueFromQuery(rest, out value));

                    case NdfType.List:
                        NdfCollection list = val as NdfCollection;
                        return(list.TryGetValueFromQuery(rest, out value));

                    case NdfType.Map:
                        NdfMap map = val as NdfMap;
                        return(map.TryGetValueFromQuery(rest, out value));

                    case Types.NdfType.Unknown:
                        break;

                    case Types.NdfType.Unset:
                        break;

                    default:
                        value = val;
                        return(true);
                    }
                }
                catch { value = null; return(false); }
            }


            value = null;
            return(false);
            //throw (new Exception("Something went wrong with this path: " + propertyPath != string.Empty ? propertyPath : "empty path"));
        }