Ejemplo n.º 1
0
        private FieldMetadata(
            string name,
            TraceLoggingDataType dataType,
            EventFieldTags tags,
            byte countFlags,
            ushort fixedCount = 0,
            byte[] custom     = null)
        {
            if (name == null)
            {
                throw new ArgumentNullException(
                          nameof(name),
                          "This usually means that the object passed to Write is of a type that"
                          + " does not support being used as the top-level object in an event,"
                          + " e.g. a primitive or built-in type.");
            }

            Statics.CheckName(name);
            var coreType = (int)dataType & Statics.InTypeMask;

            this.name       = name;
            nameSize        = Encoding.UTF8.GetByteCount(this.name) + 1;
            inType          = (byte)(coreType | countFlags);
            outType         = (byte)(((int)dataType >> 8) & Statics.OutTypeMask);
            this.tags       = tags;
            this.fixedCount = fixedCount;
            this.custom     = custom;

            if (countFlags != 0)
            {
                if (coreType == (int)TraceLoggingDataType.Nil)
                {
                    throw new NotSupportedException(Resources.GetResourceString("EventSource_NotSupportedArrayOfNil"));
                }
                if (coreType == (int)TraceLoggingDataType.Binary)
                {
                    throw new NotSupportedException(Resources.GetResourceString("EventSource_NotSupportedArrayOfBinary"));
                }
#if !BROKEN_UNTIL_M3
                if (coreType == (int)TraceLoggingDataType.Utf16String ||
                    coreType == (int)TraceLoggingDataType.MbcsString)
                {
                    throw new NotSupportedException(Resources.GetResourceString("EventSource_NotSupportedArrayOfNullTerminatedString"));
                }
#endif
            }

            if (((int)this.tags & 0xfffffff) != 0)
            {
                outType |= Statics.OutTypeChainFlag;
            }

            if (outType != 0)
            {
                inType |= Statics.InTypeChainFlag;
            }
        }
 /// <summary>
 /// A complete metadata chunk can be expressed as:
 /// length16 + prefix + null-terminated-utf8-name + suffix + additionalData.
 /// We assume that excludedData will be provided by some other means,
 /// but that its size is known. This function returns a blob containing
 /// length16 + prefix + name + suffix, with prefix and suffix initialized
 /// to 0's. The length16 value is initialized to the length of the returned
 /// blob plus additionalSize, so that the concatenation of the returned blob
 /// plus a blob of size additionalSize constitutes a valid metadata blob.
 /// </summary>
 /// <param name="name">
 /// The name to include in the blob.
 /// </param>
 /// <param name="prefixSize">
 /// Amount of space to reserve before name. For provider or field blobs, this
 /// should be 0. For event blobs, this is used for the tags field and will vary
 /// from 1 to 4, depending on how large the tags field needs to be.
 /// </param>
 /// <param name="suffixSize">
 /// Amount of space to reserve after name. For example, a provider blob with no
 /// traits would reserve 0 extra bytes, but a provider blob with a single GroupId
 /// field would reserve 19 extra bytes.
 /// </param>
 /// <param name="additionalSize">
 /// Amount of additional data in another blob. This value will be counted in the
 /// blob's length field, but will not be included in the returned byte[] object.
 /// The complete blob would then be the concatenation of the returned byte[] object
 /// with another byte[] object of length additionalSize.
 /// </param>
 /// <returns>
 /// A byte[] object with the length and name fields set, with room reserved for
 /// prefix and suffix. If additionalSize was 0, the byte[] object is a complete
 /// blob. Otherwise, another byte[] of size additionalSize must be concatenated
 /// with this one to form a complete blob.
 /// </returns>
 public static byte[] MetadataForString(
     string name,
     int prefixSize,
     int suffixSize,
     int additionalSize)
 {
     Statics.CheckName(name);
     int metadataSize = Encoding.UTF8.GetByteCount(name) + 3 + prefixSize + suffixSize;
     var metadata = new byte[metadataSize];
     ushort totalSize = checked((ushort)(metadataSize + additionalSize));
     metadata[0] = unchecked((byte)totalSize);
     metadata[1] = unchecked((byte)(totalSize >> 8));
     Encoding.UTF8.GetBytes(name, 0, name.Length, metadata, 2 + prefixSize);
     return metadata;
 }
Ejemplo n.º 3
0
 internal TraceLoggingTypeInfo(Type dataType, string name, EventLevel level, EventOpcode opcode, EventKeywords keywords, EventTags tags)
 {
     if (dataType == (Type)null)
     {
         throw new ArgumentNullException("dataType");
     }
     if (name == null)
     {
         throw new ArgumentNullException("eventName");
     }
     Statics.CheckName(name);
     this.name     = name;
     this.keywords = keywords;
     this.level    = level;
     this.opcode   = opcode;
     this.tags     = tags;
     this.dataType = dataType;
 }