Пример #1
0
        /// <summary>
        /// Reads TShark formatted data files.
        /// </summary>
        /// <param name="sourceFile">The original capture file path.</param>
        /// <param name="schema">The TShark schema.</param>
        /// <param name="dataFile">The TShark data file path.</param>
        /// <param name="callback">Callback that will receive data rows.</param>
        /// <param name="fixups">Fixups object containing any fixups to apply.</param>
        public static void Read(string sourceFile, TSharkDataSchema schema, string dataFile, TSharkDataReaderCallback callback, TSharkFixups fixups)
        {
            XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();

            xmlReaderSettings.ConformanceLevel             = ConformanceLevel.Document;
            xmlReaderSettings.IgnoreComments               = true;
            xmlReaderSettings.IgnoreProcessingInstructions = true;
            xmlReaderSettings.IgnoreWhitespace             = true;
            xmlReaderSettings.ValidationType               = ValidationType.None;

            CapFile capFile = new CapFile();

            capFile.Path = sourceFile;

            using (StreamReader dataReader = new StreamReader(dataFile, Encoding.UTF8))
                using (XmlReader xmlReader = XmlReader.Create(dataReader, xmlReaderSettings))
                {
                    ParseState state = new ParseState();
                    state.Schema   = schema;
                    state.Document = new XmlDocument();
                    state.Reader   = xmlReader;
                    state.File     = capFile;
                    state.Callback = callback;
                    state.Fixups   = fixups;

                    int index = 0;

                    // read all packets in the file
                    while (true)
                    {
                        if (!xmlReader.ReadToFollowing("packet"))
                        {
                            break;
                        }

                        CapPacket capPacket = new CapPacket();
                        capPacket.File   = state.File;
                        capPacket.Number = index++;

                        try
                        {
                            state.Packet = capPacket;

                            ReadPacket(state);
                        }
                        catch (Exception ex)
                        {
                            Log.WriteError("Error processing packet.\nIndex: {0}\nError: {1}", index, ex.Message);
                        }
                        finally
                        {
                            state.Packet = null;
                        }
                    }
                }
        }
Пример #2
0
        /// <summary>
        /// Reads TShark formatted data files.
        /// </summary>
        /// <param name="sourceFile">The original capture file path.</param>
        /// <param name="schema">The TShark schema.</param>
        /// <param name="dataFile">The TShark data file path.</param>
        /// <param name="callback">Callback that will receive data rows.</param>
        /// <param name="fixups">Fixups object containing any fixups to apply.</param>
        public static void Read(string sourceFile, TSharkDataSchema schema, string dataFile, TSharkDataReaderCallback callback, TSharkFixups fixups)
        {
            XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
            xmlReaderSettings.ConformanceLevel = ConformanceLevel.Document;
            xmlReaderSettings.IgnoreComments = true;
            xmlReaderSettings.IgnoreProcessingInstructions = true;
            xmlReaderSettings.IgnoreWhitespace = true;
            xmlReaderSettings.ValidationType = ValidationType.None;

            CapFile capFile = new CapFile();
            capFile.Path = sourceFile;

            using (StreamReader dataReader = new StreamReader(dataFile, Encoding.UTF8))
            using (XmlReader xmlReader = XmlReader.Create(dataReader, xmlReaderSettings))
            {
                ParseState state = new ParseState();
                state.Schema = schema;
                state.Document = new XmlDocument();
                state.Reader = xmlReader;
                state.File = capFile;
                state.Callback = callback;
                state.Fixups = fixups;

                int index = 0;

                // read all packets in the file
                while (true)
                {
                    if (!xmlReader.ReadToFollowing("packet"))
                        break;

                    CapPacket capPacket = new CapPacket();
                    capPacket.File = state.File;
                    capPacket.Number = index++;

                    try
                    {
                        state.Packet = capPacket;

                        ReadPacket(state);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteError("Error processing packet.\nIndex: {0}\nError: {1}", index, ex.Message);
                    }
                    finally
                    {
                        state.Packet = null;
                    }
                }
            }
        }