Beispiel #1
0
        private static bool GetRelatedActivityId(IntPtr extendedDataPtr, out Guid relatedActivityId)
        {
            relatedActivityId = Guid.Empty;

            ApplicationDataReader reader = new ApplicationDataReader(extendedDataPtr, (ushort)ExtendedDataSize);
            ushort reserved1             = reader.ReadUInt16();
            ushort extType = reader.ReadUInt16();

            if (EventHeaderExtTypeRelatedActivityId != extType)
            {
                return(false);
            }
            ushort reserved2 = reader.ReadUInt16();
            ushort dataSize  = reader.ReadUInt16();
            ulong  dataPtr   = reader.ReadUInt64();

            ApplicationDataReader relatedActivityIdReader = new ApplicationDataReader(
                new IntPtr((long)dataPtr),
                dataSize);

            relatedActivityId = relatedActivityIdReader.ReadGuid();
            return(true);
        }
        public string FormatField(IFormatProvider provider, ApplicationDataReader reader, ValueMaps valueMaps)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (valueMaps == null)
            {
                throw new ArgumentNullException("valueMaps");
            }

            if (this.skipFormatting)
            {
                return("");
            }

            try
            {
                switch (this.inType)
                {
                case FieldType.UnicodeString:
                    return(reader.ReadUnicodeString());

                case FieldType.AnsiString:
                    return(reader.ReadAnsiString());

                case FieldType.Boolean:
                    return(reader.ReadBoolean().ToString());

                case FieldType.UInt8:
                    return(reader.ReadUInt8().ToString(provider));

                case FieldType.UInt16:
                    return(reader.ReadUInt16().ToString(provider));

                case FieldType.UInt32:
                    uint key = reader.ReadUInt32();

                    if (!string.IsNullOrEmpty(this.mapName))
                    {
                        string stringValue = null;
                        if (valueMaps.TryGetValue(this.mapName, key, out stringValue))
                        {
                            return(stringValue);
                        }
                    }

                    return(key.ToString(provider));

                case FieldType.UInt64:
                    UInt64 value = reader.ReadUInt64();

                    if (this.omitIfZero && value == 0)
                    {
                        return(System.String.Empty);
                    }

                    return(value.ToString(provider));

                case FieldType.Int8:
                    return(reader.ReadInt8().ToString(provider));

                case FieldType.Int16:
                    return(reader.ReadInt16().ToString(provider));

                case FieldType.Int32:
                    return(reader.ReadInt32().ToString(provider));

                case FieldType.Int64:
                    return(reader.ReadInt64().ToString(provider));

                case FieldType.HexInt32:
                    return(reader.ReadUInt32().ToString("x", provider));

                case FieldType.HexInt64:
                    value = reader.ReadUInt64();

                    if (this.omitIfZero && value == 0)
                    {
                        return(System.String.Empty);
                    }

                    return(value.ToString("x", provider));

                case FieldType.Float:
                    return(reader.ReadFloat().ToString(provider));

                case FieldType.Double:
                    return(reader.ReadDouble().ToString(provider));

                case FieldType.DateTime:
                    return(reader.ReadFileTime().ToString("yyyy-M-d HH:mm:ss.fff", provider));

                case FieldType.Guid:
                    return(reader.ReadGuid().ToString("D"));

                case FieldType.LargeInteger:
                    UInt64 highValue = reader.ReadUInt64();
                    UInt64 lowValue  = reader.ReadUInt64();

                    if (highValue == 0)
                    {
                        return(lowValue.ToString("x", provider));
                    }

                    return(highValue.ToString("x", provider) + lowValue.ToString("x16", provider));

                default:
                    return("<unknown type " + this.inType + ">");
                }
            }
            catch (OverflowException)
            {
                return("<unknown " + this.inType + " value>");
            }
            catch (ArgumentException e)
            {
                if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("WeakETLReader")))
                {
                    return(string.Format("(!!! Invalid value for field {0}: {1} !!!)", this.Name, e.Message));
                }
                throw;
            }
        }