Ejemplo n.º 1
0
        public void ReadStreamWithDifferentColumnOrder()
        {
            // arrange
            string data = "Field3,Field4,Field5,Field1,Field2" + Environment.NewLine +
                          "3,4,5,1,2" + Environment.NewLine +
                          "33,44,55,11,22" + Environment.NewLine;
            var engine = new DelimitedFileEngine <SampleType5Fields>();

            // act
            engine.SetFieldOrder(new string[] { "Field3", "Field4", "Field5", "Field1", "Field2" });
            TextReader textReader = new StringReader(data);

            SampleType5Fields[] res;
            res = engine.ReadStream(textReader, int.MaxValue);

            // assert
            Assert.AreEqual(2, res.Length);
            Assert.AreEqual(2, engine.TotalRecords);
            Assert.AreEqual(0, engine.ErrorManager.ErrorCount);

            Assert.AreEqual("1", res[0].Field1);
            Assert.AreEqual("2", res[0].Field2);
            Assert.AreEqual("3", res[0].Field3);
            Assert.AreEqual("4", res[0].Field4);
            Assert.AreEqual("5", res[0].Field5);

            Assert.AreEqual("11", res[1].Field1);
            Assert.AreEqual("22", res[1].Field2);
            Assert.AreEqual("33", res[1].Field3);
            Assert.AreEqual("44", res[1].Field4);
            Assert.AreEqual("55", res[1].Field5);
        }
Ejemplo n.º 2
0
        public static void ImportInContractBSR(TrwBudgetPeriod period, IObjectSpace os, TextReader reader)
        {
            DelimitedFileEngine engine = new DelimitedFileEngine(typeof(InContractBsrRecord));

            engine.Options.IgnoreFirstLines = 1;
            InContractBsrRecord[] records = (InContractBsrRecord[])engine.ReadStream(reader);
            os.Delete(period.InContractBSR);
            foreach (InContractBsrRecord rec in records)
            {
                if (!String.IsNullOrEmpty(rec.TrwSaleNomCode))
                {
                    TrwBudgetPeriodInContractBSR in_bsr = os.CreateObject <TrwBudgetPeriodInContractBSR>();
                    period.InContractBSR.Add(in_bsr);
                    in_bsr.SaleNomCode      = rec.TrwSaleNomCode.Trim();
                    in_bsr.SaleNomenclature = os.FindObject <TrwSaleNomenclature>(new BinaryOperator("TrwCode", rec.TrwSaleNomCode.Trim()));
//                    if (in_bsr.SaleNomenclature == null)
//                        throw new InvalidDataException("Unknow nomencalture: " + rec.TrwSaleNomCode);
                    in_bsr.Period00 = rec.Period00 != null ? (Decimal)rec.Period00 : 0;
                    in_bsr.Period01 = rec.Period01 != null ? (Decimal)rec.Period01 : 0;
                    in_bsr.Period02 = rec.Period02 != null ? (Decimal)rec.Period02 : 0;
                    in_bsr.Period03 = rec.Period03 != null ? (Decimal)rec.Period03 : 0;
                    in_bsr.Period04 = rec.Period04 != null ? (Decimal)rec.Period04 : 0;
                    in_bsr.Period05 = rec.Period05 != null ? (Decimal)rec.Period05 : 0;
                    in_bsr.Period06 = rec.Period06 != null ? (Decimal)rec.Period06 : 0;
                    in_bsr.Period07 = rec.Period07 != null ? (Decimal)rec.Period07 : 0;
                    in_bsr.Period08 = rec.Period08 != null ? (Decimal)rec.Period08 : 0;
                    in_bsr.Period09 = rec.Period09 != null ? (Decimal)rec.Period09 : 0;
                    in_bsr.Period10 = rec.Period10 != null ? (Decimal)rec.Period10 : 0;
                    in_bsr.Period11 = rec.Period11 != null ? (Decimal)rec.Period11 : 0;
                    in_bsr.Period12 = rec.Period12 != null ? (Decimal)rec.Period12 : 0;
                }
            }
        }
        //-> {Example.Name:Ignore Mode Error handling}
        //-> {Example.Description:Read the file dropping bad records}

        //-> {Example.File:RunEngine.cs}
        /// <summary>
        /// Run an example of running a file with an error using the
        /// IgnoreMode option to silently drop bad records
        /// </summary>
        public override void Run()
        {
            var engine = new DelimitedFileEngine <Customer>();

            // Switch error mode on
            engine.ErrorManager.ErrorMode = ErrorMode.IgnoreAndContinue;

            //  This fails with not in enumeration error
            Customer[] customers = engine.ReadFile("Input.txt");

            // This wont display anything, we have dropped it
            foreach (ErrorInfo err in engine.ErrorManager.Errors)
            {
                Console.WriteLine();
                Console.WriteLine("Error on Line number: {0}", err.LineNumber);
                Console.WriteLine("Record causing the problem: {0}", err.RecordString);
                Console.WriteLine("Complete exception information: {0}", err.ExceptionInfo.ToString());
            }

            // This will display only 3 of the four records
            foreach (var cust in customers)
            {
                Console.WriteLine("Customer name {0} is a {1}", cust.ContactName, cust.ContactTitle);
            }
        }
Ejemplo n.º 4
0
        private void btnCargarFactBruta_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog()
            {
                Filter           = "CSV files (*.csv)|*.csv",
                InitialDirectory = inDir,
                Title            = "INNCODE || ---> SELECCIONE EL ARCHIVO"
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                LimpiarValidacionDeCampos();
                txtRutaFactBruta.Text = openFileDialog.FileName;
                string fullPath = openFileDialog.FileName;
                inDir = @fullPath.Substring(0, fullPath.LastIndexOf('\\'));
                txtRutaExport.Text = inDir;

                try {
                    var engine = new DelimitedFileEngine <BaseCSV>();
                    engine.Encoding = Encoding.UTF8;
                    var result = engine.ReadFile(txtRutaFactBruta.Text);
                }catch (ConvertException ex) {
                    txtRutaFactBruta.Text = "";
                    MessageBoxEx.Show(this, "ERROR AL PROCESAR ARCHIVO. PUEDE QUE SE DEBA A QUE ALGUNA DE LA COLUMNAS TENGAN UN CARACTER '|' DE MAS.\nPOR FAVOR PONGASE EN CONTACTO CON OFIN.\n" + ex.Message + "\nNUMERO REGISTRO ERROR: " + ex.LineNumber,
                                      "ERROR DEL SISTEMA", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }catch (IOException ex)
                {
                    txtRutaFactBruta.Text = "";
                    MessageBoxEx.Show(this, "NO SE PUEDE TENER ACCESO AL ARCHIVO PORQUE ESTÁ SIENDO UTILIZADO POR OTRO POGRAMA.\n" + ex.Message,
                                      "ERROR DEL SISTEMA", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 5
0
        public ContributionFile Read(TextReader stream)
        {
            var engine = new DelimitedFileEngine <ContributionRecord>();

            engine.ErrorMode = ErrorMode.ThrowException;
            return(new ContributionFile(engine.ReadStream(stream)));
        }
Ejemplo n.º 6
0
        public School[] Read(string fileName)
        {
            var engine = new DelimitedFileEngine <School>();
            var list   = engine.ReadFile(fileName);

            return(list);
        }
Ejemplo n.º 7
0
        public void ReadStreamWithExtraColumnsInBetween()
        {
            // arrange
            string data = "Field3,Field4,Field5,Inbetween1,Field1,Field2,More1,More2" + Environment.NewLine +
                          "3,4,5,i,1,2,a,b" + Environment.NewLine;
            var engine = new DelimitedFileEngine <SampleType5Fields>();

            // act
            engine.SetFieldOrder(new string[] { "Field3", "Field4", "Field5", "Inbetween1", "Field1", "Field2" });
            TextReader textReader = new StringReader(data);

            SampleType5Fields[] res;
            res = engine.ReadStream(textReader, int.MaxValue);

            // assert
            Assert.AreEqual(1, res.Length);
            Assert.AreEqual(1, engine.TotalRecords);
            Assert.AreEqual(0, engine.ErrorManager.ErrorCount);

            Assert.AreEqual("1", res[0].Field1);
            Assert.AreEqual("2", res[0].Field2);
            Assert.AreEqual("3", res[0].Field3);
            Assert.AreEqual("4", res[0].Field4);
            Assert.AreEqual("5", res[0].Field5);
        }
Ejemplo n.º 8
0
        public void Write(TextWriter stream, ContributionFile file)
        {
            var engine = new DelimitedFileEngine <ContributionRecord>();

            engine.HeaderText = HEADER; // Contribution file must have header row
            engine.ErrorMode  = ErrorMode.ThrowException;
            engine.WriteStream(stream, file.Records);
        }
Ejemplo n.º 9
0
        private void ReadCSVFile(string fullName)
        {
            try
            {
                var engine = new DelimitedFileEngine <ImportCLassModel>(Encoding.UTF8);
                engine.AfterReadRecord  += AfterReadCSVEvent;
                engine.Options.Delimiter = ";";

                var records = engine.ReadFile(fullName);
                foreach (ImportCLassModel rec in records)
                {
                    if (string.IsNullOrEmpty(rec.PurchaseOrder))
                    {
                        throw new Exception("Some of Purchase Order is null/empty.");
                    }
                    if (string.IsNullOrEmpty(rec.Material))
                    {
                        throw new Exception("Some of  Material is null/empty.");
                    }
                    if (string.IsNullOrEmpty(rec.MaterialShortText))
                    {
                        throw new Exception("Some of Material Short Text is null/empty.");
                    }
                    if (string.IsNullOrEmpty(rec.Eun))
                    {
                        throw new Exception("Some of Eun Order is null/empty.");
                    }
                    if (string.IsNullOrEmpty(rec.StorageLoc))
                    {
                        throw new Exception("Some of Storage Loc is null/empty.");
                    }
                    if (string.IsNullOrEmpty(rec.StorageBin))
                    {
                        throw new Exception("Some of Storage Bin is null/empty.");
                    }

                    PopulateRecords(rec, tempCollection);
                }

                if (tempCollection.Count() > 0)
                {
                    ImportBtn           = true;
                    IsEnableAutoRefresh = false;

                    _ImportGRCommand.RaiseCanExecuteChanged();
                    _ExportGRCommand.RaiseCanExecuteChanged();

                    GoodReceives = new ListCollectionView(tempCollection);
                    GoodReceives.SortDescriptions.Add(new SortDescription("PurchaseOrder", ListSortDirection.Ascending));

                    CollectionViewSource.GetDefaultView(GoodReceives).Filter = Filter;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to read contents:\n\n" + ex.Message, "Error");
            }
        }
Ejemplo n.º 10
0
        public void ArrayReadFieldsNull()
        {
            var info   = "1,name1,10.2,,30.5";
            var engine = new DelimitedFileEngine <ArrayModel1>();
            var res    = engine.ReadString(info);

            res.Length.AssertEqualTo(1);
            res[0].Weighting.Length.AssertEqualTo(3);
            res[0].Weighting[1].AssertEqualTo(-5f);
        }
Ejemplo n.º 11
0
        public void CheckSeparator()
        {
            var engSemiColon = new DelimitedFileEngine <CustomersSemiColon>();

            engSemiColon.Options.Delimiter.AssertEqualTo(";");

            var engTab = new DelimitedFileEngine <CustomersTab>();

            engTab.Options.Delimiter.AssertEqualTo("\t");
        }
Ejemplo n.º 12
0
        private DelimitedFileEngine <T> CreateParserEngine()
        {
            var parseEngine = new DelimitedFileEngine <T> {
                ErrorMode = ErrorMode.SaveAndContinue
            };

            parseEngine.BeforeReadRecord += BeforeReadRecord;
            parseEngine.AfterReadRecord  += AfterReadRecord;
            return(parseEngine);
        }
Ejemplo n.º 13
0
        private DelimitedFileEngine <TCrossSectionPoint> CreateCsvParser <TCrossSectionPoint>(StreamReader reader)
            where TCrossSectionPoint : class, ICrossSectionPoint
        {
            var engine = new DelimitedFileEngine <TCrossSectionPoint>(reader.CurrentEncoding);

            engine.Options.IgnoreEmptyLines = true;
            engine.BeforeReadRecord        += OnBeforeReadRecord;

            return(engine);
        }
Ejemplo n.º 14
0
        public void ArrayReadFieldsNullAndNullable()
        {
            var info   = "1,name1,10.2,,30.5";
            var engine = new DelimitedFileEngine <ArrayModelNullable>();
            var res    = engine.ReadString(info);

            Check.That(res.Length).IsEqualTo(1);
            Check.That(res[0].Weighting.Length).IsEqualTo(3);
            Check.That(res[0].Weighting[1]).IsEqualTo(null);
        }
        public void LoadTargetsFromFile(string filename)
        {
            var fileHelpers    = new DelimitedFileEngine <DwellableFileEntry>();
            var fileCollection = fileHelpers.ReadFile(filename);

            foreach (var entry in fileCollection)
            {
                var target = new DwellableTarget(new Point(entry.x, entry.y), entry.label, entry.type, entry.page);
                AddTarget(target);
            }
        }
Ejemplo n.º 16
0
        private void RunTests(string fileName, Type type, string delimiter)
        {
            DelimitedFileEngine engine = new DelimitedFileEngine(type);

            engine.Options.Delimiter = delimiter;

            object[] res = Common.ReadTest(engine, fileName);


            Assert.AreEqual(ExpectedRecords, res.Length);
        }
Ejemplo n.º 17
0
        private void RunTests <type>(string delimiter, params string[] pathElements) where type : class
        {
            var engine = new DelimitedFileEngine <type>();

            engine.Options.Delimiter = delimiter;

            var res = TestCommon.ReadTest <type>(engine, pathElements);


            Assert.AreEqual(ExpectedRecords, res.Length);
        }
Ejemplo n.º 18
0
        public override void Run()
        {
            var customers = CreateCustomers();

            var engine = new DelimitedFileEngine <CustomersVerticalBar>();

            engine.Options.Fields[2].TrimMode = TrimMode.Both;
            engine.Options.RemoveField("DummyField");
            //engine.Options.Fields[3].IsOptional

            //engine.ReadString(customers)
        }
Ejemplo n.º 19
0
        //-> /File

        //-> File:RunEngine.cs
        public override void Run()
        {
            var engine = new DelimitedFileEngine <Customer>();

            //  Read input records, enumeration automatically converted
            Customer[] customers = engine.ReadFile("Input.txt");

            foreach (var cust in customers)
            {
                Console.WriteLine("Customer name {0} is a {1}", cust.ContactName, cust.ContactTitle);
            }
        }
Ejemplo n.º 20
0
        public void ArrayWriteFloatFields3()
        {
            var dataToExport = new List <ArrayModel1>();

            dataToExport.Add(new ArrayModel1()
            {
                Id = 1, Name = "name1", Weighting = new float[] { 10.2f, 30.5f, 11f }
            });

            var engine = new DelimitedFileEngine <ArrayModel1>();
            var res    = engine.WriteString(dataToExport);

            Assert.AreEqual("1,name1,10.2,30.5,11" + Environment.NewLine, res);
        }
Ejemplo n.º 21
0
            public void Import(IObjectSpace os, String acc_sys_code, String file_name)
            {
                DelimitedFileEngine engine = new DelimitedFileEngine(typeof(FAAccountImport));

                FAAccountImport[]  records = (FAAccountImport[])engine.ReadFile(file_name);
                fmCFAAccountSystem acc_sys = os.GetObjects <fmCFAAccountSystem>(new BinaryOperator("Code", acc_sys_code), true).FirstOrDefault();

                if (acc_sys == null)
                {
                    acc_sys      = os.CreateObject <fmCFAAccountSystem>();
                    acc_sys.Code = "1000";
                    acc_sys.Name = "Áóõãàëòåðèÿ";
                }
                foreach (FAAccountImport rec in records)
                {
                    fmCFAAccount bs_acc = acc_sys.Accounts.Where(x => x.Code == rec.BsCode).FirstOrDefault();
                    if (bs_acc == null)
                    {
                        bs_acc      = os.CreateObject <fmCFAAccount>();
                        bs_acc.Code = rec.BsCode;
                        acc_sys.Accounts.Add(bs_acc);
                    }
                    if (rec.SsCode == "0000")
                    {
                        bs_acc.Name     = rec.NameShort;
                        bs_acc.NameFull = rec.NameFull;
                    }
                    else
                    {
                        fmCFAAccount ss_acc = acc_sys.Accounts.Where(x => x.Code == rec.SsCode).FirstOrDefault();
                        if (ss_acc == null)
                        {
                            ss_acc      = os.CreateObject <fmCFAAccount>();
                            ss_acc.Code = rec.SsCode;
                            bs_acc.SubAccounts.Add(ss_acc);
                        }
                        ss_acc.BuhCode = rec.BuhCode;
                        if (rec.NameShort.Length > 60)
                        {
                            ss_acc.Name = rec.NameShort.Substring(0, 60);
                        }
                        else
                        {
                            ss_acc.Name = rec.NameShort;
                        }
                        ss_acc.NameFull      = rec.NameFull;
                        ss_acc.IsSelectabled = true;
                    }
                }
            }
        public DelimitedFileEngineWriteTests()
        {
            A.CallTo(() => _lineBuilder.BuildLine(A <TestRecord> .Ignored))
            .ReturnsLazily((TestRecord r) => r.ToString());

            _lineBuilderFactory = A.Fake <IDelimitedLineBuilderFactory>();
            A.CallTo(() => _lineBuilderFactory.GetBuilder(A <IDelimitedLayoutDescriptor> .Ignored))
            .Returns(_lineBuilder);

            _fileEngine = new DelimitedFileEngine(
                A.Fake <IDelimitedLayoutDescriptor>(),
                _lineBuilderFactory,
                new DelimitedLineParserFactory());
        }
Ejemplo n.º 23
0
        // Declaration of Variables

        /// <summary>
        /// used to load and save the data from csv to database
        /// </summary>
        /// <param name="FilePath"></param>
        public SaveToDatabase(string FilePath)
        {
            var engine   = new DelimitedFileEngine <CsvStructure>();
            var rows     = engine.ReadFile(FilePath);
            var fileName = Path.GetFileNameWithoutExtension(FilePath);
            var result   = CheckIfExisted(fileName, rows);

            if (result)
            {
                foreach (var row in rows)
                {
                    using (var database = _Database.Database.BeginTransaction())
                    {
                        try
                        {
                            Barcode barcode = new Barcode();
                            barcode.Matched         = row.Barcoded;
                            barcode.BarcodeItem     = row.BarItem;
                            barcode.Barcodes        = row.Barcode;
                            barcode.CardNumber      = MaskedNumber(row.CardNumber);
                            barcode.Filename        = row.FileName;
                            barcode.Finalized       = row.Finalized;
                            barcode.LeanBarcode     = row.LeanBarcode;
                            barcode.LeanBarcodeItem = row.LeanBarItem;
                            barcode.Batch           = row.Batch;
                            barcode.SequenceNumber  = row.SequenceNumber;
                            barcode.DateTime        = DateTime.Now;
                            barcode.User            = Environment.UserName;

                            _Database.Barcodes.Add(barcode);
                            _Database.SaveChanges();

                            database.Commit();
                            _Logs.CreateLogs(">>>>>> Sequence Number: " + row.SequenceNumber + " successfully save into the database");
                        }
                        catch (DbEntityValidationException e)
                        {
                            database.Rollback();
                            _Logs.CreateLogs(">>>>>> Database Error: " + e);
                            MessageBox.Show("There's an error loading the file. \nPlease check the logs for more information about the error.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                MessageBox.Show("CSV successfully saved and loaded!", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                _Logs.CreateLogs(">>>>>> ERROR: File Existed");
            }
        }
Ejemplo n.º 24
0
        private void cmdRun_Click(object sender, EventArgs e)
        {
            CustomersVerticalBar[] customers = (CustomersVerticalBar[])grid1.SelectedObject;
            //
            DelimitedFileEngine engine = new DelimitedFileEngine(typeof(CustomersVerticalBar));

            txtOut1.Text = engine.WriteString(customers);

            engine.Options.Delimiter = ";";
            txtOut2.Text             = engine.WriteString(customers);

            engine.Options.Delimiter = "\t";
            txtOut3.Text             = engine.WriteString(customers);
        }
Ejemplo n.º 25
0
 public void ArrayWriteMinError1()
 {
     Assert.Throws <InvalidOperationException>(
         () => {
         var engine = new DelimitedFileEngine <ArrayModel2To4>();
         engine.WriteString(new[] {
             new ArrayModel2To4()
             {
                 Id        = 1,
                 Name      = "name1",
                 Weighting = new float[] { 10.2f }
             }
         });
     });
 }
        //-> /File

        public override void Run()
        {
            //-> File:Example.cs
            try
            {
                var engine = new DelimitedFileEngine <Customer>();

                //  This fails with not in enumeration error
                var customers = engine.ReadFile("Input.txt");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString()); // with stack trace
            }
            //-> /File
        }
Ejemplo n.º 27
0
            public void Import(IObjectSpace os, String file_name)
            {
                DelimitedFileEngine engine = new DelimitedFileEngine(typeof(SimpleAnalyticImport));

                SimpleAnalyticImport[] records = (SimpleAnalyticImport[])engine.ReadFile(file_name);
                foreach (SimpleAnalyticImport rec in records)
                {
                    T obj = os.GetObjects <T>(new BinaryOperator("Code", rec.Code)).FirstOrDefault();
                    if (obj == default(T))
                    {
                        obj = os.CreateObject <T>();
                    }
                    obj.Code = rec.Code;
                    obj.Name = rec.Name;
                }
            }
Ejemplo n.º 28
0
        public void StandardImport()
        {
            // arrange
            var engine = new DelimitedFileEngine <FieldOrderType>();

            engine.Options.IgnoreEmptyLines = true;
            engine.ErrorMode = ErrorMode.SaveAndContinue;

            // act
            var res = engine.ReadStream(new StringReader(data_standard), Int32.MaxValue).ToList();

            // assert
            Assert.IsFalse(engine.ErrorManager.HasErrors);
            Assert.IsTrue(res.Count == 2);
            Validate_Data_Standard(res);
        }
Ejemplo n.º 29
0
        //-> /File

        protected override void Run()
        {
            //-> File:Example.txt

            var engine = new DelimitedFileEngine <CustomersVerticalBar>();

            engine.Options.Fields[2].TrimMode = TrimMode.Both;
            engine.Options.RemoveField("DummyField");

            // City is optional
            engine.Options.Fields[engine.Options.Fields.Count - 1].IsOptional = true;

            engine.ReadFile("Input.txt");

            //-> /File
        }
Ejemplo n.º 30
0
        //-> {Example.Name:ErrorMode saving Errors}
        //-> {Example.Description:Read the file saving bad records}

        //-> {Example.File:RunEngine.cs}
        /// <summary>
        /// Run an example of running a file with an error using the
        /// ErrorMode option to capture bad records and then saving them
        /// </summary>
        public override void Run()
        {
            var engine = new DelimitedFileEngine <Customer>();

            // Switch error mode on
            engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;

            //  This fails with not in enumeration error
            Customer[] customers = engine.ReadFile("Input.txt");

            if (engine.ErrorManager.HasErrors)
            {
                engine.ErrorManager.SaveErrors("errors.out");
            }
            LoadErrors();
        }
Ejemplo n.º 31
0
        public void TestDosFile()
        {
            var testdata = new SimpleData() {
                Record = "one record only"
            };

            var engine = new DelimitedFileEngine<SimpleData>();
            using (var filename = new TempFileFactory()) {
                String twoRecords = testdata.Record + StringHelper.NewLine + testdata.Record + StringHelper.NewLine;

                ProcessAppend(testdata, engine, filename, twoRecords, "\r\n\r\n", "Dos");
                ProcessAppend(testdata, engine, filename, twoRecords, "\n\n\n", "Unix");
                ProcessAppend(testdata, engine, filename, twoRecords, "\r\r\r", "Macintosh");

                GC.Collect(); //  Clean up the loose file stream from the testing
            }
        }
Ejemplo n.º 32
0
        private static void ProcessAppend(SimpleData testdata, DelimitedFileEngine<SimpleData> engine, String filename, String twoRecords,
            string LineEnds, string testname)
        {
            using (var fs = new StreamWriter(filename))
                {
                    fs.Write(testdata.Record);
                    fs.Write(LineEnds);  // lots of blanks lines to trim
                    fs.Close();
                }

                engine.AppendToFile(filename, testdata);

                using (var input = new StreamReader(filename))
                {
                    String result = input.ReadToEnd();
                    result.AssertEqualTo<String>(twoRecords, testname + ": Expected two records only on output");
                    input.Close();
                }
        }
Ejemplo n.º 33
0
        private static void ProcessAppend(SimpleData testdata,
            DelimitedFileEngine<SimpleData> engine,
            String filename,
            String twoRecords,
            string LineEnds,
            string testname)
        {
            using (var fs = new StreamWriter(filename)) {
                fs.Write(testdata.Record);
                fs.Write(LineEnds); // lots of blanks lines to trim
                fs.Close();
            }

            engine.AppendToFile(filename, testdata);

            using (var input = new StreamReader(filename)) {
                String result = input.ReadToEnd();
                Check.That(result).IsEqualTo(twoRecords);
                input.Close();
            }
        }
Ejemplo n.º 34
0
 public void ArrayWriteMinErrorNull()
 {
     Assert.Throws<InvalidOperationException>(
         () => {
             var engine = new DelimitedFileEngine<ArrayModel2To4>();
             var res =
                 engine.WriteString(new[] {
                     new ArrayModel2To4() {
                         Id = 1,
                         Name = "name1",
                         Weighting = null
                     }
                 });
         });
 }
Ejemplo n.º 35
0
 public void ArrayWriteMaxError5()
 {
     Assert.Throws<InvalidOperationException>(
         () => {
             var engine = new DelimitedFileEngine<ArrayModel2To4>();
             var res =
                 engine.WriteString(new[] {
                     new ArrayModel2To4() {
                         Id = 1,
                         Name = "name1",
                         Weighting = new float[] {10.2f, 1, 2, 3, 4}
                     }
                 });
         });
 }
Ejemplo n.º 36
0
        public void ArrayWriteFloatFieldsNullable()
        {
            var dataToExport = new List<ArrayModelNullable>();
            dataToExport.Add(new ArrayModelNullable() {
                Id = 1,
                Name = "name1",
                Weighting = new float?[] {}
            });

            var engine = new DelimitedFileEngine<ArrayModelNullable>();
            var res = engine.WriteString(dataToExport);

            Assert.AreEqual("1,name1," + Environment.NewLine, res);

            var vals = engine.ReadString(res);
            vals.Length.AssertEqualTo(1);
            vals[0].Weighting.Length.AssertEqualTo(0);
        }
Ejemplo n.º 37
0
        public void ArrayWriteFloatFields3()
        {
            var dataToExport = new List<ArrayModel1>();
            dataToExport.Add(new ArrayModel1() {
                Id = 1,
                Name = "name1",
                Weighting = new float[] {10.2f, 30.5f, 11f}
            });

            var engine = new DelimitedFileEngine<ArrayModel1>();
            var res = engine.WriteString(dataToExport);

            Assert.AreEqual("1,name1,10.2,30.5,11" + Environment.NewLine, res);
        }
Ejemplo n.º 38
0
        public void ArrayReadFieldsNullAndNullable()
        {
            var info = "1,name1,10.2,,30.5";
            var engine = new DelimitedFileEngine<ArrayModelNullable>();
            var res = engine.ReadString(info);

            res.Length.AssertEqualTo(1);
            res[0].Weighting.Length.AssertEqualTo(3);
            res[0].Weighting[1].AssertEqualTo(null);
        }
Ejemplo n.º 39
0
        public void ArrayReadFieldsNull()
        {
            var info = "1,name1,10.2,,30.5";
            var engine = new DelimitedFileEngine<ArrayModel1>();
            var res = engine.ReadString(info);

            Check.That(res.Length).IsEqualTo(1);
            Check.That(res[0].Weighting.Length).IsEqualTo(3);
            Check.That(res[0].Weighting[1]).IsEqualTo(-5f);
        }