Exemplo n.º 1
0
        public void CheckElementsDefinitionTest()
        {
            CdrDecoder target = new CdrDecoder();
            target.ElementDefinitionProvider.CurrentSchema = "CS-50";
            Stream asnStream = new FileStream("KLG_02Dec2008_181815.cdr", FileMode.Open);
            TextWriter dumpWriter = new StreamWriter("CheckElementsDefinition.log");
            int expected = 2;
            int actual;
            actual = target.CheckElementsDefinition(asnStream, dumpWriter);
            Assert.AreEqual(expected, actual);

            asnStream.Close();
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemplo n.º 2
0
        public void CheckElementsDefinitionBatchTest()
        {
            CdrDecoder target = new CdrDecoder();
            target.ElementDefinitionProvider.CurrentSchema = "CS-50";
            String srcPath = @"C:\Projects\D900Cdr.Decoder\SampleCDRs\SR13";
            TextWriter dumpWriter = new StreamWriter("CheckElementsDefinition.log");
            int expected = 2;
            int actual;

            FileInfo[] cdrFiles;

            cdrFiles = new DirectoryInfo(srcPath).GetFiles("*.cdr", SearchOption.TopDirectoryOnly);
            FileStream cdr;

            foreach (FileInfo fi in cdrFiles)
            {
                cdr = new FileStream(fi.FullName, FileMode.Open);

                actual = target.CheckElementsDefinition(cdr, dumpWriter);
                Assert.AreEqual(expected, actual);

                cdr.Close();
            }
        }
Exemplo n.º 3
0
        private void DoJob(object sender, DoWorkEventArgs e)
        {
            _logger.WriteLogMessage("+++ Start new job:", LogLevel.Info);

            _status.ResultCode = JobResultCode.FatalError;

            CdrDecoder decoder = new CdrDecoder();

            decoder.ElementDefinitionProvider.CurrentSchema = _job.DefinitionSchemaName;
            D900CdrElement record;

            RecordFormatter formatter   = (_job.IsFormatterActive && (_job.FormatterSettings != null)) ? new RecordFormatter(_job.FormatterSettings) : null;
            Regex           filterRegex = (_job.IsFilterActive && !String.IsNullOrEmpty(_job.FilterText)) ? new Regex(_job.FilterText, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline) : null;

            StreamWriter dstFile = new StreamWriter(_job.DestinationPath);

            if ((formatter != null) && _job.FormatterSettings.PrintColumnsHeader)
            {
                dstFile.WriteLine(_job.FormatterSettings.ColumnsHeader);
            }

            FileInfo[] cdrFiles;

            cdrFiles = new DirectoryInfo(Path.GetDirectoryName(_job.SourcePath)).GetFiles(Path.GetFileName(_job.SourcePath), SearchOption.TopDirectoryOnly);
            FileStream cdr;
            long       cdrLength;
            long       rem;
            string     recText;

            _status.CdrFilesIn = cdrFiles.Length;
            _logger.WriteLogMessage(String.Format("Files to decode: {0}", _status.CdrFilesIn), LogLevel.Info, false);
            _logger.WriteLogMessage(String.Format("Schema: {0}", _job.DefinitionSchemaName), LogLevel.Info, false);
            _worker.ReportProgress(_status.Percent);
            foreach (FileInfo fi in cdrFiles)
            {
                cdr       = new FileStream(fi.FullName, FileMode.Open);
                cdrLength = cdr.Length;

                if (_job.StartOffset > 0)
                {
                    cdr.Seek(_job.StartOffset, SeekOrigin.Begin);
                }

                _status.RecordsOut     = 0;
                _status.CurrentCdrFile = fi.Name;
                rem = 0;

                _logger.WriteLogMessage(String.Format("{0} ... ", fi.Name), LogLevel.Info);
                _worker.ReportProgress(_status.Percent);
                for (; ;)
                {
                    if (_status.RecordsOut == 0)
                    {
                        record = decoder.DecodeRecord(cdr, false);
                    }
                    else
                    {
                        record = decoder.DecodeRecord(cdr, true);
                    }
                    if (record == null)
                    {
                        break;
                    }

                    _status.RecordsOut++;
                    _status.RecordsOutTotal++;
                    _status.Percent = (int)Math.Ceiling((double)cdr.Position / cdrLength * 100);

                    recText = (formatter == null) ? String.Format("{0,8} > {1} {2}", record.Offset, _status.RecordsOut, record.ToString()) : formatter.FormatRecord(record);

                    if ((filterRegex == null) || (filterRegex.Match(recText).Success))
                    {
                        dstFile.WriteLine(recText);
                    }

                    Math.DivRem(_status.RecordsOut, 1000, out rem);
                    if (rem == 0)
                    {
                        _worker.ReportProgress(_status.Percent);
                    }
                    if (_worker.CancellationPending)
                    {
                        break;
                    }
                }

                cdr.Close();

                _logger.AppendLogMessage(_status.RecordsOut.ToString());

                if (_worker.CancellationPending)
                {
                    break;
                }
                else
                {
                    _status.CdrFilesIn--;
                    _status.CdrFilesOut++;
                    _status.Percent = 100;
                    _worker.ReportProgress(_status.Percent);
                }
            }

            dstFile.Close();
            if (_worker.CancellationPending)
            {
                _status.ResultCode = JobResultCode.CanceledByUser;
                _logger.WriteLogMessage("+++ Process aborted by user.", LogLevel.Info);
            }
            else
            {
                _status.ResultCode = JobResultCode.AllOK;
                _logger.WriteLogMessage("+++ Decoding is successful done.", LogLevel.Info);
            }
        }
Exemplo n.º 4
0
        public void DumpAllTest()
        {
            CdrDecoder target = new CdrDecoder();
            target.ElementDefinitionProvider.CurrentSchema = "CS-50";
            Stream asnStream = new FileStream(@"mcrsm_6504_089521.mcr", FileMode.Open);
            byte maxLevel = byte.MaxValue;
            int expected = 2;
            int actual;

            TextWriter dumpWriter1 = new StreamWriter("Dump_ELEMENT_TXT.log");
            actual = target.Dump(asnStream, dumpWriter1, DumpType.ELEMENT_TXT, maxLevel);
            Assert.AreEqual(expected, actual);

            asnStream.Seek(0, SeekOrigin.Begin);
            TextWriter dumpWriter2 = new StreamWriter("Dump_ELEMENT_XML.log");
            actual = target.Dump(asnStream, dumpWriter2, DumpType.ELEMENT_XML, maxLevel);
            Assert.AreEqual(expected, actual);

            asnStream.Seek(0, SeekOrigin.Begin);
            TextWriter dumpWriter3 = new StreamWriter("Dump_TLV_TXT.log");
            actual = target.Dump(asnStream, dumpWriter3, DumpType.TLV_TXT, maxLevel);
            Assert.AreEqual(expected, actual);

            asnStream.Seek(0, SeekOrigin.Begin);
            TextWriter dumpWriter4 = new StreamWriter("Dump_TLV_XML.log");
            actual = target.Dump(asnStream, dumpWriter4, DumpType.TLV_XML, maxLevel);
            Assert.AreEqual(expected, actual);

            asnStream.Close();
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemplo n.º 5
0
        private void DoJob(object sender, DoWorkEventArgs e)
        {
            _logger.WriteLogMessage("+++ Start new job:", LogLevel.Info);

            _status.ResultCode = JobResultCode.FatalError;

            CdrDecoder decoder = new CdrDecoder();
            decoder.ElementDefinitionProvider.CurrentSchema = _job.DefinitionSchemaName;
            D900CdrElement record;

            RecordFormatter formatter = (_job.IsFormatterActive && (_job.FormatterSettings != null)) ? new RecordFormatter(_job.FormatterSettings) : null;
            Regex filterRegex = (_job.IsFilterActive && !String.IsNullOrEmpty(_job.FilterText)) ? new Regex(_job.FilterText, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline) : null;

            StreamWriter dstFile = new StreamWriter(_job.DestinationPath);
            if ((formatter != null) && _job.FormatterSettings.PrintColumnsHeader)
            {
                dstFile.WriteLine(_job.FormatterSettings.ColumnsHeader);
            }

            FileInfo[] cdrFiles;

            cdrFiles = new DirectoryInfo(Path.GetDirectoryName(_job.SourcePath)).GetFiles(Path.GetFileName(_job.SourcePath), SearchOption.TopDirectoryOnly);
            FileStream cdr;
            long cdrLength;
            long rem;
            string recText;

            _status.CdrFilesIn = cdrFiles.Length;
            _logger.WriteLogMessage(String.Format("Files to decode: {0}", _status.CdrFilesIn), LogLevel.Info, false);
            _logger.WriteLogMessage(String.Format("Schema: {0}", _job.DefinitionSchemaName), LogLevel.Info, false);
            _worker.ReportProgress(_status.Percent);
            foreach (FileInfo fi in cdrFiles)
            {
                cdr = new FileStream(fi.FullName, FileMode.Open);
                cdrLength = cdr.Length;

                if (_job.StartOffset > 0) cdr.Seek(_job.StartOffset, SeekOrigin.Begin);

                _status.RecordsOut = 0;
                _status.CurrentCdrFile = fi.Name;
                rem = 0;

                _logger.WriteLogMessage(String.Format("{0} ... ", fi.Name), LogLevel.Info);
                _worker.ReportProgress(_status.Percent);
                for (; ; )
                {
                    if (_status.RecordsOut == 0)
                    {
                        record = decoder.DecodeRecord(cdr, false);
                    }
                    else
                    {
                        record = decoder.DecodeRecord(cdr, true);
                    }
                    if (record == null)
                        break;

                    _status.RecordsOut++;
                    _status.RecordsOutTotal++;
                    _status.Percent = (int)Math.Ceiling((double)cdr.Position / cdrLength * 100);

                    recText = (formatter == null) ? String.Format("{0,8} > {1} {2}", record.Offset, _status.RecordsOut, record.ToString()) : formatter.FormatRecord(record);

                    if ((filterRegex == null) || (filterRegex.Match(recText).Success))
                        dstFile.WriteLine(recText);

                    Math.DivRem(_status.RecordsOut, 1000, out rem);
                    if (rem == 0) _worker.ReportProgress(_status.Percent);
                    if (_worker.CancellationPending)
                    {
                        break;
                    }
                }

                cdr.Close();

                _logger.AppendLogMessage(_status.RecordsOut.ToString());

                if (_worker.CancellationPending)
                {
                    break;
                }
                else
                {
                    _status.CdrFilesIn--;
                    _status.CdrFilesOut++;
                    _status.Percent = 100;
                    _worker.ReportProgress(_status.Percent);
                }
            }

            dstFile.Close();
            if (_worker.CancellationPending)
            {
                _status.ResultCode = JobResultCode.CanceledByUser;
                _logger.WriteLogMessage("+++ Process aborted by user.", LogLevel.Info);
            }
            else
            {
                _status.ResultCode = JobResultCode.AllOK;
                _logger.WriteLogMessage("+++ Decoding is successful done.", LogLevel.Info);
            }
        }