예제 #1
0
        /// <summary>
        /// Optimized deserialization of a LogMessagePacket based on the current packet definition
        /// </summary>
        public new void ReadFieldsFast(IFieldReader reader)
        {
            base.ReadFieldsFast(reader);

            m_ID           = reader.ReadGuid();
            m_Caption      = reader.ReadString();
            m_Severity     = (LogMessageSeverity)reader.ReadInt32();
            m_LogSystem    = reader.ReadString();
            m_CategoryName = reader.ReadString();
            m_UserName     = reader.ReadString();
            m_Description  = reader.ReadString();
            m_Details      = reader.ReadString();
            m_ThreadIndex  = reader.ReadInt32();
            m_ThreadId     = reader.ReadInt32();
            m_MethodName   = reader.ReadString();
            m_ClassName    = reader.ReadString();
            m_FileName     = reader.ReadString();
            m_LineNumber   = reader.ReadInt32();
            string[] typeNames         = reader.ReadStringArray();
            string[] messages          = reader.ReadStringArray();
            string[] sources           = reader.ReadStringArray();
            string[] stackTraces       = reader.ReadStringArray();
            Guid     applicationUserId = reader.ReadGuid();

            if (m_ThreadIndex == 0)
            {
                m_ThreadIndex = m_ThreadId; // Zero isn't legal, so it must not have had it.  Fall back to ThreadId.
            }
            if (applicationUserId != Guid.Empty)
            {
                ApplicationUser applicationUser;
                m_SessionPacketCache.Users.TryGetValue(applicationUserId, out applicationUser);
                UserPacket = applicationUser.Packet;
            }

            //these are supposed to be parallel arrays - assume they're all the same size.
            int arrayLength = typeNames.GetLength(0);
            var exceptions  = new IExceptionInfo[arrayLength]; // local holder to build it up

            IExceptionInfo lastException = null;

            for (int i = 0; i < arrayLength; i++)
            {
                IExceptionInfo exception = new ExceptionInfoPacket()
                {
                    TypeName   = typeNames[i],
                    Message    = messages[i],
                    Source     = sources[i],
                    StackTrace = stackTraces[i],
                };
                exceptions[i] = exception;
                if (lastException != null)
                {
                    ((ExceptionInfoPacket)lastException).InnerException = exception; //we are the inner exception to our parent.
                }
                lastException = exception;
            }

            m_ExceptionChain = exceptions; // Set the rehydrated ExceptionInfo[] array property
        }
예제 #2
0
        /// <summary>
        /// Read any packet based solely on its PacketDefinition
        /// </summary>
        /// <param name="definition">PacketDefinition describing the next packet in the stream</param>
        /// <param name="reader">Data stream to be read</param>
        public GenericPacket(PacketDefinition definition, IFieldReader reader)
        {
            if (definition.BasePacket != null)
            {
                m_BasePacket = new GenericPacket(definition.BasePacket, reader);
            }

            m_Definition  = definition;
            m_FieldValues = new object[definition.Fields.Count];

            for (int index = 0; index < definition.Fields.Count; index++)
            {
                switch (definition.Fields[index].FieldType)
                {
                case FieldType.Bool:
                    m_FieldValues[index] = reader.ReadBool();
                    break;

                case FieldType.BoolArray:
                    m_FieldValues[index] = reader.ReadBoolArray();
                    break;

                case FieldType.String:
                    m_FieldValues[index] = reader.ReadString();
                    break;

                case FieldType.StringArray:
                    m_FieldValues[index] = reader.ReadStringArray();
                    break;

                case FieldType.Int32:
                    m_FieldValues[index] = reader.ReadInt32();
                    break;

                case FieldType.Int32Array:
                    m_FieldValues[index] = reader.ReadInt32Array();
                    break;

                case FieldType.Int64:
                    m_FieldValues[index] = reader.ReadInt64();
                    break;

                case FieldType.Int64Array:
                    m_FieldValues[index] = reader.ReadInt64Array();
                    break;

                case FieldType.UInt32:
                    m_FieldValues[index] = reader.ReadUInt32();
                    break;

                case FieldType.UInt32Array:
                    m_FieldValues[index] = reader.ReadUInt32Array();
                    break;

                case FieldType.UInt64:
                    m_FieldValues[index] = reader.ReadUInt64();
                    break;

                case FieldType.UInt64Array:
                    m_FieldValues[index] = reader.ReadUInt64Array();
                    break;

                case FieldType.Double:
                    m_FieldValues[index] = reader.ReadDouble();
                    break;

                case FieldType.DoubleArray:
                    m_FieldValues[index] = reader.ReadDoubleArray();
                    break;

                case FieldType.TimeSpan:
                    m_FieldValues[index] = reader.ReadTimeSpan();
                    break;

                case FieldType.TimeSpanArray:
                    m_FieldValues[index] = reader.ReadTimeSpanArray();
                    break;

                case FieldType.DateTime:
                    m_FieldValues[index] = reader.ReadDateTime();
                    break;

                case FieldType.DateTimeArray:
                    m_FieldValues[index] = reader.ReadDateTimeArray();
                    break;

                case FieldType.Guid:
                    m_FieldValues[index] = reader.ReadGuid();
                    break;

                case FieldType.GuidArray:
                    m_FieldValues[index] = reader.ReadGuidArray();
                    break;

                case FieldType.DateTimeOffset:
                    m_FieldValues[index] = reader.ReadDateTimeOffset();
                    break;

                case FieldType.DateTimeOffsetArray:
                    m_FieldValues[index] = reader.ReadDateTimeOffsetArray();
                    break;

                default:
#if DEBUG
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
#endif
                    throw new InvalidOperationException(string.Format("The field type {0} is unknown so we can't deserialize the packet ", definition.Fields[index].FieldType));
                }
            }
        }