public static RelationshipElement Parse(JToken statement) { RelationshipElement relationshipElement = new RelationshipElement(); relationshipElement.IsCertainConnection = true; JToken locTokenFirst = statement.SelectToken("first.keys(0).value"); if (locTokenFirst != null) { relationshipElement.FirstAssetId = locTokenFirst.ToString(); } JToken locTokenSecond = statement.SelectToken("second.keys(0).value"); if (locTokenSecond != null) { relationshipElement.SecondAssetId = locTokenSecond.ToString(); } relationshipElement.SetValuesAccordingToAsset(); relationshipElement.FirstInterface = relationshipElement.ValueFirst + ((string)statement.SelectToken("first.keys(2).value")); relationshipElement.SecondInterface = relationshipElement.ValueSecond + ((string)statement.SelectToken("second.keys(2).value")); relationshipElement.IdShort = (string)statement.SelectToken("idShort"); if (relationshipElement.ValueFirst == null || relationshipElement.ValueSecond == null) { return(null); } return(relationshipElement); }
/// <summary> /// Parses the JToken into a RelationshipElement and returns the new created RelationshipElement /// </summary> /// <param name="valueFirst"></param> /// <param name="valueSecond"></param> /// <param name="idShort"></param> /// <param name="ReferenceToAsset"></param> /// <param name="interfaceFirst"></param> /// <param name="interfaceSecond"></param> /// <returns></returns> public static RelationshipElement Parse(string valueFirst, string valueSecond, string idShort, Dictionary <string, string> ReferenceToAsset, string interfaceFirst = null, string interfaceSecond = null) { RelationshipElement relationship = new RelationshipElement(); relationship.ValueFirst = valueFirst; relationship.ValueSecond = valueSecond; if (ReferenceToAsset.ContainsKey(relationship.ValueFirst)) { relationship.FirstAssetId = ReferenceToAsset[relationship.ValueFirst]; } if (ReferenceToAsset.ContainsKey(relationship.ValueSecond)) { relationship.SecondAssetId = ReferenceToAsset[relationship.ValueSecond]; } relationship.SetValuesAccordingToAsset(); relationship.IdShort = idShort; relationship.FirstInterface = interfaceFirst; relationship.SecondInterface = interfaceSecond; return(relationship); }