public void ConceptDTOConstructor() { String uuidString = $"[\"{Misc.g1.ToString()}\" \"{Misc.g2.ToString()}\" \"{Misc.g3.ToString()}\"]"; ConceptDTO dto = ConceptDTO.Make(uuidString); Assert.True(dto.PublicId.UuidCount == 3); Assert.True(dto.PublicId.AsUuidArray[0] == Misc.g1); Assert.True(dto.PublicId.AsUuidArray[1] == Misc.g2); Assert.True(dto.PublicId.AsUuidArray[2] == Misc.g3); }
/// <summary> /// Read Tinkar items from file. /// </summary> /// <returns>Object[].</returns> public IEnumerable <ComponentDTO> GetComponents() { JObject jObject = this.ReadJsonObject(); JArray items = (JArray)jObject["root"]; foreach (JObject item in items) { String className = (String)item["class"]; switch (className) { case ConceptChronologyDTO.JSONCLASSNAME: yield return(ConceptChronologyDTO.Make(item)); break; case PatternChronologyDTO.JSONCLASSNAME: yield return(PatternChronologyDTO.Make(item)); break; case SemanticChronologyDTO.JSONCLASSNAME: yield return(SemanticChronologyDTO.Make(item)); break; case ConceptDTO.JSONCLASSNAME: yield return(ConceptDTO.Make(item)); break; case PatternDTO.JSONCLASSNAME: yield return(PatternDTO.Make(item)); break; case SemanticDTO.JSONCLASSNAME: yield return(SemanticDTO.Make(item)); break; default: throw new NotImplementedException($"Tinkar class {className} not known"); } } }
public void ConceptDTOJsonMarshal() { ConceptDTO dtoStart = Misc.CreateConceptDTO; MemoryStream ms = new MemoryStream(); using (TinkarJsonOutput output = new TinkarJsonOutput(ms, true)) { dtoStart.Marshal(output); } ms.Dump(); ms.Position = 0; using (TinkarJsonInput input = new TinkarJsonInput(ms)) { ConceptDTO dtoEnd = ConceptDTO.Make(input.ReadJsonObject()); Assert.True(dtoStart.CompareTo(dtoEnd) == 0); } }
/// <summary> /// Read IJsonMarshalable values from the named child property. /// </summary> /// <param name="jObj">JSON parent container.</param> /// <returns>IJsonMarshalable values.</returns> private static IJsonMarshalable ReadJsonMarshable(this JObject jObj) { String actualClassName = jObj[ComponentFieldForJson.CLASS]?.Value <String>(); switch (actualClassName) { case null: throw new Exception($"{TErr} Missing CLASS Declaration"); case ConceptChronologyDTO.JSONCLASSNAME: return(ConceptChronologyDTO.Make(jObj)); case ConceptDTO.JSONCLASSNAME: return(ConceptDTO.Make(jObj)); case PatternChronologyDTO.JSONCLASSNAME: return(PatternChronologyDTO.Make(jObj)); case PatternDTO.JSONCLASSNAME: return(PatternDTO.Make(jObj)); case SemanticChronologyDTO.JSONCLASSNAME: return(SemanticChronologyDTO.Make(jObj)); case SemanticDTO.JSONCLASSNAME: return(SemanticDTO.Make(jObj)); case SpatialPointDTO.JSONCLASSNAME: return(SpatialPointDTO.Make(jObj)); case PlanarPointDTO.JSONCLASSNAME: return(PlanarPointDTO.Make(jObj)); default: throw new NotImplementedException($"Class {actualClassName} not known"); } }
/// <summary> /// Read an array or Object fields. /// </summary> /// <returns>Object[].</returns> public Object GetField() { FieldDataType token; try { token = (FieldDataType)this.reader.ReadByte(); } catch { return(null); } switch (token) { case FieldDataType.ConceptChronologyType: return(ConceptChronologyDTO.Make(this)); case FieldDataType.PatternChronologyType: return(PatternChronologyDTO.Make(this)); case FieldDataType.SemanticChronologyType: return(SemanticChronologyDTO.Make(this)); case FieldDataType.ConceptVersionType: throw new NotImplementedException(); case FieldDataType.PatternVersionType: throw new NotImplementedException(); case FieldDataType.SemanticVersionType: throw new NotImplementedException(); case FieldDataType.StampType: throw new NotImplementedException(); case FieldDataType.ConceptType: return(ConceptDTO.Make(this)); case FieldDataType.PatternType: return(PatternDTO.Make(this)); case FieldDataType.SemanticType: return(SemanticDTO.Make(this)); case FieldDataType.DiTreeType: return(DiTreeDTO.Make(this)); case FieldDataType.DiGraphType: return(DiGraphDTO.Make(this)); case FieldDataType.VertexType: throw new NotImplementedException(); case FieldDataType.ComponentIdList: return(this.GetPublicIdList()); case FieldDataType.ComponentIdSet: return(this.GetPublicIdSet()); case FieldDataType.PlanarPoint: return(new PlanarPointDTO(this.GetInt32(), this.GetInt32())); case FieldDataType.SpatialPoint: return(new SpatialPointDTO(this.GetInt32(), this.GetInt32(), this.GetInt32())); case FieldDataType.StringType: return(this.GetUTF()); case FieldDataType.IntegerType: return(this.GetInt32()); case FieldDataType.FloatType: return(this.GetSingle()); case FieldDataType.BooleanType: return(this.GetBoolean()); case FieldDataType.ByteArrayType: return(this.GetByteArray()); case FieldDataType.ObjectArrayType: return(this.GetObjects().ToArray()); case FieldDataType.InstantType: return(this.GetInstant()); default: throw new NotImplementedException($"FieldDataType {token} not known"); } }