コード例 #1
0
        public void Serialize(ref JsonWriter writer, DynamicTemplateContainer value, IJsonFormatterResolver formatterResolver)
        {
            var formatter = formatterResolver.GetFormatter <IDynamicTemplateContainer>();

            formatter.Serialize(ref writer, value, formatterResolver);
        }
コード例 #2
0
        public Attachment Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var token = reader.GetCurrentJsonToken();

            if (token == JsonToken.String)
            {
                return new Attachment {
                           Content = reader.ReadString()
                }
            }
            ;

            if (token == JsonToken.BeginObject)
            {
                var attachment = new Attachment();

                var count = 0;
                while (reader.ReadIsInObject(ref count))
                {
                    var propertyName = reader.ReadPropertyNameSegmentRaw();
                    if (AutomataDictionary.TryGetValue(propertyName, out var value))
                    {
                        switch (value)
                        {
                        case 0:
                            attachment.Content = reader.ReadString();
                            break;

                        case 1:
                            attachment.Name = reader.ReadString();
                            break;

                        case 2:
                            attachment.Author = reader.ReadString();
                            break;

                        case 3:
                            attachment.Keywords = reader.ReadString();
                            break;

                        case 4:
                            attachment.Date = formatterResolver.GetFormatter <DateTime?>()
                                              .Deserialize(ref reader, formatterResolver);
                            break;

                        case 5:
                            attachment.ContentType = reader.ReadString();
                            break;

                        case 6:
                            attachment.ContentLength = reader.ReadNullableLong();
                            break;

                        case 7:
                            attachment.Language = reader.ReadString();
                            break;

                        case 8:
                            attachment.DetectLanguage = reader.ReadNullableBoolean();
                            break;

                        case 9:
                            attachment.IndexedCharacters = reader.ReadNullableLong();
                            break;

                        case 10:
                            attachment.Title = reader.ReadString();
                            break;
                        }
                    }
                }

                return(attachment);
            }

            return(null);
        }
コード例 #3
0
        public void Serialize(ref JsonWriter writer, IPrivileges value, IJsonFormatterResolver formatterResolver)
        {
            var formatter = formatterResolver.GetFormatter <IDictionary <string, IPrivilegesActions> >();

            formatter.Serialize(ref writer, value, formatterResolver);
        }
コード例 #4
0
        public ILifecycleActions Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                reader.ReadNextBlock();
                return(null);
            }

            var lifecycles = new Dictionary <string, ILifecycleAction>();
            var count      = 0;

            while (reader.ReadIsInObject(ref count))
            {
                var type = reader.ReadPropertyNameSegmentRaw();
                ILifecycleAction lifecycleAction = null;

                if (LifeCycleActions.TryGetValue(type, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        lifecycleAction = formatterResolver.GetFormatter <AllocateLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 1:
                        lifecycleAction = formatterResolver.GetFormatter <DeleteLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 2:
                        lifecycleAction = formatterResolver.GetFormatter <ForceMergeLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 3:
                        lifecycleAction = formatterResolver.GetFormatter <FreezeLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 4:
                        lifecycleAction = formatterResolver.GetFormatter <ReadOnlyLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 5:
                        lifecycleAction = formatterResolver.GetFormatter <RolloverLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 6:
                        lifecycleAction = formatterResolver.GetFormatter <SetPriorityLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 7:
                        lifecycleAction = formatterResolver.GetFormatter <ShrinkLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 8:
                        lifecycleAction = formatterResolver.GetFormatter <UnfollowLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;

                    case 9:
                        lifecycleAction = formatterResolver.GetFormatter <WaitForSnapshotLifecycleAction>()
                                          .Deserialize(ref reader, formatterResolver);
                        break;
                    }

                    lifecycles.Add(type.Utf8String(), lifecycleAction);
                }
                else
                {
                    reader.ReadNextBlock();
                }
            }

            return(new LifecycleActions(lifecycles));
        }
コード例 #5
0
        public void Serialize(ref JsonWriter writer, IMovingAverageAggregation value, IJsonFormatterResolver formatterResolver)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            writer.WriteBeginObject();
            var propertyWritten = false;

            if (value.BucketsPath != null)
            {
                writer.WritePropertyName("buckets_path");
                var formatter = formatterResolver.GetFormatter <IBucketsPath>();
                formatter.Serialize(ref writer, value.BucketsPath, formatterResolver);
                propertyWritten = true;
            }
            if (value.GapPolicy != null)
            {
                if (propertyWritten)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("gap_policy");
                writer.WriteString(value.GapPolicy.GetStringValue());
                propertyWritten = true;
            }
            if (!value.Format.IsNullOrEmpty())
            {
                if (propertyWritten)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("format");
                writer.WriteString(value.Format);
                propertyWritten = true;
            }
            if (value.Window != null)
            {
                if (propertyWritten)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("window");
                writer.WriteInt32(value.Window.Value);
                propertyWritten = true;
            }
            if (value.Minimize != null)
            {
                if (propertyWritten)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("minimize");
                writer.WriteBoolean(value.Minimize.Value);
                propertyWritten = true;
            }
            if (value.Predict != null)
            {
                if (propertyWritten)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("predict");
                writer.WriteInt32(value.Predict.Value);
                propertyWritten = true;
            }
            if (value.Model != null)
            {
                if (propertyWritten)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("model");
                writer.WriteString(value.Model.Name);
                writer.WriteValueSeparator();
                writer.WritePropertyName("settings");

                switch (value.Model.Name)
                {
                case "ewma":
                    Serialize(ref writer, (IEwmaModel)value.Model, formatterResolver);
                    break;

                case "linear":
                    Serialize(ref writer, (ILinearModel)value.Model, formatterResolver);
                    break;

                case "simple":
                    Serialize(ref writer, (ISimpleModel)value.Model, formatterResolver);
                    break;

                case "holt":
                    Serialize(ref writer, (IHoltLinearModel)value.Model, formatterResolver);
                    break;

                case "holt_winters":
                    Serialize(ref writer, (IHoltWintersModel)value.Model, formatterResolver);
                    break;

                default:
                    Serialize(ref writer, value.Model, formatterResolver);
                    break;
                }
            }
            writer.WriteEndObject();
        }
コード例 #6
0
        public void Serialize(ref JsonWriter writer, ITokenizer value, IJsonFormatterResolver formatterResolver)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            switch (value.Type)
            {
            case "char_group":
                Serialize <ICharGroupTokenizer>(ref writer, value, formatterResolver);
                break;

            case "edge_ngram":
                Serialize <IEdgeNGramTokenizer>(ref writer, value, formatterResolver);
                break;

            case "ngram":
                Serialize <INGramTokenizer>(ref writer, value, formatterResolver);
                break;

            case "path_hierarchy":
                Serialize <IPathHierarchyTokenizer>(ref writer, value, formatterResolver);
                break;

            case "pattern":
                Serialize <IPatternTokenizer>(ref writer, value, formatterResolver);
                break;

            case "standard":
                Serialize <IStandardTokenizer>(ref writer, value, formatterResolver);
                break;

            case "uax_url_email":
                Serialize <IUaxEmailUrlTokenizer>(ref writer, value, formatterResolver);
                break;

            case "whitespace":
                Serialize <IWhitespaceTokenizer>(ref writer, value, formatterResolver);
                break;

            case "kuromoji_tokenizer":
                Serialize <IKuromojiTokenizer>(ref writer, value, formatterResolver);
                break;

            case "icu_tokenizer":
                Serialize <IIcuTokenizer>(ref writer, value, formatterResolver);
                break;

            case "nori_tokenizer":
                Serialize <INoriTokenizer>(ref writer, value, formatterResolver);
                break;

            default:
                // serialize user defined tokenizer
                var formatter = formatterResolver.GetFormatter <object>();
                formatter.Serialize(ref writer, value, formatterResolver);
                break;
            }
        }
コード例 #7
0
        public GetRepositoryResponse Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var response     = new GetRepositoryResponse();
            var repositories = new Dictionary <string, ISnapshotRepository>();
            var count        = 0;

            while (reader.ReadIsInObject(ref count))
            {
                var property = reader.ReadPropertyNameSegmentRaw();
                if (DictionaryResponseFormatterHelpers.ServerErrorFields.TryGetValue(property, out var errorValue))
                {
                    switch (errorValue)
                    {
                    case 0:
                        if (reader.GetCurrentJsonToken() == JsonToken.String)
                        {
                            response.Error = new Error {
                                Reason = reader.ReadString()
                            }
                        }
                        ;
                        else
                        {
                            var formatter = formatterResolver.GetFormatter <Error>();
                            response.Error = formatter.Deserialize(ref reader, formatterResolver);
                        }
                        break;

                    case 1:
                        if (reader.GetCurrentJsonToken() == JsonToken.Number)
                        {
                            response.StatusCode = reader.ReadInt32();
                        }
                        else
                        {
                            reader.ReadNextBlock();
                        }
                        break;
                    }
                }
                else
                {
                    var name                  = property.Utf8String();
                    var snapshotSegment       = reader.ReadNextBlockSegment();
                    var snapshotSegmentReader = new JsonReader(snapshotSegment.Array, snapshotSegment.Offset);
                    var segmentCount          = 0;

                    string repositoryType        = null;
                    ArraySegment <byte> settings = default;

                    while (snapshotSegmentReader.ReadIsInObject(ref segmentCount))
                    {
                        var propertyName = snapshotSegmentReader.ReadPropertyName();
                        switch (propertyName)
                        {
                        case "type":
                            repositoryType = snapshotSegmentReader.ReadString();
                            break;

                        case "settings":
                            settings = snapshotSegmentReader.ReadNextBlockSegment();
                            break;

                        default:
                            snapshotSegmentReader.ReadNextBlock();
                            break;
                        }
                    }

                    switch (repositoryType)
                    {
                    case "fs":
                        var fs = GetRepository <FileSystemRepository, FileSystemRepositorySettings>(settings, formatterResolver);
                        repositories.Add(name, fs);
                        break;

                    case "url":
                        var url = GetRepository <ReadOnlyUrlRepository, ReadOnlyUrlRepositorySettings>(settings, formatterResolver);
                        repositories.Add(name, url);
                        break;

                    case "azure":
                        var azure = GetRepository <AzureRepository, AzureRepositorySettings>(settings, formatterResolver);
                        repositories.Add(name, azure);
                        break;

                    case "s3":
                        var s3 = GetRepository <S3Repository, S3RepositorySettings>(settings, formatterResolver);
                        repositories.Add(name, s3);
                        break;

                    case "hdfs":
                        var hdfs = GetRepository <HdfsRepository, HdfsRepositorySettings>(settings, formatterResolver);
                        repositories.Add(name, hdfs);
                        break;
                    }
                }
            }

            response.Repositories = repositories;
            return(response);
        }
コード例 #8
0
        public GetCertificatesResponse Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var response = new GetCertificatesResponse();

            if (reader.ReadIsNull())
            {
                return(response);
            }

            switch (reader.GetCurrentJsonToken())
            {
            case JsonToken.BeginArray:
                response.Certificates = Formatter.Deserialize(ref reader, formatterResolver);
                break;

            case JsonToken.BeginObject:
                var count = 0;
                while (reader.ReadIsInObject(ref count))
                {
                    var property = reader.ReadPropertyNameSegmentRaw();
                    if (ResponseFormatterHelpers.ServerErrorFields.TryGetValue(property, out var errorValue))
                    {
                        switch (errorValue)
                        {
                        case 0:
                            if (reader.GetCurrentJsonToken() == JsonToken.String)
                            {
                                response.Error = new Error {
                                    Reason = reader.ReadString()
                                }
                            }
                            ;
                            else
                            {
                                var formatter = formatterResolver.GetFormatter <Error>();
                                response.Error = formatter.Deserialize(ref reader, formatterResolver);
                            }
                            break;

                        case 1:
                            if (reader.GetCurrentJsonToken() == JsonToken.Number)
                            {
                                response.StatusCode = reader.ReadInt32();
                            }
                            else
                            {
                                reader.ReadNextBlock();
                            }
                            break;
                        }
                    }
                    else
                    {
                        reader.ReadNextBlock();
                    }
                }
                break;
            }

            return(response);
        }
コード例 #9
0
        public void Serialize(ref JsonWriter writer, TDictionary value, IJsonFormatterResolver formatterResolver)
        {
            var enumerable = (IEnumerable <KeyValuePair <TKey, TValue> >)value;

            if (enumerable == null)
            {
                writer.WriteNull();
                return;
            }

            var settings    = formatterResolver.GetConnectionSettings();
            var seenEntries = new Dictionary <string, TValue>(value.Count());

            foreach (var entry in enumerable)
            {
                if (SkipValue(entry))                 // TODO: pass _connectionSettingsValues and configure Null Handling on this
                {
                    continue;
                }

                string key;
                if (_keyIsString)
                {
                    key = entry.Key?.ToString();
                }
                else if (settings == null)
                {
                    key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture);
                }
                else if (_keyIsField)
                {
                    var fieldName = entry.Key as Field;
                    key = settings.Inferrer.Field(fieldName);
                }
                else if (_keyIsPropertyName)
                {
                    var propertyName = entry.Key as PropertyName;
                    if (propertyName?.Property != null && settings.PropertyMappings.TryGetValue(propertyName.Property, out var mapping) &&
                        mapping.Ignore)
                    {
                        continue;
                    }

                    key = settings.Inferrer.PropertyName(propertyName);
                }
                else if (_keyIsIndexName)
                {
                    var indexName = entry.Key as IndexName;
                    key = settings.Inferrer.IndexName(indexName);
                }
                else if (_keyIsRelationName)
                {
                    var typeName = entry.Key as RelationName;
                    key = settings.Inferrer.RelationName(typeName);
                }
                else
                {
                    key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture);
                }

                if (key != null)
                {
                    seenEntries[key] = entry.Value;
                }
            }

            writer.WriteBeginObject();
            if (seenEntries.Count > 0)
            {
                var valueFormatter = formatterResolver.GetFormatter <TValue>();
                var count          = 0;
                foreach (var entry in seenEntries)
                {
                    if (count > 0)
                    {
                        writer.WriteValueSeparator();
                    }

                    writer.WritePropertyName(entry.Key);
                    valueFormatter.Serialize(ref writer, entry.Value, formatterResolver);
                    count++;
                }
            }
            writer.WriteEndObject();
        }
コード例 #10
0
        public IFuzziness Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var formatter = formatterResolver.GetFormatter <Fuzziness>();

            return(formatter.Deserialize(ref reader, formatterResolver));
        }
コード例 #11
0
        public void Serialize(ref JsonWriter writer, ITermsQuery value, IJsonFormatterResolver formatterResolver)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            var settings = formatterResolver.GetConnectionSettings();
            var field    = settings.Inferrer.Field(value.Field);
            var written  = false;

            writer.WriteBeginObject();

            if (!value.Name.IsNullOrEmpty())
            {
                writer.WritePropertyName("_name");
                writer.WriteString(value.Name);
                written = true;
            }

            if (value.Boost.HasValue)
            {
                if (written)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("boost");
                writer.WriteDouble(value.Boost.Value);
                written = true;
            }

            if (written)
            {
                writer.WriteValueSeparator();
            }

            if (value.IsVerbatim)
            {
                if (value.TermsLookup != null)
                {
                    writer.WritePropertyName(field);
                    var formatter = formatterResolver.GetFormatter <IFieldLookup>();
                    formatter.Serialize(ref writer, value.TermsLookup, formatterResolver);
                }
                else if (value.Terms != null)
                {
                    writer.WritePropertyName(field);
                    writer.WriteBeginArray();
                    var count = 0;
                    foreach (var o in value.Terms)
                    {
                        if (count > 0)
                        {
                            writer.WriteValueSeparator();
                        }

                        SourceWriteFormatter.Serialize(ref writer, o, formatterResolver);
                        count++;
                    }
                    writer.WriteEndArray();
                }
            }
            else
            {
                if (value.Terms.HasAny())
                {
                    writer.WritePropertyName(field);
                    writer.WriteBeginArray();
                    var count = 0;
                    foreach (var o in value.Terms)
                    {
                        if (count > 0)
                        {
                            writer.WriteValueSeparator();
                        }

                        SourceWriteFormatter.Serialize(ref writer, o, formatterResolver);
                        count++;
                    }
                    writer.WriteEndArray();
                }
                else if (value.TermsLookup != null)
                {
                    writer.WritePropertyName(field);
                    var formatter = formatterResolver.GetFormatter <IFieldLookup>();
                    formatter.Serialize(ref writer, value.TermsLookup, formatterResolver);
                }
            }

            writer.WriteEndObject();
        }
コード例 #12
0
        public void Serialize(ref JsonWriter writer, Fuzziness value, IJsonFormatterResolver formatterResolver)
        {
            var formatter = formatterResolver.GetFormatter <IFuzziness>();

            formatter.Serialize(ref writer, value, formatterResolver);
        }
コード例 #13
0
        public void Serialize(ref JsonWriter writer, IGeoBoundingBoxQuery value, IJsonFormatterResolver formatterResolver)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            var written = false;

            writer.WriteBeginObject();

            if (!value.Name.IsNullOrEmpty())
            {
                writer.WritePropertyName("_name");
                writer.WriteString(value.Name);
                written = true;
            }

            if (value.Boost != null)
            {
                if (written)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("boost");
                writer.WriteDouble(value.Boost.Value);
                written = true;
            }

            if (value.ValidationMethod != null)
            {
                if (written)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("validation_method");
                formatterResolver.GetFormatter <GeoValidationMethod>()
                .Serialize(ref writer, value.ValidationMethod.Value, formatterResolver);
                written = true;
            }

            if (value.Type != null)
            {
                if (written)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("type");
                formatterResolver.GetFormatter <GeoExecution>()
                .Serialize(ref writer, value.Type.Value, formatterResolver);
                written = true;
            }

            if (written)
            {
                writer.WriteValueSeparator();
            }

            var settings = formatterResolver.GetConnectionSettings();

            writer.WritePropertyName(settings.Inferrer.Field(value.Field));
            formatterResolver.GetFormatter <IBoundingBox>()
            .Serialize(ref writer, value.BoundingBox, formatterResolver);

            writer.WriteEndObject();
        }
コード例 #14
0
        public override IFuzzyQuery Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() == JsonToken.Null)
            {
                return(null);
            }

            var                   count = 0;
            IFuzzyQuery           query = null;
            string                name  = null;
            double?               boost = null;
            MultiTermQueryRewrite multiTermQueryRewrite = null;
            int?                  prefixLength          = null;
            int?                  maxExpansions         = null;
            bool?                 transpositions        = null;

            while (reader.ReadIsInObject(ref count))
            {
                var field = reader.ReadPropertyName();
                // ReSharper disable once TooWideLocalVariableScope
                ArraySegment <byte> fuzzinessSegment = default;
                var valueCount = 0;
                while (reader.ReadIsInObject(ref valueCount))
                {
                    var property = reader.ReadPropertyNameSegmentRaw();
                    if (Fields.TryGetValue(property, out var value))
                    {
                        switch (value)
                        {
                        case 0:
                        {
                            var token = reader.GetCurrentJsonToken();
                            switch (token)
                            {
                            case JsonToken.String:
                                var valueSegment = reader.ReadStringSegmentUnsafe();
                                if (valueSegment.IsDateTime(formatterResolver, out var dateTime))
                                {
                                    query = new FuzzyDateQuery
                                    {
                                        Field = field,
                                        Value = dateTime
                                    };
                                }
                                else
                                {
                                    query = new FuzzyQuery
                                    {
                                        Field = field,
                                        Value = valueSegment.Utf8String()
                                    };
                                }
                                break;

                            case JsonToken.Number:
                                query = new FuzzyNumericQuery
                                {
                                    Field = field,
                                    Value = reader.ReadDouble()
                                };
                                break;
                            }

                            if (fuzzinessSegment != default)
                            {
                                var fuzzinessReader = new JsonReader(fuzzinessSegment.Array, fuzzinessSegment.Offset);
                                SetFuzziness(ref fuzzinessReader, query, formatterResolver);
                            }
                            break;
                        }

                        case 1:
                        {
                            if (query != null)
                            {
                                SetFuzziness(ref reader, query, formatterResolver);
                            }
                            else
                            {
                                fuzzinessSegment = reader.ReadNextBlockSegment();
                            }
                            break;
                        }

                        case 2:
                            prefixLength = reader.ReadInt32();
                            break;

                        case 3:
                            maxExpansions = reader.ReadInt32();
                            break;

                        case 4:
                            transpositions = reader.ReadBoolean();
                            break;

                        case 5:
                            var rewriteFormatter = formatterResolver.GetFormatter <MultiTermQueryRewrite>();
                            multiTermQueryRewrite = rewriteFormatter.Deserialize(ref reader, formatterResolver);
                            break;

                        case 6:
                            name = reader.ReadString();
                            break;

                        case 7:
                            boost = reader.ReadDouble();
                            break;
                        }
                    }
                }
            }

            query.PrefixLength   = prefixLength;
            query.MaxExpansions  = maxExpansions;
            query.Transpositions = transpositions;
            query.Rewrite        = multiTermQueryRewrite;
            query.Name           = name;
            query.Boost          = boost;
            return(query);
        }
コード例 #15
0
        public void Serialize(ref JsonWriter writer, TriggerContainer value, IJsonFormatterResolver formatterResolver)
        {
            var queryFormatter = formatterResolver.GetFormatter <ITriggerContainer>();

            queryFormatter.Serialize(ref writer, value, formatterResolver);
        }
コード例 #16
0
        private Dictionary <string, object> GetMetadata(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var meta = formatterResolver.GetFormatter <Dictionary <string, object> >().Deserialize(ref reader, formatterResolver);

            return(meta);
        }
コード例 #17
0
        public ITriggerContainer Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var formatter = formatterResolver.GetFormatter <TriggerContainer>();

            return(formatter.Deserialize(ref reader, formatterResolver));
        }
コード例 #18
0
        private IAggregate GetMultiBucketAggregate(ref JsonReader reader, IJsonFormatterResolver formatterResolver,
                                                   ref ArraySegment <byte> propertyName, IReadOnlyDictionary <string, object> meta)
        {
            var bucket = new BucketAggregate {
                Meta = meta
            };

            if (propertyName.EqualsBytes(DocCountErrorUpperBound))
            {
                bucket.DocCountErrorUpperBound = reader.ReadNullableLong();
                reader.ReadIsValueSeparatorWithVerify();
                propertyName = reader.ReadPropertyNameSegmentRaw();
            }

            if (propertyName.EqualsBytes(SumOtherDocCount))
            {
                bucket.SumOtherDocCount = reader.ReadNullableLong();
                reader.ReadIsValueSeparatorWithVerify();
                reader.ReadNext();                 // "buckets"
                reader.ReadNext();                 // :
            }

            var items = new List <IBucket>();

            bucket.Items = items;
            var count = 0;
            var token = reader.GetCurrentJsonToken();

            if (token == JsonToken.BeginObject)
            {
                var filterAggregates = new Dictionary <string, IAggregate>();
                while (reader.ReadIsInObject(ref count))
                {
                    var name     = reader.ReadPropertyName();
                    var innerAgg = ReadAggregate(ref reader, formatterResolver);
                    filterAggregates[name] = innerAgg;
                }
                return(new FiltersAggregate(filterAggregates)
                {
                    Meta = meta
                });
            }

            while (reader.ReadIsInArray(ref count))
            {
                var item = ReadBucket(ref reader, formatterResolver);
                items.Add(item);
            }

            token = reader.GetCurrentJsonToken();
            if (token == JsonToken.ValueSeparator)
            {
                reader.ReadNext();
                propertyName = reader.ReadPropertyNameSegmentRaw();
                if (propertyName.EqualsBytes(JsonWriter.GetEncodedPropertyNameWithoutQuotation("interval")))
                {
                    bucket.Interval = formatterResolver.GetFormatter <Time>().Deserialize(ref reader, formatterResolver);
                }
                else
                {
                    // skip for now
                    reader.ReadNextBlock();
                }
            }

            return(bucket);
        }
コード例 #19
0
        public IValidateDetectorRequest Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var formatter = formatterResolver.GetFormatter <ValidateDetectorRequest>();

            return(formatter.Deserialize(ref reader, formatterResolver));
        }
コード例 #20
0
        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
            });
        }
コード例 #21
0
 private void Serialize <TLifecycleAction>(ref JsonWriter writer, ILifecycleAction value, IJsonFormatterResolver formatterResolver)
     where TLifecycleAction : ILifecycleAction =>
 formatterResolver.GetFormatter <TLifecycleAction>().Serialize(ref writer, (TLifecycleAction)value, formatterResolver);
コード例 #22
0
        private IAggregate ReadAggregate(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            reader.ReadIsBeginObjectWithVerify();
            IAggregate aggregate = null;

            if (reader.ReadIsEndObject())
            {
                return(aggregate);
            }

            var propertyName = reader.ReadPropertyNameSegmentRaw();
            Dictionary <string, object> meta = null;

            if (propertyName.EqualsBytes(MetaField))
            {
                meta = GetMetadata(ref reader, formatterResolver);
                reader.ReadIsValueSeparatorWithVerify();
                propertyName = reader.ReadPropertyNameSegmentRaw();
            }

            if (RootFields.TryGetValue(propertyName, out var value))
            {
                switch (value)
                {
                case 0:
                    aggregate = GetPercentilesAggregate(ref reader, meta);
                    break;

                case 1:
                    aggregate = GetValueAggregate(ref reader, formatterResolver, meta);
                    break;

                case 2:
                    var compositeKeyFormatter = formatterResolver.GetFormatter <CompositeKey>();
                    var afterKey = compositeKeyFormatter.Deserialize(ref reader, formatterResolver);
                    reader.ReadNext();                             // ,
                    propertyName = reader.ReadPropertyNameSegmentRaw();
                    var bucketAggregate = propertyName.EqualsBytes(BucketsField)
                                                        ? GetMultiBucketAggregate(ref reader, formatterResolver, ref propertyName, meta) as BucketAggregate ?? new BucketAggregate {
                        Meta = meta
                    }
                                                        : new BucketAggregate {
                        Meta = meta
                    };
                    bucketAggregate.AfterKey = afterKey;
                    aggregate = bucketAggregate;
                    break;

                case 3:
                case 4:
                    aggregate = GetMultiBucketAggregate(ref reader, formatterResolver, ref propertyName, meta);
                    break;

                case 5:
                    aggregate = GetStatsAggregate(ref reader, formatterResolver, meta);
                    break;

                case 6:
                    aggregate = GetSingleBucketAggregate(ref reader, formatterResolver, meta);
                    break;

                case 7:
                    aggregate = GetGeoBoundsAggregate(ref reader, formatterResolver, meta);
                    break;

                case 8:
                    aggregate = GetTopHitsAggregate(ref reader, formatterResolver, meta);
                    break;

                case 9:
                    aggregate = GetGeoCentroidAggregate(ref reader, formatterResolver, meta);
                    break;

                case 10:
                    aggregate = GetMatrixStatsAggregate(ref reader, formatterResolver, meta);
                    break;

                case 11:
                    aggregate = GetBoxplotAggregate(ref reader, formatterResolver, meta);
                    break;

                case 12:
                    aggregate = GetTopMetricsAggregate(ref reader, formatterResolver, meta);
                    break;
                }
            }
            else
            {
                reader.ReadNextBlock();
            }

            reader.ReadIsEndObjectWithVerify();
            return(aggregate);
        }
コード例 #23
0
        public void Serialize(ref JsonWriter writer, IPercentilesAggregation value, IJsonFormatterResolver formatterResolver)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            writer.WriteBeginObject();
            var propertyWritten = false;

            if (value.Meta != null && value.Meta.Any())
            {
                writer.WritePropertyName("meta");
                var formatter = formatterResolver.GetFormatter <IDictionary <string, object> >();
                formatter.Serialize(ref writer, value.Meta, formatterResolver);
                propertyWritten = true;
            }

            if (value.Field != null)
            {
                if (propertyWritten)
                {
                    writer.WriteValueSeparator();
                }

                var settings = formatterResolver.GetConnectionSettings();
                writer.WritePropertyName("field");
                writer.WriteString(settings.Inferrer.Field(value.Field));
                propertyWritten = true;
            }

            if (value.Script != null)
            {
                if (propertyWritten)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("script");
                var formatter = formatterResolver.GetFormatter <IScript>();
                formatter.Serialize(ref writer, value.Script, formatterResolver);
                propertyWritten = true;
            }

            if (value.Method != null)
            {
                if (propertyWritten)
                {
                    writer.WriteValueSeparator();
                }

                switch (value.Method)
                {
                case ITDigestMethod tdigest:
                {
                    writer.WritePropertyName("tdigest");
                    writer.WriteBeginObject();
                    if (tdigest.Compression.HasValue)
                    {
                        writer.WritePropertyName("compression");
                        writer.WriteDouble(tdigest.Compression.Value);
                    }
                    writer.WriteEndObject();
                    break;
                }

                case IHDRHistogramMethod hdr:
                {
                    writer.WritePropertyName("hdr");
                    writer.WriteBeginObject();
                    if (hdr.NumberOfSignificantValueDigits.HasValue)
                    {
                        writer.WritePropertyName("number_of_significant_value_digits");
                        writer.WriteInt32(hdr.NumberOfSignificantValueDigits.Value);
                    }
                    writer.WriteEndObject();
                    break;
                }
                }

                propertyWritten = true;
            }

            if (value.Missing.HasValue)
            {
                if (propertyWritten)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("missing");
                writer.WriteDouble(value.Missing.Value);
                propertyWritten = true;
            }

            if (value.Percents != null)
            {
                if (propertyWritten)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("percents");
                var formatter = formatterResolver.GetFormatter <IEnumerable <double> >();
                formatter.Serialize(ref writer, value.Percents, formatterResolver);
                propertyWritten = true;
            }

            if (value.Keyed.HasValue)
            {
                if (propertyWritten)
                {
                    writer.WriteValueSeparator();
                }

                writer.WritePropertyName("keyed");
                writer.WriteBoolean(value.Keyed.Value);
            }

            writer.WriteEndObject();
        }
コード例 #24
0
        public IQueryContainer Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var queryFormatter = formatterResolver.GetFormatter <QueryContainer>();

            return(queryFormatter.Deserialize(ref reader, formatterResolver));
        }
コード例 #25
0
        public IMovingAverageAggregation Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            if (reader.GetCurrentJsonToken() != JsonToken.BeginObject)
            {
                reader.ReadNextBlock();
                return(null);
            }

            var count                        = 0;
            var aggregation                  = new MovingAverageAggregation();
            ArraySegment <byte> model        = default;
            ArraySegment <byte> modelSegment = default;

            while (reader.ReadIsInObject(ref count))
            {
                var propertyName = reader.ReadPropertyNameSegmentRaw();
                if (AutomataDictionary.TryGetValue(propertyName, out var value))
                {
                    switch (value)
                    {
                    case 0:
                        aggregation.Format = reader.ReadString();
                        break;

                    case 1:
                        aggregation.GapPolicy = formatterResolver.GetFormatter <GapPolicy?>()
                                                .Deserialize(ref reader, formatterResolver);
                        break;

                    case 2:
                        aggregation.Minimize = reader.ReadBoolean();
                        break;

                    case 3:
                        aggregation.Predict = reader.ReadInt32();
                        break;

                    case 4:
                        aggregation.Window = reader.ReadInt32();
                        break;

                    case 5:
                        modelSegment = reader.ReadNextBlockSegment();
                        break;

                    case 6:
                        model = reader.ReadStringSegmentUnsafe();
                        break;

                    case 7:
                        var path = reader.ReadString();
                        if (!string.IsNullOrEmpty(path))
                        {
                            aggregation.BucketsPath = new SingleBucketsPath(path);
                        }
                        break;
                    }
                }
            }

            if (model != default && ModelDictionary.TryGetValue(model, out var modelValue))
            {
                var modelReader = new JsonReader(modelSegment.Array, modelSegment.Offset);
                switch (modelValue)
                {
                case 0:
                    aggregation.Model = formatterResolver.GetFormatter <LinearModel>()
                                        .Deserialize(ref modelReader, formatterResolver);
                    break;

                case 1:
                    aggregation.Model = formatterResolver.GetFormatter <SimpleModel>()
                                        .Deserialize(ref modelReader, formatterResolver);
                    break;

                case 2:
                    aggregation.Model = formatterResolver.GetFormatter <EwmaModel>()
                                        .Deserialize(ref modelReader, formatterResolver);
                    break;

                case 3:
                    aggregation.Model = formatterResolver.GetFormatter <HoltLinearModel>()
                                        .Deserialize(ref modelReader, formatterResolver);
                    break;

                case 4:
                    aggregation.Model = formatterResolver.GetFormatter <HoltWintersModel>()
                                        .Deserialize(ref modelReader, formatterResolver);
                    break;
                }
            }

            return(aggregation);
        }
        public virtual T Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var formatter = formatterResolver.GetFormatter <TRead>();

            return(formatter.Deserialize(ref reader, formatterResolver));
        }
コード例 #27
0
        public void Serialize(ref JsonWriter writer, Attachment value, IJsonFormatterResolver formatterResolver)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            if (!value.ContainsMetadata)
            {
                writer.WriteString(value.Content);
            }
            else
            {
                writer.WriteBeginObject();
                writer.WritePropertyName("content");
                writer.WriteString(value.Content);

                if (!string.IsNullOrEmpty(value.Author))
                {
                    writer.WriteValueSeparator();
                    writer.WritePropertyName("author");
                    writer.WriteString(value.Author);
                }

                if (value.ContentLength.HasValue)
                {
                    writer.WriteValueSeparator();
                    writer.WritePropertyName("content_length");
                    writer.WriteInt64(value.ContentLength.Value);
                }

                if (!string.IsNullOrEmpty(value.ContentType))
                {
                    writer.WriteValueSeparator();
                    writer.WritePropertyName("content_type");
                    writer.WriteString(value.ContentType);
                }

                if (value.Date.HasValue)
                {
                    writer.WriteValueSeparator();
                    writer.WritePropertyName("date");
                    formatterResolver.GetFormatter <DateTime?>().Serialize(ref writer, value.Date, formatterResolver);
                }

                if (value.DetectLanguage.HasValue)
                {
                    writer.WriteValueSeparator();
                    writer.WritePropertyName("detect_language");
                    writer.WriteBoolean(value.DetectLanguage.Value);
                }

                if (value.IndexedCharacters.HasValue)
                {
                    writer.WriteValueSeparator();
                    writer.WritePropertyName("indexed_chars");
                    writer.WriteInt64(value.IndexedCharacters.Value);
                }

                if (!string.IsNullOrEmpty(value.Keywords))
                {
                    writer.WriteValueSeparator();
                    writer.WritePropertyName("keywords");
                    writer.WriteString(value.Keywords);
                }

                if (!string.IsNullOrEmpty(value.Language))
                {
                    writer.WriteValueSeparator();
                    writer.WritePropertyName("language");
                    writer.WriteString(value.Language);
                }

                if (!string.IsNullOrEmpty(value.Name))
                {
                    writer.WriteValueSeparator();
                    writer.WritePropertyName("name");
                    writer.WriteString(value.Name);
                }

                if (!string.IsNullOrEmpty(value.Title))
                {
                    writer.WriteValueSeparator();
                    writer.WritePropertyName("title");
                    writer.WriteString(value.Title);
                }

                writer.WriteEndObject();
            }
        }
コード例 #28
0
 private static IRankFeatureFunction DeserializeScoreFunction <TScoreFunction>(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
     where TScoreFunction : IRankFeatureFunction =>
 formatterResolver.GetFormatter <TScoreFunction>().Deserialize(ref reader, formatterResolver);
コード例 #29
0
 public IPrivileges Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver) =>
 formatterResolver.GetFormatter <Privileges>().Deserialize(ref reader, formatterResolver);
コード例 #30
0
        public IDynamicTemplateContainer Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
        {
            var formatter = formatterResolver.GetFormatter <DynamicTemplateContainer>();

            return(formatter.Deserialize(ref reader, formatterResolver));
        }