Utility class used to auto detect the record format, the number of fields, the type, etc.
        public void OneColumnFixed()
        {
            var detector = new SmartFormatDetector();
            var formats = detector.DetectFileFormat(FileTest.Detection.OnColumnFixed.Path);

            Assert.AreEqual(1, formats.Length);
            Assert.IsTrue(formats[0].ClassBuilder is FixedLengthClassBuilder);
            Assert.AreEqual(100, formats[0].Confidence);
            Assert.AreEqual(1, formats[0].ClassBuilder.FieldCount);

            var builder = (FixedLengthClassBuilder) formats[0].ClassBuilder;
            Assert.AreEqual(10, builder.Fields[0].FieldLength);
        }
示例#2
0
        public void FixedLength()
        {
            SmartFormatDetector detector = new SmartFormatDetector();
            RecordFormatInfo[] formats = detector.DetectFileFormat(FileTest.Detection.CustomersFixed.Path);

            Assert.AreEqual(1, formats.Length);
            Assert.IsTrue(formats[0].ClassBuilder is FixedLengthClassBuilder);
            Assert.AreEqual(100, formats[0].Confidence);
            Assert.AreEqual(7, formats[0].ClassBuilder.FieldCount);

            FixedLengthClassBuilder builder = formats[0].ClassBuilder as FixedLengthClassBuilder;
            Assert.AreEqual(11, builder.Fields[0].FieldLength);
            Assert.AreEqual(38, builder.Fields[1].FieldLength);
            Assert.AreEqual(22, builder.Fields[2].FieldLength);
            Assert.AreEqual(38, builder.Fields[3].FieldLength);
            Assert.AreEqual(41, builder.Fields[4].FieldLength);
            Assert.AreEqual(18, builder.Fields[5].FieldLength);
            Assert.AreEqual(15, builder.Fields[6].FieldLength);
        }
示例#3
0
        private void AssertDelimitedFormat(string file, string delimiter, int fields, int confidence, int numFormats)
        {
            SmartFormatDetector detector = new SmartFormatDetector();
            RecordFormatInfo[] formats;

            detector.MaxSampleLines = 10;
            formats = detector.DetectFileFormat(file);
            AssertFormat(formats, delimiter, fields, confidence, numFormats);

            detector.MaxSampleLines = 20;
            formats = detector.DetectFileFormat(file);
            AssertFormat(formats, delimiter, fields, confidence, numFormats);

            detector.MaxSampleLines = 50;
            formats = detector.DetectFileFormat(file);
            AssertFormat(formats, delimiter, fields, confidence, numFormats);

            detector.MaxSampleLines = 100;
            formats = detector.DetectFileFormat(file);
            AssertFormat(formats, delimiter, fields, confidence, numFormats);
        }
示例#4
0
        private void AutoDetectFormat(bool hasHeaders)
        {
            var dialog = new OpenFileDialog();
            dialog.Multiselect = false;
            dialog.Title = "Select a Sample File";
            if (dialog.ShowDialog() == DialogResult.Cancel)
                return;

            var detector = new SmartFormatDetector();
            detector.FileHasHeaders = hasHeaders;
            detector.MaxSampleLines = 100;
            var formats = detector.DetectFileFormat(dialog.FileName);

            if (formats.Length == 0)
                return;

            ClassBuilderToWizard(formats[0].ClassBuilder);

            var frm = new frmDataPreview(mLastCode, mWizardInfo.Language);
            frm.HasHeaders = hasHeaders;
            frm.txtInput.Text = File.ReadAllText(dialog.FileName);
            frm.AutoRunTest = true;
            frm.ShowDialog();
            frm.Dispose();
        }
        public void OneColumnNonFixed()
        {
            var detector = new SmartFormatDetector();
            RecordFormatInfo[] formats = detector.DetectFileFormat(FileTest.Detection.OnColumnNonFixed.Path);

            Assert.AreEqual(0, formats.Length);
        }