Esempio n. 1
0
        public IEnumerable <ISTDFRecord> ReadFile(string path)
        {
            DateTime start = DateTime.Now;

            List <ISTDFRecord> Records = new List <ISTDFRecord>();
            ISTDFRecord        record;

            using Stream stream = File.OpenRead(path);

            using STDFRecordFormatter recordFormatter = new STDFRecordFormatter();

            recordFormatter.Converter.SwapBytes = true;

            do
            {
                record = (ISTDFRecord)recordFormatter.Deserialize(stream);
                if (record != null)
                {
                    //Console.WriteLine(record.ToString());
                    Records.Add(record);
                }
            } while (!recordFormatter.EndOfStream);

            DateTime end = DateTime.Now;

            double execTime = (end - start).TotalMilliseconds;

            Console.WriteLine(string.Format("{0} records read from file in {1} milliseconds.", Records.Count, execTime));

            stream.Close();

            return(Records);
        }
Esempio n. 2
0
        public int WriteFile(string path, IEnumerable <ISTDFRecord> records)
        {
            DateTime start = DateTime.Now;

            using Stream stream = File.Open(path, FileMode.Create, FileAccess.Write);

            using STDFRecordFormatter recordFormatter = new STDFRecordFormatter();

            int count = 0;

            foreach (var record in records)
            {
                recordFormatter.Serialize(stream, record);
                count++;
            }

            DateTime end = DateTime.Now;

            double execTime = (end - start).TotalMilliseconds;

            Console.WriteLine(string.Format("{0} records written to file in {1} milliseconds.", count, execTime));

            stream.Close();

            return(count);
        }
Esempio n. 3
0
        public int CompareRecords(string path, IEnumerable <ISTDFRecord> records)
        {
            DateTime start = DateTime.Now;

            ISTDFRecord record;

            using Stream stream = File.OpenRead(path);

            using STDFRecordFormatter recordFormatter = new STDFRecordFormatter();

            int index    = 0;
            int mismatch = 0;

            do
            {
                if (index == 40650)
                {
                    ;
                }
                record = (ISTDFRecord)recordFormatter.Deserialize(stream);
                if (record != null)
                {
                    if (record.RecordType == records.ElementAt(index).RecordType&&
                        record.RecordLength != records.ElementAt(index).RecordLength)
                    {
                        mismatch++;
                        Console.WriteLine(string.Format("Record length mismatch.  Record # {0}, Type {1}, original length = {2}, new length = {3}",
                                                        index, record.GetType().Name, records.ElementAt(index).RecordLength, record.RecordLength));
                    }
                    index++;
                }
            } while (!recordFormatter.EndOfStream);

            DateTime end = DateTime.Now;

            double execTime = (end - start).TotalMilliseconds;

            Console.WriteLine(string.Format("{0} records read from file in {1} milliseconds.  {2,3:P0} of records passed length comparison.", records.Count(), execTime, (double)(1 - mismatch / index)));
            stream.Close();

            return(mismatch);
        }