Пример #1
0
        public static JToken ConvertPesudoTypes(JToken data, FormatOptions fmt)
        {
            var reqlTypes = data.SelectTokens("$..$reql_type$").ToList();

            foreach ( var typeToken in reqlTypes )
            {
                var reqlType = typeToken.Value<string>();
                //JObject -> JProerty -> JVaule:$reql_type$, go backup the chain.
                var pesudoObject = typeToken.Parent.Parent as JObject;

                JToken convertedValue = null;
                if( reqlType == Time )
                {
                    if( fmt.RawTime )
                        continue;
                    convertedValue = new JValue(GetTime(pesudoObject));
                }
                else if( reqlType == GroupedData )
                {
                    if( fmt.RawGroups )
                        continue;
                    convertedValue = new JValue(GetGrouped(pesudoObject));
                }
                else if( reqlType == Binary )
                {
                    if( fmt.RawBinary )
                        continue;
                    convertedValue = new JArray(GetBinary(pesudoObject));
                }

                pesudoObject.Replace(convertedValue);
            }

            return data;
        }
Пример #2
0
	    public static object ConvertPesudoTypes(object obj, FormatOptions fmt)
	    {
	        var list = obj as JArray;
	        var dict = obj as JObject;

	        if( list != null )
	        {
	            return list.Select(item => ConvertPesudoTypes(item, fmt))
	                .ToList();
	        }
            else if( dict != null )
            {
                if( dict[PSEUDOTYPE_KEY] != null )
                {
                    return ConvertPesudo(dict, fmt);
                }

                return dict.Properties()
                    .ToDictionary(p => p.Name, p => ConvertPesudoTypes(p.Value, fmt));

            }
            else
            {
                return obj;
            }
	    }
Пример #3
0
        public static JToken ConvertPesudoTypes(JToken obj, FormatOptions fmt)
        {
            var jarray = obj as JArray;
            if (jarray != null)
            {
                for( var i = 0; i < jarray.Count; i++)
                {
                    var value = ConvertPesudoTypes(jarray[i], fmt);
                    jarray[i] = value;
                }
                return jarray;
            }

            var jobject = obj as JObject;
            if (jobject != null)
            {
                var props = jobject.Properties().ToList();
                if( props.Any(prop => prop.Name == PseudoTypeKey) )
                {
                    var value = ConvertPesudo(jobject, fmt);
                    return new JValue(value);
                }
                for( var i = 0; i < props.Count; i++ )
                {
                    var value = ConvertPesudoTypes(props[i], fmt);
                    props[i].Value = value;
                }
                
                return jobject;
            }

            return (JToken)obj;
        }
Пример #4
0
        /// <summary>
        /// Factory method for FormatOptions from OptArgs
        /// </summary>
        public static FormatOptions FromOptArgs(OptArgs args)
        {
            var fmt = new FormatOptions();
            // TODO: find a better way to do this.
            ReqlAst datum;
            var value = args.TryGetValue("time_format", out datum) ? ((Datum)datum).datum : new Datum("native").datum;
            fmt.RawTime = value.Equals("raw");

            value = args.TryGetValue("binary_format", out datum) ? ((Datum)datum).datum : new Datum("native").datum;
            fmt.RawBinary = value.Equals("raw");

            value = args.TryGetValue("group_format", out datum) ? ((Datum)datum).datum : new Datum("native").datum;
            fmt.RawGroups = value.Equals("raw");

            return fmt;
        }
Пример #5
0
	    public static object ConvertPesudo(JObject value, FormatOptions fmt)
	    {
	        if( value == null ) return null;

	        var reqlType = value[PSEUDOTYPE_KEY].ToString();

	        switch( reqlType )
	        {
                case TIME:
	                return fmt.RawTime ? value : (object)GetTime(value);
                case GROUPED_DATA:
	                return fmt.RawGroups ? value : (object)GetGrouped(value);
                case BINARY:
	                return fmt.RawBinary ? value : (object)GetBinary(value);
                case GEOMETRY:
	                return value;

                default:
	                return value;
	        }
	    }
Пример #6
-1
        /// <summary>
        /// Method for converting pseudo types in JToken (JObjects)
        /// </summary>
        public static void ConvertPseudoTypes(JToken data, FormatOptions fmt)
        {
            var reqlTypes = data.SelectTokens("$..$reql_type$").ToList();

            foreach (var typeToken in reqlTypes)
            {
                var reqlType = typeToken.Value<string>();
                //JObject -> JProerty -> JVaule:$reql_type$, go backup the chain.
                var pesudoObject = typeToken.Parent.Parent as JObject;

                JToken convertedValue = null;
                if (reqlType == Time)
                {
                    if (fmt.RawTime)
                        continue;
                    convertedValue = new JValue(GetTime(pesudoObject));
                }
                else if (reqlType == GroupedData)
                {
                    if (fmt.RawGroups)
                        continue;
                    convertedValue = GetGrouped(pesudoObject);
                }
                else if (reqlType == Binary)
                {
                    if (fmt.RawBinary)
                        continue;
                    convertedValue = new JValue(GetBinary(pesudoObject));
                }
                else if (reqlType == Geometry)
                {
                    // Nothing specific here
                    continue;
                }
                else
                {
                    // Just leave unknown pseudo-types alone
                    continue;
                }

                pesudoObject.Replace(convertedValue);
            }
        }