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); }
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(ref JsonReader reader, IJsonFormatterResolver formatterResolver, IReadOnlyDictionary <string, object> meta) { var token = reader.GetCurrentJsonToken(); if (token == JsonToken.Number || token == JsonToken.Null) { var value = reader.ReadNullableDouble(); string valueAsString = null; token = reader.GetCurrentJsonToken(); if (token != JsonToken.EndObject) { reader.ReadNext(); // , var propertyName = reader.ReadPropertyNameSegmentRaw(); if (propertyName.EqualsBytes(ValueAsStringField)) { valueAsString = reader.ReadString(); token = reader.GetCurrentJsonToken(); if (token == JsonToken.EndObject) { return new ValueAggregate { Value = value, ValueAsString = valueAsString, Meta = meta } } ; reader.ReadNext(); // , propertyName = reader.ReadPropertyNameSegmentRaw(); } if (propertyName.EqualsBytes(KeysField)) { var keyedValueMetric = new KeyedValueAggregate { Value = value, Meta = meta }; var formatter = formatterResolver.GetFormatter <List <string> >(); keyedValueMetric.Keys = formatter.Deserialize(ref reader, formatterResolver); return(keyedValueMetric); } // skip any remaining properties for now while (token != JsonToken.EndObject) { reader.ReadNextBlock(); token = reader.GetCurrentJsonToken(); } } return(new ValueAggregate { Value = value, ValueAsString = valueAsString, Meta = meta }); } var scriptedMetric = reader.ReadNextBlockSegment(); var bytes = BinaryUtil.ToArray(ref scriptedMetric); var doc = new LazyDocument(bytes, formatterResolver); return(new ScriptedMetricAggregate(doc) { Meta = meta }); }
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; }