Exemplo n.º 1
0
        private IAggregate GetValueAggregate(JsonReader reader, JsonSerializer serializer)
        {
            reader.Read();
            var valueMetric = new ValueAggregate()
            {
                Value = (reader.Value as double?)
            };

            if (valueMetric.Value == null && reader.ValueType == typeof(long))
            {
                valueMetric.Value = reader.Value as long?;
            }

            if (valueMetric.Value != null)
            {
                reader.Read();
                if (reader.TokenType != JsonToken.EndObject)
                {
                    if (reader.TokenType == JsonToken.PropertyName && (reader.Value as string) == "keys")
                    {
                        var keyedValueMetric = new KeyedValueAggregate
                        {
                            Value = valueMetric.Value
                        };
                        var keys = new List <string>();
                        reader.Read();
                        reader.Read();
                        while (reader.TokenType != JsonToken.EndArray)
                        {
                            keys.Add(reader.Value.ToString());
                            reader.Read();
                        }
                        reader.Read();
                        keyedValueMetric.Keys = keys;
                        return(keyedValueMetric);
                    }
                    else
                    {
                        reader.Read();
                        reader.Read();
                    }
                }
                return(valueMetric);
            }

            var scriptedMetric = serializer.Deserialize(reader);

            if (scriptedMetric != null)
            {
                return new ScriptedMetricAggregate {
                           _Value = scriptedMetric
                }
            }
            ;

            reader.Read();
            return(valueMetric);
        }
Exemplo n.º 2
0
        private IAggregate GetValueAggregate(JsonReader reader, JsonSerializer serializer)
        {
            reader.Read();
            var valueMetric = new ValueAggregate
            {
                Value = reader.Value as double?
            };

            if (valueMetric.Value == null && reader.ValueType == typeof(long))
            {
                valueMetric.Value = reader.Value as long?;
            }

            if (valueMetric.Value != null)
            {
                reader.Read();
                if (reader.TokenType != JsonToken.EndObject)
                {
                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        var propertyName = (string)reader.Value;

                        if (propertyName == Parser.ValueAsString)
                        {
                            valueMetric.ValueAsString = reader.ReadAsString();
                            reader.Read();
                        }

                        if (reader.TokenType == JsonToken.PropertyName)
                        {
                            propertyName = (string)reader.Value;
                            if (propertyName == Parser.Keys)
                            {
                                var keyedValueMetric = new KeyedValueAggregate
                                {
                                    Value = valueMetric.Value
                                };
                                var keys = new List <string>();
                                reader.Read();
                                reader.Read();
                                while (reader.TokenType != JsonToken.EndArray)
                                {
                                    keys.Add(reader.Value.ToString());
                                    reader.Read();
                                }
                                reader.Read();
                                keyedValueMetric.Keys = keys;
                                return(keyedValueMetric);
                            }
                        }
                    }
                    else
                    {
                        reader.Read();
                        reader.Read();
                    }
                }
                return(valueMetric);
            }


            //var scriptedMetric = serializer.Deserialize(reader);
            var scriptedMetric = JToken.ReadFrom(reader);

            reader.Read();
            if (scriptedMetric != null)
            {
                var s = serializer.GetConnectionSettings().SourceSerializer;
                return(new ScriptedMetricAggregate(new LazyDocument(scriptedMetric, s)));
            }

            return(valueMetric);
        }
        private IAggregate GetValueAggregate(JsonReader reader, JsonSerializer serializer)
        {
            reader.Read();
            var valueMetric = new ValueAggregate
            {
                Value = reader.Value as double?
            };

            if (valueMetric.Value == null && reader.ValueType == typeof(long))
            {
                valueMetric.Value = reader.Value as long?;
            }

            // https://github.com/elastic/elasticsearch-net/issues/3311
            // above code just checks for long through reader.ValueType, this is not always the case
            if (valueMetric.Value != null || reader.TokenType == JsonToken.Null)
            {
                reader.Read();
                if (reader.TokenType != JsonToken.EndObject)
                {
                    if (reader.TokenType == JsonToken.PropertyName)
                    {
                        var propertyName = (string)reader.Value;

                        if (propertyName == Parser.ValueAsString)
                        {
                            valueMetric.ValueAsString = reader.ReadAsString();
                            reader.Read();
                        }

                        if (reader.TokenType == JsonToken.PropertyName)
                        {
                            propertyName = (string)reader.Value;
                            if (propertyName == Parser.Keys)
                            {
                                var keyedValueMetric = new KeyedValueAggregate
                                {
                                    Value = valueMetric.Value
                                };
                                var keys = new List <string>();
                                reader.Read();
                                reader.Read();
                                while (reader.TokenType != JsonToken.EndArray)
                                {
                                    keys.Add(reader.Value.ToString());
                                    reader.Read();
                                }
                                reader.Read();
                                keyedValueMetric.Keys = keys;
                                return(keyedValueMetric);
                            }
                        }
                    }
                    else
                    {
                        reader.Read();
                        reader.Read();
                    }
                }
                return(valueMetric);
            }

            var scriptedMetric = reader.ReadTokenWithDateParseHandlingNone();

            reader.Read();
            if (scriptedMetric != null)
            {
                var s = serializer.GetConnectionSettings().SourceSerializer;
                return(new ScriptedMetricAggregate(new LazyDocument(scriptedMetric, s)));
            }
            return(valueMetric);
        }
		private IAggregate GetValueMetric(JsonReader reader, JsonSerializer serializer)
		{
			reader.Read();
			var valueMetric = new ValueAggregate()
			{
				Value = (reader.Value as double?)
			};
			if (valueMetric.Value == null && reader.ValueType == typeof(long))
				valueMetric.Value = reader.Value as long?;

			if (valueMetric.Value != null)
			{
				reader.Read();
				if (reader.TokenType != JsonToken.EndObject)
				{
					if (reader.TokenType == JsonToken.PropertyName && (reader.Value as string) == "keys")
					{
						var keyedValueMetric = new KeyedValueAggregate
						{
							Value = valueMetric.Value
						};
						var keys = new List<string>();
						reader.Read();
						reader.Read();
						while (reader.TokenType != JsonToken.EndArray)
						{
							keys.Add(reader.Value.ToString());
							reader.Read();
						}
						reader.Read();
						keyedValueMetric.Keys = keys;
						return keyedValueMetric;
					}
					else
					{
						reader.Read();
						reader.Read();
					}
				}
				return valueMetric;
			}

			var scriptedMetric = serializer.Deserialize(reader);

			if (scriptedMetric != null)
				return new ScriptedMetricAggregate { _Value = scriptedMetric };

			reader.Read();
			return valueMetric;
		}