Beispiel #1
0
        private void processRecord(BinaryReader reader, Endian endi, int recLength, string recName, int stdf_ver)
        {
            var buf     = ReadBytes(reader, recLength, endi);
            int buf_pos = 0;

            foreach (Tuple <string, string> f in StdfSpec.getRecFields(recName, stdf_ver))
            {
                string fname    = f.Item1;
                string dataType = f.Item2;
                object dataVal  = readRecData(buf, dataType.ToUpper(), ref buf_pos);

                if (onRecordProcessed != null)
                {
                    onRecordProcessed(recName, fname, dataType, dataVal);
                }
            }
        }
Beispiel #2
0
        public void parseFile(bool header_only = false)
        {
            using (FileStream fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                BinaryReader reader   = null;
                int          cpu_type = -1;
                int          stdf_ver = -1;
                Endian       endi     = Endian.Unknown;

                if (inputFile.ToLower().EndsWith(".gz"))
                {
                    reader = new BinaryReader(new System.IO.Compression.GZipStream(fs, System.IO.Compression.CompressionMode.Decompress));
                }
                else
                {
                    reader = new BinaryReader(fs);
                }

                try
                {
                    getFAR(reader, out cpu_type, out stdf_ver);

                    if (stdf_ver != 3 && stdf_ver != 4)
                    {
                        throw new Exception("unknown cpu type");
                    }

                    if (cpu_type <= 0)
                    {
                        throw new Exception("unknown cpu type");
                    }
                    else
                    {
                        if (cpu_type == 1)
                        {
                            endi = Endian.Big;
                        }
                        else if (cpu_type == 2)
                        {
                            endi = Endian.Little;
                        }
                    }

                    int recLength  = -1;
                    int recType    = -1;
                    int recSubType = -1;

                    while (true)
                    {
                        if (abordProcess != null && abordProcess())
                        {
                            break;
                        }

                        if (getHeader(reader, endi, out recLength, out recType, out recSubType) <= 0)
                        {
                            break;
                        }

                        string recName = StdfSpec.lookupRecord(recType, recSubType, stdf_ver);
                        if (onHeaderProcessed != null)
                        {
                            onHeaderProcessed(recName, recType, recSubType, recLength);
                        }

                        //need to implement error message when recName == "" (unknown records)
                        if (!header_only && recName != "" && (recOfInterest == null || recOfInterest.Count == 0 || recOfInterest.Contains(recName)))
                        {
                            processRecord(reader, endi, recLength, recName, stdf_ver);
                        }
                        else
                        {
                            if (reader.BaseStream.CanSeek)
                            {
                                reader.BaseStream.Seek(recLength, SeekOrigin.Current);
                            }
                            else
                            {
                                reader.ReadBytes(recLength);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("unhandled exception: " + ex.Message);
                }

                reader.Close();
                reader.Dispose();
            }
        }