public ProviderManifest(byte[] serializedManifest, ManifestEnvelope.ManifestFormats format, byte majorVersion, byte minorVersion) { this.serializedManifest = serializedManifest; this.majorVersion = majorVersion; this.minorVersion = minorVersion; this.format = format; }
internal unsafe void SendManifest(byte[] rawManifest, EventSource eventSource) { ManifestEnvelope envelope = new ManifestEnvelope(); envelope.Format = ManifestEnvelope.ManifestFormats.SimpleXmlFormat; envelope.MajorVersion = 1; envelope.MinorVersion = 0; envelope.Magic = 0x5B; // An unusual number that can be checked for consistancy. int dataLeft = rawManifest.Length; envelope.TotalChunks = (ushort)((dataLeft + (ManifestEnvelope.MaxChunkSize - 1)) / ManifestEnvelope.MaxChunkSize); envelope.ChunkNumber = 0; var manifestDescr = new EventDescriptor(0xFFFE, 1, 0, 0, 0xFE, 0xFFFE, -1); if (m_curITraceEvent == null) { throw new InvalidOperationException("Currently can only write the event being processed by the callback"); } // Make a copy of the template so we can modify it var manifestEvent = m_relogger.CreateEventInstance(m_traceHandleForFirstStream, 0); _EVENT_DESCRIPTOR *ptrDescr = (_EVENT_DESCRIPTOR *)&manifestDescr; manifestEvent.SetEventDescriptor(ref *ptrDescr); // Set the provider to the EventSoruce Guid providerGuid = eventSource.Guid; manifestEvent.SetProviderId(ref providerGuid); // Clone the process ID, thread ID and TimeStamp _EVENT_RECORD *eventRecord = (_EVENT_RECORD *)m_curITraceEvent.GetEventRecord(); manifestEvent.SetThreadId(eventRecord->EventHeader.ThreadId); manifestEvent.SetProcessId(eventRecord->EventHeader.ProcessId); manifestEvent.SetTimeStamp(ref eventRecord->EventHeader.TimeStamp); int bufferSize = sizeof(ManifestEnvelope) + Math.Min(ManifestEnvelope.MaxChunkSize, rawManifest.Length); byte[] buffer = new byte[bufferSize]; int manifestIdx = 0; // Where we are in the manifest. while (dataLeft > 0) { // Copy envelope into buffer byte *envelopePtr = (byte *)&envelope; int bufferIdx = 0; while (bufferIdx < sizeof(ManifestEnvelope)) { buffer[bufferIdx++] = *envelopePtr++; } // Copy chunk of manifest into buffer while (bufferIdx < buffer.Length && manifestIdx < rawManifest.Length) buffer[bufferIdx++] = rawManifest[manifestIdx++]; // write the envelope + chunk. fixed(byte *bufferPtr = buffer) { manifestEvent.SetPayload(ref *bufferPtr, (uint)bufferIdx); m_relogger.Inject(manifestEvent); } envelope.ChunkNumber++; Debug.Assert(envelope.ChunkNumber <= envelope.TotalChunks); dataLeft -= ManifestEnvelope.MaxChunkSize; } Debug.Assert(envelope.ChunkNumber == envelope.TotalChunks); }