// This example shows how to use ordinals when reading fields. // An ordinal is actual the index of a field in a record. // If you access a field by its field name, then the name has // to be converted to the corresponding ordinal. // An field's ordinal will remain the same until the table in // the file has ended. So typically, ordinals are calculated // from field names after the first record is read in a table. // These ordinal values can then be used until all the records // in the table have been read. // // Use ordinals when a file is large and you want to read it // as quickly as possible. static void Main(string[] args) { // Name of file containing Meta const string MetaFileName = "ExampleSequenceMeta.ftm"; // Name of file to be read const string CsvFileName = "ExampleSequence.csv"; // Create Meta from file FtMeta meta = FtMetaSerializer.Deserialize(MetaFileName); // Create Reader using (FtReader reader = new FtReader(meta, CsvFileName)) { int[] recOrdinals = null; object[] recObjects = null; do { // Loop for each table in file fl while (reader.Read()) { // Read each record in table and write field values to console if (recOrdinals == null) { // Ordinals only need to be calculated for first row of table. // Will be the same for rest of records in table recOrdinals = CalculateRecordOrdinals(reader); recObjects = new object[recOrdinals.Length]; } for (int i = 0; i < recOrdinals.Length; i++) { int ordinal = recOrdinals[i]; recObjects[i] = reader[ordinal]; // specify field by ordinal } Console.WriteLine(string.Format("{0},{1}: {2}", reader.RecordCount, reader.TableCount, string.Join(",", recObjects))); } recOrdinals = null; // Ordinals are no longer valid after table is finished } while (reader.NextResult()); } }
static void Main(string[] args) { // Name of file containing Meta const string MetaFileName = "BasicExampleMeta.ftm"; // Name of file to be read 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 Reader using (FtReader reader = new FtReader(meta, CsvFileName)) { // Read each record in text file and write field values to console object[] recObjects = new object[7]; int recNumber = 0; while (reader.Read()) { recNumber++; recObjects[0] = reader[PetNameFieldName]; recObjects[1] = reader[AgeFieldName]; recObjects[2] = reader[ColorFieldName]; recObjects[3] = reader[DateReceivedFieldName]; recObjects[4] = reader[PriceFieldName]; recObjects[5] = reader[NeedsWalkingFieldName]; recObjects[6] = reader[TypeFieldName]; Console.WriteLine(recNumber.ToString() + ": " + string.Join(",", recObjects)); } } }
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); } } }
static void Main(string[] args) { // Name of file containing Meta const string MetaFileName = "ExampleSequenceMeta.ftm"; // Name of file to be read 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; const int MaxFieldCount = 7; // Create Meta from file FtMeta meta = FtMetaSerializer.Deserialize(MetaFileName); // Create Reader using (FtReader reader = new FtReader(meta, CsvFileName)) { // Normally a reader.Read() will return false when a new table starts in a file. // You would then need to call reader.NextResult() (or reader.NextTable()) to // read the record from the next table. // When a new table starts, you would need to get new field ordinal values with // reader.GetOrdinal() if you are using field ordinals. // However this example does not use field ordinal values. It just uses field names. // Accordingly we want to reader.Read() to return true until no more records. // Set AutoNextTable to true for this behaviour. reader.AutoNextTable = true; // Read each record in text file and write field values to console int recNumber = 0; while (reader.Read()) { recNumber++; object[] recObjects = new object[MaxFieldCount]; // read Root Sequence Fields recObjects[0] = reader[TypeFieldName]; recObjects[1] = reader[NameFieldName]; int fieldCount; // Type Field specifies what type of record this is and what fields there are long type = (long)recObjects[0]; switch (type) { case CatType: recObjects[2] = reader[RunningSpeedFieldName]; fieldCount = 3; break; case DogType: recObjects[2] = reader[WalkDistanceFieldName]; recObjects[3] = reader[RunningSpeedFieldName]; recObjects[4] = reader[TrainingFieldName]; bool training = (bool)recObjects[4]; if (!training) { fieldCount = 5; } else { recObjects[5] = reader[TrainerFieldName]; recObjects[6] = reader[SessionCostFieldName]; fieldCount = 7; } break; case GoldFishType: recObjects[2] = reader[ColorFieldName]; recObjects[3] = reader[ChineseClassificationFieldName]; fieldCount = 4; break; default: fieldCount = 2; break; } Array.Resize <object>(ref recObjects, fieldCount); Console.WriteLine(recNumber.ToString() + ": " + string.Join(",", recObjects)); } } }
static void Main(string[] args) { // Name of file to be read const string FileName = "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 that represents structure and format of BasicExample.csv file FtMeta meta = new FtMeta(); // All FtMeta defaults apply to BasicExample.csv except for HeadingLineCount meta.HeadingLineCount = 2; // Add fields // Add in order of fields in file so index does not have to be explicitly set FtMetaField metaField; metaField = meta.FieldList.New(FtStandardDataType.String); metaField.Name = PetNameFieldName; metaField = meta.FieldList.New(FtStandardDataType.Float); metaField.Name = AgeFieldName; metaField = meta.FieldList.New(FtStandardDataType.String); metaField.Name = ColorFieldName; metaField = meta.FieldList.New(FtStandardDataType.DateTime); metaField.Name = DateReceivedFieldName; // Default format for Date Time is not used in "Date Received" field. Specify the date format used. ((FtDateTimeMetaField)metaField).Format = "d MMM yyyy"; metaField = meta.FieldList.New(FtStandardDataType.Decimal); metaField.Name = PriceFieldName; metaField = meta.FieldList.New(FtStandardDataType.Boolean); metaField.Name = NeedsWalkingFieldName; metaField = meta.FieldList.New(FtStandardDataType.String); metaField.Name = TypeFieldName; // Create Reader using (FtReader reader = new FtReader(meta, FileName)) { // Read each record in text file and write field values to console object[] recObjects = new object[7]; int recNumber = 0; while (reader.Read()) { recNumber++; recObjects[0] = reader[PetNameFieldName]; recObjects[1] = reader[AgeFieldName]; recObjects[2] = reader[ColorFieldName]; recObjects[3] = reader[DateReceivedFieldName]; recObjects[4] = reader[PriceFieldName]; recObjects[5] = reader[NeedsWalkingFieldName]; recObjects[6] = reader[TypeFieldName]; Console.WriteLine(recNumber.ToString() + ": " + string.Join(",", recObjects)); } } }
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(); } }