public unsafe TraceEventInfoCPtr Build() { var strings = new[] { ProviderName, LevelName, ChannelName, KeywordsName, TaskName, OpcodeName, EventMessage, ProviderMessage, ActivityIDName, RelatedActivityIDName }; var size = sizeof(TRACE_EVENT_INFO); size += sizeof(EVENT_PROPERTY_INFO) * Math.Max(0, (int)PropertyCount - 1); int stringsOffset = size; foreach (var s in strings) { if (!string.IsNullOrEmpty(s)) { size += (s.Length + 1) * 2; } } var info = (TRACE_EVENT_INFO *)allocator.Allocate(size); *info = new TRACE_EVENT_INFO(); info->ProviderGuid = ProviderGuid; info->EventGuid = EventGuid; info->EventDescriptor = EventDescriptor; info->DecodingSource = DecodingSource; info->PropertyCount = PropertyCount; info->TopLevelPropertyCount = TopLevelPropertyCount; info->Flags = Flags; for (int i = 0; i < EventPropertyInfos.Length; ++i) { (&info->EventPropertyInfoArray)[i] = EventPropertyInfos[i]; } uint offset = (uint)stringsOffset; info->ProviderNameOffset = AddString(info, ref offset, ProviderName); info->LevelNameOffset = AddString(info, ref offset, LevelName); info->ChannelNameOffset = AddString(info, ref offset, ChannelName); info->KeywordsNameOffset = AddString(info, ref offset, KeywordsName); info->TaskNameOffset = AddString(info, ref offset, TaskName); info->OpcodeNameOffset = AddString(info, ref offset, OpcodeName); info->EventMessageOffset = AddString(info, ref offset, EventMessage); info->ProviderMessageOffset = AddString(info, ref offset, ProviderMessage); info->ActivityIDNameOffset = AddString(info, ref offset, ActivityIDName); info->RelatedActivityIDNameOffset = AddString(info, ref offset, RelatedActivityIDName); return(new TraceEventInfoCPtr(info, (uint)size)); }
public unsafe EventRecordCPtr Build() { if (userData.Count > ushort.MaxValue) { throw new OverflowException(); } ushort userDataLength = (ushort)userData.Count; var pr = (EVENT_RECORD *)allocator.Allocate(sizeof(EVENT_RECORD) + userDataLength); *pr = record; pr->UserData = (IntPtr)((byte *)pr + sizeof(EVENT_RECORD)); pr->UserDataLength = userDataLength; Marshal.Copy(userData.ToArray(), 0, pr->UserData, userDataLength); return(new EventRecordCPtr(pr)); }