예제 #1
0
        static unsafe ETLFile ReadETL(string cacheFile, long ETLpos)
        {
            FileStream  fileStream = null;
            long        ticks      = DateTime.MinValue.Ticks;
            long        num        = DateTime.MaxValue.Ticks;
            ushort      num1       = 0;
            List <uint> nums       = new List <uint>();

            fileStream = new FileStream(cacheFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            using (BinaryReader binaryReader = new BinaryReader(fileStream))
            {
                binaryReader.BaseStream.Position = ETLpos;
                do
                {
                    if ((binaryReader.BaseStream.Position + (long)32) > binaryReader.BaseStream.Length)
                    {
                        var result = new ETLFile
                        {
                            cacheFile = cacheFile,
                            ETLpos    = binaryReader.BaseStream.Position
                        };
                        return(result);
                    }
                    long position = binaryReader.BaseStream.Position;
                    int  num2     = binaryReader.ReadInt32();

                    //Check if full message was written
                    if ((binaryReader.BaseStream.Position + num2) > binaryReader.BaseStream.Length)
                    {
                        var result = new ETLFile
                        {
                            cacheFile = cacheFile,
                            ETLpos    = binaryReader.BaseStream.Position - 4
                        };
                        return(result);
                    }
                    //


                    byte[] numArray = new byte[num2];
                    binaryReader.BaseStream.Seek((long)-4, SeekOrigin.Current);
                    binaryReader.Read(numArray, 0, num2);
                    try
                    {
                        fixed(byte *numPointer = &numArray[0])
                        {
                            ETLCACHE_RECORD *eTLCACHERECORDPointer = (ETLCACHE_RECORD *)numPointer;
                            byte *           numPointer1           = (byte *)(eTLCACHERECORDPointer + sizeof(ETLCACHE_RECORD));
                            //string stringAnsi = Marshal.PtrToStringAnsi((IntPtr)numPointer1, (int)(*eTLCACHERECORDPointer).ComponentNameLength);
                            //long timestamp = (*eTLCACHERECORDPointer).Timestamp;
                            //ushort level = (*eTLCACHERECORDPointer).Level;
                            //uint correlationId = (*eTLCACHERECORDPointer).CorrelationId;

                            int tstart = 80 + (*eTLCACHERECORDPointer).ComponentNameLength + 15;

                            if (tstart < num2)
                            {
                                int tcount   = num2 - tstart;
                                var SipTrace = System.Text.Encoding.Default.GetString(numArray, tstart, tcount);
                                Console.WriteLine(SipTrace);
                                Console.WriteLine("-----------------------------------------------------------------------------");
                            }
                            else
                            {
                            }
                        }
                    }
                    finally
                    {
                        //numPointer = null;
                    }
                    binaryReader.BaseStream.Position = position + (long)num2;
                } while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length);
                var result1 = new ETLFile
                {
                    cacheFile = cacheFile,
                    ETLpos    = binaryReader.BaseStream.Position
                };
                return(result1);
            }
        }
예제 #2
0
        static unsafe void BuildCacheHeader(string cacheFile)
        {
            Test_ParseETL.Program.EtlCacheHeader etlCacheHeader = null;
            //if (File.Exists(cacheFile))
            //{
            //    long length = (new FileInfo(cacheFile)).Length;
            //    if (length == (long)0)
            //    {
            //        if (Tracing.traceProvider.Level >= 4 && (Tracing.traceProvider.Flags & 1) != 0)
            //        {
            //            WPP_25edaa5c3f39f667965e06ad27825958.WPP_ps(27, 10, (IntPtr)this.GetHashCode(), TraceProvider.MakeStringArg(cacheFile));
            //        }
            //        File.Delete(cacheFile);
            //        if (File.Exists(cacheHeaderFile))
            //        {
            //            File.Delete(cacheHeaderFile);
            //        }
            //        return null;
            //    }
            FileStream  fileStream = null;
            long        ticks      = DateTime.MinValue.Ticks;
            long        num        = DateTime.MaxValue.Ticks;
            ushort      num1       = 0;
            List <uint> nums       = new List <uint>();


            fileStream = new FileStream(cacheFile, FileMode.Open, FileAccess.Read);
            using (BinaryReader binaryReader = new BinaryReader(fileStream))
            {
                do
                {
                    long   position = binaryReader.BaseStream.Position;
                    int    num2     = binaryReader.ReadInt32();
                    byte[] numArray = new byte[num2];
                    binaryReader.BaseStream.Seek((long)-4, SeekOrigin.Current);
                    binaryReader.Read(numArray, 0, num2);
                    try
                    {
                        fixed(byte *numPointer = &numArray[0])
                        {
                            ETLCACHE_RECORD *eTLCACHERECORDPointer = (ETLCACHE_RECORD *)numPointer;
                            byte *           numPointer1           = (byte *)(eTLCACHERECORDPointer + sizeof(ETLCACHE_RECORD));
                            string           stringAnsi            = Marshal.PtrToStringAnsi((IntPtr)numPointer1, (int)(*eTLCACHERECORDPointer).ComponentNameLength);
                            long             timestamp             = (*eTLCACHERECORDPointer).Timestamp;
                            ushort           level         = (*eTLCACHERECORDPointer).Level;
                            uint             correlationId = (*eTLCACHERECORDPointer).CorrelationId;

                            int tstart = 80 + (*eTLCACHERECORDPointer).ComponentNameLength + 16;

                            if (tstart < num2)
                            {
                                int tcount   = num2 - tstart;
                                var SipTrace = System.Text.Encoding.Default.GetString(numArray, tstart, tcount);
                                Console.WriteLine(SipTrace);
                                Console.WriteLine("-----------------------------------------------------------------------------");
                            }
                            else
                            {
                            }

                            if (ticks == DateTime.MinValue.Ticks || timestamp < ticks)
                            {
                                ticks = timestamp;
                            }
                            if (num == DateTime.MaxValue.Ticks || timestamp > num)
                            {
                                num = timestamp;
                            }
                            if (level > 0 && (num1 == 0 || level < num1))
                            {
                                num1 = level;
                            }
                            if (!nums.Contains(correlationId))
                            {
                                nums.Add(correlationId);
                            }
                            //if (!strs.Contains<string>(stringAnsi, StringComparer.OrdinalIgnoreCase))
                            //{
                            //    strs.Add(stringAnsi);
                            //}
                        }
                    }
                    finally
                    {
                        //numPointer = null;
                    }
                    binaryReader.BaseStream.Position = position + (long)num2;
                }while (binaryReader.BaseStream.Position < 30000);
                //while (binaryReader.BaseStream.Position < length);
                //strs.Sort(StringComparer.OrdinalIgnoreCase);
                //nums.Sort();
                //EtlCacheHeader etlCacheHeader1 = new EtlCacheHeader()
                //{
                //    AgentVersion = "2.0",
                //    StartTime = new DateTime(ticks),
                //    EndTime = new DateTime(num),
                //    MostSevereLevel = num1,
                //    CorrelationIds = nums,
                //    ComponentNames = strs.ToArray()
                //};
                //etlCacheHeader = etlCacheHeader1;
                //if (!this.SerializeEtlCacheHeader(etlCacheHeader, cacheHeaderFile))
                //{
                //    if (Tracing.traceProvider.Level >= 2 && (Tracing.traceProvider.Flags & 1) != 0)
                //    {
                //        WPP_25edaa5c3f39f667965e06ad27825958.WPP_ps(27, 12, (IntPtr)this.GetHashCode(), TraceProvider.MakeStringArg(cacheFile));
                //    }
                //    etlCacheHeader = null;
                //}
                //else if (Tracing.traceProvider.Level >= 4 && (Tracing.traceProvider.Flags & 1) != 0)
                //{
                //    WPP_25edaa5c3f39f667965e06ad27825958.WPP_ps(27, 11, (IntPtr)this.GetHashCode(), TraceProvider.MakeStringArg(cacheHeaderFile));
                //}
            }


            //return etlCacheHeader;
        }