Пример #1
0
        internal unsafe ProviderManifest AddChunk(TraceEvent data)
        {
            if (provider != null)
                return null;

            // TODO
            if (data.EventDataLength <= sizeof(ManifestEnvelope) || data.GetByteAt(3) != 0x5B)  // magic number
                return null;

            ushort totalChunks = (ushort)data.GetInt16At(4);
            ushort chunkNum = (ushort)data.GetInt16At(6);
            if (chunkNum >= totalChunks || totalChunks == 0)
                return null;

            if (Chunks == null)
            {
                format = (ManifestEnvelope.ManifestFormats)data.GetByteAt(0);
                majorVersion = (byte)data.GetByteAt(1);
                minorVersion = (byte)data.GetByteAt(2);
                ChunksLeft = totalChunks;
                Chunks = new byte[ChunksLeft][];
            }
            else
            {
                // Chunks have to agree with the format and version information.
                if (format != (ManifestEnvelope.ManifestFormats)data.GetByteAt(0) ||
                    majorVersion != data.GetByteAt(1) || minorVersion == data.GetByteAt(2))
                    return null;
            }

            if (Chunks[chunkNum] != null)
                return null;

            byte[] chunk = new byte[data.EventDataLength - 8];
            Chunks[chunkNum] = data.EventData(chunk, 0, 8, chunk.Length);
            --ChunksLeft;
            if (ChunksLeft > 0)
                return null;

            // OK we have a complete set of chunks
            byte[] serializedData = Chunks[0];
            if (Chunks.Length > 1)
            {
                int totalLength = 0;
                for (int i = 0; i < Chunks.Length; i++)
                    totalLength += Chunks[i].Length;

                // Concatinate all the arrays.
                serializedData = new byte[totalLength];
                int pos = 0;
                for (int i = 0; i < Chunks.Length; i++)
                {
                    Array.Copy(Chunks[i], 0, serializedData, pos, Chunks[i].Length);
                    pos += Chunks[i].Length;
                }
            }
            Chunks = null;
            // string str = Encoding.UTF8.GetString(serializedData);
            provider = new ProviderManifest(serializedData, format, majorVersion, minorVersion);
            return provider;
        }
            internal unsafe ProviderManifest AddChunk(TraceEvent data)
            {
                //SLAB update
                //removed check to allow recomputing new manifest on any new incoming chunk 
                //if (provider != null)
                //    return null;

                // TODO 
                if (data.EventDataLength <= sizeof(ManifestEnvelope) || data.GetByteAt(3) != 0x5B)  // magic number 
                    return null;

                ushort totalChunks = (ushort)data.GetInt16At(4);
                ushort chunkNum = (ushort)data.GetInt16At(6);
                if (chunkNum >= totalChunks || totalChunks == 0)
                    return null;

                // SLAB update
                if (Chunks == null || (lastChunkReceptionTime.HasValue && lastChunkReceptionTime.Value.Add(ChunkReceptionStalePeriod) < DateTime.Now))
                {
                    format = (ManifestEnvelope.ManifestFormats)data.GetByteAt(0);
                    majorVersion = (byte)data.GetByteAt(1);
                    minorVersion = (byte)data.GetByteAt(2);
                    ChunksLeft = totalChunks;
                    Chunks = new byte[ChunksLeft][];
                }
                else
                {
                    // Chunks have to agree with the format and version information. 
                    if (format != (ManifestEnvelope.ManifestFormats)data.GetByteAt(0) ||
                        majorVersion != data.GetByteAt(1) || minorVersion != data.GetByteAt(2))
                        return null;
                }

                if (Chunks[chunkNum] != null)
                    return null;

                byte[] chunk = new byte[data.EventDataLength - 8];
                Chunks[chunkNum] = data.EventData(chunk, 0, 8, chunk.Length);
                --ChunksLeft;
                lastChunkReceptionTime = DateTime.Now;  // SLAB update

                if (ChunksLeft > 0)
                    return null;

                // OK we have a complete set of chunks
                byte[] serializedData = Chunks[0];
                if (Chunks.Length > 1)
                {
                    int totalLength = 0;
                    for (int i = 0; i < Chunks.Length; i++)
                        totalLength += Chunks[i].Length;

                    // Concatinate all the arrays. 
                    serializedData = new byte[totalLength];
                    int pos = 0;
                    for (int i = 0; i < Chunks.Length; i++)
                    {
                        Array.Copy(Chunks[i], 0, serializedData, pos, Chunks[i].Length);
                        pos += Chunks[i].Length;
                    }
                }
                Chunks = null;
                lastChunkReceptionTime = null;  // SLAB update
                // string str = Encoding.UTF8.GetString(serializedData);
                provider = new ProviderManifest(serializedData, format, majorVersion, minorVersion);
                provider.ISDynamic = true;
                return provider;
            }