public void Main() { // Name of file containing Meta const string MetaFileName = "ExampleSequenceMeta.ftm"; // Name of file to be written const string CsvFileName = "ExampleSequence.csv"; // Create Meta from file FtMeta meta = FtMetaSerializer.Deserialize(MetaFileName); finished = false; // Create Writer using (FtWriter writer = new FtWriter(meta, CsvFileName)) { writer.FieldValueWriteReady += HandleFieldValueWriteReady; writer.RecordFinished += HandleRecordFinished; while (!finished) { // loop until finished flag is set writer.Write(); } } }
// Example of using FtWriter to write a declared Fielded Text (CSV) file. static void Main(string[] args) { // Name of file containing Meta const string MetaFileName = "BasicExampleMeta.ftm"; // Name of file to be written const string FtxFileName = "BasicExample.ftx"; // Define FieldNames const string PetNameFieldName = "PetName"; const string AgeFieldName = "Age"; const string ColorFieldName = "Color"; const string DateReceivedFieldName = "DateReceived"; const string PriceFieldName = "Price"; const string NeedsWalkingFieldName = "NeedsWalking"; const string TypeFieldName = "Type"; // Create Meta from file FtMeta meta = FtMetaSerializer.Deserialize(MetaFileName); meta.LineCommentChar = '!'; // Is not set as with other examples. Change to ! meta.HeadingLineCount = 0; // Is set to 2 as with other examples. Change to 0 as we do not want any heading lines in this example // Create FtWriterSettings to flag we want Declared file written FtWriterSettings settings = new FtWriterSettings(); settings.Declared = true; settings.MetaReferenceType = FtMetaReferenceType.Embedded; // Create Writer using (FtWriter writer = new FtWriter(meta, FtxFileName, settings)) { // Write 1st Record writer[PetNameFieldName] = "Rover"; writer[AgeFieldName] = 4.5; writer[ColorFieldName] = "Brown"; writer[DateReceivedFieldName] = new DateTime(2004, 2, 12); writer[PriceFieldName] = 80M; writer[NeedsWalkingFieldName] = true; writer[TypeFieldName] = "Dog"; writer.Write(); // Write 2nd Record writer[PetNameFieldName] = "Charlie"; writer[AgeFieldName] = null; writer[ColorFieldName] = "Gold"; writer[DateReceivedFieldName] = new DateTime(2007, 4, 5); writer[PriceFieldName] = 12.3M; writer[NeedsWalkingFieldName] = false; writer[TypeFieldName] = "Fish"; writer.Write(); } }
public void Main() { // Create Meta from file FtMeta meta = FtMetaSerializer.Deserialize(MetaFileName); finished = false; // Create Writer using (FtWriter writer = new FtWriter(meta, CsvFileName)) { writer.FieldHeadingWriteReady += HandleFieldHeadingWriteReady; writer.FieldValueWriteReady += HandleFieldValueWriteReady; writer.RecordFinished += HandleRecordFinished; while (!finished) { // loop until finished flag is set writer.Write(); } } }
// Simple Example of using FtWriter to write a CSV file with comments. static void Main(string[] args) { // Name of file containing Meta const string MetaFileName = "BasicExampleMeta.ftm"; // Name of file to be written const string CsvFileName = "BasicExample.csv"; // Define FieldNames const string PetNameFieldName = "PetName"; const string AgeFieldName = "Age"; const string ColorFieldName = "Color"; const string DateReceivedFieldName = "DateReceived"; const string PriceFieldName = "Price"; const string NeedsWalkingFieldName = "NeedsWalking"; const string TypeFieldName = "Type"; // Create Meta from file FtMeta meta = FtMetaSerializer.Deserialize(MetaFileName); meta.LineCommentChar = '!'; // Is not set as with other examples. Change to ! // Create Writer using (FtWriter writer = new FtWriter(meta, CsvFileName)) { writer.WriteComment("My Pets"); writer.WriteComment("(Example writing CSV file with comments)"); writer.WriteComment(""); writer.WriteComment("Header"); writer.WriteComment(""); // only set up headings in first field writer.FieldList[0].Headings[0] = "First Field Heading 1"; writer.FieldList[0].Headings[1] = "First Field Heading 2"; writer.WriteHeader(); writer.WriteComment(""); writer.WriteComment("Records"); writer.WriteComment(""); // Write 1st Record writer.WriteComment("First Record"); writer[PetNameFieldName] = "Rover"; writer[AgeFieldName] = 4.5; writer[ColorFieldName] = "Brown"; writer[DateReceivedFieldName] = new DateTime(2004, 2, 12); writer[PriceFieldName] = 80M; writer[NeedsWalkingFieldName] = true; writer[TypeFieldName] = "Dog"; writer.Write(); // Write 2nd Record writer.WriteComment("Second Record"); writer[PetNameFieldName] = "Charlie"; writer[AgeFieldName] = null; writer[ColorFieldName] = "Gold"; writer[DateReceivedFieldName] = new DateTime(2007, 4, 5); writer[PriceFieldName] = 12.3M; writer[NeedsWalkingFieldName] = false; writer[TypeFieldName] = "Fish"; writer.Write(); writer.WriteComment("No more records"); } }
// Simple Example of using FtWriter to write a CSV file with headings. static void Main(string[] args) { // Name of file containing Meta const string MetaFileName = "BasicExampleMeta.ftm"; // Name of file to be written const string CsvFileName = "BasicExample.csv"; // Define FieldNames const string PetNameFieldName = "PetName"; const string AgeFieldName = "Age"; const string ColorFieldName = "Color"; const string DateReceivedFieldName = "DateReceived"; const string PriceFieldName = "Price"; const string NeedsWalkingFieldName = "NeedsWalking"; const string TypeFieldName = "Type"; // Create Meta from file FtMeta meta = FtMetaSerializer.Deserialize(MetaFileName); // Create Writer using (FtWriter writer = new FtWriter(meta, CsvFileName)) { FtStringField petNameField = writer.FieldList[PetNameFieldName] as FtStringField; FtFloatField ageField = writer.FieldList[AgeFieldName] as FtFloatField; FtStringField colorField = writer.FieldList[ColorFieldName] as FtStringField; FtDateTimeField dateReceivedField = writer.FieldList[DateReceivedFieldName] as FtDateTimeField; FtDecimalField priceField = writer.FieldList[PriceFieldName] as FtDecimalField; FtBooleanField needsWalkingField = writer.FieldList[NeedsWalkingFieldName] as FtBooleanField; FtStringField typeField = writer.FieldList[TypeFieldName] as FtStringField; // set headings before writing first record petNameField.Headings[0] = "Pet Name"; ageField.Headings[0] = "Age"; ageField.Headings[1] = "(Years)"; colorField.Headings[0] = "Color"; dateReceivedField.Headings[0] = "Date Received"; priceField.Headings[0] = "Price"; priceField.Headings[1] = "(Dollars)"; needsWalkingField.Headings[0] = "Needs Walking"; typeField.Headings[0] = "Type"; // Write 1st Record - this will write header (including heading lines) writer[PetNameFieldName] = "Rover"; writer[AgeFieldName] = 4.5; writer[ColorFieldName] = "Brown"; writer[DateReceivedFieldName] = new DateTime(2004, 2, 12); writer[PriceFieldName] = 80M; writer[NeedsWalkingFieldName] = true; writer[TypeFieldName] = "Dog"; writer.Write(); // Write 2nd Record writer[PetNameFieldName] = "Charlie"; writer[AgeFieldName] = null; writer[ColorFieldName] = "Gold"; writer[DateReceivedFieldName] = new DateTime(2007, 4, 5); writer[PriceFieldName] = 12.3M; writer[NeedsWalkingFieldName] = false; writer[TypeFieldName] = "Fish"; writer.Write(); } }
public void WebSiteBasicExample() { FtMeta meta = new FtMeta(); meta.LineCommentChar = '~'; meta.HeadingLineCount = 2; FtStringMetaField petNameMetaField = meta.FieldList.New(FtStandardDataType.String) as FtStringMetaField; petNameMetaField.Name = "PetName"; FtFloatMetaField ageMetaField = meta.FieldList.New(FtStandardDataType.Float) as FtFloatMetaField; ageMetaField.Name = "Age"; FtStringMetaField colorMetaField = meta.FieldList.New(FtStandardDataType.String) as FtStringMetaField; colorMetaField.Name = "Color"; FtDateTimeMetaField dateReceivedMetaField = meta.FieldList.New(FtStandardDataType.DateTime) as FtDateTimeMetaField; dateReceivedMetaField.Name = "DateReceived"; dateReceivedMetaField.Format = "d MMM yyyy"; FtDecimalMetaField priceMetaField = meta.FieldList.New(FtStandardDataType.Decimal) as FtDecimalMetaField; priceMetaField.Name = "Price"; FtBooleanMetaField needsWalkingMetaField = meta.FieldList.New(FtStandardDataType.Boolean) as FtBooleanMetaField; needsWalkingMetaField.Name = "NeedsWalking"; FtStringMetaField typeMetaField = meta.FieldList.New(FtStandardDataType.String) as FtStringMetaField; typeMetaField.Name = "Type"; string filePath = Path.Combine(TestFolder, BasicExampleFileName); FtWriterSettings writerSettings = new FtWriterSettings(); writerSettings.Declared = true; writerSettings.MetaReferenceType = FtMetaReferenceType.Embedded; writerSettings.EmbeddedMetaIndent = true; writerSettings.EmbeddedMetaIndentChars = " "; using (StreamWriter strmWriter = new StreamWriter(filePath, false, System.Text.Encoding.UTF8)) { using (FtWriter writer = new FtWriter(meta, strmWriter, writerSettings)) { FtStringField petNameField = writer.FieldList.Get(petNameMetaField.Name) as FtStringField; int petNameFieldIndex = writer.GetOrdinal(petNameMetaField.Name); FtFloatField ageField = writer.FieldList.Get(ageMetaField.Name) as FtFloatField; int ageFieldIndex = writer.GetOrdinal(ageMetaField.Name); FtStringField colorField = writer.FieldList.Get(colorMetaField.Name) as FtStringField; int colorFieldIndex = writer.GetOrdinal(colorMetaField.Name); FtDateTimeField dateReceivedField = writer.FieldList.Get(dateReceivedMetaField.Name) as FtDateTimeField; int dateReceivedFieldIndex = writer.GetOrdinal(dateReceivedMetaField.Name); FtDecimalField priceField = writer.FieldList.Get(priceMetaField.Name) as FtDecimalField; int priceFieldIndex = writer.GetOrdinal(priceMetaField.Name); FtBooleanField needsWalkingField = writer.FieldList.Get(needsWalkingMetaField.Name) as FtBooleanField; int needsWalkingFieldIndex = writer.GetOrdinal(needsWalkingMetaField.Name); FtStringField typeField = writer.FieldList.Get(typeMetaField.Name) as FtStringField; int typeFieldIndex = writer.GetOrdinal(typeMetaField.Name); for (int i = 0; i < headingArray.Length; i++) { petNameField.Headings[i] = headingArray[i].PetName; ageField.Headings[i] = headingArray[i].Age; colorField.Headings[i] = headingArray[i].Color; dateReceivedField.Headings[i] = headingArray[i].DateReceived; priceField.Headings[i] = headingArray[i].Price; needsWalkingField.Headings[i] = headingArray[i].NeedsWalking; typeField.Headings[i] = headingArray[i].Type; } for (int i = 0; i < 2; i++) { if (recArray[i].PetName != null) { petNameField.Value = recArray[i].PetName; } if (recArray[i].Age.HasValue) { // test assigning to AsObject as Single Single ageAsSingle = (Single)(recArray[i].Age.Value); ageField.AsObject = ageAsSingle; Assert.AreEqual <Single>(ageAsSingle, (Single)ageField.Value); // test assigning to AsObject as Decimal Decimal ageAsDecimal = (Decimal)(recArray[i].Age.Value); ageField.AsObject = ageAsDecimal; Assert.AreEqual <Decimal>(ageAsDecimal, (Decimal)ageField.Value); // assign as Double ageField.Value = recArray[i].Age.Value; } if (recArray[i].Color != null) { colorField.Value = recArray[i].Color; } if (recArray[i].DateReceived.HasValue) { dateReceivedField.Value = recArray[i].DateReceived.Value; } if (recArray[i].Price.HasValue) { // test assigning to AsObject as Single Single priceAsSingle = (Single)(recArray[i].Price.Value); priceField.AsObject = priceAsSingle; Assert.AreEqual <Single>(priceAsSingle, (Single)priceField.Value); // test assigning to AsObject as Double Double priceAsDouble = (Double)(recArray[i].Price.Value); priceField.AsObject = priceAsDouble; Assert.AreEqual <Double>(priceAsDouble, (Double)priceField.Value); // assign as Decimal priceField.Value = recArray[i].Price.Value; } if (recArray[i].NeedsWalking.HasValue) { needsWalkingField.Value = recArray[i].NeedsWalking.Value; } if (recArray[i].Type != null) { typeField.Value = recArray[i].Type; } writer.Write(); } for (int i = 2; i < 3; i++) { if (recArray[i].PetName == null) { writer.SetNull(i); } else { writer.SetString(petNameFieldIndex, recArray[i].PetName); } if (!recArray[i].Age.HasValue) { writer.SetNull(i); } else { // test assigning to AsObject as Single Single ageAsSingle = (Single)recArray[i].Age.Value; writer[ageMetaField.Name] = ageAsSingle; Assert.AreEqual <Single>(ageAsSingle, (Single)ageField.Value); // test assigning to AsObject as Decimal Decimal ageAsDecimal = (Decimal)(recArray[i].Age.Value); writer[ageMetaField.Name] = ageAsDecimal; Assert.AreEqual <Decimal>(ageAsDecimal, (Decimal)ageField.Value); // assign as Double writer.SetDouble(ageFieldIndex, recArray[i].Age.Value); } if (recArray[i].Color == null) { writer.SetNull(i); } else { writer.SetString(colorFieldIndex, recArray[i].Color); } if (!recArray[i].DateReceived.HasValue) { writer.SetNull(i); } else { writer.SetDateTime(dateReceivedFieldIndex, recArray[i].DateReceived.Value); } if (!recArray[i].Price.HasValue) { writer.SetNull(i); } else { // test assigning to AsObject as Single Single priceAsSingle = (Single)(recArray[i].Price.Value); writer[priceField.Name] = priceAsSingle; Assert.AreEqual <Single>(priceAsSingle, (Single)priceField.Value); // test assigning to AsObject as Double Double priceAsDouble = (Double)(recArray[i].Price.Value); writer[priceField.Name] = priceAsDouble; Assert.AreEqual <Double>(priceAsDouble, (Double)priceField.Value); // assign as Decimal writer.SetDecimal(priceFieldIndex, recArray[i].Price.Value); } if (!recArray[i].NeedsWalking.HasValue) { writer.SetNull(i); } else { writer.SetBoolean(needsWalkingFieldIndex, recArray[i].NeedsWalking.Value); } if (recArray[i].Type == null) { writer.SetNull(i); } else { writer.SetString(typeFieldIndex, recArray[i].Type); } writer.Write(); } for (int i = 3; i < recArray.Length; i++) { if (recArray[i].PetName == null) { writer[petNameMetaField.Name] = null; } else { writer[petNameMetaField.Name] = recArray[i].PetName; } if (!recArray[i].Age.HasValue) { writer[ageMetaField.Name] = null; } else { // test assigning to AsObject as Single Single ageAsSingle = (Single)recArray[i].Age.Value; writer[ageMetaField.Name] = ageAsSingle; Assert.AreEqual <Single>(ageAsSingle, (Single)ageField.Value); // test assigning to AsObject as Decimal Decimal ageAsDecimal = (Decimal)(recArray[i].Age.Value); writer[ageMetaField.Name] = ageAsDecimal; Assert.AreEqual <Decimal>(ageAsDecimal, (Decimal)ageField.Value); // assign as Double writer[ageMetaField.Name] = recArray[i].Age.Value; } if (recArray[i].Color == null) { writer[colorMetaField.Name] = null; } else { writer[colorMetaField.Name] = recArray[i].Color; } if (!recArray[i].DateReceived.HasValue) { writer[dateReceivedMetaField.Name] = null; } else { writer[dateReceivedMetaField.Name] = recArray[i].DateReceived.Value; } if (!recArray[i].Price.HasValue) { writer[priceMetaField.Name] = null; } else { // test assigning to AsObject as Single Single priceAsSingle = (Single)(recArray[i].Price.Value); writer[priceField.Name] = priceAsSingle; Assert.AreEqual <Single>(priceAsSingle, (Single)priceField.Value); // test assigning to AsObject as Double Double priceAsDouble = (Double)(recArray[i].Price.Value); writer[priceField.Name] = priceAsDouble; Assert.AreEqual <Double>(priceAsDouble, (Double)priceField.Value); // assign as Decimal writer[priceMetaField.Name] = recArray[i].Price.Value; } if (!recArray[i].NeedsWalking.HasValue) { writer[needsWalkingMetaField.Name] = null; } else { writer[needsWalkingMetaField.Name] = recArray[i].NeedsWalking.Value; } if (recArray[i].Type == null) { writer[typeMetaField.Name] = null; } else { writer[typeMetaField.Name] = recArray[i].Type; } writer.Write(); } } } string DataFilePath = Path.Combine(DataFolder, BasicExampleFileName); if (!TextFilesAreEqual(filePath, DataFilePath)) { Assert.Fail("BasicExample does not match Test Data"); } else { using (FtReader ftReader = new FtReader()) { ftReader.Open(filePath); using (StreamReader strmReader = new StreamReader(filePath)) { Assert.AreEqual <bool>(true, ftReader.Declared); Assert.AreEqual <bool>(true, ftReader.HeaderRead); Assert.AreEqual <int>(headingArray.Length, ftReader.HeadingLineReadCount); Assert.AreEqual <FtMetaReferenceType>(FtMetaReferenceType.Embedded, ftReader.MetaReferenceType); Assert.AreEqual <FtLineType>(FtLineType.Heading, ftReader.LineType); // last line in header FtStringField petNameField = ftReader.FieldList.Get(petNameMetaField.Name) as FtStringField; int petNameFieldIndex = ftReader.GetOrdinal(petNameMetaField.Name); FtFloatField ageField = ftReader.FieldList.Get(ageMetaField.Name) as FtFloatField; int ageFieldIndex = ftReader.GetOrdinal(ageMetaField.Name); FtStringField colorField = ftReader.FieldList.Get(colorMetaField.Name) as FtStringField; int colorFieldIndex = ftReader.GetOrdinal(colorMetaField.Name); FtDateTimeField dateReceivedField = ftReader.FieldList.Get(dateReceivedMetaField.Name) as FtDateTimeField; int dateReceivedFieldIndex = ftReader.GetOrdinal(dateReceivedMetaField.Name); FtDecimalField priceField = ftReader.FieldList.Get(priceMetaField.Name) as FtDecimalField; int priceFieldIndex = ftReader.GetOrdinal(priceMetaField.Name); FtBooleanField needsWalkingField = ftReader.FieldList.Get(needsWalkingMetaField.Name) as FtBooleanField; int needsWalkingFieldIndex = ftReader.GetOrdinal(needsWalkingMetaField.Name); FtStringField typeField = ftReader.FieldList.Get(typeMetaField.Name) as FtStringField; int typeFieldIndex = ftReader.GetOrdinal(typeMetaField.Name); // skip comment lines string strmLine; do { strmLine = strmReader.ReadLine(); }while (strmLine[0] == ftReader.LineCommentChar); for (int i = 0; i < headingArray.Length; i++) { strmLine = strmReader.ReadLine(); Assert.AreEqual <string>(headingArray[i].PetName, petNameField.Headings[i]); Assert.AreEqual <string>(headingArray[i].Age, ageField.Headings[i]); Assert.AreEqual <string>(headingArray[i].Color, colorField.Headings[i]); Assert.AreEqual <string>(headingArray[i].DateReceived, dateReceivedField.Headings[i]); Assert.AreEqual <string>(headingArray[i].Price, priceField.Headings[i]); Assert.AreEqual <string>(headingArray[i].NeedsWalking, needsWalkingField.Headings[i]); Assert.AreEqual <string>(headingArray[i].Type, typeField.Headings[i]); } for (int i = 0; i < recArray.Length; i++) { ftReader.Read(); Assert.AreEqual <string>(strmLine, ftReader.Line); Assert.AreEqual <int>(-1, ftReader.IgnoreExtraCharsLinePosition); Assert.AreEqual <int>(i + 1, ftReader.RecordCount); Assert.AreEqual <int>(1, ftReader.TableCount); if (recArray[i].PetName == null) { Assert.AreEqual <bool>(true, petNameField.IsNull()); } else { Assert.AreEqual <string>(recArray[i].PetName, petNameField.Value); Assert.AreEqual <object>(recArray[i].PetName, ftReader[petNameMetaField.Name]); Assert.AreEqual <object>(recArray[i].PetName, ftReader[petNameFieldIndex]); Assert.AreEqual <string>(recArray[i].PetName, ftReader.GetString(petNameFieldIndex)); } if (!recArray[i].Age.HasValue) { Assert.AreEqual <bool>(true, ageField.IsNull()); Assert.AreEqual <bool>(true, ftReader.IsDBNull(ageFieldIndex)); } else { Assert.AreEqual <double>(recArray[i].Age.Value, ageField.Value); Assert.AreEqual <object>(recArray[i].Age, ftReader[ageMetaField.Name]); Assert.AreEqual <object>(recArray[i].Age, ftReader[ageFieldIndex]); Assert.AreEqual <double>(recArray[i].Age.Value, ftReader.GetDouble(ageFieldIndex)); } if (recArray[i].Color == null) { Assert.AreEqual <bool>(true, colorField.IsNull()); } else { Assert.AreEqual <string>(recArray[i].Color, colorField.Value); Assert.AreEqual <object>(recArray[i].Color, ftReader[colorMetaField.Name]); Assert.AreEqual <object>(recArray[i].Color, ftReader[colorFieldIndex]); Assert.AreEqual <string>(recArray[i].Color, ftReader.GetString(colorFieldIndex)); } if (!recArray[i].DateReceived.HasValue) { Assert.AreEqual <bool>(true, dateReceivedField.IsNull()); } else { Assert.AreEqual <DateTime>(recArray[i].DateReceived.Value, dateReceivedField.Value); Assert.AreEqual <object>(recArray[i].DateReceived, ftReader[dateReceivedMetaField.Name]); Assert.AreEqual <object>(recArray[i].DateReceived, ftReader[dateReceivedFieldIndex]); Assert.AreEqual <DateTime>(recArray[i].DateReceived.Value, ftReader.GetDateTime(dateReceivedFieldIndex)); } if (!recArray[i].Price.HasValue) { Assert.AreEqual <bool>(true, priceField.IsNull()); } else { Assert.AreEqual <decimal>(recArray[i].Price.Value, priceField.Value); Assert.AreEqual <object>(recArray[i].Price, ftReader[priceMetaField.Name]); Assert.AreEqual <object>(recArray[i].Price, ftReader[priceFieldIndex]); Assert.AreEqual <decimal>(recArray[i].Price.Value, ftReader.GetDecimal(priceFieldIndex)); } if (!recArray[i].NeedsWalking.HasValue) { Assert.AreEqual <bool>(true, needsWalkingField.IsNull()); } else { Assert.AreEqual <bool>(recArray[i].NeedsWalking.Value, needsWalkingField.Value); Assert.AreEqual <object>(recArray[i].NeedsWalking, ftReader[needsWalkingMetaField.Name]); Assert.AreEqual <object>(recArray[i].NeedsWalking, ftReader[needsWalkingFieldIndex]); Assert.AreEqual <bool>(recArray[i].NeedsWalking.Value, ftReader.GetBoolean(needsWalkingFieldIndex)); } if (recArray[i].Type == null) { Assert.AreEqual <bool>(true, typeField.IsNull()); } else { Assert.AreEqual <string>(recArray[i].Type, typeField.Value); Assert.AreEqual <object>(recArray[i].Type, ftReader[typeMetaField.Name]); Assert.AreEqual <object>(recArray[i].Type, ftReader[typeFieldIndex]); Assert.AreEqual <string>(recArray[i].Type, ftReader.GetString(typeFieldIndex)); } strmLine = strmReader.ReadLine(); } Assert.AreEqual <bool>(false, ftReader.Read()); Assert.AreEqual <int>(recArray.Length, ftReader.RecordCount); } // repeat but read header separately ftReader.Open(filePath, false); Assert.AreEqual <int>(0, ftReader.HeadingLineReadCount); Assert.AreEqual <int>(0, ftReader.RecordCount); Assert.AreEqual <int>(0, ftReader.TableCount); Assert.AreEqual <bool>(true, ftReader.Declared); Assert.AreEqual <bool>(false, ftReader.HeaderRead); ftReader.ReadHeader(); Assert.AreEqual <bool>(true, ftReader.HeaderRead); Assert.AreEqual <int>(headingArray.Length, ftReader.HeadingLineReadCount); Assert.AreEqual <FtMetaReferenceType>(FtMetaReferenceType.Embedded, ftReader.MetaReferenceType); Assert.AreEqual <FtLineType>(FtLineType.Heading, ftReader.LineType); // last line in header ftReader.SeekEnd(); Assert.AreEqual <int>(recArray.Length, ftReader.RecordCount); // repeat but reading each line individually ftReader.Open(filePath, false); Assert.AreEqual <bool>(false, ftReader.HeaderRead); Assert.AreEqual <int>(0, ftReader.HeadingLineReadCount); Assert.AreEqual <int>(0, ftReader.RecordCount); Assert.AreEqual <int>(0, ftReader.TableCount); ftReader.ReadLine(); Assert.AreEqual <FtLineType>(FtLineType.Signature, ftReader.LineType); ftReader.ReadLine(); Assert.AreEqual <FtLineType>(FtLineType.Declaration2, ftReader.LineType); Assert.AreEqual <FtMetaReferenceType>(FtMetaReferenceType.Embedded, ftReader.MetaReferenceType); for (int i = 0; i < 10; i++) { ftReader.ReadLine(); if (i == 0) { Assert.AreEqual <FtLineType>(FtLineType.Comment, ftReader.LineType); } else { Assert.AreEqual <FtLineType>(FtLineType.EmbeddedMeta, ftReader.LineType); } } for (int i = 0; i < headingArray.Length; i++) { ftReader.ReadLine(); Assert.AreEqual <FtLineType>(FtLineType.Heading, ftReader.LineType); } Assert.AreEqual <int>(headingArray.Length, ftReader.HeadingLineReadCount); Assert.AreEqual <bool>(true, ftReader.HeaderRead); for (int i = 0; i < recArray.Length; i++) { ftReader.ReadLine(); Assert.AreEqual <FtLineType>(FtLineType.Record, ftReader.LineType); } Assert.AreEqual <bool>(false, ftReader.Read()); Assert.AreEqual <int>(recArray.Length, ftReader.RecordCount); Assert.AreEqual <int>(1, ftReader.TableCount); } } }
// Write a CSV file containing sequences // Uses ExampleSequenceMeta.ftm from BuildMetaWithSequences project static void Main(string[] args) { // Name of file containing Meta const string MetaFileName = "ExampleSequenceMeta.ftm"; // Name of file to be written const string CsvFileName = "ExampleSequence.csv"; // Define Field Names const string TypeFieldName = "Type"; const string NameFieldName = "Name"; const string RunningSpeedFieldName = "RunningSpeed"; const string WalkDistanceFieldName = "WalkDistance"; const string TrainingFieldName = "Training"; const string TrainerFieldName = "Trainer"; const string SessionCostFieldName = "SessionCost"; const string ColorFieldName = "Color"; const string ChineseClassificationFieldName = "ChineseClassification"; // Define Type values const long CatType = 1; const long DogType = 2; const long GoldFishType = 3; // Create Meta from file FtMeta meta = FtMetaSerializer.Deserialize(MetaFileName); // Create Writer using (FtWriter writer = new FtWriter(meta, CsvFileName)) { // When writing records with sequences, you must not set a field's value // if its sequence has not yet been invoked by a redirect. // When writing, whenever a sequence is invoked by a redirect, its field // values are initialized to null // Root Sequence is always automatically invoked // Write 1st Record (1st table) writer[TypeFieldName] = CatType; // invoke Cat Sequence (after Root Sequence is finished) writer[NameFieldName] = "Misty"; writer[RunningSpeedFieldName] = 45.0; writer.Write(); // Write 2nd Record writer[TypeFieldName] = CatType; // invoke Cat Sequence (after Root Sequence is finished) writer[NameFieldName] = "Oscar"; writer[RunningSpeedFieldName] = 35.0; writer.Write(); // Write 3rd Record (2nd table) writer[TypeFieldName] = DogType; // invoke Dog Sequence (after Root Sequence is finished) writer[NameFieldName] = "Buddy"; writer[WalkDistanceFieldName] = 0.5; writer[RunningSpeedFieldName] = 35.0; writer[TrainingFieldName] = false; writer.Write(); // Write 4th Record (3rd table) writer[TypeFieldName] = DogType; // invoke Dog Sequence (after Root Sequence is finished) writer[NameFieldName] = "Charlie"; writer[WalkDistanceFieldName] = 2.0; writer[RunningSpeedFieldName] = 48.0; writer[TrainingFieldName] = true; // invoke Training Sequence (after this field) writer[TrainerFieldName] = "John"; writer[SessionCostFieldName] = 32.0M; writer.Write(); // Write 5th Record (4th table) writer[TypeFieldName] = DogType; // invoke Dog Sequence (after Root Sequence is finished) writer[NameFieldName] = "Max"; writer[WalkDistanceFieldName] = 0.5; writer[RunningSpeedFieldName] = 30.0; writer[TrainingFieldName] = false; writer.Write(); // Write 6th Record (5th table) writer[TypeFieldName] = GoldFishType; // invoke Gold Fish Sequence (after Root Sequence is finished) writer[NameFieldName] = "Bubbles"; writer[ColorFieldName] = "Orange"; writer[ChineseClassificationFieldName] = "Wen"; writer.Write(); // Write 7th Record writer[TypeFieldName] = GoldFishType; // invoke Gold Fish Sequence (after Root Sequence is finished) writer[NameFieldName] = "Flash"; writer[ColorFieldName] = "Yellow"; writer[ChineseClassificationFieldName] = "Crucian"; writer.Write(); } }
public void Sequence() { int fieldsAffectedFromIndex; string metaFilePath = Path.Combine(DataFolder, SequenceMetaFileName); FtMeta meta = FtMetaSerializer.Deserialize(metaFilePath); FtWriter writer = new FtWriter(meta, filePath); // root fields FtStringField root1_StrConstField; FtDateTimeField root2_DateTimeField; FtIntegerField root3_IntRedirField; FtDecimalField level1_1_DecimalField; FtFloatField level1_1_FloatRedirField; FtBooleanField level1_Null_BooleanField; FtStringField level1_1_StringField; FtDateTimeField level1_2_DateTimeField; //FtStringField level1_3_StringField; FtStringField level2_10_StringField; FtStringField level2_11_StringField; // in this case, root fields are never affected by redirects root1_StrConstField = writer.FieldList[Root1_StrConstFieldName] as FtStringField; root2_DateTimeField = writer.FieldList[Root2_DateTimeFieldName] as FtDateTimeField; root3_IntRedirField = writer.FieldList[Root3_IntRedirFieldName] as FtIntegerField; // Record 1 - no redirect root2_DateTimeField.Value = Record1_Root2DateTimeValue; root3_IntRedirField.SetValue(Record1_Root3IntRedirValue, out fieldsAffectedFromIndex); Assert.AreEqual(-1, fieldsAffectedFromIndex); Assert.AreEqual(Record1_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Root_SequenceInvokationListCount, writer.SequenceInvokationList.Count); writer.Write(); Assert.AreEqual(1, writer.RecordCount); Assert.AreEqual(Record1_TableListCount, writer.TableCount); Assert.AreEqual(Record1_SequenceInvokationListCount, writer.SequenceInvokationList.Count); // Record 2 - no redirect root2_DateTimeField.Value = Record2_Root2DateTimeValue; root3_IntRedirField.SetValue(Record2_Root3IntRedirValue, out fieldsAffectedFromIndex); Assert.AreEqual(-1, fieldsAffectedFromIndex); Assert.AreEqual(Record2_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Record2_SequenceInvokationListCount, writer.SequenceInvokationList.Count); writer.Write(); Assert.AreEqual(2, writer.RecordCount); Assert.AreEqual(Record2_TableListCount, writer.TableCount); Assert.AreEqual(Root_SequenceInvokationListCount, writer.SequenceInvokationList.Count); // Record 3 - root redirect 1 root2_DateTimeField.Value = Record3_Root2DateTimeValue; root3_IntRedirField.SetValue(Record3_Root3IntRedirValue, out fieldsAffectedFromIndex); // redirect to level1_1 sequence { Assert.AreEqual(3, fieldsAffectedFromIndex); Assert.AreEqual(Record3_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Record3_SequenceInvokationListCount, writer.SequenceInvokationList.Count); // remove redirection root3_IntRedirField.SetValue(20, out fieldsAffectedFromIndex); Assert.AreEqual(3, fieldsAffectedFromIndex); Assert.AreEqual(Root_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Root_SequenceInvokationListCount, writer.SequenceInvokationList.Count); root3_IntRedirField.SetValue(Record3_Root3IntRedirValue, out fieldsAffectedFromIndex); Assert.AreEqual(3, fieldsAffectedFromIndex); Assert.AreEqual(Record3_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Record3_SequenceInvokationListCount, writer.SequenceInvokationList.Count); level1_1_DecimalField = writer.FieldList[Level1_1_DecimalFieldName] as FtDecimalField; level1_1_FloatRedirField = writer.FieldList[Level1_1_FloatRedirFieldName] as FtFloatField; level1_1_StringField = writer.FieldList[Level1_1_StringFieldName] as FtStringField; level1_1_DecimalField.Value = Record3_Level1_1_DecimalValue; level1_1_FloatRedirField.Value = Record3_Level1_1_FloatRedirValue; level1_1_StringField.Value = Record3_Level1_1_StringValue; } writer.Write(); Assert.AreEqual(3, writer.RecordCount); Assert.AreEqual(Record3_TableListCount, writer.TableCount); Assert.AreEqual(Root_SequenceInvokationListCount, writer.SequenceInvokationList.Count); // Record 4 - root redirect 1 root2_DateTimeField.Value = Record4_Root2DateTimeValue; root3_IntRedirField.SetValue(Record4_Root3IntRedirValue, out fieldsAffectedFromIndex); // redirect to level1_1 sequence { Assert.AreEqual(3, fieldsAffectedFromIndex); Assert.AreEqual(Record4_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Record4_SequenceInvokationListCount, writer.SequenceInvokationList.Count); level1_1_DecimalField = writer.FieldList[Level1_1_DecimalFieldName] as FtDecimalField; level1_1_FloatRedirField = writer.FieldList[Level1_1_FloatRedirFieldName] as FtFloatField; level1_1_StringField = writer.FieldList[Level1_1_StringFieldName] as FtStringField; level1_1_DecimalField.Value = Record4_Level1_1_DecimalValue; level1_1_FloatRedirField.Value = Record4_Level1_1_FloatRedirValue; level1_1_StringField.Value = Record4_Level1_1_StringValue; } writer.Write(); Assert.AreEqual(4, writer.RecordCount); Assert.AreEqual(Record4_TableListCount, writer.TableCount); Assert.AreEqual(Root_SequenceInvokationListCount, writer.SequenceInvokationList.Count); // Record 5 - root redirect 1 root2_DateTimeField.Value = Record5_Root2DateTimeValue; root3_IntRedirField.SetValue(Record5_Root3IntRedirValue, out fieldsAffectedFromIndex); // redirect to level1_1 sequence { Assert.AreEqual(3, fieldsAffectedFromIndex); Assert.AreEqual(Record5_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Record4_SequenceInvokationListCount, writer.SequenceInvokationList.Count); level1_1_DecimalField = writer.FieldList[Level1_1_DecimalFieldName] as FtDecimalField; level1_1_FloatRedirField = writer.FieldList[Level1_1_FloatRedirFieldName] as FtFloatField; level1_1_StringField = writer.FieldList[Level1_1_StringFieldName] as FtStringField; level1_1_DecimalField.Value = Record5_Level1_1_DecimalValue; level1_1_FloatRedirField.Value = Record5_Level1_1_FloatRedirValue; level1_1_StringField.Value = Record5_Level1_1_StringValue; } writer.Write(); Assert.AreEqual(5, writer.RecordCount); Assert.AreEqual(Record5_TableListCount, writer.TableCount); Assert.AreEqual(Root_SequenceInvokationListCount, writer.SequenceInvokationList.Count); // Record 6 - root redirect Null root2_DateTimeField.Value = Record6_Root2DateTimeValue; root3_IntRedirField.SetNull(out fieldsAffectedFromIndex); // redirect to level1_Null sequence { Assert.AreEqual(3, fieldsAffectedFromIndex); Assert.AreEqual(Record6_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Record6_SequenceInvokationListCount, writer.SequenceInvokationList.Count); level1_Null_BooleanField = writer.FieldList[Level1_Null_BooleanFieldName] as FtBooleanField; level1_Null_BooleanField.Value = Record6_level1_Null_BooleanValue; } writer.Write(); Assert.AreEqual(6, writer.RecordCount); Assert.AreEqual(Record6_TableListCount, writer.TableCount); Assert.AreEqual(Root_SequenceInvokationListCount, writer.SequenceInvokationList.Count); // Record 7 - root redirect 2 root2_DateTimeField.Value = Record7_Root2DateTimeValue; root3_IntRedirField.SetValue(Record7_Root3IntRedirValue, out fieldsAffectedFromIndex); // redirect to level1_2 sequence { Assert.AreEqual(3, fieldsAffectedFromIndex); Assert.AreEqual(Record7_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Record7_SequenceInvokationListCount, writer.SequenceInvokationList.Count); level1_2_DateTimeField = writer.FieldList[Level1_2_DateTimeFieldName] as FtDateTimeField; // leave it null } writer.Write(); Assert.AreEqual(7, writer.RecordCount); Assert.AreEqual(Record7_TableListCount, writer.TableCount); Assert.AreEqual(Root_SequenceInvokationListCount, writer.SequenceInvokationList.Count); // Record 8 - root redirect 1 root2_DateTimeField.Value = Record8_Root2DateTimeValue; root3_IntRedirField.SetValue(Record8_Root3IntRedirValue, out fieldsAffectedFromIndex); // redirect to level1_1 sequence { Assert.AreEqual(3, fieldsAffectedFromIndex); Assert.AreEqual(6, writer.FieldList.Count); Assert.AreEqual(2, writer.SequenceInvokationList.Count); level1_1_DecimalField = writer.FieldList[Level1_1_DecimalFieldName] as FtDecimalField; level1_1_FloatRedirField = writer.FieldList[Level1_1_FloatRedirFieldName] as FtFloatField; level1_1_StringField = writer.FieldList[Level1_1_StringFieldName] as FtStringField; level1_1_DecimalField.Value = Record8_Level1_1_DecimalValue; level1_1_FloatRedirField.SetValue(Record8_Level1_1_FloatRedirValue, out fieldsAffectedFromIndex); // redirect // redirect to Level2_10 sequence { Assert.AreEqual(5, fieldsAffectedFromIndex); Assert.AreEqual(Record8_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Record8_SequenceInvokationListCount, writer.SequenceInvokationList.Count); Assert.AreEqual(-1, writer.FieldList.IndexOfName(Level1_1_StringFieldName)); // should have been discarded by Redirect level2_10_StringField = writer.FieldList[Level2_10_StringFieldName] as FtStringField; level2_10_StringField.Value = Record8_level2_10_StringValue; } } writer.Write(); Assert.AreEqual(8, writer.RecordCount); Assert.AreEqual(Record8_TableListCount, writer.TableCount); Assert.AreEqual(Root_SequenceInvokationListCount, writer.SequenceInvokationList.Count); // Record 9 - root redirect 1 root2_DateTimeField.Value = Record9_Root2DateTimeValue; root3_IntRedirField.SetValue(Record9_Root3IntRedirValue, out fieldsAffectedFromIndex); // redirect to level1_1 sequence { Assert.AreEqual(3, fieldsAffectedFromIndex); Assert.AreEqual(6, writer.FieldList.Count); Assert.AreEqual(2, writer.SequenceInvokationList.Count); level1_1_DecimalField = writer.FieldList[Level1_1_DecimalFieldName] as FtDecimalField; level1_1_FloatRedirField = writer.FieldList[Level1_1_FloatRedirFieldName] as FtFloatField; level1_1_StringField = writer.FieldList[Level1_1_StringFieldName] as FtStringField; level1_1_DecimalField.Value = Record9_Level1_1_DecimalValue; level1_1_FloatRedirField.SetValue(Record9_Level1_1_FloatRedirValue, out fieldsAffectedFromIndex); // redirect // redirect to Level2_10 sequence { Assert.AreEqual(5, fieldsAffectedFromIndex); Assert.AreEqual(Record9_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Record9_SequenceInvokationListCount, writer.SequenceInvokationList.Count); Assert.AreEqual(-1, writer.FieldList.IndexOfName(Level1_1_StringFieldName)); // should have been discarded by Redirect level2_10_StringField = writer.FieldList[Level2_10_StringFieldName] as FtStringField; level2_10_StringField.Value = Record9_level2_10_StringValue; } } writer.Write(); Assert.AreEqual(9, writer.RecordCount); Assert.AreEqual(Record9_TableListCount, writer.TableCount); Assert.AreEqual(Root_SequenceInvokationListCount, writer.SequenceInvokationList.Count); // Record 10 - root redirect 1 root2_DateTimeField.Value = Record10_Root2DateTimeValue; root3_IntRedirField.SetValue(Record10_Root3IntRedirValue, out fieldsAffectedFromIndex); // redirect to level1_1 sequence { Assert.AreEqual(3, fieldsAffectedFromIndex); Assert.AreEqual(6, writer.FieldList.Count); Assert.AreEqual(2, writer.SequenceInvokationList.Count); level1_1_DecimalField = writer.FieldList[Level1_1_DecimalFieldName] as FtDecimalField; level1_1_FloatRedirField = writer.FieldList[Level1_1_FloatRedirFieldName] as FtFloatField; level1_1_StringField = writer.FieldList[Level1_1_StringFieldName] as FtStringField; level1_1_DecimalField.Value = Record10_Level1_1_DecimalValue; level1_1_StringField.Value = Record10_Level1_1_StringValue; level1_1_FloatRedirField.SetValue(Record10_Level1_1_FloatRedirValue, out fieldsAffectedFromIndex); // redirect // redirect to Level2_11 sequence { Assert.AreEqual(6, fieldsAffectedFromIndex); Assert.AreEqual(Record10_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Record10_SequenceInvokationListCount, writer.SequenceInvokationList.Count); Assert.AreEqual(5, writer.FieldList.IndexOfName(Level1_1_StringFieldName)); // confirm not discarded Assert.AreEqual(Record10_Level1_1_StringValue, level1_1_StringField.Value); level2_11_StringField = writer.FieldList[Level2_11_StringFieldName] as FtStringField; level2_11_StringField.Value = Record10_level2_11_StringValue; } } writer.Write(); Assert.AreEqual(10, writer.RecordCount); Assert.AreEqual(Record10_TableListCount, writer.TableCount); Assert.AreEqual(Root_SequenceInvokationListCount, writer.SequenceInvokationList.Count); // Record 11 - no redirect root2_DateTimeField.Value = Record11_Root2DateTimeValue; root3_IntRedirField.SetValue(Record11_Root3IntRedirValue, out fieldsAffectedFromIndex); Assert.AreEqual(-1, fieldsAffectedFromIndex); Assert.AreEqual(Record11_FieldListCount, writer.FieldList.Count); Assert.AreEqual(Root_SequenceInvokationListCount, writer.SequenceInvokationList.Count); writer.Write(); Assert.AreEqual(11, writer.RecordCount); Assert.AreEqual(Record11_TableListCount, writer.TableCount); Assert.AreEqual(Record11_SequenceInvokationListCount, writer.SequenceInvokationList.Count); writer.Close(); string dataFilePath = Path.Combine(DataFolder, SequenceFileName); if (!TextFilesAreEqual(filePath, dataFilePath)) { Assert.Fail("Sequence does not match Test Data"); } else { FtReader reader = new FtReader(meta); reader.Open(filePath); Assert.AreEqual <bool>(false, reader.Declared); Assert.AreEqual <bool>(true, reader.HeaderRead); Assert.AreEqual <int>(1, reader.HeadingLineReadCount); Assert.AreEqual <FtMetaReferenceType>(FtMetaReferenceType.None, reader.MetaReferenceType); Assert.AreEqual <FtLineType>(FtLineType.Heading, reader.LineType); // last line in header root1_StrConstField = reader.FieldList[Root1_StrConstFieldName] as FtStringField; root2_DateTimeField = reader.FieldList[Root2_DateTimeFieldName] as FtDateTimeField; root3_IntRedirField = reader.FieldList[Root3_IntRedirFieldName] as FtIntegerField; // Record 1 reader.Read(); Assert.AreEqual(Record1_FieldListCount, reader.FieldList.Count); Assert.AreEqual(Record1_SequenceInvokationListCount, reader.SequenceInvokationList.Count); Assert.AreEqual(1, reader.RecordCount); Assert.AreEqual(Record1_TableListCount, reader.TableCount); Assert.AreEqual <string>(Root1StrConstValue, root1_StrConstField.Value); Assert.AreEqual <DateTime>(Record1_Root2DateTimeValue, root2_DateTimeField.Value); Assert.AreEqual <long>(Record1_Root3IntRedirValue, root3_IntRedirField.Value); // Record 2 reader.Read(); Assert.AreEqual(Record2_FieldListCount, reader.FieldList.Count); Assert.AreEqual(Record2_SequenceInvokationListCount, reader.SequenceInvokationList.Count); Assert.AreEqual(2, reader.RecordCount); Assert.AreEqual(Record2_TableListCount, reader.TableCount); Assert.AreEqual <string>(Root1StrConstValue, root1_StrConstField.Value); Assert.AreEqual <DateTime>(Record2_Root2DateTimeValue, root2_DateTimeField.Value); Assert.AreEqual <long>(Record2_Root3IntRedirValue, root3_IntRedirField.Value); // Record 3 bool readResult = reader.Read(); Assert.AreEqual <bool>(false, readResult); Assert.AreEqual(2, reader.RecordCount); Assert.AreEqual(Record2_TableListCount, reader.TableCount); reader.AutoNextTable = true; readResult = reader.Read(); Assert.AreEqual <bool>(true, readResult); Assert.AreEqual(Record3_FieldListCount, reader.FieldList.Count); Assert.AreEqual(Record3_SequenceInvokationListCount, reader.SequenceInvokationList.Count); Assert.AreEqual(3, reader.RecordCount); Assert.AreEqual(Record3_TableListCount, reader.TableCount); root1_StrConstField = reader.FieldList[Root1_StrConstFieldName] as FtStringField; root2_DateTimeField = reader.FieldList[Root2_DateTimeFieldName] as FtDateTimeField; root3_IntRedirField = reader.FieldList[Root3_IntRedirFieldName] as FtIntegerField; level1_1_DecimalField = reader.FieldList[Level1_1_DecimalFieldName] as FtDecimalField; level1_1_FloatRedirField = reader.FieldList[Level1_1_FloatRedirFieldName] as FtFloatField; level1_1_StringField = reader.FieldList[Level1_1_StringFieldName] as FtStringField; Assert.AreEqual <string>(Root1StrConstValue, root1_StrConstField.Value); Assert.AreEqual <DateTime>(Record3_Root2DateTimeValue, root2_DateTimeField.Value); Assert.AreEqual <long>(Record3_Root3IntRedirValue, root3_IntRedirField.Value); Assert.AreEqual <decimal>(Record3_Level1_1_DecimalValue, level1_1_DecimalField.Value); Assert.AreEqual <double>(Record3_Level1_1_FloatRedirValue, level1_1_FloatRedirField.Value); Assert.AreEqual <string>(Record3_Level1_1_StringValue, level1_1_StringField.Value); // Record 4 reader.Read(); Assert.AreEqual(Record4_FieldListCount, reader.FieldList.Count); Assert.AreEqual(Record4_SequenceInvokationListCount, reader.SequenceInvokationList.Count); Assert.AreEqual(4, reader.RecordCount); Assert.AreEqual(Record4_TableListCount, reader.TableCount); Assert.AreEqual <string>(Root1StrConstValue, root1_StrConstField.Value); Assert.AreEqual <DateTime>(Record4_Root2DateTimeValue, root2_DateTimeField.Value); Assert.AreEqual <long>(Record4_Root3IntRedirValue, root3_IntRedirField.Value); Assert.AreEqual <decimal>(Record4_Level1_1_DecimalValue, level1_1_DecimalField.Value); Assert.AreEqual <double>(Record4_Level1_1_FloatRedirValue, level1_1_FloatRedirField.Value); Assert.AreEqual <string>(Record4_Level1_1_StringValue, level1_1_StringField.Value); // Record 5 reader.Read(); Assert.AreEqual(Record5_FieldListCount, reader.FieldList.Count); Assert.AreEqual(Record5_SequenceInvokationListCount, reader.SequenceInvokationList.Count); Assert.AreEqual(5, reader.RecordCount); Assert.AreEqual(Record5_TableListCount, reader.TableCount); Assert.AreEqual <string>(Root1StrConstValue, root1_StrConstField.Value); Assert.AreEqual <DateTime>(Record5_Root2DateTimeValue, root2_DateTimeField.Value); Assert.AreEqual <long>(Record5_Root3IntRedirValue, root3_IntRedirField.Value); Assert.AreEqual <decimal>(Record5_Level1_1_DecimalValue, level1_1_DecimalField.Value); Assert.AreEqual <double>(Record5_Level1_1_FloatRedirValue, level1_1_FloatRedirField.Value); Assert.AreEqual <string>(Record5_Level1_1_StringValue, level1_1_StringField.Value); // Record 6 reader.Read(); Assert.AreEqual(Record6_FieldListCount, reader.FieldList.Count); Assert.AreEqual(Record6_SequenceInvokationListCount, reader.SequenceInvokationList.Count); Assert.AreEqual(6, reader.RecordCount); Assert.AreEqual(Record6_TableListCount, reader.TableCount); root1_StrConstField = reader.FieldList[Root1_StrConstFieldName] as FtStringField; root2_DateTimeField = reader.FieldList[Root2_DateTimeFieldName] as FtDateTimeField; root3_IntRedirField = reader.FieldList[Root3_IntRedirFieldName] as FtIntegerField; level1_Null_BooleanField = reader.FieldList[Level1_Null_BooleanFieldName] as FtBooleanField; Assert.AreEqual <string>(Root1StrConstValue, root1_StrConstField.Value); Assert.AreEqual <DateTime>(Record6_Root2DateTimeValue, root2_DateTimeField.Value); Assert.AreEqual <bool>(true, root3_IntRedirField.IsNull()); Assert.AreEqual <bool>(Record6_level1_Null_BooleanValue, level1_Null_BooleanField.Value); // Record 7 reader.Read(); Assert.AreEqual(Record7_FieldListCount, reader.FieldList.Count); Assert.AreEqual(Record7_SequenceInvokationListCount, reader.SequenceInvokationList.Count); Assert.AreEqual(7, reader.RecordCount); Assert.AreEqual(Record7_TableListCount, reader.TableCount); root1_StrConstField = reader.FieldList[Root1_StrConstFieldName] as FtStringField; root2_DateTimeField = reader.FieldList[Root2_DateTimeFieldName] as FtDateTimeField; root3_IntRedirField = reader.FieldList[Root3_IntRedirFieldName] as FtIntegerField; level1_2_DateTimeField = reader.FieldList[Level1_2_DateTimeFieldName] as FtDateTimeField; Assert.AreEqual <string>(Root1StrConstValue, root1_StrConstField.Value); Assert.AreEqual <DateTime>(Record7_Root2DateTimeValue, root2_DateTimeField.Value); Assert.AreEqual <long>(Record7_Root3IntRedirValue, root3_IntRedirField.Value); Assert.AreEqual <bool>(true, level1_2_DateTimeField.IsNull()); // Record 8 reader.Read(); Assert.AreEqual(Record8_FieldListCount, reader.FieldList.Count); Assert.AreEqual(Record8_SequenceInvokationListCount, reader.SequenceInvokationList.Count); Assert.AreEqual(8, reader.RecordCount); Assert.AreEqual(Record8_TableListCount, reader.TableCount); root1_StrConstField = reader.FieldList[Root1_StrConstFieldName] as FtStringField; root2_DateTimeField = reader.FieldList[Root2_DateTimeFieldName] as FtDateTimeField; root3_IntRedirField = reader.FieldList[Root3_IntRedirFieldName] as FtIntegerField; level1_1_DecimalField = reader.FieldList[Level1_1_DecimalFieldName] as FtDecimalField; level1_1_FloatRedirField = reader.FieldList[Level1_1_FloatRedirFieldName] as FtFloatField; Assert.AreEqual <int>(-1, reader.FieldList.IndexOfName(Level1_1_StringFieldName)); level2_10_StringField = reader.FieldList[Level2_10_StringFieldName] as FtStringField; Assert.AreEqual <string>(Root1StrConstValue, root1_StrConstField.Value); Assert.AreEqual <DateTime>(Record8_Root2DateTimeValue, root2_DateTimeField.Value); Assert.AreEqual <long>(Record8_Root3IntRedirValue, root3_IntRedirField.Value); Assert.AreEqual <decimal>(Record8_Level1_1_DecimalValue, level1_1_DecimalField.Value); Assert.AreEqual <double>(Record8_Level1_1_FloatRedirValue, level1_1_FloatRedirField.Value); Assert.AreEqual <string>(Record8_level2_10_StringValue, level2_10_StringField.Value); // Record 9 reader.Read(); Assert.AreEqual <int>(-1, reader.FieldList.IndexOfName(Level1_1_StringFieldName)); Assert.AreEqual(Record9_FieldListCount, reader.FieldList.Count); Assert.AreEqual(Record9_SequenceInvokationListCount, reader.SequenceInvokationList.Count); Assert.AreEqual(9, reader.RecordCount); Assert.AreEqual(Record9_TableListCount, reader.TableCount); Assert.AreEqual <string>(Root1StrConstValue, root1_StrConstField.Value); Assert.AreEqual <DateTime>(Record9_Root2DateTimeValue, root2_DateTimeField.Value); Assert.AreEqual <long>(Record9_Root3IntRedirValue, root3_IntRedirField.Value); Assert.AreEqual <decimal>(Record9_Level1_1_DecimalValue, level1_1_DecimalField.Value); Assert.AreEqual <double>(Record9_Level1_1_FloatRedirValue, level1_1_FloatRedirField.Value); Assert.AreEqual <string>(Record9_level2_10_StringValue, level2_10_StringField.Value); // Record 10 reader.Read(); Assert.AreEqual(Record10_FieldListCount, reader.FieldList.Count); Assert.AreEqual(Record10_SequenceInvokationListCount, reader.SequenceInvokationList.Count); Assert.AreEqual(10, reader.RecordCount); Assert.AreEqual(Record10_TableListCount, reader.TableCount); root1_StrConstField = reader.FieldList[Root1_StrConstFieldName] as FtStringField; root2_DateTimeField = reader.FieldList[Root2_DateTimeFieldName] as FtDateTimeField; root3_IntRedirField = reader.FieldList[Root3_IntRedirFieldName] as FtIntegerField; level1_1_DecimalField = reader.FieldList[Level1_1_DecimalFieldName] as FtDecimalField; level1_1_FloatRedirField = reader.FieldList[Level1_1_FloatRedirFieldName] as FtFloatField; level1_1_StringField = reader.FieldList[Level1_1_StringFieldName] as FtStringField; level2_11_StringField = reader.FieldList[Level2_11_StringFieldName] as FtStringField; Assert.AreEqual <string>(Root1StrConstValue, root1_StrConstField.Value); Assert.AreEqual <DateTime>(Record10_Root2DateTimeValue, root2_DateTimeField.Value); Assert.AreEqual <long>(Record10_Root3IntRedirValue, root3_IntRedirField.Value); Assert.AreEqual <decimal>(Record10_Level1_1_DecimalValue, level1_1_DecimalField.Value); Assert.AreEqual <double>(Record10_Level1_1_FloatRedirValue, level1_1_FloatRedirField.Value); Assert.AreEqual <string>(Record10_Level1_1_StringValue, level1_1_StringField.Value); Assert.AreEqual <string>(Record10_level2_11_StringValue, level2_11_StringField.Value); // Record 11 reader.Read(); Assert.AreEqual(Record11_FieldListCount, reader.FieldList.Count); Assert.AreEqual(Record11_SequenceInvokationListCount, reader.SequenceInvokationList.Count); Assert.AreEqual(11, reader.RecordCount); Assert.AreEqual(Record11_TableListCount, reader.TableCount); root1_StrConstField = reader.FieldList[Root1_StrConstFieldName] as FtStringField; root2_DateTimeField = reader.FieldList[Root2_DateTimeFieldName] as FtDateTimeField; root3_IntRedirField = reader.FieldList[Root3_IntRedirFieldName] as FtIntegerField; Assert.AreEqual <string>(Root1StrConstValue, root1_StrConstField.Value); Assert.AreEqual <DateTime>(Record11_Root2DateTimeValue, root2_DateTimeField.Value); Assert.AreEqual <long>(Record11_Root3IntRedirValue, root3_IntRedirField.Value); reader.Close(); } }