IEnumerable <IComponent> ReadConcepts() { String ExportPath = TinkFile; using Stream zipFile = File.OpenRead(TinkarZipFile); using ZipArchive archive = new ZipArchive(zipFile); ZipArchiveEntry entry = archive.GetEntry("export.tink"); Stream zipStream = entry.Open(); { using TinkarInput input = new TinkarInput(zipStream); Int32 counter = 0; bool done = false; while (done == false) { IComponent c = (IComponent)input.GetField(); if (c == null) { done = true; } else { yield return(c); counter += 1; if ((counter % BlockSize) == 0) { GC.Collect(2, GCCollectionMode.Forced); } } } } }
public void Int32Test() { void Test(Int32 start) { MemoryStream ms = MSCreate(); using (TinkarOutput output = new TinkarOutput(ms)) { output.WriteField(start); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { Int32 value = (Int32)input.GetField(); Assert.True(start == value); } } Test(Int32.MinValue); Test(Int32.MaxValue); Test(0); Test(-1); Test(100); Test((Int32)0x7fe1deab); }
public void StampDTOMarshalTest() { DateTime time = new DateTime(2020, 12, 31); StampDTO dtoStart = new StampDTO( Misc.PublicIdG, Misc.PublicIdH, time, Misc.PublicIdI, Misc.PublicIdJ, Misc.PublicIdK ); MemoryStream ms = new MemoryStream(); using (TinkarOutput output = new TinkarOutput(ms)) { dtoStart.Marshal(output); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { StampDTO dtoEnd = StampDTO.Make(input); Assert.True(dtoStart.CompareTo(dtoEnd) == 0); } }
public void FloatTest() { void Test(Single start) { MemoryStream ms = MSCreate(); using (TinkarOutput output = new TinkarOutput(ms)) { output.WriteField(start); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { Single value = (Single)input.GetField(); Assert.True(start == value); } } Test(Single.MinValue); Test(Single.MaxValue); Test(0.1F); Test(-1.234F); Test(100.987F); }
public void B_BinaryReadObjects() { guidNumber = 0xfedd; String inputPath = TestFile("TinkarExport.tink"); using FileStream fs = new FileStream(inputPath, FileMode.Open, FileAccess.ReadWrite, FileShare.None); using TinkarInput input = new TinkarInput(fs); ComponentDTO[] readFields = input.GetComponents().ToArray(); ComponentDTO[] compareFields = this.CreateComponents().ToArray(); Assert.True(readFields.Length == compareFields.Length); for (Int32 i = 0; i < readFields.Length; i++) { Assert.True(readFields[i].CompareTo(compareFields[i]) == 0); } }
public void ReadIntTest() { { MemoryStream ms = MSCreate(new byte[] { 1, 2, 3, 4 }); TinkarInput ti = new TinkarInput(ms); Int32 value = ti.GetInt32(); Assert.True(value == this.MakeInt32(1, 2, 3, 4)); } { MemoryStream ms = MSCreate(new byte[] { 0xf1, 0xf2, 0xf3, 0xf4 }); TinkarInput ti = new TinkarInput(ms); Int32 value = ti.GetInt32(); Assert.True(value == this.MakeInt32(0xf1, 0xf2, 0xf3, 0xf4)); } }
public void GraphDTOMarshalTest() { GraphDTO dtoStart = Misc.CreateGraphDTO(); MemoryStream ms = new MemoryStream(); using (TinkarOutput output = new TinkarOutput(ms)) { dtoStart.MarshalVertexMap(output); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { ImmutableList <VertexDTO> dtoRead = GraphDTO.UnmarshalVertexMap(input); Assert.True(FieldCompare.CompareSequence(dtoRead, dtoStart.VertexMap) == 0); } }
public void ReadLongTest() { { MemoryStream ms = MSCreate(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }); TinkarInput ti = new TinkarInput(ms); Int64 value = ti.GetLong(); Int64 compare = MakeInt64(1, 2, 3, 4, 5, 6, 7, 8); Assert.True(value == compare); } { MemoryStream ms = MSCreate(new byte[] { 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8 }); TinkarInput ti = new TinkarInput(ms); Int64 value = ti.GetLong(); Int64 compare = MakeInt64(0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8); Assert.True(value == compare); } }
public void PatternDTOMarshalTest() { PatternDTO dtoStart = Misc.CreatePatternDTO; MemoryStream ms = new MemoryStream(); using (TinkarOutput output = new TinkarOutput(ms)) { output.WriteField(dtoStart); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { PatternDTO dtoRead = (PatternDTO)input.GetField(); Assert.True(dtoStart.CompareTo(dtoRead) == 0); } }
public void DiTreeDTOMarshalTest() { DiTreeDTO dtoStart = Misc.CreateDiTreeDTO(); MemoryStream ms = new MemoryStream(); using (TinkarOutput output = new TinkarOutput(ms)) { dtoStart.Marshal(output); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { DiTreeDTO dtoRead = DiTreeDTO.Make(input); Assert.True(dtoStart.CompareTo(dtoRead) == 0); } }
public void SemanticVersionDTOMarshalTest() { SemanticVersionDTO dtoStart = Misc.CreateSemanticVersionDTO; MemoryStream ms = new MemoryStream(); using (TinkarOutput output = new TinkarOutput(ms)) { dtoStart.Marshal(output); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { SemanticVersionDTO dtoRead = SemanticVersionDTO.Make(input, dtoStart.PublicId); Assert.True(dtoStart.CompareTo(dtoRead) == 0); } }
public void ReadUuidArrayTest() { byte[] lenZero = new byte[] { 0, 0, 0, 0 }; byte[] lenOne = new byte[] { 0, 0, 0, 1 }; byte[] lenTwo = new byte[] { 0, 0, 0, 2 }; byte[] guidBytes1 = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; byte[] guidBytes2 = new byte[] { 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff }; { MemoryStream ms = MSCreate(lenZero); TinkarInput ti = new TinkarInput(ms); Guid[] value = ti.GetUuids(); Assert.True(value.Length == 0); } { MemoryStream ms = MSCreate(lenOne, guidBytes1); TinkarInput ti = new TinkarInput(ms); Guid[] gArr = ti.GetUuids(); Assert.True(gArr.Length == 1); Assert.True(gArr[0] == new Guid(guidBytes1)); } { MemoryStream ms = MSCreate(lenOne, guidBytes2); TinkarInput ti = new TinkarInput(ms); Guid[] gArr = ti.GetUuids(); Assert.True(gArr.Length == 1); Assert.True(gArr[0] == new Guid(guidBytes2)); } { MemoryStream ms = MSCreate(lenTwo, guidBytes1, guidBytes2); TinkarInput ti = new TinkarInput(ms); Guid[] gArr = ti.GetUuids(); Assert.True(gArr.Length == 2); Assert.True(gArr[0] == new Guid(guidBytes1)); Assert.True(gArr[1] == new Guid(guidBytes2)); } }
public void ConceptVersionDTOMarshalTest() { ConceptVersionDTO dtoStart = Misc.CreateConceptVersionDTO; MemoryStream ms = new MemoryStream(); using (TinkarOutput output = new TinkarOutput(ms)) { dtoStart.Marshal(output); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { ConceptVersionDTO dtoRead = ConceptVersionDTO.Make(input, new PublicId(Misc.g1, Misc.g2, Misc.g3, Misc.g4)); Assert.True(dtoStart.CompareTo(dtoRead) == 0); } }
public void BoolTest() { void Test(bool start) { MemoryStream ms = MSCreate(); using (TinkarOutput output = new TinkarOutput(ms)) { output.WriteField(start); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { Boolean value = (Boolean)input.GetField(); Assert.True(start == value); } } Test(true); Test(false); }
public void InstantTest() { void Test(DateTime start) { MemoryStream ms = MSCreate(); using (TinkarOutput output = new TinkarOutput(ms)) { output.WriteField(start); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { DateTime value = (DateTime)input.GetField(); Assert.True(start == value); } } Test(new DateTime(1900, 1, 1)); Test(new DateTime(2020, 1, 2, 12, 30, 30, 100)); }
public void FieldDefinitionDTOMarshalTest() { FieldDefinitionDTO dtoStart = new FieldDefinitionDTO( Misc.PublicIdG, Misc.PublicIdH, Misc.PublicIdI ); MemoryStream ms = new MemoryStream(); using (TinkarOutput output = new TinkarOutput(ms)) { dtoStart.Marshal(output); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { FieldDefinitionDTO dtoRead = FieldDefinitionDTO.Make(input); Assert.True(dtoStart.CompareTo(dtoRead) == 0); } }
public void ConceptChronologyDTOMarshalTest() { ConceptChronologyDTO dtoStart = new ConceptChronologyDTO( Misc.PublicIdG, Misc.ConceptVersionsBase(Misc.PublicIdG).ToImmutableArray() ); MemoryStream ms = new MemoryStream(); using (TinkarOutput output = new TinkarOutput(ms)) { output.WriteField(dtoStart); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { ConceptChronologyDTO dtoRead = (ConceptChronologyDTO)input.GetField(); Assert.True(dtoStart.CompareTo(dtoRead) == 0); } }
public void ByteArrayTest() { void Test(byte[] start) { MemoryStream ms = MSCreate(); using (TinkarOutput output = new TinkarOutput(ms)) { output.WriteField(start); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { byte[] value = (byte[])input.GetField(); Assert.True(start.SequenceEqual(value)); } } Test(new byte[] { }); Test(new byte[] { 1 }); Test(new byte[] { 1, 30, 255 }); }
public void StringTest() { void Test(String start) { MemoryStream ms = MSCreate(); using (TinkarOutput output = new TinkarOutput(ms)) { output.WriteField(start); } ms.Position = 0; using (TinkarInput input = new TinkarInput(ms)) { String value = (String)input.GetField(); Assert.True(start == value); } } Test(String.Empty); Test("a"); Test("This is a test string"); }