/// <summary>
 /// Aggregates the data from given qualty info.
 /// </summary>
 /// <param name="source">The source quality info.</param>
 public void Aggregate(QueryResultQualityInfo source)
 {
     if (source.totalDroppedTimeSeries > 0)
     {
         foreach (var reason in source.droppedTimeSeries)
         {
             this.RegisterDroppedTimeSeries(reason.Key, reason.Value);
         }
     }
 }
示例#2
0
        private bool ReadPreamble(
            BinaryReader reader,
            out byte version,
            out uint resultTimeSeriesCount,
            out Dictionary <int, string> stringTable,
            out long stringTableLengthInByte,
            out SeriesMetadata seriesMetadata,
            out Dictionary <int, SeriesMetadata> metadataTable,
            out long metadataTableLengthInByte)
        {
            resultTimeSeriesCount     = 0;
            stringTable               = null;
            stringTableLengthInByte   = 0;
            seriesMetadata            = null;
            metadataTable             = null;
            metadataTableLengthInByte = 0;

            version = reader.ReadByte();

            if (version == 0)
            {
                throw new MetricsClientException(
                          $"The server didn't respond with the right version of serialization - the initial version is 1 but the server responds with version 0.");
            }

            this.DiagnosticInfo = new DiagnosticInfo();
            if (version == VersionToIndicateCompleteFailure)
            {
                this.ErrorCode = (FilteredTimeSeriesQueryResponseErrorCode)reader.ReadInt16();

                // The trace ID and others will be filled in by callers.
                this.DiagnosticInfo.ErrorMessage = reader.ReadString();

                bool returnRequestObjectOnFailure = reader.ReadBoolean();
                if (returnRequestObjectOnFailure)
                {
                    this.QueryRequest = JsonConvert.DeserializeObject <FilteredTimeSeriesQueryRequest>(reader.ReadString());
                }

                return(false);
            }

            if (version > NextVersion)
            {
                throw new MetricsClientException(
                          $"The server didn't respond with the right version of serialization. CurrentVersion : {CurrentVersion}, NextVersion : {NextVersion}, Responded: {version}.");
            }

            var hasDataQualityInfo = reader.ReadBoolean();

            if (hasDataQualityInfo)
            {
                var queryResultQualityInfo = new QueryResultQualityInfo();
                queryResultQualityInfo.Deserialize(reader);
            }

            this.StartTimeUtc = new DateTime(
                (long)SerializationUtils.ReadUInt64FromBase128(reader) * TimeSpan.TicksPerMinute,
                DateTimeKind.Utc);
            this.EndTimeUtc = this.StartTimeUtc.AddMinutes(SerializationUtils.ReadUInt32FromBase128(reader));
            this.TimeResolutionInMinutes = (int)SerializationUtils.ReadUInt32FromBase128(reader);
            resultTimeSeriesCount        = SerializationUtils.ReadUInt32FromBase128(reader);

            /* Read string table. */
            var currentPosition             = reader.BaseStream.Position;
            var stringTableRelativePosition = reader.ReadUInt64();

            reader.BaseStream.Position = currentPosition + (long)stringTableRelativePosition;

            var stringTableStartPostion = reader.BaseStream.Position;
            var stringTableSize         = SerializationUtils.ReadUInt32FromBase128(reader);

            stringTable = new Dictionary <int, string>((int)stringTableSize);
            for (int i = 0; i < stringTableSize; i++)
            {
                stringTable.Add(i, reader.ReadString());
            }

            stringTableLengthInByte = reader.BaseStream.Position - stringTableStartPostion;

            // + sizeof (double) since we just read the stringTableRelativePosition as double.
            reader.BaseStream.Position = currentPosition + sizeof(double);

            if (version >= 3)
            {
                /* Read metadata table */
                currentPosition = reader.BaseStream.Position;
                var metadataTableRelativePosition = reader.ReadUInt64();
                reader.BaseStream.Position = currentPosition + (long)metadataTableRelativePosition;

                var metadataTableStartPostion = reader.BaseStream.Position;
                var metadataTableSize         = SerializationUtils.ReadUInt32FromBase128(reader);

                metadataTable = new Dictionary <int, SeriesMetadata>((int)metadataTableSize);
                for (var i = 0; i < metadataTableSize; i++)
                {
                    metadataTable.Add(i, DeserializeTimeSeriesMetadata(reader, stringTable));
                }

                metadataTableLengthInByte = reader.BaseStream.Position - metadataTableStartPostion;

                // + sizeof (double) since we just read the metadataTableRelativePosition as double.
                reader.BaseStream.Position = currentPosition + sizeof(double);
            }

            if (resultTimeSeriesCount > 0)
            {
                if (version < 3)
                {
                    seriesMetadata    = DeserializeTimeSeriesMetadata(reader, stringTable);
                    this.QueryRequest = new FilteredTimeSeriesQueryRequest(seriesMetadata.MetricIdentifier);
                }
                else
                {
                    this.QueryRequest = new FilteredTimeSeriesQueryRequest(metadataTable.Values.First().MetricIdentifier);
                }
            }

            return(true);
        }