public static IComponent Convert(PBTinkarMsg c) { switch (c.ValueCase) { case PBTinkarMsg.ValueOneofCase.ConceptValue: return(c.ConceptValue.ToConcept()); case PBTinkarMsg.ValueOneofCase.ConceptVersionValue: return(c.ConceptVersionValue.ToConceptVersion()); case PBTinkarMsg.ValueOneofCase.ConceptChronologyValue: return(c.ConceptChronologyValue.ToConceptChronology()); case PBTinkarMsg.ValueOneofCase.PatternValue: return(c.PatternValue.ToPattern()); case PBTinkarMsg.ValueOneofCase.PatternVersionValue: return(c.PatternVersionValue.ToPatternVersion()); case PBTinkarMsg.ValueOneofCase.PatternChronologyValue: return(c.PatternChronologyValue.ToPatternChronology()); case PBTinkarMsg.ValueOneofCase.SemanticValue: return(c.SemanticValue.ToSemantic()); case PBTinkarMsg.ValueOneofCase.SemanticVersionValue: return(c.SemanticVersionValue.ToSemanticVersion()); case PBTinkarMsg.ValueOneofCase.SemanticChronologyValue: return(c.SemanticChronologyValue.ToSemanticChronology()); default: throw new NotImplementedException(); } }
public void AReadPBAndDTOAndValidate() { DateTime start = DateTime.Now; DateTime current = start; TimeSpan elapsed; using FileStream input = File.OpenRead(ProtobufFile); Int32 i = 0; PBReader pbReader = new PBReader(input); NativeMethods.PreventSleep(); foreach (IComponent component in this.ReadConcepts()) { PBTinkarMsg pbMsg = pbReader.Read(); IComponent dto = ConvertPBToDTO.Convert(pbMsg); Assert.True(component.CompareTo(dto) == 0); if ((i % BlockSize) == 0) { elapsed = DateTime.Now - current; current = DateTime.Now; float itemsPerSec = (float)BlockSize / (float)elapsed.TotalSeconds; Trace.WriteLine($"{i} - Read time {elapsed.TotalSeconds} / {itemsPerSec.ToString("F2")}"); GC.Collect(2, GCCollectionMode.Forced); } i += 1; } Assert.True(pbReader.Read() == null); elapsed = DateTime.Now - start; NativeMethods.AllowSleep(); Trace.WriteLine($"AProtobufReadConcepts time {elapsed}"); }
public void AReadDTOAndWritePBAllConcepts() { DateTime start = DateTime.Now; FileStream output = File.Create(ProtobufFile); using PBWriter pbWriter = new PBWriter(output); NativeMethods.PreventSleep(); Int32 i = 0; foreach (IComponent component in this.ReadConcepts()) { PBTinkarMsg pb = ConvertDTOToPB.Convert(component); pbWriter.Write(pb); i += 1; } NativeMethods.AllowSleep(); TimeSpan elapsed = DateTime.Now - start; Trace.WriteLine($"AConvertAndWriteAllConcepts time {elapsed}"); }
public void AConvertAndVerifyAllConcepts() { NativeMethods.PreventSleep(); DateTime start = DateTime.Now; Int32 i = 0; foreach (IComponent component in this.ReadConcepts()) { PBTinkarMsg pb = ConvertDTOToPB.Convert(component); if (pb != null) { IComponent dto = ConvertPBToDTO.Convert(pb); Assert.True(component.CompareTo(dto) == 0); } i += 1; } NativeMethods.AllowSleep(); TimeSpan elapsed = DateTime.Now - start; Trace.WriteLine($"AConvertAndVerifyAllConcepts time {elapsed}"); }