Ejemplo n.º 1
0
 internal static SupportedFileFormat DetectFileSchema(string filePath)
 {
     if (!string.IsNullOrEmpty(filePath))
     {
         if (filePath.EndsWith(SR.GetString("MainFrm_FileEtl"), StringComparison.OrdinalIgnoreCase))
         {
             return(SupportedFileFormat.EtlBinary);
         }
         if (filePath.EndsWith(SR.GetString("PJ_Extension"), StringComparison.OrdinalIgnoreCase))
         {
             return(SupportedFileFormat.STVProjectFile);
         }
         FileStream fileStream = null;
         char[]     array      = new char[8192];
         try
         {
             fileStream = Utilities.CreateFileStreamHelper(filePath);
             Utilities.SeekFileStreamHelper(fileStream, 0L, SeekOrigin.Begin);
             Utilities.CreateStreamReaderHelper(fileStream).Read(array, 0, array.Length);
         }
         catch (IOException)
         {
             return(SupportedFileFormat.UnknownFormat);
         }
         finally
         {
             Utilities.CloseStreamWithoutException(fileStream, isFlushStream: false);
         }
         string text = new string(array);
         text = text.Trim(' ', '\0', '\t', '\n');
         if (string.IsNullOrEmpty(text))
         {
             return(SupportedFileFormat.E2ETraceEventSchema);
         }
         int num  = text.IndexOf(crimsonSchemaTag, StringComparison.Ordinal);
         int num2 = text.IndexOf(e2eSchemaTag, StringComparison.Ordinal);
         if (num != -1 && num2 == -1)
         {
             return(SupportedFileFormat.CrimsonSchema);
         }
         if (num == -1 && num2 != -1)
         {
             return(SupportedFileFormat.E2ETraceEventSchema);
         }
         if (num != -1 && num2 == -1 && num < num2)
         {
             return(SupportedFileFormat.CrimsonSchema);
         }
         if (num != -1 && num2 == -1 && num > num2)
         {
             return(SupportedFileFormat.E2ETraceEventSchema);
         }
     }
     return(SupportedFileFormat.NotSupported);
 }
Ejemplo n.º 2
0
        internal TraceRecord GetFirstValidTrace(FileStream fs, long fileOffset, out long foundTraceFileOffset, out long potentialNextTraceOffset, TaskInfoBase task)
        {
            foundTraceFileOffset     = -1L;
            potentialNextTraceOffset = -1L;
            if (fs == null || fileOffset < 0 || fileOffset > fileLength)
            {
                return(null);
            }
            Utilities.SeekFileStreamHelper(fs, fileOffset, SeekOrigin.Begin);
            BinaryReader binaryReader = Utilities.CreateBinaryReaderHelper(fs);
            long         num          = fileOffset;

            while (true)
            {
                byte[] bytes = Utilities.ReadBytesHelper(binaryReader, 2046);
                int    num2  = 0;
                int    num3  = Utilities.ByteArrayIndexOf(bytes, findingBytes, num2);
                while (num3 != -1)
                {
                    num = fileOffset + num3;
                    Utilities.SeekFileStreamHelper(fs, num, SeekOrigin.Begin);
                    XmlTextReader xmlTextReader = new XmlTextReader(fs, XmlNodeType.Element, null);
                    xmlTextReader.WhitespaceHandling = WhitespaceHandling.None;
                    try
                    {
                        if (xmlTextReader.Read() && xmlTextReader.Name == "E2ETraceEvent")
                        {
                            TraceRecord traceRecord = new TraceRecord(dataSource);
                            traceRecord.ReadFrom(xmlTextReader, xmlUtil);
                            foundTraceFileOffset     = num;
                            potentialNextTraceOffset = foundTraceFileOffset + findingBytes.Length;
                            int typePositionPriority = 1024;
                            traceRecord.TraceRecordPos = new TraceRecordPosition(this, foundTraceFileOffset, traceRecord.Time, typePositionPriority);
                            traceRecord.TraceID        = foundTraceFileOffset + filePath.GetHashCode();
                            return(traceRecord);
                        }
                        if (fs.Position >= FileSize)
                        {
                            return(null);
                        }
                    }
                    catch (XmlException ex)
                    {
                        task?.SaveException(new E2EInvalidFileException(ex.Message, fs.Name, ex, num));
                    }
                    catch (E2EInvalidFileException ex2)
                    {
                        task?.SaveException(new E2EInvalidFileException(ex2.Message, fs.Name, ex2, num));
                    }
                    finally
                    {
                        num2 += num3 + findingBytes.Length;
                        num3  = Utilities.ByteArrayIndexOf(bytes, findingBytes, num2);
                    }
                }
                if (fs.Position >= FileSize)
                {
                    break;
                }
                fileOffset += 2046 - findingBytes.Length - 2;
                Utilities.SeekFileStreamHelper(fs, fileOffset, SeekOrigin.Begin);
            }
            return(null);
        }